26 Commits

Author SHA1 Message Date
Eric Blake
9123df1a73 Consistently use size_t for number of arguments.
* m4/m4module.h (m4_builtin_func): Alter prototype.
(struct m4_builtin): Adjust type of min_args, max_args.
(M4BUILTIN, M4BUILTIN_HANDLER): Adjust all builtins.
(m4_bad_argc, m4_dump_args, m4_macro_call, m4_arg_argc)
(m4_arg_symbol, m4_is_arg_text, m4_is_arg_func, m4_arg_text)
(m4_arg_equal, m4_arg_empty, m4_arg_len, m4_arg_func)
(m4_arg_print, m4_push_arg): Adjust all clients.
* m4/m4private.h (struct m4__symbol_chain, m4_symbol_value)
(m4_macro_args): Adjust type of various fields.
(m4__push_arg_quote): Adjust all clients.
* m4/input.c (m4_pop_wrapup): Likewise.
* m4/macro.c (m4_macro_call, trace_pre, make_argv_ref)
(arg_symbol, m4_arg_symbol, m4_is_arg_text, m4_is_arg_func)
(m4_arg_text, m4_arg_equal, m4_arg_empty, m4_arg_len)
(m4_arg_func, m4_arg_print, m4_make_argv_ref, m4_push_arg)
(m4__push_arg_quote, m4_push_args, m4_arg_argc): Likewise.
* m4/utility.c (m4_bad_argc, m4_dump_args): Likewise.
* modules/evalparse.c (m4_evaluate): Likewise.
* modules/gnu.c (changesyntax): Likewise.
* modules/m4.c (m4_dump_symbols, undefine, popdef, ifelse, defn)
(undivert, traceon, traceoff): Likewise.
* modules/m4.h (m4_dump_symbols_func): Likewise.
* modules/perl.c (perleval): Likewise.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-02-02 14:55:08 -07:00
Eric Blake
6128996ce3 Stage 4: route indir, builtin through ref; make argv opaque.
* m4/system_.h (obstack_regrow): Fix precedence.
* m4/m4module.h (m4_arg_equal, m4_arg_empty, m4_make_argv_ref):
New prototypes.
(struct m4_macro_args): Move...
* m4/m4private.h (struct m4_macro_args): ...here, making it opaque
to modules.  Add has_ref member.
(bool_bitfield): New helper typedef.
(struct m4_symbol_chain): Add flatten and len members.
* m4/macro.c (empty_symbol): New placeholder, for optimizing
comparison with empty string.
(m4_macro_expand_input): Initialize it.
(collect_arguments): Alter signature, and populate new fields.
(trace_pre, trace_post): Remove redundant parameter.
(expand_macro): Alter handling of obstacks.
(m4_arg_symbol): Account for wrapped argv.
(m4_arg_equal, m4_arg_empty, m4_make_argv_ref): New methods.
(m4_arg_text, m4_arg_len, m4_arg_func): Use new methods.
* modules/m4.c (ifelse, syscmd): Likewise.
* modules/evalparse.c (m4_evaluate): Likewise.
(undefine, popdef, m4_dump_symbols): Optimize.
* modules/gnu.c (builtin, indir, esyscmd, debugfile): Use new
methods.
(changesyntax, regexp): Optimize.
* m4/output.c (diversion_storage): Use typedef.

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-11-29 22:01:26 -07:00
Eric Blake
5d2ce0f461 Stage 2: use accessors, not direct reference, into argv.
* m4/m4private.h (m4_arg_argc): New fast accessor.
* m4/m4module.h (m4_arg_argc, m4_arg_symbol, m4_is_arg_text)
(m4_is_arg_func, m4_arg_text, m4_arg_len, m4_arg_func): New
prototypes.
(m4_builtin_func, M4BUILTIN, M4BUILTIN_HANDLER, m4_dump_args)
(m4_macro_call): Make argc unsigned.
(M4ARG): Use new accessors.
* modules/m4.c (define, pushdef): Likewise.
(undefine, popdef, ifelse, m4_dump_symbols, defn, undivert)
(traceon, traceoff): Make argc unsigned.
* modules/m4.h (m4_dump_symbols_func): Likewise.
* modules/evalparse.c (m4_evaluate): Likewise.
* modules/gnu.c (builtin, indir): Use new accessors.
(changesyntax): Make argc unsigned.
* modules/perl.c (perleval): Likewise.
* m4/utility.c (m4_dump_args): Use new accessors.
* m4/macro.c (trace_pre): Likewise.
(m4_arg_symbol, m4_arg_argc, m4_is_arg_text, m4_is_arg_func)
(m4_arg_text, m4_arg_len, m4_arg_func): New functions.
(expand_macro, trace_pre, trace_post, m4_macro_call): Update argc
usage.

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-11-27 19:10:43 -07:00
Eric Blake
14b2ffbb82 Stage 1: convert m4_symbol_value** into new object.
* ltdl/m4/gnulib-cache.m4: Import flexmember module.
* m4/m4module.h (m4_macro_args): New type, will be opaque to
modules later.
(m4_builtin_func, M4BUILTIN, M4BUILTIN_HANDLER, m4_dump_args)
(m4_macro_call): Alter signature to use m4_macro_args object.
(M4ARG): Redefine to access new struct.
* m4/m4private.h (M4_SYMBOL_COMP): New enumerator.
(struct m4_symbol_chain): New type.
(struct m4_symbol_value): Add chain alternative.
* m4/macro.c (collect_arguments): Build new struct.
(expand_macro, m4_macro_call, process_macro, trace_pre)
(trace_post): Adjust implementation to use it.
* m4/utility.c (m4_dump_args): Likewise.
* modules/gnu.c (builtin, indir): Likewise.
* modules/format.c (format): Likewise.
* modules/m4.h (m4_dump_symbols_func): Likewise.
* modules/m4.c (m4_dump_symbols, define, pushdef, defn, ifelse)
(shift, include, errprint, m4wrap): Likewise.
* modules/evalparse.c (m4_evaluate): Likewise.

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-11-24 16:23:47 -07:00
Eric Blake
32ab6f9f81 Pass only macro name to utility functions.
* m4/m4module.h (m4_bad_argc, m4_numeric_arg): Adjust signature.
* m4/utility.c (m4_bad_argc, m4_numeric_arg): Adjust
implementation.
* m4/macro.c (m4_macro_call): Adjust callers.
* modules/gnu.c (builtin, debuglen): Likewise.
* modules/m4.c (ifelse, incr, decr, divert, undivert, m4exit)
(substr): Likewise.
* modules/evalparse.c (m4_evaluate): Likewise.
* modules/stdlib.c (setenv, getpwuid, srand): Likewise.
* modules/time.c (ctime, gmtime, localtime, mktime, strftime):
Likewise.

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-11-24 07:04:18 -07:00
Eric Blake
f6e28cf9c7 Factor out handling of macro name in error messages.
* m4/m4module.h (m4_error, m4_error_at_line, m4_warn)
(m4_warn_at_line): Add new parameter.
* m4/utility.c (m4_verror_at_line): New helper method.
(m4_error, m4_error_at_line, m4_warn, m4_warn_at_line): Add new
parameter.
(m4_bad_argc, m4_numeric_arg, m4_parse_truth_arg): All callers
changed.
* m4/debug.c: Likewise.
* m4/input.c: Likewise.
* m4/macro.c: Likewise.
* m4/module.c: Likewise.
* m4/output.c: Likewise.
* m4/path.c: Likewise.
* modules/evalparse.c: Likewise.
* modules/format.c: Likewise.
* modules/gnu.c: Likewise.
* modules/load.c: Likewise.
* modules/m4.c: Likewise.
* modules/mpeval.c: Likewise.
* src/freeze.c: Likewise.
* src/main.c: Likewise.

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-11-23 15:18:40 -07:00
Eric Blake
5ced71a68d Normalize all GPL license notices.
* m4/COPYING.LIB: Delete - libm4 is not distributed under LGPLv2
at this time.
* Makefile.am: Update license wording.
* bootstrap: Likewise.
* commit: Likewise.
* configure.ac: Likewise.
* ltdl/config/mailnotify: Likewise.
* ltdl/config/mkstamp: Likewise.
* ltdl/m4/debug.m4: Likewise.
* ltdl/m4/gmp.m4: Likewise.
* ltdl/m4/m4-error.m4: Likewise.
* ltdl/m4/m4-getopt.m4: Likewise.
* ltdl/m4/m4-gettext.m4: Likewise.
* ltdl/m4/m4-obstack.m4: Likewise.
* ltdl/m4/m4-regex.m4: Likewise.
* ltdl/m4/stackovf.m4: Likewise.
* m4/builtin.c: Likewise.
* m4/debug.c: Likewise.
* m4/hash.c: Likewise.
* m4/hash.h: Likewise.
* m4/input.c: Likewise.
* m4/m4.c: Likewise.
* m4/m4module.h: Likewise.
* m4/m4private.h: Likewise.
* m4/macro.c: Likewise.
* m4/module.c: Likewise.
* m4/output.c: Likewise.
* m4/path.c: Likewise.
* m4/resyntax.c: Likewise.
* m4/symtab.c: Likewise.
* m4/syntax.c: Likewise.
* m4/system_.h: Likewise.
* m4/utility.c: Likewise.
* modules/evalp
2007-10-06 07:08:43 -06:00
Eric Blake
4755abc0ee Upgrade to GPLv3, and document 1.4.10.
* bootstrap: Adjust to GPLv3.
(func_update): Port from branch.
* ltdl/m4/gnulib-cache.m4: Augment with 'gnulib-tool
--local-dir=local --import gpl-3.0'.
* doc/m4.texinfo (History): Mention 1.4.11.
(Copying This Package): New appendix.
* NEWS: Document 1.4.10.
* local/doc/gpl-3.0.texi.diff: New file.
* Makefile.am: Update license.
(doc_m4_TEXINFOS, EXTRA_DIST): Distribute additions.
* commit: Update license.
* configure.ac: Likewise.
* ltdl/config/mailnotify: Likewise.
* ltdl/config/mkstamp: Likewise.
* ltdl/m4/debug.m4: Likewise.
* ltdl/m4/gmp.m4: Likewise.
* ltdl/m4/m4-error.m4: Likewise.
* ltdl/m4/m4-getopt.m4: Likewise.
* ltdl/m4/m4-gettext.m4: Likewise.
* ltdl/m4/m4-obstack.m4: Likewise.
* ltdl/m4/m4-regex.m4: Likewise.
* ltdl/m4/stackovf.m4: Likewise.
* m4/builtin.c: Likewise.
* m4/debug.c: Likewise.
* m4/hash.c: Likewise.
* m4/hash.h: Likewise.
* m4/input.c: Likewise.
* m4/m4.c: Likewise.
* m4/m4module.h: Likewise.
* m4/m4private.
2007-10-06 07:08:39 -06:00
Gary V. Vaughan
1722215a83 M4 was designed to have a small number of header files defining
the interfaces to several source files each.  Keeping this in
mind allows us to tidy things up considerably.  Having done this,
it becomes clear that some of the installed headers reference
other headers which are not installed (but that's another patch):

* m4/m4private.h (stdio--.h, stdlib--.h, unistd--.h): Moved from
here...
* m4/system_.h (gnu/stdio--.h, gnu/stdlib--.h, gnu/unistd--.h):
...to here, so client modules can benefit too.
(assert.h, errno.h, limits.h, sys/stat.h): Include one here at the
lowest level to save doing it multiple times elsewhere.
* m4/debug.c (stdio.h): Removed.  The portable <gnu/stdio--.h>
is already included via m4private.h.
* modules/time.c (stdio.h): Ditto.
* modules/gnu.c (stdlib.h): Ditto resp <gnu/stdlib--.h>.
* modules/stdlib.c (stdlib.h, unistd.h): Ditto resp <gnu/stdlib--.h>
and <gnu/unistd--.h>,
* m4/m4private.h (m4module.h): Use angle brackets for an installed
file.
* m4/hash.h (system.h): Ditto.
* modules/gnu.c (progname.h): Removed.
* src/freeze.c (m4/system.h, m4private.h): Already included vi m4.h.
* m4/m4private.h (assert.h, errno.h): Already included via
m4/m4module.h.
* m4/input.c (ctype.h): Ditto.
* m4/module.c (ltdl.h): Ditto.
* m4/output.c (errno.h, limits.h, stdio.h, sys/types.h, sys/stat.h)
(unistd.h): Ditto.
* m4/path.c (config.h, stdlib.h): Ditto.
* m4/utility.c (config.h): Ditto.
* modules/evalparse.c (assert.h, ctype.h): Ditto.
* modules/gnu.c (assert.h, ctype.h, errno.h): Ditto.
* modules/import.c (assert.h): Ditto.
* modules/m4.c (assert.h, errno.h): Ditto.
* modules/modtest.c (assert.h): Ditto.
* modules/stdlib.c (sys/types.h): DittAo.
* src/m4.h (ctype.h, errno.h, string.h, sys/types.h, ltdl.h):
Ditto.
* src/stackovf.c (assert.h): Ditto.
* modules/gnu.c (m4/m4module.h, m4private.h): Build using the faster
private interfaces when NDEBUG is defined.
* modules/import.c (m4/m4module.h, m4private.h): Ditto.
* modules/load.c (m4/m4module.h, m4private.h): Ditto.
* modules/m4.c (m4/m4module.h, m4private.h): Ditto.
* modules/modtest.c (m4/m4module.h, m4private.h): Ditto.
* modules/mpeval.c (m4/m4module.h, m4private.h): Ditto.
* modules/perl.c (m4/m4module.h, m4private.h): Ditto.
* modules/shadow.c (m4/m4module.h, m4private.h): Ditto.
* modules/time.c (m4/m4module.h, m4private.h): Ditto.
* modules/traditional.c (m4/m4module.h, m4private.h): Ditto.
* src/m4.h (locale.h): Moved from here...
* src/main.h: ...to here.
(m4private.h): Already included via m4.h.
* src/stackovf.c (m4private.h): Ditto.
2007-10-06 07:08:19 -06:00
Eric Blake
37cb2a3e79 POSIX XCU ERN 137 was approved.
* modules/mpeval.c (numb_extension): Delete.
* modules/m4.c (numb_extension): Likewise.
* modules/evalparse.c (comma_term, condition_term): Always
implement ?: and , operators.
* m4/symtab.c: Update comment to match reality.
* src/freeze.c (produce_frozen_state, reload_frozen_state): Avoid
dereferencing context directly when accessor exists.
* src/main.c (usage): Prefer GNU_M4 over EMACS.
(struct macro_definition): Rename...
(struct deferred): ...to match usage.  All uses changed.
* doc/m4.texinfo (Eval): Document this change.
(Operation modes, Changeresyntax): Fix wording to prefer GNU_M4
over emacs.
(Preprocessor features, Changesyntax): Fix inaccuracies.
* NEWS: Import branch NEWS items for 1.4.x series.  Document
change in eval.
2007-10-06 07:08:10 -06:00
Eric Blake
99a8d4311e * m4/m4private.h (to_uchar): Move...
* m4/m4module.h: here, so modules can use it.
* src/main.c (usage, long_options): Support --posix as a synonym
for --traditional.
* modules/m4.c (numb_invert): Detect unsupported x**-y.
(numb_incr, numb_urshift, numb_extension): New macros.
(numb_obstack): Port patch from branch to support radix 1 output.
* modules/mpeval.c (numb_obstack): Use  for ratios.
(numb_incr, numb_urshift, numb_extension): New macros.
(mpq2mpz): Warn rather than error.
* modules/evalparse.c (URSHIFT, NEGATIVE_EXPONENT): New
enumerators.
(eval_error): Rearrange, so that all ignorable errors are less
than SYNTAX_ERROR.
(eval_text, last_text): Obey C++ type safety rules.
(numb_pow): Change return type.
(exp_term): Adjust caller.
(m4_evaluate): Fail on bad exponent.
(logical_or_term, logical_and_term): Ignore failed ** in short
circuit.
(eval_lex): Fix typos when detecting <<= and >>=.  Use  instead
of : for ratio.  Support >>>, ,, and ?:.  Port patch from branch
to
2007-10-06 07:07:50 -06:00
Eric Blake
b259fc5dd9 * doc/m4.texinfo (Format, Incr): More merges.
(Eval): Ensure C precedence rules are met.
* modules/evalparse.c (BADOP, INVALID_OPERATOR): New enumerators.
(not_term, logical_not_term): Delete; these are same precedence
as other unary operators.
(equality_term): New; these are lower precedence than relational
operators.
(eval_lex, simple_term, m4_evaluate): Recognize forbidden C
operators for better error messages.
(logical_or_term, logical_and_term): Short-circuit out the error
of division by zero.
(unary_term): Allow consecutive unary operators.
* modules/m4.c (int2numb, numb2int): Delete; these potentially
truncate bits.
(numb_not, numb_eor, numb_ior, numb_and): Update callers.
* modules/mpeval.c (reduce1, reduce2): Protect macros better.
* NEWS: Document this change.
2007-10-06 07:07:48 -06:00
Eric Blake
c38df922f5 * bootstrap: Recent gnulib no longer has jm_* macros to worry
about.
* ltdl/m4/gnulib-cache.m4: Augment with gnulib-tool --import
verror.
* m4/m4module.h (M4ERROR, M4WARN): Delete, replaced by...
(m4_error, m4_warn): ... these new prototypes.
(m4_current_file, m4_current_line): Move into context, rather
than leaving as globals.
(m4_insert_file, m4_insert_diversion, m4_freeze_diversions)
(m4_undivert_all, m4_input_init): Now takes context.
* m4/utility.c (m4_error, m4_warn): New functions.
* m4/m4private.h: Assume errno exists.
(struct m4): Move warning_status to a bit flag,
and add exit_status.  Adjust accessors accordingly.
* src/main.c (print_program_name_CB): No longer needed.
(main): Use new m4_get_fatal_warnings_opt.
* m4/debug.c: Adjust all callers of M4WARN and M4ERROR, and abort
instead of issuing "INTERNAL ERROR".  Pass context when needed,
and use new accessors.
* m4/input.c: Likewise.
* m4/macro.c: Likewise.
* m4/output.c: Likewise.
* m4/utility.c: Likewise.
* mod
2007-10-06 06:52:51 -06:00
Eric Blake
a0d7f42329 Reduce compiler warnings. Inside GMP, mpq_t is an array type, so
const mpq_t is not assignable from plain mpq_t.  Avoid
type-punning warnings caused trying to mix these types.
* modules/mpeval.c (numb_ior, numb_eor, numb_and, numb_lshift),
(numb_rshift, numb_divide, numb_modulo): Remove const qualifier.
* modules/evalparse.c (or_term, xor_term, and_term, shift_term),
(mult_term, exp_term): Remove type-punning casts.
(numb_pow): Remove const qualifier.
* src/freeze.c (reload_frozen_state): Fix typo in messages.
Fix variables that can be used uninitialized, which fixes
security hole where malicious frozen file can execute arbitrary
code.
2007-10-06 06:51:11 -06:00
Gary V. Vaughan
e46a681a9f The FSF are moving offices today. Changed their contact address
in all files from `59 Temple Place, Suite 330, MA 02111-1307' to
`51 Franklin Street, Fifth Floor, MA 02110-1301'.
2007-10-05 22:01:03 -06:00
Gary V. Vaughan
f2d311322e * config/debug.m4: perl -pi.bak -e 's/(Copyright) (d)/$1 (C) $2/g'
* config/gmp.m4: Ditto.
* config/gnu-obstack.m4: Ditto.
* config/stackovf.m4: Ditto.
* m4/builtin.c: Ditto.
* m4/debug.c: Ditto.
* m4/error.c: Ditto.
* m4/error.h: Ditto.
* m4/gnu-obstack.h: Ditto.
* m4/hash.c: Ditto.
* m4/hash.h: Ditto.
* m4/input.c: Ditto.
* m4/m4.c: Ditto.
* m4/m4module.h: Ditto.
* m4/m4private.h: Ditto.
* m4/macro.c: Ditto.
* m4/module.c: Ditto.
* m4/obstack.c: Ditto.
* m4/output.c: Ditto.
* m4/path.c: Ditto.
* m4/regex.c: Ditto.
* m4/regex.h: Ditto.
* m4/strtol.c: Ditto.
* m4/symtab.c: Ditto.
* m4/syntax.c: Ditto.
* m4/utility.c: Ditto.
* m4/xmalloc.c: Ditto.
* m4/xstrdup.c: Ditto.
* m4/xstrzdup.c: Ditto.
* modules/evalparse.c: Ditto.
* modules/format.c: Ditto.
* modules/gnu.c: Ditto.
* modules/import.c: Ditto.
* modules/load.c: Ditto.
* modules/m4.c: Ditto.
* modules/m4.h: Ditto.
* modules/modtest.c: Ditto.
* modules/mpeval.c: Ditto.
* modules/perl.c: Ditto.
* modules/shadow.c: Ditto.
2007-10-05 22:00:20 -06:00
Gary V. Vaughan
f7530f7df0 * m4/m4module.h: Reformatting and rearranging lines a bit.
(m4_obstack): Save typing by typedefing `struct obstack'.  Changed
all users.
(m4_call_macro, m4_expand_input): Renamed...
(m4_macro_call, m4_macro_expand_input): ...to these.  Changed all
callers.
(m4_expansion_level, m4_process_macro): Moved...
* m4/macro.c (expansion_level, process_macro): ...to here, and
made static.
2007-10-05 22:00:10 -06:00
Gary V. Vaughan
5ebfef1256 Two related changes, and a huge knockon effect throughout the
source: Moved the option variables out of global space and into
`struct m4'; made `m4_symtab' a real datatype, so that it's api
is not marred passing `struct m4' around just so it can decide
whether to keep traced symbol names or not.  Added setters and
getters for the formerly global option variables, and obviously
changed a vast number of functions to take a `struct m4' and use
the getter funcs to find option values.

* m4/utility.c (interactive, sync_output, debug_level)
(no_gnu_extensions, prefix_all_builtins, suppress_warnings)
(max_debug_argument_length, warning_status, nesting_limit)
(discard_comments): Removed.
* m4/m4module (warning_status, no_gnu_extensions, nesting_limit)
(debug_level, max_debug_argument_length, prefix_all_builtins)
(suppress_warnings, discard_comments, interactive, sync_output):
Removed from here...
* m4/m4private.h (struct m4): ...and equivalent fields added to
this structure.
(m4_get_warning_status_opt, m4_get_no_gnu_extensions_opt)
(m4_get_nesting_limit_opt, m4_get_debug_level_opt)
(m4_get_max_debug_arg_length_opt, m4_get_prefix_builtins_opt)
(m4_get_suppress_warnings_opt, m4_get_discard_comments_opt)
(m4_get_interactive_opt, m4_get_sync_output_opt): Fast access
macros for the new fields.
* m4/m4module.h (m4_context_field_table)
(m4_context_opt_bit_table): Helper macros used to generate
prototypes, setters and getters for new option fields
consistently.
* m4/m4.c (m4_get_warning_status_opt, m4_get_no_gnu_extensions_opt)
(m4_get_nesting_limit_opt, m4_get_debug_level_opt)
(m4_get_max_debug_arg_length_opt, m4_get_prefix_builtins_opt)
(m4_get_suppress_warnings_opt, m4_get_discard_comments_opt)
(m4_get_interactive_opt, m4_get_sync_output_opt)
(m4_set_warning_status_opt, m4_set_no_gnu_extensions_opt)
(m4_set_nesting_limit_opt, m4_set_debug_level_opt)
(m4_set_max_debug_arg_length_opt, m4_set_prefix_builtins_opt)
(m4_set_suppress_warnings_opt, m4_set_discard_comments_opt)
(m4_set_interactive_opt, m4_set_sync_output_opt): Addressable
setter and getter functions generated by cpp from
m4_context_field_table and m4_context_opt_bit_table, exported as
part of the module api.  Changed all callers.
* m4/symtab (struct m4_symtab): Used as the concrete type for
m4_symtab now.
(m4_symtab_create): Allocate and initialise a new struct.
(m4_symtab_apply): New function that works like m4_hash_apply, but
with different callbacks specific to symbol tables.  Changed all
callers.
(symbol_destroy, arg_destroy, arg_copy): Renamed
symbol_destroy_CB, arg_destroy_CB, arg_copy_CB to remind me that
they have unused parameters for a reason!
(dump_symbol_CB): New callback to dump the contents of a single
symbol.
(symtob_dump): Rewritten in terms of dump_symbol_CB.
* m4/utility.c (m4_dump_symbol): Renamed to m4_dump_symbol_CB.
Changed all callers.
* m4/m4.c (m4_create): By default point the `nuke_trace_bit' field
of the contained `m4_symtab' at the `no_gnu_extensions' field.
Although I'm not convinced these semantics are correct, they are
at least consistent with how things were before this delta.  Also
set the default nesting limit to M4_DEFAULT_NESTING_LIMIT.
2007-10-05 21:58:39 -06:00
Gary V. Vaughan
8a709ff826 Renamed some of the types and their accessors to make more sense.
Now we have a SYMTAB in which we store SYMBOLs, and each SYMBOL
has a stack of SYMBOL_VALUEs.

* m4/m4module.h (m4_token, m4_get_token_type, m4_get_token_text)
(m4_get_token_func, m4_token_copy): Renamed to m4_symbol_value,
m4_get_symbol_value_type,  m4_get_symbol_value_text,
m4_get_symbol_value_func and m4_symbol_value_copy respectively.
Changed all callers.
(m4_symbol_type): s/M4_TOKEN_/M4_SYMBOL_/
(m4_get_token_type): Renamed
* m4/input.c (m4_next_token): Renamed to m4__next_token, and moved
to the internal api.
* m4/m4private.h: s/TOKEN_ARG_/SYMBOL_ARG_/
s/TOKEN_/VALUE_/
(m4__symtab_init, m4__symtab_exit): Removed prototypes.
(m4_token_arg): Renamed to m4_symbol_arg. Changed all callers.
(m4__token_type): Moved here from m4module.h.
(m4__next_token): Renamed from m4_next_token.
* m4/symtab.c: Removed some of the parameterised macro support
functions for modularisation later.
(m4_token_copy): Renamed to m4_symbol_value_copy, and use new
m4_hash_dup to perform a true deep copy of the SRC.
(arg_copy): Callback for m4_symbol_value_copy.
* utility.c (m4_token_get_type, m4_token_text, m4_token_func):
Renamed to m4_get_symbol_value_type, m4_get_symbol_value_text and
m4_get_symbol_value_func.  Changed all callers.
2007-10-05 21:58:37 -06:00
Gary V. Vaughan
362858ad92 Begin work on lifting the curse of the global variables. To start
with create a `struct m4' context container, and replace
`m4__symtab' with `context->symtab' throughout.  This means
initialising a context container in main, and adjusting many
functions between main and the module entry points so that the
container gets passed through.  It would have been nice to
defer this until after 1.5, but it has a major effect on the
user's module writing ABI, so it needs to be addressed now - at
least in the areas that impact the ABI.  An interrelatated change
in the symtab API removes the dependency on a global symbol table,
and instead focuses on a passed table (from the context
container).

* TODO: Reminders for finishing context functionality.
* m4/Makefile.am (libm4_la_SOURCES): Add m4.c.
* m4/m4.c: New file. Manage new struct m4 objects to eliminate
global variables and eventually allow m4 to be reentrant.
* m4/m4private.h (m4): Define the new structure here...
(M4_SYMTAB, m4_get_symtab): ...so we can have fast accessors that
don't carry the overhead of a function call.
* m4/m4module.h: Prototype extern functions from m4/m4.c.
(m4): Declare type for new struct m4 objects.
(M4SYMTAB): User macro to ease finding the symbol table for the
current context for module developers.
(m4_symbol_token): Renamed to m4_symbol_set_token which contains a
verb.
(M4_BUILTIN, m4_builtin_func, M4_BUILTIN_HANDLER)
(m4_builtin_define, m4_builtin_pushdef, m4_builtin_table_install)
(m4_call_macro, m4_dump_symbols, m4_expand_input)
(M4_FINISH_HANDLER, M4_INIT_HANDLE, m4_macro_define)
(m4_macro_pushdef, m4_macro_table_install, m4_module_load)
(m4_module_unload, m4_process_macro, m4_symbol_set_token): Add an
m4* context parameter. Changed definitions and all callers.
(m4_symtab): Alias for m4_hash to decouple the
m4_symtab api from m4_hash.
(m4_symtab_apply, m4_symtab_apply_func): Use m4_symtab instead of
m4_hash.
(m4_symtab_create): New function to return an initialised
m4_symtab.
(m4_symtab_delete): New function to delete an m4_symtab's memory.
(m4_symbol_define, m4_symbol_delete, m4_symbol_lookup)
(m4_symbol_popdef, m4_symbol_pushdef): Add an m4_symtab parameter
instead of simply using the global m4__symtab.  Changed
definitions and all callers.
* m4/m4private.h (m4__symtab_remove_module_references): Ditto.
* m4/symtab.c (m4__symtab_init, m4__symtab_exit): Removed.
* src/main.c (main): Create a context and use that instead of the
former global m4__symtab.
2007-10-05 21:58:34 -06:00
Akim Demaille
605ddc9be0 * m4/utility.c (m4_numeric_arg): Use the usual (argc, argv, ...)
interface instead of (name, argc...).
Upon failure, specify which argument was guilty.
Adjust callers.
2007-10-05 17:21:19 -06:00
Akim Demaille
538c626231 * modules/evalparse.c: Save translators' time: don't translate
internal error messages.
(m4_evaluate): Simplify/normalize error messages.
* doc/m4.texinfo (Eval): Adjust.
2007-10-05 17:21:18 -06:00
Gary V. Vaughan
008a582dc6 Rather than forcing each builtin definition to manage its own
argument range checking, tabulate the maxima and minima for all
builtins in each module.  This forces us to consider what the
valid ranges for each builtin should be, and moves the checking
code out of each builtin implementation and into the builtin
caller infrastructure.

* m4/m4module.h (struct m4_builtin): Add argument minima and
maxima.
* m4/m4private.h (struct m4_token): Reflect them here too.
* m4/input.c (struct input_block): ...and here.
(m4_token_copy): New function for token copying.
(init_macro_token): Copy them from a token to the input stack.
(m4_next_token): Don't forget to initialise them for text
macros.
* m4/macro.c (expand_argument): Use m4_token_copy, and also
check argument counts before calling the builtin handler.
* m4/symtab.c (m4_symbol_builtin): Take minima and maxima params.
(m4_symbol_macro): Likewise.
* m4/builtin.c (m4_builtin_pushdef): Add min_args and max_args
parameters.  Updated all callers.
(m4_builtin_define): Ditto.
(m4_macro_pushdef, m4_macro_define): Ditto.
* m4/symtab.c (m4_symbol_builtin, m4_symbol_define): Ditto.
* modules/evalparse.c:  Declare argument counts for defined
builtins and remove explicit calls to m4_bad_argc().
* modules/gnu.c: Ditto.
* modules/load.c: Ditto.
* modules/m4.c: Ditto.
* modules/modtest.c: Ditto.
* modules/mpeval.c: Ditto.
* modules/perl.c: Ditto.
* modules/shadow.c: Ditto.
* modules/stdlib.c: Ditto.
* modules/time.c: Ditto.
* TODO: Updated.
2007-10-05 17:21:14 -06:00
Gary V. Vaughan
6c0ddae370 The trace semantics now attach the trace bit to a symbol name.
For as long as a traceon(`foo') is active, calls to foo will be
traced regardless of intervening undefines or module unloads.
Fixed the flag propogation issues differently to the fixes
reverted with the last attempt at nailing down trace:

* m4/m4private.h:  This file is not visible outside of the m4
source tree, so I removed all the `M4_' and `m4_' prefixes to save
on typing.  Updated all clients.
(m4_token): New typedef contains the fields that need to be passed
around with the low level tokeniser.
(m4_token_data):  Removed.
(m4_symbol): Now contains the traced flag again.
* m4/symtab.c:  Rewritten again.  Now we don't remove symbols with
the trace bit set.  This change is contained entirely within this
module and doesn't leak out into the callers.  Updated all
clients.
(m4_symbol_builtin, m4_symbol_macro):  Adjusted to make use of the
new fields in m4_token.  Updated all clients.
* m4/builtin.c (m4_builtin_pushdef):  Needs a flags argument so
that `groks_macro_args' and `blind_if_no_args' flags are retained
when defn() results are passed around in m4 code.  Updated all
callers.
(m4_builtin_define): Ditto.
(m4_macro_pushdef, m4_macro_define): Ditto.
* m4/input.c (struct input_block): Add a flags field to facilitate
the above.
(m4_push_macro):  ...use it.
(init_macro_token):  Retrieve it.
(m4_next_token): Initialise it.
* m4/macro.c (expand_argument):  Copy it.
* m4/m4module.h: Adjust.
* tests/builtins.at:  Adjust the expected output of the trace
tests to reflect the change in semantics.
* tests/modules.at (modules: trace):  Check that unloading a
module which supplies a traced symbol definition doesn't lose te
trace bit.
2007-10-05 17:21:14 -06:00
Gary V. Vaughan
ca6af9acfd Reverted my large patch for removing the old m4_symbol
structure on 2001-09-20.  We are still not happy about the way
trace works in conjunction with defn and undefine, and leaving
the reverted patch active prevents us from moving the traced
bit from the definition back to the symbol.
2007-10-05 17:21:03 -06:00
Gary V. Vaughan
17b9a9aacd * m4/evalparse.c: Moved to...
* modules/evalparse.c:  ...here.  This code is shared between
modules/mpeval.c and modules/m4.c, so there is no need to pollute
the libm4 API with its details.  Moderately rewritten to interface
into its clients more simply.
* m4/eval.c: Deleted.  Migrated functionality to...
* modules/m4.c: ...here.
(builtin_eval):  Implemented in terms of the new interface style.
* modules/mpeval.c (builtin_mpeval): Ditto.
* m4/m4module.h: Removed references to the former m4/eval.c.
* m4/Makefile.am (libm4_la_SOURCES):  Removed eval.c.
(EXTRA_libm4_la_SOURCES): Deleted.
* modules/Makefile.am (EXTRA_m4_la_SOURCES): Reference evalparse.c.
(EXTRA_mpeval_la_SOURCES): Reference evalparse.c.
2007-10-05 17:20:56 -06:00