225 Commits

Author SHA1 Message Date
Eric Blake
dde5417b29 Upgrade to FDL 1.3, keep COPYING in repository.
* Makefile.am (MAINTAINERCLEANFILES): Don't remove COPYING.
* .cvsignore: Don't ignore it.
* .gitignore: Likewise.
* COPYING: Store in repository, per automake 1.10.2
recommendation.
* m4/gnulib-cache.m4: Replace fdl module with fdl-1.3.
* doc/m4.texinfo (GNU Free Documentation License): Upgrade
license.
* doc/Makefile.am (m4_TEXINFOS): Likewise.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-12-06 10:34:23 -07:00
Eric Blake
15ddfa0680 Replace stackovf with gnulib c-stack.
* m4/gnulib.cache.m4: Import c-stack module.
* configure.ac (AC_CHECK_HEADERS_ONCE): Remove check for
siginfo.h, sys/wait.h.
(AC_CHECK_TYPES): Likewise for siginfo_t.
(AC_CHECK_MEMBERS): Likewise for sa_sigaction, ss_sp.
(AC_CHECK_FUNCS_ONCE): Likewise for sigaction, sigaltstack,
sigstack, sigvec, strerror.
(M4_cv_use_stackovf): Likewise for stack overflow detection.
* src/Makefile.am (m4_SOURCES): Don't build stackovf.c.
* src/stackovf.c: Delete.
* src/m4.h (setup_stackovf_trap): Delete.
* src/m4.c (stackovf_handler): Delete.
(main): Use c_stack_action instead of setup_stackovf_trap.  If
stack overflow is detectable, don't limit -L artificially.
(usage): Document unlimited default on supported systems.
* doc/m4.texinfo (Limits control): Document new default nesting
limit.
* NEWS: Document this change.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-06-06 09:35:30 -06:00
Eric Blake
f3fbfb92cc Stage 24: Allow embedded NUL in macro names.
* m4/gnulib-cache.m4: Import xmemdup0 module.
* src/m4.h (define_builtin, push_string_init, push_wrapup_init)
(lookup_symbol): Add parameters.
(struct call_info): Add name_len member.
(struct token_data) [ENABLE_CHANGEWORD]: Add original_len member.
(struct symbol): Add len member.
(TOKEN_DATA_ORIG_LEN, SYMBOL_NAME_LEN): New accessors.
(m4_error_at_line, m4_warn_at_line): Delete.
(m4_error, m4_warn, debug_set_output, skip_line, set_word_regexp)
(bad_argc, evaluate): Adjust parameter type.
* src/m4.c (m4_error_at_line, m4_warn_at_line): Delete.
(m4_verror_at_line, m4_error, m4_warn): Adjust parameter type.
(main): Adjust caller.
* src/symtab.c (profile_strcmp) [DEBUG_SYMTAB]: Rename...
(profile_memcmp): ...and accomodate NUL.
(hash, lookup_symbol): Add parameter to track length.
(symtab_debug, symtab_print_list): Adjust callers.
* src/input.c (push_string_init, push_wrapup_init): Take location
as parameter rather than using global state.
(skip_line, set_word_regexp, next_token): Adjust parameter type.
(peek_input, next_char_1, match_input, lex_debug): Adjust
callers.
* src/macro.c (struct macro_arguments): Delete argv0 and argv0_len
members, now covered by info.
(expand_input, expand_token, expand_argument, collect_arguments)
(expand_macro, arg_text, arg_empty, arg_len, make_argv_ref)
(push_arg, wrap_args): Adjust callers.
* src/builtin.c (define_builtin): Add parameter.
(bad_argc, numeric_arg, mkstemp_helper, substitute): Adjust
parameter type.
(define_user_macro, builtin_init, define_macro, m4_undefine)
(m4_popdef, m4_ifdef, m4_ifelse, dumpdef_cmp, m4_dumpdef)
(m4_builtin, m4_indir, m4_defn, m4_syscmd, m4_esyscmd, m4_eval)
(m4_incr, m4_decr, m4_divert, m4_divnum, m4_undivert, m4_shift)
(m4_changequote, m4_changecom, m4_changeword, include)
(m4_maketemp, m4_mkstemp, m4_errprint, m4___file__, m4___line__)
(m4___program__, m4_m4exit, m4_m4wrap, m4_traceon, m4_traceoff)
(m4_debugmode, m4_debugfile, m4_len, m4_index, m4_substr)
(m4_translit, m4_format, m4_regexp, m4_patsubst): Adjust all
callers.
* src/debug.c (debug_set_file, debug_set_output): Adjust parameter
type.
(trace_flush, trace_prepre, trace_pre): Adjust all callers.
* src/eval.c (logical_or_term, logical_and_term, or_term)
(xor_term, and_term, equality_term, cmp_term, shift_term)
(add_term, mult_term, exp_term, unary_term, simple_term)
(evaluate): Adjust parameter type.
* src/format.c (arg_int, arg_long, arg_double): Likewise.
(expand_format): Adjust caller.
* doc/m4.texinfo (Using frozen files): Test this.
* examples/null.m4: Likewise.
* examples/null.err: Adjust expected output.
* examples/null.out: Likewise.

