refactor: remove dead M4MODPATH code.
[m4/ericb.git] / modules / load.c
blob0b0eb1beb680214430674b0a462ae4a8ede63aaf
1 /* GNU m4 -- A simple macro processor
2 Copyright (C) 2000, 2005-2008, 2010, 2013 Free Software Foundation,
3 Inc.
5 This file is part of GNU M4.
7 GNU M4 is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU M4 is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <config.h>
23 /* This module needs private symbols, and may not compile correctly if
24 m4private.h isn't included. */
25 #include "m4private.h"
28 /* Rename exported symbols for dlpreload()ing. */
29 #define m4_builtin_table load_LTX_m4_builtin_table
30 #define m4_macro_table load_LTX_m4_macro_table
33 /* Maintain each of the builtins implemented in this modules along
34 with their details in a single table for easy maintenance.
36 function macros blind side minargs maxargs */
37 #define builtin_functions \
38 BUILTIN (m4modules, false, false, false, 0, 0 ) \
39 BUILTIN (refcount, false, true, false, 1, 1 ) \
40 BUILTIN (unload, false, true, false, 1, 1 ) \
43 /* Generate prototypes for each builtin handler function. */
44 #define BUILTIN(handler, macros, blind, side, min, max) M4BUILTIN (handler)
45 builtin_functions
46 #undef BUILTIN
49 /* Generate a table for mapping m4 symbol names to handler functions. */
50 const m4_builtin m4_builtin_table[] =
52 #define BUILTIN(handler, macros, blind, side, min, max) \
53 M4BUILTIN_ENTRY (handler, #handler, macros, blind, side, min, max)
55 builtin_functions
56 #undef BUILTIN
58 { NULL, NULL, 0, 0, 0 },
62 /* A table for mapping m4 symbol names to simple expansion text. */
63 const m4_macro m4_macro_table[] =
65 /* name text min max */
66 { "__load__", "", 0, 0 },
67 { NULL, NULL, 0, 0 },
71 /* This module cannot be safely unloaded from memory, incase the unload
72 is triggered by the unload builtin, and the module is removed while
73 unload is in progress. */
74 M4INIT_HANDLER (load)
76 const char *err = m4_module_makeresident (module);
77 if (err)
78 m4_error (context, 0, 0, NULL, _("cannot make module `%s' resident: %s"),
79 m4_get_module_name (module), err);
84 /* Loading an external module at runtime.
85 The following functions provide the implementation for each
86 of the m4 builtins declared in `m4_builtin_table[]' above. */
88 /**
89 * m4modules()
90 **/
91 M4BUILTIN_HANDLER (m4modules)
93 /* The expansion of this builtin is a comma separated list of
94 loaded modules. */
95 m4_module *module = m4__module_next (NULL);
97 if (module)
100 m4_shipout_string (context, obs, m4_get_module_name (module), SIZE_MAX,
101 true);
103 if ((module = m4__module_next (module)))
104 obstack_1grow (obs, ',');
106 while (module);
110 * refcount(module)
112 M4BUILTIN_HANDLER (refcount)
114 m4_module *module = m4__module_find (M4ARG (1));
115 m4_shipout_int (obs, module ? m4_module_refcount (module) : 0);
119 * unload(MODULE-NAME)
121 M4BUILTIN_HANDLER (unload)
123 /* Remove all builtins and macros installed by the named module,
124 and then unload the module from memory entirely. */
125 m4_module_unload (context, M4ARG(1), obs);