maint: summarize highlights of 1.4.18 release
[m4/ericb.git] / m4 / m4private.h
bloba09ca9f83e75db080ada882569d960bb40a943ba
1 /* GNU m4 -- A simple macro processor
2 Copyright (C) 1989-1994, 1998-1999, 2004-2010, 2013-2014, 2017 Free
3 Software Foundation, 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 #ifndef M4PRIVATE_H
22 #define M4PRIVATE_H 1
24 #include <m4/m4module.h>
26 #include "cloexec.h"
27 #include "quotearg.h"
28 #include "xmemdup0.h"
30 typedef struct m4__search_path_info m4__search_path_info;
31 typedef struct m4__macro_arg_stacks m4__macro_arg_stacks;
32 typedef struct m4__symbol_chain m4__symbol_chain;
34 typedef enum {
35 M4_SYMBOL_VOID, /* Traced but undefined, u is invalid. */
36 M4_SYMBOL_TEXT, /* Plain text, u.u_t is valid. */
37 M4_SYMBOL_FUNC, /* Builtin function, u.func is valid. */
38 M4_SYMBOL_PLACEHOLDER, /* Placeholder for unknown builtin from -R. */
39 M4_SYMBOL_COMP /* Composite symbol, u.u_c.c is valid. */
40 } m4__symbol_type;
42 #define BIT_TEST(flags, bit) (((flags) & (bit)) == (bit))
43 #define BIT_SET(flags, bit) ((flags) |= (bit))
44 #define BIT_RESET(flags, bit) ((flags) &= ~(bit))
46 /* Gnulib's stdbool doesn't work with bool bitfields. For nicer
47 debugging, use bool when we know it works, but use the more
48 portable unsigned int elsewhere. */
49 #if __GNUC__ > 2
50 typedef bool bool_bitfield;
51 #else
52 typedef unsigned int bool_bitfield;
53 #endif /* !__GNUC__ */
56 /* --- CONTEXT MANAGEMENT --- */
58 struct m4 {
59 m4_symbol_table * symtab;
60 m4_syntax_table * syntax;
61 m4_module * modules;
62 m4_hash * namemap;
64 const char * current_file; /* Current input file. */
65 int current_line; /* Current input line. */
66 int output_line; /* Current output line. */
68 FILE * debug_file; /* File for debugging output. */
69 m4_obstack trace_messages;
70 int exit_status; /* Cumulative exit status. */
71 int current_diversion; /* Current output diversion. */
73 /* Option flags (set in src/main.c). */
74 size_t nesting_limit; /* -L */
75 int debug_level; /* -d */
76 size_t max_debug_arg_length; /* -l */
77 int regexp_syntax; /* -r */
78 int opt_flags;
80 /* __PRIVATE__: */
81 m4__search_path_info *search_path; /* The list of path directories. */
82 m4__macro_arg_stacks *arg_stacks; /* Array of current argv refs. */
83 size_t stacks_count; /* Size of arg_stacks. */
84 size_t expansion_level;/* Macro call nesting level. */
87 #define M4_OPT_PREFIX_BUILTINS_BIT (1 << 0) /* -P */
88 #define M4_OPT_SUPPRESS_WARN_BIT (1 << 1) /* -Q */
89 #define M4_OPT_DISCARD_COMMENTS_BIT (1 << 2) /* -c */
90 #define M4_OPT_INTERACTIVE_BIT (1 << 3) /* -e */
91 #define M4_OPT_SYNCOUTPUT_BIT (1 << 4) /* -s */
92 #define M4_OPT_POSIXLY_CORRECT_BIT (1 << 5) /* -G/POSIXLY_CORRECT */
93 #define M4_OPT_FATAL_WARN_BIT (1 << 6) /* -E once */
94 #define M4_OPT_WARN_EXIT_BIT (1 << 7) /* -E twice */
95 #define M4_OPT_SAFER_BIT (1 << 8) /* --safer */
97 /* Fast macro versions of accessor functions for public fields of m4,
98 that also have an identically named function exported in m4module.h. */
99 #ifdef NDEBUG
100 # define m4_get_symbol_table(C) ((C)->symtab)
101 # define m4_set_symbol_table(C, V) ((C)->symtab = (V))
102 # define m4_get_syntax_table(C) ((C)->syntax)
103 # define m4_set_syntax_table(C, V) ((C)->syntax = (V))
104 # define m4_get_current_file(C) ((C)->current_file)
105 # define m4_set_current_file(C, V) ((C)->current_file = (V))
106 # define m4_get_current_line(C) ((C)->current_line)
107 # define m4_set_current_line(C, V) ((C)->current_line = (V))
108 # define m4_get_output_line(C) ((C)->output_line)
109 # define m4_set_output_line(C, V) ((C)->output_line = (V))
110 # define m4_get_debug_file(C) ((C)->debug_file)
111 # define m4_set_debug_file(C, V) ((C)->debug_file = (V))
112 # define m4_get_trace_messages(C) ((C)->trace_messages)
113 # define m4_set_trace_messages(C, V) ((C)->trace_messages = (V))
114 # define m4_get_exit_status(C) ((C)->exit_status)
115 # define m4_set_exit_status(C, V) ((C)->exit_status = (V))
116 # define m4_get_current_diversion(C) ((C)->current_diversion)
117 # define m4_set_current_diversion(C, V) ((C)->current_diversion = (V))
118 # define m4_get_nesting_limit_opt(C) ((C)->nesting_limit)
119 # define m4_set_nesting_limit_opt(C, V) ((C)->nesting_limit = (V))
120 # define m4_get_debug_level_opt(C) ((C)->debug_level)
121 # define m4_set_debug_level_opt(C, V) ((C)->debug_level = (V))
122 # define m4_get_max_debug_arg_length_opt(C) ((C)->max_debug_arg_length)
123 # define m4_set_max_debug_arg_length_opt(C, V) ((C)->max_debug_arg_length=(V))
124 # define m4_get_regexp_syntax_opt(C) ((C)->regexp_syntax)
125 # define m4_set_regexp_syntax_opt(C, V) ((C)->regexp_syntax = (V))
127 # define m4_get_prefix_builtins_opt(C) \
128 (BIT_TEST((C)->opt_flags, M4_OPT_PREFIX_BUILTINS_BIT))
129 # define m4_get_suppress_warnings_opt(C) \
130 (BIT_TEST((C)->opt_flags, M4_OPT_SUPPRESS_WARN_BIT))
131 # define m4_get_discard_comments_opt(C) \
132 (BIT_TEST((C)->opt_flags, M4_OPT_DISCARD_COMMENTS_BIT))
133 # define m4_get_interactive_opt(C) \
134 (BIT_TEST((C)->opt_flags, M4_OPT_INTERACTIVE_BIT))
135 # define m4_get_syncoutput_opt(C) \
136 (BIT_TEST((C)->opt_flags, M4_OPT_SYNCOUTPUT_BIT))
137 # define m4_get_posixly_correct_opt(C) \
138 (BIT_TEST((C)->opt_flags, M4_OPT_POSIXLY_CORRECT_BIT))
139 # define m4_get_fatal_warnings_opt(C) \
140 (BIT_TEST((C)->opt_flags, M4_OPT_FATAL_WARN_BIT))
141 # define m4_get_warnings_exit_opt(C) \
142 (BIT_TEST((C)->opt_flags, M4_OPT_WARN_EXIT_BIT))
143 # define m4_get_safer_opt(C) \
144 (BIT_TEST((C)->opt_flags, M4_OPT_SAFER_BIT))
146 /* No fast opt bit set macros, as they would need to evaluate their
147 arguments more than once, which would subtly change their semantics. */
148 #endif
150 /* Accessors for private fields of m4, which have no function version
151 exported in m4module.h. */
152 #define m4__get_search_path(C) ((C)->search_path)
155 /* --- BUILTIN MANAGEMENT --- */
157 /* Internal representation of loaded builtins. */
158 struct m4__builtin
160 /* Copied from module's BUILTIN_SYMBOL table, although builtin.flags
161 can be used for additional bits beyond what is allowed for
162 modules. */
163 m4_builtin builtin;
164 m4_module *module; /* Module that owns this builtin. */
166 typedef struct m4__builtin m4__builtin;
168 extern void m4__set_symbol_value_builtin (m4_symbol_value *,
169 const m4__builtin *);
170 extern void m4__builtin_print (m4_obstack *, const m4__builtin *, bool,
171 m4__symbol_chain **, const m4_string_pair *,
172 bool);
175 /* --- MODULE MANAGEMENT --- */
177 /* Representation of a loaded m4 module. */
178 struct m4_module
180 const char *name; /* Name of the module. */
181 void *handle; /* System module handle. */
182 m4__builtin *builtins; /* Sorted array of builtins. */
183 m4_macro *macros; /* Unsorted array of macros. */
184 size_t builtins_len; /* Number of builtins. */
185 m4_module *next;
188 extern m4_module * m4__module_open (m4 *context, const char *name,
189 m4_obstack *obs);
190 extern m4_module * m4__module_find (m4 *context, const char *name);
193 /* --- SYMBOL TABLE MANAGEMENT --- */
195 struct m4_symbol
197 bool traced; /* True if this symbol is traced. */
198 m4_symbol_value *value; /* Linked list of pushdef'd values. */
201 /* Type of a link in a symbol chain. */
202 enum m4__symbol_chain_type
204 M4__CHAIN_STR, /* Link contains a string, u.u_s is valid. */
205 M4__CHAIN_FUNC, /* Link contains builtin token, u.builtin is valid. */
206 M4__CHAIN_ARGV, /* Link contains a $@ reference, u.u_a is valid. */
207 M4__CHAIN_LOC /* Link contains m4wrap location, u.u_l is valid. */
210 /* Composite symbols are built of a linked list of chain objects. */
211 struct m4__symbol_chain
213 m4__symbol_chain *next; /* Pointer to next link of chain. */
214 enum m4__symbol_chain_type type; /* Type of this link. */
215 unsigned int quote_age; /* Quote_age of this link, or 0. */
216 union
218 struct
220 const char *str; /* Pointer to text. */
221 size_t len; /* Remaining length of str. */
222 size_t level; /* Expansion level of content, or SIZE_MAX. */
223 } u_s; /* M4__CHAIN_STR. */
224 const m4__builtin *builtin; /* M4__CHAIN_FUNC. */
225 struct
227 m4_macro_args *argv; /* Reference to earlier $@. */
228 size_t index; /* Argument index within argv. */
229 bool_bitfield flatten : 1; /* True to treat builtins as text. */
230 bool_bitfield comma : 1; /* True when `,' is next input. */
231 bool_bitfield skip_last : 1; /* True if last argument omitted. */
232 bool_bitfield has_func : 1; /* True if argv includes func. */
233 const m4_string_pair *quotes; /* NULL for $*, quotes for $@. */
234 } u_a; /* M4__CHAIN_ARGV. */
235 struct
237 const char *file; /* File where subsequent links originate. */
238 int line; /* Line where subsequent links originate. */
239 } u_l; /* M4__CHAIN_LOC. */
240 } u;
243 /* A symbol value is used both for values associated with a macro
244 name, and for arguments to a macro invocation. */
245 struct m4_symbol_value
247 m4_symbol_value * next;
248 m4_module * module;
249 unsigned int flags;
251 m4_hash * arg_signature;
252 size_t min_args;
253 size_t max_args;
254 size_t pending_expansions;
256 m4__symbol_type type;
257 union
259 struct
261 size_t len; /* Length of string. */
262 const char * text; /* String contents. */
263 /* Quote age when this string was built, or zero to force a
264 rescan of the string. Ignored for 0 len. */
265 unsigned int quote_age;
266 } u_t; /* Valid when type is TEXT, PLACEHOLDER. */
267 const m4__builtin * builtin;/* Valid when type is FUNC. */
268 struct
270 m4__symbol_chain *chain; /* First link of the chain. */
271 m4__symbol_chain *end; /* Last link of the chain. */
272 bool_bitfield wrapper : 1; /* True if this is a $@ ref. */
273 bool_bitfield has_func : 1; /* True if chain includes func. */
274 } u_c; /* Valid when type is COMP. */
275 } u;
278 /* Structure describing all arguments to a macro, including the macro
279 name at index 0. */
280 struct m4_macro_args
282 /* One more than the highest actual argument. May be larger than
283 arraylen since the array can refer to multiple arguments via a
284 single $@ reference. */
285 size_t argc;
286 /* False unless the macro expansion refers to $@; determines whether
287 this object can be freed at end of macro expansion or must wait
288 until all references have been rescanned. */
289 bool_bitfield inuse : 1;
290 /* False if all arguments are just text or func, true if this argv
291 refers to another one. */
292 bool_bitfield wrapper : 1;
293 /* False if all arguments belong to this argv, true if some of them
294 include references to another. */
295 bool_bitfield has_ref : 1;
296 /* True to flatten builtins contained in references. */
297 bool_bitfield flatten : 1;
298 /* True if any token contains builtins. */
299 bool_bitfield has_func : 1;
300 /* The value of quote_age for all tokens, or 0 if quote_age changed
301 during parsing or any token is potentially unsafe and requires a
302 rescan. */
303 unsigned int quote_age;
304 /* The context of the macro call during expansion, and NULL in a
305 back-reference. */
306 m4_call_info *info;
307 size_t level; /* Which obstack owns this argv. */
308 size_t arraylen; /* True length of allocated elements in array. */
309 /* Used as a variable-length array, storing information about each
310 argument. */
311 m4_symbol_value *array[FLEXIBLE_ARRAY_MEMBER];
314 /* Internal structure for managing multiple argv references. See
315 macro.c for a much more detailed comment on usage. */
316 struct m4__macro_arg_stacks
318 size_t refcount; /* Number of active $@ references at this level. */
319 size_t argcount; /* Number of argv at this level. */
320 m4_obstack *args; /* Content of arguments. */
321 m4_obstack *argv; /* Argv pointers into args. */
322 void *args_base; /* Location for clearing the args obstack. */
323 void *argv_base; /* Location for clearing the argv obstack. */
326 /* Opaque structure for managing call context information. Contains
327 the context used in tracing and error messages that was valid at
328 the start of the macro expansion, even if argument collection
329 changes global context in the meantime. */
330 struct m4_call_info
332 const char *file; /* The file containing the macro invocation. */
333 int line; /* The line the macro was called on. */
334 size_t call_id; /* The unique sequence call id of the macro. */
335 int trace : 1; /* True to trace this macro. */
336 int debug_level : 31; /* The debug level for tracing the macro call. */
337 const char *name; /* The macro name. */
338 size_t name_len; /* The length of name. */
341 extern size_t m4__adjust_refcount (m4 *, size_t, bool);
342 extern bool m4__arg_adjust_refcount (m4 *, m4_macro_args *, bool);
343 extern void m4__push_arg_quote (m4 *, m4_obstack *, m4_macro_args *,
344 size_t, const m4_string_pair *);
345 extern bool m4__arg_print (m4 *, m4_obstack *, m4_macro_args *,
346 size_t, const m4_string_pair *, bool,
347 m4__symbol_chain **, const char *,
348 size_t *, bool, bool);
350 #define VALUE_NEXT(T) ((T)->next)
351 #define VALUE_MODULE(T) ((T)->module)
352 #define VALUE_FLAGS(T) ((T)->flags)
353 #define VALUE_ARG_SIGNATURE(T) ((T)->arg_signature)
354 #define VALUE_MIN_ARGS(T) ((T)->min_args)
355 #define VALUE_MAX_ARGS(T) ((T)->max_args)
356 #define VALUE_PENDING(T) ((T)->pending_expansions)
358 #define SYMBOL_NEXT(S) (VALUE_NEXT ((S)->value))
359 #define SYMBOL_MODULE(S) (VALUE_MODULE ((S)->value))
360 #define SYMBOL_FLAGS(S) (VALUE_FLAGS ((S)->value))
361 #define SYMBOL_ARG_SIGNATURE(S) (VALUE_ARG_SIGNATURE ((S)->value))
362 #define SYMBOL_MIN_ARGS(S) (VALUE_MIN_ARGS ((S)->value))
363 #define SYMBOL_MAX_ARGS(S) (VALUE_MAX_ARGS ((S)->value))
364 #define SYMBOL_PENDING(S) (VALUE_PENDING ((S)->value))
366 /* Fast macro versions of symbol table accessor functions,
367 that also have an identically named function exported in m4module.h. */
368 #ifdef NDEBUG
369 # define m4_get_symbol_traced(S) ((S)->traced)
370 # define m4_get_symbol_value(S) ((S)->value)
371 # define m4_set_symbol_value(S, V) ((S)->value = (V))
373 /* m4_symbol_value_{create,delete} are too complex for a simple macro. */
375 # define m4_is_symbol_value_text(V) ((V)->type == M4_SYMBOL_TEXT)
376 # define m4_is_symbol_value_func(V) ((V)->type == M4_SYMBOL_FUNC)
377 # define m4_is_symbol_value_void(V) ((V)->type == M4_SYMBOL_VOID)
378 # define m4_is_symbol_value_placeholder(V) \
379 ((V)->type == M4_SYMBOL_PLACEHOLDER)
380 # define m4_get_symbol_value_text(V) ((V)->u.u_t.text)
381 # define m4_get_symbol_value_len(V) ((V)->u.u_t.len)
382 # define m4_get_symbol_value_quote_age(V) ((V)->u.u_t.quote_age)
383 # define m4_get_symbol_value_func(V) ((V)->u.builtin->builtin.func)
384 # define m4_get_symbol_value_builtin(V) (&(V)->u.builtin->builtin)
385 # define m4_get_symbol_value_placeholder(V) \
386 ((V)->u.u_t.text)
387 # define m4_symbol_value_flatten_args(V) \
388 (BIT_TEST ((V)->flags, VALUE_FLATTEN_ARGS_BIT))
390 # define m4_set_symbol_value_text(V, T, L, A) \
391 ((V)->type = M4_SYMBOL_TEXT, (V)->u.u_t.text = (T), \
392 (V)->u.u_t.len = (L), (V)->u.u_t.quote_age = (A))
393 # define m4_set_symbol_value_placeholder(V, T) \
394 ((V)->type = M4_SYMBOL_PLACEHOLDER, (V)->u.u_t.text = (T))
395 # define m4__set_symbol_value_builtin(V, B) \
396 ((V)->type = M4_SYMBOL_FUNC, (V)->u.builtin = (B), \
397 VALUE_MODULE (V) = (B)->module, \
398 VALUE_FLAGS (V) = (B)->builtin.flags, \
399 VALUE_MIN_ARGS (V) = (B)->builtin.min_args, \
400 VALUE_MAX_ARGS (V) = (B)->builtin.max_args)
401 #endif
405 /* m4_symbol_value.flags bit masks. Be sure these are a consistent
406 superset of the M4_BUILTIN_* bit masks, so we can copy
407 m4_builtin.flags to m4_symbol_arg.flags. We can use additional
408 bits for private use. */
410 #define VALUE_FLATTEN_ARGS_BIT (1 << 0)
411 #define VALUE_BLIND_ARGS_BIT (1 << 1)
412 #define VALUE_SIDE_EFFECT_ARGS_BIT (1 << 2)
413 #define VALUE_DELETED_BIT (1 << 3)
416 struct m4_symbol_arg {
417 int index;
418 int flags;
419 char * default_val;
422 #define SYMBOL_ARG_INDEX(A) ((A)->index)
423 #define SYMBOL_ARG_FLAGS(A) ((A)->flags)
424 #define SYMBOL_ARG_DEFAULT(A) ((A)->default_val)
426 /* m4_symbol_arg.flags bit masks: */
428 #define SYMBOL_ARG_REST_BIT (1 << 0)
429 #define SYMBOL_ARG_KEY_BIT (1 << 1)
431 extern void m4__symtab_remove_module_references (m4_symbol_table *,
432 m4_module *);
433 extern bool m4__symbol_value_print (m4 *, m4_symbol_value *, m4_obstack *,
434 const m4_string_pair *, bool,
435 m4__symbol_chain **, size_t *, bool);
439 /* --- SYNTAX TABLE MANAGEMENT --- */
441 /* CHAR_RETRY must be last, because we size the syntax table to hold
442 all other characters and sentinels. */
443 #define CHAR_EOF (UCHAR_MAX + 1) /* Return on EOF. */
444 #define CHAR_BUILTIN (UCHAR_MAX + 2) /* Return for BUILTIN token. */
445 #define CHAR_QUOTE (UCHAR_MAX + 3) /* Return for quoted string. */
446 #define CHAR_ARGV (UCHAR_MAX + 4) /* Return for $@ reference. */
447 #define CHAR_RETRY (UCHAR_MAX + 5) /* Return for end of input block. */
449 #define DEF_LQUOTE "`" /* Default left quote delimiter. */
450 #define DEF_RQUOTE "\'" /* Default right quote delimiter. */
451 #define DEF_BCOMM "#" /* Default begin comment delimiter. */
452 #define DEF_ECOMM "\n" /* Default end comment delimiter. */
454 struct m4_syntax_table {
455 /* Please read the comment at the top of input.c for details. table
456 holds the current syntax, and orig holds the default syntax. */
457 unsigned short table[CHAR_RETRY];
458 unsigned short orig[CHAR_RETRY];
460 m4_string_pair quote; /* Quote delimiters. */
461 m4_string_pair comm; /* Comment delimiters. */
463 char dollar; /* Dollar character, if is_single_dollar. */
465 /* True iff only one start and end quote delimiter exist. */
466 bool_bitfield is_single_quotes : 1;
468 /* True iff only one start and end comment delimiter exist. */
469 bool_bitfield is_single_comments : 1;
471 /* True iff only one byte has M4_SYNTAX_DOLLAR. */
472 bool_bitfield is_single_dollar : 1;
474 /* True iff some character has M4_SYNTAX_ESCAPE. */
475 bool_bitfield is_macro_escaped : 1;
477 /* True iff a changesyntax call has impacted something that requires
478 cleanup at the end. */
479 bool_bitfield suspect : 1;
481 /* Track the number of changesyntax calls. This saturates at
482 0xffff, so the idea is that most users won't be changing the
483 syntax that frequently; perhaps in the future we will cache
484 frequently used syntax schemes by index. */
485 unsigned short syntax_age;
487 /* Track the current quote age, determined by all significant
488 changequote, changecom, and changesyntax calls, since any of
489 these can alter the rescan of a prior parameter in a quoted
490 context. */
491 unsigned int quote_age;
493 /* Track a cached quote pair on the input obstack. */
494 m4_string_pair *cached_quote;
496 /* Storage for a simple cached quote that can be recreated on the fly. */
497 char cached_lquote[2];
498 char cached_rquote[2];
499 m4_string_pair cached_simple;
502 /* Fast macro versions of syntax table accessor functions,
503 that also have an identically named function exported in m4module.h. */
504 #ifdef NDEBUG
505 # define m4_get_syntax_lquote(S) ((S)->quote.str1)
506 # define m4_get_syntax_rquote(S) ((S)->quote.str2)
507 # define m4_get_syntax_bcomm(S) ((S)->comm.str1)
508 # define m4_get_syntax_ecomm(S) ((S)->comm.str2)
509 # define m4_get_syntax_quotes(S) (&(S)->quote)
510 # define m4_get_syntax_comments(S) (&(S)->comm)
512 # define m4_is_syntax_single_quotes(S) ((S)->is_single_quotes)
513 # define m4_is_syntax_single_comments(S) ((S)->is_single_comments)
514 # define m4_is_syntax_single_dollar(S) ((S)->is_single_dollar)
515 # define m4_is_syntax_macro_escaped(S) ((S)->is_macro_escaped)
516 #endif
518 /* Return the current quote age. */
519 #define m4__quote_age(S) ((S)->quote_age)
521 /* Return true if the current quote age guarantees that parsing the
522 current token in the context of a quoted string of the same quote
523 age will give the same parse. */
524 #define m4__safe_quotes(S) (((S)->quote_age & 0xffff) != 0)
526 /* Set or refresh the cached quote. */
527 extern const m4_string_pair *m4__quote_cache (m4_syntax_table *,
528 m4_obstack *obs, unsigned int,
529 const m4_string_pair *);
531 /* Clear the cached quote. */
532 #define m4__quote_uncache(S) ((S)->cached_quote = NULL)
535 /* --- MACRO MANAGEMENT --- */
537 /* Various different token types. */
538 typedef enum {
539 M4_TOKEN_EOF, /* End of file, M4_SYMBOL_VOID. */
540 M4_TOKEN_NONE, /* Discardable token, M4_SYMBOL_VOID. */
541 M4_TOKEN_STRING, /* Quoted string, M4_SYMBOL_TEXT or M4_SYMBOL_COMP. */
542 M4_TOKEN_COMMENT, /* Comment, M4_SYMBOL_TEXT or M4_SYMBOL_COMP. */
543 M4_TOKEN_SPACE, /* Whitespace, M4_SYMBOL_TEXT. */
544 M4_TOKEN_WORD, /* An identifier, M4_SYMBOL_TEXT. */
545 M4_TOKEN_OPEN, /* Argument list start, M4_SYMBOL_TEXT. */
546 M4_TOKEN_COMMA, /* Argument separator, M4_SYMBOL_TEXT. */
547 M4_TOKEN_CLOSE, /* Argument list end, M4_SYMBOL_TEXT. */
548 M4_TOKEN_SIMPLE, /* Single character, M4_SYMBOL_TEXT. */
549 M4_TOKEN_MACDEF, /* Builtin token, M4_SYMBOL_FUNC or M4_SYMBOL_COMP. */
550 M4_TOKEN_ARGV /* A series of parameters, M4_SYMBOL_COMP. */
551 } m4__token_type;
553 extern void m4__make_text_link (m4_obstack *, m4__symbol_chain **,
554 m4__symbol_chain **);
555 extern void m4__append_builtin (m4_obstack *, const m4__builtin *,
556 m4__symbol_chain **,
557 m4__symbol_chain **);
558 extern bool m4__push_symbol (m4 *, m4_symbol_value *, size_t,
559 bool);
560 extern m4_obstack *m4__push_wrapup_init (m4 *, const m4_call_info *,
561 m4__symbol_chain ***);
562 extern void m4__push_wrapup_finish (void);
563 extern m4__token_type m4__next_token (m4 *, m4_symbol_value *, int *,
564 m4_obstack *, bool,
565 const m4_call_info *);
566 extern bool m4__next_token_is_open (m4 *);
568 /* Fast macro versions of macro argv accessor functions,
569 that also have an identically named function exported in m4module.h. */
570 #ifdef NDEBUG
571 # define m4_arg_argc(A) (A)->argc
572 # define m4_arg_info(A) (A)->info
573 # define m4_arg_scratch(C) \
574 ((C)->arg_stacks[(C)->expansion_level - 1].argv)
575 #endif /* NDEBUG */
578 /* --- PATH MANAGEMENT --- */
580 typedef struct m4__search_path m4__search_path;
582 struct m4__search_path {
583 m4__search_path *next; /* next directory to search */
584 const char *dir; /* directory */
585 int len;
588 struct m4__search_path_info {
589 m4__search_path *list; /* the list of path directories */
590 m4__search_path *list_end; /* the end of same */
591 int max_length; /* length of longest directory name */
594 extern void m4__include_init (m4 *);
597 /* Debugging the memory allocator. */
599 #if WITH_DMALLOC
600 # define DMALLOC_FUNC_CHECK
601 # include <dmalloc.h>
602 #endif /* WITH_DMALLOC */
606 /* Convenience macro to zero a variable after freeing it, as well as
607 casting away any const. */
608 #define DELETE(Expr) ((Expr) = (free ((void *) (Expr)), (void *) 0))
610 /* Avoid negative logic when comparing two strings. */
611 #define STREQ(a, b) (strcmp (a, b) == 0)
612 #define STRNEQ(a, b) (strcmp (a, b) != 0)
615 #if DEBUG
616 # define DEBUG_INCL 1
617 # define DEBUG_INPUT 1
618 # define DEBUG_MACRO 1
619 # define DEBUG_MODULES 1
620 # define DEBUG_OUTPUT 1
621 # define DEBUG_STKOVF 1
622 # define DEBUG_SYM 1
623 # define DEBUG_SYNTAX 1
624 #endif
626 #endif /* m4private.h */