(cherry picked from commit 6167507cf07ddbc838e14e3d66803b360e63f6f2)

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-06-02 21:31:43 -06:00
Eric Blake
fba265c02e Don't allow failure to freeze give exit status of 0.
* doc/m4.texinfo (Using frozen files): Test the fix from
2007-11-22.
* THANKS: Update.
Reported by Jean-Charles Longuet.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-05-22 05:58:07 -06:00
Eric Blake
bc4cf0aa6f Stage 23: allow tracing of indirect macro calls.
* src/m4.h (struct call_info): New struct.
(trace_prepre, trace_pre, trace_post, push_string_finish)
(input_print, call_macro): Alter signatures.
(arg_info): New prototype.
(input_block): Delete...
* src/input.c (input_block): ...and make typedef local again.
(push_string_init): Initialize length.
(push_string_finish, input_print): Change signature, so that
printing can be done before finalization.
* src/macro.c (struct macro_arguments): Add info member.
(collect_arguments, make_argv_ref): Manage new field.
(expand_macro): Change call context management.  Move tracing...
(call_macro): ...here, and remove redundant parameter.
(arg_info): New function.
* src/debug.c (trace_format): Delete unused modifiers.
(trace_header, trace_flush, trace_prepre, trace_pre, trace_post):
Change signatures for stacked trace messages, and for using call
context.
* src/builtin.c (m4_builtin, m4_indir): Update callers.
* src/m4.c (usage): Update debugmode flag summary.
* doc/m4.texinfo (Defn): Update examples to match new behavior.
(Trace): Mention new capability of indir.
(Debug Levels): Enhance text for 'c' and 'x', update examples.
(Incompatibilities): Mention risk of parsing trace output.
* examples/null.m4: Enhance test.
* examples/null.err: Update expected output.
* NEWS: Mention these changes.
Reported by Akim Demaille in the autoconf TODO file in 2000.

(cherry picked from commit ec804cba9ceeef7ca863d163eeae3fca669ccd16)

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-05-09 06:12:25 -06:00
Eric Blake
c8a2c296df Fix traceon regression introduced 2006-06-06.
* src/builtin.m4 (traceon): Only perform insertion if lookup
fails.
* doc/m4.texinfo (Trace): Test for the bug.
* NEWS: Document it.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-05-07 10:55:33 -06:00
Eric Blake
50fabc46c2 Stage 22: allow builtin token concatenation outside $@.
* src/m4.h (arg_text): Add parameter.
(ARG): Adjust callers.
* src/input.c (init_macro_token): Add parameter.
(next_token): Support concatenating builtins.
* src/macro.c (warn_builtin_concat): Delete warning.
(expand_argument, arg_adjust_refcount): Handle builtin tokens.
(arg_text): Add parameter.
(arg_print): Adjust caller.
* src/builtin.c (define_macro): Flatten builtins, rather than
doing nothing.
(defn): Warn on undefined macro name.
* src/m4.c (main): Avoid atoi.
* src/output.c: Whitespace fixes.
* doc/m4.texinfo (Defn): Document the new semantics.
(Ifelse, Debug Levels, M4wrap): Enhance tests.
* NEWS: Document this change.

