summaryrefslogtreecommitdiff
path: root/m4
Commit message (Collapse)AuthorAgeFilesLines
* maint: fix some warnings that break compilation with -Werror.Gary V. Vaughan2013-09-221-7/+7
| | | | | | | | | | * m4/hash.c (ITERATOR_NEXT_NEXT): Hide unused macro. (maybe_grow): Prevent implicit double promotion. (m4_get_hash_length, m4_get_hash_iterator_key) (m4_get_hash_iterator_value, m4_hash_string_hash) (m4_hash_string_cmp): Add pure attribute for gcc. Signed-off-by: Gary V. Vaughan <gary@gnu.org>
* modules: huge simplification of module loading without libltdl.Gary V. Vaughan2013-09-214-177/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Libltdl is huge and slow, and carrying the weight of support for decades old systems. We can do much better using POSIX dlopen and dlsym directly, simplifying and speeding up as we do so. * configure.ac (LT_CONFIG_LTDL_DIR, LTDL_INIT): Remove. (M4_DEFAULT_PRELOAD): Set to ""; we lost preload support along with removing libltdl. * Makefile.am: Don't include ltdl/Makefile.inc. (AM_CPPFLAGS): Manually add current directory to include search paths. * m4/m4private.h (includes): Remove ltdl.h. (INIT_SYMBOL, m4__module_init): Remove. (struct m4_module): Change handle type from lt_dlhandle to void *. * m4/m4module.h (M4INIT_HANDLER): Remove. * m4/module.c (includes): Add dlfcn.h. (m4__module_interface, iface_id, m4__module_init, module_dlerror): Remove. (m4__module_open): Drastically simplified without all the libltdl setup and interface id twiddling. Just call dlopen to get a native handle, and the dlsym to get the init function. (m4_module_import): Similarly wrt dlsym. * m4/path.c (FILE_SUFFIXES): Replace .la and LT_MODULE_EXT with hardcoded ".so". (m4_load_filename): Likewise. * modules/gnu.c: Remove libltdl preprocessor symbol renaming, and use "include_<modulename>" as the single entry point function. * modules/import.c, modules/m4.c, modules/modtest.c, modules/mpeval.c, modules/shadow.c, modules/stdlib.c, modules/time.c, modules/traditional.c: Likewise. * main.c (main): Remove calls to m4__module_init and LTDL_SET_PRELOADED_SYMBOLS. * tests/m4.in: Make sure we always have the modules/.libs and tests/.libs directories at the front of M4PATH so that the tests will find the modules they need to include. Signed-off-by: Gary V. Vaughan <gary@gnu.org>
* modules: speed up multiple includes of the same module.Gary V. Vaughan2013-09-201-5/+5
| | | | | | | | * m4/module.c (m4_module_load): If we already have the module loaded, reuse that. Otherwise, open the module afresh and register it's builtins and macros on success. Signed-off-by: Gary V. Vaughan <gary@gnu.org>
* modules: simplify module lookup by name.Gary V. Vaughan2013-09-203-14/+22
| | | | | | | | | | | | | * m4/m4private.h (m4:namemap): New field for hash table to lookup module structures by name string. * m4/m4.c (hashfn): Hash function for plain strings. (m4_create): Initialise namemap field to a hash table using hashfn for inserting and looking up keys. * m4/module.c (m4__module_find): Replace the fussy libltdl twiddling with a hash lookup in m4:namemap. Add a new context parameter. Adjust all callers. Signed-off-by: Gary V. Vaughan <gary@gnu.org>
* modules: store loaded modules in context struct.Gary V. Vaughan2013-09-204-27/+17
| | | | | | | | | | | | * m4/m4private.h (struct m4_module): Add a next pointer. (struct m4): Add a module list pointer. * m4/module.c (m4__module_open): Initialise the next pointer and update the list head when a new module is successfully opened. (m4_module_next): Replace the ugly libltdl twiddling with a straight forward module list traversal one-liner! Add a context parameter. Adjust all callers. Signed-off-by: Gary V. Vaughan <gary@gnu.org>
* modules: store module name in the module struct.Gary V. Vaughan2013-09-203-10/+7
| | | | | | | | | | | * m4/m4private.h (m4_module): Add name field. * m4/module.c (m4__module_open): Save the name field. * m4/path.c (m4_load_filename): Pass the raw filename to m4_module_load. * m4/module.c (m4_get_module_name): Replace all the ltdl twiddling with returning the saved name field. Signed-off-by: Gary V. Vaughan <gary@gnu.org>
* modules: allow only a single function access point.Gary V. Vaughan2013-09-203-78/+79
| | | | | | | | | | | | | | | | | | | | | | Exporting non-function symbols barely works on Windows, so change the module loading API to use a single function access point which is then responsible for calling back to install symbols and macros. * m4/m4module.h, m4/m4module.c (m4_install_builtins) (m4_install_macros): New APIs for saving builtins and macros into the module struct. * m4/m4module.c (install_macro_table, install_builtin_table): Adjust accordingly. (m4__module_open): Simplify accordingly. * m4/m4private.h (BUILTIN_SYMBOL, MACRO_SYMBOL): Remove. * modules/gnu.c, modules/import.c, modules/m4.c, modules/modtest.c, modules/mpeval.c, modules/shadow.c, modules/time.c, modules/traditional.c (m4_builtin_table, m4_macro_table): Make static, and remove LTX symbol mangling macros. (M4INIT_HANDLER): Call m4_install_builtins and/or m4_install_macros. * tests/options.at: Now that init_func is always called, adjust expected debug output. Signed-off-by: Gary V. Vaughan <gary@gnu.org>
* modules: remove support for module unload and refcount.Gary V. Vaughan2013-09-204-248/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Module management is horrifically more complex than it needs to be for the simple purpose of providing a means to implement new builtins using C. Fussing about reference counting or needing to maintain and test a facility to unload modules is an easy 600 lines to cut as a start at simplification. * src/main.c (main): Don't call m4__module_exit to unload all modules just prior to exiting the application. * m4/m4private.h (FINISH_SYMBOL, m4_module:refcount) (m4__module_exit, m4_module_refcount): Remove. (m4__module_next): Rename from this... * m4/m4module.h (m4_module_next): ...to this. Adjust all callers. (M4FINISH_HANDLER, m4_module_finish_func, m4_module_makeresident) (m4_module_refcount, m4_module_unload, m4_module_exit): Remove. * m4/m4module.c (m4__module_next): Rename from this... (m4_module_next): ...to this. (module_remove, m4_module_makeresident, m4_module_unload) (m4_module_exit, m4_module_refcount): Remove. * modules/load.c: Remove. (m4modules): Move from here... * modules/gnu.c (m4modules): ...to here. Update all callers. (M4FINISH_HANDLER(gnu)): Remove. * modules/m4.c (M4INIT_HANDLER(m4)): Remove. * modules/modtest.c (M4FINISH_HANDLER(modtest)): Remove. * modules/shadow.c (M4INIT_HANDLER(shadow)): Rewrite to work without refcount. * Makefile.am (pkglib_LTLIBRARIES): Remove modules/load.la. (modules_load_la_LDFLAGS, modules_load_la_LIBADD): Remove. * tests/modules.at: Remove references to load module, and tests of unload builtin. * tests/options.at: Remove obsolute finish hook and module unload trace output. * doc/m4.texi (Unload, Refcount): Remove. (M4modules): Change module reference from load to gnu. Signed-off-by: Gary V. Vaughan <gary@gnu.org>
* refactor: remove dead M4MODPATH code.Gary V. Vaughan2013-09-203-25/+13
| | | | | | | | | | | * m4/m4private.h (USER_MODULE_PATH_ENV): Remove. * m4/module.c: Correct doc-comment header details. (m4__module_init): Remove PKGLIBEXECDIR and M4MODPATH handling. Move configmake.h include from here... * m4/path.c: ...to here. (m4__include_init): Append PKGLIBDIR to search path. Signed-off-by: Gary V. Vaughan <gary@gnu.org>
* maint: either fix or disable failing syntax-check rules.Gary V. Vaughan2013-09-184-5/+3
| | | | | | | | | | | | | | | | | * cfg.mk (local-checks-to-skip): Skip bindtextdomain until I understand it! (old_NEWS_hash): Update. (exclude_file_name_regexp--sc_prohibit_always_true_header_tests) (exclude_file_name_regexp--sc_prohibit_strncpy) (exclude_file_name_regexp--update_copyright): Exclude failing files. * doc/Makefile.am: Remove trailing blank line. * m4/path.c: Remove trailing whitespace. * doc/m4.texi: Fix some errors flagged by syntax checks. * m4/input.c, m4/macro.c, m4/output.c, m4/stackovf.c: Don't use `main ()', which confuses syntax-checks. Signed-off-by: Gary V. Vaughan <gary@gnu.org>
* build: mark several pure functionsEric Blake2013-09-182-2/+3
| | | | | | | | | Found by using gcc 4.7.0's -Wsuggest-attribute=pure. * m4/system_.h (M4_GNUC_PURE): New macro. * m4/builtin.c (m4_builtin_find_by_name, m4_builtin_find_by_func): Mark pure. Signed-off-by: Eric Blake <eblake@redhat.com>
* maint: prefer STREQ/STRNEQ to strcmp contortions.Gary V. Vaughan2013-09-182-1/+2
| | | | | | | | * m4/m4private (STRNEQ): New macro. * m4/path.c (m4_load_filename): Use it. * src/freeze.c (produce_frozen_state): Likewise. Signed-off-by: Gary V. Vaughan <gary@gnu.org>
* maint: update copyright year.Gary V. Vaughan2013-09-1817-33/+31
| | | | | | | * all files: Run 'make update-copyright' to add 2013 to list of copyright years. Signed-off-by: Gary V. Vaughan <gary@gnu.org>
* maint: clean up compiler warnings.Eric Blake2013-09-171-1/+1
| | | | | | | | * modules/evalparse.c (unary_term): Likewise. * m4/input.c (match_input): Likewise. Also drop useless casts to void. Signed-off-by: Gary V. Vaughan <gary@gnu.org>
* maint: fix build on newer glibc.Eric Blake2013-09-171-0/+2
| | | | | | | | | | | POSIX allows, but does not require, that <fcntl.h> implicitly includes <sys/stat.h>. Until recent glibc, most systems did this implicit inclusion, and m4 was mistakenly relying on it. * m4/output.c (includes): Add <sys/stat.h>. * THANKS: Update. Reported by Todd Rinaldo. Signed-off-by: Eric Blake <eblake@redhat.com>
* Factor load functionality into include builtin.Gary V. Vaughan2013-09-163-69/+212
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * m4/module.c (m4__module_open): Instead of calling lt_dlopenext right away, use the preload hint first incase path searching has been disabled by POSIXLY_CORRECT. Otherwise fallback to a manual path search to override libltdl's algorithm. * m4/m4module.h: Adjust. * m4/path.c (FILE_SUFFIXES): Order to try suffixes in our path search algorithm. (NO_SUFFIXES): Alternatively, how to to search a path without adding file suffixes. (m4_path_search): Add a new suffixes parameter defaulting to NO_SUFFIXES. Adjust all callers. (m4_load_filename): New generic load function that tries to open a matched file first as a module, and if that fails fall back to a (possibly frozen) m4 input file. (m4_fopen): New function with close on exec functionality. * modules/m4.c (include): Use m4_load_filename to with modules or m4 files. Adjust all callers. * modules/load.c (load): Removed this builtin. * src/main.c: Remove Dynamic loading features section, and M4MODPATH support. (long_options): Remove "load-module", "unload-module" and "module-directory" options. (OPTSTRING): Remove 'M' and 'm' options. (process_file): Use m4_load_filename to support module names on the command line. * tests/generate.awk (new_test): Output AT_CHECK_DYNAMIC_MODULE and AT_CHECK_GMP without relying on the (deleted!) -m option. * Makefile.am (TESTS_ENVIRONMENT): No need for abs_top_builddir any more. * doc/m4.texinfo: Update examples. (Dynamic loading features, Load): Removed. (Command line files): Describe how non-option arguments are treated to try to find a matching macro file or dso. (Include): Describe additional dso loading features if a suitable text file cannot be found. (Modules): Updated. * tests/builtins.at, tests/m4.in, tests/modules.at, tests/options.at, others.at: Adjust test cases and calling conventions to new semantics. * modules/modtest.m4, modules/shadow.m4, modules/stdlib.m4, modules/time.m4, modules/time2.m4: Move from here... * examples/modtest.m4, examples/shadow.m4, examples/stdlib.m4, examples/time.m4, examples/time2.m4: ...to here, to prevent a namespace clash with similarly named loadable modules in the modules directory. * NEWS: Updated. Signed-off-by: Gary V. Vaughan <gary@gnu.org>
* Address remaining 'make syntax-check' findings.Eric Blake2010-01-085-6/+9
| | | | | | | | | | | | | | | | | | | | | | | | * gnulib: Update to latest. * Makefile.am (tests/package.m4): Avoid @@ substitution. (src_m4_LDADD): Link with libiconv. * m4/m4private.h (STREQ): New macro. * m4/resyntax.c (m4_regexp_syntax_encode): Use it. * src/main.c (process_file): Likewise. (includes): Drop unused header. * m4/macro.c (m4_arg_equal): Adjust comment. * m4/syntax.c: Likewise. * m4/system_.h: Avoid useless preprocessor parenthesis. * ltdl/m4/stackovf.m4 (M4_SYS_STACKOVF): Likewise. * src/stackovf.c: Likewise. (setup_stackovf_trap): Mark diagnostics. * modules/mpeval.c (includes): Move quotearg.h inclusion... * modules/evalparse.c (includes): ...to where it is used. * cfg.mk (local-checks-to-skip): Exempt tests that cause spurious failures, but first fix what they were intended to detect. (_makefile_at_at_check_exceptions): Allow an exception. Signed-off-by: Eric Blake <ebb9@byu.net> (cherry picked from commit 2f6096389e2047a01618419af3f4471735444520)
* Address 'make sc_error_message_uppercase' failures.Eric Blake2010-01-072-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | * m4/output.c (m4_freeze_diversions): Silence false positive. * src/main.c (main): Use 'warning', not 'Warning', in messages. * m4/utility.c (m4_verror_at_line): Likewise. * doc/m4.texinfo (Operation modes, Macro Arguments, Undefine) (Defn, Pushdef, Indir, Builtin, Ifdef, Ifelse, Dumpdef, Trace) (Debuglen, Debugfile, Dnl, Changeresyntax, Standard Modules) (Index macro, Regexp, Substr, Translit, Patsubst, Format, Incr) (Eval, Mkstemp, Syncoutput, Improved forloop) (Improved fatal_error): Adjust expected output. * tests/builtins.at (define, mkdtemp, mkstemp): Likewise. * tests/freeze.at (loading format 1, reloading unknown builtin): Likewise. * tests/macros.at (Arity and defn, 'Arity, defn, and freeze') (pushdef/popdef): Likewise. * tests/null.err: Likewise. * tests/options.at (deprecated options, POSIXLY_CORRECT) (--fatal-warnings, --regexp-syntax, --syncoutput): Likewise. * tests/others.at (nul character, stdin seekable): Likewise. * tests/modules.at (AT_CHECK_M4_MODTEST, modules: text): Likewise. Signed-off-by: Eric Blake <ebb9@byu.net>
* Address 'make sc_cast_of_argument_to_free' failures.Eric Blake2010-01-074-9/+10
| | | | | | | | | | | | * m4/m4private.h (DELETE): Adjust comment and fix parentheses. * m4/m4.c (m4_delete): Use it to avoid warning. * m4/module.c (install_builtin_table, module_remove): Likewise. * m4/symtab.c (m4_symbol_value_delete, m4_symbol_value_copy): Likewise. * .x-sc_cast_of_argument_to_free: New file. * Makefile.am (syntax_check_exceptions): Distribute exceptions. Signed-off-by: Eric Blake <ebb9@byu.net>
* More whitespace cleanup.Eric Blake2010-01-0713-810/+810
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * HACKING: Nuke trailing whitespace. * examples/WWW/Makefile: Likewise. * examples/WWW/_footer.htm: Likewise. * examples/WWW/_header.htm: Likewise. * examples/WWW/m4lib/bugs.m4: Likewise. * examples/WWW/m4lib/html.m4: Likewise. * examples/WWW/m4lib/menu.m4: Likewise. * examples/WWW/m4lib/visions.m4: Likewise. * examples/esyscmd.m4: Likewise. * examples/fstab.m4: Avoid space-tab. * examples/patsubst.m4: Likewise. * NEWS: Prefer space over tab for alignment. * THANKS: Likewise. * TODO: Likewise. * bootstrap: Likewise. * configure.ac: Likewise. * ltdl/m4/stackovf.m4: 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. * modules/evalparse.c: Likewise. * modules/format.c: Likewise. * modules/gnu.c: Likewise. * modules/import.c: Likewise. * modules/load.c: Likewise. * modules/m4.c: Likewise. * modules/m4.h: Likewise. * modules/modtest.c: Likewise. * modules/mpeval.c: Likewise. * modules/perl.c: Likewise. * modules/shadow.c: Likewise. * modules/stdlib.c: Likewise. * modules/time.c: Likewise. * modules/traditional.c: Likewise. * src/freeze.c: Likewise. * src/main.c: Likewise. * src/stackovf.c: Likewise. * tests/stackovf.test: Likewise. * doc/STYLE: Mention the change. Signed-off-by: Eric Blake <ebb9@byu.net> (cherry picked from commit b30b61aa1be7659c155272135fa17a8d7528f80e)
* Switch to indentation by space, not tab.Eric Blake2010-01-0516-2502/+2502
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Now that gnulib has converted and git has better support for ignoring whitespace differences across this commit, we might as well be consistent with other GNU projects. Done with: t=$'\t' git ls-files \ | grep -vE '(^|/)(.*akefile|ChangeLog|HACKING|.*-aux/.*)|\.(am|mk)$' \ | xargs grep -lE "^ *$t" \ | xargs perl -MText::Tabs -ni -le \ '$m=/^( *\t[ \t]*)(.*)/; print $m ? expand($1) . $2 : $_' followed by tweaks to pass 'make check' again. * .gitmodules: Convert leading tabs to spaces. * TODO: Likewise. * bootstrap: Likewise. * configure.ac: Likewise. * examples/WWW/m4lib/html.m4: Likewise. * examples/WWW/m4lib/layout.m4: Likewise. * examples/WWW/m4lib/menu.m4: Likewise. * ltdl/m4/debug.m4: Likewise. * ltdl/m4/gmp.m4: Likewise. * ltdl/m4/m4-obstack.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/utility.c: Likewise. * modules/evalparse.c: Likewise. * modules/format.c: Likewise. * modules/gnu.c: Likewise. * modules/load.c: Likewise. * modules/m4.c: Likewise. * modules/m4.h: Likewise. * modules/mpeval.c: Likewise. * modules/perl.c: Likewise. * modules/stdlib.c: Likewise. * modules/time.c: Likewise. * src/freeze.c: Likewise. * src/m4.h: Likewise. * src/main.c: Likewise. * src/stackovf.c: Likewise. * tests/builtins.at: Likewise. * tests/freeze.at: Likewise. * tests/generate.awk: Likewise. * tests/modules.at: Likewise. * tests/others.at: Likewise. * tests/stackovf.test: Likewise. * tests/testsuite.at: Likewise. Signed-off-by: Eric Blake <ebb9@byu.net> (cherry picked from commit 180b7d19bf95d2abb21bca587a0684eca69679ad)
* Update copyright year.Eric Blake2010-01-0516-17/+19
| | | | | | | | All files impacted, via 'make update-copyright'. Additionally: * .gitignore: Ignore backup files. Signed-off-by: Eric Blake <ebb9@byu.net> (cherry picked from commit 5f42c4dabb6858601abce7b38ca78f4c3069f301)
* Update to latest gnulib.Eric Blake2010-01-051-1/+2
| | | | | | | | | | | | * gnulib: Update. * ltdl/m4/gnulib-cache.m4: Import xoset. * m4/output.c (includes): Ensure that gnulib oset usage will call xalloc_die on memory failure. * Makefile.am (src/getopt.h): Update snippet from gnulib. (LINK_WARNING_H, ARG_NONNULL_H): New macros. Signed-off-by: Eric Blake <ebb9@byu.net> (cherry picked from commit 43b9828d5bfe5c9be902ad86053e59f3a5ab2dd4)
* Use bitrotate for hashing.Eric Blake2009-06-261-2/+4
| | | | | | | | | * gnulib: Update to latest. * ltdl/m4/gnulib-cache.m4: Import bitrotate module. * m4/hash.c (m4_hash_string_hash): Use it. Signed-off-by: Eric Blake <ebb9@byu.net> (cherry picked from commit 891a0fd44d0666fc0576071ec9866cb2b87490eb)
* Drop .cvsignore and redundant .gitignore files.Eric Blake2009-06-152-22/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * .cvsignore: Delete. We are moving further away from CVS. * build-aux/.cvsignore: Likewise. * doc/.cvsignore: Likewise. * examples/.cvsignore: Likewise. * ltdl/.cvsignore: Likewise. * m4/.cvsignore: Likewise. * modules/.cvsignore: Likewise. * po/.cvsignore: Likewise. * src/.cvsignore: Likewise. * tests/.cvsignore: Likewise. * .gitignore: Consolidate from other files. * build-aux/.gitignore: Delete, now that it is consolidated. * doc/.gitignore: Likewise. * examples/.gitignore: Likewise. * ltdl/.gitignore: Likewise. * m4/.gitignore: Likewise. * modules/.gitignore: Likewise. * po/.gitignore: Likewise. * src/.gitignore: Likewise. * tests/.gitignore: Likewise. * bootstrap: Simplify accordingly. Sync gnulib tree prior to libtoolize, to avoid libtool overwriting config.guess. Signed-off-by: Eric Blake <ebb9@byu.net> (cherry picked from commit 76b384f1d84225d0412d58999d2becc8936dd645)
* Avoid compiler warning.Eric Blake2009-06-151-1/+2
| | | | | | * m4/macro.c (process_macro): Use correct type for isdigit. Signed-off-by: Eric Blake <ebb9@byu.net>
* Use gnulib execute module instead of system(3).Eric Blake2009-03-132-0/+11
| | | | | | | | | | | | | | | * ltdl/m4/gnulib-cache.m4: Import execute module. * m4/utility.c (m4_info_name): New function. * m4/m4module.h (m4_info_name): New prototype. * modules/m4.c (syscmd): Rewrite with execute module. (M4_SYSVAL_EXITBITS, M4_SYSVAL_TERMSIGBITS, m4_sysval): Move computation... * modules/gnu.c (M4_SYSVAL_EXITBITS, M4_SYSVAL_TERMSIGBITS) (esyscmd): ...here. Resolves a failure on AIX, reported by Gary V. Vaughan. Signed-off-by: Eric Blake <ebb9@byu.net> (cherry picked from commit 5d2f4a97b5e56a9bd0ce543c3f74ce3084808fe6)
* Prefer buffer over byte operations.Eric Blake2009-02-182-23/+27
| | | | | | | | | | | | * modules/format.c (format): Use memchr for speed. * modules/gnu.c (substitute): Likewise. * m4/macro.c (locate_dollar): Inline into only caller... (process_macro): ...and rearrange for readability. * m4/input.c (consume_buffer): Allow C++ compilation. * doc/m4.texinfo (Changesyntax): Enhance test. Signed-off-by: Eric Blake <ebb9@byu.net> (cherry picked from commit 45a154e6d70517bf1b837715aae2fe366c9c1116)
* Avoid risk of stack overflow.Eric Blake2009-02-181-4/+4
| | | | | | | | * m4/output.c (insert_file): Avoid stack allocation of large buffer. Signed-off-by: Eric Blake <ebb9@byu.net> (cherry picked from commit 01f216c3c98d41db7878b18c93d23e8dc38d8643)
* Improve handling of $ in syntax table.Eric Blake2009-02-185-65/+115
| | | | | | | | | | | | | | | | | | | | * m4/m4module.h (m4_is_syntax_single_dollar): New function. (M4_SYNTAX_DOLLAR, M4_SYNTAX_LBRACE, M4_SYNTAX_RBRACE): Change to be context rather than basic syntax categories. (M4_SYNTAX_MASKS): Adjust macro. * m4/m4private.h (struct m4_syntax_table): Add dollar and is_single_dollar members. (m4_is_syntax_single_dollar): Add fast alternative. * m4/syntax.c (m4_syntax_create, reset_syntax_set): Adjust to account for change to context categories. (m4_set_syntax): Manage is_single_dollar. (m4_is_syntax_single_dollar): New function. * m4/macro.c (locate_dollar): New helper function. (process_macro): Use it to speed up macro expansion. * m4/input.c (m4__next_token): Adjust client. * doc/m4.texinfo (Changesyntax): Document this. Signed-off-by: Eric Blake <ebb9@byu.net>
* Stage 29b: Process quotes and comments by buffer, not bytes.Eric Blake2009-02-171-3/+98
| | | | | | | | | * ltdl/m4/gnulib-cache.m4: Import memchr2 module. * m4/input.c (m4__next_token): Add buffer reads to quote and comment parsing. * NEWS: Document this. Signed-off-by: Eric Blake <ebb9@byu.net>
* Stage 29a: Process dnl and macro names by buffer, not bytes.Eric Blake2009-02-161-36/+281
| | | | | | | | | | | | | | | | | | * ltdl/m4/gnulib-cache.m4: Import freadptr and freadseek modules. * m4/input.c (struct input_funcs): Add virtual functions buffer_func and consume_func. (file_buffer, file_consume, string_buffer, string_consume) (composite_buffer, composite_consume, eof_buffer): Implement them. (file_funcs, string_funcs, composite_funcs, eof_funcs): Update vtables accordingly. (buffer_retry): New sentinel. (next_buffer, consume_buffer): New functions. (m4_skip_line, match_input, consume_syntax): Use them for faster parsing. Suggested by Bruno Haible. Signed-off-by: Eric Blake <ebb9@byu.net>
* Unify single and multi-character delimiter handling.Eric Blake2009-02-162-149/+82
| | | | | | | | | | | * m4/input.c (MATCH): Add a parameter. (m4__next_token): Simplify logic and reduce redundancy. (m4__next_token_is_open): Adjust caller. * m4/syntax.c (m4_set_comment, m4_set_quotes): Handle delimiters of differing lengths. (m4_set_syntax): Recognize restoration of single delimiters. Signed-off-by: Eric Blake <ebb9@byu.net>
* Revamp changesyntax vs. changequote interactions.Eric Blake2009-02-164-247/+232
| | | | | | | | | | | | | | | | | | | | | | | | | | * m4/m4module.h (M4_SYNTAX_VALUE): Delete unused macro. (M4_SYNTAX_SUSPECT): New macro. * m4/m4private.h (struct m4_syntax_table): Add suspect field. * m4/syntax.c (check_is_single_quotes, check_is_single_comments) (check_is_macro_escaped): Delete, by inlining body... (m4_set_syntax): ...into here. Improves handling between changesyntax and changequote/changecom. (add_syntax_set, subtract_syntax_set, set_syntax_set): Simplify, and let suspect field track needed cleanup. (m4_set_quotes, m4_set_comment): Adjust meaning of is_single_quotes and is_single_comment flags to always be true if only one delimiter exists, regardless of its length. Ensure that the syntax categories M4_SYNTAX_LQUOTE and M4_SYNTAX_BCOMM are only used on 1-byte delimiters. (add_syntax_attribute, remove_syntax_attribute): Change signature to allow the use of fewer casts. Adjust the suspect field when necessary. (m4_reset_syntax, set_quote_age): Adjust callers. * m4/input.c (m4__next_token, m4__next_token_is_open): Simplify callers. * doc/m4.texinfo (Changesyntax): Update documentation and tests. Signed-off-by: Eric Blake <ebb9@byu.net>
* Fix regression in multicharacter quotes, from 2008-01-26.Eric Blake2009-02-161-10/+10
| | | | | | | * m4/input.c (m4__next_token): Fix typo. * tests/builtins.at (changequote): Enhance test. Signed-off-by: Eric Blake <ebb9@byu.net>
* Speed up parsing when detecting input file change.Eric Blake2009-02-131-2/+3
| | | | | | | * m4/input.c (next_char): Clear input_change flag. Bug introduced 2006-10-25. Signed-off-by: Eric Blake <ebb9@byu.net>
* Stage 28c: Warn on embedded NUL in remaining cases.Eric Blake2009-02-114-21/+34
| | | | | | | | | | | | | | | | | | | | | | * m4/m4module.h (m4_debug_decode, m4_parse_truth_arg): Add parameter. * m4/macro.c (m4_macro_call): Improve diagnostic. * modules/m4.c (defn): Likewise. * m4/debug.c (m4_debug_decode): Handle embedded NUL. * m4/utility.c (m4_parse_truth_arg): Likewise. * modules/format.c (arg_int, arg_long, arg_double): Likewise. (arg_string): New function. (ARG_INT, ARG_LONG, ARG_STR, ARG_DOUBLE): Update callers. * src/main.c (main): Likewise. * src/freeze.c (reload_frozen_state): Likewise. * modules/gnu.c (debugmode, syncoutput): Likewise. * tests/options.at (--regexp-syntax): Adjust test. * tests/freeze.at (reloading nul): Likewise. * tests/null.m4: Likewise. * tests/null.out: Likewise. * tests/null.err: Likewise. Signed-off-by: Eric Blake <ebb9@byu.net>
* Stage 28b: Warn on embedded NUL in file arguments.Eric Blake2009-02-111-3/+4
| | | | | | | | | | | | | | * m4/path.c (m4_path_search): Quote file names in message. * modules/m4.c (syscmd, include, m4_make_temp): Handle embedded NUL. * modules/gnu.c (debugfile, esyscmd): Likewise. * tests/others.at (nul character): Adjust test. * tests/builtins.at (mkdtemp, mkstemp): Likewise. * tests/null.m4: Likewise. * tests/null.out: Likewise. * tests/null.err: Likewise. Signed-off-by: Eric Blake <ebb9@byu.net>
* Stage 28a: Warn on embedded NUL in numeric arguments.Eric Blake2009-02-112-11/+17
| | | | | | | | | | | | | | | | | | | * m4/m4module.h (m4_numeric_arg): Adjust prototype. * m4/utility.c (m4_numeric_arg): Add parameter. * modules/gnu.c (debuglen): Adjust callers. * modules/m4.c (incr, decr, divert, undivert, m4exit, substr) (index): Likewise. * modules/evalparse.c (m4_evaluate): Likewise. * modules/stdlib.c (setenv, getpwuid, srand): Likewise. * modules/time.c (ctime, gmtime, localtime, mktime, strftime): Likewise. * doc/m4.texinfo (Changesyntax): Fix typo. * tests/others.at (nul character): Adjust test. * tests/null.m4: Likewise. * tests/null.out: Likewise. * tests/null.err: Likewise. Signed-off-by: Eric Blake <ebb9@byu.net>
* Add debugmode(o) to control dumpdef output location.Eric Blake2008-12-232-1/+7
| | | | | | | | | | | | | | | | | * m4/m4module.h (M4_DEBUG_TRACE_OUTPUT_DUMPDEF): New enumerator. (M4_DEBUG_TRACE_VERBOSE): Update. * m4/debug.c (m4_debug_decode): Support new debug option. * src/freeze.c (produce_debugmode_state): Likewise. * modules/m4.c (dumpdef): When set, force dumpdef to stderr rather than the debug file. * src/main.c (usage): Document it. * doc/m4.texinfo (Debugmode, Dumpdef, Debugging options) (Debugfile): Likewise. * NEWS: Likewise. Based on an autoconf bug report by Paolo Bonzini. Signed-off-by: Eric Blake <ebb9@byu.net> (cherry picked from commit df6bfeeaac6bdc1ef8e5406c6ac051af2c10d0d8)
* Double size of temp file cache.Eric Blake2008-12-151-21/+67
| | | | | | | | | | | * m4/output.c (tmp_file, tmp_file_owner): Split... (tmp_file1, tmp_file2, tmp_file1_owner, tmp_file2_owner): ...into two variables. (tmp_file2_recent): New variable. (m4_tmpopen, m4_tmpclose, m4_tmpremove, m4_tmprename) (m4_output_exit): Adjust callers. Signed-off-by: Eric Blake <ebb9@byu.net>
* Use fewer seeks on cached files.Eric Blake2008-12-151-17/+21
| | | | | | | | | * m4/output.c (m4_tmpfile): Use write, not append mode. (m4_tmpopen): Add parameter to decide when to skip seeks. (m4_tmprename, m4_make_diversion, insert_diversion_helper) (m4_freeze_diversions): Adjust callers. Signed-off-by: Eric Blake <ebb9@byu.net>
* Cache most recently spilled diversion.Eric Blake2008-12-151-8/+57
| | | | | | | | | | | | | | | | | | * m4/output.c (tmp_file, tmp_file_owner): New variables, for 1-deep cache of spilled diversions. (m4_tmpfile): Open in append mode, since we might revisit diversion without closing it now. (m4_tmpopen): Check cache first. (m4_tmpclose): Update cache, rather than closing. Add parameter. (m4_tmpremove): Close cache before removing. (m4_tmprename): Deal with open files when renaming. (m4_output_exit): Close cache before exiting. (make_room_for, m4_make_diversion, insert_diversion_helper): Adjust callers. * ltdl/m4/m4-rename.m4 (M4_RENAME): New file. * configure.ac (M4_RENAME): Invoke it. Signed-off-by: Eric Blake <ebb9@byu.net>
* Correctly track size of in-memory diversions.Eric Blake2008-12-151-0/+6
| | | | | | | * m4/output.c (insert_diversion_helper): Correctly track total in-memory diversion size after undivert. Signed-off-by: Eric Blake <ebb9@byu.net>
* Avoid quadratic behavior for some cases of divert/undivert.Eric Blake2008-12-151-52/+118
| | | | | | | | | | | | | | | * m4/output.c (struct m4_diversion): Improve comments. (m4_tmpname, m4_make_diversion): Strengthen preconditions. (m4_tmprename): New function. (m4_output_init, m4_output_exit): Move after internal functions. (make_room_for): Don't bother copying uninitialized bytes. (insert_diversion_helper): Transfer metadata, rather than copying contents, when undiverting into a previously unused diversion. * tests/builtins.at (divert): Add a check to the test. * doc/m4.texinfo (Undivert): Enhance test. * NEWS: Document the speedup. Signed-off-by: Eric Blake <ebb9@byu.net>
* Tweak error message on command line failure.Eric Blake2008-09-253-6/+10
| | | | | | | | | | | | | | | | | | * m4/m4private.h (includes): Use "quotearg.h". * src/main.c (process_file, main): Use nicer quotes for file name in error messages. * m4/input.c (file_clean, m4_push_file): Likewise. * m4/module.c (m4__module_open): Likewise. * src/freeze.c (produce_frozen_state, reload_frozen_state): Likewise. * modules/gnu.c (debugfile): Likewise. * modules/m4.c (undivert, include): Likewise. * tests/others.at (directory, stdin closed): Update tests. * tests/options.at (file names, --debugmode): Likewise. * doc/m4.texinfo (Debugmode): Likewise. Signed-off-by: Eric Blake <ebb9@byu.net> (cherry picked from commit 5116db0fcd37e4480062b4819dca17a98a7890d7)
* Unify error handling for reading directories.Eric Blake2008-09-251-9/+25
| | | | | | | | | | | * m4/path.c (m4_path_search): Factor open attempts... (m4_fopen): ...into new function, to reject directories. * tests/others.at (directory): Enhance test. * doc/m4.texinfo (Include): Document that directories cannot be input files. Signed-off-by: Eric Blake <ebb9@byu.net> (cherry picked from commit eed62f0d2729c243d7c081c48d789f9d86fa340f)
* Typos in source code comments.Ralf Wildenhues2008-09-011-1/+1
| | | | | | | | * modules/m4.c: Fix typos in comments. * m4/input.c: Likewise. * src/main.c: Likewise. Signed-off-by: Eric Blake <ebb9@byu.net>
* Allow debugmode control over whether defn(undef) warns.Eric Blake2008-08-234-5/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * ltdl/m4/gnulib-cache.m4: Import verify module. * m4/m4module.h (M4_DEBUG_TRACE_DEREF, M4_DEBUG_TRACE_INITIAL): New values. (M4_DEBUG_TRACE_VERBOSE, M4_DEBUG_TRACE_DEFAULT): Adjust. * m4/m4.c (m4_create): Start with debugmode = d. * src/main.c (usage): Mention this. (main): Let -E impact debug mode. * m4/utility.c (m4_symbol_value_lookup): Squelch undefined warning if flag is clear. * modules/gnu.c (builtin, inder): Likewise. * m4/debug.c (m4_debug_decode): Parse new mode. * src/freeze.c (produce_debugmode_state): Accomodate new mode. * doc/m4.texinfo (Debugging options): Mention change in the default behavior. (Debugmode): Mention new flag d. (Operation modes): Mention interaction with -E. (Undefine, Defn, Pushdef, Indir, Builtin, Dumpdef): Document and test its effect. * tests/options.at (--debugmode): Update tests. * tests/freeze.at (reloading debugmode): Likewise. * NEWS: Document this. Reported by Ralf Wildenhues; without this patch, M4 1.6+ would be incompatible with Autoconf 2.62. Signed-off-by: Eric Blake <ebb9@byu.net>
* Improve --debugmode behavior.Eric Blake2008-08-222-4/+5
| | | | | | | | | | | | | * m4/m4module.h (m4_debug_decode): Simplify interface. * m4/debug.c (m4_debug_decode): Remove parameter, and handle setting the new value. * modules/gnu.c (debugmode): Adjust caller. * src/freeze.c (reload_frozen_state): Likewise. * src/main.c (main): Likewise. (usage): Fix default for --debug. * doc/m4.texinfo (Debugging options): Add an example. Signed-off-by: Eric Blake <ebb9@byu.net>