* lib/m4sugar/m4sugar.m4 (m4_joinall, _m4_joinall): New macros.
* tests/m4sugar.at (m4@&t@_join): Test them.
* doc/autoconf.texi (Text processing Macros) <m4_join>: Document
m4_joinall.
* NEWS: Likewise.
Signed-off-by: Eric Blake <ebb9@byu.net>
+2008-07-18 Eric Blake <ebb9@byu.net>
+
+ 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) <m4_join>: Document
+ m4_joinall.
+ * NEWS: Likewise.
+
2008-07-17 Stepan Kasal <skasal@redhat.com>
and Eric Blake <ebb9@byu.net>
** 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].
@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
[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...)
# --------------------------------------------------------
AT_SETUP([m4@&t@_join])
+AT_KEYWORDS([m4@&t@_joinall])
+
AT_CHECK_M4SUGAR_TEXT(
[[m4_define([active], [ACTIVE])
m4_join
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])
]],
[[
two
one active two
onetwo
+one--two
+--three--
+onetwo
+
+
+one
]])
AT_CLEANUP