aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Allen <axlecrusher@gmail.com>2017-03-07 21:39:40 -0500
committerJoshua Allen <axlecrusher@gmail.com>2017-03-07 21:39:40 -0500
commit57e82519b4844620851784e7682a2c562cb06d47 (patch)
treee6ee2e9d0cb2c3d023ee982b04fcb5af6ae0b0af
parent53dfb546789773b173deb34ef0429aaa0d00e0a9 (diff)
downloadlibsurvive-57e82519b4844620851784e7682a2c562cb06d47.tar.gz
libsurvive-57e82519b4844620851784e7682a2c562cb06d47.tar.bz2
add init and destroy functions for config_entry
-rw-r--r--src/survive_config.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/survive_config.c b/src/survive_config.c
index b59bd85..f30bf87 100644
--- a/src/survive_config.c
+++ b/src/survive_config.c
@@ -9,8 +9,6 @@
#define MAX_CONFIG_ENTRIES 100
#define MAX_LIGHTHOUSES 2
-
-
config_group global_config_values;
config_group lh_config[MAX_LIGHTHOUSES]; //lighthouse configs
@@ -19,6 +17,18 @@ config_group lh_config[MAX_LIGHTHOUSES]; //lighthouse configs
//static FILE *config_file = NULL;
const FLT* config_set_float_a(config_group *cg, const char *tag, const FLT* values, uint8_t count);
+void init_config_entry(config_entry* ce) {
+ ce->data = NULL;
+ ce->tag = NULL;
+ ce->type = CONFIG_UNKNOWN;
+ ce->elements = 0;
+}
+
+void destroy_config_entry(config_entry* ce) {
+ if (ce->tag!=NULL) free(ce->tag);
+ if (ce->data!=NULL) free(ce->data);
+}
+
void init_config_group(config_group *cg, uint16_t count) {
uint16_t i = 0;
cg->config_entries = malloc(count*sizeof(config_entry));
@@ -26,10 +36,7 @@ void init_config_group(config_group *cg, uint16_t count) {
cg->max_entries = count;
for (i=0;i<count;++i) {
- cg->config_entries[i].data = NULL;
- cg->config_entries[i].tag = NULL;
- cg->config_entries[i].type = CONFIG_UNKNOWN;
- cg->config_entries[i].elements = 0;
+ init_config_entry(cg->config_entries+i);
}
}
@@ -43,10 +50,7 @@ void resize_config_group(config_group *cg, uint16_t count) {
cg->config_entries = ptr;
for (i=cg->max_entries;i<count;++i) {
- cg->config_entries[i].data = NULL;
- cg->config_entries[i].tag = NULL;
- cg->config_entries[i].type = CONFIG_UNKNOWN;
- cg->config_entries[i].elements = 0;
+ init_config_entry(cg->config_entries+i);
}
cg->max_entries = count;