diff options
author | Dave Davenport <qball@gmpclient.org> | 2017-03-28 17:33:43 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2017-03-28 17:33:43 +0200 |
commit | 5259eb11bc7327074511bc83595542fe616ae1b1 (patch) | |
tree | 34efbba69c837ca923a2f8607841f78a93e354a7 /source/xrmoptions.c | |
parent | 14b43523bef26208b20593533dd60786d046c469 (diff) |
Merge the configuration loading into something more simple (3)
Diffstat (limited to 'source/xrmoptions.c')
-rw-r--r-- | source/xrmoptions.c | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 5a910b19..189c0ee2 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -385,21 +385,61 @@ void config_parse_cmd_options ( void ) } } +static void __config_parser_set_property ( XrmOption *option, const Property *p ) +{ + if ( option->type == xrm_String ) + { + if ( p->type != P_STRING ) { + fprintf(stderr, "Option: %s needs to be set with a string.\n", option->name); + return; + } + if ( ( option )->mem != NULL ) { + g_free ( option->mem ); + option->mem = NULL; + } + *( option->value.str ) = g_strdup ( p->value.s ); + + // Memory + ( option )->mem = *( option->value.str ); + option->source = CONFIG_FILE_THEME; + } else if ( option->type == xrm_Number ) { + if ( p->type != P_INTEGER ){ + fprintf(stderr, "Option: %s needs to be set with a number.\n", option->name); + return; + } + *(option->value.snum) = p->value.i; + option->source = CONFIG_FILE_THEME; + } else if ( option->type == xrm_SNumber ) { + if ( p->type != P_INTEGER ){ + fprintf(stderr, "Option: %s needs to be set with a number.\n", option->name); + return; + } + *(option->value.num) = (unsigned int )(p->value.i); + option->source = CONFIG_FILE_THEME; + } else if ( option->type == xrm_Boolean ) { + if ( p->type != P_BOOLEAN ){ + fprintf(stderr, "Option: %s needs to be set with a boolean.\n", option->name); + return; + } + *(option->value.num) = (p->value.b); + option->source = CONFIG_FILE_THEME; + } +} -void config_parser_set_option ( char *option, char *value) +void config_parse_set_property ( const Property *p ) { for ( unsigned int i = 0; i < sizeof ( xrmOptions ) / sizeof ( XrmOption ); ++i ) { XrmOption *op = &( xrmOptions[i] ); - if ( g_strcmp0 ( op->name, option) == 0 ) { - config_parser_set ( op, value, CONFIG_FILE_THEME); + if ( g_strcmp0 ( op->name, p->name) == 0 ) { + __config_parser_set_property ( op, p ); return; } } for ( unsigned int i = 0; i < num_extra_options; ++i ) { XrmOption *op = &( extra_options[i] ); - if ( g_strcmp0 ( op->name, option) == 0 ) { - config_parser_set ( op, value, CONFIG_FILE_THEME); + if ( g_strcmp0 ( op->name, p->name) == 0 ) { + __config_parser_set_property ( op, p ); return; } } |