diff options
author | Dave Davenport <qball@gmpclient.org> | 2016-06-28 23:34:07 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2016-06-28 23:34:07 +0200 |
commit | 7c9f5e01fd3250cfe1c9bcb83f1d87038fe867b5 (patch) | |
tree | 51c1f5443b4c5bb39e56df8e6bc1cff25639eb86 /source | |
parent | 9f25a975ae97df5cbb050825d157f221a9e88110 (diff) |
Fix tests and crash.
Diffstat (limited to 'source')
-rw-r--r-- | source/dialogs/dmenu.c | 40 | ||||
-rw-r--r-- | source/dialogs/window.c | 3 |
2 files changed, 41 insertions, 2 deletions
diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index ebb0b9cd..6fe27791 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -87,6 +87,9 @@ typedef struct unsigned int cmd_list_length; unsigned int only_selected; unsigned int selected_count; + + gchar **columns; + gchar *column_separator; } DmenuModePrivateData; static char **get_dmenu ( DmenuModePrivateData *pd, FILE *fd, unsigned int *length ) @@ -173,6 +176,34 @@ static void parse_ranges ( char *input, struct range_pair **list, unsigned int * } } +static gchar * dmenu_format_output_string ( const DmenuModePrivateData *pd, const char *input ) +{ + if ( pd->columns == NULL ) { + return g_strdup ( input ); + } + char *retv = NULL; + char ** splitted = g_regex_split_simple ( pd->column_separator, input, G_REGEX_CASELESS, 00 ); + uint32_t ns = 0; + for (; splitted && splitted[ns]; ns++ ) { + ; + } + for ( uint32_t i = 0; pd->columns && pd->columns[i]; i++ ) { + unsigned int index = (unsigned int ) g_ascii_strtoull ( pd->columns[i], NULL, 10 ); + if ( index < ns && index > 0 ) { + if ( retv == NULL ) { + retv = g_strdup ( splitted[index - 1] ); + } + else { + gchar *t = g_strjoin ( "\t", retv, splitted[index - 1], NULL ); + g_free ( retv ); + retv = t; + } + } + } + g_strfreev ( splitted ); + return retv ? retv : g_strdup ( "" ); +} + static char *get_display_data ( const Mode *data, unsigned int index, int *state, int get_entry ) { Mode *sw = (Mode *) data; @@ -194,7 +225,7 @@ static char *get_display_data ( const Mode *data, unsigned int index, int *state if ( pd->do_markup ) { *state |= MARKUP; } - return get_entry ? g_strdup ( retv[index] ) : NULL; + return get_entry ? dmenu_format_output_string ( pd, retv[index] ) : NULL; } /** @@ -341,6 +372,13 @@ static int dmenu_mode_init ( Mode *sw ) if ( fd != NULL ) { fclose ( fd ); } + + gchar *columns = NULL; + if ( find_arg_str ( "-display-columns", &columns ) ) { + pd->columns = g_strsplit ( columns, ",", 0 ); + pd->column_separator = "\t"; + find_arg_str ( "-display-column-separator", &pd->column_separator ); + } return TRUE; } diff --git a/source/dialogs/window.c b/source/dialogs/window.c index 08cb090c..5fda3561 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -365,7 +365,8 @@ static int window_match ( const Mode *sw, GRegex **tokens, unsigned int index ) static unsigned int window_mode_get_num_entries ( const Mode *sw ) { const ModeModePrivateData *pd = (const ModeModePrivateData *) mode_get_private_data ( sw ); - return pd->ids->len; + + return pd->ids?pd->ids->len:0; } /** * Small helper function to find the right entry in the ewmh reply. |