summaryrefslogtreecommitdiffstats
path: root/cmd-string.c
authornicm <nicm>2009-02-08 16:38:19 (GMT)
committer nicm <nicm>2009-02-08 16:38:19 (GMT)
commitb85c275708fb74e62a420548b06a9a288693eb31 (patch) (side-by-side diff)
treef744b051893ccb8460f8481a983fd2ab3f8ac43a /cmd-string.c
parent9f5350e797bf3a8af2adcd2b6732115b8932d9e9 (diff)
downloadtmux-old-b85c275708fb74e62a420548b06a9a288693eb31.zip
tmux-old-b85c275708fb74e62a420548b06a9a288693eb31.tar.gz
tmux-old-b85c275708fb74e62a420548b06a9a288693eb31.tar.bz2
Handle "" properly.
Diffstat (limited to 'cmd-string.c') (more/less context) (ignore whitespace changes)
-rw-r--r--cmd-string.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/cmd-string.c b/cmd-string.c
index 7486325..940d698 100644
--- a/cmd-string.c
+++ b/cmd-string.c
@@ -56,7 +56,7 @@ int
cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
{
size_t p;
- int ch, argc, rval;
+ int ch, argc, rval, have_arg;
char **argv, *buf, *t, *u;
size_t len;
@@ -77,6 +77,8 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
buf = NULL;
len = 0;
+ have_arg = 0;
+
*cause = NULL;
*cmdlist = NULL;
@@ -92,6 +94,8 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
buf = xrealloc(buf, 1, len + strlen(t) + 1);
strlcpy(buf + len, t, strlen(t) + 1);
len += strlen(t);
+
+ have_arg = 1;
break;
case '"':
if ((t = cmd_string_string(s, &p, '"', 1)) == NULL)
@@ -99,6 +103,8 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
buf = xrealloc(buf, 1, len + strlen(t) + 1);
strlcpy(buf + len, t, strlen(t) + 1);
len += strlen(t);
+
+ have_arg = 1;
break;
case '$':
if ((t = cmd_string_variable(s, &p)) == NULL)
@@ -106,6 +112,8 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
buf = xrealloc(buf, 1, len + strlen(t) + 1);
strlcpy(buf + len, t, strlen(t) + 1);
len += strlen(t);
+
+ have_arg = 1;
break;
case '#':
/* Comment: discard rest of line. */
@@ -115,7 +123,7 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
case EOF:
case ' ':
case '\t':
- if (len != 0) {
+ if (have_arg) {
buf = xrealloc(buf, 1, len + 1);
buf[len] = '\0';
@@ -124,6 +132,8 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
buf = NULL;
len = 0;
+
+ have_arg = 0;
}
if (ch != EOF)
@@ -143,6 +153,8 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
buf = xrealloc(buf, 1, len + 1);
buf[len++] = ch;
+
+ have_arg = 1;
break;
}
}