sites

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit bb4dd1c48745e2b03ae0c22eba23c78d11d9b5b2
parent 0aafd826a7a1e43f1ae1b983b6d5afafed25521c
Author: StephenB <mail4stb@gmail.com>
Date:   Thu, 12 Aug 2010 00:48:19 +0100

updated dmenu xmms tip patch to use Connor's version

this patch is against dmenu r358
Diffstat:
Atools.suckless.org/dmenu/patches/dmenu-tip-tok.diff | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dtools.suckless.org/dmenu/patches/dmenu-tip-xmms.diff | 121-------------------------------------------------------------------------------
Mtools.suckless.org/dmenu/patches/xmms-like_pattern_matching.md | 17++++++++++++-----
3 files changed, 115 insertions(+), 126 deletions(-)

diff --git a/tools.suckless.org/dmenu/patches/dmenu-tip-tok.diff b/tools.suckless.org/dmenu/patches/dmenu-tip-tok.diff @@ -0,0 +1,103 @@ +diff -r 8e45498dc735 dmenu.1 +--- a/dmenu.1 Wed Aug 11 15:02:03 2010 +0100 ++++ b/dmenu.1 Thu Aug 12 00:24:17 2010 +0100 +@@ -5,6 +5,7 @@ + .B dmenu + .RB [ \-b ] + .RB [ \-i ] ++.RB [ \-t ] + .RB [ \-l + .IR lines ] + .RB [ \-p +@@ -48,6 +49,9 @@ + .B \-i + dmenu matches menu items case insensitively. + .TP ++.B \-t ++dmenu uses space separated tokens to match menu items. ++.TP + .BI \-l " lines" + dmenu lists items vertically, with the given number of lines. + .TP +diff -r 8e45498dc735 dmenu.c +--- a/dmenu.c Wed Aug 11 15:02:03 2010 +0100 ++++ b/dmenu.c Thu Aug 12 00:24:17 2010 +0100 +@@ -31,7 +31,8 @@ + static void grabkeyboard(void); + static void insert(const char *s, ssize_t n); + static void keypress(XKeyEvent *ev); +-static void match(void); ++static void matchstr(void); ++static void matchtok(void); + static void paste(Atom atom); + static void readstdin(void); + static void run(void); +@@ -61,6 +62,7 @@ + static Window root, win; + + static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; ++static void (*match)(void) = matchstr; + + void + appenditem(Item *item, Item **list, Item **last) { +@@ -331,7 +333,7 @@ + } + + void +-match(void) { ++matchstr(void) { + size_t len; + Item *item, *itemend, *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend; + +@@ -371,6 +373,33 @@ + } + + void ++matchtok(void) { ++ char buf[sizeof text]; ++ char **tokv, *s; ++ int tokc, i; ++ Item *item, *end; ++ ++ tokc = 0; ++ tokv = NULL; ++ strcpy(buf, text); ++ for(s = strtok(buf, " "); s; tokv[tokc-1] = s, s = strtok(NULL, " ")) ++ if(!(tokv = realloc(tokv, ++tokc * sizeof *tokv))) ++ eprintf("cannot realloc %u bytes\n", tokc * sizeof *tokv); ++ ++ matches = end = NULL; ++ for(item = items; item; item = item->next) { ++ for(i = 0; i < tokc; i++) ++ if(!fstrstr(item->text, tokv[i])) ++ break; ++ if(i == tokc) ++ appenditem(item, &matches, &end); ++ } ++ free(tokv); ++ curr = prev = next = sel = matches; ++ calcoffsets(); ++} ++ ++void + paste(Atom atom) { + char *p, *q; + int di; +@@ -489,7 +518,7 @@ + + void + usage(void) { +- fputs("usage: dmenu [-b] [-i] [-l lines] [-p prompt] [-fn font] [-nb color]\n" ++ fputs("usage: dmenu [-b] [-i] [-t] [-l lines] [-p prompt] [-fn font] [-nb color]\n" + " [-nf color] [-sb color] [-sf color] [-v]\n", stderr); + exit(EXIT_FAILURE); + } +@@ -509,6 +538,8 @@ + topbar = False; + else if(!strcmp(argv[i], "-i")) + fstrncmp = strncasecmp; ++ else if(!strcmp(argv[i], "-t")) ++ match = matchtok; + else if(i == argc-1) + usage(); + /* double flags */ diff --git a/tools.suckless.org/dmenu/patches/dmenu-tip-xmms.diff b/tools.suckless.org/dmenu/patches/dmenu-tip-xmms.diff @@ -1,121 +0,0 @@ -diff -r de7ad128a8b9 dmenu.1 ---- a/dmenu.1 Fri Aug 06 14:16:08 2010 +0100 -+++ b/dmenu.1 Sat Aug 07 21:28:03 2010 +0100 -@@ -19,6 +19,7 @@ - .IR color ] - .RB [ \-sf - .IR color ] -+.RB [ \-xs ] - .RB [ \-v ] - .P - .BR dmenu_run " ..." -@@ -72,6 +73,9 @@ - .BI \-sf " color" - defines the selected foreground color. - .TP -+.B \-xs -+xmms-like pattern matching. -+.TP - .B \-v - prints version information to standard output, then exits. - .SH USAGE -diff -r de7ad128a8b9 dmenu.c ---- a/dmenu.c Fri Aug 06 14:16:08 2010 +0100 -+++ b/dmenu.c Sat Aug 07 21:28:03 2010 +0100 -@@ -45,6 +45,9 @@ - static const char *normfgcolor = "#000000"; - static const char *selbgcolor = "#0066ff"; - static const char *selfgcolor = "#ffffff"; -+static const unsigned int maxtokens = 16; /* max. tokens for pattern matching */ -+static char **tokens = NULL; -+static Bool xmms = False; - static unsigned int inputw = 0; - static unsigned int lines = 0; - static unsigned int mw, mh; -@@ -339,20 +342,53 @@ - drawmenu(); - } - -+unsigned int -+tokenize(char **tok) { -+ unsigned int i = 0; -+ char tmp[sizeof text] = {0}; -+ -+ strcpy(tmp, text); -+ tok[0] = strtok(tmp, " "); -+ -+ while(tok[i] && i < maxtokens) -+ tok[++i] = strtok(NULL, " "); -+ return i; -+} -+ - void - match(void) { - size_t len; -+ unsigned int tokencnt = 0; -+ char append = 0; - Item *item, *itemend, *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend; - -- len = strlen(text); -+ if(!xmms) -+ tokens[(tokencnt = 1)-1] = text; -+ else -+ if(!(tokencnt = tokenize(tokens))) -+ tokens[(tokencnt = 1)-1] = ""; - matches = lexact = lprefix = lsubstr = itemend = exactend = prefixend = substrend = NULL; -- for(item = allitems; item; item = item->next) -- if(!fstrncmp(text, item->text, len + 1)) -- appenditem(item, &lexact, &exactend); -- else if(!fstrncmp(text, item->text, len)) -- appenditem(item, &lprefix, &prefixend); -- else if(fstrstr(item->text, text)) -- appenditem(item, &lsubstr, &substrend); -+ for(item = allitems; item; item = item->next) { -+ for(int j = 0; j < tokencnt; ++j) { -+ len = strlen(tokens[j]); -+ if(!fstrncmp(tokens[j], item->text, len + 1)) -+ append = !append || append > 1 ? 1 : append; -+ else if(!fstrncmp(tokens[j], item->text, len )) -+ append = !append || append > 2 ? 2 : append; -+ else if(fstrstr(item->text, tokens[j])) -+ append = append > 0 && append < 3 ? append : 3; -+ else { -+ append = 0; -+ break; -+ } -+ } -+ if(append == 1) -+ appenditem(item, &lexact, &exactend); -+ else if(append == 2) -+ appenditem(item, &lprefix, &prefixend); -+ else if(append == 3) -+ appenditem(item, &lsubstr, &substrend); -+ } - if(lexact) { - matches = lexact; - itemend = exactend; -@@ -495,13 +531,14 @@ - promptw = prompt ? MIN(textw(dc, prompt), mw/5) : 0; - XMapRaised(dc->dpy, win); - text[0] = '\0'; -+ tokens = malloc((xmms?maxtokens:1)*sizeof(char*)); - match(); - } - - void - usage(void) { - fputs("usage: dmenu [-b] [-i] [-l lines] [-p prompt] [-fn font] [-nb color]\n" -- " [-nf color] [-sb color] [-sf color] [-v]\n", stderr); -+ " [-nf color] [-sb color] [-sf color] [-xs] [-v]\n", stderr); - exit(EXIT_FAILURE); - } - -@@ -541,6 +578,8 @@ - selbgcolor = argv[++i]; - else if(!strcmp(argv[i], "-sf")) - selfgcolor = argv[++i]; -+ else if(!strcmp(argv[i], "-xs")) -+ xmms = True; - else - usage(); - diff --git a/tools.suckless.org/dmenu/patches/xmms-like_pattern_matching.md b/tools.suckless.org/dmenu/patches/xmms-like_pattern_matching.md @@ -10,14 +10,21 @@ could match http://tools.suckless.org/dmenu/patches/ - in someone's bookmarks file. +It can be useful to ease the matching on huge strings. -This feature is enabled by -xs command line flag, it can be useful to ease the matching on huge strings. +The patch comes in two flavours: -Download --------- +* **tok** (tokenise), for dmenu tip and upcoming release. Enabled with **-t** command line flag. -* [dmenu-tip-xmms.diff](dmenu-tip-xmms.diff) (for hg tip - **use at your own risk**) +* **xmms**, for legacy dmenu. The original patch submitted by Julien Steinhauser. Enabled with the **-xs** command line flag. + +Download tok +------------ + +* [dmenu-tip-tok.diff](dmenu-tip-tok.diff) (for hg tip (checked against 358) - **use at your own risk**) + +Download xmms +------------- * [dmenu-4.1.1-xmms.diff](dmenu-4.1.1-xmms.diff) (latest dmenu release at time of writing)