Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh Fix bin/9184, bin/9194, bin/9265, bin/9266



details:   https://anonhg.NetBSD.org/src/rev/3d879a2485d9
branches:  trunk
changeset: 481385:3d879a2485d9
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jan 27 23:39:38 2000 +0000

description:
Fix bin/9184, bin/9194, bin/9265, bin/9266
Exitcode and negation problems (From Martin Husemann)

diffstat:

 bin/sh/eval.c     |  43 +++++++++++++++++++++++++------------------
 bin/sh/eval.h     |   4 ++--
 bin/sh/histedit.c |   8 ++++----
 bin/sh/main.c     |   6 +++---
 bin/sh/parser.c   |  19 +++++++++++++++----
 bin/sh/trap.c     |   8 ++++----
 6 files changed, 53 insertions(+), 35 deletions(-)

diffs (truncated from 337 to 300 lines):

diff -r f1be5996da1e -r 3d879a2485d9 bin/sh/eval.c
--- a/bin/sh/eval.c     Thu Jan 27 22:27:50 2000 +0000
+++ b/bin/sh/eval.c     Thu Jan 27 23:39:38 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eval.c,v 1.49 1999/10/13 00:59:10 mrg Exp $    */
+/*     $NetBSD: eval.c,v 1.50 2000/01/27 23:39:38 christos Exp $       */
 
 /*-
  * Copyright (c) 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)eval.c     8.9 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: eval.c,v 1.49 1999/10/13 00:59:10 mrg Exp $");
+__RCSID("$NetBSD: eval.c,v 1.50 2000/01/27 23:39:38 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -93,8 +93,8 @@
 int oexitstatus;               /* saved exit status */
 
 
-STATIC void evalloop __P((union node *));
-STATIC void evalfor __P((union node *));
+STATIC void evalloop __P((union node *, int));
+STATIC void evalfor __P((union node *, int));
 STATIC void evalcase __P((union node *, int));
 STATIC void evalsubshell __P((union node *, int));
 STATIC void expredir __P((union node *));
@@ -151,7 +151,7 @@
                         STPUTC('\0', concat);
                         p = grabstackstr(concat);
                 }
-                evalstring(p);
+                evalstring(p, EV_TESTED);
         }
         return exitstatus;
 }
@@ -162,8 +162,9 @@
  */
 
 void
-evalstring(s)
+evalstring(s, flag)
        char *s;
+       int flag;
        {
        union node *n;
        struct stackmark smark;
@@ -171,7 +172,7 @@
        setstackmark(&smark);
        setinputstring(s, 1);
        while ((n = parsecmd(0)) != NEOF) {
-               evaltree(n, 0);
+               evaltree(n, flag);
                popstackmark(&smark);
        }
        popfile();
@@ -201,7 +202,7 @@
        TRACE(("evaltree(0x%lx: %d) called\n", (long)n, n->type));
        switch (n->type) {
        case NSEMI:
-               evaltree(n->nbinary.ch1, 0);
+               evaltree(n->nbinary.ch1, flags & EV_TESTED);
                if (evalskip)
                        goto out;
                evaltree(n->nbinary.ch2, flags);
@@ -213,13 +214,13 @@
                        flags |= EV_TESTED;
                        goto out;
                }
-               evaltree(n->nbinary.ch2, flags);
+               evaltree(n->nbinary.ch2, flags | EV_TESTED);
                break;
        case NOR:
                evaltree(n->nbinary.ch1, EV_TESTED);
                if (evalskip || exitstatus == 0)
                        goto out;
-               evaltree(n->nbinary.ch2, flags);
+               evaltree(n->nbinary.ch2, flags | EV_TESTED);
                break;
        case NREDIR:
                expredir(n->nredir.redirect);
@@ -247,10 +248,10 @@
        }
        case NWHILE:
        case NUNTIL:
-               evalloop(n);
+               evalloop(n, flags);
                break;
        case NFOR:
-               evalfor(n);
+               evalfor(n, flags);
                break;
        case NCASE:
                evalcase(n, flags);
@@ -278,14 +279,15 @@
 out:
        if (pendingsigs)
                dotrap();
-       if ((flags & EV_EXIT) || (eflag && exitstatus && !(flags & EV_TESTED)))
+       if (flags & EV_EXIT)
                exitshell(exitstatus);
 }
 
 
 STATIC void
-evalloop(n)
+evalloop(n, flags)
        union node *n;
+       int flags;
 {
        int status;
 
@@ -309,7 +311,7 @@
                        if (exitstatus == 0)
                                break;
                }
-               evaltree(n->nbinary.ch2, 0);
+               evaltree(n->nbinary.ch2, flags & EV_TESTED);
                status = exitstatus;
                if (evalskip)
                        goto skipping;
@@ -321,8 +323,9 @@
 
 
 STATIC void
-evalfor(n)
+evalfor(n, flags)
     union node *n;
