preproc: correctly handle quoted strings inside %[...] constructs

We need to skip quoted strings when determining the ending point of
%[...] constructs.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2008-10-19 19:30:11 -07:00
parent 0ca00860df
commit ca544db4b6

View File

@ -779,7 +779,7 @@ static char *read_line(void)
*/
static Token *tokenize(char *line)
{
char *p = line;
char c, *p = line;
enum pp_token_type type;
Token *list = NULL;
Token *t, **tail = &list;
@ -810,12 +810,23 @@ static Token *tokenize(char *line)
int lvl = 1;
line += 2; /* Skip the leading %[ */
p++;
while (*p) {
if (*p == ']') {
if (!--lvl)
break;
} else if (*p == '%' && p[1] == '[') {
lvl++;
while (lvl && (c = *p)) {
switch (c) {
case ']':
lvl--;
break;
case '%':
p++;
if (*p == '[')
lvl++;
break;
case '\'':
case '\"':
case '`':
p = nasm_skip_string(p);
break;
default:
break;
}
p++;
}