mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-01-01 05:16:05 +01:00
39625: case needs to reset lastval if no pattern matched
This commit is contained in:
parent
9d393f7b7d
commit
31c6cfca9c
3 changed files with 28 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2016-10-13 Peter Stephenson <p.stephenson@samsung.com>
|
||||||
|
|
||||||
|
* 39625: Martijn Dekker: Src/loop.c, Test/A01grammar.ztst: case
|
||||||
|
needs to reset lastval if no pattern matched.
|
||||||
|
|
||||||
2016-10-13 Oliver Kiddle <opk@zsh.org>
|
2016-10-13 Oliver Kiddle <opk@zsh.org>
|
||||||
|
|
||||||
* 39622: Test/Y03arguments.ztst: add test cases for recent
|
* 39622: Test/Y03arguments.ztst: add test cases for recent
|
||||||
|
|
|
@ -584,7 +584,7 @@ execcase(Estate state, int do_exec)
|
||||||
Wordcode end, next;
|
Wordcode end, next;
|
||||||
wordcode code = state->pc[-1];
|
wordcode code = state->pc[-1];
|
||||||
char *word, *pat;
|
char *word, *pat;
|
||||||
int npat, save, nalts, ialt, patok;
|
int npat, save, nalts, ialt, patok, anypatok;
|
||||||
Patprog *spprog, pprog;
|
Patprog *spprog, pprog;
|
||||||
|
|
||||||
end = state->pc + WC_CASE_SKIP(code);
|
end = state->pc + WC_CASE_SKIP(code);
|
||||||
|
@ -592,6 +592,7 @@ execcase(Estate state, int do_exec)
|
||||||
word = ecgetstr(state, EC_DUP, NULL);
|
word = ecgetstr(state, EC_DUP, NULL);
|
||||||
singsub(&word);
|
singsub(&word);
|
||||||
untokenize(word);
|
untokenize(word);
|
||||||
|
anypatok = 0;
|
||||||
|
|
||||||
cmdpush(CS_CASE);
|
cmdpush(CS_CASE);
|
||||||
while (state->pc < end) {
|
while (state->pc < end) {
|
||||||
|
@ -648,7 +649,7 @@ execcase(Estate state, int do_exec)
|
||||||
*spprog = pprog;
|
*spprog = pprog;
|
||||||
}
|
}
|
||||||
if (pprog && pattry(pprog, word))
|
if (pprog && pattry(pprog, word))
|
||||||
patok = 1;
|
patok = anypatok = 1;
|
||||||
state->pc += 2;
|
state->pc += 2;
|
||||||
nalts--;
|
nalts--;
|
||||||
}
|
}
|
||||||
|
@ -679,6 +680,9 @@ execcase(Estate state, int do_exec)
|
||||||
|
|
||||||
state->pc = end;
|
state->pc = end;
|
||||||
|
|
||||||
|
if (!anypatok)
|
||||||
|
lastval = 0;
|
||||||
|
|
||||||
return lastval;
|
return lastval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -763,6 +763,23 @@
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
0:case retains exit status for execution of cases
|
0:case retains exit status for execution of cases
|
||||||
|
>37
|
||||||
|
|
||||||
|
false
|
||||||
|
case stuff in
|
||||||
|
(nomatch) foo
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
echo $?
|
||||||
|
0:case sets exit status to zero if no patterns are matched
|
||||||
|
>0
|
||||||
|
|
||||||
|
case match in
|
||||||
|
(match) true; false; (exit 37)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
echo $?
|
||||||
|
0:case keeps exit status of last command executed in compound-list
|
||||||
>37
|
>37
|
||||||
|
|
||||||
x=1
|
x=1
|
||||||
|
|
Loading…
Reference in a new issue