From 30743d17896fc09778f615da74793013313c725f Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sun, 28 Jun 2015 13:53:37 +0200 Subject: [PATCH] Move fuzzy_token_match to where it can be reused. --- include/helper.h | 4 ++++ source/dialogs/dmenu.c | 25 ------------------------- source/helper.c | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/include/helper.h b/include/helper.h index 99b1bf7d..cff62427 100644 --- a/include/helper.h +++ b/include/helper.h @@ -108,6 +108,10 @@ int token_match ( char **tokens, const char *input, int case_sensitive, __attribute__( ( unused ) ) unsigned int index, __attribute__( ( unused ) ) Switcher * data ); +int fuzzy_token_match ( char **tokens, const char *input, int case_sensitive, + __attribute__( ( unused ) ) unsigned int index, + __attribute__( ( unused ) ) Switcher * data ); + /** * @param cmd The command to execute. * diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index 5ddfc9b4..1979c069 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -178,31 +178,6 @@ static void dmenu_output_formatted_line ( const char *format, const char *string fflush ( stdout ); } - -static int fuzzy_token_match ( char **tokens, const char *input, int case_sensitive, - __attribute__( ( unused ) ) unsigned int index, - __attribute__( ( unused ) ) Switcher * data ) -{ - int match = 1; - char *compk = token_collate_key ( input, case_sensitive ); - // Do a tokenized match. - if ( tokens ) { - for ( int j = 0; match && tokens[j]; j++ ) { - char *t = compk; - int token_len = strlen ( tokens[j] ); - for ( int id = 0; match && t != NULL && id < token_len; id++ ) { - match = ( ( t = strchr ( t, tokens[j][id] ) ) != NULL ); - // next should match the next character. - if(t != NULL) { - t++; - } - } - } - } - g_free ( compk ); - return match; -} - int dmenu_switcher_dialog ( char **input ) { char *dmenu_prompt = "dmenu "; diff --git a/source/helper.c b/source/helper.c index 47127866..9a5125c8 100644 --- a/source/helper.c +++ b/source/helper.c @@ -345,6 +345,29 @@ int token_match ( char **tokens, const char *input, int case_sensitive, g_free ( compk ); return match; } +int fuzzy_token_match ( char **tokens, const char *input, int case_sensitive, + __attribute__( ( unused ) ) unsigned int index, + __attribute__( ( unused ) ) Switcher * data ) +{ + int match = 1; + char *compk = token_collate_key ( input, case_sensitive ); + // Do a tokenized match. + if ( tokens ) { + for ( int j = 0; match && tokens[j]; j++ ) { + char *t = compk; + int token_len = strlen ( tokens[j] ); + for ( int id = 0; match && t != NULL && id < token_len; id++ ) { + match = ( ( t = strchr ( t, tokens[j][id] ) ) != NULL ); + // next should match the next character. + if ( t != NULL ) { + t++; + } + } + } + } + g_free ( compk ); + return match; +} int execute_generator ( const char * cmd ) {