diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | Doc/Zsh/options.yo | 15 | ||||
-rw-r--r-- | Src/builtin.c | 21 | ||||
-rw-r--r-- | Src/exec.c | 4 | ||||
-rw-r--r-- | Src/options.c | 1 | ||||
-rw-r--r-- | Src/zsh.h | 1 |
6 files changed, 44 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog index 8ba3c08c1..e97d7a2cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-09-03 Peter Stephenson <pws@csr.com> + + * 20308: Doc/Zsh/options.yo, Src/builtin.c, Src/exec.c, + Src/options.c, Src/zsh.h: add option EVAL_LINENO <Z> which + issues separate line numbers inside eval's, as at present. + Without it, the line from the surrounding environment is + reported. + 2004-09-02 Peter Stephenson <pws@csr.com> * 20303: Src/Zle/zle_thingy.c, Doc/Zsh/zle.yo: Make test for diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 49f65d186..fdd498c50 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -929,7 +929,7 @@ scripts. ) pindex(ERR_RETURN) cindex(function return, on error) -cidnex(return from function, on error) +cindex(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), @@ -937,6 +937,19 @@ 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(EVAL_LINENO) +cindex(line number, in evaluated expression) +item(tt(EVAL_LINENO) <Z>)( +If set, line numbers of expressions evaluated using the builtin tt(eval) +are tracked separately of the enclosing environment. This applies both +to the parameter tt(LINENO) and the line number output by the prompt +escape tt(%i). If the option is set, the prompt escape tt(%N) will output +the string `tt((eval))' instead of the script or function name as an +indication. (The two prompt escapes are typically used in the parameter +tt(PS4) to be output when the option tt(XTRACE) is set.) If +tt(EVAL_LINENO) is unset, the line number of the surrounding script or +function is retained during the evaluation. +) pindex(EXEC) cindex(command execution, enabling) item(tt(EXEC) (tt(PLUS()n), ksh: tt(PLUS()n)) <D>)( diff --git a/Src/builtin.c b/Src/builtin.c index 294b405b3..44d85b80a 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -4220,27 +4220,42 @@ bin_emulate(UNUSED(char *nam), char **argv, Options ops, UNUSED(int func)) /* eval: simple evaluation */ /**/ +int ineval; + +/**/ int bin_eval(UNUSED(char *nam), char **argv, UNUSED(Options ops), UNUSED(int func)) { Eprog prog; char *oscriptname = scriptname; - - scriptname = "(eval)"; + int oineval = ineval; + /* + * If EVALLINENO is not set, we use the line number of the + * environment and must flag this up to exec.c. Otherwise, + * we use a special script name to indicate the special line number. + */ + ineval = !isset(EVALLINENO); prog = parse_string(zjoin(argv, ' ', 1)); if (!prog) { errflag = 0; return 1; } + lastval = 0; + if (!ineval) + scriptname = "(eval)"; + execode(prog, 1, 0); + if (errflag) { lastval = errflag; errflag = 0; } - scriptname = oscriptname; + if (!ineval) + scriptname = oscriptname; + ineval = oineval; return lastval; } diff --git a/Src/exec.c b/Src/exec.c index d1c3bb98e..5fd2a2e30 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -788,7 +788,7 @@ execsimple(Estate state) return (lastval = 1); /* In evaluated traps, don't modify the line number. */ - if ((!intrap || trapisfunc) && code) + if ((!intrap || trapisfunc) && !ineval && code) lineno = code - 1; code = wc_code(*state->pc++); @@ -1260,7 +1260,7 @@ execpline2(Estate state, wordcode pcode, return; /* In evaluated traps, don't modify the line number. */ - if ((!intrap || trapisfunc) && WC_PIPE_LINENO(pcode)) + if ((!intrap || trapisfunc) && !ineval && WC_PIPE_LINENO(pcode)) lineno = WC_PIPE_LINENO(pcode) - 1; if (pline_level == 1) { diff --git a/Src/options.c b/Src/options.c index 21d9d00ed..70a7364fc 100644 --- a/Src/options.c +++ b/Src/options.c @@ -115,6 +115,7 @@ static struct optname optns[] = { {NULL, "exec", OPT_ALL, EXECOPT}, {NULL, "extendedglob", OPT_EMULATE, EXTENDEDGLOB}, {NULL, "extendedhistory", OPT_CSH, EXTENDEDHISTORY}, +{NULL, "evallineno", OPT_EMULATE|OPT_ZSH, EVALLINENO}, {NULL, "flowcontrol", OPT_ALL, FLOWCONTROL}, {NULL, "functionargzero", OPT_EMULATE|OPT_NONBOURNE, FUNCTIONARGZERO}, {NULL, "glob", OPT_EMULATE|OPT_ALL, GLOBOPT}, diff --git a/Src/zsh.h b/Src/zsh.h index 1501fdf8e..40d506044 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -1445,6 +1445,7 @@ enum { EXECOPT, EXTENDEDGLOB, EXTENDEDHISTORY, + EVALLINENO, FLOWCONTROL, FUNCTIONARGZERO, GLOBOPT, |