Re: M4 syntax $11 vs. ${11}

Eric Blake <[email protected]>
Newsgroups gmane.comp.gnu.m4.patches
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Eric Blake on 2/8/2007 7:52 AM:
> Here's what I'm checking in for 1.4.9.  Anyone who has been testing the
> --warn-syntax option (available only in CVS for a couple of weeks) now
> needs to test with --warn-macro-sequence.  I'm hoping this is the last
> change prior to 1.4.9, but will not release it for a couple of weeks to
> make sure things settle first.
> 
> 2007-02-08  Eric Blake  <[email protected]>
> 
> 	Rename --warn-syntax to --warn-macro-sequence[=regex], to make it
> 	more flexible, and so that autoconf can use it.

A couple more problems on the branch, found while trying to port this to
CVS head:

2007-02-28  Eric Blake  <[email protected]>

	* src/m4.h (DEFAULT_MACRO_SEQUENCE): Factor out from...
	* src/m4.c (usage): ...here,...
	* src/builtin.c (set_macro_sequence): ...and here.
	(define_user_macro): Fix typo.
	* doc/m4.texinfo (Preprocessor features, Arguments): Fix minor
	inaccuracies.
	(Shift): Document composite macro argn for portably getting at
	positional parameters beyond 9.
	* configure.ac (AC_INIT): Bump version number.
	* NEWS: Start changes of 1.4.8c.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             [email protected]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF5YeB84KuGfSFAYARAlwkAKCuidHgGGywbu3xu0MkDll2SW0AwQCeJ0Gh
cVCNu96iWjtFyQrZ6y3SmmY=
=6Uxs
-----END PGP SIGNATURE-----

_______________________________________________
M4-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/m4-patches
m4.patch240 (text/plain, 8.1 KB)
Index: NEWS
===================================================================
RCS file: /sources/m4/m4/NEWS,v
retrieving revision 1.1.1.1.2.95
diff -u -p -r1.1.1.1.2.95 NEWS
--- NEWS	24 Feb 2007 17:32:58 -0000	1.1.1.1.2.95
+++ NEWS	28 Feb 2007 13:41:35 -0000
@@ -2,6 +2,10 @@ GNU M4 NEWS - User visible changes.
 Copyright (C) 1992, 1993, 1994, 2004, 2005, 2006, 2007 Free Software
 Foundation, Inc.
 
+Version 1.4.9 - ?? ??? 2007, by ???  (CVS version 1.4.8c)
+
+* Minor documentation and portability cleanups.
+
 Version 1.4.8b - 24 Feb 2007, by Eric Blake  (CVS version 1.4.8a)
 
 * Fix a regression introduced in 1.4.8 that made m4 unable to process
Index: configure.ac
===================================================================
RCS file: /sources/m4/m4/configure.ac,v
retrieving revision 1.36.2.35
diff -u -p -r1.36.2.35 configure.ac
--- configure.ac	24 Feb 2007 17:32:58 -0000	1.36.2.35
+++ configure.ac	28 Feb 2007 13:41:35 -0000
@@ -18,7 +18,7 @@
 # 02110-1301  USA
 
 AC_PREREQ([2.60])
-AC_INIT([GNU M4], [1.4.8b], [[email protected]])
+AC_INIT([GNU M4], [1.4.8c], [[email protected]])
 AM_INIT_AUTOMAKE([1.9.6 dist-bzip2 gnu])
 PACKAGE=$PACKAGE_TARNAME; AC_SUBST([PACKAGE])
 VERSION=$PACKAGE_VERSION; AC_SUBST([VERSION])
Index: doc/m4.texinfo
===================================================================
RCS file: /sources/m4/m4/doc/m4.texinfo,v
retrieving revision 1.1.1.1.2.115
diff -u -p -r1.1.1.1.2.115 m4.texinfo
--- doc/m4.texinfo	24 Feb 2007 14:02:23 -0000	1.1.1.1.2.115
+++ doc/m4.texinfo	28 Feb 2007 13:41:36 -0000
@@ -618,13 +618,12 @@ input came from.  These features occur w
 @table @code
 @item -D @var{NAME}@r{[}=@var{VALUE}@r{]}
 @itemx --define=@var{NAME}@r{[}=@var{VALUE}@r{]}
-This enters @var{NAME} into the symbol table, before any input files are
-read.  If @samp{=@var{VALUE}} is missing, the value is taken to be the
-empty string.  The @var{VALUE} can be any string, and the macro can be
-defined to take arguments, just as if it was defined from within the
-input.  This option may be given more than once; order with respect to
-file names is significant, and redefining the same @var{NAME} loses the
-previous value.
+This enters @var{NAME} into the symbol table.  If @samp{=@var{VALUE}} is
+missing, the value is taken to be the empty string.  The @var{VALUE} can
+be any string, and the macro can be defined to take arguments, just as
+if it was defined from within the input.  This option may be given more
+than once; order with respect to file names is significant, and
+redefining the same @var{NAME} loses the previous value.
 
 @item -I @var{DIRECTORY}
 @itemx --include=@var{DIRECTORY}
@@ -1615,9 +1614,9 @@ consist of one or more digits, allowing 
 arguments.  The extension of accepting multiple digits is incompatible
 with @acronym{POSIX}, and is different than traditional implementations
 of @code{m4}, which only recognize one digit.  Therefore, future
