Add tokenize option and append * to glob.

This commit is contained in:
Dave Davenport 2015-10-04 16:37:07 +02:00
parent 1369c162fe
commit 6b039ac524
5 changed files with 30 additions and 7 deletions

View file

@ -129,8 +129,9 @@ Settings config = {
/** Modi to combine into one view. */
.combi_modi = "window,run",
/** Fuzzy matching. */
.fuzzy = FALSE,
.glob = FALSE,
.fuzzy = FALSE,
.glob = FALSE,
.tokenize = FALSE,
/** Monitor */
.monitor = -1,
/** set line margin */

View file

@ -231,6 +231,7 @@ typedef struct _Settings
/** Fuzzy match */
unsigned int fuzzy;
unsigned int glob;
unsigned int tokenize;
/** Monitors */
int monitor;
/** Line margin */

View file

@ -59,8 +59,8 @@ typedef struct _DmenuModePrivateData
static char **get_dmenu ( unsigned int *length )
{
char buffer[1024];
char **retv = NULL;
char buffer[1024];
char **retv = NULL;
*length = 0;

View file

@ -176,8 +176,21 @@ char **tokenize ( const char *input, int case_sensitive )
char *saveptr = NULL, *token;
char **retv = NULL;
if ( !config.tokenize ) {
retv = g_malloc0 ( sizeof ( char* ) * 2 );
if ( config.glob ) {
token = g_strconcat ( input, "*", NULL );
retv[0] = token_collate_key ( token, case_sensitive );
g_free ( token ); token = NULL;
}
else{
token = token_collate_key ( input, case_sensitive );
}
return retv;
}
// First entry is always full (modified) stringtext.
int num_tokens = 0;
int num_tokens = 0;
// Copy the string, 'strtok_r' modifies it.
char *str = g_strdup ( input );
@ -185,8 +198,15 @@ char **tokenize ( const char *input, int case_sensitive )
// Iterate over tokens.
// strtok should still be valid for utf8.
for ( token = strtok_r ( str, " ", &saveptr ); token != NULL; token = strtok_r ( NULL, " ", &saveptr ) ) {
retv = g_realloc ( retv, sizeof ( char* ) * ( num_tokens + 2 ) );
retv[num_tokens] = token_collate_key ( token, case_sensitive );
retv = g_realloc ( retv, sizeof ( char* ) * ( num_tokens + 2 ) );
if ( config.glob ) {
char *t = token_collate_key ( token, case_sensitive );
retv[num_tokens] = g_strconcat ( t, "*", NULL );
g_free ( t );
}
else {
retv[num_tokens] = token_collate_key ( token, case_sensitive );
}
retv[num_tokens + 1] = NULL;
num_tokens++;
}

View file

@ -123,6 +123,7 @@ static XrmOption xrmOptions[] = {
{ xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL },
{ xrm_Boolean, "fuzzy", { .num = &config.fuzzy }, NULL },
{ xrm_Boolean, "glob", { .num = &config.glob }, NULL },
{ xrm_Boolean, "tokenize", { .num = &config.tokenize }, NULL },
{ xrm_Number, "monitor", { .snum = &config.monitor }, NULL },
/* Alias for dmenu compatibility. */
{ xrm_SNumber, "m", { .snum = &config.monitor }, NULL },