diff options
author | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1996-03-08 22:01:04 +0000 |
---|---|---|
committer | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1996-03-08 22:01:04 +0000 |
commit | 47a83f71e826662fc09f41168287b5fd398e1a5a (patch) | |
tree | 34b3a74281dcb14688e33e8fb40ad88e82345dc7 /bin/sh/parser.c | |
parent | f002504e4c0ab3d830bf64c740d87aa36bee2fc6 (diff) |
From NetBSD:
- parser.c: Fix prompting in old style backquote expansion. Fixes PR/2139
and many user complaints why the shell hangs in echo "`"
- eval.c: Fix exitstatus invalid resetting in `if' statements were:
if (exit 3); then
echo foo $?
else
echo bar $?
fi
printed 'bar 0' instead of bar 3
Return zero status if `else' clause is empty.
Diffstat (limited to 'bin/sh/parser.c')
-rw-r--r-- | bin/sh/parser.c | 57 |
1 files changed, 48 insertions, 9 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c index d70b3ebb9c3..41eed597ee3 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -1,4 +1,5 @@ -/* $NetBSD: parser.c,v 1.27 1995/10/19 04:14:41 christos Exp $ */ +/* $OpenBSD: parser.c,v 1.3 1996/03/08 22:01:03 niklas Exp $ */ +/* $NetBSD: parser.c,v 1.28 1996/03/05 21:04:00 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -40,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95"; #else -static char rcsid[] = "$NetBSD: parser.c,v 1.27 1995/10/19 04:14:41 christos Exp $"; +static char rcsid[] = "$NetBSD: parser.c,v 1.28 1996/03/05 21:04:00 christos Exp $"; #endif #endif /* not lint */ @@ -1233,6 +1234,7 @@ parsebackq: { struct jmploc jmploc; struct jmploc *volatile savehandler; int savelen; + int saveprompt; savepbq = parsebackquote; if (setjmp(jmploc.loc)) { @@ -1260,17 +1262,42 @@ parsebackq: { register c; int savelen; char *str; + STARTSTACKSTR(out); - while ((c = pgetc ()) != '`') { - if (c == '\\') { - c = pgetc (); + for (;;) { + if (needprompt) { + setprompt(2); + needprompt = 0; + } + switch (c = pgetc()) { + case '`': + goto done; + + case '\\': + if ((c = pgetc()) == '\n') { + plinno++; + if (doprompt) + setprompt(2); + else + setprompt(0); + } if (c != '\\' && c != '`' && c != '$' && (!dblquote || c != '"')) STPUTC('\\', out); - } - STPUTC(c, out); + break; + + case '\n': + plinno++; + needprompt = doprompt; + break; + + default: + break; + } + STPUTC(c, out); } +done: STPUTC('\0', out); savelen = out - stackblock(); if (savelen > 0) { @@ -1285,9 +1312,21 @@ parsebackq: { *nlpp = (struct nodelist *)stalloc(sizeof (struct nodelist)); (*nlpp)->next = NULL; parsebackquote = oldstyle; + + if (oldstyle) { + saveprompt = doprompt; + doprompt = 0; + } + n = list(0); - if (!oldstyle && (readtoken() != TRP)) - synexpect(TRP); + + if (oldstyle) + doprompt = saveprompt; + else { + if (readtoken() != TRP) + synexpect(TRP); + } + (*nlpp)->n = n; if (oldstyle) { /* |