Subversion Repositories HelenOS

Rev

Rev 1224 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1224 Rev 1226
Line 216... Line 216...
216
{
216
{
217
    char *digits = digits_small;
217
    char *digits = digits_small;
218
    char d[PRINT_NUMBER_BUFFER_SIZE];   /* this is good enough even for base == 2, prefix and sign */
218
    char d[PRINT_NUMBER_BUFFER_SIZE];   /* this is good enough even for base == 2, prefix and sign */
219
    char *ptr = &d[PRINT_NUMBER_BUFFER_SIZE - 1];
219
    char *ptr = &d[PRINT_NUMBER_BUFFER_SIZE - 1];
220
    int size = 0;
220
    int size = 0;
-
 
221
    int number_size; /* size of plain number */
221
    int written = 0;
222
    int written = 0;
222
    char sgn;
223
    char sgn;
223
   
224
   
224
    if (flags & __PRINTF_FLAG_BIGCHARS)
225
    if (flags & __PRINTF_FLAG_BIGCHARS)
225
        digits = digits_big;   
226
        digits = digits_big;   
Line 234... Line 235...
234
            *ptr-- = digits[num % base];
235
            *ptr-- = digits[num % base];
235
            size++;
236
            size++;
236
        } while (num /= base);
237
        } while (num /= base);
237
    }
238
    }
238
 
239
 
-
 
240
    number_size = size;
-
 
241
   
239
    /* Collect sum of all prefixes/signs/... to calculate padding and leading zeroes */
242
    /* Collect sum of all prefixes/signs/... to calculate padding and leading zeroes */
240
    if (flags & __PRINTF_FLAG_PREFIX) {
243
    if (flags & __PRINTF_FLAG_PREFIX) {
241
        switch(base) {
244
        switch(base) {
242
            case 2: /* Binary formating is not standard, but usefull */
245
            case 2: /* Binary formating is not standard, but usefull */
243
                size += 2;
246
                size += 2;
Line 270... Line 273...
270
    }
273
    }
271
 
274
 
272
    /* if number is leftaligned or precision is specified then zeropadding is ignored */
275
    /* if number is leftaligned or precision is specified then zeropadding is ignored */
273
    if (flags & __PRINTF_FLAG_ZEROPADDED) {
276
    if (flags & __PRINTF_FLAG_ZEROPADDED) {
274
        if ((precision == 0) && (width > size)) {
277
        if ((precision == 0) && (width > size)) {
275
            precision = width - size;
278
            precision = width - size + number_size;
276
        }
279
        }
277
    }
280
    }
278
 
281
 
279
    /* print leading spaces */
282
    /* print leading spaces */
280
    if (size > precision) /* We must print the whole number,  not only a part */
283
    if (number_size > precision) /* We must print whole number not only a part */
281
        precision = size;
284
        precision = number_size;
282
 
285
 
283
    width -= precision;
286
    width -= precision + size - number_size;
284
   
287
   
285
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
288
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
286
        while (width-- > 0) {  
289
        while (width-- > 0) {  
287
            putchar(' ');  
290
            putchar(' ');  
288
            written++;
291
            written++;
Line 323... Line 326...
323
                break;
326
                break;
324
        }
327
        }
325
    }
328
    }
326
 
329
 
327
    /* print leading zeroes */
330
    /* print leading zeroes */
328
    precision -= size;
331
    precision -= number_size;
329
    while (precision-- > 0) {  
332
    while (precision-- > 0) {  
330
        putchar('0');  
333
        putchar('0');  
331
        written++;
334
        written++;
332
    }
335
    }
333
 
336