Changeset a35b458 in mainline for boot/generic/src/printf_core.c


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • boot/generic/src/printf_core.c

    r3061bc1 ra35b458  
    138138        if (str == NULL)
    139139                return printf_putnchars(nullstr, str_size(nullstr), ps);
    140        
     140
    141141        return ps->str_write((void *) str, str_size(str), ps->data);
    142142}
     
    154154        if (!ascii_check(ch))
    155155                return ps->str_write((void *) &invalch, 1, ps->data);
    156        
     156
    157157        return ps->str_write(&ch, 1, ps->data);
    158158}
     
    180180                }
    181181        }
    182        
     182
    183183        if (printf_putchar(ch, ps) > 0)
    184184                counter++;
    185        
     185
    186186        while (--width > 0) {
    187187                /*
     
    192192                        counter++;
    193193        }
    194        
     194
    195195        return (int) (counter);
    196196}
     
    210210        if (str == NULL)
    211211                return printf_putstr(nullstr, ps);
    212        
     212
    213213        /* Print leading spaces. */
    214214        size_t strw = str_length(str);
    215215        if ((precision == 0) || (precision > strw))
    216216                precision = strw;
    217        
     217
    218218        /* Left padding */
    219219        size_t counter = 0;
     
    225225                }
    226226        }
    227        
     227
    228228        /* Part of @a str fitting into the alloted space. */
    229229        int retval;
     
    231231        if ((retval = printf_putnchars(str, size, ps)) < 0)
    232232                return -counter;
    233        
     233
    234234        counter += retval;
    235        
     235
    236236        /* Right padding */
    237237        while (width-- > 0) {
     
    264264        else
    265265                digits = digits_small;
    266        
     266
    267267        char data[PRINT_NUMBER_BUFFER_SIZE];
    268268        char *ptr = &data[PRINT_NUMBER_BUFFER_SIZE - 1];
    269        
     269
    270270        /* Size of number with all prefixes and signs */
    271271        int size = 0;
    272        
     272
    273273        /* Put zero at end of string */
    274274        *ptr-- = 0;
    275        
     275
    276276        if (num == 0) {
    277277                *ptr-- = '0';
     
    283283                } while (num /= base);
    284284        }
    285        
     285
    286286        /* Size of plain number */
    287287        int number_size = size;
    288        
     288
    289289        /*
    290290         * Collect the sum of all prefixes/signs/etc. to calculate padding and
     
    305305                }
    306306        }
    307        
     307
    308308        char sgn = 0;
    309309        if (flags & __PRINTF_FLAG_SIGNED) {
     
    319319                }
    320320        }
    321        
     321
    322322        if (flags & __PRINTF_FLAG_LEFTALIGNED)
    323323                flags &= ~__PRINTF_FLAG_ZEROPADDED;
    324        
     324
    325325        /*
    326326         * If the number is left-aligned or precision is specified then
     
    331331                        precision = width - size + number_size;
    332332        }
    333        
     333
    334334        /* Print leading spaces */
    335335        if (number_size > precision) {
     
    337337                precision = number_size;
    338338        }
    339        
     339
    340340        width -= precision + size - number_size;
    341341        size_t counter = 0;
    342        
     342
    343343        if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
    344344                while (width-- > 0) {
     
    347347                }
    348348        }
    349        
     349
    350350        /* Print sign */
    351351        if (sgn) {
     
    353353                        counter++;
    354354        }
    355        
     355
    356356        /* Print prefix */
    357357        if (flags & __PRINTF_FLAG_PREFIX) {
     
    386386                }
    387387        }
    388        
     388
    389389        /* Print leading zeroes */
    390390        precision -= number_size;
     
    393393                        counter++;
    394394        }
    395        
     395
    396396        /* Print the number itself */
    397397        int retval;
    398398        if ((retval = printf_putstr(++ptr, ps)) > 0)
    399399                counter += retval;
    400        
     400
    401401        /* Print trailing spaces */
    402        
     402
    403403        while (width-- > 0) {
    404404                if (printf_putchar(' ', ps) == 1)
    405405                        counter++;
    406406        }
    407        
     407
    408408        return ((int) counter);
    409409}
     
    497497        size_t nxt = 0;  /* Index of the next character from fmt */
    498498        size_t j = 0;    /* Index to the first not printed nonformating character */
    499        
     499
    500500        size_t counter = 0;   /* Number of characters printed */
    501501        int retval;           /* Return values from nested functions */
    502        
     502
    503503        while (true) {
    504504                i = nxt;
    505505                wchar_t uc = str_decode(fmt, &nxt, STR_NO_LIMIT);
    506                
     506
    507507                if (uc == 0)
    508508                        break;
    509                
     509
    510510                /* Control character */
    511511                if (uc == '%') {
     
    519519                                counter += retval;
    520520                        }
    521                        
     521
    522522                        j = i;
    523                        
     523
    524524                        /* Parse modifiers */
    525525                        uint32_t flags = 0;
    526526                        bool end = false;
    527                        
     527
    528528                        do {
    529529                                i = nxt;
     
    549549                                };
    550550                        } while (!end);
    551                        
     551
    552552                        /* Width & '*' operator */
    553553                        int width = 0;
     
    556556                                        width *= 10;
    557557                                        width += uc - '0';
    558                                        
     558
    559559                                        i = nxt;
    560560                                        uc = str_decode(fmt, &nxt, STR_NO_LIMIT);
     
    575575                                }
    576576                        }
    577                        
     577
    578578                        /* Precision and '*' operator */
    579579                        int precision = 0;
     
    585585                                                precision *= 10;
    586586                                                precision += uc - '0';
    587                                                
     587
    588588                                                i = nxt;
    589589                                                uc = str_decode(fmt, &nxt, STR_NO_LIMIT);
     
    604604                                }
    605605                        }
    606                        
     606
    607607                        qualifier_t qualifier;
    608                        
     608
    609609                        switch (uc) {
    610610                        case 't':
     
    653653                                qualifier = PrintfQualifierInt;
    654654                        }
    655                        
     655
    656656                        unsigned int base = 10;
    657                        
     657
    658658                        switch (uc) {
    659659                        /*
     
    662662                        case 's':
    663663                                retval = print_str(va_arg(ap, char *), width, precision, flags, ps);
    664                                
     664
    665665                                if (retval < 0) {
    666666                                        counter = -counter;
    667667                                        goto out;
    668668                                }
    669                                
     669
    670670                                counter += retval;
    671671                                j = nxt;
     
    673673                        case 'c':
    674674                                retval = print_char(va_arg(ap, unsigned int), width, flags, ps);
    675                                
     675
    676676                                if (retval < 0) {
    677677                                        counter = -counter;
    678678                                        goto out;
    679679                                };
    680                                
     680
    681681                                counter += retval;
    682682                                j = nxt;
    683683                                goto next_char;
    684                        
     684
    685685                        /*
    686686                         * Integer values
     
    714714                                base = 16;
    715715                                break;
    716                        
     716
    717717                        /* Percentile itself */
    718718                        case '%':
    719719                                j = i;
    720720                                goto next_char;
    721                        
     721
    722722                        /*
    723723                         * Bad formatting.
     
    730730                                goto next_char;
    731731                        }
    732                        
     732
    733733                        /* Print integers */
    734734                        size_t size;
    735735                        uint64_t number;
    736                        
     736
    737737                        switch (qualifier) {
    738738                        case PrintfQualifierByte:
     
    774774                                goto out;
    775775                        }
    776                        
     776
    777777                        if ((retval = print_number(number, width, precision,
    778778                            base, flags, ps)) < 0) {
     
    780780                                goto out;
    781781                        }
    782                        
     782
    783783                        counter += retval;
    784784                        j = nxt;
     
    787787                ;
    788788        }
    789        
     789
    790790        if (i > j) {
    791791                if ((retval = printf_putnchars(&fmt[j], i - j, ps)) < 0) {
     
    796796                counter += retval;
    797797        }
    798        
     798
    799799out:
    800800        return ((int) counter);
Note: See TracChangeset for help on using the changeset viewer.