X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=quote.c;h=e220dcc280d9ed6be2e2357e2660c7e828f3631b;hb=5f468c4805c785115cd9c5f6a8f299f23a9034f5;hp=7218a7080d9a4282530b58c013606c86e4a5fdf5;hpb=d69dc373cbf58d88d19dcbc6cff37e12b17f8fd2;p=git.git diff --git a/quote.c b/quote.c index 7218a7080..e220dcc28 100644 --- a/quote.c +++ b/quote.c @@ -13,7 +13,7 @@ * a!b ==> a'\!'b ==> 'a'\!'b' */ #undef EMIT -#define EMIT(x) ( (++len < n) && (*bp++ = (x)) ) +#define EMIT(x) do { if (++len < n) *bp++ = (x); } while(0) static inline int need_bs_quote(char c) { @@ -45,6 +45,23 @@ size_t sq_quote_buf(char *dst, size_t n, const char *src) return len; } +void sq_quote_print(FILE *stream, const char *src) +{ + char c; + + fputc('\'', stream); + while ((c = *src++)) { + if (need_bs_quote(c)) { + fputs("'\\", stream); + fputc(c, stream); + fputc('\'', stream); + } else { + fputc(c, stream); + } + } + fputc('\'', stream); +} + char *sq_quote(const char *src) { char *buf; @@ -144,8 +161,6 @@ static int quote_c_style_counted(const char *name, int namelen, case '\\': /* fallthru */ case '"': EMITQ(); break; - case ' ': - break; default: /* octal */ EMITQ(); @@ -208,7 +223,14 @@ char *unquote_c_style(const char *quoted, const char **endp) case '\\': case '"': break; /* verbatim */ - case '0'...'7': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': /* octal */ ac = ((ch - '0') << 6); if ((ch = *sp++) < '0' || '7' < ch)