Changeset 043eca0 in mainline for kernel/generic/src/printf/printf_core.c
- Timestamp:
- 2009-04-03T07:54:27Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d1dabe1f
- Parents:
- b888d5f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/printf/printf_core.c
rb888d5f r043eca0 83 83 static char digits_big[] = "0123456789ABCDEF"; 84 84 85 /** Print one or more UTF-8characters without adding newline.86 * 87 * @param buf Buffer holding UTF-8characters with size of85 /** Print one or more characters without adding newline. 86 * 87 * @param buf Buffer holding characters with size of 88 88 * at least size bytes. NULL is not allowed! 89 89 * @param size Size of the buffer in bytes. 90 90 * @param ps Output method and its data. 91 91 * 92 * @return Number of UTF-8characters printed.93 * 94 */ 95 static int printf_putnchars _utf8(const char *buf, size_t size,92 * @return Number of characters printed. 93 * 94 */ 95 static int printf_putnchars(const char *buf, size_t size, 96 96 printf_spec_t *ps) 97 97 { 98 return ps-> write_utf8((void *) buf, size, ps->data);99 } 100 101 /** Print one or more UTF-32characters without adding newline.102 * 103 * @param buf Buffer holding UTF-32characters with size of98 return ps->str_write((void *) buf, size, ps->data); 99 } 100 101 /** Print one or more wide characters without adding newline. 102 * 103 * @param buf Buffer holding wide characters with size of 104 104 * at least size bytes. NULL is not allowed! 105 105 * @param size Size of the buffer in bytes. 106 106 * @param ps Output method and its data. 107 107 * 108 * @return Number of UTF-32characters printed.109 * 110 */ 111 static int printf_ putnchars_utf32(const wchar_t *buf, size_t size,108 * @return Number of wide characters printed. 109 * 110 */ 111 static int printf_wputnchars(const wchar_t *buf, size_t size, 112 112 printf_spec_t *ps) 113 113 { 114 return ps->w rite_utf32((void *) buf, size, ps->data);115 } 116 117 /** Print string without adding newline.118 * 119 * @param str 120 * @param ps 114 return ps->wstr_write((void *) buf, size, ps->data); 115 } 116 117 /** Print string without adding a newline. 118 * 119 * @param str String to print. 120 * @param ps Write function specification and support data. 121 121 * 122 122 * @return Number of characters printed. … … 126 126 { 127 127 if (str == NULL) 128 return printf_putnchars _utf8(nullstr, str_size(nullstr), ps);129 130 return ps-> write_utf8((void *) str, str_size(str), ps->data);128 return printf_putnchars(nullstr, str_size(nullstr), ps); 129 130 return ps->str_write((void *) str, str_size(str), ps->data); 131 131 } 132 132 … … 142 142 { 143 143 if (!ascii_check(ch)) 144 return ps-> write_utf8((void *) &invalch, 1, ps->data);145 146 return ps-> write_utf8(&ch, 1, ps->data);147 } 148 149 /** Print one UTF-32character.150 * 151 * @param c UTF-32character to be printed.144 return ps->str_write((void *) &invalch, 1, ps->data); 145 146 return ps->str_write(&ch, 1, ps->data); 147 } 148 149 /** Print one wide character. 150 * 151 * @param c Wide character to be printed. 152 152 * @param ps Output method. 153 153 * … … 157 157 static int printf_putwchar(const wchar_t ch, printf_spec_t *ps) 158 158 { 159 if (! unicode_check(ch))160 return ps-> write_utf8((void *) &invalch, 1, ps->data);161 162 return ps->w rite_utf32(&ch, sizeof(wchar_t), ps->data);159 if (!chr_check(ch)) 160 return ps->str_write((void *) &invalch, 1, ps->data); 161 162 return ps->wstr_write(&ch, sizeof(wchar_t), ps->data); 163 163 } 164 164 … … 201 201 } 202 202 203 /** Print one formatted UTF-32character.203 /** Print one formatted wide character. 204 204 * 205 205 * @param ch Character to print. … … 239 239 } 240 240 241 /** Format and print astring.241 /** Print string. 242 242 * 243 243 * @param str String to be printed. … … 271 271 /* Part of @a str fitting into the alloted space. */ 272 272 int retval; 273 size_t size = str_ wsize(str, precision);274 if ((retval = printf_putnchars _utf8(str, size, ps)) < 0)273 size_t size = str_lsize(str, precision); 274 if ((retval = printf_putnchars(str, size, ps)) < 0) 275 275 return -counter; 276 276 … … 287 287 } 288 288 289 /** Format and print a wide string. 290 * 291 * @param wstr Wide string to be printed. 292 * @param width Width modifier. 293 * @param precision Precision modifier. 294 * @param flags Flags that modify the way the string is printed. 295 * 296 * @return Number of characters printed, negative value 297 * on failure. 298 */ 299 static int print_wstr(wchar_t *wstr, int width, unsigned int precision, 289 /** Print wide string. 290 * 291 * @param str Wide string to be printed. 292 * @param width Width modifier. 293 * @param precision Precision modifier. 294 * @param flags Flags that modify the way the string is printed. 295 * 296 * @return Number of wide characters printed, negative value on failure. 297 */ 298 static int print_wstr(wchar_t *str, int width, unsigned int precision, 300 299 uint32_t flags, printf_spec_t *ps) 301 300 { 302 if ( wstr == NULL)301 if (str == NULL) 303 302 return printf_putstr(nullstr, ps); 304 303 305 304 /* Print leading spaces. */ 306 size_t strw = wstr_length( wstr);305 size_t strw = wstr_length(str); 307 306 if (precision == 0) 308 307 precision = strw; … … 320 319 /* Part of @a wstr fitting into the alloted space. */ 321 320 int retval; 322 size_t size = wstr_ wlength(wstr, precision) * sizeof(wchar_t);323 if ((retval = printf_ putnchars_utf32(wstr, size, ps)) < 0)321 size_t size = wstr_lsize(str, precision); 322 if ((retval = printf_wputnchars(str, size, ps)) < 0) 324 323 return -counter; 325 324 … … 424 423 } 425 424 426 /* Print leading spaces .*/425 /* Print leading spaces */ 427 426 if (number_size > precision) { 428 /* Print the whole number, not only a part .*/427 /* Print the whole number, not only a part */ 429 428 precision = number_size; 430 429 } … … 440 439 } 441 440 442 /* Print sign .*/441 /* Print sign */ 443 442 if (sgn) { 444 443 if (printf_putchar(sgn, ps) == 1) … … 446 445 } 447 446 448 /* Print prefix .*/447 /* Print prefix */ 449 448 if (flags & __PRINTF_FLAG_PREFIX) { 450 449 switch(base) { … … 479 478 } 480 479 481 /* Print leading zeroes .*/480 /* Print leading zeroes */ 482 481 precision -= number_size; 483 482 while (precision-- > 0) { … … 486 485 } 487 486 488 /* Print the number itself .*/487 /* Print the number itself */ 489 488 int retval; 490 489 if ((retval = printf_putstr(++ptr, ps)) > 0) 491 490 counter += retval; 492 491 493 /* Print tailing spaces .*/492 /* Print tailing spaces */ 494 493 495 494 while (width-- > 0) { … … 546 545 * - "" Signed or unsigned int (default value).@n 547 546 * - "l" Signed or unsigned long int.@n 548 * If conversion is "c", the character is wchar_t ( UTF-32).@n549 * If conversion is "s", the string is wchar_t * ( UTF-32).@n547 * If conversion is "c", the character is wchar_t (wide character).@n 548 * If conversion is "s", the string is wchar_t * (wide string).@n 550 549 * - "ll" Signed or unsigned long long int.@n 551 550 * … … 555 554 * - c Print single character. The character is expected to be plain 556 555 * ASCII (e.g. only values 0 .. 127 are valid).@n 557 * If type is "l", then the character is expected to be UTF-32556 * If type is "l", then the character is expected to be wide character 558 557 * (e.g. values 0 .. 0x10ffff are valid). 559 558 * 560 559 * - s Print zero terminated string. If a NULL value is passed as 561 560 * value, "(NULL)" is printed instead.@n 562 * The string is expected to be correctly encoded UTF-8 (or plain 563 * ASCII, which is a subset of UTF-8).@n 564 * If type is "l", then the string is expected to be correctly 565 * encoded UTF-32. 561 * If type is "l", then the string is expected to be wide string. 566 562 * 567 563 * - P, p Print value of a pointer. Void * value is expected and it is … … 586 582 * verbatim. 587 583 * 588 * @param fmt Format string. 584 * @param fmt Format NULL-terminated string. 585 * 589 586 * @return Number of characters printed, negative value on failure. 590 587 * … … 592 589 int printf_core(const char *fmt, printf_spec_t *ps, va_list ap) 593 590 { 594 size_t i = 0; /* Index of the currently processed character from fmt */ 595 size_t nxt = 0; 596 size_t j = 0; /* Index to the first not printed nonformating character */ 597 598 wchar_t uc; /* Current character decoded from fmt */ 591 size_t i; /* Index of the currently processed character from fmt */ 592 size_t nxt = 0; /* Index of the next character from fmt */ 593 size_t j = 0; /* Index to the first not printed nonformating character */ 594 599 595 count_t counter = 0; /* Number of characters printed */ 600 596 int retval; /* Return values from nested functions */ … … 602 598 while (true) { 603 599 i = nxt; 604 uc = chr_decode(fmt, &nxt, UTF8_NO_LIMIT); 605 606 if (uc == '\0') break; 607 600 wchar_t uc = str_decode(fmt, &nxt, STR_NO_LIMIT); 601 602 if (uc == 0) 603 break; 604 608 605 /* Control character */ 609 606 if (uc == '%') { 610 607 /* Print common characters if any processed */ 611 608 if (i > j) { 612 if ((retval = printf_putnchars _utf8(&fmt[j], i - j, ps)) < 0) {609 if ((retval = printf_putnchars(&fmt[j], i - j, ps)) < 0) { 613 610 /* Error */ 614 611 counter = -counter; … … 626 623 do { 627 624 i = nxt; 628 uc = chr_decode(fmt, &nxt, UTF8_NO_LIMIT);625 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); 629 626 switch (uc) { 630 627 case '#': … … 654 651 width *= 10; 655 652 width += uc - '0'; 656 653 657 654 i = nxt; 658 uc = chr_decode(fmt, &nxt, UTF8_NO_LIMIT);659 if (uc == '\0')655 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); 656 if (uc == 0) 660 657 break; 661 658 if (!isdigit(uc)) … … 665 662 /* Get width value from argument list */ 666 663 i = nxt; 667 uc = chr_decode(fmt, &nxt, UTF8_NO_LIMIT);664 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); 668 665 width = (int) va_arg(ap, int); 669 666 if (width < 0) { … … 678 675 if (uc == '.') { 679 676 i = nxt; 680 uc = chr_decode(fmt, &nxt, UTF8_NO_LIMIT);677 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); 681 678 if (isdigit(uc)) { 682 679 while (true) { 683 680 precision *= 10; 684 681 precision += uc - '0'; 685 682 686 683 i = nxt; 687 uc = chr_decode(fmt, &nxt, UTF8_NO_LIMIT);688 if (uc == '\0')684 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); 685 if (uc == 0) 689 686 break; 690 687 if (!isdigit(uc)) … … 694 691 /* Get precision value from the argument list */ 695 692 i = nxt; 696 uc = chr_decode(fmt, &nxt, UTF8_NO_LIMIT);693 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); 697 694 precision = (int) va_arg(ap, int); 698 695 if (precision < 0) { … … 713 710 qualifier = PrintfQualifierShort; 714 711 i = nxt; 715 uc = chr_decode(fmt, &nxt, UTF8_NO_LIMIT);712 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); 716 713 if (uc == 'h') { 717 714 i = nxt; 718 uc = chr_decode(fmt, &nxt, UTF8_NO_LIMIT);715 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); 719 716 qualifier = PrintfQualifierByte; 720 717 } … … 724 721 qualifier = PrintfQualifierLong; 725 722 i = nxt; 726 uc = chr_decode(fmt, &nxt, UTF8_NO_LIMIT);723 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); 727 724 if (uc == 'l') { 728 725 i = nxt; 729 uc = chr_decode(fmt, &nxt, UTF8_NO_LIMIT);726 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); 730 727 qualifier = PrintfQualifierLongLong; 731 728 } … … 879 876 880 877 if (i > j) { 881 if ((retval = printf_putnchars _utf8(&fmt[j], i - j, ps)) < 0) {878 if ((retval = printf_putnchars(&fmt[j], i - j, ps)) < 0) { 882 879 /* Error */ 883 880 counter = -counter;
Note:
See TracChangeset
for help on using the changeset viewer.