mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-25 17:41:19 +02:00
17979: Add ERR_RETURN option.
This commit is contained in:
parent
252da01c87
commit
28a62d5a4b
5 changed files with 34 additions and 7 deletions
|
@ -1,3 +1,8 @@
|
|||
2002-12-04 Peter Stephenson <pws@csr.com>
|
||||
|
||||
* 17979: Doc/Zsh/options.yo, Src/exec.c, Src/options.c, Src/zsh.h:
|
||||
Add ERR_RETURN option, similiar to ERR_EXIT option.
|
||||
|
||||
2002-11-26 Peter Stephenson <pws@csr.com>
|
||||
|
||||
* 17967: Test/B02typeset.ztst: globbable arguments to
|
||||
|
|
|
@ -380,6 +380,16 @@ If a command has a non-zero exit status, execute the tt(ZERR)
|
|||
trap, if set, and exit. This is disabled while running initialization
|
||||
scripts.
|
||||
)
|
||||
pindex(ERR_RETURN)
|
||||
cindex(function return, on error)
|
||||
cidnex(return from function, on error)
|
||||
item(tt(ERR_RETURN))(
|
||||
If a command has a non-zero exit status, return immediately from the
|
||||
enclosing function. The logic is identical to that for tt(ERR_EXIT),
|
||||
except that an implicit tt(return) statement is executed instead of an
|
||||
tt(exit). This will trigger an exit at the outermost level of a
|
||||
non-interactive script.
|
||||
)
|
||||
pindex(EXEC)
|
||||
cindex(command execution, enabling)
|
||||
item(tt(EXEC) (tt(PLUS()n), ksh: tt(PLUS()n)) <D>)(
|
||||
|
|
24
Src/exec.c
24
Src/exec.c
|
@ -924,13 +924,23 @@ sublist_done:
|
|||
dotrap(SIGZERR);
|
||||
donetrap = 1;
|
||||
}
|
||||
if (lastval && isset(ERREXIT)) {
|
||||
if (sigtrapped[SIGEXIT])
|
||||
dotrap(SIGEXIT);
|
||||
if (mypid != getpid())
|
||||
_exit(lastval);
|
||||
else
|
||||
exit(lastval);
|
||||
if (lastval) {
|
||||
int errreturn = isset(ERRRETURN) &&
|
||||
(isset(INTERACTIVE) || locallevel || sourcelevel);
|
||||
int errexit = isset(ERREXIT) ||
|
||||
(isset(ERRRETURN) && !errreturn);
|
||||
if (errexit) {
|
||||
if (sigtrapped[SIGEXIT])
|
||||
dotrap(SIGEXIT);
|
||||
if (mypid != getpid())
|
||||
_exit(lastval);
|
||||
else
|
||||
exit(lastval);
|
||||
}
|
||||
if (errreturn) {
|
||||
retflag = 1;
|
||||
breaks = loops;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ltype & Z_END)
|
||||
|
|
|
@ -109,6 +109,7 @@ static struct optname optns[] = {
|
|||
{NULL, "cshnullglob", OPT_EMULATE|OPT_CSH, CSHNULLGLOB},
|
||||
{NULL, "equals", OPT_EMULATE|OPT_ZSH, EQUALS},
|
||||
{NULL, "errexit", OPT_EMULATE, ERREXIT},
|
||||
{NULL, "errreturn", OPT_EMULATE, ERRRETURN},
|
||||
{NULL, "exec", OPT_ALL, EXECOPT},
|
||||
{NULL, "extendedglob", OPT_EMULATE, EXTENDEDGLOB},
|
||||
{NULL, "extendedhistory", OPT_CSH, EXTENDEDHISTORY},
|
||||
|
|
|
@ -1419,6 +1419,7 @@ enum {
|
|||
CSHNULLGLOB,
|
||||
EQUALS,
|
||||
ERREXIT,
|
||||
ERRRETURN,
|
||||
EXECOPT,
|
||||
EXTENDEDGLOB,
|
||||
EXTENDEDHISTORY,
|
||||
|
|
Loading…
Reference in a new issue