# -------------------
# 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)
# ----------------
#
# 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)
# -----------------
# 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...)
# 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])-])])
# 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])