Move fuzzy_token_match to where it can be reused.

This commit is contained in:
Dave Davenport 2015-06-28 13:53:37 +02:00
parent 67089677b5
commit 30743d1789
3 changed files with 27 additions and 25 deletions

View File

@ -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.
*

View File

@ -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 ";

View File

@ -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 )
{