Changeset 694ca3d6 in mainline


Ignore:
Timestamp:
2023-10-27T18:56:50Z (13 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, topic/msim-upgrade, topic/simplify-dev-export
Children:
34120f10
Parents:
ad9178bf
Message:

Deduplicate printf_core()

Files:
1 deleted
8 edited
2 moved

Legend:

Unmodified
Added
Removed
  • common/printf/printf_core.c

    rad9178bf r694ca3d6  
    4040#include <stddef.h>
    4141#include <stdlib.h>
    42 #include <io/printf_core.h>
     42#include <printf_core.h>
    4343#include <ctype.h>
    4444#include <str.h>
    45 #include <double_to_str.h>
    46 #include <ieee_double.h>
    4745#include <assert.h>
    4846#include <macros.h>
    4947#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
    5058
    5159/** show prefixes 0x or 0 */
     
    122130static const char *digits_big = "0123456789ABCDEF";
    123131static 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 }
    162132
    163133/** Print one or more characters without adding newline.
     
    585555}
    586556
     557#ifdef HAS_FLOAT
     558
     559/** Unformatted double number string representation. */
     560typedef 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. */
     572static 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. */
     586static 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
    587597/** Prints a special double (ie NaN, infinity) padded to width characters. */
    588598static int print_special(ieee_double_t val, int width, uint32_t flags,
     
    12291239        }
    12301240}
     1241
     1242#endif
    12311243
    12321244/** Print formatted string.
     
    15201532                                continue;
    15211533
     1534#ifdef HAS_FLOAT
    15221535                                /*
    15231536                                 * Floating point values
     
    15401553                                j = nxt;
    15411554                                continue;
     1555#endif
    15421556
    15431557                                /*
  • kernel/generic/meson.build

    rad9178bf r694ca3d6  
    4040        'common/adt/list.c',
    4141        'common/adt/odict.c',
     42        'common/printf/printf_core.c',
    4243        'common/stdc/calloc.c',
    4344        'common/stdc/ctype.c',
     
    9697        'src/preempt/preemption.c',
    9798        'src/printf/printf.c',
    98         'src/printf/printf_core.c',
    9999        'src/printf/snprintf.c',
    100100        'src/printf/vprintf.c',
  • uspace/lib/c/generic/io/asprintf.c

    rad9178bf r694ca3d6  
    3939#include <stddef.h>
    4040#include <str.h>
    41 #include <io/printf_core.h>
     41#include <printf_core.h>
    4242
    4343static int asprintf_str_write(const char *str, size_t count, void *unused)
  • uspace/lib/c/generic/io/kio.c

    rad9178bf r694ca3d6  
    4242#include <abi/kio.h>
    4343#include <io/kio.h>
    44 #include <io/printf_core.h>
     44#include <printf_core.h>
    4545#include <macros.h>
    4646#include <libarch/config.h>
  • uspace/lib/c/generic/io/printf.c

    rad9178bf r694ca3d6  
    3333 */
    3434
    35 #include <io/printf_core.h>
     35#include <printf_core.h>
    3636#include <stdio.h>
    3737
  • uspace/lib/c/generic/io/vprintf.c

    rad9178bf r694ca3d6  
    3535#include <stdarg.h>
    3636#include <stdio.h>
    37 #include <io/printf_core.h>
     37#include <printf_core.h>
    3838#include <fibril_synch.h>
    3939#include <async.h>
  • uspace/lib/c/generic/io/vsnprintf.c

    rad9178bf r694ca3d6  
    3636#include <stdio.h>
    3737#include <str.h>
    38 #include <io/printf_core.h>
     38#include <printf_core.h>
    3939#include <errno.h>
    4040
  • uspace/lib/c/meson.build

    rad9178bf r694ca3d6  
    6767        'common/adt/odict.c',
    6868        'common/adt/prodcons.c',
     69        'common/printf/printf_core.c',
    6970        'common/stdc/ctype.c',
    7071        'common/stdc/mem.c',
     
    120121        'generic/io/vprintf.c',
    121122        'generic/io/vsnprintf.c',
    122         'generic/io/printf_core.c',
    123123        'generic/io/con_srv.c',
    124124        'generic/io/console.c',
  • uspace/lib/posix/src/stdio.c

    rad9178bf r694ca3d6  
    5353#include <unistd.h>
    5454
    55 #include <io/printf_core.h>
     55#include <printf_core.h>
    5656#include <str.h>
    5757#include <stdlib.h>
Note: See TracChangeset for help on using the changeset viewer.