From 246404a44d14e733d275e20c32dcb756e5b88a0b Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 12 Sep 2014 20:35:16 +0100 Subject: Add $functypestack special parameter in zsh/parameter --- Src/Modules/parameter.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'Src/Modules/parameter.c') 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, -- cgit v1.2.3 From 08e5191ff016f9df61bb157fc56cb9af6c599863 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 18 Sep 2014 19:09:52 +0100 Subject: users/19097: remove $functypetrace in favour of ref to $zsheval_context --- ChangeLog | 6 ++++++ Doc/Zsh/mod_parameter.yo | 22 +++++++++------------- Src/Modules/parameter.c | 39 --------------------------------------- 3 files changed, 15 insertions(+), 52 deletions(-) (limited to 'Src/Modules/parameter.c') diff --git a/ChangeLog b/ChangeLog index 7d1ea2b23..27b567740 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-09-18 Peter Stephenson + + * users/19097: Doc/Zsh/mod_parameter.yo, + Src/Modules/parameter.c: remove functypetrace and instead add + cross-reference to zsh_eval_context. + 2014-09-16 Marc Finet * 33188: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: diff --git a/Doc/Zsh/mod_parameter.yo b/Doc/Zsh/mod_parameter.yo index c1571603c..09ceba258 100644 --- a/Doc/Zsh/mod_parameter.yo +++ b/Doc/Zsh/mod_parameter.yo @@ -201,10 +201,7 @@ 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. - -The most recent call is the first element in the array. +shown as var(filename)tt(:)var(0), since the entire file is the definition. Most users will be interested in the information in the tt(funcfiletrace) array instead. @@ -215,6 +212,14 @@ This array contains the names of the functions, sourced files, and (if tt(EVAL_LINENO) is set) tt(eval) commands. currently being executed. The first element is the name of the function using the parameter. + +The standard shell array tt(zsh_eval_context) can be used to +determine the type of shell construct being executed at each depth: +note, however, that is in the opposite order, with the most recent +item last, and it is more detailed, for example including an +entry for tt(toplevel), the main shell code being executed +either interactively or from a script, which is not present +in tt($funcstack). ) vindex(functrace) item(tt(functrace))( @@ -224,13 +229,4 @@ 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 02a642bec..0385a709e 100644 --- a/Src/Modules/parameter.c +++ b/Src/Modules/parameter.c @@ -640,41 +640,6 @@ 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. */ /**/ @@ -2081,8 +2046,6 @@ 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 = @@ -2127,8 +2090,6 @@ 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, -- cgit v1.2.3 From 0557c226fcd817ef21f91ed76e01db6e965b0709 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 30 Sep 2014 12:58:52 +0100 Subject: 33294: $functions[func_with_redir] plus extra tests --- ChangeLog | 4 ++++ Src/Modules/parameter.c | 55 +++++++++++++++++++++++++++++++++++++++---------- Test/A04redirect.ztst | 24 +++++++++++++++++++++ 3 files changed, 72 insertions(+), 11 deletions(-) (limited to 'Src/Modules/parameter.c') diff --git a/ChangeLog b/ChangeLog index d3b01a394..3f449cdf1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2014-09-30 Peter Stephenson + * 33294: Src/Modules/parameter.c, Test/A04redirect.ztst: + functions[func] value for functions with redirections and + extra tests. + * 33293: Src/Zle/compctl.c, Src/Zle/zle_refresh.c: fix warnings from swish new compilers with a contemporary outlook. diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c index 0385a709e..55157a90c 100644 --- a/Src/Modules/parameter.c +++ b/Src/Modules/parameter.c @@ -392,20 +392,36 @@ getfunction(UNUSED(HashTable ht), const char *name, int dis) ((shf->node.flags & PM_TAGGED) ? "t" : ""))); } else { char *t = getpermtext(shf->funcdef, NULL, 1), *n, *h; + char *start; + + if (shf->redir) + start = "{\n\t"; + else + start = "\t"; if (shf->funcdef->flags & EF_RUN) { n = nicedupstring(name); - h = (char *) zhalloc(strlen(t) + strlen(n) + 9); - h[0] = '\t'; - strcpy(h + 1, t); + h = (char *) zhalloc(strlen(start) + strlen(t) + strlen(n) + 8); + strcpy(h, start); + strcat(h, t); strcat(h, "\n\t"); strcat(h, n); strcat(h, " \"$@\""); } else - h = dyncat("\t", t); + h = dyncat(start, t); zsfree(t); + /* + * TBD: Is this unmetafy correct? Surely as this + * is a parameter value it stays metafied? + */ unmetafy(h, NULL); + if (shf->redir) { + t = getpermtext(shf->redir, NULL, 1); + h = zhtricat(h, "\n}", t); + zsfree(t); + } + pm->u.str = h; } } else { @@ -456,21 +472,38 @@ scanfunctions(UNUSED(HashTable ht), ScanFunc func, int flags, int dis) ((shf->node.flags & PM_TAGGED) ? "Ut" : "U") : ((shf->node.flags & PM_TAGGED) ? "t" : ""))); } else { - char *t = getpermtext(((Shfunc) hn)->funcdef, NULL, 1); - char *n; + Shfunc shf = (Shfunc)hn; + char *t = getpermtext(shf->funcdef, NULL, 1); + char *n, *start; - if (((Shfunc) hn)->funcdef->flags & EF_RUN) { + if (shf->redir) + start = "{\n\t"; + else + start = "\t"; + + if (shf->funcdef->flags & EF_RUN) { n = nicedupstring(hn->nam); - pm.u.str = (char *) zhalloc(strlen(t) + strlen(n) + 9); - pm.u.str[0] = '\t'; - strcpy(pm.u.str + 1, t); + pm.u.str = (char *) zhalloc( + strlen(start) + strlen(t) + strlen(n) + 8); + strcpy(pm.u.str, start); + strcat(pm.u.str, t); strcat(pm.u.str, "\n\t"); strcat(pm.u.str, n); strcat(pm.u.str, " \"$@\""); } else - pm.u.str = dyncat("\t", t); + pm.u.str = dyncat(start, t); + /* + * TBD: Is this unmetafy correct? Surely as this + * is a parameter value it stays metafied? + */ unmetafy(pm.u.str, NULL); zsfree(t); + + if (shf->redir) { + t = getpermtext(shf->redir, NULL, 1); + pm.u.str = zhtricat(pm.u.str, "\n}", t); + zsfree(t); + } } } func(&pm.node, flags); diff --git a/Test/A04redirect.ztst b/Test/A04redirect.ztst index 6c38a3194..a39ce46c8 100644 --- a/Test/A04redirect.ztst +++ b/Test/A04redirect.ztst @@ -507,3 +507,27 @@ >Ich heisse 2func >Running 3func >Ich heisse 3func + + redirfn2() { print The latest output; } >&3 + redirfn2 3>output4 + print No output yet + cat output4 +0:Redirections in both function definition and command line +>No output yet +>The latest output + +# This relies on the fact that the test harness always loads +# the zsh/parameter module. + print $functions[redirfn] +0:Output from $functions[] for definition with redirection +>{ +> local var +> read var +> print I want to tell you about $var +> print Also, this might be an error >&2 +>} < input2 > output2 2>&1 + + noredirfn() { print This rather boring function has no redirection.; } + print $functions[noredirfn] +0:Output from $functions[] for definition with no redirection +> print This rather boring function has no redirection. -- cgit v1.2.3