about summary refs log tree commit diff
path: root/Src/module.c
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-04-25 15:43:41 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-04-25 15:43:41 +0000
commit206237c8ec4b7619d9e70a75004cd1ae1066b0a0 (patch)
treeff703cbc295605f90755edb68672ed2de11f4a81 /Src/module.c
parent8ceb54fbc2f879e0e80f58c18761bd54db07e5f7 (diff)
downloadzsh-206237c8ec4b7619d9e70a75004cd1ae1066b0a0.tar.gz
zsh-206237c8ec4b7619d9e70a75004cd1ae1066b0a0.tar.xz
zsh-206237c8ec4b7619d9e70a75004cd1ae1066b0a0.zip
Diffstat (limited to 'Src/module.c')
-rw-r--r--Src/module.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/Src/module.c b/Src/module.c
index 1117571a4..ff386c630 100644
--- a/Src/module.c
+++ b/Src/module.c
@@ -30,6 +30,12 @@
 #include "zsh.mdh"
 #include "module.pro"
 
+/* List of builtin modules. */
+
+/**/
+LinkList bltinmodules;
+
+
 /* The `zsh' module contains all the base code that can't actually be built *
  * as a separate module.  It is initialised by main(), so there's nothing   *
  * for the boot function to do.                                             */
@@ -48,6 +54,17 @@ boot_zsh(Module m)
     return 0;
 }
 
+/* This registers a builtin module.                                   */
+
+/**/
+void
+register_module(char *n)
+{
+    PERMALLOC {
+	addlinknode(bltinmodules, n);
+    } LASTALLOC;
+}
+
 /* addbuiltin() can be used to add a new builtin.  It returns zero on *
  * success, 1 on failure.  The only possible type of failure is that  *
  * a builtin with the specified name already exists.  An autoloaded   *
@@ -573,29 +590,34 @@ load_module(char const *name)
  * about trying to load a module with a full path name in restricted mode.
  * The last argument should be non-zero if this function should signal an
  * error if the module is already loaded.
- * The return value is the module of NULL if the module couldn't be loaded. */
+ * The return value is non-zero if the module was found or loaded. */
 
 /**/
-Module
+int
 require_module(char *nam, char *module, int res, int test)
 {
     Module m = NULL;
     LinkNode node;
 
+    /* First see if the module is linked in. */
+    for (node = firstnode(bltinmodules); node; incnode(node)) {
+	if (!strcmp((char *) getdata(node), nam))
+	    return 1;
+    }
     node = find_module(module);
     if (node && (m = ((Module) getdata(node)))->handle &&
 	!(m->flags & MOD_UNLOAD)) {
 	if (test) {
 	    zwarnnam(nam, "module %s already loaded.", module, 0);
-	    return NULL;
+	    return 0;
 	}
     } else if (res && isset(RESTRICTED) && strchr(module, '/')) {
 	zwarnnam(nam, "%s: restricted", module, 0);
-	return NULL;
+	return 0;
     } else
-	return load_module(module);
+	return !!load_module(module);
 
-    return m;
+    return 1;
 }
 
 /**/