1 /* GNU m4 -- A simple macro processor
2 Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 2001, 2004, 2006,
3 2007, 2008 Free 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/>.
23 #include "m4private.h"
25 #define DEFAULT_NESTING_LIMIT 1024
31 m4
*context
= (m4
*) xzalloc (sizeof *context
);
33 context
->symtab
= m4_symtab_create (0);
34 context
->syntax
= m4_syntax_create ();
36 context
->debug_file
= stderr
;
37 obstack_init (&context
->trace_messages
);
39 context
->nesting_limit
= DEFAULT_NESTING_LIMIT
;
40 context
->debug_level
= M4_DEBUG_TRACE_INITIAL
;
41 context
->max_debug_arg_length
= SIZE_MAX
;
43 context
->search_path
=
44 (m4__search_path_info
*) xzalloc (sizeof *context
->search_path
);
45 m4__include_init (context
);
51 m4_delete (m4
*context
)
57 m4_symtab_delete (context
->symtab
);
60 m4_syntax_delete (context
->syntax
);
62 /* debug_file should have been reset to stdout or stderr, both of
63 which are closed later. */
64 assert (context
->debug_file
== stderr
|| context
->debug_file
== stdout
);
66 obstack_free (&context
->trace_messages
, NULL
);
68 if (context
->search_path
)
70 m4__search_path
*path
= context
->search_path
->list
;
74 m4__search_path
*stale
= path
;
77 free ((void*) stale
->dir
);
80 free (context
->search_path
);
83 for (i
= 0; i
< context
->stacks_count
; i
++)
85 assert (context
->arg_stacks
[i
].refcount
== 0
86 && context
->arg_stacks
[i
].argcount
== 0);
87 if (context
->arg_stacks
[i
].args
)
89 obstack_free (context
->arg_stacks
[i
].args
, NULL
);
90 free (context
->arg_stacks
[i
].args
);
91 obstack_free (context
->arg_stacks
[i
].argv
, NULL
);
92 free (context
->arg_stacks
[i
].argv
);
95 free (context
->arg_stacks
);
102 /* Use the preprocessor to generate the repetitive bit twiddling functions
103 for us. Note the additional paretheses around the expanded function
104 name to protect against macro expansion from the fast macros used to
105 replace these functions when NDEBUG is defined. */
106 #define M4FIELD(type, base, field) \
107 type (CONC(m4_get_, base)) (m4 *context) \
110 return context->field; \
112 m4_context_field_table
115 #define M4FIELD(type, base, field) \
116 type (CONC(m4_set_, base)) (m4 *context, type value) \
119 return context->field = value; \
121 m4_context_field_table
124 #define M4OPT_BIT(bit, base) \
125 bool (CONC(m4_get_, base)) (m4 *context) \
128 return BIT_TEST (context->opt_flags, (bit)); \
130 m4_context_opt_bit_table
133 #define M4OPT_BIT(bit, base) \
134 bool (CONC(m4_set_, base)) (m4 *context, bool value) \
138 BIT_SET (context->opt_flags, (bit)); \
140 BIT_RESET (context->opt_flags, (bit)); \
143 m4_context_opt_bit_table