zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk
Subject: Re: zsh-4.2.1: LINENO lost in evals
Date: Thu, 02 Sep 2004 16:53:50 +0100	[thread overview]
Message-ID: <200409021553.i82FroQw015081@news01.csr.com> (raw)
In-Reply-To: ""Dieter Lambrecht""'s message of "Thu, 02 Sep 2004 15:57:10 +0200." <OF6190409D.74BBAAAF-ONC1256F03.004C2404-C1256F03.004CAA3D@db.com>

"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@csr.com>                  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.
**********************************************************************


  reply	other threads:[~2004-09-02 17:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-02 13:57 Dieter Lambrecht
2004-09-02 15:53 ` Peter Stephenson [this message]
  -- strict thread matches above, loose matches on Subject: below --
2004-08-17  8:27 Dieter Lambrecht
2004-09-01 12:02 ` Peter Stephenson
2004-09-01 15:10   ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200409021553.i82FroQw015081@news01.csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).