Changeset d7baee6 in mainline for uspace/libc/generic/io/printf_core.c
- Timestamp:
- 2007-01-17T13:03:08Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- df4ed85
- Parents:
- c738d65
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/libc/generic/io/printf_core.c
rc738d65 rd7baee6 246 246 if (flags & __PRINTF_FLAG_PREFIX) { 247 247 switch(base) { 248 249 250 251 252 253 254 255 256 248 case 2: /* Binary formating is not standard, but usefull */ 249 size += 2; 250 break; 251 case 8: 252 size++; 253 break; 254 case 16: 255 size += 2; 256 break; 257 257 } 258 258 } … … 306 306 if (flags & __PRINTF_FLAG_PREFIX) { 307 307 switch(base) { 308 case 2: /* Binary formating is not standard, but usefull */ 309 if (printf_putchar('0', ps) == 1) 308 case 2: /* Binary formating is not standard, but usefull */ 309 if (printf_putchar('0', ps) == 1) 310 counter++; 311 if (flags & __PRINTF_FLAG_BIGCHARS) { 312 if (printf_putchar('B', ps) == 1) 310 313 counter++; 311 if (flags & __PRINTF_FLAG_BIGCHARS) { 312 if (printf_putchar('B', ps) == 1) 313 counter++; 314 } else { 315 if (printf_putchar('b', ps) == 1) 316 counter++; 317 } 318 break; 319 case 8: 320 if (printf_putchar('o', ps) == 1) 314 } else { 315 if (printf_putchar('b', ps) == 1) 321 316 counter++; 322 break; 323 case 16: 324 if (printf_putchar('0', ps) == 1) 317 } 318 break; 319 case 8: 320 if (printf_putchar('o', ps) == 1) 321 counter++; 322 break; 323 case 16: 324 if (printf_putchar('0', ps) == 1) 325 counter++; 326 if (flags & __PRINTF_FLAG_BIGCHARS) { 327 if (printf_putchar('X', ps) == 1) 325 328 counter++; 326 if (flags & __PRINTF_FLAG_BIGCHARS) { 327 if (printf_putchar('X', ps) == 1) 328 counter++; 329 } else { 330 if (printf_putchar('x', ps) == 1) 331 counter++; 332 } 333 break; 329 } else { 330 if (printf_putchar('x', ps) == 1) 331 counter++; 332 } 333 break; 334 334 } 335 335 } … … 472 472 ++i; 473 473 switch (c = fmt[i]) { 474 475 476 477 478 479 474 case '#': flags |= __PRINTF_FLAG_PREFIX; break; 475 case '-': flags |= __PRINTF_FLAG_LEFTALIGNED; break; 476 case '+': flags |= __PRINTF_FLAG_SHOWPLUS; break; 477 case ' ': flags |= __PRINTF_FLAG_SPACESIGN; break; 478 case '0': flags |= __PRINTF_FLAG_ZEROPADDED; break; 479 default: end = 1; 480 480 }; 481 481 … … 521 521 522 522 switch (fmt[i++]) { 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 523 /** TODO: unimplemented qualifiers: 524 * t ptrdiff_t - ISO C 99 525 */ 526 case 'h': /* char or short */ 527 qualifier = PrintfQualifierShort; 528 if (fmt[i] == 'h') { 529 i++; 530 qualifier = PrintfQualifierByte; 531 } 532 break; 533 case 'l': /* long or long long*/ 534 qualifier = PrintfQualifierLong; 535 if (fmt[i] == 'l') { 536 i++; 537 qualifier = PrintfQualifierLongLong; 538 } 539 break; 540 case 'z': /* size_t */ 541 qualifier = PrintfQualifierSizeT; 542 break; 543 default: 544 qualifier = PrintfQualifierInt; /* default type */ 545 --i; 546 546 } 547 547 … … 553 553 * String and character conversions. 554 554 */ 555 556 557 558 };555 case 's': 556 if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) < 0) { 557 goto minus_out; 558 } 559 559 560 561 562 563 564 565 566 567 };568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 560 counter += retval; 561 j = i + 1; 562 goto next_char; 563 case 'c': 564 c = va_arg(ap, unsigned int); 565 if ((retval = print_char(c, width, flags, ps)) < 0) { 566 goto minus_out; 567 } 568 569 counter += retval; 570 j = i + 1; 571 goto next_char; 572 573 /* 574 * Integer values 575 */ 576 case 'P': /* pointer */ 577 flags |= __PRINTF_FLAG_BIGCHARS; 578 case 'p': 579 flags |= __PRINTF_FLAG_PREFIX; 580 base = 16; 581 qualifier = PrintfQualifierPointer; 582 break; 583 case 'b': 584 base = 2; 585 break; 586 case 'o': 587 base = 8; 588 break; 589 case 'd': 590 case 'i': 591 flags |= __PRINTF_FLAG_SIGNED; 592 case 'u': 593 break; 594 case 'X': 595 flags |= __PRINTF_FLAG_BIGCHARS; 596 case 'x': 597 base = 16; 598 break; 599 /* percentile itself */ 600 case '%': 601 j = i; 602 goto next_char; 603 /* 604 * Bad formatting. 605 */ 606 default: 607 /* Unknown format 608 * now, the j is index of '%' so we will 609 * print whole bad format sequence 610 */ 611 goto next_char; 612 612 } 613 613 … … 616 616 /* print number */ 617 617 switch (qualifier) { 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 618 case PrintfQualifierByte: 619 size = sizeof(unsigned char); 620 number = (uint64_t)va_arg(ap, unsigned int); 621 break; 622 case PrintfQualifierShort: 623 size = sizeof(unsigned short); 624 number = (uint64_t)va_arg(ap, unsigned int); 625 break; 626 case PrintfQualifierInt: 627 size = sizeof(unsigned int); 628 number = (uint64_t)va_arg(ap, unsigned int); 629 break; 630 case PrintfQualifierLong: 631 size = sizeof(unsigned long); 632 number = (uint64_t)va_arg(ap, unsigned long); 633 break; 634 case PrintfQualifierLongLong: 635 size = sizeof(unsigned long long); 636 number = (uint64_t)va_arg(ap, unsigned long long); 637 break; 638 case PrintfQualifierPointer: 639 size = sizeof(void *); 640 number = (uint64_t)(unsigned long)va_arg(ap, void *); 641 break; 642 case PrintfQualifierSizeT: 643 size = sizeof(size_t); 644 number = (uint64_t)va_arg(ap, size_t); 645 break; 646 default: /* Unknown qualifier */ 647 goto minus_out; 648 648 649 649 }
Note:
See TracChangeset
for help on using the changeset viewer.