From cab4ee6f89a661190b2bd80c30e42d5f45614f20 Mon Sep 17 00:00:00 2001 From: Joshua Allen Date: Sun, 26 Feb 2017 10:13:31 -0500 Subject: json helpers for writing --- redist/json_helpers.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ redist/json_helpers.h | 14 ++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 redist/json_helpers.c create mode 100644 redist/json_helpers.h (limited to 'redist') diff --git a/redist/json_helpers.c b/redist/json_helpers.c new file mode 100644 index 0000000..e96e873 --- /dev/null +++ b/redist/json_helpers.c @@ -0,0 +1,63 @@ +// (C) 2017 <>< Joshua Allen, Under MIT/x11 License. + +#define _GNU_SOURCE + +#include +#include +#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< Joshua Allen, Under MIT/x11 License. + +#ifndef JSON_HELPERS_H +#define JSON_HELPERS_H + +#include + +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 -- cgit v1.2.3 From e8d696e03128242be33eb0734addee645e894635 Mon Sep 17 00:00:00 2001 From: Joshua Allen Date: Mon, 27 Feb 2017 20:52:26 -0500 Subject: basic config can be written to file --- redist/json_helpers.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'redist') diff --git a/redist/json_helpers.c b/redist/json_helpers.c index e96e873..74028b2 100644 --- a/redist/json_helpers.c +++ b/redist/json_helpers.c @@ -3,6 +3,7 @@ #define _GNU_SOURCE #include +#include #include #include "json_helpers.h" @@ -22,7 +23,7 @@ void json_write_float_array(FILE* f, const char* tag, float* v, uint8_t count) { str1=str2; str2=NULL; } - asprintf(&str2, "%s]\n", str1,v[i]); + asprintf(&str2, "%s]", str1,v[i]); fputs(str2,f); free(str1); free(str2); @@ -44,20 +45,20 @@ void json_write_double_array(FILE* f, const char* tag, double* v, uint8_t count) str1=str2; str2=NULL; } - asprintf(&str2, "%s]\n", str1,v[i]); + 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\"\n", tag, v); + fprintf(f, "\"%s\":\"%d\"", tag, v); } void json_write_float(FILE* f, const char* tag, float v) { - fprintf(f, "\"%s\":\"%f\"\n", tag, v); + fprintf(f, "\"%s\":\"%f\"", tag, v); } void json_write_str(FILE* f, const char* tag, const char* v) { - fprintf(f, "\"%s\":\"%s\"\n", tag, v); + fprintf(f, "\"%s\":\"%s\"", tag, v); } \ No newline at end of file -- cgit v1.2.3 From 294481ff114b210f3ccb436719e9595e7ffaa96b Mon Sep 17 00:00:00 2001 From: axlecrusher Date: Fri, 3 Mar 2017 06:33:26 -0500 Subject: Remove extra asprintf parameter --- redist/json_helpers.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'redist') diff --git a/redist/json_helpers.c b/redist/json_helpers.c index 74028b2..fd04203 100644 --- a/redist/json_helpers.c +++ b/redist/json_helpers.c @@ -23,7 +23,7 @@ void json_write_float_array(FILE* f, const char* tag, float* v, uint8_t count) { str1=str2; str2=NULL; } - asprintf(&str2, "%s]", str1,v[i]); + asprintf(&str2, "%s]", str1); fputs(str2,f); free(str1); free(str2); @@ -45,7 +45,7 @@ void json_write_double_array(FILE* f, const char* tag, double* v, uint8_t count) str1=str2; str2=NULL; } - asprintf(&str2, "%s]", str1,v[i]); + asprintf(&str2, "%s]", str1); fputs(str2,f); free(str1); free(str2); @@ -61,4 +61,4 @@ void json_write_float(FILE* f, const char* tag, float 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 +} -- cgit v1.2.3 From 0ebe84be5824202aecfd87ac58005afa76b36be9 Mon Sep 17 00:00:00 2001 From: Joshua Allen Date: Mon, 6 Mar 2017 22:05:02 -0500 Subject: Load strings from config files. I need to finish the loading of numeric values and arrays. --- redist/json_helpers.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++-- redist/json_helpers.h | 6 +++ 2 files changed, 117 insertions(+), 3 deletions(-) (limited to 'redist') diff --git a/redist/json_helpers.c b/redist/json_helpers.c index fd04203..b7ccb40 100644 --- a/redist/json_helpers.c +++ b/redist/json_helpers.c @@ -6,6 +6,8 @@ #include #include #include "json_helpers.h" +#include + void json_write_float_array(FILE* f, const char* tag, float* v, uint8_t count) { uint8_t i = 0; @@ -14,10 +16,10 @@ void json_write_float_array(FILE* f, const char* tag, float* v, uint8_t count) { asprintf(&str1,"\"%s\":[", tag); for (i=0;i=npos) return NULL; + + char* x = malloc(l); + memcpy(x,str+start,l); + x[l-1] = '\0'; + return x; +} + +static uint16_t json_load_array(const char* JSON_STRING, jsmntok_t* tokens, uint16_t size, char* tag) { + jsmntok_t* t = tokens; + uint16_t i = 0; + + char* values[size]; + + for (i=0;istart, t->end, JSON_STRING_LEN); + } + + if (json_tag_value != NULL) json_tag_value(tag, values, i); + + for (i=0;istart, tag_t->end, JSON_STRING_LEN); + char* value = substr(JSON_STRING, value_t->start, value_t->end, JSON_STRING_LEN); + + printf("%d %d c:%d %d %s \n", tag_t->start, tag_t->end, tag_t->size, tag_t->type, tag); + + + if (value_t->type == JSMN_ARRAY) { + i += json_load_array(JSON_STRING, tokens+i+2,value_t->size, tag); //look at array children + } else if (value_t->type == JSMN_OBJECT) { + printf("Begin Object\n"); + if (json_begin_object != NULL) json_begin_object(tag); + children = value_t->size +1; //+1 to account for this loop where we are not yed parsing children +// i += decode_jsmn_object(JSON_STRING, tokens+i+2,value_t->size); + } + else { + if (json_tag_value != NULL) json_tag_value(tag, &value, 1); + } + + if (children>=0) children--; + if (children == 0) { + children = -1; + printf("End Object\n"); + if (json_end_object!=NULL) json_end_object(); + } + +// printf("%d %s \n", value_t->type, tag); + + free(tag); + free(value); + } + + free(JSON_STRING); +} + diff --git a/redist/json_helpers.h b/redist/json_helpers.h index 8d6eb64..1670058 100644 --- a/redist/json_helpers.h +++ b/redist/json_helpers.h @@ -11,4 +11,10 @@ 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); +void json_load_file(const char* path); +extern void (*json_begin_object)(char* tag); +extern void (*json_end_object)(); +extern void (*json_tag_value)(char* tag, char** values, uint16_t count); + + #endif \ No newline at end of file -- cgit v1.2.3 From b960e4d04b49bee0f60a5b1d1199c256cfbc17d6 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Wed, 8 Mar 2017 00:34:00 -0500 Subject: apparently quat code had been wrong for quite some time. Luckily it was code that would rarely execute. --- redist/linmath.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'redist') diff --git a/redist/linmath.c b/redist/linmath.c index 157141f..1c5c25b 100644 --- a/redist/linmath.c +++ b/redist/linmath.c @@ -93,11 +93,6 @@ void quatsetnone(FLT * q) q[0] = 1; q[1] = 0; q[2] = 0; q[3] = 0; } -void quatsetidentity(FLT * q) -{ - q[0] = 1; q[1] = 0; q[2] = 0; q[3] = 1; -} - void quatcopy(FLT * qout, const FLT * qin) { qout[0] = qin[0]; @@ -447,7 +442,7 @@ void quatfrom2vectors(FLT *q, const FLT *src, const FLT *dest) // If dot == 1, vectors are the same if (d >= 1.0f) { - quatsetidentity(q); + quatsetnone(q); return; } if (d < (1e-6f - 1.0f)) -- cgit v1.2.3