summaryrefslogtreecommitdiff
path: root/Src/loop.c
diff options
context:
space:
mode:
authorAxel Beckert <abe@deuxchevaux.org>2016-12-04 04:32:03 +0100
committerAxel Beckert <abe@deuxchevaux.org>2016-12-04 04:32:03 +0100
commit3e439c3863f14c82f70666804c8570a13b3732e6 (patch)
tree07036c43e0f3f9242bb6dd42cd2a849ec8ea8aca /Src/loop.c
parent2aedc4b88fd0e87b89583983951b04b96f48efd3 (diff)
parent7b7e84f0815ed22a0ee348a217776529035dccf3 (diff)
downloadzsh-3e439c3863f14c82f70666804c8570a13b3732e6.tar.gz
zsh-3e439c3863f14c82f70666804c8570a13b3732e6.zip
Merge tag 'zsh-5.2-test-1' into debian
Diffstat (limited to 'Src/loop.c')
-rw-r--r--Src/loop.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/Src/loop.c b/Src/loop.c
index 4def9b652..367c0df5c 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -289,6 +289,8 @@ execselect(Estate state, UNUSED(int do_exec))
}
} else
str = (char *)getlinknode(bufstack);
+ if (!str && !errflag)
+ setsparam("REPLY", ztrdup("")); /* EOF (user pressed Ctrl+D) */
if (!str || errflag) {
if (breaks)
breaks--;
@@ -437,13 +439,12 @@ execwhile(Estate state, UNUSED(int do_exec))
if (!((lastval == 0) ^ isuntil)) {
if (breaks)
breaks--;
- lastval = oldval;
+ if (!retflag)
+ lastval = oldval;
break;
}
- if (retflag) {
- lastval = oldval;
+ if (retflag)
break;
- }
/* In case the loop body is also a functional no-op,
* make sure signal handlers recognize ^C as above. */
@@ -493,7 +494,9 @@ execrepeat(Estate state, UNUSED(int do_exec))
tmp = ecgetstr(state, EC_DUPTOK, &htok);
if (htok)
singsub(&tmp);
- count = atoi(tmp);
+ count = mathevali(tmp);
+ if (errflag)
+ return 1;
pushheap();
cmdpush(CS_REPEAT);
loops++;
@@ -566,7 +569,8 @@ execif(Estate state, int do_exec)
cmdpop();
} else {
noerrexit = olderrexit;
- lastval = 0;
+ if (!retflag)
+ lastval = 0;
}
state->pc = end;
@@ -580,7 +584,7 @@ execcase(Estate state, int do_exec)
Wordcode end, next;
wordcode code = state->pc[-1];
char *word, *pat;
- int npat, save, nalts, ialt, patok;
+ int npat, save, nalts, ialt, patok, anypatok;
Patprog *spprog, pprog;
end = state->pc + WC_CASE_SKIP(code);
@@ -588,7 +592,7 @@ execcase(Estate state, int do_exec)
word = ecgetstr(state, EC_DUP, NULL);
singsub(&word);
untokenize(word);
- lastval = 0;
+ anypatok = 0;
cmdpush(CS_CASE);
while (state->pc < end) {
@@ -645,7 +649,7 @@ execcase(Estate state, int do_exec)
*spprog = pprog;
}
if (pprog && pattry(pprog, word))
- patok = 1;
+ patok = anypatok = 1;
state->pc += 2;
nalts--;
}
@@ -658,7 +662,7 @@ execcase(Estate state, int do_exec)
execlist(state, 1, ((WC_CASE_TYPE(code) == WC_CASE_OR) &&
do_exec));
while (!retflag && wc_code(code) == WC_CASE &&
- WC_CASE_TYPE(code) == WC_CASE_AND) {
+ WC_CASE_TYPE(code) == WC_CASE_AND && state->pc < end) {
state->pc = next;
code = *state->pc++;
next = state->pc + WC_CASE_SKIP(code);
@@ -676,6 +680,9 @@ execcase(Estate state, int do_exec)
state->pc = end;
+ if (!anypatok)
+ lastval = 0;
+
return lastval;
}