aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lechner <david@pybricks.com>2019-06-16 15:02:12 -0500
committerDavid Lechner <david@pybricks.com>2019-06-16 15:38:19 -0500
commitff0a5f69c20a9a808402a16dde8b20ce88e04f4d (patch)
tree4998d2edb83abd9baa1b94496a6233830f8d6e86
parent108fd93a34802db90c1cb56a2aa68cdd7ef14858 (diff)
downloadlibfixmath-ff0a5f69c20a9a808402a16dde8b20ce88e04f4d.tar.gz
add FIXMATH_NO_CTYPE option
When compiling with -nostdlib, the functions in ctype may not be available. Add FIXMATH_NO_CTYPE option to replace them with inline functions. Also add unit test to test str functions with this option enabled.
-rw-r--r--libfixmath/fix16_str.c12
-rw-r--r--unittests/Makefile15
2 files changed, 21 insertions, 6 deletions
diff --git a/libfixmath/fix16_str.c b/libfixmath/fix16_str.c
index eff906f..07df864 100644
--- a/libfixmath/fix16_str.c
+++ b/libfixmath/fix16_str.c
@@ -1,6 +1,18 @@
#include "fix16.h"
#include <stdbool.h>
+#ifndef FIXMATH_NO_CTYPE
#include <ctype.h>
+#else
+static inline int isdigit(int c)
+{
+ return c >= '0' && c <= '9';
+}
+
+static inline int isspace(int c)
+{
+ return c == ' ' || c == '\r' || c == '\n' || c == '\t' || c == '\v' || c == '\f';
+}
+#endif
static const uint32_t scales[8] = {
/* 5 decimals is enough for full fix16_t precision */
diff --git a/unittests/Makefile b/unittests/Makefile
index a9adb87..78433fe 100644
--- a/unittests/Makefile
+++ b/unittests/Makefile
@@ -12,7 +12,8 @@ all: run_fix16_unittests run_fix16_exp_unittests run_fix16_str_unittests run_fix
clean:
rm -f fix16_unittests_????
- rm -f fix16_str_unittests
+ rm -f fix16_str_unittests_default
+ rm -f fix16_str_unittests_no_ctype
rm -f fix16_exp_unittests
rm -f fix16_macros_unittests
@@ -47,6 +48,7 @@ fix16_unittests_ro08: DEFINES=-DFIXMATH_OPTIMIZE_8BIT
fix16_unittests_no08: DEFINES=-DFIXMATH_NO_ROUNDING -DFIXMATH_OPTIMIZE_8BIT
fix16_unittests_rn08: DEFINES=-DFIXMATH_NO_OVERFLOW -DFIXMATH_OPTIMIZE_8BIT
fix16_unittests_nn08: DEFINES=-DFIXMATH_NO_OVERFLOW -DFIXMATH_NO_ROUNDING -DFIXMATH_OPTIMIZE_8BIT
+fix16_str_unittests_no_ctype: DEFINES=-DFIXMATH_NO_CTYPE
fix16_unittests_% : fix16_unittests.c $(FIX16_SRC)
$(CC) $(CFLAGS) $(DEFINES) -o $@ $^ -lm
@@ -58,12 +60,13 @@ run_fix16_exp_unittests: fix16_exp_unittests
fix16_exp_unittests: fix16_exp_unittests.c $(FIX16_SRC)
$(CC) $(CFLAGS) $(DEFINES) -o $@ $^ -lm
-
-# Tests for string conversion, run only in default config
-run_fix16_str_unittests: fix16_str_unittests
- ./fix16_str_unittests > /dev/null
-fix16_str_unittests: fix16_str_unittests.c $(FIX16_SRC)
+# Tests for string conversion, run only in default config and no ctype
+run_fix16_str_unittests: fix16_str_unittests_default fix16_str_unittests_no_ctype
+ ./fix16_str_unittests_default > /dev/null
+ ./fix16_str_unittests_no_ctype > /dev/null
+
+fix16_str_unittests_%: fix16_str_unittests.c $(FIX16_SRC)
$(CC) $(CFLAGS) $(DEFINES) -o $@ $^ -lm
# Tests for literal macros, run only in default config