free(to_free);
}
+void sq_quote_buf_pretty(struct strbuf *dst, const char *src)
+{
+ static const char ok_punct[] = "+,-./:=@_^";
+ const char *p;
+
+ for (p = src; *p; p++) {
+ if (!isalpha(*p) && !isdigit(*p) && !strchr(ok_punct, *p)) {
+ sq_quote_buf(dst, src);
+ return;
+ }
+ }
+
+ /* if we get here, we did not need quoting */
+ strbuf_addstr(dst, src);
+}
+
void sq_quotef(struct strbuf *dst, const char *fmt, ...)
{
struct strbuf src = STRBUF_INIT;
strbuf_release(&src);
}
-void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen)
+void sq_quote_argv(struct strbuf *dst, const char **argv)
{
int i;
for (i = 0; argv[i]; ++i) {
strbuf_addch(dst, ' ');
sq_quote_buf(dst, argv[i]);
- if (maxlen && dst->len > maxlen)
- die("Too many or long arguments");
+ }
+}
+
+void sq_quote_argv_pretty(struct strbuf *dst, const char **argv)
+{
+ int i;
+
+ for (i = 0; argv[i]; i++) {
+ strbuf_addch(dst, ' ');
+ sq_quote_buf_pretty(dst, argv[i]);
}
}
*next = NULL;
return arg;
case '\\':
- c = *++src;
- if (need_bs_quote(c) && *++src == '\'') {
- *dst++ = c;
+ /*
+ * Allow backslashed characters outside of
+ * single-quotes only if they need escaping,
+ * and only if we resume the single-quoted part
+ * afterward.
+ */
+ if (need_bs_quote(src[1]) && src[2] == '\'') {
+ *dst++ = src[1];
+ src += 2;
continue;
}
/* Fallthrough */
* Return value is the same as in (1).
*/
static size_t quote_c_style_counted(const char *name, ssize_t maxlen,
- struct strbuf *sb, FILE *fp, int no_dq)
+ struct strbuf *sb, FILE *fp, int no_dq)
{
#undef EMIT
#define EMIT(c) \