From 5fd8d772fd078915c0e892cb383fbebb7a1da716 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 11:14:24 +0200 Subject: [PATCH] Move the string-to-float functions into core, after marking them as ACKCONF_WANT_FLOAT. --- lang/cem/libcc.ansi/build.lua | 2 +- lang/cem/libcc.ansi/{ => core}/stdlib/atof.c | 5 +++++ .../libcc.ansi/{stdio => core/stdlib}/ecvt.c | 7 +++--- .../libcc.ansi/{ => core}/stdlib/ext_comp.c | 8 +++++-- lang/cem/libcc.ansi/core/stdlib/ext_fmt.h | 22 +++++++++++++++++++ .../cem/libcc.ansi/{ => core}/stdlib/strtod.c | 5 +---- lang/cem/libcc.ansi/stdlib/ext_fmt.h | 13 ----------- 7 files changed, 38 insertions(+), 24 deletions(-) rename lang/cem/libcc.ansi/{ => core}/stdlib/atof.c (85%) rename lang/cem/libcc.ansi/{stdio => core/stdlib}/ecvt.c (71%) rename lang/cem/libcc.ansi/{ => core}/stdlib/ext_comp.c (99%) create mode 100644 lang/cem/libcc.ansi/core/stdlib/ext_fmt.h rename lang/cem/libcc.ansi/{ => core}/stdlib/strtod.c (60%) delete mode 100644 lang/cem/libcc.ansi/stdlib/ext_fmt.h diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index 9ca2279cd..d5e33a6e2 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -57,8 +57,8 @@ for _, plat in ipairs(vars.plats) do "plat/"..plat.."/include+pkg", "./malloc/malloc.h", "./core/math/localmath.h", + "./core/stdlib/ext_fmt.h", "./stdio/loc_incl.h", - "./stdlib/ext_fmt.h", "./time/loc_time.h", }, vars = { plat = plat } diff --git a/lang/cem/libcc.ansi/stdlib/atof.c b/lang/cem/libcc.ansi/core/stdlib/atof.c similarity index 85% rename from lang/cem/libcc.ansi/stdlib/atof.c rename to lang/cem/libcc.ansi/core/stdlib/atof.c index c46304817..d8092b841 100644 --- a/lang/cem/libcc.ansi/stdlib/atof.c +++ b/lang/cem/libcc.ansi/core/stdlib/atof.c @@ -6,6 +6,9 @@ #include #include +#include + +#if ACKCONF_WANT_FLOAT double(atof)(const char* nptr) { @@ -16,3 +19,5 @@ double(atof)(const char* nptr) errno = e; return d; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/ecvt.c b/lang/cem/libcc.ansi/core/stdlib/ecvt.c similarity index 71% rename from lang/cem/libcc.ansi/stdio/ecvt.c rename to lang/cem/libcc.ansi/core/stdlib/ecvt.c index 25243f0a4..f17ec9f50 100644 --- a/lang/cem/libcc.ansi/stdio/ecvt.c +++ b/lang/cem/libcc.ansi/core/stdlib/ecvt.c @@ -1,12 +1,11 @@ /* $Id$ */ -#include "loc_incl.h" +#include +#include #if ACKCONF_WANT_STDIO_FLOAT -#include "../stdlib/ext_fmt.h" -void _dbl_ext_cvt(double value, struct EXTEND* e); -char* _ext_str_cvt(struct EXTEND* e, int ndigit, int* decpt, int* sign, int ecvtflag); +#include "ext_fmt.h" static char* cvt(long double value, int ndigit, int* decpt, int* sign, int ecvtflag) diff --git a/lang/cem/libcc.ansi/stdlib/ext_comp.c b/lang/cem/libcc.ansi/core/stdlib/ext_comp.c similarity index 99% rename from lang/cem/libcc.ansi/stdlib/ext_comp.c rename to lang/cem/libcc.ansi/core/stdlib/ext_comp.c index c9b0b8b13..28eb213a4 100644 --- a/lang/cem/libcc.ansi/stdlib/ext_comp.c +++ b/lang/cem/libcc.ansi/core/stdlib/ext_comp.c @@ -17,6 +17,8 @@ #include #include +#if ACKCONF_WANT_FLOAT + static int b64_add(struct mantissa* e1, struct mantissa* e2); static b64_sft(struct mantissa* e1, int n); @@ -494,7 +496,7 @@ static add_exponent(struct EXTEND* e, int exp) } } -_str_ext_cvt(const char* s, char** ss, struct EXTEND* e) +void _str_ext_cvt(const char* s, char** ss, struct EXTEND* e) { /* Like strtod, but for extended precision */ register int c; @@ -781,7 +783,7 @@ char* _ext_str_cvt(struct EXTEND* e, int ndigit, int* decpt, int* sign, int ecvt return buf; } -_dbl_ext_cvt(double value, struct EXTEND* e) +void _dbl_ext_cvt(double value, struct EXTEND* e) { /* Convert double to extended */ @@ -833,3 +835,5 @@ _ext_dbl_cvt(struct EXTEND* e) } return f; } + +#endif diff --git a/lang/cem/libcc.ansi/core/stdlib/ext_fmt.h b/lang/cem/libcc.ansi/core/stdlib/ext_fmt.h new file mode 100644 index 000000000..7b3a88824 --- /dev/null +++ b/lang/cem/libcc.ansi/core/stdlib/ext_fmt.h @@ -0,0 +1,22 @@ +#ifndef _EXT_FMT_H +#define _EXT_FMT_H + +struct mantissa { + unsigned long h_32; + unsigned long l_32; +}; + +struct EXTEND { + short sign; + short exp; + struct mantissa mantissa; +#define m1 mantissa.h_32 +#define m2 mantissa.l_32 +}; + +extern void _str_ext_cvt(const char* s, char** ss, struct EXTEND* e); +extern double _ext_dbl_cvt(struct EXTEND* e); +extern void _dbl_ext_cvt(double value, struct EXTEND* e); +extern char* _ext_str_cvt(struct EXTEND* e, int ndigit, int* decpt, int* sign, int ecvtflag); + +#endif diff --git a/lang/cem/libcc.ansi/stdlib/strtod.c b/lang/cem/libcc.ansi/core/stdlib/strtod.c similarity index 60% rename from lang/cem/libcc.ansi/stdlib/strtod.c rename to lang/cem/libcc.ansi/core/stdlib/strtod.c index d9009bcc6..36a568d05 100644 --- a/lang/cem/libcc.ansi/stdlib/strtod.c +++ b/lang/cem/libcc.ansi/core/stdlib/strtod.c @@ -4,10 +4,7 @@ #include #include "ext_fmt.h" -#if ACKCONF_WANT_STDIO_FLOAT - -void _str_ext_cvt(const char* s, char** ss, struct EXTEND* e); -double _ext_dbl_cvt(struct EXTEND* e); +#if ACKCONF_WANT_FLOAT double strtod(const char* p, char** pp) diff --git a/lang/cem/libcc.ansi/stdlib/ext_fmt.h b/lang/cem/libcc.ansi/stdlib/ext_fmt.h deleted file mode 100644 index e8a5db1b8..000000000 --- a/lang/cem/libcc.ansi/stdlib/ext_fmt.h +++ /dev/null @@ -1,13 +0,0 @@ -struct mantissa { - unsigned long h_32; - unsigned long l_32; -}; - -struct EXTEND { - short sign; - short exp; - struct mantissa mantissa; -#define m1 mantissa.h_32 -#define m2 mantissa.l_32 -}; - -- 2.34.1