summary refs log tree commit diff
path: root/src/var.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2018-05-19 02:39:55 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2018-05-28 17:12:23 +0800
commit811a36120aef848cd308d56e06bf62e721be853c (patch)
treef841172b0a488bc4c0ea7382c3837b48e2167398 /src/var.c
parenteval: Fail immediately with redirections errors for simple command (diff)
downloaddash-811a36120aef848cd308d56e06bf62e721be853c.tar.gz
dash-811a36120aef848cd308d56e06bf62e721be853c.zip
eval: Replace with listsetvar with mklocal/setvareq
This patch replaces listsetvar with mklocal/setvareq.  As we now
determine special built-in status prior to variable assignment, we
no longer have to do a second pass listsetvar.  Instead we will
call setvareq directly instead of mklocal when necessary.

In order to do this mklocal can now take a flag in order to mark
a variable for export.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to '')
-rw-r--r--src/var.c32
1 files changed, 5 insertions, 27 deletions
diff --git a/src/var.c b/src/var.c
index 604ab1f..40743e5 100644
--- a/src/var.c
+++ b/src/var.c
@@ -302,28 +302,6 @@ out:
 	return vp;
 }
 
-
-
-/*
- * Process a linked list of variable assignments.
- */
-
-void
-listsetvar(struct strlist *list, int flags)
-{
-	struct strlist *lp;
-
-	lp = list;
-	if (!lp)
-		return;
-	INTOFF;
-	do {
-		setvareq(lp->text, flags);
-	} while ((lp = lp->next));
-	INTON;
-}
-
-
 /*
  * Find the value of a variable.  Returns NULL if not set.
  */
@@ -468,7 +446,7 @@ localcmd(int argc, char **argv)
 
 	argv = argptr;
 	while ((name = *argv++) != NULL) {
-		mklocal(name);
+		mklocal(name, 0);
 	}
 	return 0;
 }
@@ -481,7 +459,7 @@ localcmd(int argc, char **argv)
  * "-" as a special case.
  */
 
-void mklocal(char *name)
+void mklocal(char *name, int flags)
 {
 	struct localvar *lvp;
 	struct var **vpp;
@@ -502,16 +480,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;