]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Change m4_join to match libtool's ltsugar semantics.
authorEric Blake <ebb9@byu.net>
Sat, 13 Oct 2007 17:11:44 +0000 (11:11 -0600)
committerEric Blake <ebb9@byu.net>
Sat, 13 Oct 2007 17:11:44 +0000 (11:11 -0600)
* lib/m4sugar/m4sugar.m4 (m4_join): Just define this, not defun.
Ignore empty arguments, using...
(_m4_join): ...this new helper.
* tests/m4sugar.at (m4@&t@_join): New test.
* doc/autoconf.texi (Text processing Macros): Document new
semantics of m4_join.

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

index ac752fd9ef7024e873ee7a1a923f4843ca786198..9efbbe4143e21e8c720540ee7135e00fe18b6957 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2007-10-13  Eric Blake  <ebb9@byu.net>
 
+       Change m4_join to match libtool's ltsugar semantics.
+       * lib/m4sugar/m4sugar.m4 (m4_join): Just define this, not defun.
+       Ignore empty arguments, using...
+       (_m4_join): ...this new helper.
+       * tests/m4sugar.at (m4@&t@_join): New test.
+       * doc/autoconf.texi (Text processing Macros): Document new
+       semantics of m4_join.
+
        Make AC_PREREQ faster and more robust.
        * lib/m4sugar/m4sugar.m4 (m4_ignore, m4_unquote): New macros.
        (m4_version_prereq): Inline constant expansions.
index f63dfa20999ef4e06dc3c4bb0b93f3f979b46182..3a8c126c6fae7900fe7972c3137f4cb1d407dd83 100644 (file)
@@ -10832,8 +10832,14 @@ still a quoted string.
 
 @defmac m4_join (@ovar{separator}, @var{args}@dots{})
 @msindex{join}
-Concatenate each @var{arg}, separated by @var{separator}.  The result is
-a quoted string.
+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.
+@example
+m4_define([active], [ACTIVE])dnl
+m4_join([|], [one], [], [active], [two])
+@result{}one|active|two
+@end example
 @end defmac
 
 @defmac m4_newline
index dd5138ef1abf835f30c13b39acabfb4db11b0477..8c7070ba5b86191b07f2d5e720c7f855914ed9db 100644 (file)
@@ -1663,13 +1663,24 @@ m4_define([m4_normalize],
 
 # m4_join(SEP, ARG1, ARG2...)
 # ---------------------------
-# Produce ARG1SEPARG2...SEPARGn.
-m4_defun([m4_join],
-[m4_case([$#],
-        [1], [],
-        [2], [[$2]],
-        [[$2][$1]$0([$1], m4_shift2($@))])])
-
+# Produce ARG1SEPARG2...SEPARGn.  Avoid back-to-back SEP when a given ARG
+# is the empty string.
+#
+# Since the number of arguments to join can be arbitrarily long, we
+# want to avoid having more than one $@ in the macro definition;
+# otherwise, the expansion would require twice the memory of the already
+# long list.  Hence, m4_join merely looks for the first non-empty element,
+# and outputs just that element; while _m4_join looks for all non-empty
+# elements, and outputs them following a separator.  The final trick to
+# note is that we decide between recursing with $0 or _$0 based on the
+# nested m4_if ending with `_'.
+m4_define([m4_join],
+[m4_if([$#], [1], [],
+       [$#], [2], [[$2]],
+       [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift2($@))])])
+m4_define([_m4_join],
+[m4_if([$#$2], [2], [],
+       [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift2($@))])])
 
 
 # m4_append(MACRO-NAME, STRING, [SEPARATOR])
index a946104d7f21e44a0221000da14851606cd1195a..f42c6c877f4544d16d1577792f5e2556b7e3b31e 100644 (file)
@@ -44,6 +44,8 @@ AT_CHECK_M4SUGAR([-o-],, [$2], [$3])
 #
 # - m4_append
 #
+# - m4_join
+#
 # - m4_text_wrap
 # uses m4_split code.
 
@@ -251,6 +253,43 @@ one, two, three
 AT_CLEANUP
 
 
+## --------- ##
+## m4_join.  ##
+## --------- ##
+
+AT_SETUP([m4@&t@_join])
+
+AT_CHECK_M4SUGAR_TEXT(
+[[m4_define([active], [ACTIVE])
+m4_join
+m4_join([|])
+m4_join([, ], [one], [two])
+m4_dquote(m4_join([, ], [one], [two]))
+m4_join([|], [active], [active])
+m4_join([|], ,,,[one])
+m4_join([|], [one],,,)
+m4_join([], ,,,[two])
+m4_join([], [two],,,)
+m4_join([ active ], [one], , [two])
+m4_join([], [one], [two])
+]],
+[[
+
+
+one, two
+[one, two]
+active|active
+one
+one
+two
+two
+one active two
+onetwo
+]])
+
+AT_CLEANUP
+
+
 ## -------------- ##
 ## m4_text_wrap.  ##
 ## -------------- ##