Merge the configuration loading into something more simple (3)

This commit is contained in:
Dave Davenport 2017-03-28 17:33:43 +02:00
parent 14b43523be
commit 5259eb11bc
8 changed files with 54 additions and 30 deletions

View File

@ -4,6 +4,7 @@
#include <cairo.h> #include <cairo.h>
#include <widgets/widget.h> #include <widgets/widget.h>
#include <settings.h> #include <settings.h>
#include "theme.h"
/** Style of text highlight */ /** Style of text highlight */
typedef enum typedef enum

View File

@ -1,6 +1,7 @@
#ifndef ROFI_XRMOPTIONS_H #ifndef ROFI_XRMOPTIONS_H
#define ROFI_XRMOPTIONS_H #define ROFI_XRMOPTIONS_H
#include "xcb.h" #include "xcb.h"
#include "theme.h"
// Big thanks to Sean Pringle for this code. // Big thanks to Sean Pringle for this code.
/** /**
@ -139,9 +140,8 @@ char ** config_parser_return_display_help ( unsigned int *length );
* *
* Sets both the static as dynamic config option. * Sets both the static as dynamic config option.
* *
* @param option Option to set. * @param p Property to set
* @param value Value to set it too
*/ */
void config_parser_set_option ( char *option, char *value); void config_parse_set_property ( const Property *p);
/* @}*/ /* @}*/
#endif #endif

View File

@ -139,24 +139,7 @@ NAME_PREFIX name_path BOPEN optional_properties BCLOSE
gpointer key,value; gpointer key,value;
while ( g_hash_table_iter_next ( &iter, &key, &value ) ) { while ( g_hash_table_iter_next ( &iter, &key, &value ) ) {
Property *p = (Property *) value; Property *p = (Property *) value;
switch ( p ->type ) config_parse_set_property ( p );
{
case P_STRING:
config_parser_set_option ( p->name, p->value.s);
break;
case P_BOOLEAN:
config_parser_set_option ( p->name, p->value.b?"true":"false");
break;
case P_INTEGER:
{
char *str = g_strdup_printf("%d", p->value.i);
config_parser_set_option ( p->name, str );
g_free(str);
}
default:
break;
}
} }
} }
; ;

View File

@ -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 ) { for ( unsigned int i = 0; i < sizeof ( xrmOptions ) / sizeof ( XrmOption ); ++i ) {
XrmOption *op = &( xrmOptions[i] ); XrmOption *op = &( xrmOptions[i] );
if ( g_strcmp0 ( op->name, option) == 0 ) { if ( g_strcmp0 ( op->name, p->name) == 0 ) {
config_parser_set ( op, value, CONFIG_FILE_THEME); __config_parser_set_property ( op, p );
return; return;
} }
} }
for ( unsigned int i = 0; i < num_extra_options; ++i ) { for ( unsigned int i = 0; i < num_extra_options; ++i ) {
XrmOption *op = &( extra_options[i] ); XrmOption *op = &( extra_options[i] );
if ( g_strcmp0 ( op->name, option) == 0 ) { if ( g_strcmp0 ( op->name, p->name) == 0 ) {
config_parser_set ( op, value, CONFIG_FILE_THEME); __config_parser_set_property ( op, p );
return; return;
} }
} }

View File

@ -23,7 +23,7 @@ unsigned int test =0;
} \ } \
} }
void config_parser_set_option ( const char *k, const char *v) void config_parse_set_property ( const void *p )
{ {
} }
char * rofi_expand_path ( const char *path ) char * rofi_expand_path ( const char *path )

View File

@ -22,7 +22,7 @@ unsigned int test =0;
abort ( ); \ abort ( ); \
} \ } \
} }
void config_parser_set_option ( const char *k, const char *v) void config_parse_set_property ( const void *p )
{ {
} }
void rofi_add_error_message ( GString *msg ) void rofi_add_error_message ( GString *msg )

View File

@ -22,7 +22,7 @@ unsigned int normal_window_mode = 0;
#include "view.h" #include "view.h"
void config_parser_set_option ( const char *k, const char *v) void config_parse_set_property ( void *p )
{ {
} }

View File

@ -12,7 +12,7 @@ unsigned int test =0;
assert ( a ); \ assert ( a ); \
printf ( "Test %3i passed (%s)\n", ++test, # a ); \ printf ( "Test %3i passed (%s)\n", ++test, # a ); \
} }
void config_parser_set_option ( const char *k, const char *v) void config_parse_set_property ( const void *p )
{ {
} }
void rofi_add_error_message ( GString *msg ) void rofi_add_error_message ( GString *msg )