aboutsummaryrefslogtreecommitdiff
path: root/pp.c
diff options
context:
space:
mode:
Diffstat (limited to 'pp.c')
-rw-r--r--pp.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/pp.c b/pp.c
index c861852..c03e4b1 100644
--- a/pp.c
+++ b/pp.c
@@ -386,9 +386,18 @@ stringize(struct array *buf, struct token *t)
{
const char *lit;
+ if ((t->space || t->kind == TNEWLINE) && ((char *)buf->val)[buf->len - 1] != ' ')
+ arrayaddbuf(buf, " ", 1);
lit = t->lit ? t->lit : tokstr[t->kind];
- /* XXX: double escape string literal */
- arrayaddbuf(buf, lit, strlen(lit));
+ if (t->kind == TSTRINGLIT || t->kind == TCHARCONST) {
+ for (; *lit; ++lit) {
+ if (*lit == '\\' || *lit == '"')
+ arrayaddbuf(buf, "\\", 1);
+ arrayaddbuf(buf, lit, 1);
+ }
+ } else if (lit) {
+ arrayaddbuf(buf, lit, strlen(lit));
+ }
}
static bool