From 517ced5334f62771153cc16c73ba382c7da42f8e Mon Sep 17 00:00:00 2001 From: Toby Goodwin Date: Mon, 1 Sep 2014 22:39:21 +0100 Subject: fix both Zekoll and Neukirchen bugs --- lex.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'lex.c') diff --git a/lex.c b/lex.c index 4a61b40..0179521 100644 --- a/lex.c +++ b/lex.c @@ -35,6 +35,7 @@ static void getpair(int); int lineno; +/* lookup table for non-word characters */ const char nw[] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, @@ -46,6 +47,7 @@ const char nw[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +/* lookup table for non-word characters in variable names */ const char dnw[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, @@ -57,6 +59,18 @@ const char dnw[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; +/* lookup table for quotable characters: nw + glob metachars */ +const char q[] = { + 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + static size_t bufsize = BUFSIZE; static char *realbuf = NULL; static bool newline = FALSE; @@ -76,7 +90,7 @@ extern bool quotep(char *s, bool dollar) { unsigned char c; const char *meta; - meta = dollar ? dnw : nw; + meta = dollar ? dnw : q; while ((c = *s++)) if (meta[c]) return TRUE; @@ -97,7 +111,6 @@ extern int yylex() { } /* rc variable-names may contain only alnum, '*' and '_', so use dnw if we are scanning one. */ meta = (dollar ? dnw : nw); - dollar = FALSE; if (newline) { --lineno; /* slight space optimization; nextline() always increments lineno */ nextline(); @@ -105,6 +118,7 @@ extern int yylex() { } top: while ((c = gchar()) == ' ' || c == '\t') w = NW; + if (c != '(') dollar = FALSE; if (c == EOF) return END; if (!meta[(unsigned char) c]) { /* it's a word or keyword. */ @@ -225,7 +239,7 @@ top: while ((c = gchar()) == ' ' || c == '\t') i = 0; goto bs; case '(': - if (w == RW) /* SUB's happen only after real words, not keyowrds, so if () and while () work */ + if (w == RW) /* SUB's happen only after real words, not keywords, so if () and while () work */ c = SUB; w = NW; return c; -- cgit v1.2.3