From patchwork Wed Nov 5 08:48:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 5232831 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-dash@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0C4C1C11AC for ; Wed, 5 Nov 2014 08:48:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1945F20165 for ; Wed, 5 Nov 2014 08:48:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4092220173 for ; Wed, 5 Nov 2014 08:48:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751188AbaKEIs2 (ORCPT ); Wed, 5 Nov 2014 03:48:28 -0500 Received: from helcar.apana.org.au ([209.40.204.226]:60805 "EHLO helcar.apana.org.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750860AbaKEIs2 (ORCPT ); Wed, 5 Nov 2014 03:48:28 -0500 Received: from gondolin.me.apana.org.au ([192.168.0.6]) by fornost.hengli.com.au with esmtp (Exim 4.80 #3 (Debian)) id 1XlwGP-0005Rx-RP for ; Wed, 05 Nov 2014 19:48:25 +1100 Received: from herbert by gondolin.me.apana.org.au with local (Exim 4.80) (envelope-from ) id 1XlwGP-0005Xd-4f; Wed, 05 Nov 2014 16:48:25 +0800 Subject: [PATCH 2/3] [PARSER] Simplify EOF/newline handling in list parser References: <20141105084749.GA21242@gondor.apana.org.au> To: dash@vger.kernel.org Message-Id: From: Herbert Xu Date: Wed, 05 Nov 2014 16:48:25 +0800 Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- ChangeLog | 1 src/parser.c | 60 +++++++++++++++++++++++++---------------------------------- 2 files changed, 27 insertions(+), 34 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/ChangeLog b/ChangeLog index 70ccfed..8e0d276 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2014-10-28 Herbert Xu * Removed unnecessary pungetc on EOF from parser. + * Simplify EOF/newline handling in list parser. 2014-10-27 Herbert Xu diff --git a/src/parser.c b/src/parser.c index f0c919d..382ddf2 100644 --- a/src/parser.c +++ b/src/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