From f80e7d52bcd10d1220be571e103e119bae4ad437 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Wed, 17 Oct 2018 22:41:20 +0200 Subject: [PATCH] [Helper] Remove fixed key/values and accept keys with NULL as values. --- source/helper.c | 6 ------ test/helper-test.c | 16 ++++++++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/source/helper.c b/source/helper.c index 6722cf50..788eb489 100644 --- a/source/helper.c +++ b/source/helper.c @@ -1287,9 +1287,6 @@ char *helper_string_replace_if_exists ( char * string, ... ) GError *error = NULL; GHashTable *h; h = g_hash_table_new ( g_str_hash, g_str_equal ); - // By default, we insert terminal and ssh-client - g_hash_table_insert ( h, "{terminal}", config.terminal_emulator ); - g_hash_table_insert ( h, "{ssh-client}", config.ssh_client ); // Add list from variable arguments. va_list ap; va_start ( ap, string ); @@ -1299,9 +1296,6 @@ char *helper_string_replace_if_exists ( char * string, ... ) break; } char *value = va_arg ( ap, char * ); - if ( value == (char *) 0 ) { - break; - } g_hash_table_insert ( h, key, value ); } va_end ( ap ); diff --git a/test/helper-test.c b/test/helper-test.c index 052af651..5ed575e5 100644 --- a/test/helper-test.c +++ b/test/helper-test.c @@ -159,26 +159,30 @@ int main ( int argc, char ** argv ) char *a; - a = helper_string_replace_if_exists ( "{terminal} [-t {title} blub ]-e {cmd}", "{cmd}", "aap", "{title}", "some title", NULL); + a = helper_string_replace_if_exists ( "{terminal} [-t {title} blub ]-e {cmd}", "{cmd}", "aap", "{title}", "some title", "{terminal}", "rofi-sensible-terminal", NULL); printf("%s\n",a); TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal -t some title blub -e aap") == 0); g_free(a); - a = helper_string_replace_if_exists ( "{terminal} [-t {title} blub ]-e {cmd}", "{cmd}", "aap", NULL); + a = helper_string_replace_if_exists ( "{terminal} [-t {title} blub ]-e {cmd}", "{cmd}", "aap", "{terminal}", "rofi-sensible-terminal", NULL); printf("%s\n",a); TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal -e aap") == 0); g_free(a); - a = helper_string_replace_if_exists ( "{name} [({category})]", "{name}", "Librecad", "{category}", "Desktop app", NULL ); + a = helper_string_replace_if_exists ( "{name} [({category})]", "{name}", "Librecad", "{category}", "Desktop app", "{terminal}", "rofi-sensible-terminal", NULL ); printf("%s\n",a); TASSERT ( g_utf8_collate ( a, "Librecad (Desktop app)") == 0); g_free(a); - a = helper_string_replace_if_exists ( "{name}[ ({category})]", "{name}", "Librecad", NULL ); + a = helper_string_replace_if_exists ( "{name}[ ({category})]", "{name}", "Librecad", "{terminal}", "rofi-sensible-terminal", NULL ); TASSERT ( g_utf8_collate ( a, "Librecad") == 0); g_free(a); - a = helper_string_replace_if_exists ( "{terminal} [{title} blub ]-e {cmd}", "{cmd}", "aap", "{title}", "some title", NULL); + a = helper_string_replace_if_exists ( "{terminal} [{title} blub ]-e {cmd}", "{cmd}", "aap", "{title}", "some title", "{terminal}", "rofi-sensible-terminal", NULL); printf("%s\n",a); TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal some title blub -e aap") == 0); g_free(a); - a = helper_string_replace_if_exists ( "{terminal} [{title} blub ]-e {cmd}", "{cmd}", "aap", "{title}", NULL, NULL); + a = helper_string_replace_if_exists ( "{terminal} [{title} blub ]-e {cmd}", + "{cmd}", "aap", + "{title}", NULL, + "{terminal}", "rofi-sensible-terminal", + NULL); printf("%s\n",a); TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal -e aap") == 0); g_free(a);