52 |
* NULL on failure or else a libtool module handle for the newly mapped |
* NULL on failure or else a libtool module handle for the newly mapped |
53 |
* vm segment containing the module code. If the module is not already |
* vm segment containing the module code. If the module is not already |
54 |
* loaded, m4_module_load() retrieves its value for the symbol |
* loaded, m4_module_load() retrieves its value for the symbol |
55 |
* `m4_builtin_table', which is installed using m4_set_module_builtin_table(). |
* `m4_builtin_table', which is installed using set_module_builtin_table(). |
56 |
* |
* |
57 |
* In addition to builtin functions, you can also define static macro |
* In addition to builtin functions, you can also define static macro |
58 |
* expansions in the `m4_macro_table' symbol. If you define this symbol |
* expansions in the `m4_macro_table' symbol. If you define this symbol |
59 |
* in your modules, it should be an array of `m4_macro's, mapping macro |
* in your modules, it should be an array of `m4_macro's, mapping macro |
60 |
* names to the expansion text. Any macros defined in `m4_macro_table' |
* names to the expansion text. Any macros defined in `m4_macro_table' |
61 |
* are installed into the M4 symbol table with m4_set_module_macro_table(). |
* are installed into the M4 symbol table with set_module_macro_table(). |
62 |
* |
* |
63 |
* Each time a module is loaded, the module function prototyped as |
* Each time a module is loaded, the module function prototyped as |
64 |
* "M4INIT_HANDLER (<module name>)" is called, if defined. Any value |
* "M4INIT_HANDLER (<module name>)" is called, if defined. Any value |
90 |
static void module_close (m4 *context, lt_dlhandle handle, |
static void module_close (m4 *context, lt_dlhandle handle, |
91 |
struct obstack *obs); |
struct obstack *obs); |
92 |
|
|
93 |
|
static void m4_set_module_macro_table (m4*, lt_dlhandle, const m4_macro*); |
94 |
|
static void m4_set_module_builtin_table (m4*, lt_dlhandle, const m4_builtin*); |
95 |
|
|
96 |
static lt_dlcaller_id caller_id = 0; |
static lt_dlcaller_id caller_id = 0; |
97 |
|
|
98 |
const char * |
const char * |
119 |
return data ? data->builtin_table : 0; |
return data ? data->builtin_table : 0; |
120 |
} |
} |
121 |
|
|
122 |
void |
static void |
123 |
m4_set_module_builtin_table (m4 *context, lt_dlhandle handle, |
set_module_builtin_table (m4 *context, lt_dlhandle handle, |
124 |
const m4_builtin *table) |
const m4_builtin *table) |
125 |
{ |
{ |
126 |
const m4_builtin *bp; |
const m4_builtin *bp; |
127 |
|
|
128 |
|
assert (context); |
129 |
assert (handle); |
assert (handle); |
130 |
assert (table); |
assert (table); |
131 |
|
|
132 |
for (bp = table; bp->name != NULL; bp++) |
for (bp = table; bp->name != NULL; bp++) |
133 |
{ |
{ |
134 |
m4_symbol_value *token = XCALLOC (m4_symbol_value, 1); |
m4_symbol_value *value = m4_symbol_value_create (); |
135 |
char * name; |
char * name; |
136 |
|
|
137 |
VALUE_TYPE (token) = M4_SYMBOL_FUNC; |
m4_set_symbol_value_func (value, bp->func); |
138 |
VALUE_FUNC (token) = bp->func; |
VALUE_HANDLE (value) = handle; |
139 |
VALUE_HANDLE (token) = handle; |
VALUE_MIN_ARGS (value) = bp->min_args; |
140 |
VALUE_MIN_ARGS (token) = bp->min_args; |
VALUE_MAX_ARGS (value) = bp->max_args; |
|
VALUE_MAX_ARGS (token) = bp->max_args; |
|
141 |
|
|
142 |
if (bp->groks_macro_args) |
if (bp->groks_macro_args) |
143 |
BIT_SET (VALUE_FLAGS (token), VALUE_MACRO_ARGS_BIT); |
BIT_SET (VALUE_FLAGS (value), VALUE_MACRO_ARGS_BIT); |
144 |
if (bp->blind_if_no_args) |
if (bp->blind_if_no_args) |
145 |
BIT_SET (VALUE_FLAGS (token), VALUE_BLIND_ARGS_BIT); |
BIT_SET (VALUE_FLAGS (value), VALUE_BLIND_ARGS_BIT); |
146 |
|
|
147 |
if (prefix_all_builtins) |
if (prefix_all_builtins) |
148 |
{ |
{ |
156 |
name = (char *) bp->name; |
name = (char *) bp->name; |
157 |
|
|
158 |
|
|
159 |
m4_symbol_pushdef (M4SYMTAB, name, token); |
m4_symbol_pushdef (M4SYMTAB, name, value); |
160 |
|
|
161 |
if (prefix_all_builtins) |
if (prefix_all_builtins) |
162 |
xfree (name); |
xfree (name); |
175 |
return data ? data->macro_table : 0; |
return data ? data->macro_table : 0; |
176 |
} |
} |
177 |
|
|
178 |
void |
static void |
179 |
m4_set_module_macro_table (m4 *context, lt_dlhandle handle, |
set_module_macro_table (m4 *context, lt_dlhandle handle, |
180 |
const m4_macro *table) |
const m4_macro *table) |
181 |
{ |
{ |
182 |
const m4_macro *mp; |
const m4_macro *mp; |
183 |
|
|
184 |
|
assert (context); |
185 |
|
assert (handle); |
186 |
|
assert (table); |
187 |
|
|
188 |
for (mp = table; mp->name != NULL; mp++) |
for (mp = table; mp->name != NULL; mp++) |
189 |
{ |
{ |
190 |
m4_symbol_value *token = XCALLOC (m4_symbol_value, 1); |
m4_symbol_value *value = m4_symbol_value_create (); |
191 |
|
|
192 |
VALUE_TYPE (token) = M4_SYMBOL_TEXT; |
m4_set_symbol_value_text (value, xstrdup (mp->value)); |
193 |
VALUE_TEXT (token) = xstrdup (mp->value); |
VALUE_HANDLE (value) = handle; |
|
VALUE_HANDLE (token) = handle; |
|
194 |
|
|
195 |
m4_symbol_pushdef (M4SYMTAB, mp->name, token); |
m4_symbol_pushdef (M4SYMTAB, mp->name, value); |
196 |
} |
} |
197 |
} |
} |
198 |
|
|
219 |
} |
} |
220 |
else if (info->ref_count == 1) |
else if (info->ref_count == 1) |
221 |
{ |
{ |
222 |
const m4_builtin *builtin_table = m4_get_module_builtin_table (handle); |
const m4_builtin *builtin_table |
223 |
const m4_macro *macro_table = m4_get_module_macro_table (handle); |
= m4_get_module_builtin_table (handle); |
224 |
|
const m4_macro *macro_table |
225 |
|
= m4_get_module_macro_table (handle); |
226 |
|
|
227 |
/* Install the macro functions. */ |
/* Install the macro functions. */ |
228 |
if (builtin_table) |
if (builtin_table) |
229 |
{ |
{ |
230 |
m4_set_module_builtin_table (context, handle, builtin_table); |
set_module_builtin_table (context, handle, builtin_table); |
231 |
#ifdef DEBUG_MODULES |
#ifdef DEBUG_MODULES |
232 |
M4_DEBUG_MESSAGE1("module %s: builtins loaded", name); |
M4_DEBUG_MESSAGE1("module %s: builtins loaded", name); |
233 |
#endif /* DEBUG_MODULES */ |
#endif /* DEBUG_MODULES */ |
236 |
/* Install the user macros. */ |
/* Install the user macros. */ |
237 |
if (macro_table) |
if (macro_table) |
238 |
{ |
{ |
239 |
m4_set_module_macro_table (context, handle, macro_table); |
set_module_macro_table (context, handle, macro_table); |
240 |
#ifdef DEBUG_MODULES |
#ifdef DEBUG_MODULES |
241 |
M4_DEBUG_MESSAGE1("module %s: macros loaded", name); |
M4_DEBUG_MESSAGE1("module %s: macros loaded", name); |
242 |
#endif /* DEBUG_MODULES */ |
#endif /* DEBUG_MODULES */ |