Changeset a35b458 in mainline for kernel/generic/src/printf/printf_core.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/printf/printf_core.c
r3061bc1 ra35b458 157 157 if (str == NULL) 158 158 return printf_putnchars(nullstr, str_size(nullstr), ps); 159 159 160 160 return ps->str_write((void *) str, str_size(str), ps->data); 161 161 } … … 173 173 if (!ascii_check(ch)) 174 174 return ps->str_write((void *) &invalch, 1, ps->data); 175 175 176 176 return ps->str_write(&ch, 1, ps->data); 177 177 } … … 189 189 if (!chr_check(ch)) 190 190 return ps->str_write((void *) &invalch, 1, ps->data); 191 191 192 192 return ps->wstr_write(&ch, sizeof(wchar_t), ps->data); 193 193 } … … 215 215 } 216 216 } 217 217 218 218 if (printf_putchar(ch, ps) > 0) 219 219 counter++; 220 220 221 221 while (--width > 0) { 222 222 /* … … 227 227 counter++; 228 228 } 229 229 230 230 return (int) (counter); 231 231 } … … 253 253 } 254 254 } 255 255 256 256 if (printf_putwchar(ch, ps) > 0) 257 257 counter++; 258 258 259 259 while (--width > 0) { 260 260 /* … … 265 265 counter++; 266 266 } 267 267 268 268 return (int) (counter); 269 269 } … … 283 283 if (str == NULL) 284 284 return printf_putstr(nullstr, ps); 285 285 286 286 /* Print leading spaces. */ 287 287 size_t strw = str_length(str); 288 288 if ((precision == 0) || (precision > strw)) 289 289 precision = strw; 290 290 291 291 /* Left padding */ 292 292 size_t counter = 0; … … 298 298 } 299 299 } 300 300 301 301 /* Part of @a str fitting into the alloted space. */ 302 302 int retval; … … 331 331 if (str == NULL) 332 332 return printf_putstr(nullstr, ps); 333 333 334 334 /* Print leading spaces. */ 335 335 size_t strw = wstr_length(str); 336 336 if ((precision == 0) || (precision > strw)) 337 337 precision = strw; 338 338 339 339 /* Left padding */ 340 340 size_t counter = 0; … … 346 346 } 347 347 } 348 348 349 349 /* Part of @a wstr fitting into the alloted space. */ 350 350 int retval; … … 352 352 if ((retval = printf_wputnchars(str, size, ps)) < 0) 353 353 return -counter; 354 354 355 355 counter += retval; 356 356 357 357 /* Right padding */ 358 358 while (width-- > 0) { … … 385 385 else 386 386 digits = digits_small; 387 387 388 388 char data[PRINT_NUMBER_BUFFER_SIZE]; 389 389 char *ptr = &data[PRINT_NUMBER_BUFFER_SIZE - 1]; 390 390 391 391 /* Size of number with all prefixes and signs */ 392 392 int size = 0; 393 393 394 394 /* Put zero at end of string */ 395 395 *ptr-- = 0; 396 396 397 397 if (num == 0) { 398 398 *ptr-- = '0'; … … 404 404 } while (num /= base); 405 405 } 406 406 407 407 /* Size of plain number */ 408 408 int number_size = size; 409 409 410 410 /* 411 411 * Collect the sum of all prefixes/signs/etc. to calculate padding and … … 426 426 } 427 427 } 428 428 429 429 char sgn = 0; 430 430 if (flags & __PRINTF_FLAG_SIGNED) { … … 440 440 } 441 441 } 442 442 443 443 if (flags & __PRINTF_FLAG_LEFTALIGNED) 444 444 flags &= ~__PRINTF_FLAG_ZEROPADDED; 445 445 446 446 /* 447 447 * If the number is left-aligned or precision is specified then … … 452 452 precision = width - size + number_size; 453 453 } 454 454 455 455 /* Print leading spaces */ 456 456 if (number_size > precision) { … … 458 458 precision = number_size; 459 459 } 460 460 461 461 width -= precision + size - number_size; 462 462 size_t counter = 0; 463 463 464 464 if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) { 465 465 while (width-- > 0) { … … 468 468 } 469 469 } 470 470 471 471 /* Print sign */ 472 472 if (sgn) { … … 474 474 counter++; 475 475 } 476 476 477 477 /* Print prefix */ 478 478 if (flags & __PRINTF_FLAG_PREFIX) { … … 507 507 } 508 508 } 509 509 510 510 /* Print leading zeroes */ 511 511 precision -= number_size; … … 514 514 counter++; 515 515 } 516 516 517 517 /* Print the number itself */ 518 518 int retval; 519 519 if ((retval = printf_putstr(++ptr, ps)) > 0) 520 520 counter += retval; 521 521 522 522 /* Print trailing spaces */ 523 523 524 524 while (width-- > 0) { 525 525 if (printf_putchar(' ', ps) == 1) 526 526 counter++; 527 527 } 528 528 529 529 return ((int) counter); 530 530 } … … 624 624 size_t nxt = 0; /* Index of the next character from fmt */ 625 625 size_t j = 0; /* Index to the first not printed nonformating character */ 626 626 627 627 size_t counter = 0; /* Number of characters printed */ 628 628 int retval; /* Return values from nested functions */ 629 629 630 630 while (true) { 631 631 i = nxt; 632 632 wchar_t uc = str_decode(fmt, &nxt, STR_NO_LIMIT); 633 633 634 634 if (uc == 0) 635 635 break; 636 636 637 637 /* Control character */ 638 638 if (uc == '%') { … … 646 646 counter += retval; 647 647 } 648 648 649 649 j = i; 650 650 651 651 /* Parse modifiers */ 652 652 uint32_t flags = 0; 653 653 bool end = false; 654 654 655 655 do { 656 656 i = nxt; … … 676 676 }; 677 677 } while (!end); 678 678 679 679 /* Width & '*' operator */ 680 680 int width = 0; … … 683 683 width *= 10; 684 684 width += uc - '0'; 685 685 686 686 i = nxt; 687 687 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); … … 702 702 } 703 703 } 704 704 705 705 /* Precision and '*' operator */ 706 706 int precision = 0; … … 712 712 precision *= 10; 713 713 precision += uc - '0'; 714 714 715 715 i = nxt; 716 716 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); … … 731 731 } 732 732 } 733 733 734 734 qualifier_t qualifier; 735 735 736 736 switch (uc) { 737 737 case 't': … … 780 780 qualifier = PrintfQualifierInt; 781 781 } 782 782 783 783 unsigned int base = 10; 784 784 785 785 switch (uc) { 786 786 /* … … 792 792 else 793 793 retval = print_str(va_arg(ap, char *), width, precision, flags, ps); 794 794 795 795 if (retval < 0) { 796 796 counter = -counter; 797 797 goto out; 798 798 } 799 799 800 800 counter += retval; 801 801 j = nxt; … … 806 806 else 807 807 retval = print_char(va_arg(ap, unsigned int), width, flags, ps); 808 808 809 809 if (retval < 0) { 810 810 counter = -counter; 811 811 goto out; 812 812 }; 813 813 814 814 counter += retval; 815 815 j = nxt; 816 816 goto next_char; 817 817 818 818 /* 819 819 * Integer values … … 847 847 base = 16; 848 848 break; 849 849 850 850 /* Percentile itself */ 851 851 case '%': 852 852 j = i; 853 853 goto next_char; 854 854 855 855 /* 856 856 * Bad formatting. … … 863 863 goto next_char; 864 864 } 865 865 866 866 /* Print integers */ 867 867 size_t size; 868 868 uint64_t number; 869 869 870 870 switch (qualifier) { 871 871 case PrintfQualifierByte: … … 907 907 goto out; 908 908 } 909 909 910 910 if ((retval = print_number(number, width, precision, 911 911 base, flags, ps)) < 0) { … … 913 913 goto out; 914 914 } 915 915 916 916 counter += retval; 917 917 j = nxt; … … 920 920 ; 921 921 } 922 922 923 923 if (i > j) { 924 924 if ((retval = printf_putnchars(&fmt[j], i - j, ps)) < 0) { … … 929 929 counter += retval; 930 930 } 931 931 932 932 out: 933 933 return ((int) counter);
Note:
See TracChangeset
for help on using the changeset viewer.