about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2004-09-03 09:47:44 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2004-09-03 09:47:44 +0000
commit97fd0d9b8907827d786b92f6cc66618d57ac7518 (patch)
tree84e4930f9db51eb8f5bb82006fd752cf8900fdc3 /Src
parentfb7907257503b2c8915d3623c694bfb21122b7df (diff)
downloadzsh-97fd0d9b8907827d786b92f6cc66618d57ac7518.tar.gz
zsh-97fd0d9b8907827d786b92f6cc66618d57ac7518.tar.xz
zsh-97fd0d9b8907827d786b92f6cc66618d57ac7518.zip
20308: add EVAL_LINENO option
Diffstat (limited to 'Src')
-rw-r--r--Src/builtin.c21
-rw-r--r--Src/exec.c4
-rw-r--r--Src/options.c1
-rw-r--r--Src/zsh.h1
4 files changed, 22 insertions, 5 deletions
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,