aboutsummaryrefslogtreecommitdiff
path: root/tcc.c
diff options
context:
space:
mode:
Diffstat (limited to 'tcc.c')
-rw-r--r--tcc.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/tcc.c b/tcc.c
index ce1a210..c43d919 100644
--- a/tcc.c
+++ b/tcc.c
@@ -1967,7 +1967,7 @@ static inline void inp(void)
}
/* handle '\[\r]\n' */
-static void handle_stray(void)
+static int handle_stray_noerror(void)
{
while (ch == '\\') {
inp();
@@ -1982,9 +1982,16 @@ static void handle_stray(void)
inp();
} else {
fail:
- error("stray '\\' in program");
+ return 1;
}
}
+ return 0;
+}
+
+static void handle_stray(void)
+{
+ if (handle_stray_noerror())
+ error("stray '\\' in program");
}
/* skip the stray and handle the \\n case. Output an error if
@@ -2264,9 +2271,8 @@ void preprocess_skip(void)
if (c == CH_EOF) {
expect("#endif");
} else if (c == '\\') {
- /* XXX: incorrect: should not give an error */
ch = file->buf_ptr[0];
- handle_stray();
+ handle_stray_noerror();
}
p = file->buf_ptr;
goto redo_no_start;
@@ -2896,13 +2902,16 @@ static void preprocess(int is_bof)
} else if (ch == '\"') {
c = ch;
read_name:
- /* XXX: better stray handling */
- minp();
+ inp();
q = buf;
while (ch != c && ch != '\n' && ch != CH_EOF) {
if ((q - buf) < sizeof(buf) - 1)
*q++ = ch;
- minp();
+ if (ch == '\\') {
+ if (handle_stray_noerror() == 0)
+ --q;
+ } else
+ inp();
}
*q = '\0';
minp();
@@ -3104,7 +3113,11 @@ static void preprocess(int is_bof)
while (ch != '\n' && ch != CH_EOF) {
if ((q - buf) < sizeof(buf) - 1)
*q++ = ch;
- minp();
+ if (ch == '\\') {
+ if (handle_stray_noerror() == 0)
+ --q;
+ } else
+ inp();
}
*q = '\0';
if (c == TOK_ERROR)