dwm-noxz

[fork] suckless dwm - personal fork
git clone https://noxz.tech/git/dwm-noxz.git
dwm-noxz

commit: ba6c0542ec0e92f109a948563e5617358d709813
parent: 76cc0eb6180a23f6b3b045cad4aa35fceadfe520
author: Chris Noxz <chris@noxz.tech>
date:   Wed, 28 Jun 2023 15:51:26 +0200
Handle cmdline containing quotes
Mdwm.c32++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/dwm.c b/dwm.c
@@ -174,6 +174,7 @@ static void destroynotify(XEvent *e);
 static void detach(Client *c);
 static void detachstack(Client *c);
 static Monitor *dirtomon(int dir);
+static char *strmbtok(char *, const char *);
 static void strsplit(char *, char ***, const char *);
 static void dispatchline(const char*, int, void (*)(const Arg*), const Arg*);
 static void dispatchcmd(void);
@@ -734,17 +735,44 @@ dirtomon(int dir)
 	return m;
 }
 
+char *
+strmbtok(char *str, const char *toks)
+{
+	static char *tok = NULL;
+	char *lead = NULL;
+	Bool block = False;
+
+	if (str != NULL)
+		tok = lead = str;
+	else if (*(lead = tok) == '\0')
+		lead = NULL;
+
+	while (*tok != '\0') {
+		if (block && '\"' == *tok) {
+			block = False;
+		} else if (!block && '\"' == *tok) {
+			block = True;
+		} else if (!block && strchr(toks, *tok) != NULL) {
+			*tok = '\0';
+			tok++;
+			break;
+		}
+		tok++;
+	}
+	return lead;
+}
+
 void
 strsplit(char *str, char ***arr, const char *toks)
 {
-	char *p = strtok(str, toks);
+	char *p = strmbtok(str, toks);
 	int len = 0;
 
 	while (p) {
 		if ((*arr = realloc(*arr, sizeof (char*) * ++len)) == NULL)
 			die("realloc: failed\n");
 		(*arr)[len - 1] = p;
-		p = strtok(NULL, toks);
+		p = strmbtok(NULL, toks);
 	}
 
 	if ((*arr = realloc(*arr, sizeof (char*) * (len + 1))) == NULL)