Subversion Repositories HelenOS

Rev

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

Rev 1866 Rev 2070
Line 243... Line 243...
243
    number_size = size;
243
    number_size = size;
244
 
244
 
245
    /* Collect sum of all prefixes/signs/... to calculate padding and leading zeroes */
245
    /* Collect sum of all prefixes/signs/... to calculate padding and leading zeroes */
246
    if (flags & __PRINTF_FLAG_PREFIX) {
246
    if (flags & __PRINTF_FLAG_PREFIX) {
247
        switch(base) {
247
        switch(base) {
248
            case 2: /* Binary formating is not standard, but usefull */
248
        case 2: /* Binary formating is not standard, but usefull */
249
                size += 2;
249
            size += 2;
250
                break;
250
            break;
251
            case 8:
251
        case 8:
252
                size++;
252
            size++;
253
                break;
253
            break;
254
            case 16:
254
        case 16:
255
                size += 2;
255
            size += 2;
256
                break;
256
            break;
257
        }
257
        }
258
    }
258
    }
259
 
259
 
260
    sgn = 0;
260
    sgn = 0;
261
    if (flags & __PRINTF_FLAG_SIGNED) {
261
    if (flags & __PRINTF_FLAG_SIGNED) {
Line 303... Line 303...
303
   
303
   
304
    /* print prefix */
304
    /* print prefix */
305
   
305
   
306
    if (flags & __PRINTF_FLAG_PREFIX) {
306
    if (flags & __PRINTF_FLAG_PREFIX) {
307
        switch(base) {
307
        switch(base) {
308
            case 2: /* Binary formating is not standard, but usefull */
308
        case 2: /* Binary formating is not standard, but usefull */
-
 
309
            if (printf_putchar('0', ps) == 1)
-
 
310
                counter++;
-
 
311
            if (flags & __PRINTF_FLAG_BIGCHARS) {
309
                if (printf_putchar('0', ps) == 1)
312
                if (printf_putchar('B', ps) == 1)
310
                    counter++;
313
                    counter++;
311
                if (flags & __PRINTF_FLAG_BIGCHARS) {
-
 
312
                    if (printf_putchar('B', ps) == 1)
-
 
313
                        counter++;
-
 
314
                } else {
314
            } else {
315
                    if (printf_putchar('b', ps) == 1)
315
                if (printf_putchar('b', ps) == 1)
316
                        counter++;
-
 
317
                }
-
 
318
                break;
-
 
319
            case 8:
-
 
320
                if (printf_putchar('o', ps) == 1)
-
 
321
                    counter++;
316
                    counter++;
-
 
317
            }
322
                break;
318
            break;
-
 
319
        case 8:
-
 
320
            if (printf_putchar('o', ps) == 1)
-
 
321
                counter++;
-
 
322
            break;
323
            case 16:
323
        case 16:
-
 
324
            if (printf_putchar('0', ps) == 1)
-
 
325
                counter++;
-
 
326
            if (flags & __PRINTF_FLAG_BIGCHARS) {
324
                if (printf_putchar('0', ps) == 1)
327
                if (printf_putchar('X', ps) == 1)
325
                    counter++;
328
                    counter++;
326
                if (flags & __PRINTF_FLAG_BIGCHARS) {
-
 
327
                    if (printf_putchar('X', ps) == 1)
-
 
328
                        counter++;
-
 
329
                } else {
329
            } else {
330
                    if (printf_putchar('x', ps) == 1)
330
                if (printf_putchar('x', ps) == 1)
331
                        counter++;
331
                    counter++;
332
                }
332
            }
333
                break;
333
            break;
334
        }
334
        }
335
    }
335
    }
336
 
336
 
337
    /* print leading zeroes */
337
    /* print leading zeroes */
338
    precision -= number_size;
338
    precision -= number_size;
Line 469... Line 469...
469
            end = 0;
469
            end = 0;
470
           
470
           
471
            do {
471
            do {
472
                ++i;
472
                ++i;
473
                switch (c = fmt[i]) {
473
                switch (c = fmt[i]) {
474
                    case '#': flags |= __PRINTF_FLAG_PREFIX; break;
474
                case '#': flags |= __PRINTF_FLAG_PREFIX; break;
475
                    case '-': flags |= __PRINTF_FLAG_LEFTALIGNED; break;
475
                case '-': flags |= __PRINTF_FLAG_LEFTALIGNED; break;
476
                    case '+': flags |= __PRINTF_FLAG_SHOWPLUS; break;
476
                case '+': flags |= __PRINTF_FLAG_SHOWPLUS; break;
477
                    case ' ': flags |= __PRINTF_FLAG_SPACESIGN; break;
477
                case ' ': flags |= __PRINTF_FLAG_SPACESIGN; break;
478
                    case '0': flags |= __PRINTF_FLAG_ZEROPADDED; break;
478
                case '0': flags |= __PRINTF_FLAG_ZEROPADDED; break;
479
                    default: end = 1;
479
                default: end = 1;
480
                }; 
480
                }; 
481
               
481
               
482
            } while (end == 0);
482
            } while (end == 0);
483
           
483
           
484
            /* width & '*' operator */
484
            /* width & '*' operator */
Line 518... Line 518...
518
                    }
518
                    }
