Changeset 694ca3d6 in mainline
- Timestamp:
- 2023-10-27T18:56:50Z (13 months ago)
- Branches:
- master, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 34120f10
- Parents:
- ad9178bf
- Files:
-
- 1 deleted
- 8 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
common/printf/printf_core.c
rad9178bf r694ca3d6 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 /* -
kernel/generic/meson.build
rad9178bf r694ca3d6 40 40 'common/adt/list.c', 41 41 'common/adt/odict.c', 42 'common/printf/printf_core.c', 42 43 'common/stdc/calloc.c', 43 44 'common/stdc/ctype.c', … … 96 97 'src/preempt/preemption.c', 97 98 'src/printf/printf.c', 98 'src/printf/printf_core.c',99 99 'src/printf/snprintf.c', 100 100 'src/printf/vprintf.c', -
uspace/lib/c/generic/io/asprintf.c
rad9178bf r694ca3d6 39 39 #include <stddef.h> 40 40 #include <str.h> 41 #include < io/printf_core.h>41 #include <printf_core.h> 42 42 43 43 static int asprintf_str_write(const char *str, size_t count, void *unused) -
uspace/lib/c/generic/io/kio.c
rad9178bf r694ca3d6 42 42 #include <abi/kio.h> 43 43 #include <io/kio.h> 44 #include < io/printf_core.h>44 #include <printf_core.h> 45 45 #include <macros.h> 46 46 #include <libarch/config.h> -
uspace/lib/c/generic/io/printf.c
rad9178bf r694ca3d6 33 33 */ 34 34 35 #include < io/printf_core.h>35 #include <printf_core.h> 36 36 #include <stdio.h> 37 37 -
uspace/lib/c/generic/io/vprintf.c
rad9178bf r694ca3d6 35 35 #include <stdarg.h> 36 36 #include <stdio.h> 37 #include < io/printf_core.h>37 #include <printf_core.h> 38 38 #include <fibril_synch.h> 39 39 #include <async.h> -
uspace/lib/c/generic/io/vsnprintf.c
rad9178bf r694ca3d6 36 36 #include <stdio.h> 37 37 #include <str.h> 38 #include < io/printf_core.h>38 #include <printf_core.h> 39 39 #include <errno.h> 40 40 -
uspace/lib/c/meson.build
rad9178bf r694ca3d6 67 67 'common/adt/odict.c', 68 68 'common/adt/prodcons.c', 69 'common/printf/printf_core.c', 69 70 'common/stdc/ctype.c', 70 71 'common/stdc/mem.c', … … 120 121 'generic/io/vprintf.c', 121 122 'generic/io/vsnprintf.c', 122 'generic/io/printf_core.c',123 123 'generic/io/con_srv.c', 124 124 'generic/io/console.c', -
uspace/lib/posix/src/stdio.c
rad9178bf r694ca3d6 53 53 #include <unistd.h> 54 54 55 #include < io/printf_core.h>55 #include <printf_core.h> 56 56 #include <str.h> 57 57 #include <stdlib.h>
Note:
See TracChangeset
for help on using the changeset viewer.