2 http://tools.suckless.org/dmenu/patches/xmms-like_pattern_matching
4 diff -up dmenu-4.1.1/config.def.h dmenu-4.1.1_xmms/config.def.h
5 --- dmenu-4.1.1/config.def.h 2009-04-18 13:50:04.000000000 +0200
6 +++ dmenu-4.1.1_xmms/config.def.h 2009-11-19 21:31:17.000000000 +0100
7 @@ -7,3 +7,4 @@ static const char *normfgcolor = "#00000
8 static const char *selbgcolor = "#0066ff";
9 static const char *selfgcolor = "#ffffff";
10 static unsigned int spaceitem = 30; /* px between menu items */
11 +static unsigned int maxtokens = 16; /* max. tokens for pattern matching */
12 diff -up dmenu-4.1.1/dmenu.1 dmenu-4.1.1_xmms/dmenu.1
13 --- dmenu-4.1.1/dmenu.1 2009-04-18 13:50:04.000000000 +0200
14 +++ dmenu-4.1.1_xmms/dmenu.1 2009-11-19 21:14:24.000000000 +0100
15 @@ -11,6 +11,7 @@ dmenu \- dynamic menu
16 .RB [ \-p " <prompt>"]
17 .RB [ \-sb " <color>"]
18 .RB [ \-sf " <color>"]
23 @@ -44,6 +45,9 @@ defines the selected background color (#
25 defines the selected foreground color (#RGB, #RRGGBB, and color names are supported).
28 +xmms-like pattern matching.
31 prints version information to standard output, then exits.
33 diff -u dmenu-4.1.1/dmenu.c.orig dmenu-4.1.1/dmenu.c
34 --- dmenu-4.1.1/dmenu.c.orig 2010-05-29 13:56:51.000000000 +0200
35 +++ dmenu-4.1.1/dmenu.c 2010-07-05 22:23:30.000000000 +0200
38 static char *maxname = NULL;
39 static char *prompt = NULL;
40 +static char **tokens = NULL;
41 static char text[4096];
43 static int promptw = 0;
45 static unsigned int mw, mh;
46 static unsigned int numlockmask = 0;
47 static Bool running = True;
48 +static Bool xmms = False;
51 static Item *allitems = NULL; /* first of all items */
56 +unsigned int tokenize(char *pat, char **tok)
59 + char tmp[4096] = {0};
61 + strncpy(tmp, pat, strlen(pat));
62 + tok[0] = strtok(tmp, " ");
64 + while(tok[i] && i < maxtokens)
65 + tok[++i] = strtok(NULL, " ");
70 match(char *pattern) {
72 + unsigned int plen, tokencnt = 0;
74 Item *i, *itemend, *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend;
78 - plen = strlen(pattern);
81 + tokens[(tokencnt = 1)-1] = pattern;
83 + if(!(tokencnt = tokenize(pattern, tokens)))
84 + tokens[(tokencnt = 1)-1] = "";
85 item = lexact = lprefix = lsubstr = itemend = exactend = prefixend = substrend = NULL;
86 - for(i = allitems; i; i = i->next)
87 - if(!fstrncmp(pattern, i->text, plen + 1))
88 + for(i = allitems; i; i = i->next) {
89 + for(int j = 0; j < tokencnt; ++j) {
90 + plen = strlen(tokens[j]);
91 + if(!fstrncmp(tokens[j], i->text, plen + 1))
92 + append = !append || append > 1 ? 1 : append;
93 + else if(!fstrncmp(tokens[j], i->text, plen ))
94 + append = !append || append > 2 ? 2 : append;
95 + else if(fstrstr(i->text, tokens[j]))
96 + append = append > 0 && append < 3 ? append : 3;
103 appenditem(i, &lexact, &exactend);
104 - else if(!fstrncmp(pattern, i->text, plen))
105 + else if(append == 2)
106 appenditem(i, &lprefix, &prefixend);
107 - else if(fstrstr(i->text, pattern))
108 + else if(append == 3)
109 appenditem(i, &lsubstr, &substrend);
116 promptw = MIN(textw(prompt), mw / 5);
118 + tokens = malloc((xmms?maxtokens:1)*sizeof(char*));
120 XMapRaised(dpy, win);
122 @@ -806,11 +842,13 @@
123 else if(!strcmp(argv[i], "-sf")) {
124 if(++i < argc) selfgcolor = argv[i];
126 + else if(!strcmp(argv[i], "-xs"))
128 else if(!strcmp(argv[i], "-v"))
129 eprint("dmenu-"VERSION", © 2006-2010 dmenu engineers, see LICENSE for details\n");
131 eprint("usage: dmenu [-i] [-b] [-e <xid>] [-l <lines>] [-fn <font>] [-nb <color>]\n"
132 - " [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n");
133 + " [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-xs] [-v]\n");
134 if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
135 fprintf(stderr, "warning: no locale support\n");
136 if(!(dpy = XOpenDisplay(NULL)))