From f78983a584768a54503535be0366b07c97738299 Mon Sep 17 00:00:00 2001 From: Joshua Allen Date: Sun, 26 Feb 2017 10:20:48 -0500 Subject: use json helpers --- src/survive_config.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'src/survive_config.c') diff --git a/src/survive_config.c b/src/survive_config.c index b18f083..6afe3d1 100644 --- a/src/survive_config.c +++ b/src/survive_config.c @@ -1,8 +1,8 @@ // (C) 2017 <>< Joshua Allen, Under MIT/x11 License. - #include #include #include "survive_config.h" +#include #define MAX_CONFIG_ENTRIES 100 @@ -227,22 +227,8 @@ const FLT* config_set_float_a(const char *tag, const FLT* values, uint8_t count) return values; } -void write_float_array(FILE* f, char* tag, FLT* v, uint8_t count) { - uint8_t i = 0; - printf("save float array\n"); - - fprintf(f, "\"%s\":[", tag); - for (i=0;i0) { - fprintf(f, "\"%f\",", v[i]); -// } else { -// fprintf(f, "\"%f\"", v[i]); -// } - } - - fseek(f,-1,SEEK_CUR); - fprintf(f, "]\n"); - +void _json_write_float_array(FILE* f, const char* tag, FLT* v, uint8_t count) { + json_write_double_array(f,tag,v,count); } void config_save(const char* path) { @@ -252,13 +238,13 @@ void config_save(const char* path) { for (i=0;i<=used_entries;++i) { if (config_values[i].type == CONFIG_FLOAT) { - fprintf(f, "\"%s\":\"%F\"\n", config_values[i].tag, config_values[i].numeric.f); + json_write_float(f, config_values[i].tag, config_values[i].numeric.f); } else if (config_values[i].type == CONFIG_UINT32) { - fprintf(f, "\"%s\":\"%d\"\n", config_values[i].tag, config_values[i].numeric.i); + json_write_uint32(f, config_values[i].tag, config_values[i].numeric.i); } else if (config_values[i].type == CONFIG_STRING) { - fprintf(f, "\"%s\":\"%s\"\n", config_values[i].tag, config_values[i].data); + json_write_str(f, config_values[i].tag, config_values[i].data); } else if (config_values[i].type == CONFIG_FLOAT_ARRAY) { - write_float_array(f, config_values[i].tag, (FLT*)config_values[i].data, config_values[i].elements); + _json_write_float_array(f, config_values[i].tag, (FLT*)config_values[i].data, config_values[i].elements); } }; -- cgit v1.2.3