Small fix

This commit is contained in:
Dave Davenport 2015-11-17 16:21:30 +01:00
parent aeaceb154a
commit 00c8439b57
1 changed files with 7 additions and 9 deletions

View File

@ -207,18 +207,18 @@ char **tokenize ( const char *input, int case_sensitive )
for ( token = strtok_r ( str, " ", &saveptr ); token != NULL; token = strtok_r ( NULL, " ", &saveptr ) ) { for ( token = strtok_r ( str, " ", &saveptr ); token != NULL; token = strtok_r ( NULL, " ", &saveptr ) ) {
retv = g_realloc ( retv, sizeof ( char* ) * ( num_tokens + 2 ) ); retv = g_realloc ( retv, sizeof ( char* ) * ( num_tokens + 2 ) );
if ( config.glob ) { if ( config.glob ) {
char *t = token_collate_key ( token, case_sensitive ); char *str = g_strdup_printf ( "*%s*", token);
char *str = g_strdup_printf ( "*%s*", input ); char *t = token_collate_key ( str, case_sensitive );
retv[num_tokens] = (char *) g_pattern_spec_new ( str ); retv[num_tokens] = (char *) g_pattern_spec_new ( t );
g_free ( t ); g_free ( t );
g_free ( str ); g_free ( str );
} }
else if ( config.regex ) { else if ( config.regex ) {
GError *error = NULL; GError *error = NULL;
retv[num_tokens] = (char *) g_regex_new ( token, case_sensitive ? 0 : G_REGEX_CASELESS, 0, &error ); retv[num_tokens] = (char *) g_regex_new ( token, case_sensitive?0:G_REGEX_CASELESS, 0, &error);
if ( retv[num_tokens] == NULL ) { if ( retv[num_tokens] == NULL ) {
fprintf ( stderr, "Failed to parse: '%s'\n", error->message ); fprintf ( stderr, "Failed to parse: '%s'\n", error->message );
g_error_free ( error ); g_error_free(error);
num_tokens--; num_tokens--;
} }
} }
@ -459,7 +459,7 @@ static int regex_token_match ( char **tokens, const char *input, G_GNUC_UNUSED i
static int glob_token_match ( char **tokens, const char *input, int not_ascii, int case_sensitive ) static int glob_token_match ( char **tokens, const char *input, int not_ascii, int case_sensitive )
{ {
int match = 1; int match = 1;
char *compk = not_ascii ? token_collate_key ( input, case_sensitive ) : (char *) input; char *compk = not_ascii ? token_collate_key ( input, case_sensitive ) : g_ascii_strdown(input,-1);
// Do a tokenized match. // Do a tokenized match.
if ( tokens ) { if ( tokens ) {
@ -467,9 +467,7 @@ static int glob_token_match ( char **tokens, const char *input, int not_ascii, i
match = g_pattern_match_string ( (GPatternSpec *) tokens[j], compk ); match = g_pattern_match_string ( (GPatternSpec *) tokens[j], compk );
} }
} }
if ( not_ascii ) { g_free ( compk );
g_free ( compk );
}
return match; return match;
} }