modules: remove support for module unload and refcount.

Module management is horrifically more complex than it needs to
be for the simple purpose of providing a means to implement new
builtins using C. Fussing about reference counting or needing to
maintain and test a facility to unload modules is an easy 600
lines to cut as a start at simplification.
* src/main.c (main): Don't call m4__module_exit to unload all
modules just prior to exiting the application.
* m4/m4private.h (FINISH_SYMBOL, m4_module:refcount)
(m4__module_exit, m4_module_refcount): Remove.
(m4__module_next): Rename from this...
* m4/m4module.h (m4_module_next): ...to this. Adjust all callers.
(M4FINISH_HANDLER, m4_module_finish_func, m4_module_makeresident)
(m4_module_refcount, m4_module_unload, m4_module_exit): Remove.
* m4/m4module.c (m4__module_next): Rename from this...
(m4_module_next): ...to this.
(module_remove, m4_module_makeresident, m4_module_unload)
(m4_module_exit, m4_module_refcount): Remove.
* modules/load.c: Remove.
(m4modules): Move from here...
* modules/gnu.c (m4modules): ...to here. Update all callers.
(M4FINISH_HANDLER(gnu)): Remove.
* modules/m4.c (M4INIT_HANDLER(m4)): Remove.
* modules/modtest.c (M4FINISH_HANDLER(modtest)): Remove.
* modules/shadow.c (M4INIT_HANDLER(shadow)): Rewrite to work
without refcount.
* Makefile.am (pkglib_LTLIBRARIES): Remove modules/load.la.
(modules_load_la_LDFLAGS, modules_load_la_LIBADD): Remove.
* tests/modules.at: Remove references to load module, and
tests of unload builtin.
* tests/options.at: Remove obsolute finish hook and module unload
trace output.
* doc/m4.texi (Unload, Refcount): Remove.
(M4modules): Change module reference from load to gnu.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
modules: allow only a single function access point.

Exporting non-function symbols barely works on Windows, so change
the module loading API to use a single function access point which
is then responsible for calling back to install symbols and macros.
* m4/m4module.h, m4/m4module.c (m4_install_builtins)
(m4_install_macros): New APIs for saving builtins and macros into
the module struct.
* m4/m4module.c (install_macro_table, install_builtin_table):
Adjust accordingly.
(m4__module_open): Simplify accordingly.
* m4/m4private.h (BUILTIN_SYMBOL, MACRO_SYMBOL): Remove.
* modules/gnu.c, modules/import.c, modules/m4.c, modules/modtest.c,
modules/mpeval.c, modules/shadow.c, modules/time.c,
modules/traditional.c (m4_builtin_table, m4_macro_table): Make
static, and remove LTX symbol mangling macros.
(M4INIT_HANDLER): Call m4_install_builtins and/or m4_install_macros.
* tests/options.at: Now that init_func is always called, adjust
expected debug output.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
modules: store module name in the module struct.

* m4/m4private.h (m4_module): Add name field.
* m4/module.c (m4__module_open): Save the name field.
* m4/path.c (m4_load_filename): Pass the raw filename to
m4_module_load.
* m4/module.c (m4_get_module_name): Replace all the ltdl
twiddling with returning the saved name field.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
modules: store loaded modules in context struct.

* m4/m4private.h (struct m4_module): Add a next pointer.
(struct m4): Add a module list pointer.
* m4/module.c (m4__module_open): Initialise the next pointer and
update the list head when a new module is successfully opened.
(m4_module_next): Replace the ugly libltdl twiddling with a
straight forward module list traversal one-liner!
Add a context parameter. Adjust all callers.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
modules: simplify module lookup by name.

* m4/m4private.h (m4:namemap): New field for hash table to lookup
module structures by name string.
* m4/m4.c (hashfn): Hash function for plain strings.
(m4_create): Initialise namemap field to a hash table using hashfn
for inserting and looking up keys.
* m4/module.c (m4__module_find): Replace the fussy libltdl
twiddling with a hash lookup in m4:namemap.
Add a new context parameter. Adjust all callers.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
modules: speed up multiple includes of the same module.

* m4/module.c (m4_module_load): If we already have the module
loaded, reuse that.  Otherwise, open the module afresh and
register it's builtins and macros on success.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>