autoconf-patches
[Top][All Lists]
Advanced

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

m4_combine


From: Eric Blake
Subject: m4_combine
Date: Wed, 17 Oct 2007 07:14:31 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070728 Thunderbird/2.0.0.6 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Based on libtool's lt_combine, but a bit more efficient.  Committed.

2007-10-17  Eric Blake  <address@hidden>

        Add m4_combine, based on Libtool's lt_combine.
        * lib/m4sugar/m4sugar.m4 (m4_combine): New macro.
        * doc/autoconf.texi (Text processing Macros): Document it.
        * NEWS: Likewise.

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

Eric Blake             address@hidden
-----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

iD8DBQFHFgq284KuGfSFAYARArcjAJ0SsN5DEgLaseuORhx07BVhJ/FYywCdG81V
AQuxCAdQNXA4DwivAcAMAVI=
=iZuW
-----END PGP SIGNATURE-----
>From f2ea75eb0315e4782420689f733c2a79231fae3f Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Wed, 17 Oct 2007 07:13:00 -0600
Subject: [PATCH] Add m4_combine, based on Libtool's lt_combine.

* lib/m4sugar/m4sugar.m4 (m4_combine): New macro.
* doc/autoconf.texi (Text processing Macros): Document it.
* NEWS: Likewise.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog              |    7 +++++++
 NEWS                   |    6 +++---
 doc/autoconf.texi      |   24 ++++++++++++++++++++++--
 lib/m4sugar/m4sugar.m4 |   27 +++++++++++++++++++++++++++
 4 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 60a1558..2afeb3d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-10-17  Eric Blake  <address@hidden>
+
+       Add m4_combine, based on Libtool's lt_combine.
+       * lib/m4sugar/m4sugar.m4 (m4_combine): New macro.
+       * doc/autoconf.texi (Text processing Macros): Document it.
+       * NEWS: Likewise.
+
 2007-10-16  Ralf Wildenhues  <address@hidden>
 
        Fix `configure --help=recursive' in unconfigured/read-only trees.
diff --git a/NEWS b/NEWS
index 9d31144..082961e 100644
--- a/NEWS
+++ b/NEWS
@@ -123,9 +123,9 @@ GNU Autoconf NEWS - User visible changes.
    be used to take action depending on whether anything was appended.
 
 ** The following m4sugar macros are new:
-   m4_apply  m4_cond  m4_count  m4_dquote_elt  m4_echo  m4_expand
-   m4_ignore  m4_make_list  m4_max  m4_min  m4_newline  m4_shift2
-   m4_shift3  m4_unquote
+   m4_apply  m4_combine  m4_cond  m4_count  m4_dquote_elt  m4_echo
+   m4_expand  m4_ignore  m4_make_list  m4_max  m4_min  m4_newline
+   m4_shift2  m4_shift3  m4_unquote
 
 ** Warnings are now generated by default when an installer invokes
    'configure' with an unknown --enable-* or --with-* option.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 369b555..3c553c1 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -10884,8 +10884,12 @@ mkargs
 @node Text processing Macros
 @subsection String manipulation in M4
 
-The following macros may be used to manipulate strings in M4.
-They are not intended for casual use.
+The following macros may be used to manipulate strings in M4.  Many of
+the macros in this section intentionally result in quoted strings as
+output, rather than subjecting the arguments to further expansions.  As
+a result, if you are manipulating text that contains active M4
+characters, the arguments are passed with single quoting rather than
+double.
 
 @defmac m4_append (@var{macro-name}, @var{string}, @ovar{separator})
 @defmacx m4_append_uniq (@var{macro-name}, @var{string}, @ovar{separator} @
@@ -10938,6 +10942,22 @@ m4_dquote(list2)
 @end example
 @end defmac
 
address@hidden m4_combine (@ovar{separator}, @var{prefix-list}, @ovar{infix}, @
+  @var{suffix-1}, @dots{})
address@hidden
+This macro produces a quoted string containing the pairwise combination
+of every element of the quoted, comma-separated @var{prefix-list}, and
+every element from the @var{suffix} arguments.  Each pairwise
+combination is joined with @var{infix} in the middle, and successive
+pairs are joined by @var{separator}.  No expansion occurs on any of the
+arguments.
address@hidden
+m4_define([a], [oops])dnl
+m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
address@hidden, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
address@hidden example
address@hidden defmac
+
 @defmac m4_flatten (@var{string})
 @msindex{flatten}
 Flatten @var{string} into a single line.  Delete all backslash-newline
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index ad46ae4..14ded41 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -1812,6 +1812,33 @@ m4_define([_m4_join],
        [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift2($@))])])
 
 
+# m4_combine([SEPARATOR], PREFIX-LIST, [INFIX], SUFFIX...)
+# --------------------------------------------------------
+# Produce the pairwise combination of every element in the quoted,
+# comma-separated PREFIX-LIST with every element from the SUFFIX arguments.
+# Each pair is joined with INFIX, and pairs are separated by SEPARATOR.
+# No expansion occurs on SEPARATOR, INFIX, or elements of either list.
+#
+# For example:
+#   m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
+#   => a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
+#
+# In order to have the correct number of SEPARATORs, we use a temporary
+# variable that redefines itself after the first use.  Note that since there
+# is no user expansion, we can avoid m4_defn overhead by overquoting the
+# second definition of m4_Separator, and by using m4_builtin.  Likewise,
+# we compute the m4_shift3 only once, rather than in each iteration of the
+# outer m4_foreach.
+m4_define([m4_combine],
+[m4_pushdef([m4_Separator], [m4_define([m4_Separator], [[$1]])])]dnl
+[m4_foreach([m4_Prefix], [$2],
+           [m4_foreach([m4_Suffix], ]m4_dquote(m4_dquote(m4_shift3($@)))[,
+                       [m4_Separator[]m4_builtin([defn],
+                                      [m4_Prefix])[$3]m4_builtin([defn],
+                                                      [m4_Suffix])])])]dnl
+[m4_builtin([popdef], [m4_Separator])])
+
+
 # m4_append(MACRO-NAME, STRING, [SEPARATOR])
 # ------------------------------------------
 # Redefine MACRO-NAME to hold its former content plus `SEPARATOR`'STRING'
-- 
1.5.3.2


reply via email to

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