Commit 17d59c2c0f7e03af292c49978e077e3cc2f9a604

Daniel Mendler 2019-10-27T09:06:05

replace PRIx64 by MP_PRIx64 for c89 mode

diff --git a/makefile b/makefile
index c06849a..4694189 100644
--- a/makefile
+++ b/makefile
@@ -161,20 +161,10 @@ c89:
 	-e 's/bool/mp_bool/g' \
 	-e 's/true/MP_YES/g' \
 	-e 's/false/MP_NO/g' \
+	-e 's/\(PRI[iux]64\)/MP_\1/g' \
 	-e 's/uint\([0-9][0-9]*\)_t/mp_u\1/g' \
 	-e 's/int\([0-9][0-9]*\)_t/mp_i\1/g' \
-	*.c *.h demo/*.c demo/*.h etc/*.c
-	@echo "/* please adapt this header to your needs */" > tommath_c89.h
-	@echo "typedef enum { MP_NO, MP_YES } mp_bool;" >> tommath_c89.h
-	@echo "typedef __INT8_TYPE__   mp_i8;"          >> tommath_c89.h
-	@echo "typedef __INT16_TYPE__  mp_i16;"         >> tommath_c89.h
-	@echo "typedef __INT32_TYPE__  mp_i32;"         >> tommath_c89.h
-	@echo "typedef __INT64_TYPE__  mp_i64;"         >> tommath_c89.h
-	@echo "typedef __UINT8_TYPE__  mp_u8;"          >> tommath_c89.h
-	@echo "typedef __UINT16_TYPE__ mp_u16;"         >> tommath_c89.h
-	@echo "typedef __UINT32_TYPE__ mp_u32;"         >> tommath_c89.h
-	@echo "typedef __UINT64_TYPE__ mp_u64;"         >> tommath_c89.h
-
+	*.c tommath.h tommath_private.h demo/*.c demo/*.h etc/*.c
 
 c99:
 	@echo "Applying substitutions for c99 compatibility..."
@@ -185,11 +175,10 @@ c99:
 	-e 's/MP_YES/true/g' \
 	-e 's/MP_NO/false/g' \
 	-e 's/false_/MP_NO_/g' \
+	-e 's/MP_\(PRI[iux]64\)/\1/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
-
+	*.c tommath.h tommath_private.h demo/*.c demo/*.h etc/*.c
 
 astyle:
 	@echo "   * run astyle on all sources"
diff --git a/tommath_c89.h b/tommath_c89.h
new file mode 100644
index 0000000..e2beab8
--- /dev/null
+++ b/tommath_c89.h
@@ -0,0 +1,18 @@
+/* please adapt this header to your needs */
+typedef enum { MP_NO, MP_YES } mp_bool;
+typedef __INT8_TYPE__   mp_i8;
+typedef __INT16_TYPE__  mp_i16;
+typedef __INT32_TYPE__  mp_i32;
+typedef __INT64_TYPE__  mp_i64;
+typedef __UINT8_TYPE__  mp_u8;
+typedef __UINT16_TYPE__ mp_u16;
+typedef __UINT32_TYPE__ mp_u32;
+typedef __UINT64_TYPE__ mp_u64;
+# if __WORDSIZE == 64
+#  define MP_PRI64_PREFIX "l"
+# else
+#  define MP_PRI64_PREFIX "ll"
+# endif
+#define MP_PRIi64 MP_PRI64_PREFIX "i"
+#define MP_PRIu64 MP_PRI64_PREFIX "u"
+#define MP_PRIx64 MP_PRI64_PREFIX "x"