From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22216 invoked from network); 2 Nov 1999 09:05:32 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 2 Nov 1999 09:05:32 -0000 Received: (qmail 9872 invoked by alias); 2 Nov 1999 09:05:15 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8480 Received: (qmail 9861 invoked from network); 2 Nov 1999 09:05:05 -0000 Date: Tue, 2 Nov 1999 10:04:56 +0100 (MET) Message-Id: <199911020904.KAA30028@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk Subject: PATCH: funcstack parameter I'm currently playing with the grouping/priority stuff for completion and I think for that it might be nice/useful to have a way to get at the names of the function currently being executed. So this add the `funcstack' parameter to the parameter module which is an array containing these names. Maybe it's useful in other places, too. Bye Sven diff -u -r oldsrc/Modules/parameter.c Src/Modules/parameter.c --- oldsrc/Modules/parameter.c Mon Nov 1 20:43:22 1999 +++ Src/Modules/parameter.c Mon Nov 1 21:06:03 1999 @@ -555,6 +555,44 @@ 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 @@ { "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 @@ { 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 @@ def->pm->unsetfn = def->unsetfn; } } + PERMALLOC { + funcstack = newlinklist(); + } LASTALLOC; + + addwrapper(m, wrapper); + return 0; } @@ -1888,6 +1939,9 @@ unsetparam_pm(pm, 0, 1); } } + deletewrapper(m, wrapper); + freelinklist(funcstack, freestr); + return 0; } diff -u -r oldsrc/Modules/parameter.mdd Src/Modules/parameter.mdd --- oldsrc/Modules/parameter.mdd Mon Nov 1 20:43:22 1999 +++ Src/Modules/parameter.mdd Mon Nov 1 21:10:00 1999 @@ -1,3 +1,3 @@ -autoparams="parameters commands functions disfunctions builtins disbuiltins reswords disreswords options modules dirstack history historywords jobtexts jobstates nameddirs userdirs raliases disraliases galiases disgaliases" +autoparams="parameters commands functions disfunctions funcstack builtins disbuiltins reswords disreswords options modules dirstack history historywords jobtexts jobstates nameddirs userdirs raliases disraliases galiases disgaliases" objects="parameter.o" diff -u olddoc/Zsh/mod_parameter.yo Doc/Zsh/mod_parameter.yo --- olddoc/Zsh/mod_parameter.yo Fri Oct 29 21:18:25 1999 +++ Doc/Zsh/mod_parameter.yo Mon Nov 1 21:13:50 1999 @@ -137,4 +137,10 @@ This association maps user names to the pathnames of their home directories. ) +vindex(funcstack) +item(tt(funcstack))( +This array contains the names of the functions currently being +executed. The first element is the name of the function using the +parameter. +) enditem() --- oldcompletion/Core/compinit Fri Oct 29 21:15:45 1999 +++ Completion/Core/compinit Mon Nov 1 21:11:08 1999 @@ -113,6 +113,10 @@ comppostfuncs=() +# Loading it now ensures that the `funcstack' parameter is always correct. + +zmodload -i parameter + # This function is used to register or delete completion functions. For # registering completion functions, it is invoked with the name of the # function as it's first argument (after the options). The other -- Sven Wischnowsky wischnow@informatik.hu-berlin.de