]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Fix m4_cdr for one-member lists.
authorStepan Kasal <kasal@ucw.cz>
Mon, 6 Jun 2005 08:47:02 +0000 (08:47 +0000)
committerStepan Kasal <kasal@ucw.cz>
Mon, 6 Jun 2005 08:47:02 +0000 (08:47 +0000)
ChangeLog
lib/m4sugar/m4sugar.m4

index a922359fc5820bceb581d326b99b54bc4d81a63c..d963409f660c6bc8fdc10db522eee8f147c7b1df 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2005-06-06  Stepan Kasal  <kasal@ucw.cz>
+
+       m4_cdr of one-member list was [[]] (one-member list containing an
+       empty string) instead of [] (an empty list.  Callers were skewed to
+       match this misbehaviour.  As a consequence of this:
+        - m4_foreach([x], [], [foo]) expanded to `foo', while
+        - the expansion of m4_foreach([x], [[]], [foo]) was empty.
+       I fixed this bug.
+
+       * lib/m4sugar/m4sugar.m4 (m4_cdr): If only one argument is given,
+         expand to an empty string; print error msg if called without
+         an argument list.
+       (m4_foreach, m4_map, m4_map_sep): Don't expect the previous
+         misbehaviour; handle [] and [[]] correctly.
+
 2005-06-06  Stepan Kasal  <kasal@ucw.cz>
 
        * lib/autoconf/general.m4 (_AC_INIT_DEFAULTS): Nuke ac_max_here_lines.
index 6423481442cbc5f36207cfcbcf759ed523d00581..71e0072439dce756979575c76a91a8e3fee2faa6 100644 (file)
@@ -381,15 +381,25 @@ m4_define([m4_bmatch],
              [$3])])])
 
 
+# m4_car(LIST)
+# m4_cdr(LIST)
+# ------------
+# Manipulate m4 lists.
+m4_define([m4_car], [[$1]])
+m4_define([m4_cdr],
+[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
+       [$#], 1, [],
+       [m4_dquote(m4_shift($@))])])
+
+
 # m4_map(MACRO, LIST)
 # -------------------
 # Invoke MACRO($1), MACRO($2) etc. where $1, $2... are the elements
 # of LIST (which can be lists themselves, for multiple arguments MACROs).
 m4_define([m4_fst], [$1])
 m4_define([m4_map],
-[m4_if([$2], [[]], [],
-       [$1(m4_fst($2))[]dnl
-m4_map([$1], m4_cdr($2))])])
+[m4_ifval([$2],
+         [$1(m4_fst($2))[]m4_map([$1], m4_cdr($2))])])
 
 
 # m4_map_sep(MACRO, SEPARATOR, LIST)
@@ -398,12 +408,8 @@ m4_map([$1], m4_cdr($2))])])
 # are the elements of LIST (which can be lists themselves, for multiple
 # arguments MACROs).
 m4_define([m4_map_sep],
-[m4_if([$3], [[]], [],
-       [$1(m4_fst($3))[]dnl
-m4_if(m4_cdr($3),
-      [[]], [],
-      [$2])[]dnl
-m4_map_sep([$1], [$2], m4_cdr($3))])])
+[m4_ifval([$3],
+         [$1(m4_fst($3))[]m4_map([$2[]$1], m4_cdr($3))])])
 
 
 ## ---------------------------------------- ##
@@ -680,14 +686,10 @@ m4_if($1, [$2], [],
 m4_define([m4_foreach],
 [m4_pushdef([$1])_m4_foreach($@)m4_popdef([$1])])
 
-# Low level macros used to define m4_foreach.
-m4_define([m4_car], [[$1]])
-m4_define([m4_cdr], [m4_dquote(m4_shift($@))])
 m4_define([_m4_foreach],
-[m4_if([$2], [[]], [],
-       [m4_define([$1], m4_car($2))$3[]_m4_foreach([$1],
-                                                  m4_cdr($2),
-                                                  [$3])])])
+[m4_ifval([$2],
+         [m4_define([$1], m4_car($2))$3[]dnl
+_m4_foreach([$1], m4_cdr($2), [$3])])])