From b3782d2dc8f872c43fcf53b9436c4e881d3f1e2d Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 4 Jun 2020 07:12:05 +0000 Subject: 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. --- cmd.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'cmd.c') 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); } -- cgit