aboutsummaryrefslogtreecommitdiff
path: root/redist
diff options
context:
space:
mode:
Diffstat (limited to 'redist')
-rw-r--r--redist/json_helpers.c64
-rw-r--r--redist/json_helpers.h14
-rw-r--r--redist/linmath.h2
3 files changed, 80 insertions, 0 deletions
diff --git a/redist/json_helpers.c b/redist/json_helpers.c
new file mode 100644
index 0000000..74028b2
--- /dev/null
+++ b/redist/json_helpers.c
@@ -0,0 +1,64 @@
+// (C) 2017 <>< Joshua Allen, Under MIT/x11 License.
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "json_helpers.h"
+
+void json_write_float_array(FILE* f, const char* tag, float* v, uint8_t count) {
+ uint8_t i = 0;
+ char * str1 = NULL;
+ char * str2 = NULL;
+ asprintf(&str1,"\"%s\":[", tag);
+
+ for (i=0;i<count;++i) {
+ if (i<(count-1)) {
+ asprintf(&str2, "%s\"%f\",", str1,v[i]);
+ } else {
+ asprintf(&str2, "%s\"%f\"", str1,v[i]);
+ }
+ free(str1);
+ str1=str2;
+ str2=NULL;
+ }
+ asprintf(&str2, "%s]", str1,v[i]);
+ fputs(str2,f);
+ free(str1);
+ free(str2);
+}
+
+void json_write_double_array(FILE* f, const char* tag, double* v, uint8_t count) {
+ uint8_t i = 0;
+ char * str1 = NULL;
+ char * str2 = NULL;
+ asprintf(&str1,"\"%s\":[", tag);
+
+ for (i=0;i<count;++i) {
+ if (i<(count-1)) {
+ asprintf(&str2, "%s\"%f\",", str1,v[i]);
+ } else {
+ asprintf(&str2, "%s\"%f\"", str1,v[i]);
+ }
+ free(str1);
+ str1=str2;
+ str2=NULL;
+ }
+ asprintf(&str2, "%s]", str1,v[i]);
+ fputs(str2,f);
+ free(str1);
+ free(str2);
+}
+
+void json_write_uint32(FILE* f, const char* tag, uint32_t v) {
+ fprintf(f, "\"%s\":\"%d\"", tag, v);
+}
+
+void json_write_float(FILE* f, const char* tag, float v) {
+ fprintf(f, "\"%s\":\"%f\"", tag, v);
+}
+
+void json_write_str(FILE* f, const char* tag, const char* v) {
+ fprintf(f, "\"%s\":\"%s\"", tag, v);
+} \ No newline at end of file
diff --git a/redist/json_helpers.h b/redist/json_helpers.h
new file mode 100644
index 0000000..8d6eb64
--- /dev/null
+++ b/redist/json_helpers.h
@@ -0,0 +1,14 @@
+// (C) 2017 <>< Joshua Allen, Under MIT/x11 License.
+
+#ifndef JSON_HELPERS_H
+#define JSON_HELPERS_H
+
+#include <stdint.h>
+
+void json_write_float_array(FILE* f, const char* tag, float* v, uint8_t count);
+void json_write_double_array(FILE* f, const char* tag, double* v, uint8_t count);
+void json_write_uint32(FILE* f, const char* tag, uint32_t v);
+void json_write_float(FILE* f, const char* tag, float v);
+void json_write_str(FILE* f, const char* tag, const char* v);
+
+#endif \ No newline at end of file
diff --git a/redist/linmath.h b/redist/linmath.h
index 20a7848..caec281 100644
--- a/redist/linmath.h
+++ b/redist/linmath.h
@@ -19,6 +19,7 @@
#define FLT double
#define FLT_SQRT sqrt
+#define FLT_TAN tan
#define FLT_SIN sin
#define FLT_COS cos
#define FLT_ACOS acos
@@ -30,6 +31,7 @@
#define FLT float
#define FLT_SQRT sqrtf
+#define FLT_TAN tanf
#define FLT_SIN sinf
#define FLT_COS cosf
#define FLT_ACOS acosf