Changeset d7baee6 in mainline for uspace/libc/generic/io/printf_core.c


Ignore:
Timestamp:
2007-01-17T13:03:08Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
df4ed85
Parents:
c738d65
Message:

Rather big indentation and formatting changes.
More inteligent long line wrapping.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/libc/generic/io/printf_core.c

    rc738d65 rd7baee6  
    246246        if (flags & __PRINTF_FLAG_PREFIX) {
    247247                switch(base) {
    248                         case 2: /* Binary formating is not standard, but usefull */
    249                                 size += 2;
    250                                 break;
    251                         case 8:
    252                                 size++;
    253                                 break;
    254                         case 16:
    255                                 size += 2;
    256                                 break;
     248                case 2: /* Binary formating is not standard, but usefull */
     249                        size += 2;
     250                        break;
     251                case 8:
     252                        size++;
     253                        break;
     254                case 16:
     255                        size += 2;
     256                        break;
    257257                }
    258258        }
     
    306306        if (flags & __PRINTF_FLAG_PREFIX) {
    307307                switch(base) {
    308                         case 2: /* Binary formating is not standard, but usefull */
    309                                 if (printf_putchar('0', ps) == 1)
     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) {
     312                                if (printf_putchar('B', ps) == 1)
    310313                                        counter++;
    311                                 if (flags & __PRINTF_FLAG_BIGCHARS) {
    312                                         if (printf_putchar('B', ps) == 1)
    313                                                 counter++;
    314                                 } else {
    315                                         if (printf_putchar('b', ps) == 1)
    316                                                 counter++;
    317                                 }
    318                                 break;
    319                         case 8:
    320                                 if (printf_putchar('o', ps) == 1)
     314                        } else {
     315                                if (printf_putchar('b', ps) == 1)
    321316                                        counter++;
    322                                 break;
    323                         case 16:
    324                                 if (printf_putchar('0', ps) == 1)
     317                        }
     318                        break;
     319                case 8:
     320                        if (printf_putchar('o', ps) == 1)
     321                                counter++;
     322                        break;
     323                case 16:
     324                        if (printf_putchar('0', ps) == 1)
     325                                counter++;
     326                        if (flags & __PRINTF_FLAG_BIGCHARS) {
     327                                if (printf_putchar('X', ps) == 1)
    325328                                        counter++;
    326                                 if (flags & __PRINTF_FLAG_BIGCHARS) {
    327                                         if (printf_putchar('X', ps) == 1)
    328                                                 counter++;
    329                                 } else {
    330                                         if (printf_putchar('x', ps) == 1)
    331                                                 counter++;
    332                                 }
    333                                 break;
     329                        } else {
     330                                if (printf_putchar('x', ps) == 1)
     331                                        counter++;
     332                        }
     333                        break;
    334334                }
    335335        }
     
    472472                                ++i;
    473473                                switch (c = fmt[i]) {
    474                                         case '#': flags |= __PRINTF_FLAG_PREFIX; break;
    475                                         case '-': flags |= __PRINTF_FLAG_LEFTALIGNED; break;
    476                                         case '+': flags |= __PRINTF_FLAG_SHOWPLUS; break;
    477                                         case ' ': flags |= __PRINTF_FLAG_SPACESIGN; break;
    478                                         case '0': flags |= __PRINTF_FLAG_ZEROPADDED; break;
    479                                         default: end = 1;
     474                                case '#': flags |= __PRINTF_FLAG_PREFIX; break;
     475                                case '-': flags |= __PRINTF_FLAG_LEFTALIGNED; break;
     476                                case '+': flags |= __PRINTF_FLAG_SHOWPLUS; break;
     477                                case ' ': flags |= __PRINTF_FLAG_SPACESIGN; break;
     478                                case '0': flags |= __PRINTF_FLAG_ZEROPADDED; break;
     479                                default: end = 1;
    480480                                };     
    481481                               
     
    521521
    522522                        switch (fmt[i++]) {
    523                                 /** TODO: unimplemented qualifiers:
    524                                 * t ptrdiff_t - ISO C 99
    525                                 */
    526                                 case 'h':       /* char or short */
    527                                         qualifier = PrintfQualifierShort;
    528                                         if (fmt[i] == 'h') {
    529                                                 i++;
    530                                                 qualifier = PrintfQualifierByte;
    531                                         }
    532                                         break;
    533                                 case 'l':       /* long or long long*/
    534                                         qualifier = PrintfQualifierLong;
    535                                         if (fmt[i] == 'l') {
    536                                                 i++;
    537                                                 qualifier = PrintfQualifierLongLong;
    538                                         }
    539                                         break;
    540                                 case 'z':       /* size_t */
    541                                         qualifier = PrintfQualifierSizeT;
    542                                         break;
    543                                 default:
    544                                         qualifier = PrintfQualifierInt; /* default type */
    545                                         --i;
     523                        /** TODO: unimplemented qualifiers:
     524                        * t ptrdiff_t - ISO C 99
     525                        */
     526                        case 'h':       /* char or short */
     527                                qualifier = PrintfQualifierShort;
     528                                if (fmt[i] == 'h') {
     529                                        i++;
     530                                        qualifier = PrintfQualifierByte;
     531                                }
     532                                break;
     533                        case 'l':       /* long or long long*/
     534                                qualifier = PrintfQualifierLong;
     535                                if (fmt[i] == 'l') {
     536                                        i++;
     537                                        qualifier = PrintfQualifierLongLong;
     538                                }
     539                                break;
     540                        case 'z':       /* size_t */
     541                                qualifier = PrintfQualifierSizeT;
     542                                break;
     543                        default:
     544                                qualifier = PrintfQualifierInt; /* default type */
     545                                --i;
    546546                        }       
    547547                       
     
    553553                                * String and character conversions.
    554554                                */
    555                                 case 's':
    556                                         if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) < 0) {
    557                                                 goto minus_out;
    558                                         };
     555                        case 's':
     556                                if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) < 0) {
     557                                        goto minus_out;
     558                                }
    559559                                       
    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                                        
    569                                         counter += retval;
    570                                         j = i + 1;
    571                                         goto next_char;
    572 
    573                                 /*
    574                                 * Integer values
    575                                 */
    576                                 case 'P': /* pointer */
    577                                         flags |= __PRINTF_FLAG_BIGCHARS;
    578                                 case 'p':
    579                                         flags |= __PRINTF_FLAG_PREFIX;
    580                                         base = 16;
    581                                         qualifier = PrintfQualifierPointer;
    582                                         break; 
    583                                 case 'b':
    584                                         base = 2;
    585                                         break;
    586                                 case 'o':
    587                                         base = 8;
    588                                         break;
    589                                 case 'd':
    590                                 case 'i':
    591                                         flags |= __PRINTF_FLAG_SIGNED; 
    592                                 case 'u':
    593                                         break;
    594                                 case 'X':
    595                                         flags |= __PRINTF_FLAG_BIGCHARS;
    596                                 case 'x':
    597                                         base = 16;
    598                                         break;
    599                                 /* percentile itself */
    600                                 case '%':
    601                                         j = i;
    602                                         goto next_char;
    603                                 /*
    604                                 * Bad formatting.
    605                                 */
    606                                 default:
    607                                         /* Unknown format
    608                                         *  now, the j is index of '%' so we will
    609                                         * print whole bad format sequence
    610                                         */
    611                                         goto next_char;         
     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
     569                                counter += retval;
     570                                j = i + 1;
     571                                goto next_char;
     572
     573                        /*
     574                        * Integer values
     575                        */
     576                        case 'P': /* pointer */
     577                                flags |= __PRINTF_FLAG_BIGCHARS;
     578                        case 'p':
     579                                flags |= __PRINTF_FLAG_PREFIX;
     580                                base = 16;
     581                                qualifier = PrintfQualifierPointer;
     582                                break; 
     583                        case 'b':
     584                                base = 2;
     585                                break;
     586                        case 'o':
     587                                base = 8;
     588                                break;
     589                        case 'd':
     590                        case 'i':
     591                                flags |= __PRINTF_FLAG_SIGNED; 
     592                        case 'u':
     593                                break;
     594                        case 'X':
     595                                flags |= __PRINTF_FLAG_BIGCHARS;
     596                        case 'x':
     597                                base = 16;
     598                                break;
     599                        /* percentile itself */
     600                        case '%':
     601                                j = i;
     602                                goto next_char;
     603                        /*
     604                        * Bad formatting.
     605                        */
     606                        default:
     607                                /* Unknown format
     608                                *  now, the j is index of '%' so we will
     609                                * print whole bad format sequence
     610                                */
     611                                goto next_char;         
    612612                        }
    613613               
     
    616616                        /* print number */
    617617                        switch (qualifier) {
    618                                 case PrintfQualifierByte:
    619                                         size = sizeof(unsigned char);
    620                                         number = (uint64_t)va_arg(ap, unsigned int);
    621                                         break;
    622                                 case PrintfQualifierShort:
    623                                         size = sizeof(unsigned short);
    624                                         number = (uint64_t)va_arg(ap, unsigned int);
    625                                         break;
    626                                 case PrintfQualifierInt:
    627                                         size = sizeof(unsigned int);
    628                                         number = (uint64_t)va_arg(ap, unsigned int);
    629                                         break;
    630                                 case PrintfQualifierLong:
    631                                         size = sizeof(unsigned long);
    632                                         number = (uint64_t)va_arg(ap, unsigned long);
    633                                         break;
    634                                 case PrintfQualifierLongLong:
    635                                         size = sizeof(unsigned long long);
    636                                         number = (uint64_t)va_arg(ap, unsigned long long);
    637                                         break;
    638                                 case PrintfQualifierPointer:
    639                                         size = sizeof(void *);
    640                                         number = (uint64_t)(unsigned long)va_arg(ap, void *);
    641                                         break;
    642                                 case PrintfQualifierSizeT:
    643                                         size = sizeof(size_t);
    644                                         number = (uint64_t)va_arg(ap, size_t);
    645                                         break;
    646                                 default: /* Unknown qualifier */
    647                                         goto minus_out;
     618                        case PrintfQualifierByte:
     619                                size = sizeof(unsigned char);
     620                                number = (uint64_t)va_arg(ap, unsigned int);
     621                                break;
     622                        case PrintfQualifierShort:
     623                                size = sizeof(unsigned short);
     624                                number = (uint64_t)va_arg(ap, unsigned int);
     625                                break;
     626                        case PrintfQualifierInt:
     627                                size = sizeof(unsigned int);
     628                                number = (uint64_t)va_arg(ap, unsigned int);
     629                                break;
     630                        case PrintfQualifierLong:
     631                                size = sizeof(unsigned long);
     632                                number = (uint64_t)va_arg(ap, unsigned long);
     633                                break;
     634                        case PrintfQualifierLongLong:
     635                                size = sizeof(unsigned long long);
     636                                number = (uint64_t)va_arg(ap, unsigned long long);
     637                                break;
     638                        case PrintfQualifierPointer:
     639                                size = sizeof(void *);
     640                                number = (uint64_t)(unsigned long)va_arg(ap, void *);
     641                                break;
     642                        case PrintfQualifierSizeT:
     643                                size = sizeof(size_t);
     644                                number = (uint64_t)va_arg(ap, size_t);
     645                                break;
     646                        default: /* Unknown qualifier */
     647                                goto minus_out;
    648648                                       
    649649                        }
Note: See TracChangeset for help on using the changeset viewer.