klibc-bot for Herbert Xu
2020-Mar-28 21:48 UTC
[klibc] [klibc:update-dash] dash: [PARSER] Simplify EOF/newline handling in list parser
Commit-ID: a5a6a6ba303805417242138104643d8c40d71d00 Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=a5a6a6ba303805417242138104643d8c40d71d00 Author: Herbert Xu <herbert at gondor.apana.org.au> AuthorDate: Tue, 28 Oct 2014 17:22:16 +0800 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Sat, 28 Mar 2020 21:42:54 +0000 [klibc] dash: [PARSER] Simplify EOF/newline handling in list parser [ dash commit 7c245aa8ed33ba5db30eef9369d67036a05b0371 ] This patch simplifies the EOF and new handling in the list parser. In particular, it eliminates a case where we may leave here-documents unfinished upon EOF. It also removes special EOF/newline handling from parsecmd. Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au> Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/dash/parser.c | 60 ++++++++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/usr/dash/parser.c b/usr/dash/parser.c index f0c919d5..382ddf24 100644 --- a/usr/dash/parser.c +++ b/usr/dash/parser.c @@ -135,19 +135,13 @@ static inline int realeofmark(const char *eofmark) union node * parsecmd(int interact) { - int t; - tokpushback = 0; + checkkwd = 0; + heredoclist = 0; doprompt = interact; if (doprompt) setprompt(doprompt); needprompt = 0; - t = readtoken(); - if (t == TEOF) - return NEOF; - if (t == TNL) - return NULL; - tokpushback++; return list(1); } @@ -158,11 +152,27 @@ list(int nlflag) union node *n1, *n2, *n3; int tok; - checkkwd = CHKNL | CHKKWD | CHKALIAS; - if (nlflag == 2 && tokendlist[peektoken()]) - return NULL; n1 = NULL; for (;;) { + switch (peektoken()) { + case TNL: + if (!(nlflag & 1)) + break; + parseheredoc(); + return n1; + + case TEOF: + if (!n1 && (nlflag & 1)) + n1 = NEOF; + parseheredoc(); + return n1; + } + + checkkwd = CHKNL | CHKKWD | CHKALIAS; + if (nlflag == 2 && tokendlist[peektoken()]) + return n1; + nlflag |= 2; + n2 = andor(); tok = readtoken(); if (tok == TBACKGND) { @@ -189,29 +199,15 @@ list(int nlflag) n1 = n3; } switch (tok) { - case TBACKGND: - case TSEMI: - tok = readtoken(); - /* fall through */ case TNL: - if (tok == TNL) { - parseheredoc(); - if (nlflag == 1) - return n1; - } else { - tokpushback++; - } - checkkwd = CHKNL | CHKKWD | CHKALIAS; - if (tokendlist[peektoken()]) - return n1; - break; case TEOF: - if (heredoclist) - parseheredoc(); tokpushback++; - return n1; + /* fall through */ + case TBACKGND: + case TSEMI: + break; default: - if (nlflag == 1) + if ((nlflag & 1)) synexpect(-1); tokpushback++; return n1; @@ -1443,10 +1439,6 @@ parsearith: { #ifdef mkinit INCLUDE "parser.h" -RESET { - tokpushback = 0; - checkkwd = 0; -} #endif
Reasonably Related Threads
- [klibc:update-dash] [PARSER] Simplify EOF/newline handling in list parser
- [klibc:update-dash] dash: parser: Do not push token back before parseheredoc
- [klibc:update-dash] [SHELL] Optimize dash -c "command" to avoid a fork
- [klibc:update-dash] dash: [SHELL] Optimize dash -c "command" to avoid a fork
- [klibc:update-dash] [PARSER] Removed unnecessary pungetc on EOF from parser