diff options
author | Eric Blake <ebb9@byu.net> | 2008-02-11 07:14:20 -0700 |
---|---|---|
committer | Eric Blake <ebb9@byu.net> | 2008-02-11 13:33:08 -0700 |
commit | 4af40c4d6f65e3d311ef4643b6b3bdb9729a9db6 (patch) | |
tree | df8c65019d968f7175a1d837819cc8beb74c8f7a | |
parent | 7a7a1413755c74b416295b13fe90eef3bffa7345 (diff) | |
download | m4-4af40c4d6f65e3d311ef4643b6b3bdb9729a9db6.tar.gz |
Allow builtin text macros to specify number of arguments.
* m4/m4module.h (struct m4_macro): Add argument limits to builtin
text macros.
* m4/module.c (install_macro_table): Allow text macros to warn on
extra arguments.
* modules/gnu.c (m4_macro_table): Update all clients.
* modules/load.c (m4_macro_table): Likewise.
* modules/mpeval.c (m4_macro_table): Likewise.
* modules/perl.c (m4_macro_table): Likewise.
* modules/shadow.c (m4_macro_table): Likewise.
* modules/traditional.c (m4_macro_table): Likewise.
* modules/modtest.c (m4_macro_table): Likewise. Also add text
macros, for testing this.
* doc/m4.texinfo (Standard Modules): Update text, and enhance
test.
* tests/modules.at (modules: text): New test.
Signed-off-by: Eric Blake <ebb9@byu.net>
-rw-r--r-- | ChangeLog | 17 | ||||
-rw-r--r-- | doc/m4.texinfo | 24 | ||||
-rw-r--r-- | m4/m4module.h | 3 | ||||
-rw-r--r-- | m4/module.c | 7 | ||||
-rw-r--r-- | modules/gnu.c | 14 | ||||
-rw-r--r-- | modules/load.c | 9 | ||||
-rw-r--r-- | modules/modtest.c | 12 | ||||
-rw-r--r-- | modules/mpeval.c | 9 | ||||
-rw-r--r-- | modules/perl.c | 6 | ||||
-rw-r--r-- | modules/shadow.c | 9 | ||||
-rw-r--r-- | modules/traditional.c | 14 | ||||
-rw-r--r-- | tests/modules.at | 44 |
12 files changed, 129 insertions, 39 deletions
@@ -1,5 +1,22 @@ 2008-02-11 Eric Blake <ebb9@byu.net> + Allow builtin text macros to specify number of arguments. + * m4/m4module.h (struct m4_macro): Add argument limits to builtin + text macros. + * m4/module.c (install_macro_table): Allow text macros to warn on + extra arguments. + * modules/gnu.c (m4_macro_table): Update all clients. + * modules/load.c (m4_macro_table): Likewise. + * modules/mpeval.c (m4_macro_table): Likewise. + * modules/perl.c (m4_macro_table): Likewise. + * modules/shadow.c (m4_macro_table): Likewise. + * modules/traditional.c (m4_macro_table): Likewise. + * modules/modtest.c (m4_macro_table): Likewise. Also add text + macros, for testing this. + * doc/m4.texinfo (Standard Modules): Update text, and enhance + test. + * tests/modules.at (modules: text): New test. + Fix regression in command line -D option, from 2006-08-25. * m4/m4private.h (m4_symbol_value_create): Delete fast accessor. * m4/m4module.h: Fix typo. diff --git a/doc/m4.texinfo b/doc/m4.texinfo index 642c14eb..357358ff 100644 --- a/doc/m4.texinfo +++ b/doc/m4.texinfo @@ -5804,7 +5804,9 @@ refcount(`NoSuchModule') @acronym{GNU} @code{m4} ships with several bundled modules as standard. By convention, these modules define a text macro that can be tested with @code{ifdef} when they are loaded; only the @code{m4} module lacks -this feature test macro. +this feature test macro, since it is not permitted by @acronym{POSIX}. +Each of the feature test macros are intended to be used without +arguments. @table @code @item m4 @@ -5823,8 +5825,8 @@ module is loaded. @end deffn @deffn {Macro (gnu)} __m4_version__ -Expands to a quoted string containing the release version number of the -running @acronym{GNU} @code{m4} executable. +Expands to an unquoted string containing the release version number of +the running @acronym{GNU} @code{m4} executable. @end deffn This module is always loaded, unless the @option{-G} command line @@ -5871,6 +5873,9 @@ __gnu__-__traditional__ @result{}-__traditional__ ifdef(`__gnu__', `Extensions are active', `Minimal features') @result{}Extensions are active +__gnu__(`ignored') +@error{}m4:stdin:3: Warning: __gnu__: extra arguments ignored: 1 > 0 +@result{} @end example @comment options: -G @@ -5882,6 +5887,19 @@ ifdef(`__gnu__', `Extensions are active', `Minimal features') @result{}Minimal features @end example +Since the version string is unquoted and can potentially contain macro +names (consider the beta release @samp{1.9b}, or the use of +@code{changesyntax}), the @code{__m4_version__} macro should generally +be used via @code{defn} rather than directly invoked. + +@comment This test is excluded from the testsuite since it depends on a +@comment texinfo macro; but builtin.at covers the same thing. +@comment ignore +@example +defn(`__m4_version__') +@result{}@value{VERSION} +@end example + @node Text handling @chapter Macros for text handling diff --git a/m4/m4module.h b/m4/m4module.h index 5f144be2..a807e70b 100644 --- a/m4/m4module.h +++ b/m4/m4module.h @@ -75,6 +75,9 @@ struct m4_macro { const char *name; const char *value; + size_t min_args; /* 0-based minimum number of arguments */ + /* max arguments, SIZE_MAX if unlimited; must be >= min_args */ + size_t max_args; }; /* Describe a pair of strings, such as begin and end quotes. */ diff --git a/m4/module.c b/m4/module.c index 901a48f7..7ef6ab32 100644 --- a/m4/module.c +++ b/m4/module.c @@ -1,6 +1,6 @@ /* GNU m4 -- A simple macro processor Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1998, 1999, 2002, 2003, - 2004, 2005, 2006, 2007 Free Software Foundation, Inc. + 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. This file is part of GNU M4. @@ -195,9 +195,14 @@ install_macro_table (m4 *context, m4_module *module) m4_symbol_value *value = m4_symbol_value_create (); size_t len = strlen (mp->value); + /* Sanity check that builtins meet the required interface. */ + assert (mp->min_args <= mp->max_args); + m4_set_symbol_value_text (value, xmemdup (mp->value, len + 1), len, 0); VALUE_MODULE (value) = module; + VALUE_MIN_ARGS (value) = mp->min_args; + VALUE_MAX_ARGS (value) = mp->max_args; m4_symbol_pushdef (M4SYMTAB, mp->name, value); } diff --git a/modules/gnu.c b/modules/gnu.c index 1f6bf299..10fb0acb 100644 --- a/modules/gnu.c +++ b/modules/gnu.c @@ -85,20 +85,20 @@ m4_builtin m4_builtin_table[] = /* A table for mapping m4 symbol names to simple expansion text. */ m4_macro m4_macro_table[] = { - /* name text */ + /* name text min max */ #if UNIX - { "__unix__", "" }, + { "__unix__", "", 0, 0 }, #elif W32_NATIVE - { "__windows__", "" }, + { "__windows__", "", 0, 0 }, #elif OS2 - { "__os2__", "" }, + { "__os2__", "", 0, 0 }, #else # warning Platform macro not provided #endif - { "__gnu__", "" }, - { "__m4_version__", VERSION/**/TIMESTAMP }, + { "__gnu__", "", 0, 0 }, + { "__m4_version__", VERSION/**/TIMESTAMP, 0, 0 }, - { NULL, NULL }, + { NULL, NULL, 0, 0 }, }; diff --git a/modules/load.c b/modules/load.c index 4ee1cc62..5ea72424 100644 --- a/modules/load.c +++ b/modules/load.c @@ -1,5 +1,6 @@ /* GNU m4 -- A simple macro processor - Copyright (C) 2000, 2005, 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 2000, 2005, 2006, 2007, 2008 Free Software + Foundation, Inc. This file is part of GNU M4. @@ -65,9 +66,9 @@ m4_builtin m4_builtin_table[] = /* A table for mapping m4 symbol names to simple expansion text. */ m4_macro m4_macro_table[] = { - /* name text */ - { "__load__", "" }, - { NULL, NULL }, + /* name text min max */ + { "__load__", "", 0, 0 }, + { NULL, NULL, 0, 0 }, }; diff --git a/modules/modtest.c b/modules/modtest.c index 022a2efa..f2d39eac 100644 --- a/modules/modtest.c +++ b/modules/modtest.c @@ -1,6 +1,6 @@ /* GNU m4 -- A simple macro processor - Copyright (C) 1999, 2000, 2001, 2003, 2004, 2006, 2007 Free Software - Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2003, 2004, 2006, 2007, 2008 Free + Software Foundation, Inc. This file is part of GNU M4. @@ -61,9 +61,11 @@ m4_builtin m4_builtin_table[] = m4_macro m4_macro_table[] = { - /* name text */ - { "__test__", "`modtest'" }, - { NULL, NULL }, + /* name text min max */ + { "__test__", "`modtest'", 0, 0 }, + { "onearg", "$1", 1, 1 }, + { "manyargs", "$@", 0, SIZE_MAX }, + { NULL, NULL, 0, 0 }, }; diff --git a/modules/mpeval.c b/modules/mpeval.c index e70eb091..ab9a040f 100644 --- a/modules/mpeval.c +++ b/modules/mpeval.c @@ -1,5 +1,6 @@ /* GNU m4 -- A simple macro processor - Copyright (C) 2000, 2001, 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 2000, 2001, 2006, 2007, 2008 Free Software + Foundation, Inc. This file is part of GNU M4. @@ -123,9 +124,9 @@ m4_builtin m4_builtin_table[] = /* A table for mapping m4 symbol names to simple expansion text. */ m4_macro m4_macro_table[] = { - /* name text */ - { "__mpeval__", "" }, - { NULL, NULL }, + /* name text min max */ + { "__mpeval__", "", 0, 0 }, + { NULL, NULL, 0, 0 }, }; diff --git a/modules/perl.c b/modules/perl.c index 46cf2cde..61db8032 100644 --- a/modules/perl.c +++ b/modules/perl.c @@ -64,9 +64,9 @@ m4_builtin m4_builtin_table[] = /* A table for mapping m4 symbol names to simple expansion text. */ m4_macro m4_macro_table[] = { - /* name text */ - { "__perleval__", "" }, - { NULL, NULL }, + /* name text min max */ + { "__perleval__", "", 0, 0 }, + { NULL, NULL, 0, 0 }, }; diff --git a/modules/shadow.c b/modules/shadow.c index 3698b4f0..1a15798f 100644 --- a/modules/shadow.c +++ b/modules/shadow.c @@ -1,5 +1,6 @@ /* GNU m4 -- A simple macro processor - Copyright (C) 1999, 2000, 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2006, 2007, 2008 Free Software + Foundation, Inc. This file is part of GNU M4. @@ -58,9 +59,9 @@ m4_builtin m4_builtin_table[] = m4_macro m4_macro_table[] = { - /* name text */ - { "__test__", "`shadow'" }, - { NULL, NULL }, + /* name text min max */ + { "__test__", "`shadow'", 0, 0 }, + { NULL, NULL, 0, 0 }, }; diff --git a/modules/traditional.c b/modules/traditional.c index 9fc2e818..13a112d2 100644 --- a/modules/traditional.c +++ b/modules/traditional.c @@ -1,5 +1,5 @@ /* GNU m4 -- A simple macro processor - Copyright (C) 2000, 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 2000, 2006, 2007, 2008 Free Software Foundation, Inc. This file is part of GNU M4. @@ -33,16 +33,16 @@ /* A table for mapping m4 symbol names to simple expansion text. */ m4_macro m4_macro_table[] = { - /* name text */ + /* name text min max */ #if UNIX - { "unix", "" }, + { "unix", "", 0, 0 }, #elif W32_NATIVE - { "windows", "" }, + { "windows", "", 0, 0 }, #elif OS2 - { "os2", "" }, + { "os2", "", 0, 0 }, #else # warning Platform macro not provided #endif - { "__traditional__", "" }, - { NULL, NULL }, + { "__traditional__", "", 0, 0 }, + { NULL, NULL, 0, 0 }, }; diff --git a/tests/modules.at b/tests/modules.at index 86f13888..0d818481 100644 --- a/tests/modules.at +++ b/tests/modules.at @@ -1,5 +1,5 @@ # Hand crafted tests for GNU M4. -*- Autotest -*- -# Copyright (C) 2001, 2006, 2007 Free Software Foundation, Inc. +# Copyright (C) 2001, 2006, 2007, 2008 Free Software Foundation, Inc. # This file is part of GNU M4. # @@ -422,6 +422,48 @@ AT_CLEANUP +## ------------------- ## +## text module symbols ## +## ------------------- ## + +# Support text macros with requested numbers of parameters. + +AT_SETUP([modules: text]) +AT_CHECK_DYNAMIC_MODULE + +AT_DATA([input.m4], +[[__test__ +__test__(1) +__test__(1,2) +onearg +onearg(1) +onearg(1,2) +manyargs +manyargs(1) +manyargs(1,2) +]]) + +AT_CHECK_M4([-M "$abs_builddir" -m modtest input.m4], [0], +[[modtest +modtest +modtest + +1 +1 + +1 +1,2 +]], [[Test module loaded. +m4:input.m4:2: Warning: __test__: extra arguments ignored: 1 > 0 +m4:input.m4:3: Warning: __test__: extra arguments ignored: 2 > 0 +m4:input.m4:4: Warning: onearg: too few arguments: 0 < 1 +m4:input.m4:6: Warning: onearg: extra arguments ignored: 2 > 1 +Test module unloaded. +]]) + +AT_CLEANUP + + ## -------------------- ## ## trace module symbols ## ## -------------------- ## |