[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: m4_wrap behavior
From: |
Eric Blake |
Subject: |
Re: m4_wrap behavior |
Date: |
Thu, 15 Jun 2006 21:08:46 -0600 |
User-agent: |
Thunderbird 1.5.0.4 (Windows/20060516) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Eric Blake on 6/13/2006 6:47 AM:
>
> As an idea of how to force m4_wrap ordering, this shows how
> to give m4 1.4.4 FIFO ordering:
>
> changequote([,])dnl
> define([m4wrap_],[0])define([_m4wrap], defn([m4wrap]))dnl
> define([m4wrap], [ifdef([m4wrap]m4wrap_,
> [define([m4wrap]m4wrap_, defn([m4wrap]m4wrap_)[$1])],
> [_m4wrap([define([m4wrap_], incr(m4wrap_))m4wrap]m4wrap_)dnl
> define([m4wrap]m4wrap_, [$1])])])dnl
Or, a little more readable, and now as part of the testsuite:
2006-06-15 Eric Blake <address@hidden>
* checks/wrapfifo.m4: New file. Use it...
* doc/m4.texinfo (Incompatibilities): here, in a new test case to
demonstrate how to get POSIX behavior of m4wrap prior to m4 2.0.
- --
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
iD8DBQFEkiC+84KuGfSFAYARAn52AJ9eNTE8qTxsxMcGr/zoZvi3gADaEgCgvxPb
ixb9Hc86gUFJoN83FvUSmC4=
=TTra
-----END PGP SIGNATURE-----
Index: doc/m4.texinfo
===================================================================
RCS file: /sources/m4/m4/doc/m4.texinfo,v
retrieving revision 1.1.1.1.2.19
diff -u -p -r1.1.1.1.2.19 m4.texinfo
--- doc/m4.texinfo 6 Jun 2006 13:20:57 -0000 1.1.1.1.2.19
+++ doc/m4.texinfo 16 Jun 2006 03:02:41 -0000
@@ -3501,7 +3501,9 @@ future release of GNU @code{m4} may chan
@itemize @bullet
@item
System V @code{m4} supports multiple arguments to @code{defn}, and
address@hidden requires it. This is not implemented in GNU @code{m4}.
address@hidden requires it. This is not yet implemented in GNU
address@hidden Unfortunately, this means it is not possible to mix builtins
+and other text into a single macro; a helper macro is required.
@item
@acronym{POSIX} requires an application to exit with non-zero status if
@@ -3518,11 +3520,34 @@ it encounters a read error on stdin or w
@item
@acronym{POSIX} requires @code{m4wrap} (@pxref{M4wrap}) to act in FIFO
-(first-in, first-out) order, but GNU @code{m4} uses LIFO order.
+(first-in, first-out) order, but GNU @code{m4} currently uses LIFO order.
Furthermore, @acronym{POSIX} states that only the first argument to
@code{m4wrap} is saved for later evaluation, bug GNU @code{m4} saves and
processes all arguments, with output separated by spaces.
+However, it is possible to emulate @acronym{POSIX} behavior by
+including the sample file @file{wrapfifo.m4}:
+
address@hidden
+undivert(`wrapfifo.m4')dnl
address@hidden(`_m4wrap_level', `0')dnl
address@hidden(`m4wrap',
address@hidden(`m4wrap'_m4wrap_level,
address@hidden `define(`m4wrap'_m4wrap_level,
address@hidden defn(`m4wrap'_m4wrap_level)`$1')',
address@hidden `builtin(`m4wrap', `define(`_m4wrap_level',
address@hidden incr(_m4wrap_level))dnl
address@hidden'_m4wrap_level)dnl
address@hidden(`m4wrap'_m4wrap_level, `$1')')')dnl
+include(`wrapfifo.m4')
address@hidden
+m4wrap(`a`'m4wrap(`c
+', `d')')m4wrap(`b')
address@hidden
+^D
address@hidden
address@hidden example
+
@item
@acronym{POSIX} requires that all builtins that require arguments, but
are called without arguments, behave as though empty strings had been
@@ -3531,11 +3556,11 @@ But GNU @code{m4} ignores certain builti
arguments, giving @code{adefineb} for the above example.
@item
-Traditional implementations treat @code{define(`f',1} (@pxref{Define})
-as though it were @code{undefine(`f')pushdef(`f',1)}, effectively
+Traditional implementations treat @code{define(`f',`1')} (@pxref{Define})
+as though it were @code{undefine(`f')pushdef(`f',`1')}, effectively
replacing the entire stack of previously pushdef'd definitions with a
single definition. GNU @code{m4} behaves as
address@hidden(`f')pushdef(`f',1)}, keeping all previous definitions on
address@hidden(`f')pushdef(`f',`1')}, keeping all previous definitions on
the stack intact.
@item
Index: checks/wrapfifo.m4
===================================================================
RCS file: checks/wrapfifo.m4
diff -N checks/wrapfifo.m4
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ checks/wrapfifo.m4 16 Jun 2006 03:02:41 -0000
@@ -0,0 +1,9 @@
+define(`_m4wrap_level', `0')dnl
+define(`m4wrap',
+`ifdef(`m4wrap'_m4wrap_level,
+ `define(`m4wrap'_m4wrap_level,
+ defn(`m4wrap'_m4wrap_level)`$1')',
+ `builtin(`m4wrap', `define(`_m4wrap_level',
+ incr(_m4wrap_level))dnl
+m4wrap'_m4wrap_level)dnl
+define(`m4wrap'_m4wrap_level, `$1')')')dnl
- Re: m4_wrap behavior,
Eric Blake <=