diff --git a/bin/sh/parser.c b/bin/sh/parser.c index 87fc31ab4cfe..5538c03f3fb8 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -1,4 +1,4 @@ -/* $NetBSD: parser.c,v 1.30 1996/10/16 14:53:23 christos Exp $ */ +/* $NetBSD: parser.c,v 1.31 1996/11/25 20:22:00 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95"; #else -static char rcsid[] = "$NetBSD: parser.c,v 1.30 1996/10/16 14:53:23 christos Exp $"; +static char rcsid[] = "$NetBSD: parser.c,v 1.31 1996/11/25 20:22:00 christos Exp $"; #endif #endif /* not lint */ @@ -251,16 +251,10 @@ andor() { STATIC union node * pipeline() { - union node *n1, *pipenode, *notnode; + union node *n1, *pipenode; struct nodelist *lp, *prev; - int negate = 0; TRACE(("pipeline: entered\n")); - while (readtoken() == TNOT) { - TRACE(("pipeline: TNOT recognized\n")); - negate = !negate; - } - tokpushback++; n1 = command(); if (readtoken() == TPIPE) { pipenode = (union node *)stalloc(sizeof (struct npipe)); @@ -279,12 +273,6 @@ pipeline() { n1 = pipenode; } tokpushback++; - if (negate) { - notnode = (union node *)stalloc(sizeof (struct nnot)); - notnode->type = NNOT; - notnode->nnot.com = n1; - n1 = notnode; - } return n1; } @@ -296,12 +284,13 @@ command() { union node *ap, **app; union node *cp, **cpp; union node *redir, **rpp; - int t; + int t, negate = 0; checkkwd = 2; redir = NULL; n1 = NULL; rpp = &redir; + /* Check for redirection which may precede command */ while (readtoken() == TREDIR) { *rpp = n2 = redirnode; @@ -310,6 +299,12 @@ command() { } tokpushback++; + while (readtoken() == TNOT) { + TRACE(("command: TNOT recognized\n")); + negate = !negate; + } + tokpushback++; + switch (readtoken()) { case TIF: n1 = (union node *)stalloc(sizeof (struct nif)); @@ -480,7 +475,8 @@ TRACE(("expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : "")); case TWORD: case TRP: tokpushback++; - return simplecmd(rpp, redir); + n1 = simplecmd(rpp, redir); + goto checkneg; default: synexpect(-1); } @@ -502,7 +498,16 @@ TRACE(("expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : "")); } n1->nredir.redirect = redir; } - return n1; + +checkneg: + if (negate) { + n2 = (union node *)stalloc(sizeof (struct nnot)); + n2->type = NNOT; + n2->nnot.com = n1; + return n2; + } + else + return n1; } @@ -512,7 +517,8 @@ simplecmd(rpp, redir) { union node *args, **app; union node **orig_rpp = rpp; - union node *n = NULL; + union node *n = NULL, *n2; + int negate = 0; /* If we don't have any redirections already, then we must reset */ /* rpp to be the address of the local redir variable. */ @@ -528,6 +534,12 @@ simplecmd(rpp, redir) */ orig_rpp = rpp; + while (readtoken() == TNOT) { + TRACE(("command: TNOT recognized\n")); + negate = !negate; + } + tokpushback++; + for (;;) { if (readtoken() == TWORD) { n = (union node *)stalloc(sizeof (struct narg)); @@ -551,7 +563,7 @@ simplecmd(rpp, redir) #endif n->type = NDEFUN; n->narg.next = command(); - return n; + goto checkneg; } else { tokpushback++; break; @@ -564,7 +576,16 @@ simplecmd(rpp, redir) n->ncmd.backgnd = 0; n->ncmd.args = args; n->ncmd.redirect = redir; - return n; + +checkneg: + if (negate) { + n2 = (union node *)stalloc(sizeof (struct nnot)); + n2->type = NNOT; + n2->nnot.com = n; + return n2; + } + else + return n; } STATIC union node * @@ -723,7 +744,7 @@ readtoken() { } } out: - checkkwd = 0; + checkkwd = (t == TNOT) ? savecheckkwd : 0; } #ifdef DEBUG if (!alreadyseen)