1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Do better error reporting on configuration entries in rasi format.

This commit is contained in:
Dave Davenport 2017-06-20 18:10:18 +02:00
parent 8375fbb513
commit da00848416
5 changed files with 63 additions and 36 deletions

View file

@ -160,7 +160,10 @@ char ** config_parser_return_display_help ( unsigned int *length );
* Sets both the static as dynamic config option.
*
* @param p Property to set
* @param error Error msg when not found.
*
* @returns true when failed to set property.
*/
void config_parse_set_property ( const Property *p );
gboolean config_parse_set_property ( const Property *p, char **error );
/* @}*/
#endif

View file

@ -275,18 +275,32 @@ T_NAME_PREFIX t_entry_name_path T_BOPEN t_property_list_optional T_BCLOSE
T_PDEFAULTS T_BOPEN t_property_list_optional T_BCLOSE {
rofi_theme_widget_add_properties ( rofi_theme, $3);
}
| T_CONFIGURATION T_BOPEN t_property_list_optional T_BCLOSE {
GHashTableIter iter;
g_hash_table_iter_init ( &iter, $3 );
gpointer key,value;
while ( g_hash_table_iter_next ( &iter, &key, &value ) ) {
Property *p = (Property *) value;
config_parse_set_property ( p );
}
g_hash_table_destroy ( $3 );
| T_CONFIGURATION T_BOPEN t_config_property_list_optional T_BCLOSE {
// Dummy at this point.
}
;
t_config_property_list_optional
: %empty {}
| t_config_property_list
;
t_config_property_list
: t_config_property {
}
| t_config_property_list t_config_property {
};
t_config_property
: t_property {
char *error = NULL;
if ( config_parse_set_property ( $1, &error ) ) {
// TODO Generate error.
yyerror ( &(@$), @$.filename, error );
g_free(error);
}
}
/**
* properties
*/

View file

@ -82,7 +82,7 @@ void rofi_add_error_message ( GString *str )
}
/** Path to the configuration file */
G_MODULE_EXPORT char *config_path = NULL;
G_MODULE_EXPORT char *config_path = NULL;
G_MODULE_EXPORT char *config_path_new = NULL;
/** Array holding all activated modi. */
Mode **modi = NULL;
@ -324,7 +324,8 @@ static void help ( G_GNUC_UNUSED int argc, char **argv )
if ( find_arg ( "-no-config" ) < 0 ) {
if ( config_path_new ) {
printf ( " Configuration file: %s%s%s\n", is_term ? color_bold : "", config_path_new, is_term ? color_reset : "" );
} else {
}
else {
printf ( " Configuration file: %s%s%s\n", is_term ? color_bold : "", config_path, is_term ? color_reset : "" );
}
}
@ -771,8 +772,8 @@ int main ( int argc, char *argv[] )
if ( find_arg ( "-config" ) < 0 ) {
const char *cpath = g_get_user_config_dir ();
if ( cpath ) {
config_path = g_build_filename ( cpath, "rofi", "config", NULL );
config_path_new = g_strconcat ( config_path, ".rasi" , NULL );
config_path = g_build_filename ( cpath, "rofi", "config", NULL );
config_path_new = g_strconcat ( config_path, ".rasi", NULL );
}
}
else {
@ -780,7 +781,8 @@ int main ( int argc, char *argv[] )
find_arg_str ( "-config", &c );
if ( g_str_has_suffix ( c, ".rasi" ) ) {
config_path_new = rofi_expand_path ( c );
} else {
}
else {
config_path = rofi_expand_path ( c );
}
}
@ -822,12 +824,13 @@ int main ( int argc, char *argv[] )
g_free ( etc );
// Load in config from X resources.
config_parse_xresource_options ( xcb );
if ( config_path_new && g_file_test ( config_path_new, G_FILE_TEST_IS_REGULAR) ) {
if ( rofi_theme_parse_file ( config_path_new) ) {
if ( config_path_new && g_file_test ( config_path_new, G_FILE_TEST_IS_REGULAR ) ) {
if ( rofi_theme_parse_file ( config_path_new ) ) {
rofi_theme_free ( rofi_theme );
rofi_theme = NULL;
}
} else {
}
else {
config_parse_xresource_options_file ( config_path );
}
}

View file

@ -786,15 +786,15 @@ char * rofi_theme_parse_prepare_file ( const char *file, const char *parent_file
{
char *filename = rofi_expand_path ( file );
// If no absolute path specified, expand it.
if ( parent_file != NULL && ! g_path_is_absolute ( filename ) ) {
if ( parent_file != NULL && !g_path_is_absolute ( filename ) ) {
char *basedir = g_path_get_dirname ( parent_file );
char *path = g_build_filename ( basedir, filename, NULL );
g_free ( filename);
char *path = g_build_filename ( basedir, filename, NULL );
g_free ( filename );
filename = path;
g_free ( basedir );
}
GFile *gf = g_file_new_for_path ( filename );
g_free(filename);
g_free ( filename );
filename = g_file_get_path ( gf );
g_object_unref ( gf );

View file

@ -368,12 +368,13 @@ void config_parse_cmd_options ( void )
}
}
static void __config_parser_set_property ( XrmOption *option, const Property *p )
static gboolean __config_parser_set_property ( XrmOption *option, const Property *p, char **error )
{
extern const char *PropertyTypeName[];
if ( option->type == xrm_String ) {
if ( p->type != P_STRING ) {
g_warning ( "Option: %s needs to be set with a string.", option->name );
return;
*error = g_strdup_printf ( "Option: %s needs to be set with a string not a %s.", option->name, PropertyTypeName[p->type] );
return TRUE;
}
if ( ( option )->mem != NULL ) {
g_free ( option->mem );
@ -387,46 +388,52 @@ static void __config_parser_set_property ( XrmOption *option, const Property *p
}
else if ( option->type == xrm_Number ) {
if ( p->type != P_INTEGER ) {
g_warning ( "Option: %s needs to be set with a number.", option->name );
return;
*error = g_strdup_printf ( "Option: %s needs to be set with a numger not a %s.", option->name, PropertyTypeName[p->type] );
return TRUE;
}
*( option->value.snum ) = p->value.i;
option->source = CONFIG_FILE_THEME;
}
else if ( option->type == xrm_SNumber ) {
if ( p->type != P_INTEGER ) {
g_warning ( "Option: %s needs to be set with a number.", option->name );
return;
*error = g_strdup_printf ( "Option: %s needs to be set with a numger not a %s.", option->name, PropertyTypeName[p->type] );
return TRUE;
}
*( option->value.num ) = (unsigned int ) ( p->value.i );
option->source = CONFIG_FILE_THEME;
}
else if ( option->type == xrm_Boolean ) {
if ( p->type != P_BOOLEAN ) {
g_warning ( "Option: %s needs to be set with a boolean.", option->name );
return;
*error = g_strdup_printf ( "Option: %s needs to be set with a boolean not a %s.", option->name, PropertyTypeName[p->type] );
return TRUE;
}
*( option->value.num ) = ( p->value.b );
option->source = CONFIG_FILE_THEME;
}
else {
// TODO add type
*error = g_strdup_printf ( "Option: %s is not of a supported type: %s.", option->name, PropertyTypeName[p->type] );
return TRUE;
}
return FALSE;
}
void config_parse_set_property ( const Property *p )
gboolean config_parse_set_property ( const Property *p, char **error )
{
for ( unsigned int i = 0; i < sizeof ( xrmOptions ) / sizeof ( XrmOption ); ++i ) {
XrmOption *op = &( xrmOptions[i] );
if ( g_strcmp0 ( op->name, p->name ) == 0 ) {
__config_parser_set_property ( op, p );
return;
return __config_parser_set_property ( op, p, error );
}
}
for ( unsigned int i = 0; i < num_extra_options; ++i ) {
XrmOption *op = &( extra_options[i] );
if ( g_strcmp0 ( op->name, p->name ) == 0 ) {
__config_parser_set_property ( op, p );
return;
return __config_parser_set_property ( op, p, error );
}
}
*error = g_strdup_printf ( "Option: %s is not found.", p->name );
return TRUE;
}
void config_xresource_free ( void )