zsh-workers
 help / color / mirror / code / Atom feed
* Re: zsh-4.2.1: LINENO lost in evals
@ 2004-09-02 13:57 Dieter Lambrecht
  2004-09-02 15:53 ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Dieter Lambrecht @ 2004-09-02 13:57 UTC (permalink / raw)
  To: zsh-workers


Hi,

the behaviour of LINENO-behavior may be similiar to perl in some curcumstances. Script

#! /bin/ksh

print $LINENO
eval 'print $LINENO'

used with a real ksh on AIX or Solaris always prints the correct LINENO. The behaviour of zsh is incompatible to ksh, even though in "emulate ksh"-mode.

Kind Regards,

Dieter Lambrecht




                                                                                                                                                                
                      Bart Schaefer                                                                                                                             
                      <schaefer@brassla        To:       zsh-workers@sunsite.dk                                                                                 
                      ntern.com>               cc:       Dieter Lambrecht/DMG/Zentrale/DeuBa@Zentrale                                                           
                                               Subject:  Re: zsh-4.2.1: LINENO lost in evals                                                                    
                      09/01/2004 05:10                                                                                                                          
                      PM                                                                                                                                        
                      Please respond to                                                                                                                         
                      zsh-workers                                                                                                                               
                                                                                                                                                                
                                                                                                                                                                




On Wed, 1 Sep 2004, Peter Stephenson wrote:

> "Dieter Lambrecht" wrote:
> >#! /bin/zsh -x
>
> (There must be a set -x or setopt xtrace lurking somewhere.)

Welcome back, Peter. :-)

> It's not actually lost, it's showing you the line in the eval.  That's
> a feature (compare error messages from Perl evals, which is where we
> pinched the output format from).

The thing is, Perl has two kinds of "eval":

schaefer[676] perl <<\EOF
print __LINE__."\n";
eval 'print __LINE__."\n"';
eval { print __LINE__."\n"; };
EOF
1
1
3

The kind in braces, which gets precompiled, behaves differently than the
 kind in quotes.  Zsh only has the kind in quotes.




--

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: zsh-4.2.1: LINENO lost in evals
  2004-09-02 13:57 zsh-4.2.1: LINENO lost in evals Dieter Lambrecht
@ 2004-09-02 15:53 ` Peter Stephenson
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2004-09-02 15:53 UTC (permalink / raw)
  To: zsh-workers

"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.
**********************************************************************


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: zsh-4.2.1: LINENO lost in evals
  2004-09-01 12:02 ` Peter Stephenson
@ 2004-09-01 15:10   ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2004-09-01 15:10 UTC (permalink / raw)
  To: zsh-workers; +Cc: Dieter Lambrecht

On Wed, 1 Sep 2004, Peter Stephenson wrote:

> "Dieter Lambrecht" wrote:
> >#! /bin/zsh -x
> 
> (There must be a set -x or setopt xtrace lurking somewhere.)

Welcome back, Peter. :-)

> It's not actually lost, it's showing you the line in the eval.  That's
> a feature (compare error messages from Perl evals, which is where we
> pinched the output format from).

The thing is, Perl has two kinds of "eval":

schaefer[676] perl <<\EOF
print __LINE__."\n";
eval 'print __LINE__."\n"';
eval { print __LINE__."\n"; };
EOF
1
1
3

The kind in braces, which gets precompiled, behaves differently than the 
kind in quotes.  Zsh only has the kind in quotes.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: zsh-4.2.1: LINENO lost in evals
  2004-08-17  8:27 Dieter Lambrecht
@ 2004-09-01 12:02 ` Peter Stephenson
  2004-09-01 15:10   ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2004-09-01 12:02 UTC (permalink / raw)
  To: Dieter Lambrecht, zsh-workers

"Dieter Lambrecht" wrote:
>#! /bin/zsh -x
>emulate -L zsh
>
>print $LINENO
>eval 'print $LINENO'
>
>return
>
> produces the following output:
>
> ./t4.sh
> +./t4.sh:2> emulate -L zsh
> +./t4.sh:4> print 4
> 4
> +./t4.sh:5> eval 'print $LINENO'
> +(eval):1> print 1
> 1
> .
> 
> It seems that LINENO is lost in the eval-statement. Is there any possib=
> ility to retrieve the original value inside evals ?

(There must be a set -x or setopt xtrace lurking somewhere.)

It's not actually lost, it's showing you the line in the eval.  That's
a feature (compare error messages from Perl evals, which is where we
pinched the output format from).

What are you trying to do?  You can record the line number outside if
you need it, e.g.

lineno=LINENO; eval 'print $lineno'

I take it the complaint isn't about the debugging output from xtrace
this time, since that shows the line number of the eval command (5).

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


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


^ permalink raw reply	[flat|nested] 5+ messages in thread

* zsh-4.2.1: LINENO lost in evals
@ 2004-08-17  8:27 Dieter Lambrecht
  2004-09-01 12:02 ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Dieter Lambrecht @ 2004-08-17  8:27 UTC (permalink / raw)
  To: zsh-workers

Hi,

script

#! /bin/zsh -x
emulate -L zsh

print $LINENO
eval 'print $LINENO'

return


produces the following output:

./t4.sh
+./t4.sh:2> emulate -L zsh
+./t4.sh:4> print 4
4
+./t4.sh:5> eval 'print $LINENO'
+(eval):1> print 1
1
.

It seems that LINENO is lost in the eval-statement. Is there any possibility to retrieve the original value inside evals ?


Kind Regards,

Dieter Lambrecht



--

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-09-02 17:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-02 13:57 zsh-4.2.1: LINENO lost in evals Dieter Lambrecht
2004-09-02 15:53 ` Peter Stephenson
  -- 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

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).