mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-02 22:11:54 +02:00
33294: $functions[func_with_redir] plus extra tests
This commit is contained in:
parent
15222bcdcb
commit
0557c226fc
3 changed files with 72 additions and 11 deletions
|
@ -1,5 +1,9 @@
|
|||
2014-09-30 Peter Stephenson <p.stephenson@samsung.com>
|
||||
|
||||
* 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.
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue