summaryrefslogtreecommitdiffstats
path: root/cmd.c
diff options
context:
space:
mode:
authornicm <nicm>2020-06-04 07:12:05 +0000
committernicm <nicm>2020-06-04 07:12:05 +0000
commitb3782d2dc8f872c43fcf53b9436c4e881d3f1e2d (patch)
treef7c75fcbdc0ce56e6f55cce00480a49a3dd02f84 /cmd.c
parent3f6af4156f451cfbee867babe74cc6675eb3f947 (diff)
Instead of using a custom parse function to process {}, treat it as a
set of statements and parse with yacc, then convert back to a string as the last step. This means the rules are consistent inside and outside {}, %if and friends work at the right time, and the final result isn't littered with unnecessary newlines.
Diffstat (limited to 'cmd.c')
-rw-r--r--cmd.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/cmd.c b/cmd.c
index 8a977023..f6023c20 100644
--- a/cmd.c
+++ b/cmd.c
@@ -357,25 +357,27 @@ cmd_free_argv(int argc, char **argv)
char *
cmd_stringify_argv(int argc, char **argv)
{
- char *buf;
+ char *buf = NULL, *s;
+ size_t len = 0;
int i;
- size_t len;
if (argc == 0)
return (xstrdup(""));
- len = 0;
- buf = NULL;
-
for (i = 0; i < argc; i++) {
- len += strlen(argv[i]) + 1;
+ s = args_escape(argv[i]);
+ log_debug("%s: %u %s = %s", __func__, i, argv[i], s);
+
+ len += strlen(s) + 1;
buf = xrealloc(buf, len);
if (i == 0)
*buf = '\0';
else
strlcat(buf, " ", len);
- strlcat(buf, argv[i], len);
+ strlcat(buf, s, len);
+
+ free(s);
}
return (buf);
}