From eaa5228eb1bb5a8071cd9e2538b25588b081a1eb Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Tue, 2 Nov 1999 09:09:21 +0000 Subject: zsh-workers/8480 --- Src/Modules/parameter.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'Src/Modules/parameter.c') diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c index 624d33933..abe7cacd9 100644 --- a/Src/Modules/parameter.c +++ b/Src/Modules/parameter.c @@ -555,6 +555,44 @@ scanpmdisfunctions(HashTable ht, ScanFunc func, int flags) scanfunctions(ht, func, flags, DISABLED); } +/* Functions for the funcstack special parameter. */ + +static LinkList funcstack; + +/**/ +static char ** +funcstackgetfn(Param pm) +{ + char **ret, **p; + LinkNode node; + + ret = (char **) zhalloc((countlinknodes(funcstack) + 1) * sizeof(char *)); + + for (node = firstnode(funcstack), p = ret; node; incnode(node), p++) + *p = (char *) getdata(node); + *p = NULL; + + return ret; +} + +/**/ +static int +func_wrapper(List list, FuncWrap w, char *name) +{ + PERMALLOC { + pushnode(funcstack, ztrdup(name)); + } LASTALLOC; + + runshfunc(list, w, name); + + DPUTS(strcmp(name, (char *) getdata(firstnode(funcstack))), + "funcstack wrapper with wrong function"); + + zsfree((char *) remnode(funcstack, firstnode(funcstack))); + + return 0; +} + /* Functions for the builtins special parameter. */ /**/ @@ -1775,6 +1813,9 @@ static struct pardef partab[] = { { "disfunctions", 0, getpmdisfunction, scanpmdisfunctions, setpmdisfunctions, NULL, NULL, stdunsetfn, NULL }, + { "funcstack", PM_ARRAY|PM_SPECIAL|PM_READONLY, + NULL, NULL, NULL, + arrsetfn, funcstackgetfn, stdunsetfn, NULL }, { "builtins", PM_READONLY, getpmbuiltin, scanpmbuiltins, hashsetfn, NULL, NULL, stdunsetfn, NULL }, @@ -1829,6 +1870,10 @@ static struct pardef partab[] = { { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL } }; +static struct funcwrap wrapper[] = { + WRAPDEF(func_wrapper), +}; + /**/ int setup_parameter(Module m) @@ -1867,6 +1912,12 @@ boot_parameter(Module m) def->pm->unsetfn = def->unsetfn; } } + PERMALLOC { + funcstack = newlinklist(); + } LASTALLOC; + + addwrapper(m, wrapper); + return 0; } @@ -1888,6 +1939,9 @@ cleanup_parameter(Module m) unsetparam_pm(pm, 0, 1); } } + deletewrapper(m, wrapper); + freelinklist(funcstack, freestr); + return 0; } -- cgit 1.4.1