Changeset a35b458 in mainline for boot/generic/src/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
-
boot/generic/src/printf_core.c
r3061bc1 ra35b458 138 138 if (str == NULL) 139 139 return printf_putnchars(nullstr, str_size(nullstr), ps); 140 140 141 141 return ps->str_write((void *) str, str_size(str), ps->data); 142 142 } … … 154 154 if (!ascii_check(ch)) 155 155 return ps->str_write((void *) &invalch, 1, ps->data); 156 156 157 157 return ps->str_write(&ch, 1, ps->data); 158 158 } … … 180 180 } 181 181 } 182 182 183 183 if (printf_putchar(ch, ps) > 0) 184 184 counter++; 185 185 186 186 while (--width > 0) { 187 187 /* … … 192 192 counter++; 193 193 } 194 194 195 195 return (int) (counter); 196 196 } … … 210 210 if (str == NULL) 211 211 return printf_putstr(nullstr, ps); 212 212 213 213 /* Print leading spaces. */ 214 214 size_t strw = str_length(str); 215 215 if ((precision == 0) || (precision > strw)) 216 216 precision = strw; 217 217 218 218 /* Left padding */ 219 219 size_t counter = 0; … … 225 225 } 226 226 } 227 227 228 228 /* Part of @a str fitting into the alloted space. */ 229 229 int retval; … … 231 231 if ((retval = printf_putnchars(str, size, ps)) < 0) 232 232 return -counter; 233 233 234 234 counter += retval; 235 235 236 236 /* Right padding */ 237 237 while (width-- > 0) { … … 264 264 else 265 265 digits = digits_small; 266 266 267 267 char data[PRINT_NUMBER_BUFFER_SIZE]; 268 268 char *ptr = &data[PRINT_NUMBER_BUFFER_SIZE - 1]; 269 269 270 270 /* Size of number with all prefixes and signs */ 271 271 int size = 0; 272 272 273 273 /* Put zero at end of string */ 274 274 *ptr-- = 0; 275 275 276 276 if (num == 0) { 277 277 *ptr-- = '0'; … … 283 283 } while (num /= base); 284 284 } 285 285 286 286 /* Size of plain number */ 287 287 int number_size = size; 288 288 289 289 /* 290 290 * Collect the sum of all prefixes/signs/etc. to calculate padding and … … 305 305 } 306 306 } 307 307 308 308 char sgn = 0; 309 309 if (flags & __PRINTF_FLAG_SIGNED) { … … 319 319 } 320 320 } 321 321 322 322 if (flags & __PRINTF_FLAG_LEFTALIGNED) 323 323 flags &= ~__PRINTF_FLAG_ZEROPADDED; 324 324 325 325 /* 326 326 * If the number is left-aligned or precision is specified then … … 331 331 precision = width - size + number_size; 332 332 } 333 333 334 334 /* Print leading spaces */ 335 335 if (number_size > precision) { … … 337 337 precision = number_size; 338 338 } 339 339 340 340 width -= precision + size - number_size; 341 341 size_t counter = 0; 342 342 343 343 if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) { 344 344 while (width-- > 0) { … … 347 347 } 348 348 } 349 349 350 350 /* Print sign */ 351 351 if (sgn) { … … 353 353 counter++; 354 354 } 355 355 356 356 /* Print prefix */ 357 357 if (flags & __PRINTF_FLAG_PREFIX) { … … 386 386 } 387 387 } 388 388 389 389 /* Print leading zeroes */ 390 390 precision -= number_size; … … 393 393 counter++; 394 394 } 395 395 396 396 /* Print the number itself */ 397 397 int retval; 398 398 if ((retval = printf_putstr(++ptr, ps)) > 0) 399 399 counter += retval; 400 400 401 401 /* Print trailing spaces */ 402 402 403 403 while (width-- > 0) { 404 404 if (printf_putchar(' ', ps) == 1) 405 405 counter++; 406 406 } 407 407 408 408 return ((int) counter); 409 409 } … … 497 497 size_t nxt = 0; /* Index of the next character from fmt */ 498 498 size_t j = 0; /* Index to the first not printed nonformating character */ 499 499 500 500 size_t counter = 0; /* Number of characters printed */ 501 501 int retval; /* Return values from nested functions */ 502 502 503 503 while (true) { 504 504 i = nxt; 505 505 wchar_t uc = str_decode(fmt, &nxt, STR_NO_LIMIT); 506 506 507 507 if (uc == 0) 508 508 break; 509 509 510 510 /* Control character */ 511 511 if (uc == '%') { … … 519 519 counter += retval; 520 520 } 521 521 522 522 j = i; 523 523 524 524 /* Parse modifiers */ 525 525 uint32_t flags = 0; 526 526 bool end = false; 527 527 528 528 do { 529 529 i = nxt; … … 549 549 }; 550 550 } while (!end); 551 551 552 552 /* Width & '*' operator */ 553 553 int width = 0; … … 556 556 width *= 10; 557 557 width += uc - '0'; 558 558 559 559 i = nxt; 560 560 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); … … 575 575 } 576 576 } 577 577 578 578 /* Precision and '*' operator */ 579 579 int precision = 0; … … 585 585 precision *= 10; 586 586 precision += uc - '0'; 587 587 588 588 i = nxt; 589 589 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); … … 604 604 } 605 605 } 606 606 607 607 qualifier_t qualifier; 608 608 609 609 switch (uc) { 610 610 case 't': … … 653 653 qualifier = PrintfQualifierInt; 654 654 } 655 655 656 656 unsigned int base = 10; 657 657 658 658 switch (uc) { 659 659 /* … … 662 662 case 's': 663 663 retval = print_str(va_arg(ap, char *), width, precision, flags, ps); 664 664 665 665 if (retval < 0) { 666 666 counter = -counter; 667 667 goto out; 668 668 } 669 669 670 670 counter += retval; 671 671 j = nxt; … … 673 673 case 'c': 674 674 retval = print_char(va_arg(ap, unsigned int), width, flags, ps); 675 675 676 676 if (retval < 0) { 677 677 counter = -counter; 678 678 goto out; 679 679 }; 680 680 681 681 counter += retval; 682 682 j = nxt; 683 683 goto next_char; 684 684 685 685 /* 686 686 * Integer values … … 714 714 base = 16; 715 715 break; 716 716 717 717 /* Percentile itself */ 718 718 case '%': 719 719 j = i; 720 720 goto next_char; 721 721 722 722 /* 723 723 * Bad formatting. … … 730 730 goto next_char; 731 731 } 732 732 733 733 /* Print integers */ 734 734 size_t size; 735 735 uint64_t number; 736 736 737 737 switch (qualifier) { 738 738 case PrintfQualifierByte: … … 774 774 goto out; 775 775 } 776 776 777 777 if ((retval = print_number(number, width, precision, 778 778 base, flags, ps)) < 0) { … … 780 780 goto out; 781 781 } 782 782 783 783 counter += retval; 784 784 j = nxt; … … 787 787 ; 788 788 } 789 789 790 790 if (i > j) { 791 791 if ((retval = printf_putnchars(&fmt[j], i - j, ps)) < 0) { … … 796 796 counter += retval; 797 797 } 798 798 799 799 out: 800 800 return ((int) counter);
Note:
See TracChangeset
for help on using the changeset viewer.