version 1.126, 2016/10/16 19:04:05 |
version 1.127, 2016/10/21 13:51:59 |
|
|
cmd_template_replace(const char *template, const char *s, int idx) |
cmd_template_replace(const char *template, const char *s, int idx) |
{ |
{ |
char ch, *buf; |
char ch, *buf; |
const char *ptr; |
const char *ptr, *cp; |
int replaced; |
int replaced, quoted; |
size_t len; |
size_t len; |
|
|
if (strchr(template, '%') == NULL) |
if (strchr(template, '%') == NULL) |
|
|
} |
} |
ptr++; |
ptr++; |
|
|
len += strlen(s); |
quoted = (*ptr == '%'); |
buf = xrealloc(buf, len + 1); |
if (quoted) |
strlcat(buf, s, len + 1); |
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; |
continue; |
} |
} |
buf = xrealloc(buf, len + 2); |
buf = xrealloc(buf, len + 2); |