about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2014-09-12 20:35:16 +0100
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2014-09-12 20:35:16 +0100
commit246404a44d14e733d275e20c32dcb756e5b88a0b (patch)
tree0f619dda23773b65681d4f3c5b58aa98f862eb6b
parentadd8d94665bc180e781b87051d8dcf71e7b3cb53 (diff)
downloadzsh-246404a44d14e733d275e20c32dcb756e5b88a0b.tar.gz
zsh-246404a44d14e733d275e20c32dcb756e5b88a0b.tar.xz
zsh-246404a44d14e733d275e20c32dcb756e5b88a0b.zip
Add $functypestack special parameter in zsh/parameter
-rw-r--r--ChangeLog6
-rw-r--r--Doc/Zsh/mod_parameter.yo14
-rw-r--r--Src/Modules/parameter.c39
3 files changed, 58 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index eacf4e31b..d70037525 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-09-12  Peter Stephenson  <p.w.stephenson@ntlworld.com>
+
+	* users/19075: Doc/Zsh/mod_parameter.yo,
+	Src/Modules/parameter.c: $functypestack gives "function",
+	"source" or "eval" for parallel element of $funcstack.
+
 2014-09-09  Peter Stephenson  <p.stephenson@samsung.com>
 
 	* Eric Cook: 33132: Completion/Unix/Type/_net_interfaces: use ip
diff --git a/Doc/Zsh/mod_parameter.yo b/Doc/Zsh/mod_parameter.yo
index 32d4796f7..c1571603c 100644
--- a/Doc/Zsh/mod_parameter.yo
+++ b/Doc/Zsh/mod_parameter.yo
@@ -201,7 +201,10 @@ The format of each element is var(filename)tt(:)var(lineno).
 For functions autoloaded from a file in native zsh format, where only the
 body of the function occurs in the file, or for files that have been
 executed by the tt(source) or `tt(.)' builtins, the trace information is
-shown as var(filename)tt(:)var(0), since the entire file is the definition.
+shown as var(filename)tt(:)var(0), since the entire file is the
+definition.
+
+The most recent call is the first element in the array.
 
 Most users will be interested in the information in the
 tt(funcfiletrace) array instead.
@@ -221,4 +224,13 @@ The format of each element is var(name)tt(:)var(lineno).
 Callers are also shown for sourced files; the caller is the point
 where the tt(source) or `tt(.)' command was executed.
 )
+vindex(functypestack)
+item(tt(functypestack))(
+This array corresponds element by element with tt(funcstack).
+Each element contains `tt(source)' for a sourced file, `tt(function)'
+for a function and `tt(eval)' for an tt(eval)'d expression.  At the top
+level of execution of a series of commands, tt($functypestack[1]) is
+empty if the commands are being executed as a script, or one of the
+previous strings if the commands are being executed as that type.
+)
 enditem()
diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c
index 0385a709e..02a642bec 100644
--- a/Src/Modules/parameter.c
+++ b/Src/Modules/parameter.c
@@ -640,6 +640,41 @@ funcfiletracegetfn(UNUSED(Param pm))
     return ret;
 }
 
+/* Functions for the functypestack special parameter. */
+
+static char **
+functypestackgetfn(UNUSED(Param pm))
+{
+    Funcstack f;
+    int num;
+    char **ret, **p;
+
+    for (f = funcstack, num = 0; f; f = f->prev, num++);
+
+    ret = (char **) zhalloc((num + 1) * sizeof(char *));
+
+    for (f = funcstack, p = ret; f; f = f->prev, p++)
+    {
+	switch (f->tp)
+	{
+	case FS_SOURCE:
+	    *p = "source";
+	    break;
+
+	case FS_FUNC:
+	    *p = "function";
+	    break;
+
+	case FS_EVAL:
+	    *p = "eval";
+	    break;
+	}
+    }
+    *p = NULL;
+
+    return ret;
+}
+
 /* Functions for the builtins special parameter. */
 
 /**/
@@ -2046,6 +2081,8 @@ static const struct gsu_array funcsourcetrace_gsu =
 { funcsourcetracegetfn, arrsetfn, stdunsetfn };
 static const struct gsu_array funcfiletrace_gsu =
 { funcfiletracegetfn, arrsetfn, stdunsetfn };
+static const struct gsu_array functypestack_gsu =
+{ functypestackgetfn, arrsetfn, stdunsetfn };
 static const struct gsu_array reswords_gsu =
 { reswordsgetfn, arrsetfn, stdunsetfn };
 static const struct gsu_array disreswords_gsu =
@@ -2090,6 +2127,8 @@ static struct paramdef partab[] = {
 		 scanpmfunctions),
     SPECIALPMDEF("functrace", PM_ARRAY|PM_READONLY,
 	    &functrace_gsu, NULL, NULL),
+    SPECIALPMDEF("functypestack", PM_ARRAY|PM_READONLY,
+		 &functypestack_gsu, NULL, NULL),
     SPECIALPMDEF("galiases", 0,
 	    &pmgaliases_gsu, getpmgalias, scanpmgaliases),
     SPECIALPMDEF("history", PM_READONLY,