Module Name:    src
Committed By:   kre
Date:           Tue May  9 05:14:03 UTC 2017

Modified Files:
        src/bin/sh: eval.c jobs.c nodetypes parser.c show.c

Log Message:
If we are going to permit
        ! ! pipeline
(And for now the other places where ! is permitted)
we should at least generate the logically correct exit
status:
        ! ! (exit 5); echo $?
should print 1, not 5.   ksh and bosh do it this way - and it makes sense.
bash and the FreeBSD sh echo "5" (as did we until now.)
dash, zsh, yash all enforce the standard syntax, and prohibit this.


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/bin/sh/eval.c
cvs rdiff -u -r1.82 -r1.83 src/bin/sh/jobs.c
cvs rdiff -u -r1.14 -r1.15 src/bin/sh/nodetypes
cvs rdiff -u -r1.124 -r1.125 src/bin/sh/parser.c
cvs rdiff -u -r1.37 -r1.38 src/bin/sh/show.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/eval.c
diff -u src/bin/sh/eval.c:1.138 src/bin/sh/eval.c:1.139
--- src/bin/sh/eval.c:1.138	Tue May  9 04:08:37 2017
+++ src/bin/sh/eval.c	Tue May  9 05:14:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: eval.c,v 1.138 2017/05/09 04:08:37 kre Exp $	*/
+/*	$NetBSD: eval.c,v 1.139 2017/05/09 05:14:03 kre Exp $	*/
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)eval.c	8.9 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: eval.c,v 1.138 2017/05/09 04:08:37 kre Exp $");
+__RCSID("$NetBSD: eval.c,v 1.139 2017/05/09 05:14:03 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -321,6 +321,11 @@ evaltree(union node *n, int flags)
 		evaltree(n->nnot.com, (sflags & EV_MORE) | EV_TESTED);
 		exitstatus = !exitstatus;
 		break;
+	case NDNOT:
+		evaltree(n->nnot.com, (sflags & EV_MORE) | EV_TESTED);
+		if (exitstatus != 0)
+			exitstatus = 1;
+		break;
 	case NPIPE:
 		evalpipe(n);
 		do_etest = !(flags & EV_TESTED);

Index: src/bin/sh/jobs.c
diff -u src/bin/sh/jobs.c:1.82 src/bin/sh/jobs.c:1.83
--- src/bin/sh/jobs.c:1.82	Thu May  4 04:37:51 2017
+++ src/bin/sh/jobs.c	Tue May  9 05:14:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: jobs.c,v 1.82 2017/05/04 04:37:51 kre Exp $	*/
+/*	$NetBSD: jobs.c,v 1.83 2017/05/09 05:14:03 kre Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)jobs.c	8.5 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: jobs.c,v 1.82 2017/05/04 04:37:51 kre Exp $");
+__RCSID("$NetBSD: jobs.c,v 1.83 2017/05/09 05:14:03 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -1275,6 +1275,9 @@ cmdtxt(union node *n)
 		cmdputs(" || ");
 		cmdtxt(n->nbinary.ch2);
 		break;
+	case NDNOT:
+		cmdputs("! ");
+		/* FALLTHROUGH */
 	case NNOT:
 		cmdputs("! ");
 		cmdtxt(n->nnot.com);

Index: src/bin/sh/nodetypes
diff -u src/bin/sh/nodetypes:1.14 src/bin/sh/nodetypes:1.15
--- src/bin/sh/nodetypes:1.14	Thu May  4 04:37:51 2017
+++ src/bin/sh/nodetypes	Tue May  9 05:14:03 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: nodetypes,v 1.14 2017/05/04 04:37:51 kre Exp $
+#	$NetBSD: nodetypes,v 1.15 2017/05/09 05:14:03 kre Exp $
 # Copyright (c) 1991, 1993
 #	The Regents of the University of California.  All rights reserved.
 #
@@ -140,5 +140,6 @@ NXHERE nhere			# fd<<!
 	doc	  nodeptr		# input to command (NARG node)
 
 NNOT nnot			# ! command  (actually pipeline)
+NDNOT nnot			# ! ! pipeline (optimisation)
 	type	  int
 	com	  nodeptr

Index: src/bin/sh/parser.c
diff -u src/bin/sh/parser.c:1.124 src/bin/sh/parser.c:1.125
--- src/bin/sh/parser.c:1.124	Tue May  9 02:47:47 2017
+++ src/bin/sh/parser.c	Tue May  9 05:14:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: parser.c,v 1.124 2017/05/09 02:47:47 kre Exp $	*/
+/*	$NetBSD: parser.c,v 1.125 2017/05/09 05:14:03 kre Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)parser.c	8.7 (Berkeley) 5/16/95";
 #else
-__RCSID("$NetBSD: parser.c,v 1.124 2017/05/09 02:47:47 kre Exp $");
+__RCSID("$NetBSD: parser.c,v 1.125 2017/05/09 05:14:03 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -262,7 +262,7 @@ pipeline(void)
 	checkkwd = 2;
 	while (readtoken() == TNOT) {
 		TRACE(("pipeline: TNOT recognized\n"));
-		negate = !negate;
+		negate++;
 	}
 	tokpushback++;
 	n1 = command();
@@ -284,9 +284,9 @@ pipeline(void)
 	}
 	tokpushback++;
 	if (negate) {
-		TRACE(("negate pipeline\n"));
+		TRACE(("%snegate pipeline\n", (negate&1) ? "" : "double "));
 		n2 = stalloc(sizeof(struct nnot));
-		n2->type = NNOT;
+		n2->type = (negate & 1) ? NNOT : NDNOT;
 		n2->nnot.com = n1;
 		return n2;
 	} else
@@ -321,7 +321,7 @@ command(void)
 
 	while (readtoken() == TNOT) {
 		TRACE(("command: TNOT recognized\n"));
-		negate = !negate;
+		negate++;
 	}
 	tokpushback++;
 
@@ -565,9 +565,9 @@ TRACE(("expecting DO got %s %s\n", tokna
 
 checkneg:
 	if (negate) {
-		TRACE(("negate command\n"));
+		TRACE(("%snegate command\n", (negate&1) ? "" : "double "));
 		n2 = stalloc(sizeof(struct nnot));
-		n2->type = NNOT;
+		n2->type = (negate & 1) ? NNOT : NDNOT;
 		n2->nnot.com = n1;
 		return n2;
 	}
@@ -593,7 +593,7 @@ simplecmd(union node **rpp, union node *
 
 	while (readtoken() == TNOT) {
 		TRACE(("simplcmd: TNOT recognized\n"));
-		negate = !negate;
+		negate++;
 	}
 	tokpushback++;
 
@@ -640,9 +640,9 @@ simplecmd(union node **rpp, union node *
 
 checkneg:
 	if (negate) {
-		TRACE(("negate simplecmd\n"));
+		TRACE(("%snegate simplecmd\n", (negate&1) ? "" : "double "));
 		n2 = stalloc(sizeof(struct nnot));
-		n2->type = NNOT;
+		n2->type = (negate & 1) ? NNOT : NDNOT;
 		n2->nnot.com = n;
 		return n2;
 	}

Index: src/bin/sh/show.c
diff -u src/bin/sh/show.c:1.37 src/bin/sh/show.c:1.38
--- src/bin/sh/show.c:1.37	Wed May  3 21:34:51 2017
+++ src/bin/sh/show.c	Tue May  9 05:14:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: show.c,v 1.37 2017/05/03 21:34:51 kre Exp $	*/
+/*	$NetBSD: show.c,v 1.38 2017/05/09 05:14:03 kre Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)show.c	8.3 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: show.c,v 1.37 2017/05/03 21:34:51 kre Exp $");
+__RCSID("$NetBSD: show.c,v 1.38 2017/05/09 05:14:03 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -127,10 +127,16 @@ binop:
 		if (nl && len > 0)
 			len = 0, putc('\n', fp);
 		break;
+
+	case NDNOT:
+		fputs("! ", fp);
+		len += 2;
+		/* FALLTHROUGH */
 	case NNOT:
 		fputs("! ", fp);
 		len += 2 + shtree(n->nnot.com, 0, 0, NULL, fp);
 		break;
+
 	case NPIPE:
 		for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
 			len += shtree(lp->n, 0, 0, NULL, fp);

Reply via email to