From: Eric Blake Date: Wed, 5 Nov 2008 18:47:04 +0000 (-0700) Subject: Unify m4_set_foreach and m4_set_map. X-Git-Tag: v2.63b~136 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8c4be749a992c2e9c2f0a59336f964f4cce6d4f;p=thirdparty%2Fautoconf.git Unify m4_set_foreach and m4_set_map. * lib/m4sugar/m4sugar.m4 (m4_set_map_sep): New macro, undocumented for now. (m4_set_contents, m4_set_foreach, m4_set_list, m4_set_listc) (m4_set_map): Adjust callers. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index 3be1d3a1f..d14b179f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2008-11-05 Eric Blake + Unify m4_set_foreach and m4_set_map. + * lib/m4sugar/m4sugar.m4 (m4_set_map_sep): New macro, undocumented + for now. + (m4_set_contents, m4_set_foreach, m4_set_list, m4_set_listc) + (m4_set_map): Adjust callers. + Use _m4_foreach in more places. * lib/m4sugar/foreach.m4 (m4_dquote_elt, m4_join, m4_joinall) (_m4_minmax, m4_set_add_all): Use _m4_foreach instead of diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index 5107792d5..15fd80701 100644 --- a/lib/m4sugar/m4sugar.m4 +++ b/lib/m4sugar/m4sugar.m4 @@ -2688,8 +2688,7 @@ m4_define([m4_set_contains], # Use _m4_popdef for speed. The existence of _m4_set_cleanup($1) # determines which version of _1 helper we use. m4_define([m4_set_contents], -[m4_ifdef([_m4_set_cleanup($1)], [_$0_1c], [_$0_1])([$1])_$0_2([$1], - [], [], [[$2]])]) +[m4_set_map_sep([$1], [], [], [[$2]])]) # _m4_set_contents_1(SET) # _m4_set_contents_1c(SET) @@ -2804,9 +2803,7 @@ m4_define([m4_set_empty], # guaranteed. This is faster than the corresponding m4_foreach([VAR], # m4_indir([m4_dquote]m4_set_listc([SET])), [ACTION]) m4_define([m4_set_foreach], -[m4_pushdef([$2])m4_ifdef([_m4_set_cleanup($1)], - [_m4_set_contents_1c], [_m4_set_contents_1])([$1])_m4_set_contents_2([$1], - [m4_define([$2],], [)$3[]])m4_popdef([$2])]) +[m4_pushdef([$2])m4_set_map_sep([$1], [m4_define([$2],], [)$3])]) # m4_set_intersection(SET1, SET2) # ------------------------------- @@ -2835,12 +2832,10 @@ m4_define([m4_set_intersection], # containing only the empty string; with m4_set_listc, a leading comma # is output if there are any elements. m4_define([m4_set_list], -[m4_ifdef([_m4_set_cleanup($1)], [_m4_set_contents_1c], - [_m4_set_contents_1])([$1])_m4_set_contents_2([$1], [], [], [,])]) +[m4_set_map_sep([$1], [], [], [,])]) m4_define([m4_set_listc], -[m4_ifdef([_m4_set_cleanup($1)], [_m4_set_contents_1c], - [_m4_set_contents_1])([$1])_m4_set_contents_2([$1], [,])]) +[m4_set_map_sep([$1], [,])]) # m4_set_map(SET, ACTION) # ----------------------- @@ -2848,12 +2843,19 @@ m4_define([m4_set_listc], # current element. ACTION should not recursively list SET's contents, # add elements to SET, nor delete any element from SET except the one # passed as an argument. The order that the elements are visited in -# is not guaranteed. This is faster than the corresponding +# is not guaranteed. This is faster than either of the corresponding # m4_map_args([ACTION]m4_set_listc([SET])) +# m4_set_foreach([SET], [VAR], [ACTION(m4_defn([VAR]))]) m4_define([m4_set_map], -[m4_ifdef([_m4_set_cleanup($1)], - [_m4_set_contents_1c], [_m4_set_contents_1])([$1])_m4_set_contents_2([$1], - [$2(], [)])]) +[m4_set_map_sep([$1], [$2(], [)])]) + +# m4_set_map_sep(SET, PRE, POST, SEP) +# ----------------------------------- +# For each element of SET, expand PRE[value]POST[], and expand SEP +# between elements. +m4_define([m4_set_map_sep], +[m4_ifdef([_m4_set_cleanup($1)], [_m4_set_contents_1c], + [_m4_set_contents_1])([$1])_m4_set_contents_2($@)]) # m4_set_remove(SET, VALUE, [IF-PRESENT], [IF-ABSENT]) # ----------------------------------------------------