aboutsummaryrefslogtreecommitdiff
path: root/src/survive_config.c
diff options
context:
space:
mode:
authorcnlohr <lohr85@gmail.com>2018-03-18 19:48:25 -0400
committercnlohr <lohr85@gmail.com>2018-03-18 22:21:59 -0400
commit36e8d2425bfe48fd25b041fa2a301e2ed2bb3fa3 (patch)
tree42b402a51d13252398ac64f5308b4d6dad6820cb /src/survive_config.c
parent179d8a02e231fe853831cdf886c9196929303adb (diff)
downloadlibsurvive-36e8d2425bfe48fd25b041fa2a301e2ed2bb3fa3.tar.gz
libsurvive-36e8d2425bfe48fd25b041fa2a301e2ed2bb3fa3.tar.bz2
Almost at a config interface.
Diffstat (limited to 'src/survive_config.c')
-rw-r--r--src/survive_config.c109
1 files changed, 81 insertions, 28 deletions
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;
+}
+