From 498fadc735df509ef0a864db1e93d2120d8eb9ee Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sun, 22 May 2016 17:47:34 +0200 Subject: [PATCH] Remove the is_ascii mess. --- include/helper.h | 8 +++--- include/mode-private.h | 6 +---- include/mode.h | 14 +---------- include/view-internal.h | 1 - source/dialogs/combi.c | 21 ++++------------ source/dialogs/dmenu.c | 23 ++++++------------ source/dialogs/drun.c | 25 ++++--------------- source/dialogs/run.c | 11 ++------- source/dialogs/script.c | 11 ++------- source/dialogs/ssh.c | 20 ++------------- source/dialogs/window.c | 35 +++++--------------------- source/helper.c | 43 +++++++++++++------------------- source/mode.c | 10 ++------ source/view.c | 54 +++-------------------------------------- 14 files changed, 59 insertions(+), 223 deletions(-) diff --git a/include/helper.h b/include/helper.h index cca31cc0..e48b6d7f 100644 --- a/include/helper.h +++ b/include/helper.h @@ -32,8 +32,8 @@ int helper_parse_setup ( char * string, char ***output, int *length, ... ); * * @returns a newly allocated 2 dimensional array of strings. */ -char **tokenize ( const char *input, int case_sensitive ); -void tokenize_free ( char ** tokens ); +GRegex **tokenize ( const char *input, int case_sensitive ); +void tokenize_free ( GRegex ** tokens ); /** * @param key The key to search for @@ -97,7 +97,7 @@ int find_arg ( const char * const key ); * * @returns 1 when matches, 0 otherwise */ -int token_match ( char **tokens, const char *input, int not_ascii, int case_sensitive ); +int token_match ( GRegex **tokens, const char *input); /** * @param cmd The command to execute. * @@ -160,6 +160,6 @@ unsigned int levenshtein ( const char *needle, const char *haystack ); */ char * rofi_force_utf8 ( gchar *data ); char * rofi_latin_to_utf8_strdup ( const char *input, gssize length ); -PangoAttrList *token_match_get_pango_attr ( char **tokens, const char *input, PangoAttrList *retv ); +PangoAttrList *token_match_get_pango_attr ( GRegex **tokens, const char *input, PangoAttrList *retv ); /*@}*/ #endif // ROFI_HELPER_H diff --git a/include/mode-private.h b/include/mode-private.h index 7747de0a..530827e8 100644 --- a/include/mode-private.h +++ b/include/mode-private.h @@ -17,7 +17,7 @@ typedef char * ( *_mode_get_completion )( const Mode *sw, unsigned int selected_ * * @returns 1 when it matches, 0 if not. */ -typedef int ( *_mode_token_match )( const Mode *data, char **tokens, int not_ascii, int case_sensitive, unsigned int index ); +typedef int ( *_mode_token_match )( const Mode *data, GRegex **tokens, unsigned int index ); typedef int ( *__mode_init )( Mode *sw ); @@ -27,8 +27,6 @@ typedef void ( *__mode_destroy )( Mode *sw ); typedef ModeMode ( *_mode_result )( Mode *sw, int menu_retv, char **input, unsigned int selected_line ); -typedef int ( *_mode_is_not_ascii )( const Mode *sw, unsigned int index ); - /** * Structure defining a switcher. * It consists of a name, callback and if enabled @@ -50,8 +48,6 @@ struct rofi_mode __mode_destroy _destroy; /** Get number of entries to display. (unfiltered). */ __mode_get_num_entries _get_num_entries; - /** Check if the element is ascii. */ - _mode_is_not_ascii _is_not_ascii; /** Process the result of the user selection. */ _mode_result _result; /** Token match. */ diff --git a/include/mode.h b/include/mode.h index aaf38566..672d74db 100644 --- a/include/mode.h +++ b/include/mode.h @@ -96,16 +96,6 @@ char * mode_get_display_value ( const Mode *mode, unsigned int selected_line, in */ char * mode_get_completion ( const Mode *mode, unsigned int selected_line ); -/** - * @param mode The mode to query - * @param selected_line The entry to query - * - * Check if the entry has non-ascii characters. - * - * @returns TRUE when selected line has non-ascii characters. - */ -int mode_is_not_ascii ( const Mode *mode, unsigned int selected_line ); - /** * @param mode The mode to query * @param mretv The menu return value. @@ -121,15 +111,13 @@ ModeMode mode_result ( Mode *mode, int menu_retv, char **input, unsigned int sel /** * @param mode The mode to query * @param tokens The set of tokens to match against - * @param not_ascii If the entry is pure-ascii - * @param case_sensitive If the entry should be matched case sensitive * @param selected_line The index of the entry to match * * Match entry against the set of tokens. * * @returns TRUE if matches */ -int mode_token_match ( const Mode *mode, char **tokens, int not_ascii, int case_sensitive, unsigned int selected_line ); +int mode_token_match ( const Mode *mode, GRegex **tokens, unsigned int selected_line ); /** * @param mode The mode to query diff --git a/include/view-internal.h b/include/view-internal.h index 4912da10..43ba6875 100644 --- a/include/view-internal.h +++ b/include/view-internal.h @@ -56,7 +56,6 @@ struct RofiViewState // Return state unsigned int selected_line; MenuReturn retv; - int *lines_not_ascii; int line_height; unsigned int border; workarea mon; diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index 5ab58940..89c634b8 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -175,18 +175,17 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned } return MODE_EXIT; } -static int combi_mode_match ( const Mode *sw, char **tokens, int not_ascii, - int case_sensitive, unsigned int index ) +static int combi_mode_match ( const Mode *sw, GRegex **tokens, unsigned int index ) { CombiModePrivateData *pd = mode_get_private_data ( sw ); - if ( config.regex || config.glob ) { +// if ( config.regex || config.glob ) { // Bang support only works in text mode. for ( unsigned i = 0; i < pd->num_switchers; i++ ) { if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) { - return mode_token_match ( pd->switchers[i], tokens, not_ascii, case_sensitive, - index - pd->starts[i] ); + return mode_token_match ( pd->switchers[i], tokens, index - pd->starts[i] ); } } + /* @TODO fix this } else{ for ( unsigned i = 0; i < pd->num_switchers; i++ ) { @@ -205,6 +204,7 @@ static int combi_mode_match ( const Mode *sw, char **tokens, int not_ascii, } } } + */ abort (); return 0; } @@ -231,16 +231,6 @@ static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *stat return NULL; } -static int combi_is_not_ascii ( const Mode *sw, unsigned int index ) -{ - CombiModePrivateData *pd = mode_get_private_data ( sw ); - for ( unsigned i = 0; i < pd->num_switchers; i++ ) { - if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) { - return mode_is_not_ascii ( pd->switchers[i], index - pd->starts[i] ); - } - } - return FALSE; -} static char * combi_get_completion ( const Mode *sw, unsigned int index ) { CombiModePrivateData *pd = mode_get_private_data ( sw ); @@ -269,7 +259,6 @@ Mode combi_mode = ._token_match = combi_mode_match, ._get_completion = combi_get_completion, ._get_display_value = combi_mgrv, - ._is_not_ascii = combi_is_not_ascii, .private_data = NULL, .free = NULL }; diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index 56f397bf..4d4cdbbc 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -332,16 +332,10 @@ static int dmenu_mode_init ( Mode *sw ) return TRUE; } -static int dmenu_token_match ( const Mode *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index ) +static int dmenu_token_match ( const Mode *sw, GRegex **tokens, unsigned int index ) { DmenuModePrivateData *rmpd = (DmenuModePrivateData *) mode_get_private_data ( sw ); - return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive ); -} - -static int dmenu_is_not_ascii ( const Mode *sw, unsigned int index ) -{ - DmenuModePrivateData *rmpd = (DmenuModePrivateData *) mode_get_private_data ( sw ); - return !g_str_is_ascii ( rmpd->cmd_list[index] ); + return token_match ( tokens, rmpd->cmd_list[index] ); } #include "mode-private.h" @@ -356,7 +350,6 @@ Mode dmenu_mode = ._token_match = dmenu_token_match, ._get_display_value = get_display_data, ._get_completion = NULL, - ._is_not_ascii = dmenu_is_not_ascii, .private_data = NULL, .free = NULL }; @@ -516,25 +509,25 @@ int dmenu_switcher_dialog ( void ) char *select = NULL; find_arg_str ( "-select", &select ); if ( select != NULL ) { - char **tokens = tokenize ( select, config.case_sensitive ); + GRegex **tokens = tokenize ( select, config.case_sensitive ); unsigned int i = 0; for ( i = 0; i < cmd_list_length; i++ ) { - if ( token_match ( tokens, cmd_list[i], !g_str_is_ascii ( cmd_list[i] ), config.case_sensitive ) ) { + if ( token_match ( tokens, cmd_list[i] ) ) { pd->selected_line = i; break; } } - g_strfreev ( tokens ); + tokenize_free ( tokens ); } if ( find_arg ( "-dump" ) >= 0 ) { - char **tokens = tokenize ( config.filter ? config.filter : "", config.case_sensitive ); + GRegex **tokens = tokenize ( config.filter ? config.filter : "", config.case_sensitive ); unsigned int i = 0; for ( i = 0; i < cmd_list_length; i++ ) { - if ( token_match ( tokens, cmd_list[i], !g_str_is_ascii ( cmd_list[i] ), config.case_sensitive ) ) { + if ( token_match ( tokens, cmd_list[i] ) ) { dmenu_output_formatted_line ( pd->format, cmd_list[i], i, config.filter ); } } - g_strfreev ( tokens ); + tokenize_free ( tokens ); return TRUE; } // TODO remove diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c index 5f063701..39fee13f 100644 --- a/source/dialogs/drun.c +++ b/source/dialogs/drun.c @@ -378,29 +378,24 @@ static char *drun_get_completion ( const Mode *sw, unsigned int index ) } } -static int drun_token_match ( const Mode *data, - char **tokens, - int not_ascii, - int case_sensitive, - unsigned int index - ) +static int drun_token_match ( const Mode *data, GRegex **tokens, unsigned int index) { DRunModePrivateData *rmpd = (DRunModePrivateData *) mode_get_private_data ( data ); int match = 1; if ( tokens ) { for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) { int test = 0; - char *ftokens[2] = { tokens[j], NULL }; + GRegex *ftokens[2] = { tokens[j], NULL }; if ( !test && rmpd->entry_list[index].name && - token_match ( ftokens, rmpd->entry_list[index].name, not_ascii, case_sensitive ) ) { + token_match ( ftokens, rmpd->entry_list[index].name ) ) { test = 1; } if ( !test && rmpd->entry_list[index].generic_name && - token_match ( ftokens, rmpd->entry_list[index].generic_name, not_ascii, case_sensitive ) ) { + token_match ( ftokens, rmpd->entry_list[index].generic_name) ) { test = 1; } - if ( !test && token_match ( ftokens, rmpd->entry_list[index].exec, not_ascii, case_sensitive ) ) { + if ( !test && token_match ( ftokens, rmpd->entry_list[index].exec) ) { test = 1; } if ( test == 0 ) { @@ -416,15 +411,6 @@ static unsigned int drun_mode_get_num_entries ( const Mode *sw ) const DRunModePrivateData *pd = (const DRunModePrivateData *) mode_get_private_data ( sw ); return pd->cmd_list_length; } -static int drun_is_not_ascii ( const Mode *sw, unsigned int index ) -{ - DRunModePrivateData *pd = (DRunModePrivateData *) mode_get_private_data ( sw ); - if ( pd->entry_list[index].generic_name ) { - return !g_str_is_ascii ( pd->entry_list[index].name ) || !g_str_is_ascii ( pd->entry_list[index].generic_name ); - } - return !g_str_is_ascii ( pd->entry_list[index].name ); -} - #include "mode-private.h" Mode drun_mode = { @@ -437,7 +423,6 @@ Mode drun_mode = ._token_match = drun_token_match, ._get_completion = drun_get_completion, ._get_display_value = _get_display_value, - ._is_not_ascii = drun_is_not_ascii, .private_data = NULL, .free = NULL }; diff --git a/source/dialogs/run.c b/source/dialogs/run.c index 00dae3fe..51db25d9 100644 --- a/source/dialogs/run.c +++ b/source/dialogs/run.c @@ -418,16 +418,10 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_ const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data; return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL; } -static int run_token_match ( const Mode *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index ) +static int run_token_match ( const Mode *sw, GRegex **tokens, unsigned int index ) { const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data; - return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive ); -} - -static int run_is_not_ascii ( const Mode *sw, unsigned int index ) -{ - const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data; - return !g_str_is_ascii ( rmpd->cmd_list[index] ); + return token_match ( tokens, rmpd->cmd_list[index]); } #include "mode-private.h" @@ -442,7 +436,6 @@ Mode run_mode = ._token_match = run_token_match, ._get_display_value = _get_display_value, ._get_completion = NULL, - ._is_not_ascii = run_is_not_ascii, .private_data = NULL, .free = NULL }; diff --git a/source/dialogs/script.c b/source/dialogs/script.c index 92f9129b..3abb2aba 100644 --- a/source/dialogs/script.c +++ b/source/dialogs/script.c @@ -168,16 +168,10 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_ return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL; } -static int script_token_match ( const Mode *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index ) +static int script_token_match ( const Mode *sw, GRegex **tokens, unsigned int index ) { ScriptModePrivateData *rmpd = sw->private_data; - return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive ); -} - -static int script_is_not_ascii ( const Mode *sw, unsigned int index ) -{ - ScriptModePrivateData *rmpd = sw->private_data; - return !g_str_is_ascii ( rmpd->cmd_list[index] ); + return token_match ( tokens, rmpd->cmd_list[index] ); } #include "mode-private.h" @@ -207,7 +201,6 @@ Mode *script_switcher_parse_setup ( const char *str ) sw->_token_match = script_token_match; sw->_get_completion = NULL, sw->_get_display_value = _get_display_value; - sw->_is_not_ascii = script_is_not_ascii; return sw; } diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c index 95bcd080..3bf38f8e 100644 --- a/source/dialogs/ssh.c +++ b/source/dialogs/ssh.c @@ -481,26 +481,11 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_ * * @returns TRUE if matches */ -static int ssh_token_match ( const Mode *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index ) +static int ssh_token_match ( const Mode *sw, GRegex **tokens, unsigned int index ) { SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw ); - return token_match ( tokens, rmpd->hosts_list[index], not_ascii, case_sensitive ); + return token_match ( tokens, rmpd->hosts_list[index] ); } - -/** - * @param sw Object handle to the SSH Mode object - * @param index The index of the entry to match - * - * Check if the selected entry contains non-ascii symbols. - * - * @returns TRUE if string contains non-ascii symbols - */ -static int ssh_is_not_ascii ( const Mode *sw, unsigned int index ) -{ - SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw ); - return !g_str_is_ascii ( rmpd->hosts_list[index] ); -} - #include "mode-private.h" Mode ssh_mode = { @@ -513,7 +498,6 @@ Mode ssh_mode = ._token_match = ssh_token_match, ._get_display_value = _get_display_value, ._get_completion = NULL, - ._is_not_ascii = ssh_is_not_ascii, .private_data = NULL, .free = NULL }; diff --git a/source/dialogs/window.c b/source/dialogs/window.c index f228cbf7..a2918bb7 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -319,9 +319,7 @@ typedef struct char *cache; } ModeModePrivateData; -static int window_match ( const Mode *sw, char **tokens, - __attribute__( ( unused ) ) int not_ascii, - int case_sensitive, unsigned int index ) +static int window_match ( const Mode *sw, GRegex **tokens, unsigned int index ) { ModeModePrivateData *rmpd = (ModeModePrivateData *) mode_get_private_data ( sw ); int match = 1; @@ -338,21 +336,21 @@ static int window_match ( const Mode *sw, char **tokens, // Now we want it to match only one item at the time. // If hack not in place it would not match queries spanning multiple fields. // e.g. when searching 'title element' and 'class element' - char *ftokens[2] = { tokens[j], NULL }; + GRegex *ftokens[2] = { tokens[j], NULL }; if ( !test && c->title != NULL && c->title[0] != '\0' ) { - test = token_match ( ftokens, c->title, not_ascii, case_sensitive ); + test = token_match ( ftokens, c->title); } if ( !test && c->class != NULL && c->class[0] != '\0' ) { - test = token_match ( ftokens, c->class, not_ascii, case_sensitive ); + test = token_match ( ftokens, c->class); } if ( !test && c->role != NULL && c->role[0] != '\0' ) { - test = token_match ( ftokens, c->role, not_ascii, case_sensitive ); + test = token_match ( ftokens, c->role); } if ( !test && c->name != NULL && c->name[0] != '\0' ) { - test = token_match ( ftokens, c->name, not_ascii, case_sensitive ); + test = token_match ( ftokens, c->name); } if ( test == 0 ) { @@ -655,25 +653,6 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, in return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL; } -static int window_is_not_ascii ( const Mode *sw, unsigned int index ) -{ - const ModeModePrivateData *rmpd = mode_get_private_data ( sw ); - const winlist *ids = ( winlist * ) rmpd->ids; - // Want to pull directly out of cache, X calls are not thread safe. - int idx = winlist_find ( cache_client, ids->array[index] ); - g_assert ( idx >= 0 ); - client *c = cache_client->data[idx]; - if ( c->role && !g_str_is_ascii ( c->role ) ) { - return TRUE; - } - if ( c->class && !g_str_is_ascii ( c->class ) ) { - return TRUE; - } - if ( c->title && !g_str_is_ascii ( c->title ) ) { - return TRUE; - } - return FALSE; -} #include "mode-private.h" Mode window_mode = @@ -687,7 +666,6 @@ Mode window_mode = ._token_match = window_match, ._get_display_value = _get_display_value, ._get_completion = NULL, - ._is_not_ascii = window_is_not_ascii, .private_data = NULL, .free = NULL }; @@ -702,7 +680,6 @@ Mode window_mode_cd = ._token_match = window_match, ._get_display_value = _get_display_value, ._get_completion = NULL, - ._is_not_ascii = window_is_not_ascii, .private_data = NULL, .free = NULL }; diff --git a/source/helper.c b/source/helper.c index 3d36b538..1897516f 100644 --- a/source/helper.c +++ b/source/helper.c @@ -136,7 +136,7 @@ int helper_parse_setup ( char * string, char ***output, int *length, ... ) return FALSE; } -void tokenize_free ( char ** tokens ) +void tokenize_free ( GRegex ** tokens ) { for ( size_t i = 0; tokens && tokens[i]; i++ ) { g_regex_unref ( (GRegex *) tokens[i] ); @@ -194,17 +194,17 @@ static GRegex * create_regex ( const char *input, int case_sensitive ) } return retv; } -char **tokenize ( const char *input, int case_sensitive ) +GRegex **tokenize ( const char *input, int case_sensitive ) { if ( input == NULL || strlen(input) == 0 ) { return NULL; } char *saveptr = NULL, *token; - char **retv = NULL; + GRegex **retv = NULL; if ( !config.tokenize ) { - retv = g_malloc0 ( sizeof ( char* ) * 2 ); - retv[0] = (char *) create_regex ( input, case_sensitive ); + retv = g_malloc0 ( sizeof ( GRegex* ) * 2 ); + retv[0] = (GRegex *) create_regex ( input, case_sensitive ); return retv; } @@ -218,8 +218,8 @@ char **tokenize ( const char *input, int case_sensitive ) // strtok should still be valid for utf8. const char * const sep = " "; for ( token = strtok_r ( str, sep, &saveptr ); token != NULL; token = strtok_r ( NULL, sep, &saveptr ) ) { - retv = g_realloc ( retv, sizeof ( char* ) * ( num_tokens + 2 ) ); - retv[num_tokens] = (char *) create_regex ( token, case_sensitive ); + retv = g_realloc ( retv, sizeof ( GRegex* ) * ( num_tokens + 2 ) ); + retv[num_tokens] = (GRegex*) create_regex ( token, case_sensitive ); retv[num_tokens + 1] = NULL; num_tokens++; } @@ -335,20 +335,8 @@ int find_arg_char ( const char * const key, char *val ) return FALSE; } -static int regex_token_match ( char **tokens, const char *input, G_GNUC_UNUSED int not_ascii, G_GNUC_UNUSED int case_sensitive ) -{ - int match = 1; - // Do a tokenized match. - if ( tokens ) { - for ( int j = 0; match && tokens[j]; j++ ) { - match = g_regex_match ( (GRegex *) tokens[j], input, G_REGEX_MATCH_PARTIAL, NULL ); - } - } - return match; -} - -static PangoAttrList *regex_token_match_get_pango_attr ( char **tokens, const char *input, PangoAttrList *retv ) +PangoAttrList *token_match_get_pango_attr ( GRegex **tokens, const char *input, PangoAttrList *retv ) { // Do a tokenized match. if ( tokens ) { @@ -369,14 +357,17 @@ static PangoAttrList *regex_token_match_get_pango_attr ( char **tokens, const ch } return retv; } -PangoAttrList *token_match_get_pango_attr ( char **tokens, const char *input, PangoAttrList *retv ) -{ - return regex_token_match_get_pango_attr ( tokens, input, retv ); -} -int token_match ( char **tokens, const char *input, int not_ascii, int case_sensitive ) +int token_match ( GRegex **tokens, const char *input) { - return regex_token_match ( tokens, input, not_ascii, case_sensitive ); + int match = 1; + // Do a tokenized match. + if ( tokens ) { + for ( int j = 0; match && tokens[j]; j++ ) { + match = g_regex_match ( (GRegex *) tokens[j], input, G_REGEX_MATCH_PARTIAL, NULL ); + } + } + return match; } int execute_generator ( const char * cmd ) diff --git a/source/mode.c b/source/mode.c index 2e5b1969..216e0148 100644 --- a/source/mode.c +++ b/source/mode.c @@ -57,12 +57,6 @@ char * mode_get_completion ( const Mode *mode, unsigned int selected_line ) } } -int mode_is_not_ascii ( const Mode *mode, unsigned int selected_line ) -{ - g_assert ( mode != NULL ); - g_assert ( mode->_is_not_ascii != NULL ); - return mode->_is_not_ascii ( mode, selected_line ); -} ModeMode mode_result ( Mode *mode, int menu_retv, char **input, unsigned int selected_line ) { g_assert ( mode != NULL ); @@ -71,11 +65,11 @@ ModeMode mode_result ( Mode *mode, int menu_retv, char **input, unsigned int sel return mode->_result ( mode, menu_retv, input, selected_line ); } -int mode_token_match ( const Mode *mode, char **tokens, int not_ascii, int case_sensitive, unsigned int selected_line ) +int mode_token_match ( const Mode *mode, GRegex **tokens, unsigned int selected_line ) { g_assert ( mode != NULL ); g_assert ( mode->_token_match != NULL ); - return mode->_token_match ( mode, tokens, not_ascii, case_sensitive, selected_line ); + return mode->_token_match ( mode, tokens, selected_line ); } const char *mode_get_name ( const Mode *mode ) diff --git a/source/view.c b/source/view.c index 2c98b972..1114c923 100644 --- a/source/view.c +++ b/source/view.c @@ -301,7 +301,6 @@ void rofi_view_free ( RofiViewState *state ) g_free ( state->boxes ); g_free ( state->line_map ); g_free ( state->distance ); - g_free ( state->lines_not_ascii ); // Free the switcher boxes. // When state is free'ed we should no longer need these. if ( config.sidebar_mode == TRUE ) { @@ -465,7 +464,7 @@ static RofiViewState * __rofi_view_state_create ( void ) typedef struct _thread_state { RofiViewState *state; - char **tokens; + GRegex **tokens; unsigned int start; unsigned int stop; unsigned int count; @@ -494,8 +493,7 @@ static void filter_elements ( thread_state *t, G_GNUC_UNUSED gpointer user_data { // input changed for ( unsigned int i = t->start; i < t->stop; i++ ) { - int match = mode_token_match ( t->state->sw, t->tokens, t->state->lines_not_ascii[i], - config.case_sensitive, i ); + int match = mode_token_match ( t->state->sw, t->tokens, i ); // If each token was matched, add it to list. if ( match ) { t->state->line_map[t->start + t->count] = i; @@ -509,12 +507,6 @@ static void filter_elements ( thread_state *t, G_GNUC_UNUSED gpointer user_data } } } -static void check_is_ascii ( thread_state *t, G_GNUC_UNUSED gpointer user_data ) -{ - for ( unsigned int i = t->start; i < t->stop; i++ ) { - t->state->lines_not_ascii[i] = mode_is_not_ascii ( t->state->sw, i ); - } -} static void rofi_view_setup_fake_transparency ( void ) { @@ -933,7 +925,7 @@ static void rofi_view_draw ( RofiViewState *state, cairo_t *d ) int x_offset = state->border; if ( state->rchanged ) { - char **tokens = tokenize ( state->text->text, config.case_sensitive ); + GRegex **tokens = tokenize ( state->text->text, config.case_sensitive ); // Move, resize visible boxes and show them. for ( i = 0; i < max_elements && ( i + offset ) < state->filtered_lines; i++ ) { unsigned int ex = ( ( i ) / state->max_rows ) * ( element_width + config.line_margin ); @@ -1256,7 +1248,7 @@ static void rofi_view_refilter ( RofiViewState *state ) TICK_N ( "Filter start" ); if ( strlen ( state->text->text ) > 0 ) { unsigned int j = 0; - char **tokens = tokenize ( state->text->text, config.case_sensitive ); + GRegex **tokens = tokenize ( state->text->text, config.case_sensitive ); /** * On long lists it can be beneficial to parallelize. * If number of threads is 1, no thread is spawn. @@ -1641,45 +1633,7 @@ RofiViewState *rofi_view_create ( Mode *sw, // Request the lines to show. state->num_lines = mode_get_num_entries ( sw ); - state->lines_not_ascii = g_malloc0_n ( state->num_lines, sizeof ( int ) ); - // find out which lines contain non-ascii codepoints, so we can be faster in some cases. - if ( state->num_lines > 0 ) { - TICK_N ( "Is ASCII start" ); - unsigned int nt = MAX ( 1, state->num_lines / 5000 ); - thread_state states[nt]; - unsigned int steps = ( state->num_lines + nt ) / nt; - unsigned int count = nt; - GCond cond; - GMutex mutex; - g_mutex_init ( &mutex ); - g_cond_init ( &cond ); - for ( unsigned int i = 0; i < nt; i++ ) { - states[i].state = state; - states[i].start = i * steps; - states[i].stop = MIN ( ( i + 1 ) * steps, state->num_lines ); - states[i].acount = &count; - states[i].mutex = &mutex; - states[i].cond = &cond; - states[i].callback = check_is_ascii; - if ( i > 0 ) { - g_thread_pool_push ( tpool, &( states[i] ), NULL ); - } - } - // Run one in this thread. - rofi_view_call_thread ( &( states[0] ), NULL ); - // No need to do this with only one thread. - if ( nt > 1 ) { - g_mutex_lock ( &mutex ); - while ( count > 0 ) { - g_cond_wait ( &cond, &mutex ); - } - g_mutex_unlock ( &mutex ); - } - g_cond_clear ( &cond ); - g_mutex_clear ( &mutex ); - TICK_N ( "Is ASCII stop" ); - } TICK_N ( "Startup notification" ); // Try to grab the keyboard as early as possible.