Fix escaping by remembering state, allows "\\" to be used as text.
Thanks to rephorm for hints, dj2 and mekius for review. SVN revision: 30769
This commit is contained in:
parent
0e45d25776
commit
233ecdf481
|
@ -165,6 +165,7 @@ next_token(char *p, char *end, char **new_p, int *delim)
|
||||||
int in_comment_cpp = 0;
|
int in_comment_cpp = 0;
|
||||||
int in_comment_sa = 0;
|
int in_comment_sa = 0;
|
||||||
int had_quote = 0;
|
int had_quote = 0;
|
||||||
|
int is_escaped = 0;
|
||||||
char *cpp_token_line = NULL;
|
char *cpp_token_line = NULL;
|
||||||
char *cpp_token_file = NULL;
|
char *cpp_token_file = NULL;
|
||||||
|
|
||||||
|
@ -255,15 +256,19 @@ next_token(char *p, char *end, char **new_p, int *delim)
|
||||||
{
|
{
|
||||||
if (in_quote)
|
if (in_quote)
|
||||||
{
|
{
|
||||||
if (((*p) == '"') && (*(p - 1) != '\\'))
|
if ((*p) == '\\')
|
||||||
|
is_escaped = !is_escaped;
|
||||||
|
else if (((*p) == '"') && (!is_escaped))
|
||||||
{
|
{
|
||||||
in_quote = 0;
|
in_quote = 0;
|
||||||
had_quote = 1;
|
had_quote = 1;
|
||||||
}
|
}
|
||||||
|
else if (is_escaped)
|
||||||
|
is_escaped = 0;
|
||||||
}
|
}
|
||||||
else if (in_parens)
|
else if (in_parens)
|
||||||
{
|
{
|
||||||
if (((*p) == ')') && (*(p - 1) != '\\'))
|
if (((*p) == ')') && (!is_escaped))
|
||||||
in_parens--;
|
in_parens--;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -310,12 +315,12 @@ next_token(char *p, char *end, char **new_p, int *delim)
|
||||||
|
|
||||||
if (had_quote)
|
if (had_quote)
|
||||||
{
|
{
|
||||||
|
is_escaped = 0;
|
||||||
p = tok;
|
p = tok;
|
||||||
|
|
||||||
while (*p)
|
while (*p)
|
||||||
{
|
{
|
||||||
if ((*p == '\"') &&
|
if ((*p == '\"') && (!is_escaped))
|
||||||
((p == tok) || ((p > tok) && (*(p - 1) != '\\'))))
|
|
||||||
{
|
{
|
||||||
memmove(p, p + 1, strlen(p));
|
memmove(p, p + 1, strlen(p));
|
||||||
}
|
}
|
||||||
|
@ -332,13 +337,16 @@ next_token(char *p, char *end, char **new_p, int *delim)
|
||||||
else if (*p == '\\')
|
else if (*p == '\\')
|
||||||
{
|
{
|
||||||
memmove(p, p + 1, strlen(p));
|
memmove(p, p + 1, strlen(p));
|
||||||
p++;
|
|
||||||
if (*p == '\\') p++;
|
if (*p == '\\') p++;
|
||||||
|
else is_escaped = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (is_escaped) is_escaped = 0;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (tok && *tok == '(')
|
else if (tok && *tok == '(')
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
Loading…
Reference in New Issue