commit 61d8cb619913f5b54df22c02c97b999e592ef70f
parent b17cc0af133dcaeb60d742159836cae7d0d431f7
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 31 Oct 2021 09:51:32 +0100
cc1: Improve escaped characters in outcpp()
The reverse escaping was lacking a lot of the escape
sequences, making a bit unusable the output of cpp.
Diffstat:
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/cmd/cc/cc1/cpp.c b/src/cmd/cc/cc1/cpp.c
@@ -805,7 +805,7 @@ outcpp(void)
printf("%s ", yytext);
continue;
}
- for (s = yytext; c = *s; ++s) {
+ for (s = yytext; (c = *s) != '\0'; ++s) {
switch (c) {
case '\n':
t = "\\n";
@@ -822,9 +822,27 @@ outcpp(void)
case '\a':
t = "\\a";
goto print_str;
+ case '\f':
+ t = "\\f";
+ goto print_str;
+ case '\r':
+ t = "\\r";
+ goto print_str;
+ case '"':
+ if (s == yytext || s[1] == '\0')
+ goto print_chr;
+ t = "\\\"";
+ goto print_str;
+ case '\'':
+ t = "\\'";
+ goto print_str;
+ case '\?':
+ t = "\\\?";
+ goto print_str;
case '\\':
putchar('\\');
default:
+ print_chr:
if (!isprint(c))
printf("\\x%x", c);
else