summaryrefslogtreecommitdiffstats
path: root/source/helper.c
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2015-07-01 09:12:22 +0200
committerDave Davenport <qball@gmpclient.org>2015-07-01 09:12:22 +0200
commit98b8e583cbd670afe8d69066209ce2c432e41053 (patch)
treed5e19a329e30195fd23989be3b67d1088f8d1712 /source/helper.c
parentc7ed92e40c2ef8e73cb6ca4eb139fe27020fd2c4 (diff)
Make fuzzy matching available everywhere: #133 (-fuzzy)
Diffstat (limited to 'source/helper.c')
-rw-r--r--source/helper.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/source/helper.c b/source/helper.c
index 9a5125c8..bda83714 100644
--- a/source/helper.c
+++ b/source/helper.c
@@ -329,45 +329,50 @@ int find_arg_char ( const char * const key, char *val )
* Shared 'token_match' function.
* Matches tokenized.
*/
-int token_match ( char **tokens, const char *input, int case_sensitive,
- __attribute__( ( unused ) ) unsigned int index,
- __attribute__( ( unused ) ) Switcher *data )
+static int fuzzy_token_match ( char **tokens, const char *input, int case_sensitive )
{
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++ ) {
- match = ( strstr ( compk, tokens[j] ) != NULL );
+ 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 fuzzy_token_match ( char **tokens, const char *input, int case_sensitive,
- __attribute__( ( unused ) ) unsigned int index,
- __attribute__( ( unused ) ) Switcher * data )
+static int normal_token_match ( char **tokens, const char *input, int case_sensitive )
{
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++;
- }
- }
+ match = ( strstr ( compk, tokens[j] ) != NULL );
}
}
g_free ( compk );
return match;
}
+int token_match ( char **tokens, const char *input, int case_sensitive,
+ __attribute__( ( unused ) ) unsigned int index,
+ __attribute__( ( unused ) ) Switcher *data )
+{
+ if ( config.fuzzy ) {
+ return fuzzy_token_match ( tokens, input, case_sensitive );
+ }
+ return normal_token_match ( tokens, input, case_sensitive );
+}
int execute_generator ( const char * cmd )
{