about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2002-02-25 09:21:14 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2002-02-25 09:21:14 +0000
commit4e354ca36f5c1259b9f561bea52828f457e8e8ba (patch)
treef9a28a57afdc02de1b3591cc99bbadd86d3fb36b /Src
parent9b8176a659443094762f242c854c4af7afd3d0ec (diff)
downloadzsh-4e354ca36f5c1259b9f561bea52828f457e8e8ba.tar.gz
zsh-4e354ca36f5c1259b9f561bea52828f457e8e8ba.tar.xz
zsh-4e354ca36f5c1259b9f561bea52828f457e8e8ba.zip
allow nterruption of empty while-loops with ^C (16711)
Diffstat (limited to 'Src')
-rw-r--r--Src/loop.c78
1 files changed, 47 insertions, 31 deletions
diff --git a/Src/loop.c b/Src/loop.c
index 89ef59689..4da5a50f0 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -380,37 +380,53 @@ execwhile(Estate state, int do_exec)
     cmdpush(isuntil ? CS_UNTIL : CS_WHILE);
     loops++;
     loop = state->pc;
-    for (;;) {
-	state->pc = loop;
-	noerrexit = 1;
-	execlist(state, 1, 0);
-	noerrexit = olderrexit;
-	if (!((lastval == 0) ^ isuntil)) {
-	    if (breaks)
-		breaks--;
-	    lastval = oldval;
-	    break;
-	}
-	if (retflag) {
-	    lastval = oldval;
-	    break;
-	}
-	execlist(state, 1, 0);
-	if (breaks) {
-	    breaks--;
-	    if (breaks || !contflag)
-		break;
-	    contflag = 0;
-	}
-	if (errflag) {
-	    lastval = 1;
-	    break;
-	}
-	if (retflag)
-	    break;
-	freeheap();
-	oldval = lastval;
-    }
+
+    if (loop[0] == WC_END && loop[1] == WC_END) {
+
+        /* This is an empty loop.  Make sure the signal handler sets the
+        * flags and then just wait for someone hitting ^C. */
+
+        int old_simple_pline = simple_pline;
+
+        simple_pline = 1;
+
+        while (!breaks)
+            ;
+        breaks--;
+
+        simple_pline = old_simple_pline;
+    } else
+        for (;;) {
+            state->pc = loop;
+            noerrexit = 1;
+            execlist(state, 1, 0);
+            noerrexit = olderrexit;
+            if (!((lastval == 0) ^ isuntil)) {
+                if (breaks)
+                    breaks--;
+                lastval = oldval;
+                break;
+            }
+            if (retflag) {
+                lastval = oldval;
+                break;
+            }
+            execlist(state, 1, 0);
+            if (breaks) {
+                breaks--;
+                if (breaks || !contflag)
+                    break;
+                contflag = 0;
+            }
+            if (errflag) {
+                lastval = 1;
+                break;
+            }
+            if (retflag)
+                break;
+            freeheap();
+            oldval = lastval;
+        }
     cmdpop();
     popheap();
     loops--;