519
                }
519
                }
520
            }
520
            }
521
 
521
 
522
            switch (fmt[i++]) {
522
            switch (fmt[i++]) {
523
                /** TODO: unimplemented qualifiers:
523
            /** TODO: unimplemented qualifiers:
524
                 * t ptrdiff_t - ISO C 99
524
             * t ptrdiff_t - ISO C 99
525
                 */
525
             */
526
                case 'h':   /* char or short */
526
            case 'h':   /* char or short */
527
                    qualifier = PrintfQualifierShort;
527
                qualifier = PrintfQualifierShort;
528
                    if (fmt[i] == 'h') {
528
                if (fmt[i] == 'h') {
529
                        i++;
529
                    i++;
530
                        qualifier = PrintfQualifierByte;
530
                    qualifier = PrintfQualifierByte;
531
                    }
531
                }
532
                    break;
532
                break;
533
                case 'l':   /* long or long long*/
533
            case 'l':   /* long or long long*/
534
                    qualifier = PrintfQualifierLong;
534
                qualifier = PrintfQualifierLong;
535
                    if (fmt[i] == 'l') {
535
                if (fmt[i] == 'l') {
536
                        i++;
536
                    i++;
537
                        qualifier = PrintfQualifierLongLong;
537
                    qualifier = PrintfQualifierLongLong;
538
                    }
538
                }
539
                    break;
539
                break;
540
                case 'z':   /* size_t */
540
            case 'z':   /* size_t */
541
                    qualifier = PrintfQualifierSizeT;
541
                qualifier = PrintfQualifierSizeT;
542
                    break;
542
                break;
543
                default:
543
            default:
544
                    qualifier = PrintfQualifierInt; /* default type */
544
                qualifier = PrintfQualifierInt; /* default type */
545
                    --i;
545
                --i;
546
            }  
546
            }  
547
           
547
           
548
            base = 10;
548
            base = 10;
549
 
549
 
550
            switch (c = fmt[i]) {
550
            switch (c = fmt[i]) {
551
 
551
 
552
                /*
552
                /*
553
                * String and character conversions.
553
                * String and character conversions.
554
                */
554
                */
555
                case 's':
555
            case 's':
556
                    if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) < 0) {
556
                if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) < 0) {
557
                        goto minus_out;
557
                    goto minus_out;
558
                    };
-
 
559
                   
558
                }
560
                    counter += retval;
-
 
561
                    j = i + 1;
-
 
562
                    goto next_char;
-
 
563
                case 'c':
-
 
564
                    c = va_arg(ap, unsigned int);
-
 
565
                    if ((retval = print_char(c, width, flags, ps)) < 0) {
-
 
566
                        goto minus_out;
-
 
567
                    };
-
 
568
                   
559
                   
569
                    counter += retval;
560
                counter += retval;
570
                    j = i + 1;
561
                j = i + 1;
571
                    goto next_char;
562
                goto next_char;
-
 
563
            case 'c':
-
 
564
                c = va_arg(ap, unsigned int);
-
 
565
                if ((retval = print_char(c, width, flags, ps)) < 0) {
-
 
566
                    goto minus_out;
-
 
567
                }
572
 
568
 
-
 
569
                counter += retval;
-
 
570
                j = i + 1;
-
 
571
                goto next_char;
-
 
572
 
573
                /*
573
            /*
574
                 * Integer values
574
             * Integer values
575
                */
575
            */
576
                case 'P': /* pointer */
576
            case 'P': /* pointer */
577
                        flags |= __PRINTF_FLAG_BIGCHARS;
577
                    flags |= __PRINTF_FLAG_BIGCHARS;
578
                case 'p':
578
            case 'p':
579
                    flags |= __PRINTF_FLAG_PREFIX;
579
                flags |= __PRINTF_FLAG_PREFIX;
580
                    base = 16;
580
                base = 16;
581
                    qualifier = PrintfQualifierPointer;
581
                qualifier = PrintfQualifierPointer;
582
                    break; 
582
                break; 
583
                case 'b':
