- 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
This commit is contained in:
christos 1996-03-05 21:03:52 +00:00
parent 41c2cff5ab
commit b09ffc42b1
2 changed files with 50 additions and 16 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: eval.c,v 1.27 1995/09/11 17:05:41 christos Exp $ */
/* $NetBSD: eval.c,v 1.28 1996/03/05 21:03:52 christos Exp $ */
/*-
* Copyright (c) 1993
@ -40,7 +40,7 @@
#if 0
static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95";
#else
static char sccsid[] = "$NetBSD: eval.c,v 1.27 1995/09/11 17:05:41 christos Exp $";
static char sccsid[] = "$NetBSD: eval.c,v 1.28 1996/03/05 21:03:52 christos Exp $";
#endif
#endif /* not lint */
@ -230,14 +230,10 @@ evaltree(n, flags)
evalsubshell(n, flags);
break;
case NIF: {
int status;
evaltree(n->nif.test, EV_TESTED);
status = exitstatus;
exitstatus = 0;
if (evalskip)
goto out;
if (status == 0)
if (exitstatus == 0)
evaltree(n->nif.ifpart, flags);
else if (n->nif.elsepart)
evaltree(n->nif.elsepart, flags);

View File

@ -1,4 +1,4 @@
/* $NetBSD: parser.c,v 1.27 1995/10/19 04:14:41 christos Exp $ */
/* $NetBSD: parser.c,v 1.28 1996/03/05 21:04: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.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 +1233,7 @@ parsebackq: {
struct jmploc jmploc;
struct jmploc *volatile savehandler;
int savelen;
int saveprompt;
savepbq = parsebackquote;
if (setjmp(jmploc.loc)) {
@ -1260,17 +1261,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 +1311,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) {
/*