add "make c99" to convert back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
diff --git a/.travis.yml b/.travis.yml
index 42960d0..738c62b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -61,6 +61,9 @@ matrix:
# We have only one program and the variable $BUILDOPTIONS
# has only the options to that program: testme.sh
+ # Check c89 <-> c99 roundtrip
+ - env: BUILDOPTIONS='--c89-c99-roundtrip'
+
# Check source code format
- env: BUILDOPTIONS='--format'
addons:
diff --git a/makefile b/makefile
index be7ef0c..c06849a 100644
--- a/makefile
+++ b/makefile
@@ -154,8 +154,9 @@ perlcritic:
c89:
@echo "Applying substitutions for c89 compatibility..."
+ @if grep mp_bool tommath.h > /dev/null; then echo "Already applied"; exit 1; fi
@sed -i \
- -e 's/#include <stdbool.h>//g' \
+ -e '/#include <stdbool.h>/d' \
-e 's/#include <stdint.h>/#include "tommath_c89.h"/g' \
-e 's/bool/mp_bool/g' \
-e 's/true/MP_YES/g' \
@@ -175,6 +176,21 @@ c89:
@echo "typedef __UINT64_TYPE__ mp_u64;" >> tommath_c89.h
+c99:
+ @echo "Applying substitutions for c99 compatibility..."
+ @if ! grep mp_bool tommath.h > /dev/null; then echo "Already applied"; exit 1; fi
+ @sed -i \
+ -e 's/#include "tommath_c89.h"/#include <stdint.h>\n#include <stdbool.h>/g' \
+ -e 's/mp_bool/bool/g' \
+ -e 's/MP_YES/true/g' \
+ -e 's/MP_NO/false/g' \
+ -e 's/false_/MP_NO_/g' \
+ -e 's/mp_u\([0-9][0-9]*\)/uint\1_t/g' \
+ -e 's/mp_i\([0-9][0-9]*\)/int\1_t/g' \
+ *.c *.h demo/*.c demo/*.h etc/*.c
+ @rm -f tommath_c89.h
+
+
astyle:
@echo " * run astyle on all sources"
@astyle --options=astylerc --formatted $(OBJECTS:.o=.c) tommath*.h demo/*.c etc/*.c mtest/mtest.c
diff --git a/testme.sh b/testme.sh
index 3375fa6..6c71ac4 100755
--- a/testme.sh
+++ b/testme.sh
@@ -196,6 +196,7 @@ VALGRIND_OPTS=" --leak-check=full --show-leak-kinds=all --error-exitcode=1 "
VALGRIND_BIN=""
CHECK_FORMAT=""
C89=""
+C89_C99_ROUNDTRIP=""
TUNE_CMD="./etc/tune -t -r 10 -L 3"
alive_pid=0
@@ -221,6 +222,9 @@ do
--c89)
C89="1"
;;
+ --c89-c99-roundtrip)
+ C89_C99_ROUNDTRIP="1"
+ ;;
--with-cc=*)
COMPILERS="$COMPILERS ${1#*=}"
;;
@@ -297,6 +301,14 @@ function _check_git() {
[[ "$C89" == "1" ]] && make c89
+if [[ "$C89_C99_ROUNDTRIP" == "1" ]]
+then
+ make c89
+ make c99
+ _check_git "make c89; make c99"
+ exit $?
+fi
+
if [[ "$CHECK_FORMAT" == "1" ]]
then
make astyle
diff --git a/tommath.h b/tommath.h
index a55c57f..5ebd50c 100644
--- a/tommath.h
+++ b/tommath.h
@@ -4,8 +4,8 @@
#ifndef TOMMATH_H_
#define TOMMATH_H_
-#include <stdint.h>
#include <stddef.h>
+#include <stdint.h>
#include <stdbool.h>
#ifndef MP_NO_FILE