From b3b9943da25aa0f86e2542c6846142aeeaa0cfe5 Mon Sep 17 00:00:00 2001 From: Toby Goodwin Date: Mon, 5 Mar 2018 06:51:31 +0000 Subject: implement walk half of if not, plus tests --- walk.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'walk.c') 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; -- cgit v1.2.3