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.
This commit is contained in:
David Lechner 2019-06-16 15:02:12 -05:00
parent 108fd93a34
commit ff0a5f69c2
2 changed files with 21 additions and 6 deletions

View File

@ -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 */

View File

@ -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