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

[Helper] Remove fixed key/values and accept keys with NULL as values.

This commit is contained in:
Dave Davenport 2018-10-17 22:41:20 +02:00
parent e8edc42f9d
commit f80e7d52bc
2 changed files with 10 additions and 12 deletions

View file

@ -1287,9 +1287,6 @@ char *helper_string_replace_if_exists ( char * string, ... )
GError *error = NULL; GError *error = NULL;
GHashTable *h; GHashTable *h;
h = g_hash_table_new ( g_str_hash, g_str_equal ); 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. // Add list from variable arguments.
va_list ap; va_list ap;
va_start ( ap, string ); va_start ( ap, string );
@ -1299,9 +1296,6 @@ char *helper_string_replace_if_exists ( char * string, ... )
break; break;
} }
char *value = va_arg ( ap, char * ); char *value = va_arg ( ap, char * );
if ( value == (char *) 0 ) {
break;
}
g_hash_table_insert ( h, key, value ); g_hash_table_insert ( h, key, value );
} }
va_end ( ap ); va_end ( ap );

View file

@ -159,26 +159,30 @@ int main ( int argc, char ** argv )
char *a; 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); printf("%s\n",a);
TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal -t some title blub -e aap") == 0); TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal -t some title blub -e aap") == 0);
g_free(a); 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); printf("%s\n",a);
TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal -e aap") == 0); TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal -e aap") == 0);
g_free(a); g_free(a);
a = helper_string_replace_if_exists ( "{name} [<span weight='light' size='small'><i>({category})</i></span>]", "{name}", "Librecad", "{category}", "Desktop app", NULL ); a = helper_string_replace_if_exists ( "{name} [<span weight='light' size='small'><i>({category})</i></span>]", "{name}", "Librecad", "{category}", "Desktop app", "{terminal}", "rofi-sensible-terminal", NULL );
printf("%s\n",a); printf("%s\n",a);
TASSERT ( g_utf8_collate ( a, "Librecad <span weight='light' size='small'><i>(Desktop app)</i></span>") == 0); TASSERT ( g_utf8_collate ( a, "Librecad <span weight='light' size='small'><i>(Desktop app)</i></span>") == 0);
g_free(a); g_free(a);
a = helper_string_replace_if_exists ( "{name}[ <span weight='light' size='small'><i>({category})</i></span>]", "{name}", "Librecad", NULL ); a = helper_string_replace_if_exists ( "{name}[ <span weight='light' size='small'><i>({category})</i></span>]", "{name}", "Librecad", "{terminal}", "rofi-sensible-terminal", NULL );
TASSERT ( g_utf8_collate ( a, "Librecad") == 0); TASSERT ( g_utf8_collate ( a, "Librecad") == 0);
g_free(a); 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); printf("%s\n",a);
TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal some title blub -e aap") == 0); TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal some title blub -e aap") == 0);
g_free(a); 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); printf("%s\n",a);
TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal -e aap") == 0); TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal -e aap") == 0);
g_free(a); g_free(a);