summaryrefslogtreecommitdiff
path: root/walk.c
diff options
context:
space:
mode:
authorToby Goodwin <toby@paccrat.org>2018-03-05 06:51:31 +0000
committerToby Goodwin <toby@paccrat.org>2018-03-05 06:51:31 +0000
commitb3b9943da25aa0f86e2542c6846142aeeaa0cfe5 (patch)
treec7ff0edf52a46b34de69df7a36e8f4b3391e871e /walk.c
parent7d179ce096c89963deae835327596de435e66cdf (diff)
implement walk half of if not, plus tests
Diffstat (limited to 'walk.c')
-rw-r--r--walk.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/walk.c b/walk.c
index cb734fe..b9218ca 100644
--- a/walk.c
+++ b/walk.c
@@ -18,6 +18,7 @@ static bool isallpre(Node *);
static bool dofork(bool);
static void dopipe(Node *);
static void loop_body(Node* n);
+static int if_state = 2; /* last if, for "if not" interactive top-level */
/* Tail-recursive version of walk() */
@@ -33,6 +34,7 @@ top: sigchk();
set(TRUE);
return TRUE;
}
+ if (parent && n->type != nIfnot) if_state = 2;
switch (n->type) {
case nArgs: case nBackq: case nConcat: case nCount:
case nFlat: case nLappend: case nRedir: case nVar:
@@ -96,10 +98,17 @@ top: sigchk();
true_cmd = true_cmd->u[0].p;
}
cond = TRUE;
- if (!walk(n->u[0].p, TRUE))
- true_cmd = false_cmd; /* run the else clause */
+ if_state = walk(n->u[0].p, TRUE);
cond = oldcond;
- WALK(true_cmd, parent);
+ WALK(if_state ? true_cmd : false_cmd, parent);
+ }
+ case nIfnot: {
+ if (if_state == 2)
+ rc_error("`if not' must follow `if'");
+ if (if_state == 0)
+ walk(n->u[0].p, TRUE);
+ if_state = 2;
+ break;
}
case nWhile: {
Jbwrap break_jb;