Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

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@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author