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 <ebb9@byu.net>
This commit is contained in:
Eric Blake 2007-10-17 07:13:00 -06:00
parent bbb9c9628d
commit f2ea75eb03
4 changed files with 59 additions and 5 deletions

View File

@ -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.

6
NEWS
View File

@ -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.

View 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

View 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'