Rev 1444 | Rev 1617 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1444 | Rev 1616 | ||
---|---|---|---|
Line 35... | Line 35... | ||
35 | #include <unistd.h> |
35 | #include <unistd.h> |
36 | #include <stdio.h> |
36 | #include <stdio.h> |
37 | #include <io/printf_core.h> |
37 | #include <io/printf_core.h> |
38 | #include <ctype.h> |
38 | #include <ctype.h> |
39 | #include <string.h> |
39 | #include <string.h> |
- | 40 | /* For serialization */ |
|
- | 41 | #include <async.h> |
|
40 | 42 | ||
41 | #define __PRINTF_FLAG_PREFIX 0x00000001 /**< show prefixes 0x or 0*/ |
43 | #define __PRINTF_FLAG_PREFIX 0x00000001 /**< show prefixes 0x or 0*/ |
42 | #define __PRINTF_FLAG_SIGNED 0x00000002 /**< signed / unsigned number */ |
44 | #define __PRINTF_FLAG_SIGNED 0x00000002 /**< signed / unsigned number */ |
43 | #define __PRINTF_FLAG_ZEROPADDED 0x00000004 /**< print leading zeroes */ |
45 | #define __PRINTF_FLAG_ZEROPADDED 0x00000004 /**< print leading zeroes */ |
44 | #define __PRINTF_FLAG_LEFTALIGNED 0x00000010 /**< align to left */ |
46 | #define __PRINTF_FLAG_LEFTALIGNED 0x00000010 /**< align to left */ |
Line 442... | Line 444... | ||
442 | uint64_t number; /* argument value */ |
444 | uint64_t number; /* argument value */ |
443 | size_t size; /* byte size of integer parameter */ |
445 | size_t size; /* byte size of integer parameter */ |
444 | int width, precision; |
446 | int width, precision; |
445 | uint64_t flags; |
447 | uint64_t flags; |
446 | 448 | ||
- | 449 | /* Don't let other threads interfere */ |
|
- | 450 | async_serialize_start(); |
|
- | 451 | ||
447 | counter = 0; |
452 | counter = 0; |
448 | 453 | ||
449 | while ((c = fmt[i])) { |
454 | while ((c = fmt[i])) { |
450 | /* control character */ |
455 | /* control character */ |
451 | if (c == '%' ) { |
456 | if (c == '%' ) { |
452 | /* print common characters if any processed */ |
457 | /* print common characters if any processed */ |
453 | if (i > j) { |
458 | if (i > j) { |
454 | if ((retval = printf_putnchars(&fmt[j], (size_t)(i - j), ps)) == EOF) { /* error */ |
459 | if ((retval = printf_putnchars(&fmt[j], (size_t)(i - j), ps)) == EOF) { /* error */ |
455 | return -counter; |
460 | goto minus_out; |
456 | } |
461 | } |
457 | counter += retval; |
462 | counter += retval; |
458 | } |
463 | } |
459 | 464 | ||
460 | j = i; |
465 | j = i; |
Line 546... | Line 551... | ||
546 | /* |
551 | /* |
547 | * String and character conversions. |
552 | * String and character conversions. |
548 | */ |
553 | */ |
549 | case 's': |
554 | case 's': |
550 | if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) == EOF) { |
555 | if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) == EOF) { |
551 | return -counter; |
556 | goto minus_out; |
552 | }; |
557 | }; |
553 | 558 | ||
554 | counter += retval; |
559 | counter += retval; |
555 | j = i + 1; |
560 | j = i + 1; |
556 | goto next_char; |
561 | goto next_char; |
557 | case 'c': |
562 | case 'c': |
558 | c = va_arg(ap, unsigned int); |
563 | c = va_arg(ap, unsigned int); |
559 | if ((retval = print_char(c, width, flags, ps)) == EOF) { |
564 | if ((retval = print_char(c, width, flags, ps)) == EOF) { |
560 | return -counter; |
565 | goto minus_out; |
561 | }; |
566 | }; |
562 | 567 | ||
563 | counter += retval; |
568 | counter += retval; |
564 | j = i + 1; |
569 | j = i + 1; |
565 | goto next_char; |
570 | goto next_char; |
Line 636... | Line 641... | ||
636 | case PrintfQualifierSizeT: |
641 | case PrintfQualifierSizeT: |
637 | size = sizeof(size_t); |
642 | size = sizeof(size_t); |
638 | number = (uint64_t)va_arg(ap, size_t); |
643 | number = (uint64_t)va_arg(ap, size_t); |
639 | break; |
644 | break; |
640 | default: /* Unknown qualifier */ |
645 | default: /* Unknown qualifier */ |
641 | return -counter; |
646 | goto minus_out; |
642 | 647 | ||
643 | } |
648 | } |
644 | 649 | ||
645 | if (flags & __PRINTF_FLAG_SIGNED) { |
650 | if (flags & __PRINTF_FLAG_SIGNED) { |
646 | if (number & (0x1 << (size*8 - 1))) { |
651 | if (number & (0x1 << (size*8 - 1))) { |
Line 655... | Line 660... | ||
655 | } |
660 | } |
656 | } |
661 | } |
657 | } |
662 | } |
658 | 663 | ||
659 | if ((retval = print_number(number, width, precision, base, flags, ps)) == EOF ) { |
664 | if ((retval = print_number(number, width, precision, base, flags, ps)) == EOF ) { |
660 | return -counter; |
665 | goto minus_out; |
661 | }; |
666 | }; |
662 | 667 | ||
663 | counter += retval; |
668 | counter += retval; |
664 | j = i + 1; |
669 | j = i + 1; |
665 | } |
670 | } |
Line 668... | Line 673... | ||
668 | ++i; |
673 | ++i; |
669 | } |
674 | } |
670 | 675 | ||
671 | if (i > j) { |
676 | if (i > j) { |
672 | if ((retval = printf_putnchars(&fmt[j], (size_t)(i - j), ps)) == EOF) { /* error */ |
677 | if ((retval = printf_putnchars(&fmt[j], (size_t)(i - j), ps)) == EOF) { /* error */ |
673 | return -counter; |
678 | goto minus_out; |
674 | } |
679 | } |
675 | counter += retval; |
680 | counter += retval; |
676 | } |
681 | } |
677 | 682 | ||
- | 683 | async_serialize_end(); |
|
678 | return counter; |
684 | return counter; |
- | 685 | minus_out: |
|
- | 686 | async_serialize_end(); |
|
- | 687 | return -counter; |
|
679 | } |
688 | } |
680 | 689 |