From f2ea75eb0315e4782420689f733c2a79231fae3f Mon Sep 17 00:00:00 2001 From: Eric Blake 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 --- 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 60a1558a..2afeb3d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-10-17 Eric Blake + + 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 Fix `configure --help=recursive' in unconfigured/read-only trees. diff --git a/NEWS b/NEWS index 9d31144a..082961e8 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 369b5556..3c553c14 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 +@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 diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index ad46ae45..14ded41f 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'