commit 11c2f9d8aedc5338cdb03b6c53d9461e12f9aaaa parent 1126acd115d8cded1f3b6a6e20134b60266f382e Author: Roberto E. Vargas Caballero <k0ga@shike2.com> Date: Mon, 11 May 2015 16:29:28 +0200 Merge consecutive strings Diffstat:
M | cc1/lex.c | | | 26 | ++++++++++++++++++++------ |
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/cc1/lex.c b/cc1/lex.c @@ -1,5 +1,4 @@ -#include <assert.h> #include <errno.h> #include <inttypes.h> #include <setjmp.h> @@ -353,21 +352,36 @@ character(void) static uint8_t string(void) { - static char buf[STRINGSIZ+1]; + char buf[STRINGSIZ+1]; Symbol *sym; char *bp = buf, c; - assert(STRINGSIZ <= INPUTSIZ); - for (++input->p; (c = *input->p) != '\0'; ++input->p) { - if (c == '"') - break; +repeat: + for (++input->p; (c = *input->p) != '\0' && c != '"'; ++input->p) { if (c == '\\') c = escape(); + if (bp == &buf[STRINGSIZ]) + error("string too long"); *bp++ = c; } if (c == '\0') error("missing terminating '\"' character"); + ++input->p; + + for (;;) { + if (isspace((c = *input->p))) { + ++input->p; + } else if (c == '\0') { + input->begin = input->p; + fill(); + } else if (c == '"') { + goto repeat; + } else { + break; + } + } + *bp = '\0'; sym = install("", NS_IDEN); sym->u.s = xstrdup(buf);