[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fix m4_join
From: |
Eric Blake |
Subject: |
Fix m4_join |
Date: |
Sat, 13 Oct 2007 11:35:59 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070728 Thunderbird/2.0.0.6 Mnenhy/0.7.5.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Another improvement borrowed from libtool. m4_join was mistakenly
m4_defun'd instead of m4_define'd. Additionally, it is nice to avoid
back-to-back separators for an empty argument. A quick search didn't turn
up any clients of m4_join that expected back-to-back separators (since
most clients provided non-empty arguments in every position, rather than
taking libtool's approach of m4_join'ing a list of macro expansions, some
of which might be empty). And it doesn't hurt that this new
implementation is slightly faster, or that m4_join was previously
undocumented (hmm, it looks like I already snuck in the NEWS for this
change in an earlier patch).
2007-10-13 Eric Blake <address@hidden>
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@&address@hidden): New test.
* doc/autoconf.texi (Text processing Macros): Document new
semantics of m4_join.
- --
Don't work too hard, make some time for fun as well!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFHEQH/84KuGfSFAYARAtnhAJ9sFF2LmjsHLDhZHTZNBKesJsEtAQCg1MKl
cLiBaJ5NLSjYqz9NG21yN/k=
=zR9t
-----END PGP SIGNATURE-----
>From 72431d8c84fdbf893fd5ef724cce99220539f7f8 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Sat, 13 Oct 2007 11:11:44 -0600
Subject: [PATCH] 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@&address@hidden): New test.
* doc/autoconf.texi (Text processing Macros): Document new
semantics of m4_join.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 8 ++++++++
doc/autoconf.texi | 10 ++++++++--
lib/m4sugar/m4sugar.m4 | 25 ++++++++++++++++++-------
tests/m4sugar.at | 39 +++++++++++++++++++++++++++++++++++++++
4 files changed, 73 insertions(+), 9 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ac752fd..9efbbe4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2007-10-13 Eric Blake <address@hidden>
+ 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@&address@hidden): 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.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index f63dfa2..3a8c126 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -10832,8 +10832,14 @@ still a quoted string.
@defmac m4_join (@ovar{separator}, @address@hidden)
@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.
address@hidden
+m4_define([active], [ACTIVE])dnl
+m4_join([|], [one], [], [active], [two])
address@hidden|active|two
address@hidden example
@end defmac
@defmac m4_newline
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index dd5138e..8c7070b 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -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])
diff --git a/tests/m4sugar.at b/tests/m4sugar.at
index a946104..f42c6c8 100644
--- a/tests/m4sugar.at
+++ b/tests/m4sugar.at
@@ -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@&address@hidden)
+
+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. ##
## -------------- ##
--
1.5.3.2
- Fix m4_join,
Eric Blake <=
- Re: Fix m4_join, Ralf Wildenhues, 2007/10/14
- Re: Fix m4_join, Eric Blake, 2007/10/14
- Re: Fix m4_join, Ralf Wildenhues, 2007/10/15
- Re: Fix m4_join, Eric Blake, 2007/10/15
- Re: Fix m4_join, Ralf Wildenhues, 2007/10/15
- Re: Fix m4_join, Eric Blake, 2007/10/15
- Re: Fix m4_join, Ralf Wildenhues, 2007/10/16
- Re: Fix m4_join, Eric Blake, 2007/10/16