(cherry picked from commit 8a47a2029b7eb60ac61abb1b6423d4a67b371281)

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-05-05 21:24:30 -06:00
Eric Blake
26b3c17ceb Document define_blind.
* doc/m4.texinfo (Ifelse): Add a new composite macro.
* THANKS: Update.
Suggested by Mike R.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-05-03 11:51:55 -06:00
Eric Blake
f87a1e3fe9 Fix debugmode regression from 2008-04-14.
* src/input.c (pop_input): Fix -di output on end of input.
* doc/m4.texinfo (Debug Levels): Test this behavior.
(Changeword, Location): Correct examples.
* checks/check-them (examples): Update to account for recommended
location for running tests.
* doc/m4.texinfo (Debug Levels): Test this behavior.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-04-24 16:27:16 -06:00
Eric Blake
05528e98e0 Fix spelling of attribution to Christopher Strachey.
* doc/m4.texinfo (History, Inhibiting Invocation): Fix typo.
* THANKS: Update.
Reported by Fernando Carrijo.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-04-21 16:27:01 -06:00
Eric Blake
2b570fc019 Fix buildbot failure.
* doc/m4.texinfo (Diversions): Consume all of m4's output, in case
SIGPIPE is ignored.
* THANKS: Update.
Detected by Bob Proulx's buildbot.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-04-17 06:50:34 -06:00
Eric Blake
14840bcf0e Another 'make installcheck' fix.
* doc/m4.texinfo (Diversions): s/m4/__program__/ in case
--program-prefix was active.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-04-15 14:27:54 -06:00
Eric Blake
6b67f52903 Stage 21: $@ concatenates builtins, m4wrap takes builtins.
* src/m4.h (append_macro): New prototype.
(push_macro, push_wrapup_init, arg_print, func_print): Alter
prototypes.
* src/input.c (INPUT_MACRO): Delete, covered by INPUT_CHAIN.
(INPUT_EOF): New input block type, for efficiency.
(struct input_block): Remove u.func member.
(input_eof): New input sentinel.
(append_macro): New function.
(push_macro, push_wrapup_init): Add parameter.
(push_token): Support builtin tokens.
(init_macro_token): Always use chain for builtin tokens.
(push_string_init, pop_input, pop_wrapup, input_print)
(peek_input, next_char, next_char_1, input_init): Adjust callers.
* src/macro.c (arg_equal, wrap_args): Handle builtin tokens.
(arg_print): Add parameter.
(collect_arguments, arg_type, arg_text): Adjust callers.
* src/builtin.c (m4_m4wrap): Handle builtin tokens.
(func_print): Add parameter.
(m4_defn): Allow pushing builtin alongside other text.
(m4_errprint): Adjust caller.
* src/debug.c (trace_pre): Likewise.
* doc/m4.texinfo (Defn, Ifelse, Debug Levels): Update tests to new
behavior.
(M4wrap): New test.

(cherry picked from commit 32d4bf4d447e0e252c809897b795b57b3bfd74de)

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-04-14 22:05:40 -06:00
Eric Blake
7541b497e8 Improve OS/2+emx build.
* src/m4.h [__EMX__]: OS/2 does not have a Unix-compatible
system(3), no matter what other macros it pre-defined.
* doc/m4.texinfo (Mkstemp): Rework test to avoid globbing failure
on OS/2.
* src/builtin.c (predefined_tab): Ensure all possible system
identifiers are defined, not just the first; the testsuite will
catch if multiple identifiers mistakenly made it through.
* examples/null.m4 (esyscmd): Don't rely on printf to generate NUL
byte.
* examples/null.out (esyscmd): Check for esyscmd success.
* THANKS: Update.
Reported by Elbert Pol.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-04-11 10:05:33 -06:00
Eric Blake
a82c183e85 Mention 1.4.11 release.
* NEWS: Update to match release on branch-1.4.
* doc/m4.texinfo (History): Update release history.
(Format): Test for C99 hex-float parsing.
* src/Makefile.am (m4_LDADD): Use POW_LIB when needed.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-04-02 14:52:33 -06:00
Eric Blake
d8075cd139 Improve release process.
* maint.mk (alpha): Check for PREV_VERSION setting sooner, and
remove tag operation.
(version-check): Enhance this check.
(prev-tarball): Depend on version-check.
(web-manual): Fix VPATH usage.
(this-vc-tag): Delete, and mention need to run tag...
* HACKING: ...here, prior to make maintainer-distcheck.
Update the instructions to match this particular release process.
* Makefile.am (.version, announcement): Allow for VPATH build.
* cfg.mk (gnulib_dir): Likewise.
* doc/Makefile.am ($(srcdir)/m4.1): Include release number in man
page.

Signed-off-by: Eric Blake <ebb9@byu.net>
(cherry picked from commit c07173b0a58b56c07633a28323d56451b98b7de5)

