autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: more fun with m4_expand


From: Eric Blake
Subject: Re: more fun with m4_expand
Date: Tue, 25 Nov 2008 08:35:55 -0800 (PST)

> > BTW, is there a way to kill a diversion without outputting anything?
> > Maybe you can add that to m4sugar.
> 
> m4_divert_text([KILL], [m4_undivert(diversion)])
> 
> But yes, maybe an m4_divert_discard(diversion) would be nice shorthand for
> that.

I'm committing this; it uses the same base macro name as suggested in
the m4 manual for the same purpose (although without support for
clearing every diversion, which doesn't seem useful for m4sh).
http://www.gnu.org/software/m4/manual/html_node/Cleardivert.html#Cleardivert

From: Eric Blake <address@hidden>
Date: Tue, 25 Nov 2008 09:28:43 -0700
Subject: [PATCH] Add m4_cleardivert.

* lib/m4sugar/m4sugar.m4 (m4_cleardivert): New macro.
* lib/autotest/general.m4 (AT_INIT): Use it.
* lib/autoconf/general.m4 (_AC_INIT_NOTICE): Likewise.
* tests/m4sugar.at (m4@&address@hidden): Test it.
* doc/autoconf.texi (Diversion support) <m4_cleardivert>: Document
it.
* NEWS: Likewise.
Suggested by Paolo Bonzini.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog               |   10 ++++++++++
 NEWS                    |   10 +++++-----
 doc/autoconf.texi       |    6 ++++++
 lib/autoconf/general.m4 |    4 ++--
 lib/autotest/general.m4 |   10 +++++-----
 lib/m4sugar/m4sugar.m4  |   11 +++++++++++
 tests/m4sugar.at        |   13 ++++++++++++-
 7 files changed, 51 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 043d793..34dc21d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2008-11-25  Eric Blake  <address@hidden>
 
+       Add m4_cleardivert.
+       * lib/m4sugar/m4sugar.m4 (m4_cleardivert): New macro.
+       * lib/autotest/general.m4 (AT_INIT): Use it.
+       * lib/autoconf/general.m4 (_AC_INIT_NOTICE): Likewise.
+       * tests/m4sugar.at (m4@&address@hidden): Test it.
+       * doc/autoconf.texi (Diversion support) <m4_cleardivert>: Document
+       it.
+       * NEWS: Likewise.
+       Suggested by Paolo Bonzini.
+
        Add safety check for m4_expand vs. diversions.
        * lib/m4sugar/m4sugar.m4 (m4_expand): Make more robust against
        diverted text.
diff --git a/NEWS b/NEWS
index 3edc6bc..86bf8d5 100644
--- a/NEWS
+++ b/NEWS
@@ -93,11 +93,11 @@ GNU Autoconf NEWS - User visible changes.
    allowing the output of unbalanced parentheses in more contexts.
 
 ** The following m4sugar macros are new:
-   m4_joinall  m4_mapall  m4_mapall_sep  m4_reverse  m4_set_add
-   m4_set_add_all  m4_set_contains  m4_set_contents  m4_set_delete
-   m4_set_difference  m4_set_dump  m4_set_empty  m4_set_foreach
-   m4_set_intersection  m4_set_list  m4_set_listc  m4_set_remove
-   m4_set_size  m4_set_union
+   m4_cleardivert  m4_joinall  m4_mapall  m4_mapall_sep  m4_reverse
+   m4_set_add  m4_set_add_all  m4_set_contains  m4_set_contents
+   m4_set_delete  m4_set_difference  m4_set_dump  m4_set_empty
+   m4_set_foreach  m4_set_intersection  m4_set_list  m4_set_listc
+   m4_set_remove  m4_set_size  m4_set_union
 
 ** The following m4sugar macros now accept multiple arguments, as is the
    case with underlying m4:
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 7c7b972..1decd4b 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -10815,6 +10815,12 @@ Diversion support
 intentionally outputting text into an undocumented diversion is subject
 to breakage in a future release of Autoconf.
 
address@hidden m4_cleardivert (@address@hidden)
address@hidden
+Permanently discard any text that has been diverted into
address@hidden
address@hidden defmac
+
 @defmac m4_divert_once (@var{diversion}, @ovar{content})
 @msindex{divert_once}
 Similar to @code{m4_divert_text}, except that @var{content} is only
diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index 50b6eae..bcf8720 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -344,8 +344,8 @@ m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])
 # ---------------
 # Provide useful headers; override the HEADER-COMMENT created by M4sh.
 m4_define([_AC_INIT_NOTICE],
-[m4_divert_text([KILL], [m4_undivert([HEADER-COMMENT])])dnl
-m4_divert_text([HEADER-COMMENT],
+[m4_cleardivert([HEADER-COMMENT])]dnl
+[m4_divert_text([HEADER-COMMENT],
 address@hidden:@ Guess values for system-dependent variables and create 
Makefiles.
 @%:@ Generated by m4_PACKAGE_STRING[]dnl
 m4_ifset([AC_PACKAGE_STRING], [ for AC_PACKAGE_STRING]).])
diff --git a/lib/autotest/general.m4 b/lib/autotest/general.m4
index f391503..3462cc0 100644
--- a/lib/autotest/general.m4
+++ b/lib/autotest/general.m4
@@ -216,13 +216,13 @@ m4_define([AT_INIT],
 [m4_define([AT_help_all], [])]
 [m4_map_args([_m4_popdef], _AT_DEFINE_INIT_LIST)]
 [m4_wrap([_AT_FINISH])]
-[AS_INIT[]dnl
+[AS_INIT[]]dnl
 dnl We don't use m4sh's BODY diversion, but AS_INIT sticks a banner there.
 dnl This trick removes that banner, since it adds nothing to autotest.
-m4_divert_text([KILL], [m4_undivert([BODY])])dnl
-AS_ME_PREPARE[]dnl
-m4_divert_push([DEFAULTS])dnl
-AT_COPYRIGHT(
+[m4_cleardivert([BODY])]dnl
+[AS_ME_PREPARE[]]dnl
+[m4_divert_push([DEFAULTS])]dnl
+[AT_COPYRIGHT(
 [Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
 Free Software Foundation, Inc.
 This test suite is free software; the Free Software Foundation gives
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index 55dcd49..e3b712a 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -1301,6 +1301,17 @@ m4_define([_m4_stack_reverse],
 ## --------------------------- ##
 
 
+# m4_cleardivert(DIVERSION-NAME...)
+# ---------------------------------
+# Discard any text in DIVERSION-NAME.
+#
+# This works even inside m4_expand.
+m4_define([m4_cleardivert],
+[m4_if([$#], [0], [m4_fatal([$0: missing argument])],
+       [m4_builtin([divert], [-1])m4_undivert($@)m4_builtin([divert],
+        _m4_divert(_m4_defn([_m4_divert_diversion])))])])
+
+
 # _m4_divert(DIVERSION-NAME or NUMBER)
 # ------------------------------------
 # If DIVERSION-NAME is the name of a diversion, return its number,
diff --git a/tests/m4sugar.at b/tests/m4sugar.at
index 4bdc06c..36787fc 100644
--- a/tests/m4sugar.at
+++ b/tests/m4sugar.at
@@ -248,7 +248,7 @@ AT_CLEANUP
 
 AT_SETUP([m4@&address@hidden)
 AT_KEYWORDS([m4@&address@hidden m4@&address@hidden m4@&address@hidden
-m4@&address@hidden)
+m4@&address@hidden m4@&address@hidden m4@&address@hidden)
 
 AT_CHECK_M4SUGAR_TEXT([[1.m4_divert_stack
 m4_divert_push([10])2.m4_divert_stack
@@ -272,6 +272,17 @@ script.4s:2: m4@&address@hidden: 0
 script.4s:1: m4@&address@hidden: KILL
 ]])
 
+AT_CHECK_M4SUGAR_TEXT([[dnl
+m4_divert_text([3], [three])dnl
+m4_divert_text([4], [four])dnl
+m4_divert_text([1], [one])dnl
+m4_divert_text([2], [two])dnl
+m4_cleardivert([2], [3])dnl
+]],
+[[one
+four
+]])
+
 AT_DATA_M4SUGAR([script.4s],
 [[m4_divert_pop
 ]])
-- 
1.6.0.4


-- 
View this message in context: 
http://www.nabble.com/more-fun-with-m4_expand-tp20671548p20684795.html
Sent from the Gnu - Autoconf - Patches mailing list archive at Nabble.com.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]