diff options
author | Dave Davenport <qball@blame.services> | 2021-06-27 12:21:26 +0200 |
---|---|---|
committer | Dave Davenport <qball@blame.services> | 2021-06-27 12:21:26 +0200 |
commit | 067a3b82ade2ca8906ac46105358aaf4f272f77e (patch) | |
tree | 5dc566547e0ff00c619e4beb26d8eb9072c2e6bd | |
parent | 33248f511ca9a468cd2a36182a8a4b5c9f22153b (diff) |
[Config system] Add a bit of a hack to auto-add commandline options.
For new config system.
-rw-r--r-- | include/rofi.h | 1 | ||||
-rw-r--r-- | source/helper.c | 4 | ||||
-rw-r--r-- | source/rofi.c | 19 | ||||
-rw-r--r-- | source/xrmoptions.c | 53 |
4 files changed, 67 insertions, 10 deletions
diff --git a/include/rofi.h b/include/rofi.h index 5c882d0b..69564ebc 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -70,6 +70,7 @@ const Mode * rofi_get_mode ( unsigned int index ); */ void rofi_add_error_message ( GString *str ); +void rofi_clear_error_messages ( void ); /** * @param code the code to return * diff --git a/source/helper.c b/source/helper.c index 47c8a11f..efa59104 100644 --- a/source/helper.c +++ b/source/helper.c @@ -66,9 +66,9 @@ const char *const monitor_position_entries[] = { "on monitor that has mouse pointer" }; /** copy of the argc for use in commandline argument parser. */ -static int stored_argc = 0; +int stored_argc = 0; /** copy of the argv pointer for use in the commandline argument parser */ -static char **stored_argv = NULL; +char **stored_argv = NULL; char *helper_string_replace_if_exists_v ( char * string, GHashTable *h ); diff --git a/source/rofi.c b/source/rofi.c index b2e62805..a94d4611 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -91,6 +91,17 @@ void rofi_add_error_message ( GString *str ) { list_of_error_msgs = g_list_append ( list_of_error_msgs, str ); } +void rofi_clear_error_messages ( void ) +{ + if ( list_of_error_msgs ) { + for ( GList *iter = g_list_first ( list_of_error_msgs ); + iter != NULL; iter = g_list_next ( iter ) ) { + g_string_free ( (GString *) iter->data, TRUE ); + } + g_list_free ( list_of_error_msgs ); + list_of_error_msgs = NULL; + } +} /** Path to the configuration file */ G_MODULE_EXPORT char *config_path = NULL; @@ -457,13 +468,7 @@ static void cleanup () g_free ( config_path ); - if ( list_of_error_msgs ) { - for ( GList *iter = g_list_first ( list_of_error_msgs ); - iter != NULL; iter = g_list_next ( iter ) ) { - g_string_free ( (GString *) iter->data, TRUE ); - } - g_list_free ( list_of_error_msgs ); - } + rofi_clear_error_messages(); if ( rofi_theme ) { rofi_theme_free ( rofi_theme ); diff --git a/source/xrmoptions.c b/source/xrmoptions.c index aba59ee4..7f377852 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -27,6 +27,7 @@ /** Log domain for this module */ #define G_LOG_DOMAIN "XrmOptions" +#include <ctype.h> #include <config.h> #include <stdio.h> #include <stdlib.h> @@ -301,6 +302,8 @@ static void config_parse_cmd_option ( XrmOption *option ) break; } g_free ( key ); + + } void config_parse_cmd_options ( void ) @@ -313,6 +316,55 @@ void config_parse_cmd_options ( void ) XrmOption *op = &( extra_options[i] ); config_parse_cmd_option ( op ); } + + + /** copy of the argc for use in commandline argument parser. */ + extern int stored_argc; + /** copy of the argv pointer for use in the commandline argument parser */ + extern char **stored_argv; + for ( int in = 1; in < (stored_argc-1) ; in ++ ) { + if ( stored_argv[in][0] == '-' ) { + /** TODO: This is a hack, and should be fixed in a nicer way. */ + char **tokens = g_strsplit(stored_argv[in], "-", 3); + int count = 1; + for ( int j = 1; tokens && tokens[j]; j++ ){ + count++; + } + if ( count > 2 && g_strcmp0(tokens[1], "no") != 0 ){ + GString *str = g_string_new("configuration { "); + for ( int j = 1; j < (count-1); j++ ){ + g_string_append_printf(str, "%s { ", tokens[j]); + } + g_string_append_printf ( str, "%s: %s;", tokens[count-1], stored_argv[in+1]); + for ( int j = 0; j < (count-1); j++ ){ + g_string_append(str, " } "); + } + if ( rofi_theme_parse_string(str->str) == 1 ) { + /** Failed to parse, try again as string. */ + rofi_clear_error_messages(); + g_string_assign ( str, "configuration { "); + for ( int j = 1; j < (count-1); j++ ){ + g_string_append_printf(str, "%s { ", tokens[j]); + } + char *esc = g_strescape(stored_argv[in+1], NULL); + g_string_append_printf ( str, "%s: \"%s\";", tokens[count-1], esc); + g_free(esc); + printf("%s %s\r\n", stored_argv[in], stored_argv[in+1]); + + for ( int j = 0; j < (count-1); j++ ){ + g_string_append(str, " } "); + } + printf("str: %s\n", str->str); + if ( rofi_theme_parse_string(str->str) == 1 ) { + printf("failed\n"); + } + } + g_string_free(str,TRUE); + in++; + } + g_strfreev(tokens); + } + } } static gboolean __config_parser_set_property ( XrmOption *option, const Property *p, char **error ) @@ -407,7 +459,6 @@ gboolean config_parse_set_property ( const Property *p, char **error ) for ( GList *iter = g_list_first ( extra_parsed_options) ; iter != NULL; iter = g_list_next ( iter ) ) { if ( g_strcmp0(((Property *)(iter->data))->name, p->name ) == 0 ){ - rofi_theme_property_free ( (Property *)(iter->data)); iter->data = (void *)rofi_theme_property_copy ( p ) ; return TRUE; |