Conflicts:
2008-04-02 14:14:56 -06:00
Eric Blake
a86f1dcafc Add test for divert bug on 2007-05-28, patched 2007-07-21.
* doc/m4.texinfo (Diversions): Add test.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-03-27 06:58:07 -06:00
Eric Blake
972ddeee22 Mention FIFO m4wrap more prominently in NEWS.
* NEWS: Describe effect on autoconf 2.59 and earlier.
* doc/m4.texinfo (History): The next version will be 1.6, not
1.4.11.
Reported by Ralf Wildenhues.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-03-24 06:53:38 -06:00
Eric Blake
ca0ae27571 Stage 20: make m4wrap obey POSIX fifo ordering.
* src/m4.h (enum token_chain_type): Add CHAIN_LOC.
(struct token_chain): Add u_l member.
(wrap_args): New prototype.
* src/input.c (push_wrapup_init, push_wrapup_finish): Rewrite to
guarantee a FIFO chain in the wrapup stack.
(pop_input, peek_input, next_char_1): Support location link.
(next_char): Add parameter.
(init_macro_token, init_argv_token): Require user to consume empty
input.
(skip_line, match_input): Adjust callers.
(next_token): Always consume first character.
* src/macro.c (arg_text): Tighten assertion.
(wrap_args): New method.
* src/builtin.c (m4_m4wrap): Use it.
(define_macro): Issue warning when ignoring builtin token during
macro definition.
* doc/m4.texinfo (M4wrap, Location, Incompatibilities)
(Improved m4wrap): Adjust examples to corrected behavior.
* NEWS: Document this fix.

(cherry picked from commit f7f45337fa1bfba9512841e8d3d2251359944681)

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-03-18 20:03:21 -06:00
Eric Blake
4cc7916e4d Document join, in order to fix bug in m4wrap example.
* examples/join.m4: New file.
* examples/wraplifo2.m4: Likewise.
* examples/Makefile.am (EXTRA_DIST): Add new files.
* doc/m4.texinfo (Improved m4wrap): New node.
(Defn, Location): Enhance tests.
(Shift): Document the composit macro join.
(Incompatibilities): Move documentation of LIFO vs. FIFO...
(M4wrap): ...here, to match improved example.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-03-15 20:20:36 -06:00
Eric Blake
d53cf5ec91 Stage 19: allow builtin tokens in more macros.
* src/m4.h (enum token_chain_type): Add CHAIN_FUNC.
(struct token_chain): Add func member.
* src/input.c (push_token, pop_input, input_print, peek_input)
(next_char_1, init_macro_token): Handle builtin tokens from
back-references.
(next_token): Flatten builtin tokens inside comments or quotes,
except when a builtin is the only thing inside quotes.
* src/macro.c (expand_argument): Strengthen assertion.
(collect_arguments): Handle builtin tokens.
(expand_macro): Fix harmless typo.
(arg_token): Add parameter.
(arg_type, arg_text, arg_equal, arg_empty, arg_len, arg_func)
(arg_print, push_arg_quote, push_args): Update callers to either
require flattened arguments or to handle builtins.
* src/builtin.c (m4_defn, m4_dumpdef, m4_ifdef, m4_ifelse)
(m4_popdef, m4_shift, m4_traceoff, m4_traceon, m4_undefine):
Handle builtin tokens, either by recognizing invalid macro names
or passing them through transparently.
(define_user_macro): Make all user macros handle builtin token
arguments transparently.
* doc/m4.texinfo (Defn, Ifdef, Ifelse, Debuglen): Document and
test the new behavior.
* NEWS: Document this change.