583
            case 'b':
584
                    base = 2;
584
                base = 2;
585
                    break;
585
                break;
586
                case 'o':
586
            case 'o':
587
                    base = 8;
587
                base = 8;
588
                    break;
588
                break;
589
                case 'd':
589
            case 'd':
590
                case 'i':
590
            case 'i':
591
                    flags |= __PRINTF_FLAG_SIGNED;  
591
                flags |= __PRINTF_FLAG_SIGNED;  
592
                case 'u':
592
            case 'u':
593
                    break;
593
                break;
594
                case 'X':
594
            case 'X':
595
                    flags |= __PRINTF_FLAG_BIGCHARS;
595
                flags |= __PRINTF_FLAG_BIGCHARS;
596
                case 'x':
596
            case 'x':
597
                    base = 16;
597
                base = 16;
598
                    break;
598
                break;
599
                /* percentile itself */
599
            /* percentile itself */
600
                case '%':
600
            case '%':
601
                    j = i;
601
                j = i;
602
                    goto next_char;
602
                goto next_char;
603
                /*
603
            /*
604
                * Bad formatting.
604
            * Bad formatting.
605
                */
605
            */
606
                default:
606
            default:
607
                    /* Unknown format
607
                /* Unknown format
608
                     *  now, the j is index of '%' so we will
608
                 *  now, the j is index of '%' so we will
609
                     * print whole bad format sequence
609
                 * print whole bad format sequence
610
                     */
610
                 */
611
                    goto next_char;    
611
                goto next_char;    
612
            }
612
            }
613
       
613
       
614
       
614
       
615
        /* Print integers */
615
        /* Print integers */
616
            /* print number */
616
            /* print number */
617
            switch (qualifier) {
617
            switch (qualifier) {
618
                case PrintfQualifierByte:
618
            case PrintfQualifierByte:
619
                    size = sizeof(unsigned char);
619
                size = sizeof(unsigned char);
620
                    number = (uint64_t)va_arg(ap, unsigned int);
620
                number = (uint64_t)va_arg(ap, unsigned int);
621
                    break;
621
                break;
622
                case PrintfQualifierShort:
622
            case PrintfQualifierShort:
623
                    size = sizeof(unsigned short);
623
                size = sizeof(unsigned short);
624
                    number = (uint64_t)va_arg(ap, unsigned int);
624
                number = (uint64_t)va_arg(ap, unsigned int);
625
                    break;
625
                break;
626
                case PrintfQualifierInt:
626
            case PrintfQualifierInt:
627
                    size = sizeof(unsigned int);
627
                size = sizeof(unsigned int);
628
                    number = (uint64_t)va_arg(ap, unsigned int);
628
                number = (uint64_t)va_arg(ap, unsigned int);
629
                    break;
629
                break;
630
                case PrintfQualifierLong:
630
            case PrintfQualifierLong:
631
                    size = sizeof(unsigned long);
631
                size = sizeof(unsigned long);
632
                    number = (uint64_t)va_arg(ap, unsigned long);
632
                number = (uint64_t)va_arg(ap, unsigned long);
633
                    break;
633
                break;
634
                case PrintfQualifierLongLong:
634
            case PrintfQualifierLongLong:
635
                    size = sizeof(unsigned long long);
635
                size = sizeof(unsigned long long);
636
                    number = (uint64_t)va_arg(ap, unsigned long long);
636
                number = (uint64_t)va_arg(ap, unsigned long long);
637
                    break;
637
                break;
638
                case PrintfQualifierPointer:
638
            case PrintfQualifierPointer:
639
                    size = sizeof(void *);
639
                size = sizeof(void *);
640
                    number = (uint64_t)(unsigned long)va_arg(ap, void *);
640
                number = (uint64_t)(unsigned long)va_arg(ap, void *);
641
                    break;
641
                break;
642
                case PrintfQualifierSizeT:
642
            case PrintfQualifierSizeT:
643
                    size = sizeof(size_t);
643
                size = sizeof(size_t);
644
                    number = (uint64_t)va_arg(ap, size_t);
644
                number = (uint64_t)va_arg(ap, size_t);
645
                    break;
645
                break;
646
                default: /* Unknown qualifier */
646
            default: /* Unknown qualifier */
647
                    goto minus_out;
647
                goto minus_out;
648
                   
648
                   
649
            }
649
            }
650
           
650
           
651
            if (flags & __PRINTF_FLAG_SIGNED) {
651
            if (flags & __PRINTF_FLAG_SIGNED) {
652
                if (number & (0x1 << (size*8 - 1))) {
652
                if (number & (0x1 << (size*8 - 1))) {