[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: branch-1_4 debian bug 96075 - blind macros
From: |
Eric Blake |
Subject: |
Re: branch-1_4 debian bug 96075 - blind macros |
Date: |
Tue, 15 Aug 2006 07:51:13 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Thunderbird/1.5.0.5 Mnenhy/0.7.4.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Eric Blake on 7/31/2006 7:19 AM:
> http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=96075 complains:
>
>>> "format", "divert" and "shift" are all English words that
>>> might occur in text. And they are all recognised without
>>> arguments - the default behaviour of m4 is to make these
>>> words disappear
>
>
> However, this patch will do what you request (as well as for errprint and
> m4wrap). I will need some feedback before applying this patch to 1.4.6;
> otherwise, you will have to wait for m4 2.0. Plus I would need to
> document the change in the .texinfo and NEWS.
I got no feedback, but decided to apply anyways. Here is the patch I used:
2006-08-15 Eric Blake <address@hidden>
* src/builtin.c (m4_m4wrap, m4_errprint, m4_shift): Make blind,
per debian bug 96075.
* doc/m4.texinfo (Loops, M4wrap, Errprint): Document this change.
(Changeword): Don't use shift as an example of a swallowed word.
(Divert): Discuss fact that divert is an English word.
- --
Life is short - so eat dessert first!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFE4dFR84KuGfSFAYARAhz9AJ92Gd4IcYuMAL3ojuWhXKCZ5WiPbwCePHUn
lomRc5wHtIkfPdI6tRunk3w=
=OCN7
-----END PGP SIGNATURE-----
Index: NEWS
===================================================================
RCS file: /sources/m4/m4/NEWS,v
retrieving revision 1.1.1.1.2.51
diff -u -p -r1.1.1.1.2.51 NEWS
--- NEWS 9 Aug 2006 12:28:00 -0000 1.1.1.1.2.51
+++ NEWS 15 Aug 2006 13:47:10 -0000
@@ -28,6 +28,8 @@ Version 1.4.6 - ?? 2006, by ?? (CVS ver
* The new macro __program__ is added, which allows the input file to issue
an error message that resembles messages from m4. Warning and error
messages have been reformatted to comply with GNU Coding Standards.
+* The errprint, m4wrap, and shift macros are now recognized only with
+ arguments.
Version 1.4.5 - 15 July 2006, by Eric Blake (CVS version 1.4.4c)
@@ -318,5 +320,6 @@ Version 0.50 - January 1990, by Rene' Se
* Initial beta release.
Local Variables:
+mode: outline
fill-column: 75
End:
Index: doc/m4.texinfo
===================================================================
RCS file: /sources/m4/m4/doc/m4.texinfo,v
retrieving revision 1.1.1.1.2.65
diff -u -p -r1.1.1.1.2.65 m4.texinfo
--- doc/m4.texinfo 14 Aug 2006 13:07:14 -0000 1.1.1.1.2.65
+++ doc/m4.texinfo 15 Aug 2006 13:47:11 -0000
@@ -903,7 +903,8 @@ call is not triggered. This solves the
specific provision.
There is also a command line option (@option{--prefix-builtins}, or
address@hidden) which requires all builtin macro names to be prefixed
address@hidden, @pxref{Invoking m4}) which requires all builtin macro names
+to be prefixed
by @samp{m4_} for them to be recognized. The option has no effect
whatsoever on user defined macros. For example, with this option,
one has to write @code{m4_dnl} and even @code{m4_m4exit}.
@@ -1010,8 +1011,8 @@ there are too many arguments, the excess
Normally @code{m4} will issue warnings if a builtin macro is called
with an inappropriate number of arguments, but it can be suppressed with
-the @option{-Q} command line option. For user defined macros, there is no
-check of the number of arguments given.
+the @option{-Q} command line option (@pxref{Invoking m4}). For user
+defined macros, there is no check of the number of arguments given.
Macros are expanded normally during argument collection, and whatever
commas, quotes and parentheses that might show up in the resulting
@@ -1847,11 +1848,13 @@ be used for iterating through the actual
@deffn Builtin shift (@dots{})
Takes any number of arguments, and expands to all but the first
argument, separated by commas, with each argument quoted.
+
+The macro @code{shift} is recognized only with parameters.
@end deffn
@example
shift
address@hidden
address@hidden
shift(`bar')
@result{}
shift(`foo', `bar', `baz')
@@ -2061,7 +2064,7 @@ The number between dashes is the depth o
of the time, signifying an expansion at the outermost level, but it
increases when macro arguments contain unquoted macro calls. The
maximum number that will appear between dashes is controlled by the
-option @option{--nesting-limit}.
+option @option{--nesting-limit} (@pxref{Invoking m4}).
Tracing by name is an attribute that is preserved whether the macro is
defined or not. This allows the @option{-t} option to select macros to
@@ -2123,8 +2126,9 @@ display.
@cindex controlling debugging output
@cindex debugging output, controlling
-The @option{-d} option to @code{m4} controls the amount of details
-presented, when using the macros described in the preceding sections.
+The @option{-d} option to @code{m4} (@pxref{Invoking m4}) controls the
+amount of details presented, when using the macros described in the
+preceding sections.
The @var{flags} following the option can be one or more of the
following:
@@ -2224,7 +2228,8 @@ foo
@cindex output, saving debugging
@cindex @acronym{GNU} extensions
Debug and tracing output can be redirected to files using either the
address@hidden option to @code{m4}, or with the builtin macro @code{debugfile}:
address@hidden option to @code{m4} (@pxref{Invoking m4}, or with the
+builtin macro @code{debugfile}:
@deffn Builtin debugfile (@ovar{file})
Sends all further debug and trace output to @var{file}. If
@@ -2711,9 +2716,8 @@ changeword(`#\([_a-zA-Z0-9]*\)')
@end example
@code{m4} now requires a @samp{#} mark at the beginning of every
-macro invocation, so one can use @code{m4} to preprocess shell
-scripts without getting @code{shift} commands swallowed, and plain
-text without losing various common words.
+macro invocation, so one can use @code{m4} to preprocess plain
+text without losing various words like @samp{divert}.
In @code{m4}, macro substitution is based on text, while in @TeX{}, it
is based on tokens. @code{changeword} can throw this difference into
@@ -2781,6 +2785,7 @@ reached. As a @acronym{GNU} extension,
concatenated with a space to the @var{string}.
The expansion of @code{m4wrap} is void.
+The macro @code{m4wrap} is recognized only with parameters.
@end deffn
@example
@@ -2896,9 +2901,9 @@ sinclude()
@end example
The rest of this section assumes that @code{m4} is invoked with the
address@hidden option pointing to the @file{examples} directory shipped as
-part of the @acronym{GNU} @code{m4} package. The file
address@hidden/@/incl.m4} in the distribution contains the lines:
address@hidden option (@pxref{Invoking m4}) pointing to the @file{examples}
+directory shipped as part of the @acronym{GNU} @code{m4} package. The
+file @file{examples/@/incl.m4} in the distribution contains the lines:
@comment ignore
@example
Include file start
@@ -2956,7 +2961,8 @@ than the current working directory.
If a file is not found in the current working directory, and the file
name is not absolute, the file will be looked for in a specified search
path. First, the directories specified with the @option{-I} option will
-be searched, in the order found on the command line. Second, if the
+be searched, in the order found on the command line (@pxref{Invoking
+m4}). Second, if the
@env{M4PATH} environment variable is set, it is expected to contain a
colon-separated list of directories, which will be searched in order.
@@ -3054,6 +3060,26 @@ divert
This is a common programming idiom in @code{m4}.
+Note that @code{divert} is an English word, but also an active macro
+without arguments. When processing plain text, the word might appear in
+normal text and be unintentionally swallowed as a macro invocation. One
+way to avoid this is to use the @option{-P} option to rename all
+builtins (@pxref{Invoking m4}). Another is to write a wrapper that
+requires a parameter to be recognized.
+
address@hidden
+We decided to divert the stream for irrigation.
address@hidden decided to the stream for irrigation.
+define(`divert', `ifelse(`$#', `0', ``$0'', `builtin(`$0', $@@)')')
address@hidden
+divert(-1)
+Ignored text.
+divert(0)
address@hidden
+We decided to divert the stream for irrigation.
address@hidden decided to divert the stream for irrigation.
address@hidden example
+
@node Undivert
@section Undiverting output
@@ -3822,8 +3848,8 @@ string.
@end deffn
When @acronym{GNU} extensions are in effect (that is, when you did not use the
address@hidden option), @acronym{GNU} @code{m4} will define the macro
address@hidden to expand to the empty string.
address@hidden option, @pxref{Invoking m4}), @acronym{GNU} @code{m4} will
+define the macro @code{__gnu__} to expand to the empty string.
@example
__gnu__
@@ -4070,6 +4096,7 @@ Prints @var{message} and the rest of the
standard error output, separated by spaces.
The expansion of @code{errprint} is void.
+The macro @code{errprint} is recognized only with parameters.
@end deffn
@example
@@ -4108,7 +4135,8 @@ errprint(__program__:__file__:__line__:
Line numbers start at 1 for each file. If the file was found due to the
@option{-I} option or @env{M4PATH} environment variable, that is
-reflected in the file name. The syncline option (@option{-s}), and the
+reflected in the file name. The syncline option (@option{-s},
address@hidden m4}), and the
@samp{f} and @samp{l} flags of @code{debugmode} (@pxref{Debug Levels}),
also use this notion of current file and line. Redefining the three
location macros has no effect on syncline, debug, or warning message
@@ -4406,8 +4434,8 @@ is made to summarize these here.
@cindex @acronym{GNU} extensions
This version of @code{m4} contains a few facilities that do not exist
in System V @code{m4}. These extra facilities are all suppressed by
-using the @option{-G} command line option, unless overridden by other
-command line options.
+using the @option{-G} command line option (@pxref{Invoking m4}, unless
+overridden by other command line options.
@itemize @bullet
@item
Index: src/builtin.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/builtin.c,v
retrieving revision 1.1.1.1.2.31
diff -u -p -r1.1.1.1.2.31 builtin.c
--- src/builtin.c 4 Aug 2006 13:19:41 -0000 1.1.1.1.2.31
+++ src/builtin.c 15 Aug 2006 13:47:11 -0000
@@ -114,7 +114,7 @@ builtin_tab[] =
{ "divnum", FALSE, FALSE, FALSE, m4_divnum },
{ "dnl", FALSE, FALSE, FALSE, m4_dnl },
{ "dumpdef", FALSE, FALSE, FALSE, m4_dumpdef },
- { "errprint", FALSE, FALSE, FALSE, m4_errprint },
+ { "errprint", FALSE, FALSE, TRUE, m4_errprint },
{ "esyscmd", TRUE, FALSE, TRUE, m4_esyscmd },
{ "eval", FALSE, FALSE, TRUE, m4_eval },
{ "format", TRUE, FALSE, TRUE, m4_format },
@@ -126,13 +126,13 @@ builtin_tab[] =
{ "indir", TRUE, FALSE, TRUE, m4_indir },
{ "len", FALSE, FALSE, TRUE, m4_len },
{ "m4exit", FALSE, FALSE, FALSE, m4_m4exit },
- { "m4wrap", FALSE, FALSE, FALSE, m4_m4wrap },
+ { "m4wrap", FALSE, FALSE, TRUE, m4_m4wrap },
{ "maketemp", FALSE, FALSE, TRUE, m4_maketemp },
{ "patsubst", TRUE, FALSE, TRUE, m4_patsubst },
{ "popdef", FALSE, FALSE, TRUE, m4_popdef },
{ "pushdef", FALSE, TRUE, TRUE, m4_pushdef },
{ "regexp", TRUE, FALSE, TRUE, m4_regexp },
- { "shift", FALSE, FALSE, FALSE, m4_shift },
+ { "shift", FALSE, FALSE, TRUE, m4_shift },
{ "sinclude", FALSE, FALSE, TRUE, m4_sinclude },
{ "substr", FALSE, FALSE, TRUE, m4_substr },
{ "syscmd", FALSE, FALSE, TRUE, m4_syscmd },
@@ -1090,6 +1090,8 @@ m4_dnl (struct obstack *obs, int argc, t
static void
m4_shift (struct obstack *obs, int argc, token_data **argv)
{
+ if (bad_argc (argv[0], argc, 2, -1))
+ return;
dump_args (obs, argc - 1, argv + 1, ",", TRUE);
}
@@ -1225,6 +1227,8 @@ m4_maketemp (struct obstack *obs, int ar
static void
m4_errprint (struct obstack *obs, int argc, token_data **argv)
{
+ if (bad_argc (argv[0], argc, 2, -1))
+ return;
dump_args (obs, argc, argv, " ", FALSE);
obstack_1grow (obs, '\0');
fprintf (stderr, "%s", (char *) obstack_finish (obs));
@@ -1306,6 +1310,8 @@ m4_m4exit (struct obstack *obs, int argc
static void
m4_m4wrap (struct obstack *obs, int argc, token_data **argv)
{
+ if (bad_argc (argv[0], argc, 2, -1))
+ return;
if (no_gnu_extensions)
obstack_grow (obs, ARG (1), strlen (ARG (1)));
else
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: branch-1_4 debian bug 96075 - blind macros,
Eric Blake <=