aboutsummaryrefslogtreecommitdiff
path: root/src/survive_config.c
diff options
context:
space:
mode:
authorJoshua Allen <axlecrusher@gmail.com>2017-02-26 10:20:48 -0500
committerJoshua Allen <axlecrusher@gmail.com>2017-02-26 10:20:48 -0500
commitf78983a584768a54503535be0366b07c97738299 (patch)
tree27487cf0f60dbaccc8d4051bd20defc85b6f220f /src/survive_config.c
parentcab4ee6f89a661190b2bd80c30e42d5f45614f20 (diff)
downloadlibsurvive-f78983a584768a54503535be0366b07c97738299.tar.gz
libsurvive-f78983a584768a54503535be0366b07c97738299.tar.bz2
use json helpers
Diffstat (limited to 'src/survive_config.c')
-rw-r--r--src/survive_config.c28
1 files changed, 7 insertions, 21 deletions
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 <string.h>
#include <assert.h>
#include "survive_config.h"
+#include <json_helpers.h>
#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;i<count;++i) {
-// if (i>0) {
- 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);
}
};