# This file is part of Autoconf.
# Base M4 layer.
# Requires GNU M4.
-# Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
+# Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
[m4_if([$#], 0, [],
[$#], 1, [],
[$#], 2, [$2],
- m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shiftn(3, $@))],
- [$3])])
+ [m4_if(m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shiftn(3, $@))],
+ [$3])])])
+# m4_map(MACRO, LIST)
+# -------------------
+# Invoke MACRO($1), MACRO($2) etc. where $1, $2... are the elements
+# of LIST (which can be lists themselves, for multiple arguments MACROs).
+m4_define([m4_fst], [$1])
+m4_define([m4_map],
+[m4_if([$2], [], [],
+ [$2], [[]], [],
+ [$1(m4_fst($2))[]dnl
+m4_map([$1], m4_cdr($2))])])
+
+
+# m4_map_sep(MACRO, SEPARATOR, LIST)
+# ----------------------------------
+# Invoke MACRO($1), SEPARATOR, MACRO($2), ..., MACRO($N) where $1, $2... $N
+# are the elements of LIST (which can be lists themselves, for multiple
+# arguments MACROs).
+m4_define([m4_map_sep],
+[m4_if([$3], [[]], [],
+ [$1(m4_fst($3))[]dnl
+m4_if(m4_cdr($3),
+ [[]], [],
+ [$2])[]dnl
+m4_map_sep([$1], [$2], m4_cdr($3))])])
+
## ---------------------------------------- ##
## 6. Enhanced version of some primitives. ##
# ------------------
# This macro invokes all its arguments (in sequence, of course). It is
# useful for making your macros more structured and readable by dropping
-# unecessary dnl's and have the macros indented properly.
+# unnecessary dnl's and have the macros indented properly.
m4_define([m4_do],
[m4_if($#, 0, [],
$#, 1, [$1],
[$1[]m4_do(m4_shift($@))])])
+# m4_define_default(MACRO, VALUE)
+# -------------------------------
+# If MACRO is undefined, set it to VALUE.
+m4_define([m4_define_default],
+[m4_ifndef([$1], [m4_define($@)])])
+
+
# m4_default(EXP1, EXP2)
# ----------------------
# Returns EXP1 if non empty, otherwise EXP2.
m4_builtin([popdef], $@)])
-# m4_quote(STRING)
-# ----------------
-# Return STRING quoted.
+# m4_quote(ARGS)
+# --------------
+# Return ARGS as a single arguments.
#
# 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_dquote], [[$@]])
# m4_noquote(STRING)
# Implementing `foreach' loops in m4 is much more tricky than it may
# seem. Actually, the example of a `foreach' loop in the m4
# documentation is wrong: it does not quote the arguments properly,
-# which leads to undesired expansions.
+# which leads to undesirable expansions.
#
# The example in the documentation is:
#
# 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_define([$1], [m4_car($2)])$3[]_m4_foreach([$1],
- m4_car2(m4_shift($2)),
- [$3])])])
+[m4_if([$2], [[]], [],
+ [m4_define([$1], m4_car($2))$3[]_m4_foreach([$1],
+ 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_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_defn([m4_cr_symbols1])dnl
m4_defn([m4_re_string])dnl
)
# of brackets around $1 (don't forget that the result must be quoted
# too, hence one more quoting than applications).
#
-# Then notice the 2 last pattens: they are in charge of removing the
+# Then notice the 2 last patterns: they are in charge of removing the
# leading/trailing spaces. Why not just `[^ ]'? Because they are
# applied to doubly quoted strings, i.e. more or less [[STRING]]. So
# if there is a leading space in STRING, then it is the *third*
[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