about summary refs log tree commit diff
path: root/Src/Modules/terminfo.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2007-05-28 22:57:39 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2007-05-28 22:57:39 +0000
commitb0c5f09169ac31855ebf0e93772bb57b9635b380 (patch)
tree410c43a9843b2c88166c2cb9acd531eaa36d036d /Src/Modules/terminfo.c
parentbd7632079045b1b6d0dee498c40833b409cf757e (diff)
downloadzsh-b0c5f09169ac31855ebf0e93772bb57b9635b380.tar.gz
zsh-b0c5f09169ac31855ebf0e93772bb57b9635b380.tar.xz
zsh-b0c5f09169ac31855ebf0e93772bb57b9635b380.zip
see 23479: add initial features support for modules
Diffstat (limited to 'Src/Modules/terminfo.c')
-rw-r--r--Src/Modules/terminfo.c112
1 files changed, 39 insertions, 73 deletions
diff --git a/Src/Modules/terminfo.c b/Src/Modules/terminfo.c
index b4a1c599b..d324c3a6c 100644
--- a/Src/Modules/terminfo.c
+++ b/Src/Modules/terminfo.c
@@ -37,7 +37,6 @@
 #endif
 
 #include "terminfo.pro"
-static char terminfo_nam[] = "terminfo";
 
 /**/
 #ifdef USE_TERMINFO_MODULE
@@ -55,8 +54,6 @@ static char terminfo_nam[] = "terminfo";
 #  include <term.h>
 # endif
 
-static Param terminfo_pm;
-
 /* echoti: output a terminfo capability */
 
 /**/
@@ -126,64 +123,11 @@ bin_echoti(char *name, char **argv, UNUSED(Options ops), UNUSED(int func))
     return 0;
 }
 
-/**/
-#else /* !USE_TERMINFO_MODULE */
-
-#define bin_echoti bin_notavail
-
-/**/
-#endif /* !USE_TERMINFO_MODULE */
-
 static struct builtin bintab[] = {
     BUILTIN("echoti", 0, bin_echoti, 1, -1, 0, NULL, NULL),
 };
 
 /**/
-#ifdef USE_TERMINFO_MODULE
-
-/* Empty dummy function for special hash parameters. */
-
-/**/
-static void
-shempty(void)
-{
-}
-
-/* Create a simple special hash parameter. */
-
-/**/
-static Param
-createtihash()
-{
-    Param pm;
-    HashTable ht;
-
-    unsetparam(terminfo_nam);
-
-    if (!(pm = createparam(terminfo_nam, PM_SPECIAL|PM_HIDE|PM_HIDEVAL|
-			   PM_REMOVABLE|PM_HASHED)))
-	return NULL;
-
-    pm->level = pm->old ? locallevel : 0;
-    pm->gsu.h = &stdhash_gsu;
-    pm->u.hash = ht = newhashtable(7, terminfo_nam, NULL);
-
-    ht->hash        = hasher;
-    ht->emptytable  = (TableFunc) shempty;
-    ht->filltable   = NULL;
-    ht->addnode     = (AddNodeFunc) shempty;
-    ht->getnode     = ht->getnode2 = getterminfo;
-    ht->removenode  = (RemoveNodeFunc) shempty;
-    ht->disablenode = NULL;
-    ht->enablenode  = NULL;
-    ht->freenode    = (FreeNodeFunc) shempty;
-    ht->printnode   = printparamnode;
-    ht->scantab     = scanterminfo;
-
-    return (terminfo_pm = pm);
-}
-
-/**/
 static HashNode
 getterminfo(UNUSED(HashTable ht), char *name)
 {
@@ -339,9 +283,30 @@ scanterminfo(UNUSED(HashTable ht), ScanFunc func, int flags)
     }
 }
 
+static struct paramdef partab[] = {
+    SPECIALPMDEF("terminfo", PM_READONLY, NULL,
+		 getterminfo, scanterminfo)
+};
+
 /**/
 #endif /* USE_TERMINFO_MODULE */
 
+static struct features module_features = {
+#ifdef USE_TERMINFO_MODULE
+    bintab, sizeof(bintab)/sizeof(*bintab),
+#else
+    NULL, 0,
+#endif
+    NULL, 0,
+#ifdef USE_TERMINFO_MODULE
+    partab, sizeof(partab)/sizeof(*partab),
+#else
+    NULL, 0,
+#endif
+    NULL, 0,
+    0
+};
+
 /**/
 int
 setup_(UNUSED(Module m))
@@ -351,6 +316,21 @@ setup_(UNUSED(Module m))
 
 /**/
 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)
 {
 #ifdef USE_TERMINFO_MODULE
@@ -360,30 +340,16 @@ boot_(Module m)
     if (setupterm((char *)0, 1, &errret) == ERR)
 	return 1;
 # endif
-
-    if (!createtihash())
-    	return 1;
-#else
-    unsetparam(terminfo_nam);
 #endif
-    return  !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
+
+    return 0;
 }
 
 /**/
 int
 cleanup_(Module m)
 {
-#ifdef USE_TERMINFO_MODULE
-    Param pm;
-
-    if ((pm = (Param) paramtab->getnode(paramtab, terminfo_nam)) &&
-	pm == terminfo_pm) {
-	pm->node.flags &= ~PM_READONLY;
-	unsetparam_pm(pm, 0, 1);
-    }
-#endif
-    deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
-    return 0;
+    return setfeatureenables(m->nam, &module_features, NULL);
 }
 
 /**/