From patchwork Wed May 9 08:56:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 10388775 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 915C260170 for ; Wed, 9 May 2018 08:57:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81048288CD for ; Wed, 9 May 2018 08:57:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7599E28E3F; Wed, 9 May 2018 08:57:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 395F4288CD for ; Wed, 9 May 2018 08:57:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934141AbeEII4V (ORCPT ); Wed, 9 May 2018 04:56:21 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:43640 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934157AbeEII4O (ORCPT ); Wed, 9 May 2018 04:56:14 -0400 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1fGKtR-0006Fw-8J; Wed, 09 May 2018 16:56:13 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1fGKtQ-0002eF-M7; Wed, 09 May 2018 16:56:12 +0800 Date: Wed, 9 May 2018 16:56:12 +0800 From: Herbert Xu To: DASH Mailing List Subject: eval: Replace external use of mklocal with listsetvar Message-ID: <20180509085612.dr72efjltbjxcjfr@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for listsetvar to be used for setting local variables in bulk through the VLOCAL flag. It also removes the use of mklocal in evalcommand, and replaces it with listsetvar. Signed-off-by: Herbert Xu diff --git a/src/eval.c b/src/eval.c index 39c4e41..23be7ba 100644 --- a/src/eval.c +++ b/src/eval.c @@ -714,6 +714,7 @@ evalcommand(union node *cmd, int flags) int execcmd; int status; char **nargv; + int vflags; errlinno = lineno = cmd->ncmd.linno; if (funcline) @@ -769,8 +770,6 @@ evalcommand(union node *cmd, int flags) spp = varlist.lastp; expandarg(argp, &varlist, EXP_VARTILDE); - mklocal((*spp)->text); - /* * Modify the command lookup path, if a PATH= assignment * is present @@ -852,6 +851,13 @@ bail: jp = NULL; + if (cmdentry.cmdtype == CMDBUILTIN && (spclbltin > 0 || argc == 0)) + vflags = execcmd && argc > 1 ? VEXPORT : 0; + else + vflags = VLOCAL | (cmdentry.cmdtype == CMDNORMAL ? + VEXPORT | VNOFUNC : 0); + listsetvar(varlist.list, vflags); + /* Execute the command. */ switch (cmdentry.cmdtype) { default: @@ -863,16 +869,10 @@ bail: break; FORCEINTON; } - listsetvar(varlist.list, VEXPORT|VSTACK); shellexec(argv, path, cmdentry.u.index); /* NOTREACHED */ case CMDBUILTIN: - if (spclbltin > 0 || argc == 0) { - poplocalvars(1); - if (execcmd && argc > 1) - listsetvar(varlist.list, VEXPORT); - } if (evalbltin(cmdentry.u.cmd, argc, argv, flags) && !(exception == EXERROR && spclbltin <= 0)) { raise: diff --git a/src/var.c b/src/var.c index cc6f7f2..c877f68 100644 --- a/src/var.c +++ b/src/var.c @@ -116,6 +116,7 @@ STATIC struct var *vartab[VTABSIZE]; STATIC struct var **hashvar(const char *); STATIC int vpcmp(const void *, const void *); STATIC struct var **findvar(struct var **, const char *); +static void mklocal(char *name, int flags); /* * Initialize the varable symbol tables and import the environment @@ -325,7 +326,10 @@ listsetvar(struct strlist *list, int flags) return; INTOFF; do { - setvareq(lp->text, flags); + if (flags & VLOCAL) + mklocal(lp->text, flags & ~VLOCAL); + else + setvareq(lp->text, flags); } while ((lp = lp->next)); INTON; } @@ -475,7 +479,7 @@ localcmd(int argc, char **argv) argv = argptr; while ((name = *argv++) != NULL) { - mklocal(name); + mklocal(name, 0); } return 0; } @@ -488,7 +492,7 @@ localcmd(int argc, char **argv) * "-" as a special case. */ -void mklocal(char *name) +static void mklocal(char *name, int flags) { struct localvar *lvp; struct var **vpp; @@ -509,16 +513,16 @@ void mklocal(char *name) eq = strchr(name, '='); if (vp == NULL) { if (eq) - vp = setvareq(name, VSTRFIXED); + vp = setvareq(name, VSTRFIXED | flags); else - vp = setvar(name, NULL, VSTRFIXED); + vp = setvar(name, NULL, VSTRFIXED | flags); lvp->flags = VUNSET; } else { lvp->text = vp->text; lvp->flags = vp->flags; vp->flags |= VSTRFIXED|VTEXTFIXED; if (eq) - setvareq(name, 0); + setvareq(name, flags); } } lvp->vp = vp; diff --git a/src/var.h b/src/var.h index 872e2db..60eac4b 100644 --- a/src/var.h +++ b/src/var.h @@ -50,6 +50,7 @@ #define VNOFUNC 0x40 /* don't call the callback function */ #define VNOSET 0x80 /* do not set variable - just readonly test */ #define VNOSAVE 0x100 /* when text is on the heap before setvareq */ +#define VLOCAL 0x200 /* Tell listsetvar to call mklocal */ struct var { @@ -151,7 +152,6 @@ char **listvars(int, int, char ***); int showvars(const char *, int, int); int exportcmd(int, char **); int localcmd(int, char **); -void mklocal(char *); struct localvar_list *pushlocalvars(void); void poplocalvars(int); void unwindlocalvars(struct localvar_list *stop);