diff options
author | nicm <nicm> | 2016-10-21 13:51:59 +0000 |
---|---|---|
committer | nicm <nicm> | 2016-10-21 13:51:59 +0000 |
commit | 8084a2c9e60b8cc0c32b55f23bfd7b839f082252 (patch) | |
tree | bc599d4a06ad465f6b6d905d1516e6c7fb8d02bb /cmd.c | |
parent | 99c262b7d0a2f41497327e8f5caefde802178346 (diff) | |
download | rtmux-8084a2c9e60b8cc0c32b55f23bfd7b839f082252.tar.gz rtmux-8084a2c9e60b8cc0c32b55f23bfd7b839f082252.tar.bz2 rtmux-8084a2c9e60b8cc0c32b55f23bfd7b839f082252.zip |
Add %%% to substitute with quotes escaped (convert " to \"). Use this
for the prompts in copy mode. Fixes problems with jumping to ' reported
by Theo Buehler.
Diffstat (limited to 'cmd.c')
-rw-r--r-- | cmd.c | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -653,8 +653,8 @@ char * cmd_template_replace(const char *template, const char *s, int idx) { char ch, *buf; - const char *ptr; - int replaced; + const char *ptr, *cp; + int replaced, quoted; size_t len; if (strchr(template, '%') == NULL) @@ -676,9 +676,17 @@ cmd_template_replace(const char *template, const char *s, int idx) } ptr++; - len += strlen(s); - buf = xrealloc(buf, len + 1); - strlcat(buf, s, len + 1); + quoted = (*ptr == '%'); + if (quoted) + ptr++; + + buf = xrealloc(buf, len + (strlen(s) * 2) + 1); + for (cp = s; *cp != '\0'; cp++) { + if (quoted && *cp == '"') + buf[len++] = '\\'; + buf[len++] = *cp; + } + buf[len] = '\0'; continue; } buf = xrealloc(buf, len + 2); |