From: Stepan Kasal Date: Mon, 6 Jun 2005 08:47:02 +0000 (+0000) Subject: Fix m4_cdr for one-member lists. X-Git-Tag: AUTOCONF-2.59c~350 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d354edbe652e75c5f0329e7e2c4de4b3c83887ee;p=thirdparty%2Fautoconf.git Fix m4_cdr for one-member lists. --- diff --git a/ChangeLog b/ChangeLog index a922359fc..d963409f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2005-06-06 Stepan Kasal + + 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 * lib/autoconf/general.m4 (_AC_INIT_DEFAULTS): Nuke ac_max_here_lines. diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index 642348144..71e007243 100644 --- a/lib/m4sugar/m4sugar.m4 +++ b/lib/m4sugar/m4sugar.m4 @@ -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])])])