]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Add m4_combine, based on Libtool's lt_combine.
authorEric Blake <ebb9@byu.net>
Wed, 17 Oct 2007 13:13:00 +0000 (07:13 -0600)
committerEric Blake <ebb9@byu.net>
Wed, 17 Oct 2007 13:13:00 +0000 (07:13 -0600)
* lib/m4sugar/m4sugar.m4 (m4_combine): New macro.
* doc/autoconf.texi (Text processing Macros): Document it.
* NEWS: Likewise.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
NEWS
doc/autoconf.texi
lib/m4sugar/m4sugar.m4

index 60a1558ac5d8c4d3dca3419534d9ea0867583d93..2afeb3d65b805ec20e53b4493912e6a64d2d569c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-10-17  Eric Blake  <ebb9@byu.net>
+
+       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  <Ralf.Wildenhues@gmx.de>
 
        Fix `configure --help=recursive' in unconfigured/read-only trees.
diff --git a/NEWS b/NEWS
index 9d31144a9e25e2760ef503da14e63a2fa555752f..082961e8c81b4f5de8dcaeb6d40166cf9f2eca44 100644 (file)
--- 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.
index 369b555624ae710fd128591d93a0a4ed99455a75..3c553c144da04addbe6d40d4d0a122e702dd28d0 100644 (file)
@@ -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
 
+@defmac m4_combine (@ovar{separator}, @var{prefix-list}, @ovar{infix}, @
+  @var{suffix-1}, @dots{})
+@msindex{combine}
+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.
+@example
+m4_define([a], [oops])dnl
+m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
+@result{}a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
+@end example
+@end defmac
+
 @defmac m4_flatten (@var{string})
 @msindex{flatten}
 Flatten @var{string} into a single line.  Delete all backslash-newline
index ad46ae451d959dfe7ef48c67a01a92b4631210a8..14ded41fa59bef05b51d7ec3e0e81b499204e986 100644 (file)
@@ -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'