Subversion Repositories HelenOS-historic

Rev

Rev 1702 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1702 Rev 1780
Line 86... Line 86...
86
 
86
 
87
/** Compute length of given zero terminated string.
87
/** Compute length of given zero terminated string.
88
 * @param str Pointer to valid string.
88
 * @param str Pointer to valid string.
89
 * @return string length without trailing zero.
89
 * @return string length without trailing zero.
90
 */
90
 */
91
static __native strlen(const char *str)
91
static unative_t strlen(const char *str)
92
{
92
{
93
    __native counter = 0;
93
    unative_t counter = 0;
94
 
94
 
95
    while (str[counter] != 0) {
95
    while (str[counter] != 0) {
96
        counter++;
96
        counter++;
97
    }
97
    }
98
 
98
 
Line 144... Line 144...
144
 * @param c character to print
144
 * @param c character to print
145
 * @param width
145
 * @param width
146
 * @param flags
146
 * @param flags
147
 * @return number of printed characters, negative value on fail
147
 * @return number of printed characters, negative value on fail
148
 */
148
 */
149
static int print_char(char c, int width, __u64 flags, struct printf_spec *ps)
149
static int print_char(char c, int width, uint64_t flags, struct printf_spec *ps)
150
{
150
{
151
    int counter = 0;
151
    int counter = 0;
152
   
152
   
153
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
153
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
154
        while (--width > 0) {   /* one space is consumed by character itself hence predecrement */
154
        while (--width > 0) {   /* one space is consumed by character itself hence predecrement */
Line 174... Line 174...
174
 * @param precision
174
 * @param precision
175
 * @param flags
175
 * @param flags
176
 * @return number of printed characters or negative value on fail
176
 * @return number of printed characters or negative value on fail
177
 */
177
 */
178
                       
178
                       
179
static int print_string(char *s, int width, int precision, __u64 flags, struct printf_spec *ps)
179
static int print_string(char *s, int width, int precision, uint64_t flags, struct printf_spec *ps)
180
{
180
{
181
    int counter = 0;
181
    int counter = 0;
182
    size_t size;
182
    size_t size;
183
    int retval;
183
    int retval;
184
 
184
 
Line 234... Line 234...
234
 *             be in range 2 .. 16).
234
 *             be in range 2 .. 16).
235
 * @param flags output modifiers
235
 * @param flags output modifiers
236
 * @return number of written characters or EOF
236
 * @return number of written characters or EOF
237
 *
237
 *
238
 */
238
 */
239
static int print_number(__u64 num, int width, int precision, int base , __u64 flags, struct printf_spec *ps)
239
static int print_number(uint64_t num, int width, int precision, int base , uint64_t flags, struct printf_spec *ps)
240
{
240
{
241
    char *digits = digits_small;
241
    char *digits = digits_small;
242
    char d[PRINT_NUMBER_BUFFER_SIZE];   /* this is good enough even for base == 2, prefix and sign */
242
    char d[PRINT_NUMBER_BUFFER_SIZE];   /* this is good enough even for base == 2, prefix and sign */
243
    char *ptr = &d[PRINT_NUMBER_BUFFER_SIZE - 1];
243
    char *ptr = &d[PRINT_NUMBER_BUFFER_SIZE - 1];
244
    int size = 0; /* size of number with all prefixes and signs */
244
    int size = 0; /* size of number with all prefixes and signs */
Line 425... Line 425...
425
 *  - "hh"  Signed or unsigned char.@n
425
 *  - "hh"  Signed or unsigned char.@n
426
 *  - "h"   Signed or usigned short.@n
426
 *  - "h"   Signed or usigned short.@n
427
 *  - ""    Signed or usigned int (default value).@n
427
 *  - ""    Signed or usigned int (default value).@n
428
 *  - "l"   Signed or usigned long int.@n
428
 *  - "l"   Signed or usigned long int.@n
429
 *  - "ll"  Signed or usigned long long int.@n
429
 *  - "ll"  Signed or usigned long long int.@n
430
 *  - "z"   __native (non-standard extension).@n
430
 *  - "z"   unative_t (non-standard extension).@n
431
 *
431
 *
432
 *
432
 *
433
 * CONVERSION:@n
433
 * CONVERSION:@n
434
 *  - % Print percentile character itself.
434
 *  - % Print percentile character itself.
435
 *
435
 *
Line 464... Line 464...
464
    int counter; /**< counter of printed characters */
464
    int counter; /**< counter of printed characters */
465
    int retval; /**< used to store return values from called functions */
465
    int retval; /**< used to store return values from called functions */
466
    char c;
466
    char c;
467
    qualifier_t qualifier;  /* type of argument */
467
    qualifier_t qualifier;  /* type of argument */
468
    int base;   /**< base in which will be parameter (numbers only) printed */
468
    int base;   /**< base in which will be parameter (numbers only) printed */
469
    __u64 number; /**< argument value */
469
    uint64_t number; /**< argument value */
470
    size_t  size; /**< byte size of integer parameter */
470
    size_t  size; /**< byte size of integer parameter */
471
    int width, precision;
471
    int width, precision;
472
    __u64 flags;
472
    uint64_t flags;
473
   
473
   
474
    counter = 0;
474
    counter = 0;
475
   
475
   
476
    irqpri = interrupts_disable();
476
    irqpri = interrupts_disable();
477
    spinlock_lock(&printflock);
477
    spinlock_lock(&printflock);
Line 560... Line 560...
560
                    if (fmt[i] == 'l') {
560
                    if (fmt[i] == 'l') {
561
                        i++;
561
                        i++;
562
                        qualifier = PrintfQualifierLongLong;
562
                        qualifier = PrintfQualifierLongLong;
563
                    }
563
                    }
564
                    break;
564
                    break;
565
                case 'z':   /* __native */
565
                case 'z':   /* unative_t */
566
                    qualifier = PrintfQualifierNative;
566
                    qualifier = PrintfQualifierNative;
567
                    break;
567
                    break;
568
                default:
568
                default:
569
                    qualifier = PrintfQualifierInt; /* default type */
569
                    qualifier = PrintfQualifierInt; /* default type */
570
                    --i;
570
                    --i;
Line 642... Line 642...
642
        /* Print integers */
642
        /* Print integers */
643
            /* print number */
643
            /* print number */
644
            switch (qualifier) {
644
            switch (qualifier) {
645
                case PrintfQualifierByte:
645
                case PrintfQualifierByte:
646
                    size = sizeof(unsigned char);
646
                    size = sizeof(unsigned char);
647
                    number = (__u64)va_arg(ap, unsigned int);
647
                    number = (uint64_t)va_arg(ap, unsigned int);
648
                    break;
648
                    break;
649
                case PrintfQualifierShort:
649
                case PrintfQualifierShort:
650
                    size = sizeof(unsigned short);
650
                    size = sizeof(unsigned short);
651
                    number = (__u64)va_arg(ap, unsigned int);
651
                    number = (uint64_t)va_arg(ap, unsigned int);
652
                    break;
652
                    break;
653
                case PrintfQualifierInt:
653
                case PrintfQualifierInt:
654
                    size = sizeof(unsigned int);
654
                    size = sizeof(unsigned int);
655
                    number = (__u64)va_arg(ap, unsigned int);
655
                    number = (uint64_t)va_arg(ap, unsigned int);
656
                    break;
656
                    break;
657
                case PrintfQualifierLong:
657
                case PrintfQualifierLong:
658
                    size = sizeof(unsigned long);
658
                    size = sizeof(unsigned long);
659
                    number = (__u64)va_arg(ap, unsigned long);
659
                    number = (uint64_t)va_arg(ap, unsigned long);
660
                    break;
660
                    break;
661
                case PrintfQualifierLongLong:
661
                case PrintfQualifierLongLong:
662
                    size = sizeof(unsigned long long);
662
                    size = sizeof(unsigned long long);
663
                    number = (__u64)va_arg(ap, unsigned long long);
663
                    number = (uint64_t)va_arg(ap, unsigned long long);
664
                    break;
664
                    break;
665
                case PrintfQualifierPointer:
665
                case PrintfQualifierPointer:
666
                    size = sizeof(void *);
666
                    size = sizeof(void *);
667
                    number = (__u64)(unsigned long)va_arg(ap, void *);
667
                    number = (uint64_t)(unsigned long)va_arg(ap, void *);
668
                    break;
668
                    break;
669
                case PrintfQualifierNative:
669
                case PrintfQualifierNative:
670
                    size = sizeof(__native);
670
                    size = sizeof(unative_t);
671
                    number = (__u64)va_arg(ap, __native);
671
                    number = (uint64_t)va_arg(ap, unative_t);
672
                    break;
672
                    break;
673
                default: /* Unknown qualifier */
673
                default: /* Unknown qualifier */
674
                    counter = -counter;
674
                    counter = -counter;
675
                    goto out;
675
                    goto out;
676
            }
676
            }
677
           
677
           
678
            if (flags & __PRINTF_FLAG_SIGNED) {
678
            if (flags & __PRINTF_FLAG_SIGNED) {
679
                if (number & (0x1 << (size*8 - 1))) {
679
                if (number & (0x1 << (size*8 - 1))) {
680
                    flags |= __PRINTF_FLAG_NEGATIVE;
680
                    flags |= __PRINTF_FLAG_NEGATIVE;
681
               
681
               
682
                    if (size == sizeof(__u64)) {
682
                    if (size == sizeof(uint64_t)) {
683
                        number = -((__s64)number);
683
                        number = -((int64_t)number);
684
                    } else {
684
                    } else {
685
                        number = ~number;
685
                        number = ~number;
686
                        number &= (~((0xFFFFFFFFFFFFFFFFll) <<  (size * 8)));
686
                        number &= (~((0xFFFFFFFFFFFFFFFFll) <<  (size * 8)));
687
                        number++;
687
                        number++;
688
                    }
688
                    }
Line 701... Line 701...
701
           
701
           
702
        ++i;
702
        ++i;
703
    }
703
    }
704
   
704
   
705
    if (i > j) {
705
    if (i > j) {
706
        if ((retval = printf_putnchars(&fmt[j], (__native)(i - j), ps)) < 0) { /* error */
706
        if ((retval = printf_putnchars(&fmt[j], (unative_t)(i - j), ps)) < 0) { /* error */
707
            counter = -counter;
707
            counter = -counter;
708
            goto out;
708
            goto out;
709
           
709
           
710
        }
710
        }
711
        counter += retval;
711
        counter += retval;