Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh-4.2.1: LINENO lost in evals



"Dieter Lambrecht" wrote:
> The behaviour of zsh is incompatible to ksh, even though in "emulate
> ksh"-mode.

Is this the real problem?  I asked what this was being used for but
didn't get an answer.

It's easy to introduce an option, but I don't know how useful it is.

Index: Doc/Zsh/options.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/options.yo,v
retrieving revision 1.34
diff -u -r1.34 options.yo
--- Doc/Zsh/options.yo	16 Aug 2004 09:53:10 -0000	1.34
+++ Doc/Zsh/options.yo	2 Sep 2004 15:52:22 -0000
@@ -929,7 +929,7 @@
 )
 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 @@
 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>)(
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.122
diff -u -r1.122 builtin.c
--- Src/builtin.c	7 Jul 2004 15:00:57 -0000	1.122
+++ Src/builtin.c	2 Sep 2004 15:52:25 -0000
@@ -4220,27 +4220,42 @@
 /* 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;
 }
Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.69
diff -u -r1.69 exec.c
--- Src/exec.c	29 Jul 2004 15:09:51 -0000	1.69
+++ Src/exec.c	2 Sep 2004 15:52:27 -0000
@@ -788,7 +788,7 @@
 	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 @@
 	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) {
Index: Src/options.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/options.c,v
retrieving revision 1.20
diff -u -r1.20 options.c
--- Src/options.c	2 Jun 2004 22:14:26 -0000	1.20
+++ Src/options.c	2 Sep 2004 15:52:27 -0000
@@ -115,6 +115,7 @@
 {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},
Index: Src/zsh.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v
retrieving revision 1.58
diff -u -r1.58 zsh.h
--- Src/zsh.h	11 Jul 2004 22:53:03 -0000	1.58
+++ Src/zsh.h	2 Sep 2004 15:52:28 -0000
@@ -1445,6 +1445,7 @@
     EXECOPT,
     EXTENDEDGLOB,
     EXTENDEDHISTORY,
+    EVALLINENO,
     FLOWCONTROL,
     FUNCTIONARGZERO,
     GLOBOPT,

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited. 
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author