Handle backslashes within #include, #error, #warning

This commit is contained in:
grischka 2007-12-17 19:35:15 +00:00
parent 6c96c41ee4
commit adb1456472
2 changed files with 22 additions and 11 deletions

View File

@ -1,12 +1,10 @@
version 0.9.24:
- Handle backslashes within #include, #error, #warning
- Import changesets (part 4) 428,457,460,467: defines for openbsd etc.
- Use _WIN32 for a windows hosted tcc and define it for the PE target,
otherwise define __unix / __linux (Detlef Riekenberg)
- Import changesets (part 3) 409,410: ARM EABI by Daniel Glöckner
- Some in-between fixes:
TCC -E no longer hangs with macro calls involving newlines.
(next_nomacro1 now advances the read-pointer with TOK_LINEFEED)

29
tcc.c
View File

@ -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)