From b0c5f09169ac31855ebf0e93772bb57b9635b380 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 28 May 2007 22:57:39 +0000 Subject: see 23479: add initial features support for modules --- Src/Zle/compctl.c | 28 ++++++++++-- Src/Zle/complete.c | 33 ++++++++++---- Src/Zle/complist.c | 27 ++++++++++- Src/Zle/computil.c | 28 ++++++++++-- Src/Zle/deltochar.c | 29 +++++++++++- Src/Zle/zle_main.c | 27 +++++++++-- Src/Zle/zle_thingy.c | 2 +- Src/Zle/zle_tricky.c | 2 +- Src/Zle/zleparameter.c | 118 ++++++++++++------------------------------------- 9 files changed, 182 insertions(+), 112 deletions(-) (limited to 'Src/Zle') diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c index 81f11b423..bafbb2f68 100644 --- a/Src/Zle/compctl.c +++ b/Src/Zle/compctl.c @@ -3942,6 +3942,14 @@ static struct builtin bintab[] = { BUILTIN("compcall", 0, bin_compcall, 0, 0, 0, "TD", NULL), }; +static struct features module_features = { + bintab, sizeof(bintab)/sizeof(*bintab), + NULL, 0, + NULL, 0, + NULL, 0, + 0 +}; + /**/ int setup_(UNUSED(Module m)) @@ -3962,13 +3970,28 @@ setup_(UNUSED(Module m)) return 0; } +/**/ +int +features_(Module m, char ***features) +{ + *features = featuresarray(m->nam, &module_features); + return 0; +} + +/**/ +int +enables_(Module m, int **enables) +{ + return handlefeatures(m->nam, &module_features, enables); +} + /**/ int boot_(Module m) { addhookfunc("compctl_make", (Hookfn) ccmakehookfn); addhookfunc("compctl_cleanup", (Hookfn) cccleanuphookfn); - return (addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)) != 1); + return 0; } /**/ @@ -3977,8 +4000,7 @@ cleanup_(Module m) { deletehookfunc("compctl_make", (Hookfn) ccmakehookfn); deletehookfunc("compctl_cleanup", (Hookfn) cccleanuphookfn); - deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); - return 0; + return setfeatureenables(m->nam, &module_features, NULL); } /**/ diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c index a73d3cf14..aac760a92 100644 --- a/Src/Zle/complete.c +++ b/Src/Zle/complete.c @@ -1467,6 +1467,14 @@ struct hookdef comphooks[] = { HOOKDEF("comp_list_matches", ilistmatches, 0), }; +static struct features module_features = { + bintab, sizeof(bintab)/sizeof(*bintab), + cotab, sizeof(cotab)/sizeof(*cotab), + NULL, 0, + NULL, 0, + 0 +}; + /**/ int setup_(UNUSED(Module m)) @@ -1490,6 +1498,21 @@ setup_(UNUSED(Module m)) return 0; } +/**/ +int +features_(Module m, char ***features) +{ + *features = featuresarray(m->nam, &module_features); + return 0; +} + +/**/ +int +enables_(Module m, int **enables) +{ + return handlefeatures(m->nam, &module_features, enables); +} + /**/ int boot_(Module m) @@ -1502,11 +1525,7 @@ boot_(Module m) addhookfunc("list_matches", (Hookfn) list_matches); addhookfunc("invalidate_list", (Hookfn) invalidate_list); addhookdefs(m->nam, comphooks, sizeof(comphooks)/sizeof(*comphooks)); - if (!(addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)) | - addconddefs(m->nam, cotab, sizeof(cotab)/sizeof(*cotab)) | - !addwrapper(m, wrapper))) - return 1; - return 0; + return addwrapper(m, wrapper); } /**/ @@ -1521,10 +1540,8 @@ cleanup_(Module m) deletehookfunc("list_matches", (Hookfn) list_matches); deletehookfunc("invalidate_list", (Hookfn) invalidate_list); deletehookdefs(m->nam, comphooks, sizeof(comphooks)/sizeof(*comphooks)); - deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); - deleteconddefs(m->nam, cotab, sizeof(cotab)/sizeof(*cotab)); deletewrapper(m, wrapper); - return 0; + return seteatureenables(m->nam, &module_features, NULL); } /**/ diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c index cedccc254..787b7b25c 100644 --- a/Src/Zle/complist.c +++ b/Src/Zle/complist.c @@ -3219,6 +3219,14 @@ menuselect(char **args) return 0; } +static struct features module_features = { + NULL, 0, + NULL, 0, + NULL, 0, + NULL, 0, + 0 +}; + /**/ int setup_(UNUSED(Module m)) @@ -3226,6 +3234,21 @@ setup_(UNUSED(Module m)) return 0; } +/**/ +int +features_(Module m, char ***features) +{ + *features = featuresarray(m->nam, &module_features); + return 0; +} + +/**/ +int +enables_(Module m, int **enables) +{ + return handlefeatures(m->nam, &module_features, enables); +} + /**/ int boot_(Module m) @@ -3269,7 +3292,7 @@ boot_(Module m) /**/ int -cleanup_(UNUSED(Module m)) +cleanup_(Module m) { free(mtab); free(mgtab); @@ -3279,7 +3302,7 @@ cleanup_(UNUSED(Module m)) deletehookfunc("menu_start", (Hookfn) domenuselect); unlinkkeymap("menuselect", 1); unlinkkeymap("listscroll", 1); - return 0; + return setfeatureenables(m->nam, &module_features, NULL); } /**/ diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index dbbaa61e2..0d8cf5364 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -4567,6 +4567,14 @@ static struct builtin bintab[] = { BUILTIN("compgroups", 0, bin_compgroups, 1, -1, 0, NULL, NULL), }; +static struct features module_features = { + bintab, sizeof(bintab)/sizeof(*bintab), + NULL, 0, + NULL, 0, + NULL, 0, + 0 +}; + /**/ int @@ -4582,19 +4590,33 @@ setup_(UNUSED(Module m)) return 0; } +/**/ +int +features_(Module m, char ***features) +{ + *features = featuresarray(m->nam, &module_features); + return 0; +} + +/**/ +int +enables_(Module m, int **enables) +{ + return handlefeatures(m->nam, &module_features, enables); +} + /**/ int boot_(Module m) { - return !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); + return 0; } /**/ int cleanup_(Module m) { - deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); - return 0; + return setfeatureenables(m->nam, &module_features, NULL); } /**/ diff --git a/Src/Zle/deltochar.c b/Src/Zle/deltochar.c index e7bfabfd3..0c64cf18d 100644 --- a/Src/Zle/deltochar.c +++ b/Src/Zle/deltochar.c @@ -74,6 +74,16 @@ deltochar(UNUSED(char **args)) return !ok; } + +static struct features module_features = { + NULL, 0, + NULL, 0, + NULL, 0, + NULL, 0, + 0 +}; + + /**/ int setup_(UNUSED(Module m)) @@ -81,6 +91,21 @@ setup_(UNUSED(Module m)) return 0; } +/**/ +int +features_(Module m, char ***features) +{ + *features = featuresarray(m->nam, &module_features); + return 0; +} + +/**/ +int +enables_(Module m, int **enables) +{ + return handlefeatures(m->nam, &module_features, enables); +} + /**/ int boot_(Module m) @@ -100,11 +125,11 @@ boot_(Module m) /**/ int -cleanup_(UNUSED(Module m)) +cleanup_(Module m) { deletezlefunction(w_deletetochar); deletezlefunction(w_zaptochar); - return 0; + return setfeatureenables(m->nam, &module_features, NULL); } /**/ diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 9f71f692b..8ab10e5de 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -1777,6 +1777,14 @@ mod_export struct hookdef zlehooks[] = { HOOKDEF("invalidate_list", NULL, 0), }; +static struct features module_features = { + bintab, sizeof(bintab)/sizeof(*bintab), + NULL, 0, + NULL, 0, + NULL, 0, + 0 +}; + /**/ int setup_(UNUSED(Module m)) @@ -1815,13 +1823,27 @@ setup_(UNUSED(Module m)) return 0; } +/**/ +int +features_(Module m, char ***features) +{ + *features = featuresarray(m->nam, &module_features); + return 0; +} + +/**/ +int +enables_(Module m, int **enables) +{ + return handlefeatures(m->nam, &module_features, enables); +} + /**/ int boot_(Module m) { addhookfunc("before_trap", (Hookfn) zlebeforetrap); addhookfunc("after_trap", (Hookfn) zleaftertrap); - addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); addhookdefs(m->nam, zlehooks, sizeof(zlehooks)/sizeof(*zlehooks)); return 0; } @@ -1836,9 +1858,8 @@ cleanup_(Module m) } deletehookfunc("before_trap", (Hookfn) zlebeforetrap); deletehookfunc("after_trap", (Hookfn) zleaftertrap); - deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); deletehookdefs(m->nam, zlehooks, sizeof(zlehooks)/sizeof(*zlehooks)); - return 0; + return setfeatureenables(m->nam, &module_features, NULL); } /**/ diff --git a/Src/Zle/zle_thingy.c b/Src/Zle/zle_thingy.c index debd31a28..42e32f142 100644 --- a/Src/Zle/zle_thingy.c +++ b/Src/Zle/zle_thingy.c @@ -590,7 +590,7 @@ bin_zle_complete(char *name, char **args, UNUSED(Options ops), UNUSED(char func) Thingy t; Widget w, cw; - if (!require_module(name, "zsh/complete", 0, 0)) { + if (require_module(name, "zsh/complete", NULL) == 1) { zwarnnam(name, "can't load complete module"); return 1; } diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index 6aaf53e80..2b8e17c22 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -612,7 +612,7 @@ docomplete(int lst) * no completion widgets are defined. */ if (!module_loaded("zsh/compctl") && !hascompwidgets) - load_module("zsh/compctl"); + (void)load_module("zsh/compctl", NULL); if (runhookdef(BEFORECOMPLETEHOOK, (void *) &lst)) { active = 0; diff --git a/Src/Zle/zleparameter.c b/Src/Zle/zleparameter.c index 3c7f1474f..1b84fdff7 100644 --- a/Src/Zle/zleparameter.c +++ b/Src/Zle/zleparameter.c @@ -30,45 +30,6 @@ #include "zleparameter.mdh" #include "zleparameter.pro" -/* Empty dummy function for special hash parameters. */ - -/**/ -static void -shempty(void) -{ -} - -/* Create a simple special hash parameter. */ - -/**/ -static Param -createspecialhash(char *name, GetNodeFunc get, ScanTabFunc scan) -{ - Param pm; - HashTable ht; - - if (!(pm = createparam(name, PM_SPECIAL|PM_HIDE|PM_REMOVABLE|PM_HASHED))) - return NULL; - - pm->level = pm->old ? locallevel : 0; - pm->gsu.h = &stdhash_gsu; - pm->u.hash = ht = newhashtable(0, name, NULL); - - ht->hash = hasher; - ht->emptytable = (TableFunc) shempty; - ht->filltable = NULL; - ht->addnode = (AddNodeFunc) shempty; - ht->getnode = ht->getnode2 = get; - ht->removenode = (RemoveNodeFunc) shempty; - ht->disablenode = NULL; - ht->enablenode = NULL; - ht->freenode = (FreeNodeFunc) shempty; - ht->printnode = printparamnode; - ht->scantab = scan; - - return pm; -} - /* Functions for the zlewidgets special parameter. */ /**/ @@ -157,18 +118,6 @@ keymapsgetfn(UNUSED(Param pm)) return ret; } -/* Table for defined parameters. */ - -struct pardef { - char *name; - int flags; - GetNodeFunc getnfn; - ScanTabFunc scantfn; - GsuHash hash_gsu; - GsuArray array_gsu; - Param pm; -}; - /* * This is a duplicate of stdhash_gsu. On some systems * (such as Cygwin) we can't put a pointer to an imported variable @@ -179,14 +128,18 @@ static const struct gsu_hash zlestdhash_gsu = static const struct gsu_array keymaps_gsu = { keymapsgetfn, arrsetfn, stdunsetfn }; -static struct pardef partab[] = { - { "widgets", PM_READONLY, - getpmwidgets, scanpmwidgets, &zlestdhash_gsu, - NULL, NULL }, - { "keymaps", PM_ARRAY|PM_SPECIAL|PM_READONLY, - NULL, NULL, NULL, - &keymaps_gsu, NULL }, - { NULL, 0, NULL, NULL, NULL, NULL, NULL } +static struct paramdef partab[] = { + SPECIALPMDEF("widgets", PM_READONLY, + &zlestdhash_gsu, getpmwidgets, scanpmwidgets), + SPECIALPMDEF("keymaps", PM_ARRAY|PM_READONLY, &keymaps_gsu, NULL, NULL), +}; + +static struct features module_features = { + NULL, 0, + NULL, 0, + partab, sizeof(partab)/sizeof(*partab), + NULL, 0, + 0 }; /**/ @@ -198,46 +151,33 @@ setup_(UNUSED(Module m)) /**/ int -boot_(UNUSED(Module m)) +features_(Module m, char ***features) { - struct pardef *def; - - for (def = partab; def->name; def++) { - unsetparam(def->name); - - if (def->getnfn) { - if (!(def->pm = createspecialhash(def->name, def->getnfn, - def->scantfn))) - return 1; - def->pm->node.flags |= def->flags; - if (def->hash_gsu) - def->pm->gsu.h = def->hash_gsu; - } else { - if (!(def->pm = createparam(def->name, def->flags | PM_HIDE))) - return 1; - def->pm->gsu.a = def->array_gsu; - } - } + *features = featuresarray(m->nam, &module_features); return 0; } /**/ int -cleanup_(UNUSED(Module m)) +enables_(Module m, int **enables) +{ + return handlefeatures(m->nam, &module_features, enables); +} + +/**/ +int +boot_(UNUSED(Module m)) { - Param pm; - struct pardef *def; - - for (def = partab; def->name; def++) { - if ((pm = (Param) paramtab->getnode(paramtab, def->name)) && - pm == def->pm) { - pm->node.flags &= ~PM_READONLY; - unsetparam_pm(pm, 0, 1); - } - } return 0; } +/**/ +int +cleanup_(Module m) +{ + return setfeatureenables(m->nam, &module_features, NULL); +} + /**/ int finish_(UNUSED(Module m)) -- cgit 1.4.1