From ec46c5fd98d4fd6460b939a8d31ed7a472ec5770 Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Tue, 24 May 2011 15:58:56 +0430 Subject: [PATCH] cpp: ignore comments inside string macros --- cpp.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/cpp.c b/cpp.c index e43f050..57a9075 100644 --- a/cpp.c +++ b/cpp.c @@ -181,15 +181,39 @@ static int jumpcomment(void) return 1; } +static int jumpstr(void) +{ + if (buf[cur] == '\'') { + while (cur < len && buf[++cur] != '\'') + if (buf[cur] == '\\') + cur++; + cur++; + return 0; + } + if (buf[cur] == '"') { + while (cur < len && buf[++cur] != '"') + if (buf[cur] == '\\') + cur++; + cur++; + return 0; + } + return 1; +} + static void read_tilleol(char *dst) { while (cur < len && isspace(buf[cur]) && buf[cur] != '\n') cur++; while (cur < len && buf[cur] != '\n') { - if (buf[cur] == '\\' && buf[cur + 1] == '\n') + int last = cur; + if (buf[cur] == '\\' && buf[cur + 1] == '\n') { cur += 2; - else if (jumpcomment()) + } else if (jumpcomment()) { *dst++ = buf[cur++]; + } else if (jumpstr()) { + memcpy(dst, buf + last, cur - last); + dst += cur - last; + } } *dst = '\0'; } @@ -230,25 +254,6 @@ static int include_find(char *name, int std) return -1; } -static int jumpstr(void) -{ - if (buf[cur] == '\'') { - while (cur < len && buf[++cur] != '\'') - if (buf[cur] == '\\') - cur++; - cur++; - return 0; - } - if (buf[cur] == '"') { - while (cur < len && buf[++cur] != '"') - if (buf[cur] == '\\') - cur++; - cur++; - return 0; - } - return 1; -} - static void readarg(char *s) { int depth = 0; -- 2.11.4.GIT