Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh If we are going to permit
details: https://anonhg.NetBSD.org/src/rev/51f19b6e9f2a
branches: trunk
changeset: 353487:51f19b6e9f2a
user: kre <kre%NetBSD.org@localhost>
date: Tue May 09 05:14:03 2017 +0000
description:
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.
diffstat:
bin/sh/eval.c | 9 +++++++--
bin/sh/jobs.c | 7 +++++--
bin/sh/nodetypes | 3 ++-
bin/sh/parser.c | 22 +++++++++++-----------
bin/sh/show.c | 10 ++++++++--
5 files changed, 33 insertions(+), 18 deletions(-)
diffs (190 lines):
diff -r c937e899f180 -r 51f19b6e9f2a bin/sh/eval.c
--- a/bin/sh/eval.c Tue May 09 04:25:28 2017 +0000
+++ b/bin/sh/eval.c Tue May 09 05:14:03 2017 +0000
@@ -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(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);
diff -r c937e899f180 -r 51f19b6e9f2a bin/sh/jobs.c
--- a/bin/sh/jobs.c Tue May 09 04:25:28 2017 +0000
+++ b/bin/sh/jobs.c Tue May 09 05:14:03 2017 +0000
@@ -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 @@
cmdputs(" || ");
cmdtxt(n->nbinary.ch2);
break;
+ case NDNOT:
+ cmdputs("! ");
+ /* FALLTHROUGH */
case NNOT:
cmdputs("! ");
cmdtxt(n->nnot.com);
diff -r c937e899f180 -r 51f19b6e9f2a bin/sh/nodetypes
--- a/bin/sh/nodetypes Tue May 09 04:25:28 2017 +0000
+++ b/bin/sh/nodetypes Tue May 09 05:14:03 2017 +0000
@@ -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 @@
doc nodeptr # input to command (NARG node)
NNOT nnot # ! command (actually pipeline)
+NDNOT nnot # ! ! pipeline (optimisation)
type int
com nodeptr
diff -r c937e899f180 -r 51f19b6e9f2a bin/sh/parser.c
--- a/bin/sh/parser.c Tue May 09 04:25:28 2017 +0000
+++ b/bin/sh/parser.c Tue May 09 05:14:03 2017 +0000
@@ -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 @@
checkkwd = 2;
while (readtoken() == TNOT) {
TRACE(("pipeline: TNOT recognized\n"));
- negate = !negate;
+ negate++;
}
tokpushback++;
n1 = command();
@@ -284,9 +284,9 @@
}
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 @@
while (readtoken() == TNOT) {
TRACE(("command: TNOT recognized\n"));
- negate = !negate;
+ negate++;
}
tokpushback++;
@@ -565,9 +565,9 @@
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 @@
while (readtoken() == TNOT) {
TRACE(("simplcmd: TNOT recognized\n"));
- negate = !negate;
+ negate++;
}
tokpushback++;
@@ -640,9 +640,9 @@
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;
}
diff -r c937e899f180 -r 51f19b6e9f2a bin/sh/show.c
--- a/bin/sh/show.c Tue May 09 04:25:28 2017 +0000
+++ b/bin/sh/show.c Tue May 09 05:14:03 2017 +0000
@@ -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 @@
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);
Home |
Main Index |
Thread Index |
Old Index