From 65ff0e8f8876e4b4e354c8b23fba1b6e2c077689 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 18 Jul 2008 08:30:07 -0600 Subject: [PATCH] Add m4_joinall. * lib/m4sugar/m4sugar.m4 (m4_joinall, _m4_joinall): New macros. * tests/m4sugar.at (m4@&t@_join): Test them. * doc/autoconf.texi (Text processing Macros) : Document m4_joinall. * NEWS: Likewise. Signed-off-by: Eric Blake --- ChangeLog | 9 +++++++++ NEWS | 3 +++ doc/autoconf.texi | 11 ++++++++--- lib/m4sugar/m4sugar.m4 | 7 +++++++ tests/m4sugar.at | 14 ++++++++++++++ 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index da65cc7e..af9b4d9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-07-18 Eric Blake + + Add m4_joinall. + * lib/m4sugar/m4sugar.m4 (m4_joinall, _m4_joinall): New macros. + * tests/m4sugar.at (m4@&t@_join): Test them. + * doc/autoconf.texi (Text processing Macros) : Document + m4_joinall. + * NEWS: Likewise. + 2008-07-17 Stepan Kasal and Eric Blake diff --git a/NEWS b/NEWS index 06b705f7..d3fb23b9 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,9 @@ GNU Autoconf NEWS - User visible changes. ** Two new quadrigraphs have been introduced: @{:@ for (, and @:}@ for ), allowing the output of unbalanced parantheses in more contexts. +** The following m4sugar macros are new: + m4_joinall + ** AT_KEYWORDS once again performs expansion on its argument, such that AT_KEYWORDS([m4_if([$1], [], [default])]) no longer complains about the possibly unexpanded m4_if [regression introduced in 2.62]. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index bfe5c1b4..4e8638d3 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -11163,14 +11163,19 @@ still a quoted string. @end defmac @defmac m4_join (@ovar{separator}, @var{args}@dots{}) +@defmacx m4_joinall (@ovar{separator}, @var{args}@dots{}) @msindex{join} -Concatenate each @var{arg}, separated by @var{separator}, with the -exception that no back-to-back separators are issued for empty -arguments. The result is a quoted string. +@msindex{joinall} +Concatenate each @var{arg}, separated by @var{separator}. +@code{joinall} uses every argument, while @code{join} omits empty +arguments so that there are no back-to-back separators in the output. +The result is a quoted string. @example m4_define([active], [ACTIVE])dnl m4_join([|], [one], [], [active], [two]) @result{}one|active|two +m4_joinall([|], [one], [], [active], [two]) +@result{}one||active|two @end example Note that if all you intend to do is join @var{args} with commas between diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index c6993ee9..eb4374e2 100644 --- a/lib/m4sugar/m4sugar.m4 +++ b/lib/m4sugar/m4sugar.m4 @@ -1846,6 +1846,13 @@ m4_define([_m4_join], [m4_if([$#$2], [2], [], [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift2($@))])]) +# m4_joinall(SEP, ARG1, ARG2...) +# ------------------------------ +# Produce ARG1SEPARG2...SEPARGn. An empty ARG results in back-to-back SEP. +# No expansion is performed on SEP or ARGs. +m4_define([m4_joinall], [[$2]_$0([$1], m4_shift($@))]) +m4_define([_m4_joinall], +[m4_if([$#], [2], [], [[$1$3]$0([$1], m4_shift2($@))])]) # m4_combine([SEPARATOR], PREFIX-LIST, [INFIX], SUFFIX...) # -------------------------------------------------------- diff --git a/tests/m4sugar.at b/tests/m4sugar.at index 69cb74b5..b6a4cac5 100644 --- a/tests/m4sugar.at +++ b/tests/m4sugar.at @@ -284,6 +284,8 @@ AT_CLEANUP AT_SETUP([m4@&t@_join]) +AT_KEYWORDS([m4@&t@_joinall]) + AT_CHECK_M4SUGAR_TEXT( [[m4_define([active], [ACTIVE]) m4_join @@ -297,6 +299,12 @@ m4_join([], ,,,[two]) m4_join([], [two],,,) m4_join([ active ], [one], , [two]) m4_join([], [one], [two]) +m4_joinall([-], [one], [], [two]) +m4_joinall([-], [], [], [three], [], []) +m4_joinall([], [one], [], [two]) +m4_joinall +m4_joinall([-]) +m4_joinall([-], [one]) ]], [[ @@ -310,6 +318,12 @@ two two one active two onetwo +one--two +--three-- +onetwo + + +one ]]) AT_CLEANUP -- 2.11.4.GIT