From: Eric Blake Date: Wed, 5 Nov 2008 18:12:42 +0000 (-0700) Subject: Use _m4_foreach in more places. X-Git-Tag: v2.63b~137 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=641487fb34b8bb642ece91340d9fa2a57d75d9ee;p=thirdparty%2Fautoconf.git 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 m4_foreach. * lib/m4sugar/m4sugar.m4 (_m4_joinall): Use m4_map_args_sep instead of m4_foreach or m4_map_args. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index b5a82a845..3be1d3a1f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2008-11-05 Eric Blake + 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 + m4_foreach. + * lib/m4sugar/m4sugar.m4 (_m4_joinall): Use m4_map_args_sep + instead of m4_foreach or m4_map_args. + Unify _m4_foreach and _m4_map. * lib/m4sugar/m4sugar.m4 (_m4_map): Delete, merged with... (_m4_foreach): ...this. diff --git a/lib/m4sugar/foreach.m4 b/lib/m4sugar/foreach.m4 index f4325987a..d9ebfe0e5 100644 --- a/lib/m4sugar/foreach.m4 +++ b/lib/m4sugar/foreach.m4 @@ -248,9 +248,9 @@ m4_define([m4_do], # ------------------- # Return ARGS as an unquoted list of double-quoted arguments. # -# m4_foreach to the rescue. It's easier to shift off the leading comma. +# _m4_foreach to the rescue. m4_define([m4_dquote_elt], -[m4_shift(m4_foreach([_m4_elt], [$@], [,m4_dquote(_m4_defn([_m4_elt]))]))]) +[m4_if([$#], [0], [], [[[$1]]_m4_foreach([,m4_dquote(], [)], $@)])]) # m4_reverse(ARGS) # ---------------- @@ -299,23 +299,23 @@ m4_define([_m4_map_args_pair_end], # # Use a self-modifying separator, since we don't know how many # arguments might be skipped before a separator is first printed, but -# be careful if the separator contains $. m4_foreach to the rescue. +# be careful if the separator contains $. _m4_foreach to the rescue. m4_define([m4_join], [m4_pushdef([_m4_sep], [m4_define([_m4_sep], _m4_defn([m4_echo]))])]dnl -[m4_foreach([_m4_arg], [m4_shift($@)], - [m4_ifset([_m4_arg], [_m4_sep([$1])_m4_defn([_m4_arg])])])]dnl -[_m4_popdef([_m4_sep])]) +[_m4_foreach([_$0([$1],], [)], $@)_m4_popdef([_m4_sep])]) + +m4_define([_m4_join], +[m4_if([$2], [], [], [_m4_sep([$1])[$2]])]) # m4_joinall(SEP, ARG1, ARG2...) # ------------------------------ # Produce ARG1SEPARG2...SEPARGn. An empty ARG results in back-to-back SEP. # No expansion is performed on SEP or ARGs. # -# A bit easier than m4_join. m4_foreach to the rescue. +# A bit easier than m4_join. _m4_foreach to the rescue. m4_define([m4_joinall], [[$2]m4_if(m4_eval([$# <= 2]), [1], [], - [m4_foreach([_m4_arg], [m4_shift2($@)], - [[$1]_m4_defn([_m4_arg])])])]) + [_m4_foreach([$1], [], m4_shift($@))])]) # m4_list_cmp(A, B) # ----------------- @@ -358,12 +358,12 @@ m4_define([_m4_list_cmp__], # Return the decimal value of the maximum (or minimum) in a series of # integer expressions. # -# m4_foreach to the rescue; we only need to replace _m4_minmax. Here, +# _m4_foreach to the rescue; we only need to replace _m4_minmax. Here, # we need a temporary macro to track the best answer so far, so that # the foreach expression is tractable. m4_define([_m4_minmax], -[m4_pushdef([_m4_best], m4_eval([$2]))m4_foreach([_m4_arg], [m4_shift2($@)], - [m4_define([_m4_best], $1(_m4_best, _m4_defn([_m4_arg])))])]dnl +[m4_pushdef([_m4_best], m4_eval([$2]))_m4_foreach( + [m4_define([_m4_best], $1(_m4_best,], [))], m4_shift($@))]dnl [_m4_best[]_m4_popdef([_m4_best])]) # m4_set_add_all(SET, VALUE...) @@ -371,15 +371,15 @@ m4_define([_m4_minmax], # Add each VALUE into SET. This is O(n) in the number of VALUEs, and # can be faster than calling m4_set_add for each VALUE. # -# m4_foreach to the rescue. If no deletions have occurred, then avoid -# the speed penalty of m4_set_add. +# _m4_foreach to the rescue. If no deletions have occurred, then +# avoid the speed penalty of m4_set_add. m4_define([m4_set_add_all], [m4_if([$#], [0], [], [$#], [1], [], [m4_define([_m4_set_size($1)], m4_eval(m4_set_size([$1]) - + m4_len(m4_foreach([_m4_arg], [m4_shift($@)], - m4_ifdef([_m4_set_cleanup($1)], - [[m4_set_add([$1], _m4_defn([_m4_arg]))]], - [[m4_ifdef([_m4_set([$1],]_m4_defn([_m4_arg])[)], [], - [m4_define([_m4_set([$1],]_m4_defn([_m4_arg])[)], - [1])m4_pushdef([_m4_set([$1])], - _m4_defn([_m4_arg]))-])]])))))])]) + + m4_len(_m4_foreach(m4_ifdef([_m4_set_cleanup($1)], + [[m4_set_add]], [[_$0]])[([$1],], [)], $@))))])]) + +m4_define([_m4_set_add_all], +[m4_ifdef([_m4_set([$1],$2)], [], + [m4_define([_m4_set([$1],$2)], + [1])m4_pushdef([_m4_set([$1])], [$2])-])]) diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index 89d26c336..5107792d5 100644 --- a/lib/m4sugar/m4sugar.m4 +++ b/lib/m4sugar/m4sugar.m4 @@ -2171,20 +2171,14 @@ m4_define([_m4_joinall], # m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3]) # => a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3 # -# In order to have the correct number of SEPARATORs, we use a temporary -# variable that redefines itself after the first use. We must use defn -# rather than overquoting in case PREFIX or SUFFIX contains $1, but use -# _m4_defn for speed. Likewise, we compute the m4_shift3 only once, -# rather than in each iteration of the outer m4_foreach. +# This definition is a bit hairy; the thing to realize is that we want +# to construct m4_map_args_sep([[prefix$3]], [], [[$1]], m4_shift3($@)) +# as the inner loop, using each prefix generated by the outer loop, +# and without recalculating m4_shift3 every outer iteration. m4_define([m4_combine], -[m4_if(m4_eval([$# > 3]), [1], - [m4_pushdef([m4_Separator], [m4_define([m4_Separator], - _m4_defn([m4_echo]))])]]dnl -[[m4_foreach([m4_Prefix], [$2], - [m4_map_args([m4_Separator([$1])]m4_dquote(_m4_defn( - [m4_Prefix]))[[$3]m4_echo], - ]]m4_dquote(m4_dquote(m4_shift3($@)))[[)])]]dnl -[[_m4_popdef([m4_Separator])])]) +[m4_if([$2], [], [], m4_eval([$# > 3]), [1], +[m4_map_args_sep([m4_map_args_sep(m4_dquote(], [)[[$3]], [], [[$1]],]]]dnl +[m4_dquote(m4_dquote(m4_shift3($@)))[[)], [[$1]], $2)])]) # m4_append(MACRO-NAME, STRING, [SEPARATOR])