Subversion Repositories HelenOS-historic

Rev

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

Rev 1199 Rev 1225
Line 163... Line 163...
163
static int print_number(uint64_t num, int width, int precision, int base , uint64_t flags)
163
static int print_number(uint64_t num, int width, int precision, int base , uint64_t flags)
164
{
164
{
165
    char *digits = digits_small;
165
    char *digits = digits_small;
166
    char d[PRINT_NUMBER_BUFFER_SIZE];   /* this is good enough even for base == 2, prefix and sign */
166
    char d[PRINT_NUMBER_BUFFER_SIZE];   /* this is good enough even for base == 2, prefix and sign */
167
    char *ptr = &d[PRINT_NUMBER_BUFFER_SIZE - 1];
167
    char *ptr = &d[PRINT_NUMBER_BUFFER_SIZE - 1];
-
 
168
    int size = 0; /* size of number with all prefixes and signs */
168
    int size = 0;
169
    int number_size; /* size of plain number */
169
    int written = 0;
170
    int written = 0;
170
    char sgn;
171
    char sgn;
171
   
172
   
172
    if (flags & __PRINTF_FLAG_BIGCHARS)
173
    if (flags & __PRINTF_FLAG_BIGCHARS)
173
        digits = digits_big;   
174
        digits = digits_big;   
Line 181... Line 182...
181
        do {
182
        do {
182
            *ptr-- = digits[num % base];
183
            *ptr-- = digits[num % base];
183
            size++;
184
            size++;
184
        } while (num /= base);
185
        } while (num /= base);
185
    }
186
    }
-
 
187
   
-
 
188
    number_size = size;
186
 
189
   
187
    /* Collect sum of all prefixes/signs/... to calculate padding and leading zeroes */
190
    /* Collect sum of all prefixes/signs/... to calculate padding and leading zeroes */
188
    if (flags & __PRINTF_FLAG_PREFIX) {
191
    if (flags & __PRINTF_FLAG_PREFIX) {
189
        switch(base) {
192
        switch(base) {
190
            case 2: /* Binary formating is not standard, but usefull */
193
            case 2: /* Binary formating is not standard, but usefull */
191
                size += 2;
194
                size += 2;
Line 218... Line 221...
218
    }
221
    }
219
 
222
 
220
    /* if number is leftaligned or precision is specified then zeropadding is ignored */
223
    /* if number is leftaligned or precision is specified then zeropadding is ignored */
221
    if (flags & __PRINTF_FLAG_ZEROPADDED) {
224
    if (flags & __PRINTF_FLAG_ZEROPADDED) {
222
        if ((precision == 0) && (width > size)) {
225
        if ((precision == 0) && (width > size)) {
223
            precision = width - size;
226
            precision = width - size + number_size;
224
        }
227
        }
225
    }
228
    }
226
 
229
 
227
    /* print leading spaces */
230
    /* print leading spaces */
228
    if (size > precision) /* We must print whole number not only a part */
231
    if (number_size > precision) /* We must print whole number not only a part */
229
        precision = size;
232
        precision = number_size;
230
 
233
 
231
    width -= precision;
234
    width -= precision + size - number_size;
232
   
235
   
233
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
236
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
234
        while (width-- > 0) {  
237
        while (width-- > 0) {  
235
            putchar(' ');  
238
            putchar(' ');  
236
            written++;
239
            written++;
Line 271... Line 274...
271
                break;
274
                break;
272
        }
275
        }
273
    }
276
    }
274
 
277
 
275
    /* print leading zeroes */
278
    /* print leading zeroes */
276
    precision -= size;
279
    precision -= number_size;
277
    while (precision-- > 0) {  
280
    while (precision-- > 0) {  
278
        putchar('0');  
281
        putchar('0');  
279
        written++;
282
        written++;
280
    }
283
    }
281
 
284