-versions of @acronym{GNU} M4 will phase out this feature.
-@xref{Extensions}, for an example of how to portably access the eleventh
-argument.
+versions of @acronym{GNU} M4 will phase out this feature.  To portably
+access beyond the ninth argument, you can use the @code{argn} macro
+documented later (@pxref{Shift}).
 
 @acronym{POSIX} also states that @samp{$} followed immediately by
 @samp{@{} in a macro definition is implementation-defined.  This version
@@ -1645,10 +1644,10 @@ behavior due to the changed behavior of 
 @option{--warn-macro-sequence} command-line option (@pxref{Operation
 modes, , Invoking m4}) with the default regular expression.  This will
 add a warning any time a macro definition includes @samp{$} followed by
-multiple digits, or by @samp{@{} and a digit.  The warning is not
-enabled by default, because it triggers a number of warnings in Autoconf
-2.61 (and Autoconf uses @option{-E} to treat warnings as errors), and
-because it will still be possible to restore older behavior in M4 2.0.
+multiple digits, or by @samp{@{}.  The warning is not enabled by
+default, because it triggers a number of warnings in Autoconf 2.61 (and
+Autoconf uses @option{-E} to treat warnings as errors), and because it
+will still be possible to restore older behavior in M4 2.0.
 
 @comment ignore
 @example
@@ -2439,6 +2438,34 @@ undivert(`quote.m4')dnl
 @result{}divert`'dnl
 @end example
 
+@cindex nine arguments, more than
+@cindex more than nine arguments
+@cindex arguments, more than nine
+One more useful macro based on @code{shift} allows portably selecting
+an arbitrary argument (usually greater than the ninth argument), without
+relying on the @acronym{GNU} extension of multi-digit arguments
+(@pxref{Arguments}).
+
+@deffn Composite argn (@var{n}, @dots{})
+Expands to argument @var{n} out of the remaining arguments.  @var{n}
+must be a positive number.  Usually invoked as
+@samp{argn(`@var{n}',$@@)}.
+@end deffn
+
+It is implemented as:
+
+@example
+define(`argn', `ifelse(`$1', 1, ``$2'',
+  `argn(decr(`$1'), shift(shift($@@)))')')
+@result{}
+argn(`1', `a')
+@result{}a
+define(`foo', `argn(`11', $@@)')
+@result{}
+foo(`a', `b', `c', `d', `e', `f', `g', `h', `i', `j', `k', `l')
+@result{}k
+@end example
+
 @node Forloop
 @section Iteration by counting
 
@@ -5716,6 +5743,9 @@ Eleventh(`a', `b', `c', `d', `e', `f', `
 @result{}k
 @end example
 
+@noindent
+Also see the @code{argn} macro (@pxref{Shift}).
+
 @item
 The @code{divert} (@pxref{Divert}) macro can manage more than 9
 diversions.  @acronym{GNU} @code{m4} treats all positive numbers as valid
Index: src/builtin.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/builtin.c,v
retrieving revision 1.1.1.1.2.58
diff -u -p -r1.1.1.1.2.58 builtin.c
--- src/builtin.c	24 Feb 2007 14:02:23 -0000	1.1.1.1.2.58
+++ src/builtin.c	28 Feb 2007 13:41:36 -0000
@@ -253,7 +253,7 @@ set_macro_sequence (const char *regexp)
   const char *msg;
 
   if (! regexp)
-    regexp = "\\$\\({[^}]*}\\|[0-9][0-9]+\\)";
+    regexp = DEFAULT_MACRO_SEQUENCE;
   else if (regexp[0] == '\0')
     {
       macro_sequence_inuse = false;
@@ -328,7 +328,7 @@ define_user_macro (const char *name, con
 	}
       if (offset == -2)
 	M4ERROR ((warning_status, 0,
-		  "error checking --warn-define-sequence for macro `%s'",
+		  "error checking --warn-macro-sequence for macro `%s'",
 		  name));
     }
 }
Index: src/m4.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/m4.c,v
retrieving revision 1.1.1.1.2.45
diff -u -p -r1.1.1.1.2.45 m4.c
--- src/m4.c	24 Feb 2007 14:02:23 -0000	1.1.1.1.2.45
+++ src/m4.c	28 Feb 2007 13:41:36 -0000
@@ -154,7 +154,7 @@ Operation modes:\n\
       --help                   display this help and exit\n\
       --version                output version information and exit\n\
 ", stdout);
-      fputs ("\
+      printf ("\
   -E, --fatal-warnings         once: warnings become errors, twice: stop\n\
                                execution at first error\n\
   -i, --interactive            unbuffer output, ignore interrupts\n\
@@ -162,8 +162,8 @@ Operation modes:\n\
   -Q, --quiet, --silent        suppress some warnings for builtins\n\
       --warn-macro-sequence[=REGEXP]\n\
                                warn if macro definition matches REGEXP,\n\
-                               default \\$\\({[^}]*}\\|[0-9][0-9]+\\)\n\
-", stdout);
+                               default %s\n\
+", DEFAULT_MACRO_SEQUENCE);
 #ifdef ENABLE_CHANGEWORD
       fputs ("\
   -W, --word-regexp=REGEXP     use REGEXP for macro name syntax\n\
Index: src/m4.h
===================================================================
RCS file: /sources/m4/m4/src/m4.h,v
retrieving revision 1.1.1.1.2.40
diff -u -p -r1.1.1.1.2.40 m4.h
--- src/m4.h	23 Feb 2007 17:05:27 -0000	1.1.1.1.2.40
+++ src/m4.h	28 Feb 2007 13:41:36 -0000
@@ -407,6 +407,11 @@ typedef struct predefined predefined;
 struct re_pattern_buffer;
 struct re_registers;
 
+/* The default sequence detects multi-digit parameters (obsolete after
+   1.4.x), and any use of extended arguments with the default ${}
+   syntax (new in 2.0).  */
+#define DEFAULT_MACRO_SEQUENCE "\\$\\({[^}]*}\\|[0-9][0-9]+\\)"
+
 void builtin_init (void);
 void define_builtin (const char *, const builtin *, symbol_lookup);
 void set_macro_sequence (const char *);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.