[dev] [dmenu] [PATCH] Added -d delim option.

From: Alexander Sedov <alex0player_AT_gmail.com>
Date: Thu, 18 Apr 2013 12:59:35 +0400

Allows to configure which characters are used for tokenizing input string.
Passing empty string disables tokenizing.
---
This is the patch that adds configurable behaviour for this feature.
If maintainer feels like including it in upstream, fine.
Else, topicstarter may download this email and apply it with git am,
and I'll add it into wiki after a short time.
 dmenu.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/dmenu.c b/dmenu.c
index a06ae15..05db5bf 100644
--- a/dmenu.c
+++ b/dmenu.c
_AT_@ -40,6 +40,7 @@ static void run(void);
 static void setup(void);
 static void usage(void);
 
+static const char *delim = " ";
 static char text[BUFSIZ] = "";
 static int bh, mw, mh;
 static int inputw, promptw;
_AT_@ -82,6 +83,8 @@ main(int argc, char *argv[]) {
 		else if(i+1 == argc)
 			usage();
 		/* these options take one argument */
+		else if(!strcmp(argv[i], "-d"))
+			delim = argv[++i];
 		else if(!strcmp(argv[i], "-l"))   /* number of lines in vertical list */
 			lines = atoi(argv[++i]);
 		else if(!strcmp(argv[i], "-p"))   /* adds prompt to left of input field */
_AT_@ -405,7 +408,7 @@ match(void) {
 
 	strcpy(buf, text);
 	/* separate input text into tokens to be matched individually */
-	for(s = strtok(buf, " "); s; tokv[tokc-1] = s, s = strtok(NULL, " "))
+	for(s = strtok(buf, delim); s; tokv[tokc-1] = s, s = strtok(NULL, delim))
 		if(++tokc > tokn && !(tokv = realloc(tokv, ++tokn * sizeof *tokv)))
 			eprintf("cannot realloc %u bytes\n", tokn * sizeof *tokv);
 	len = tokc ? strlen(tokv[0]) : 0;
_AT_@ -612,7 +615,7 @@ setup(void) {
 
 void
 usage(void) {
-	fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font]\n"
+	fputs("usage: dmenu [-b] [-f] [-i] [-d delim] [-l lines] [-p prompt] [-fn font]\n"
 	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n", stderr);
 	exit(EXIT_FAILURE);
 }
-- 
1.7.10.4
Received on Thu Apr 18 2013 - 10:59:35 CEST

This archive was generated by hypermail 2.3.0 : Thu Apr 18 2013 - 11:12:02 CEST