summaryrefslogtreecommitdiffstats
path: root/bin/sh
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2013-08-30 20:37:52 +0000
committerjilles <jilles@FreeBSD.org>2013-08-30 20:37:52 +0000
commitfc9c61263d77ddbb901c15bec55522e26bdfda44 (patch)
tree097dddc02c9f5ecd6c7ee6bf4c96c5d0df64fb5c /bin/sh
parentae70647f7684c422d3f1a06515e582829df90929 (diff)
downloadFreeBSD-src-fc9c61263d77ddbb901c15bec55522e26bdfda44.zip
FreeBSD-src-fc9c61263d77ddbb901c15bec55522e26bdfda44.tar.gz
sh: Separate out nbinary allocation into a function.
Diffstat (limited to 'bin/sh')
-rw-r--r--bin/sh/parser.c43
1 files changed, 22 insertions, 21 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index db7db37..15e34c5 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -114,6 +114,7 @@ static union node *pipeline(void);
static union node *command(void);
static union node *simplecmd(union node **, union node *);
static union node *makename(void);
+static union node *makebinary(int type, union node *n1, union node *n2);
static void parsefname(void);
static void parseheredoc(void);
static int peektoken(void);
@@ -257,17 +258,11 @@ list(int nlflag, int erflag)
if (ntop == NULL)
ntop = n2;
else if (n1 == NULL) {
- n1 = (union node *)stalloc(sizeof (struct nbinary));
- n1->type = NSEMI;
- n1->nbinary.ch1 = ntop;
- n1->nbinary.ch2 = n2;
+ n1 = makebinary(NSEMI, ntop, n2);
ntop = n1;
}
else {
- n3 = (union node *)stalloc(sizeof (struct nbinary));
- n3->type = NSEMI;
- n3->nbinary.ch1 = n1->nbinary.ch2;
- n3->nbinary.ch2 = n2;
+ n3 = makebinary(NSEMI, n1->nbinary.ch2, n2);
n1->nbinary.ch2 = n3;
n1 = n3;
}
@@ -312,10 +307,10 @@ list(int nlflag, int erflag)
static union node *
andor(void)
{
- union node *n1, *n2, *n3;
+ union node *n;
int t;
- n1 = pipeline();
+ n = pipeline();
for (;;) {
if ((t = readtoken()) == TAND) {
t = NAND;
@@ -323,14 +318,9 @@ andor(void)
t = NOR;
} else {
tokpushback++;
- return n1;
+ return n;
}
- n2 = pipeline();
- n3 = (union node *)stalloc(sizeof (struct nbinary));
- n3->type = t;
- n3->nbinary.ch1 = n1;
- n3->nbinary.ch2 = n2;
- n1 = n3;
+ n = makebinary(t, n, pipeline());
}
}
@@ -437,12 +427,11 @@ command(void)
break;
case TWHILE:
case TUNTIL:
- n1 = (union node *)stalloc(sizeof (struct nbinary));
- n1->type = (lasttoken == TWHILE)? NWHILE : NUNTIL;
- if ((n1->nbinary.ch1 = list(0, 0)) == NULL)
+ t = lasttoken;
+ if ((n1 = list(0, 0)) == NULL)
synexpect(-1);
consumetoken(TDO);
- n1->nbinary.ch2 = list(0, 0);
+ n1 = makebinary((t == TWHILE)? NWHILE : NUNTIL, n1, list(0, 0));
consumetoken(TDONE);
checkkwd = CHKKWD | CHKALIAS;
break;
@@ -682,6 +671,18 @@ makename(void)
return n;
}
+static union node *
+makebinary(int type, union node *n1, union node *n2)
+{
+ union node *n;
+
+ n = (union node *)stalloc(sizeof (struct nbinary));
+ n->type = type;
+ n->nbinary.ch1 = n1;
+ n->nbinary.ch2 = n2;
+ return (n);
+}
+
void
fixredir(union node *n, const char *text, int err)
{
OpenPOWER on IntegriCloud