From NetBSD:
authorniklas <niklas@openbsd.org>
Fri, 8 Mar 1996 22:00:58 +0000 (22:00 +0000)
committerniklas <niklas@openbsd.org>
Fri, 8 Mar 1996 22:00:58 +0000 (22:00 +0000)
- 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.

bin/sh/eval.c
bin/sh/parser.c

index a6aafd3..eea8003 100644 (file)
@@ -1,4 +1,5 @@
-/*     $NetBSD: eval.c,v 1.27 1995/09/11 17:05:41 christos Exp $       */
+/*     $OpenBSD: eval.c,v 1.2 1996/03/08 22:00:58 niklas Exp $ */
+/*     $NetBSD: eval.c,v 1.29 1996/03/06 14:49:29 pk Exp $     */
 
 /*-
  * Copyright (c) 1993
@@ -40,7 +41,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.29 1996/03/06 14:49:29 pk Exp $";
 #endif
 #endif /* not lint */
 
@@ -230,17 +231,15 @@ 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);
+               else
+                       exitstatus = 0;
                break;
        }
        case NWHILE:
index d70b3eb..41eed59 100644 (file)
@@ -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) {
                /*