[wiki] [sites] wiki updated

From: <hg_AT_suckless.org>
Date: Wed, 11 Aug 2010 23:49:25 +0000 (UTC)

changeset: 607:e9e29e9f6f47
tag: tip
user: StephenB <mail4stb_AT_gmail.com>
date: Thu Aug 12 00:48:19 2010 +0100
files: tools.suckless.org/dmenu/patches/dmenu-tip-tok.diff tools.suckless.org/dmenu/patches/dmenu-tip-xmms.diff tools.suckless.org/dmenu/patches/xmms-like_pattern_matching.md
description:
updated dmenu xmms tip patch to use Connor's version

this patch is against dmenu r358


diff -r 17eabde414c9 -r e9e29e9f6f47 tools.suckless.org/dmenu/patches/dmenu-tip-tok.diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools.suckless.org/dmenu/patches/dmenu-tip-tok.diff Thu Aug 12 00:48:19 2010 +0100
_AT_@ -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
+_AT_@ -5,6 +5,7 @@
+ .B dmenu
+ .RB [ \-b ]
+ .RB [ \-i ]
++.RB [ \-t ]
+ .RB [ \-l
+ .IR lines ]
+ .RB [ \-p
+_AT_@ -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
+_AT_@ -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);
+_AT_@ -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) {
+_AT_@ -331,7 +333,7 @@
+ }
+
+ void
+-match(void) {
++matchstr(void) {
+ size_t len;
+ Item *item, *itemend, *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend;
+
+_AT_@ -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;
+_AT_@ -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);
+ }
+_AT_@ -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 -r 17eabde414c9 -r e9e29e9f6f47 tools.suckless.org/dmenu/patches/dmenu-tip-xmms.diff
--- a/tools.suckless.org/dmenu/patches/dmenu-tip-xmms.diff Tue Aug 10 14:09:17 2010 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
_AT_@ -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
-_AT_@ -19,6 +19,7 @@
- .IR color ]
- .RB [ \-sf
- .IR color ]
-+.RB [ \-xs ]
- .RB [ \-v ]
- .P
- .BR dmenu_run " ..."
-_AT_@ -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
-_AT_@ -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;
-_AT_@ -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;
-_AT_@ -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);
- }
-
-_AT_@ -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 -r 17eabde414c9 -r e9e29e9f6f47 tools.suckless.org/dmenu/patches/xmms-like_pattern_matching.md
--- a/tools.suckless.org/dmenu/patches/xmms-like_pattern_matching.md Tue Aug 10 14:09:17 2010 +0100
+++ b/tools.suckless.org/dmenu/patches/xmms-like_pattern_matching.md Thu Aug 12 00:48:19 2010 +0100
_AT_@ -10,14 +10,21 @@
 
          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)
 
Received on Thu Aug 12 2010 - 01:49:25 CEST

This archive was generated by hypermail 2.3.0 : Thu Sep 13 2012 - 19:31:25 CEST