From 6b039ac524e4569533b153d7a9276a82583e0ffe Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sun, 4 Oct 2015 16:37:07 +0200 Subject: [PATCH] Add tokenize option and append * to glob. --- config/config.def.c | 5 +++-- include/rofi.h | 1 + source/dialogs/dmenu.c | 4 ++-- source/helper.c | 26 +++++++++++++++++++++++--- source/xrmoptions.c | 1 + 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/config/config.def.c b/config/config.def.c index d25be080..d7d1edaa 100644 --- a/config/config.def.c +++ b/config/config.def.c @@ -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 */ diff --git a/include/rofi.h b/include/rofi.h index dc28bf99..da6c5cf7 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -231,6 +231,7 @@ typedef struct _Settings /** Fuzzy match */ unsigned int fuzzy; unsigned int glob; + unsigned int tokenize; /** Monitors */ int monitor; /** Line margin */ diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index a44dbcf4..82e8dc62 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -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; diff --git a/source/helper.c b/source/helper.c index 18270e9c..76055c12 100644 --- a/source/helper.c +++ b/source/helper.c @@ -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++; } diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 9422c861..1ea219ba 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -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 },