Changeset 1b0b48e0 in mainline


Ignore:
Timestamp:
2009-04-01T19:01:39Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
06b785f
Parents:
f25b2819
Message:

Partial refactor of printf modules to reflect new string API.

Location:
kernel/generic/src/printf
Files:
3 edited

Legend:

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

    rf25b2819 r1b0b48e0  
    253253        if (str == NULL)
    254254                return printf_putstr(nullstr, ps);
    255        
    256         /* Print leading spaces */
    257         size_t size = str_length(str);
     255
     256        /* Print leading spaces. */
     257        count_t strw = str_length(str);
    258258        if (precision == 0)
    259                 precision = size;
     259                precision = strw;
    260260
    261261        count_t counter = 0;
     
    269269
    270270        int retval;
    271         size_t bytes = str_lsize(str, min(size, precision));
    272         if ((retval = printf_putnchars_utf8(str, bytes, ps)) < 0)
     271        size_t size = str_lsize(str, precision);
     272        if ((retval = printf_putnchars_utf8(str, size, ps)) < 0)
    273273                return -counter;
    274        
     274
    275275        counter += retval;
    276        
     276
    277277        while (width-- > 0) {
    278278                if (printf_putchar(' ', ps) == 1)
     
    281281
    282282        return ((int) counter);
     283
    283284}
    284285
     
    292293 * @return Number of UTF-32 characters printed, negative value on failure.
    293294 */
    294 static int print_utf32(wchar_t *str, int width, unsigned int precision,
     295static int print_utf32(wchar_t *wstr, int width, unsigned int precision,
    295296        uint32_t flags, printf_spec_t *ps)
    296297{
    297         if (str == NULL)
     298        if (wstr == NULL)
    298299                return printf_putstr(nullstr, ps);
    299        
    300         /* Print leading spaces */
    301         size_t size = wstr_length(str);
     300
     301        /* Print leading spaces. */
     302        size_t strw = wstr_length(wstr);
    302303        if (precision == 0)
    303                 precision = size;
    304        
     304                precision = strw;
     305
    305306        count_t counter = 0;
    306307        width -= precision;
     
    311312                }
    312313        }
    313        
     314
    314315        int retval;
    315         size_t bytes = min(size, precision) * sizeof(wchar_t);
    316         if ((retval = printf_putnchars_utf32(str, bytes, ps)) < 0)
     316        size_t size = min(strw, precision) * sizeof(wchar_t);
     317        if ((retval = printf_putnchars_utf32(wstr, size, ps)) < 0)
    317318                return -counter;
    318        
     319
    319320        counter += retval;
    320        
     321
    321322        while (width-- > 0) {
    322323                if (printf_putchar(' ', ps) == 1)
    323324                        counter++;
    324325        }
    325        
     326
    326327        return ((int) counter);
    327328}
     
    585586int printf_core(const char *fmt, printf_spec_t *ps, va_list ap)
    586587{
    587         index_t i = 0;  /* Index of the currently processed character from fmt */
    588         index_t nxt = 0;
    589         index_t j = 0;  /* Index to the first not printed nonformating character */
     588        size_t i = 0;  /* Index of the currently processed character from fmt */
     589        size_t nxt = 0;
     590        size_t j = 0;  /* Index to the first not printed nonformating character */
    590591       
    591592        wchar_t uc;           /* Current UTF-32 character decoded from fmt */
  • kernel/generic/src/printf/vprintf.c

    rf25b2819 r1b0b48e0  
    4646static int vprintf_write_utf8(const char *str, size_t size, void *data)
    4747{
    48         index_t index = 0;
    49         index_t chars = 0;
    50        
    51         while (index < size) {
    52                 putchar(chr_decode(str, &index, size));
     48        size_t offset = 0;
     49        count_t chars = 0;
     50
     51        while (offset < size) {
     52                putchar(chr_decode(str, &offset, size));
    5353                chars++;
    5454        }
    55        
     55
    5656        return chars;
    5757}
     
    6060{
    6161        index_t index = 0;
    62        
     62
    6363        while (index < (size / sizeof(wchar_t))) {
    6464                putchar(str[index]);
    6565                index++;
    6666        }
    67        
     67
    6868        return index;
    6969}
     
    7171int puts(const char *str)
    7272{
    73         index_t index = 0;
    74         index_t chars = 0;
     73        size_t offset = 0;
     74        count_t chars = 0;
    7575        wchar_t uc;
    76        
    77         while ((uc = chr_decode(str, &index, UTF8_NO_LIMIT)) != 0) {
     76
     77        while ((uc = chr_decode(str, &offset, UTF8_NO_LIMIT)) != 0) {
    7878                putchar(uc);
    7979                chars++;
    8080        }
    81        
     81
    8282        return chars;
    8383}
     
    9090                NULL
    9191        };
    92        
     92
    9393        ipl_t ipl = interrupts_disable();
    9494        spinlock_lock(&printf_lock);
    95        
     95
    9696        int ret = printf_core(fmt, &ps, ap);
    97        
     97
    9898        spinlock_unlock(&printf_lock);
    9999        interrupts_restore(ipl);
    100        
     100
    101101        return ret;
    102102}
  • kernel/generic/src/printf/vsnprintf.c

    rf25b2819 r1b0b48e0  
    7878       
    7979        if (left <= size) {
    80                 /* We have not enought space for whole string
     80                /* We do not have enough space for the whole string
    8181                 * with the trailing zero => print only a part
    8282                 * of string
Note: See TracChangeset for help on using the changeset viewer.