From 70c16dd30d4cf824aa895e9f6c095fec741c65a8 Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Mon, 6 Oct 2014 21:51:26 +0800 Subject: [BUILTIN] Return without arguments in a trap should use status outside traps POSIX now requires that return without arguments in a trap should return the last command status prior to executing traps. This patch implements this behaviour. Incidentally this also changes the behaviour of return without arguments in a loop conditional to use the last exit status in the body as opposed to the last command in the conditional when there is one. Signed-off-by: Herbert Xu --- src/eval.c | 17 ++++++++++++++--- src/eval.h | 1 + src/main.c | 2 +- src/trap.c | 3 ++- 4 files changed, 18 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/eval.c b/src/eval.c index 7b341f3..071fb1b 100644 --- a/src/eval.c +++ b/src/eval.c @@ -967,7 +967,7 @@ funcdone: shellparam = saveparam; handler = savehandler; INTON; - evalskip &= ~SKIPFUNC; + evalskip &= ~(SKIPFUNC | SKIPFUNCDEF); return e; } @@ -1047,12 +1047,23 @@ breakcmd(int argc, char **argv) int returncmd(int argc, char **argv) { + int skip; + int status; + /* * If called outside a function, do what ksh does; * skip the rest of the file. */ - evalskip = SKIPFUNC; - return argv[1] ? number(argv[1]) : exitstatus; + if (argv[1]) { + skip = SKIPFUNC; + status = number(argv[1]); + } else { + skip = SKIPFUNCDEF; + status = exitstatus; + } + evalskip = skip; + + return status; } diff --git a/src/eval.h b/src/eval.h index 6e62137..6e8acda 100644 --- a/src/eval.h +++ b/src/eval.h @@ -62,3 +62,4 @@ extern int evalskip; #define SKIPBREAK (1 << 0) #define SKIPCONT (1 << 1) #define SKIPFUNC (1 << 2) +#define SKIPFUNCDEF (1 << 3) diff --git a/src/main.c b/src/main.c index 29a258d..00c5e00 100644 --- a/src/main.c +++ b/src/main.c @@ -242,7 +242,7 @@ cmdloop(int top) skip = evalskip; if (skip) { - evalskip &= ~SKIPFUNC; + evalskip &= ~(SKIPFUNC | SKIPFUNCDEF); break; } } diff --git a/src/trap.c b/src/trap.c index 15faeff..b924661 100644 --- a/src/trap.c +++ b/src/trap.c @@ -343,7 +343,8 @@ void dotrap(void) if (!p) continue; evalstring(p, 0); - exitstatus = status; + if (evalskip != SKIPFUNC) + exitstatus = status; } savestatus = last_status; -- cgit 1.4.1 d01222caecbe9923cbcddce7a181f3&showmsg=1'>unfollow)
Commit message (Collapse)Author
2019-07-27Move pdf script to MakefileJune McEnroe
2019-07-27Update macOS neovim to 0.3.8June McEnroe
Which somehow still doesn't include my man fix.
2019-07-27Rewrite port makefiles consistentlyJune McEnroe
2019-07-27Rewrite Makefile once more with more organizationJune McEnroe
2019-07-27Reference png.h in bin.7June McEnroe
2019-07-27Revert "Use scheme to style HTMLs"June McEnroe
This reverts commit 4b7d5161a30645b0a23691687ef1aafdda62d3bb. I don't know why but I don't like it.
2019-07-27Remove scheme text linkJune McEnroe
No standard base64 encoder so no way to maintain it.
2019-07-26Update Dark.terminalJune McEnroe
Why are the blobs so much bigger now?
2019-07-26Lighten dark whiteJune McEnroe
2019-07-25Add png.3 man pageJune McEnroe
2019-07-25Use scheme to style HTMLsJune McEnroe
2019-07-25Don't match comments in strings in makeJune McEnroe
2019-07-25Generate index.html with links from bin.7June McEnroe
2019-07-24Warn when date has changedJune McEnroe
2019-07-24Add whenJune McEnroe
When? Now.
2019-07-24Remove histedit from bitJune McEnroe