X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=quote.c;h=fb9e4ca253ea9bcadbcb55dcdd62be614c66758f;hb=0b59451c1be6be3d0df80be9dc8aeedb355ca44b;hp=e3a4d4aef3478148ff89aebeba23e1cbf4202ba1;hpb=69de8cc8527dc45a7aef76e8f1ace45b509b3712;p=git.git diff --git a/quote.c b/quote.c index e3a4d4aef..fb9e4ca25 100644 --- a/quote.c +++ b/quote.c @@ -209,7 +209,7 @@ static int quote_c_style_counted(const char *name, int namelen, if (!ch) break; if ((ch < ' ') || (ch == '"') || (ch == '\\') || - (ch == 0177)) { + (ch >= 0177)) { needquote = 1; switch (ch) { case '\a': EMITQ(); ch = 'a'; break; @@ -349,3 +349,75 @@ void write_name_quoted(const char *prefix, int prefix_len, else goto no_quote; } + +/* quoting as a string literal for other languages */ + +void perl_quote_print(FILE *stream, const char *src) +{ + const char sq = '\''; + const char bq = '\\'; + char c; + + fputc(sq, stream); + while ((c = *src++)) { + if (c == sq || c == bq) + fputc(bq, stream); + fputc(c, stream); + } + fputc(sq, stream); +} + +void python_quote_print(FILE *stream, const char *src) +{ + const char sq = '\''; + const char bq = '\\'; + const char nl = '\n'; + char c; + + fputc(sq, stream); + while ((c = *src++)) { + if (c == nl) { + fputc(bq, stream); + fputc('n', stream); + continue; + } + if (c == sq || c == bq) + fputc(bq, stream); + fputc(c, stream); + } + fputc(sq, stream); +} + +void tcl_quote_print(FILE *stream, const char *src) +{ + char c; + + fputc('"', stream); + while ((c = *src++)) { + switch (c) { + case '[': case ']': + case '{': case '}': + case '$': case '\\': case '"': + fputc('\\', stream); + default: + fputc(c, stream); + break; + case '\f': + fputs("\\f", stream); + break; + case '\r': + fputs("\\r", stream); + break; + case '\n': + fputs("\\n", stream); + break; + case '\t': + fputs("\\t", stream); + break; + case '\v': + fputs("\\v", stream); + break; + } + } + fputc('"', stream); +}