+    int flags;
 {
        struct arglist arglist;
        union node *argp;
@@ -343,7 +346,7 @@
        loopnest++;
        for (sp = arglist.list ; sp ; sp = sp->next) {
                setvar(n->nfor.var, sp->text, 0);
-               evaltree(n->nfor.body, 0);
+               evaltree(n->nfor.body, flags & EV_TESTED);
                if (evalskip) {
                        if (evalskip == SKIPCONT && --skipcount <= 0) {
                                evalskip = 0;
@@ -571,6 +574,7 @@
                                copyfd(pip[1], 1);
                                close(pip[1]);
                        }
+                       eflag = 0;
                        evaltree(n, EV_EXIT);
                }
                close(pip[1]);
@@ -781,7 +785,7 @@
                for (sp = varlist.list ; sp ; sp = sp->next)
                        mklocal(sp->text);
                funcnest++;
-               evaltree(cmdentry.u.func, 0);
+               evaltree(cmdentry.u.func, flags & EV_TESTED);
                funcnest--;
                INTOFF;
                poplocalvars();
@@ -882,6 +886,9 @@
        if (lastarg)
                setvar("_", lastarg, 0);
        popstackmark(&smark);
+
+       if (eflag && exitstatus && !(flags & EV_TESTED))
+           exitshell(exitstatus);
 }
 
 
diff -r f1be5996da1e -r 3d879a2485d9 bin/sh/eval.h
--- a/bin/sh/eval.h     Thu Jan 27 22:27:50 2000 +0000
+++ b/bin/sh/eval.h     Thu Jan 27 23:39:38 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eval.h,v 1.9 1995/09/11 17:05:43 christos Exp $        */
+/*     $NetBSD: eval.h,v 1.10 2000/01/27 23:39:40 christos Exp $       */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -51,7 +51,7 @@
 };
 
 int evalcmd __P((int, char **));
-void evalstring __P((char *));
+void evalstring __P((char *, int));
 union node;    /* BLETCH for ansi C */
 void evaltree __P((union node *, int));
 void evalbackcmd __P((union node *, struct backcmd *));
diff -r f1be5996da1e -r 3d879a2485d9 bin/sh/histedit.c
--- a/bin/sh/histedit.c Thu Jan 27 22:27:50 2000 +0000
+++ b/bin/sh/histedit.c Thu Jan 27 23:39:38 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: histedit.c,v 1.21 1999/07/09 03:05:50 christos Exp $   */
+/*     $NetBSD: histedit.c,v 1.22 2000/01/27 23:39:40 christos Exp $   */
 
 /*-
  * Copyright (c) 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)histedit.c 8.2 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: histedit.c,v 1.21 1999/07/09 03:05:50 christos Exp $");
+__RCSID("$NetBSD: histedit.c,v 1.22 2000/01/27 23:39:40 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -375,7 +375,7 @@
                                        out2str(s);
                                }
 
-                               evalstring(strcpy(stalloc(strlen(s) + 1), s));
+                               evalstring(strcpy(stalloc(strlen(s) + 1), s), 0);
                                free(sp);
                                if (displayhist && hist) {
                                        /*
@@ -400,7 +400,7 @@
                fclose(efp);
                editcmd = stalloc(strlen(editor) + strlen(editfile) + 2);
                sprintf(editcmd, "%s %s", editor, editfile);
-               evalstring(editcmd);    /* XXX - should use no JC command */
+               evalstring(editcmd, 0); /* XXX - should use no JC command */
                INTON;
                readcmdfile(editfile);  /* XXX - should read back - quick tst */
                unlink(editfile);
diff -r f1be5996da1e -r 3d879a2485d9 bin/sh/main.c
--- a/bin/sh/main.c     Thu Jan 27 22:27:50 2000 +0000
+++ b/bin/sh/main.c     Thu Jan 27 23:39:38 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.34 1999/07/09 03:05:50 christos Exp $       */
+/*     $NetBSD: main.c,v 1.35 2000/01/27 23:39:40 christos Exp $       */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -46,7 +46,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.7 (Berkeley) 7/19/95";
 #else
-__RCSID("$NetBSD: main.c,v 1.34 1999/07/09 03:05:50 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.35 2000/01/27 23:39:40 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -209,7 +209,7 @@
        }
 
        if (minusc)
-               evalstring(minusc);
+               evalstring(minusc, 0);
 
        if (sflag || minusc == NULL) {
 state4:        /* XXX ??? - why isn't this before the "if" statement */
diff -r f1be5996da1e -r 3d879a2485d9 bin/sh/parser.c
--- a/bin/sh/parser.c   Thu Jan 27 22:27:50 2000 +0000
+++ b/bin/sh/parser.c   Thu Jan 27 23:39:38 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parser.c,v 1.43 1999/07/09 03:05:50 christos Exp $     */
+/*     $NetBSD: parser.c,v 1.44 2000/01/27 23:39:40 christos Exp $     */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)parser.c   8.7 (Berkeley) 5/16/95";
 #else
-__RCSID("$NetBSD: parser.c,v 1.43 1999/07/09 03:05:50 christos Exp $");
+__RCSID("$NetBSD: parser.c,v 1.44 2000/01/27 23:39:40 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -245,10 +245,15 @@
 
 STATIC union node *
 pipeline() {
-       union node *n1, *pipenode;
+       union node *n1, *n2, *pipenode;
        struct nodelist *lp, *prev;
+       int negate;
 
+       negate = 0;
        TRACE(("pipeline: entered\n"));
+       while (readtoken() == TNOT)
+               negate = !negate;
+       tokpushback++;
        n1 = command();
        if (readtoken() == TPIPE) {
                pipenode = (union node *)stalloc(sizeof (struct npipe));
@@ -267,7 +272,13 @@
                n1 = pipenode;
        }
        tokpushback++;
-       return n1;
+       if (negate) {
+               n2 = (union node *)stalloc(sizeof (struct nnot));
+               n2->type = NNOT;
+               n2->nnot.com = n1;
+               return n2;
+       } else
+               return n1;
 }
 



Home | Main Index | Thread Index | Old Index