(cherry picked from commit 434656c96d6486cf959c3050aa85aecb72d948a0)

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-03-14 07:03:37 -06:00
Eric Blake
ff87075d2c Fix nested builtin(`shift',$@) regression from 2008-02-22.
* src/macro.c (make_argv_ref_token): Don't output expansion text
when making wrapper for builtin or indir.
* doc/m4.texinfo (Builtin): Test it.
* NEWS: Document the fix.
Reported by Andreas Schwab.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-03-06 17:17:37 -07:00
Eric Blake
58ffaf13f5 Stage 18: try harder to reuse argv in recursion.
* src/macro.c (make_argv_ref_token): Avoid wrapping $@ when
possible.
(push_args): Let make_argv_ref_token take care of pending data.
* doc/m4.texinfo (Improved foreach): Tweak wording to match new
performance capability.  Add regression tests.
* NEWS: Document the speedup.
* src/m4.c (AUTHORS): Claim credit for my rewrite.

(cherry picked from commit 58d580eeca1f75ddd2ca68d8b93fef6eead14350)

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-02-22 21:17:33 -07:00
Eric Blake
d59ecd1edf Stage 16: cache quotes and improve arg_print.
* src/m4.h (push_wrapup_init, push_wrapup_finish, quote_cache)
(func_print): New prototypes.
(arg_print): Adjust prototype.
* src/builtin.h (func_print): New function.
(define_user_macro): Slight cleanup.
(dump_args): Delete, no longer used.
(m4_errprint): Use arg_print.
(m4_m4wrap): Handle embedded NUL.
* src/debug.c (trace_pre): Use arg_print.
* src/input.c (cached_quote): New variable.
(push_wrapup): Split...
(push_wrapup_init, push_wrapup_finish): ...into these.
(input_print): Use arg_print.
(quote_cache): New function.
(pop_input, next_char_1, append_quote_token, set_quote_age):
Adjust users.
* src/macro.c (arg_text, make_argv_ref_token): Adjust users.
(arg_print): Add parameters.
* examples/null.m4: Test for NUL in m4wrap.
* examples/null.out: Update expected output.
* doc/m4.texinfo (Debug Levels): Test --arglength truncation.

(cherry picked from commit 44740d89961c48b712562dfc650dc0cb57898aa0)

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-02-21 06:57:06 -07:00
Eric Blake
345b7b6429 Clean up foreach example.
* doc/m4.texinfo (Foreach, Improved foreach): Document another
shortcoming in foreach.m4.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-02-19 13:36:53 -07:00
Eric Blake
702a3fe3e8 Add regression test for multi-character quote recursion.
* examples/foreach2.m4: Use $0 rather than spelling out name.
* examples/foreachq2.m4: Likewise.
* examples/forloop2.m4: Likewise.
* examples/hanoi.m4: Likewise.
* examples/trace.m4: Likewise.
* doc/m4.texinfo (Improved forloop): Document advantage of $0.
(Improved foreach): Adjust dump from file.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-02-16 15:17:08 -07:00
Eric Blake
7319157ccd Stage 15: return argv refs back to collect_arguments.
* src/m4.h (enum token_type): Add TOKEN_ARGV.
(struct token_chain): Add skip_last member to argv link.
(next_token): Update prototype.
* src/input.c (CHAR_ARGV): New placeholder input character.
(peek_input): Add parameter, to pass $@ at once.
(next_char_1, append_quote_token): Handle $@ inside quotes.
(init_argv_token): New function.
(push_token, match_input, next_token, peek_token, lex_debug):
Update callers.
* src/macro.c (expand_input, collect_arguments): Likewise.
(expand_argument): Handle incoming $@ token.
(arg_adjust_refcount, arg_token, arg_text, make_argv_ref_token):
Handle nested $@ refs.
* src/symtab.c (symtab_debug): Update caller.
* examples/null.m4: Document more tests that are needed.  Add
tests for NUL with divert, patsubst, and regexp.
* examples/null.out: Update for new tests.
* doc/m4.texinfo (Syntax): Add test for m4exit and NUL.
* checks/get-them (AWK): Give a default value.
* checks/check-them: Allow tests to invoke child processes with
same include path.  Perform message normalization on stderr.

(cherry picked from commit 1fecefc8b990254aa667a01d12c6c7a2d716df06)

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-02-16 06:36:45 -07:00
Eric Blake
c97e90f160 Fix texinfo grammar.
* doc/m4.texinfo (Incompatibilities): Use @. after capital.
(History): Use @: after abbreviations.
(M4exit): Use correct Latin abbreviation.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-02-13 20:45:15 -07:00
Eric Blake
27cdfd5ef2 Document behavior of __gnu__().
* doc/m4.texinfo (Platform macros): Enhance test.
(Macro expansion): New test.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-02-11 10:58:13 -07:00
Eric Blake
c75314631b Fix security hole introduced 2007-11-22.
* src/m4.h (includes): Add quotearg.h.
* src/m4.c (m4_verror_at_line): Properly escape macro names.
(main): Manage quoteargs defaults.
* doc/m4.texinfo (Indir): Document and test this.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-02-06 10:14:48 -07:00
Eric Blake
6aa361e373 Stage 14: allow pushing argv references.
* src/m4.h (struct token_chain): Add comma and quotes fields.
(arg_adjust_refcount, arg_print, push_arg_quote): New prototypes.
* src/input.c (push_token, pop_input, input_print, peek_input)
(next_char_1): Support $@ references.
* src/macro.c (struct macro_arguments): Add level field.  Match
type of arraylen to argc.
(collect_arguments): Populate new field.
(expand_macro, make_argv_ref, push_arg): Factor...
(arg_adjust_refcount, make_argv_ref_token, push_arg_quote):
...into these new methods.
(arg_token): Add new parameter.
(arg_print): New function.
(arg_mark, arg_type, arg_text, arg_equal, arg_empty, arg_len)
(arg_func, push_args): Adjust callers.
* doc/m4.texinfo (Ifelse): Augment test.

(cherry picked from commit 9d08c0c8685fdd749b20062e03c061275dc8afbc)

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-02-02 15:38:59 -07:00
Eric Blake
5d61bd6045 Stage 10: avoid extra copying of strings and comments.
* m4/gnulib-cache.m4: Import the intprops and vasnprintf-posix
modules.
* src/m4.h (includes): Use new gnulib modules.
(next_token): Adjust prototype.
(bad_argc): New prototype.
* src/format.c (arg_int, arg_long, arg_double): New helper
functions.
(ARG_INT, ARG_LONG, ARG_STR, ARG_DOUBLE): Track missing
arguments.
(format): Improve warnings, and avoid copying into obstack in the
common case.
* src/input.c (next_token): Add new parameter.
(lex_debug): Adjust caller.
* src/symtab.c (symtab_debug): Likewise.
* src/macro.c (expand_input, expand_token, expand_argument)
(collect_arguments): Likewise.
* src/output.c (m4_tmpname): Guarantee correct buffer size.
* src/builtin.c (builtin_init): Improve efficiency.
(bad_argc): Export.
(ntoa): Tighten buffer allocation.
* doc/m4.texinfo (Format): Test the improvements.
* NEWS: Document the improvement.

(cherry picked from commit 622fc8cb2cb6ce0fc7391a6414bb0aaffeec6fc0)

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-01-16 20:16:10 -07:00
Eric Blake
bf1bf749de Fix --warn-macro-sequence regression from 2007-11-29.
* src/builtin.c (define_user_macro): Use correct length.
* doc/m4.texinfo (Arguments): Test the fix.
(History): Reword to account for new year and eventual result of
the argv_ref branch.

Signed-off-by: Eric Blake <ebb9@byu.net>
2008-01-14 11:49:03 -07:00
Eric Blake
e2b843f0ac Stage 9: share rather than copy single-arg refs.
* m4/gnulib-cache.m4: Import quote and memmem modules.
* src/m4.h (arg_scratch): New prototype.
* src/input.c (INPUT_INLINE_THRESHOLD): New define.
(push_token): Use it to inline short text, and save references to
longer text.
(input_init, next_token): Simplify obstack handling.
* src/macro.c (expand_argument): Likewise.
(expand_macro): Track scratch space.
(arg_scratch): New function.
(make_argv_ref): Use it.
(push_args): Likewise, and simplify comma handling, since most
separators are short enough to be inlined.
* src/builtin.c (builtin_init): Avoid cast.
(m4_errprint, m4_index): Transparently support NUL.
(m4_translit): Use scratch space, rather than leaking memory on
expansion stack.
* doc/m4.texinfo (Syntax): Add new test of embedded NUL.
* checks/get-them: Extract test that uses external files.
* checks/check-them: Run the new test.  Use unified diff if
possible, and force text mode when debugging NUL handling.
* examples/null.m4: New file.
* examples/null.out: Likewise.
* examples/null.err: Likewise.
* examples/Makefile.am (EXTRA_FILES): Distribute these files.
* .gitattributes: Treat new files as text, in spite of embedded
NUL.

(cherry picked from commit a6c94a314afa34958330b719d66c2d4e403a94af)

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-12-20 21:59:17 -07:00
Eric Blake
c947bf47f4 Stage 8: extend life of references into argv.
* src/m4.h (obstack_regrow): Delete, now that it is unused.
(struct token_chain): Add level field.
(push_token): Adjust prototype.
(adjust_refcount): New prototype.
* src/macro.c [DEBUG_MACRO]: Add debugging hooks for $@ reference
counting.
(argc_stack, argv_stack): Delete, replaced by...
(struct macro_arg_stacks, stacks, stacks_count): ...these new
structure for tracking $@ references.
(expand_input): Initialize new structure.
(collect_arguments): Alter signature.
(expand_macro): Rework obstack handling, in order to keep $@
references alive until they have been rescanned.
(adjust_refcount, arg_mark): New functions.
(make_argv_ref): Use new field.
(push_arg, push_args): Update callers.
* src/input.c (make_text_link): Use new field.
(push_token): Change signature.
(pop_input, next_char_1): Call new function.
* doc/m4.texinfo: Clean up some examples of -d option usage.
(Ifelse): Add some stress tests.

(cherry picked from commit b0daa4c96f734aab4d450594f64bc15d4321fd60)

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-12-18 07:09:44 -07:00
Eric Blake
da38cc2a2e Yet more rewording.
* doc/m4.texinfo (Inhibiting Invocation): Missed one instance in
the previous patch.

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-12-13 11:47:55 -07:00
Paolo Bonzini
ba5c56ec45 * doc/m4.texinfo: Fix quoting of a quoting example.
Reported by Giovanni Toffetti.
2007-12-13 10:53:14 -07:00
Eric Blake
bd9900d65e Minor security fix: Quote output of mkstemp.
* src/builtin.c (mkstemp_helper): Produce quoted output.
* doc/m4.texinfo (Mkstemp): Update the documentation and tests.
* NEWS: Document this change.

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-12-07 12:12:15 -07:00
Eric Blake
83e9a157eb Stage 5: add notion of quote age.
* src/input.c: Comment cleanups.
(current_quote_age): New global variable.
(set_quote_age): New helper function.
(input_init, set_word_regexp): Use it.
(set_quotes, set_comment): Likewise, and detect no-op changes.
(quote_age, safe_quotes): New functions.
(next_token): Track quote age.
* src/m4.h (struct token_data): Add quote_age member.
(TOKEN_DATA_QUOTE_AGE, quote_age, safe_quotes): New prototypes.
* src/macro.c (struct macro_arguments): Add quote_age member.
(expand_token): Alter signature and track quote age.
(expand_input, expand_argument): All callers changed.
(collect_arguments, make_argv_ref): Track quote age.
(arg_text, arg_len, arg_func): Detect type mismatch.
* doc/m4.texinfo (Ifelse, Changequote): Add more tests.
(Incompatibilities): Fix typo.
* examples/wraplifo.m4: New file.
* examples/Makefile.am (EXTRA_DIST): Distribute it.

(cherry picked from commit 8b5b3b7a74f452fed795c063965966934a68755d)

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-12-07 07:07:36 -07:00
Eric Blake
8ad387be88 Fix builds with OpenBSD make.
* doc/Makefile.am (HELP2MAN): New macro.
(man_MANS, m4.1): Fix rules for building m4.1 into srcdir.
* README: Update copyright.
* HACKING: Mention help2man and makeinfo dependencies.

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-12-04 06:34:06 -07:00
Eric Blake
07108982f9 Stage 3: cache length, rather than computing it
* src/input.c (next_token): Grab length from obstack rather than
calling strlen.
* src/m4.h (token_data, macro_arguments): Add length field.
(TOKEN_DATA_LEN): New accessor.
(define_user_macro): Add parameter.
* src/builtin.c (define_user_macro, mkstemp_helper): Use
pre-computed length.
(builtin_init, define_macro, m4_maketemp, m4_mkstemp): Adjust
callers.
(dump_args, m4_ifdef, m4_ifelse, m4_builtin, m4_indir, m4_eval)
(m4_len, m4_substr, m4_translit, m4_regexp, m4_patsubst)
(expand_user_macro): Use cached lengths.
* src/freeze.c (reload_frozen_state): Adjust callers.
* src/m4.c (main): Likewise.
* src/macro.c (expand_token, expand_argument, collect_arguments)
(arg_len): Use cached length.
* doc/m4.texinfo (Mkstemp): Ensure mkstemp does not produce NUL.

(cherry picked from commit cd50e094b5f49104f66ff807c0a01d2f20c61c7f)

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-11-29 06:59:50 -07:00
Eric Blake
910837ec45 Refactor error messages to avoid macros.
* src/m4.h (_): Define, as a placeholder for now.
(M4ERROR, M4ERROR_AT_LINE): Delete.
(m4_error, m4_error_at_line): Change prototype.
(m4_warn, m4_warn_at_line): New prototypes.
* src/m4.c (m4_verror_at_line): New helper function.
(m4_error, m4_error_at_line): Use new function, and properly call
va_end.
(m4_warn, m4_warn_at_line): New functions.
(stackovf_handler, main): All callers changed.
* src/builtin.c: Likewise.
* src/debug.c: Likewise.
* src/eval.c: Likewise.
* src/format.c: Likewise.
* src/freeze.c: Likewise.
* src/input.c: Likewise.
* src/macro.c: Likewise.
* doc/m4.texinfo (Indir, Builtin, Dumpdef, Incr, Eval, Substr)
(Improved forloop): Adjust tests accordingly.

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-11-22 14:13:49 -07:00
Eric Blake
ed2e087c61 Consistently report macro name first in messages.
* src/m4.h (evaluate): Adjust prototype.
* src/builtin.c (bad_argc, numeric_arg, m4_placeholder): Alter
wording to match head.
(mkstemp_helper, substitute): Adjust signature.  All callers
changed.
(m4_dumpdef, m4_builtin, m4_indir, m4_defn, m4_esyscmd, m4_eval)
(m4_undivert, m4_maketemp, m4_m4exit, m4_debugmode)
(m4_debugfile, m4_regexp, m4_patsubst): Mention macro name in
message.
(m4_format): Adjust call.
* src/format.c (format): No longer skip argv[0].
* src/eval.c (evaluate): Mention macro name in message.
(logical_or_term, logical_and_term, or_term, xor_term, and_term)
(equality_term, cmp_term, shift_term, add_term, mult_term)
(exp_term, unary_term, simple_term): Adjust signature.
* src/macro.c (warn_builtin_concat): Likewise.
(expand_argument): Adjust caller.
* doc/m4.texinfo (Macro Arguments, Ifdef, Ifelse, Debug Output)
(Dnl, Improved fatal_error, Defn, Builtin, Index macro, Regexp)
(Substr, Translit, Patsubst, Format, Eval, Dumpdef, Include)
(Improved forloop, Indir, Trace, Incr): Adjust tests to match.

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-11-21 16:11:25 -07:00
Eric Blake
bfe28c9acd Make dnl diagnostic print macro name.
* src/m4.h (skip_line): Adjust prototype.
* src/input.c (skip_line): Report error on behalf of caller.
* src/builtin.c (m4_dnl): Adjust caller.
(dump_args, m4_dumpdef, m4_changequote, m4_changecom)
(m4_changeword, m4_traceon, m4_traceoff, expand_user_macro): Use
ARG macro instead of open-coding.
* doc/m4.texinfo (Dnl): Adjust test.

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-11-21 16:11:18 -07:00
Eric Blake
aaf838ab07 Avoid builtin concatenation in macro arguments.
* doc/m4.texinfo (Defn): Add tests.
* src/macro.c (warn_builtin_concat): New function.
(expand_argument): Use it to warn on more corner cases.
* NEWS: Mention new warning.

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-11-14 15:15:31 -07:00
Eric Blake
143b597a5a More corner-case testing.
* doc/m4.texinfo (Pseudo Arguments): Test more corner cases.

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-11-07 07:40:21 -07:00
Eric Blake
94692e6c0e Use build-aux directory.
* configure.ac (PACKAGE, VERSION): Delete, since Automake does
this now.
(AC_CONFIG_AUX_DIR): Add, with auxiliary files in build-aux
instead of the top level.
* bootstrap: Adjust accordingly.
* m4/gnulib-cache.m4: Add --aux-dir option.
* doc/Makefile.am (m4.1): Rewrite rule to use build-aux/missing.

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-11-05 09:22:44 -07:00
Eric Blake
3a38f81335 Improve error message when early end of file occurs.
* doc/m4.texinfo (Macro Arguments, Changequote, Changecom)
(M4wrap): Adjust to new messages.
(Improved capitalize): Enhance test.
* src/m4.h (next_token): Adjust prototype.
* src/input.c (next_token): Add new parameter, and improve error
message.
(lex_debug): Adjust callers.
* src/symtab.c (symtab_debug): Likewise.
* src/macro.c (expand_input, collect_arguments): Likewise.
(expand_argument): Likewise, and add parameter.

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-11-01 06:31:22 -06:00
Eric Blake
86f05e7468 Test more corner cases.
* doc/m4.texinfo (Changecom, Pseudo Arguments): Beef up tests.
(Improved foreach): Document alternate foreachq style.
* examples/foreachq3.m4: New file.
* examples/loop.m4: New file.
* examples/Makefile.am (EXTRA_DIST): Distribute them.

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-10-31 09:58:43 -06:00
Eric Blake
08d5b5e080 More test coverage for autoconf usage patterns.
* doc/m4.texinfo (Inhibiting Invocation, Pseudo Arguments)
(Builtin): Add new undocumented tests.
(Shift): Document cond macro, and add new test.

Signed-off-by: Eric Blake <ebb9@byu.net>
2007-10-28 16:57:40 -06:00