From 5aa20d099b9fe7539050a5baa4c70b678aeab64e Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sun, 18 Mar 2018 02:45:09 -0400 Subject: Moving things over... still todo: * Make functions for changing temp configs. * Make functions for config_read_str but where it checks the temp one first. * Parse command-line options. --- src/survive_config.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/survive_config.c') diff --git a/src/survive_config.c b/src/survive_config.c index d923ba4..4ef2994 100644 --- a/src/survive_config.c +++ b/src/survive_config.c @@ -181,6 +181,36 @@ FLT config_read_float(config_group *cg, const char *tag, const FLT def) { return config_set_float(cg, tag, def); } +static config_entry * sc_search(SurviveContext * ctx, const char *tag ) +{ + config_entry *cv = find_config_entry(ctx->temporary_config_values, tag); + if( !cv ) cv = find_config_entry(ctx->global_config_values, tag); + return cv; +} + +FLT survive_config_readf( SurviveContext * ctx, const char *tag, FLT def ) +{ + config_entry * cv = sc_search( ctx, tag ); + if( !cv ) return def; + return cv->numeric.f; +} + +uint32_t survive_config_readi( SurviveContext * ctx, const char *tag, uint32_t def ) +{ + config_entry * cv = sc_search( ctx, tag ); + if( !cv ) return def; + return cv->numeric.i; +} + +const char * survive_config_reads( SurviveContext * ctx, const char *tag, const char *def ) +{ + config_entry * cv = sc_search( ctx, tag ); + if( !cv ) return def; + return cv->data; +} + + + // TODO: Do something better than this: #define CFG_MIN(x,y) ((x) < (y)? (x): (y)) -- cgit v1.2.3 From c44cca299fbea4196af125dfedd8e4d60f3ae0cc Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sun, 18 Mar 2018 19:48:25 -0400 Subject: Almost at a config interface. --- src/survive_config.c | 109 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 81 insertions(+), 28 deletions(-) (limited to 'src/survive_config.c') diff --git a/src/survive_config.c b/src/survive_config.c index 4ef2994..1a64828 100644 --- a/src/survive_config.c +++ b/src/survive_config.c @@ -181,34 +181,6 @@ FLT config_read_float(config_group *cg, const char *tag, const FLT def) { return config_set_float(cg, tag, def); } -static config_entry * sc_search(SurviveContext * ctx, const char *tag ) -{ - config_entry *cv = find_config_entry(ctx->temporary_config_values, tag); - if( !cv ) cv = find_config_entry(ctx->global_config_values, tag); - return cv; -} - -FLT survive_config_readf( SurviveContext * ctx, const char *tag, FLT def ) -{ - config_entry * cv = sc_search( ctx, tag ); - if( !cv ) return def; - return cv->numeric.f; -} - -uint32_t survive_config_readi( SurviveContext * ctx, const char *tag, uint32_t def ) -{ - config_entry * cv = sc_search( ctx, tag ); - if( !cv ) return def; - return cv->numeric.i; -} - -const char * survive_config_reads( SurviveContext * ctx, const char *tag, const char *def ) -{ - config_entry * cv = sc_search( ctx, tag ); - if( !cv ) return def; - return cv->data; -} - // TODO: Do something better than this: @@ -471,3 +443,84 @@ void config_read(SurviveContext* sctx, const char* path) { json_tag_value = NULL; } + + + +static config_entry * sc_search(SurviveContext * ctx, const char *tag ) +{ + config_entry *cv = find_config_entry(ctx->temporary_config_values, tag); + if( !cv ) cv = find_config_entry(ctx->global_config_values, tag); + return cv; +} + + + +FLT survive_configf( SurviveContext * ctx, const char *tag, char flags, FLT def ) +{ + if( !(flags & SC_OVERRIDE) ) + { + config_entry * cv = sc_search( ctx, tag ); + if( cv ) + return cv->numeric.f; + } + + //If override is flagged, or, we can't find the variable, ,continue on. + if( flags & SC_SETCONFIG ) + { + config_set_float( ctx->temporary_config_values, tag, def ); + config_set_float( ctx->global_config_values, tag, def ); + } + else if( flags & SC_SET ) + { + config_set_float( ctx->temporary_config_values, tag, def ); + } + + return def; +} + +uint32_t survive_configi( SurviveContext * ctx, const char *tag, char flags, uint32_t def ) +{ + if( !(flags & SC_OVERRIDE) ) + { + config_entry * cv = sc_search( ctx, tag ); + if( cv ) + return cv->numeric.i; + } + + //If override is flagged, or, we can't find the variable, ,continue on. + if( flags & SC_SETCONFIG ) + { + config_set_uint32( ctx->temporary_config_values, tag, def ); + config_set_uint32( ctx->global_config_values, tag, def ); + } + else if( flags & SC_SET ) + { + config_set_uint32( ctx->temporary_config_values, tag, def ); + } + + return def; +} + +const char * survive_configs( SurviveContext * ctx, const char *tag, char flags, const char *def ) +{ + if( !(flags & SC_OVERRIDE) ) + { + config_entry * cv = sc_search( ctx, tag ); + if( cv ) + return cv->data; + } + + //If override is flagged, or, we can't find the variable, ,continue on. + if( flags & SC_SETCONFIG ) + { + config_set_str( ctx->temporary_config_values, tag, def ); + config_set_str( ctx->global_config_values, tag, def ); + } + else if( flags & SC_SET ) + { + config_set_str( ctx->temporary_config_values, tag, def ); + } + + return def; +} + -- cgit v1.2.3 From 0996cfcee351bfd665f48a205d2f7fe37dec336c Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sun, 18 Mar 2018 22:00:55 -0400 Subject: Fix configuration system and fix race condition in survive_vive. --- src/survive_config.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/survive_config.c') diff --git a/src/survive_config.c b/src/survive_config.c index 1a64828..44933fa 100644 --- a/src/survive_config.c +++ b/src/survive_config.c @@ -449,7 +449,10 @@ void config_read(SurviveContext* sctx, const char* path) { static config_entry * sc_search(SurviveContext * ctx, const char *tag ) { config_entry *cv = find_config_entry(ctx->temporary_config_values, tag); - if( !cv ) cv = find_config_entry(ctx->global_config_values, tag); + if( !cv ) + { + cv = find_config_entry(ctx->global_config_values, tag); + } return cv; } -- cgit v1.2.3