Ignore:
Timestamp:
2009-03-31T22:11:11Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e1813cf
Parents:
32704cb
Message:

Semantics for 'index' parameter of utf8_encode/decode() should be more logical.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/printf/printf_core.c

    r32704cb rb54d2f1  
    258258        if (precision == 0)
    259259                precision = size;
    260        
     260
    261261        count_t counter = 0;
    262262        width -= precision;
     
    267267                }
    268268        }
    269        
     269
    270270        int retval;
    271271        size_t bytes = utf8_count_bytes(str, min(size, precision));
     
    279279                        counter++;
    280280        }
    281        
     281
    282282        return ((int) counter);
    283283}
     
    586586{
    587587        index_t i = 0;  /* Index of the currently processed character from fmt */
     588        index_t nxt = 0;
    588589        index_t j = 0;  /* Index to the first not printed nonformating character */
    589590       
     
    592593        int retval;           /* Return values from nested functions */
    593594       
    594         while ((uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT)) != 0) {
     595        while (true) {
     596                i = nxt;
     597                uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
     598
     599                if (uc == '\0') break;
     600
    595601                /* Control character */
    596602                if (uc == '%') {
     
    612618                       
    613619                        do {
    614                                 i++;
    615                                 uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT);
     620                                i = nxt;
     621                                uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
    616622                                switch (uc) {
    617623                                case '#':
     
    638644                        int width = 0;
    639645                        if (isdigit(uc)) {
    640                                 while ((uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT)) != 0) {
     646                                while (true) {
     647                                        width *= 10;
     648                                        width += uc - '0';
     649
     650                                        i = nxt;
     651                                        uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
     652                                        if (uc == '\0')
     653                                                break;
    641654                                        if (!isdigit(uc))
    642655                                                break;
    643                                        
    644                                         width *= 10;
    645                                         width += uc - '0';
    646                                         i++;
    647656                                }
    648657                        } else if (uc == '*') {
    649658                                /* Get width value from argument list */
    650                                 i++;
    651                                 uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT);
     659                                i = nxt;
     660                                uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
    652661                                width = (int) va_arg(ap, int);
    653662                                if (width < 0) {
     
    661670                        int precision = 0;
    662671                        if (uc == '.') {
    663                                 i++;
    664                                 uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT);
     672                                i = nxt;
     673                                uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
    665674                                if (isdigit(uc)) {
    666                                         while ((uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT)) != 0) {
     675                                        while (true) {
     676                                                precision *= 10;
     677                                                precision += uc - '0';
     678
     679                                                i = nxt;
     680                                                uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
     681                                                if (uc == '\0')
     682                                                        break;
    667683                                                if (!isdigit(uc))
    668684                                                        break;
    669                                                
    670                                                 precision *= 10;
    671                                                 precision += uc - '0';
    672                                                 i++;
    673685                                        }
    674                                 } else if (fmt[i] == '*') {
     686                                } else if (uc == '*') {
    675687                                        /* Get precision value from the argument list */
    676                                         i++;
    677                                         uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT);
     688                                        i = nxt;
     689                                        uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
    678690                                        precision = (int) va_arg(ap, int);
    679691                                        if (precision < 0) {
     
    693705                                /* Char or short */
    694706                                qualifier = PrintfQualifierShort;
    695                                 i++;
    696                                 uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT);
     707                                i = nxt;
     708                                uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
    697709                                if (uc == 'h') {
    698                                         i++;
    699                                         uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT);
     710                                        i = nxt;
     711                                        uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
    700712                                        qualifier = PrintfQualifierByte;
    701713                                }
     
    704716                                /* Long or long long */
    705717                                qualifier = PrintfQualifierLong;
    706                                 i++;
    707                                 uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT);
     718                                i = nxt;
     719                                uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
    708720                                if (uc == 'l') {
    709                                         i++;
    710                                         uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT);
     721                                        i = nxt;
     722                                        uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
    711723                                        qualifier = PrintfQualifierLongLong;
    712724                                }
     
    735747                               
    736748                                counter += retval;
    737                                 j = i + 1;
     749                                j = nxt;
    738750                                goto next_char;
    739751                        case 'c':
     
    749761                               
    750762                                counter += retval;
    751                                 j = i + 1;
     763                                j = nxt;
    752764                                goto next_char;
    753765                       
     
    853865                       
    854866                        counter += retval;
    855                         j = i + 1;
     867                        j = nxt;
    856868                }
    857869next_char:
    858                
    859                 i++;
     870                ;
    860871        }
    861872       
Note: See TracChangeset for help on using the changeset viewer.