+2002-03-04 Akim Demaille <akim@epita.fr>
+
+ Instead of having stacking `shift's evaluated at the end, let
+ `foreach' loops immediately evaluate them.
+
+ * lib/m4sugar/m4sugar.m4 (m4_quote, m4_dquote): Use $@ rather than
+ $*. This is the n-th time I change my mind, but hopefully this is
+ the last...
+ (m4_lquote): New.
+ (m4_text_wrap): Use m4_foreach, which is finally correct _and_
+ efficient.
+ (m4_foreach_quoted, m4_car_quoted, _m4_foreach_quoted): Remove, as
+ it was only a hack for m4_text_wrap.
+ (m4_car2): Remove, replaced by...
+ (m4_cdr): New.
+ (_m4_foreach): Adjust.
+ * lib/autoconf/general.m4 (_AC_INIT_PREPARE): Adjust, and use
+ m4_bpatsubst for clarification.
+
2002-03-04 Akim Demaille <akim@epita.fr>
* doc/autoconf.texi (Changequote is Evil): New.
m4_builtin([popdef], $@)])
-# m4_quote(STRING)
-# ----------------
-# Return STRING quoted.
+# m4_quote(ARGS)
+# --------------
+# Return ARGS quoted. Note that a list of quoted arguments is returned,
+# not a quoted list.
#
# It is important to realize the difference between `m4_quote(exp)' and
# `[exp]': in the first case you obtain the quoted *result* of the
# expansion of EXP, while in the latter you just obtain the string
# `exp'.
-m4_define([m4_quote], [[$*]])
-m4_define([m4_dquote], [[[$*]]])
+m4_define([m4_quote], [[$*]])
+m4_define([m4_lquote], [$@])
+m4_define([m4_dquote], [[$@]])
# m4_noquote(STRING)
# Low level macros used to define m4_foreach.
m4_define([m4_car], [[$1]])
-m4_define([m4_car2], [[$@]])
+m4_define([m4_cdr], [m4_dquote(m4_shift($@))])
m4_define([_m4_foreach],
-[m4_if(m4_quote($2), [], [],
+[m4_if([$2], [[]], [],
[m4_define([$1], [m4_car($2)])$3[]_m4_foreach([$1],
- m4_car2(m4_shift($2)),
+ m4_cdr($2),
[$3])])])
# ------------
# Regexp for `[a-zA-Z_0-9]*'
m4_define([m4_re_string],
-m4_dquote(m4_defn([m4_cr_symbols2]))dnl
+m4_quote(m4_defn([m4_cr_symbols2]))dnl
[*]dnl
)
# ----------
# Regexp for `[a-zA-Z_][a-zA-Z_0-9]*'
m4_define([m4_re_word],
-m4_dquote(m4_defn([m4_cr_symbols1]))dnl
+m4_quote(m4_defn([m4_cr_symbols1]))dnl
m4_defn([m4_re_string])dnl
)
[m4_append($@)])])
-# m4_foreach_quoted(VARIABLE, LIST, EXPRESSION)
-# ---------------------------------------------
-# FIXME: This macro should not exists. Currently it's used only in
-# m4_wrap, which needs to be rewritten. But it's godam hard.
-m4_define([m4_foreach_quoted],
-[m4_pushdef([$1], [])_m4_foreach_quoted($@)m4_popdef([$1])])
-
-# Low level macros used to define m4_foreach.
-m4_define([m4_car_quoted], [[$1]])
-m4_define([_m4_foreach_quoted],
-[m4_if($2, [()], ,
- [m4_define([$1], [m4_car_quoted$2])$3[]_m4_foreach_quoted([$1],
- [(m4_shift$2)],
- [$3])])])
-
-
# m4_text_wrap(STRING, [PREFIX], [FIRST-PREFIX], [WIDTH])
# -------------------------------------------------------
# Expands into STRING wrapped to hold in WIDTH columns (default = 79).
m4_if(m4_eval(m4_Cursor > m4_len(m4_Prefix)),
1, [m4_define([m4_Cursor], m4_len(m4_Prefix))
m4_Prefix])[]dnl
-m4_foreach_quoted([m4_Word], (m4_split(m4_normalize([$1]))),
-[m4_define([m4_Cursor], m4_eval(m4_Cursor + m4_len(m4_Word) + 1))dnl
+m4_foreach([m4_Word], m4_quote(m4_split(m4_normalize([$1]))),
+[m4_define([m4_Cursor], m4_eval(m4_Cursor + m4_len(m4_defn([m4_Word])) + 1))dnl
dnl New line if too long, else insert a space unless it is the first
dnl of the words.
m4_if(m4_eval(m4_Cursor > m4_Width),
1, [m4_define([m4_Cursor],
- m4_eval(m4_len(m4_Prefix) + m4_len(m4_Word) + 1))]
+ m4_eval(m4_len(m4_Prefix) + m4_len(m4_defn([m4_Word])) + 1))]
m4_Prefix,
[m4_Separator])[]dnl
-m4_Word[]dnl
+m4_defn([m4_Word])[]dnl
m4_define([m4_Separator], [ ])])dnl
m4_popdef([m4_Separator])dnl
m4_popdef([m4_Cursor])dnl