Changeset 34120f10 in mainline for common/printf/printf_core.c
- Timestamp:
- 2023-10-27T19:38:31Z (15 months ago)
- Branches:
- master, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 63ed840
- Parents:
- c89ae25 (diff), 694ca3d6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
common/printf/printf_core.c
rc89ae25 r34120f10 40 40 #include <stddef.h> 41 41 #include <stdlib.h> 42 #include < io/printf_core.h>42 #include <printf_core.h> 43 43 #include <ctype.h> 44 44 #include <str.h> 45 #include <double_to_str.h>46 #include <ieee_double.h>47 45 #include <assert.h> 48 46 #include <macros.h> 49 47 #include <uchar.h> 48 49 /* Disable float support in kernel, because we usually disable floating operations there. */ 50 #if __STDC_HOSTED__ 51 #define HAS_FLOAT 52 #endif 53 54 #ifdef HAS_FLOAT 55 #include <double_to_str.h> 56 #include <ieee_double.h> 57 #endif 50 58 51 59 /** show prefixes 0x or 0 */ … … 122 130 static const char *digits_big = "0123456789ABCDEF"; 123 131 static const char invalch = U_SPECIAL; 124 125 /** Unformatted double number string representation. */126 typedef struct {127 /** Buffer with len digits, no sign or leading zeros. */128 char *str;129 /** Number of digits in str. */130 int len;131 /** Decimal exponent, ie number = str * 10^dec_exp */132 int dec_exp;133 /** True if negative. */134 bool neg;135 } double_str_t;136 137 /** Returns the sign character or 0 if no sign should be printed. */138 static int get_sign_char(bool negative, uint32_t flags)139 {140 if (negative) {141 return '-';142 } else if (flags & __PRINTF_FLAG_SHOWPLUS) {143 return '+';144 } else if (flags & __PRINTF_FLAG_SPACESIGN) {145 return ' ';146 } else {147 return 0;148 }149 }150 151 /** Prints count times character ch. */152 static int print_padding(char ch, int count, printf_spec_t *ps)153 {154 for (int i = 0; i < count; ++i) {155 if (ps->str_write(&ch, 1, ps->data) < 0) {156 return -1;157 }158 }159 160 return count;161 }162 132 163 133 /** Print one or more characters without adding newline. … … 585 555 } 586 556 557 #ifdef HAS_FLOAT 558 559 /** Unformatted double number string representation. */ 560 typedef struct { 561 /** Buffer with len digits, no sign or leading zeros. */ 562 char *str; 563 /** Number of digits in str. */ 564 int len; 565 /** Decimal exponent, ie number = str * 10^dec_exp */ 566 int dec_exp; 567 /** True if negative. */ 568 bool neg; 569 } double_str_t; 570 571 /** Returns the sign character or 0 if no sign should be printed. */ 572 static int get_sign_char(bool negative, uint32_t flags) 573 { 574 if (negative) { 575 return '-'; 576 } else if (flags & __PRINTF_FLAG_SHOWPLUS) { 577 return '+'; 578 } else if (flags & __PRINTF_FLAG_SPACESIGN) { 579 return ' '; 580 } else { 581 return 0; 582 } 583 } 584 585 /** Prints count times character ch. */ 586 static int print_padding(char ch, int count, printf_spec_t *ps) 587 { 588 for (int i = 0; i < count; ++i) { 589 if (ps->str_write(&ch, 1, ps->data) < 0) { 590 return -1; 591 } 592 } 593 594 return count; 595 } 596 587 597 /** Prints a special double (ie NaN, infinity) padded to width characters. */ 588 598 static int print_special(ieee_double_t val, int width, uint32_t flags, … … 1229 1239 } 1230 1240 } 1241 1242 #endif 1231 1243 1232 1244 /** Print formatted string. … … 1520 1532 continue; 1521 1533 1534 #ifdef HAS_FLOAT 1522 1535 /* 1523 1536 * Floating point values … … 1540 1553 j = nxt; 1541 1554 continue; 1555 #endif 1542 1556 1543 1557 /*
Note:
See TracChangeset
for help on using the changeset viewer.