From: Eric Blake Date: Tue, 16 Oct 2007 18:18:24 +0000 (-0600) Subject: m4_map is a looping construct. X-Git-Tag: v2.62~212^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96a08a7ee4a9f88d0d7e848d3bca88c3054f064b;p=thirdparty%2Fautoconf.git m4_map is a looping construct. * lib/m4sugar/m4sugar.m4 (m4_map, _m4_map, m4_map_sep): Move. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index f5b770d9..b0f6842a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2007-10-16 Eric Blake + m4_map is a looping construct. + * lib/m4sugar/m4sugar.m4 (m4_map, _m4_map, m4_map_sep): Move. + Fix m4_map, and add some more utility macros. * lib/m4sugar/m4sugar.m4 (m4_apply, m4_count, m4_dquote_elt) (m4_echo, m4_make_list): New documented macros. diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index 459dc23b..ad46ae45 100644 --- a/lib/m4sugar/m4sugar.m4 +++ b/lib/m4sugar/m4sugar.m4 @@ -447,32 +447,6 @@ m4_define([m4_cond], [m4_if($1, [$2], [$3], [$0(m4_shift3($@))])])]) -# m4_map(MACRO, LIST) -# ------------------- -# Invoke MACRO($1), MACRO($2) etc. where $1, $2... are the elements -# of LIST. $1, $2... must in turn be lists, appropriate for m4_apply. -# -# Since LIST may be quite large, we want to minimize how often it appears -# in the expansion. Rather than use m4_car/m4_cdr iteration, we unbox the -# list, and use _m4_shift2 to detect the end of recursion. -m4_define([m4_map], -[m4_if([$2], [], [], - [_$0([$1], $2)])]) -m4_define([_m4_map], -[m4_if([$#], [1], [], - [m4_apply([$1], [$2])$0([$1]_m4_shift2($@))])]) - - -# m4_map_sep(MACRO, SEPARATOR, LIST) -# ---------------------------------- -# Invoke MACRO($1), SEPARATOR, MACRO($2), ..., MACRO($N) where $1, $2... $N -# are the elements of LIST, and are in turn lists appropriate for m4_apply. -# SEPARATOR is not further expanded. -m4_define([m4_map_sep], -[m4_if([$3], [], [], - [m4_apply([$1], m4_car($3))m4_map([[$2]$1]_m4_cdr($3))])]) - - ## ---------------------------------------- ## ## 6. Enhanced version of some primitives. ## ## ---------------------------------------- ## @@ -951,6 +925,31 @@ m4_define([m4_foreach_w], [m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])]) +# m4_map(MACRO, LIST) +# ------------------- +# Invoke MACRO($1), MACRO($2) etc. where $1, $2... are the elements +# of LIST. $1, $2... must in turn be lists, appropriate for m4_apply. +# +# Since LIST may be quite large, we want to minimize how often it appears +# in the expansion. Rather than use m4_car/m4_cdr iteration, we unbox the +# list, and use _m4_shift2 to detect the end of recursion. +m4_define([m4_map], +[m4_if([$2], [], [], + [_$0([$1], $2)])]) +m4_define([_m4_map], +[m4_if([$#], [1], [], + [m4_apply([$1], [$2])$0([$1]_m4_shift2($@))])]) + + +# m4_map_sep(MACRO, SEPARATOR, LIST) +# ---------------------------------- +# Invoke MACRO($1), SEPARATOR, MACRO($2), ..., MACRO($N) where $1, $2... $N +# are the elements of LIST, and are in turn lists appropriate for m4_apply. +# SEPARATOR is not further expanded. +m4_define([m4_map_sep], +[m4_if([$3], [], [], + [m4_apply([$1], m4_car($3))m4_map([[$2]$1]_m4_cdr($3))])]) + ## --------------------------- ## ## 9. More diversion support. ##