~ubuntu-branches/ubuntu/feisty/elinks/feisty-updates

« back to all changes in this revision

Viewing changes to src/util/conv.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-06-30 08:57:43 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060630085743-l81fgbw9dehvl1ds
Tags: 0.11.1-1ubuntu1
* Merge to Debian unstable.
* Removed gnutls12 porting, this is upstream now.
* Only Ubuntu changes left:
  - Killed type-handling.
  - Add X-Ubuntu-Gettext-Domain to .desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Conversion functions */
2
 
/* $Id: conv.c,v 1.70 2004/11/25 23:50:15 miciah Exp $ */
3
2
 
4
3
#ifdef HAVE_CONFIG_H
5
4
#include "config.h"
19
18
#include "util/conv.h"
20
19
#include "util/error.h"
21
20
#include "util/string.h"
22
 
#include "util/ttime.h"
 
21
#include "util/time.h"
23
22
 
24
23
 
25
24
 
167
166
}
168
167
 
169
168
struct string *
170
 
add_xnum_to_string(struct string *string, int xnum)
 
169
add_xnum_to_string(struct string *string, off_t xnum)
171
170
{
172
171
        unsigned char suff[3] = "\0i";
173
 
        int d = -1;
 
172
        off_t d = -1;
174
173
 
175
174
        /* XXX: I don't completely like the computation of d here. --pasky */
176
175
        /* Mebi (Mi), 2^20 */
177
176
        if (xnum >= 1024 * 1024) {
178
177
                suff[0] = 'M';
179
 
                d = (xnum / (int) ((int) (1024 * 1024) / (int) 10)) % 10;
 
178
                d = (xnum * (int) 10 / (int) ((int) (1024 * 1024))) % 10;
180
179
                xnum /= 1024*1024;
181
180
        /* Kibi (Ki), 2^10 */
182
181
        } else if (xnum >= 1024) {
183
182
                suff[0] = 'K';
184
 
                d = (xnum / (int) ((int) 1024 / (int) 10)) % 10;
 
183
                d = (xnum * (int) 10 / (int) 1024) % 10;
185
184
                xnum /= 1024;
186
185
        }
 
186
 
 
187
        assert(xnum == (long) xnum);
187
188
        add_long_to_string(string, xnum);
188
189
 
189
190
        if (xnum < 10 && d != -1) {
198
199
}
199
200
 
200
201
struct string *
201
 
add_time_to_string(struct string *string, ttime time)
 
202
add_duration_to_string(struct string *string, long seconds)
202
203
{
203
204
        unsigned char q[64];
204
205
        int qlen = 0;
205
206
 
206
 
        time /= 1000;
207
 
        time &= 0xffffffff;
208
 
 
209
 
        if (time < 0) time = 0;
 
207
        if (seconds < 0) seconds = 0;
210
208
 
211
209
        /* Days */
212
 
        if (time >= (24 * 3600)) {
213
 
                ulongcat(q, &qlen, (time / (24 * 3600)), 5, 0);
 
210
        if (seconds >= (24 * 3600)) {
 
211
                ulongcat(q, &qlen, (seconds / (24 * 3600)), 5, 0);
214
212
                q[qlen++] = 'd';
215
213
                q[qlen++] = ' ';
216
214
        }
217
215
 
218
216
        /* Hours and minutes */
219
 
        if (time >= 3600) {
220
 
                time %= (24 * 3600);
221
 
                ulongcat(q, &qlen, (time / 3600), 4, 0);
 
217
        if (seconds >= 3600) {
 
218
                seconds %= (24 * 3600);
 
219
                ulongcat(q, &qlen, (seconds / 3600), 4, 0);
222
220
                q[qlen++] = ':';
223
 
                ulongcat(q, &qlen, ((time / 60) % 60), 2, '0');
 
221
                ulongcat(q, &qlen, ((seconds / 60) % 60), 2, '0');
224
222
        } else {
225
223
                /* Only minutes */
226
 
                ulongcat(q, &qlen, (time / 60), 2, 0);
 
224
                ulongcat(q, &qlen, (seconds / 60), 2, 0);
227
225
        }
228
226
 
229
227
        /* Seconds */
230
228
        q[qlen++] = ':';
231
 
        ulongcat(q, &qlen, (time % 60), 2, '0');
 
229
        ulongcat(q, &qlen, (seconds % 60), 2, '0');
232
230
 
233
231
        add_to_string(string, q);
234
232
        return string;
235
233
}
236
234
 
 
235
struct string *
 
236
add_timeval_to_string(struct string *string, timeval_T *timeval)
 
237
{
 
238
        return add_duration_to_string(string, timeval_to_seconds(timeval));
 
239
}
 
240
 
237
241
#ifdef HAVE_STRFTIME
238
242
struct string *
239
 
add_date_to_string(struct string *string, unsigned char *fmt, ttime *date)
 
243
add_date_to_string(struct string *string, unsigned char *fmt, time_t *date)
240
244
{
241
245
        unsigned char buffer[MAX_STR_LEN];
242
 
        ttime when_time = date ? *date : time(NULL);
 
246
        time_t when_time = date ? *date : time(NULL);
243
247
        struct tm *when_local = localtime(&when_time);
244
248
 
245
249
        if (strftime(buffer, sizeof(buffer), fmt, when_local) <= 0)
450
454
        if (!len) return;
451
455
 
452
456
        while (len--) {
453
 
                if (title[len] < ' ')
 
457
                if (title[len] < ' ' || title[len] == NBSP_CHAR)
454
458
                        title[len] = ' ';
455
459
        }
456
460
        trim_chars(title, ' ', NULL);