2009-04-13 Eric Blake <ebb9@byu.net>
+ Make AS_IF, AS_CASE, and AS_FOR more robust to blank arguments.
+ * lib/m4sugar/m4sh.m4 (_AS_CASE, _AS_CASE_DEFAULT, AS_FOR, _AS_IF)
+ (_AS_IF_ELSE, AS_IF): Avoid syntax error on blank argument,
+ including a macro with an empty expansion.
+ * NEWS: Mention this.
+ * tests/m4sh.at (AS@&t@_IF and AS@&t@_CASE, AS@&t@_FOR): Update
+ tests.
+ Reported by Mike Frysinger.
+
Add m4_blank and friends.
* lib/m4sugar/m4sugar.m4 (m4_blank, m4_nblank, m4_default_nblank)
(m4_default_nblank_quoted): New macros.
* Major changes in Autoconf 2.64 (2009-??-??) [stable]
Released by Eric Blake, based on git versions 2.63b.*.
+** AS_IF, AS_CASE, and AS_FOR have been taught to avoid syntax errors
+ even when given arguments that expand to just whitespace.
+
** Ensure AT_CHECK can support commands that include a # given with
proper m4 quoting. For shell comments, this is a new feature; for
non-shell comments, this fixes a regression introduced in 2.63b.
# | esac
# The shell comments are intentional, to work around people who don't
# realize the impacts of using insufficient m4 quoting. This macro
-# always provides a default case, to work around a Solaris /bin/sh
-# bug regarding the exit status when no case matches.
+# always uses : and provides a default case, to work around Solaris
+# /bin/sh bugs regarding the exit status.
m4_define([_AS_CASE],
[ [@%:@(]
- $1[)] m4_default([$2], [:]) ;;])
+ $1[)] :
+ $2 ;;])
m4_define([_AS_CASE_DEFAULT],
[ [@%:@(]
- *[)] m4_default([$1], [:]) ;;])
+ *[)] :
+ $1 ;;])
m4_defun([AS_CASE],
[case $1 in[]m4_map_args_pair([_$0], [_$0_DEFAULT],
[m4_pushdef([$1], m4_if([$3], [], [[$$2]], m4_translit([$3], ]dnl
m4_dquote(_m4_defn([m4_cr_symbols2]))[[%+=:,./-]), [], [[$3]], [[$$2]]))]dnl
[for $2[]m4_ifval([$3], [ in $3])
-do
- m4_default([$4], [:])
+do :
+ $4
done[]_m4_popdef([$1])])
# with simplifications if IF-TRUE1 and/or IF-FALSE is empty.
#
m4_define([_AS_IF],
-[elif $1; then
- m4_default([$2], [:])
+[elif $1; then :
+ $2
])
m4_define([_AS_IF_ELSE],
-[m4_ifvaln([$1],
-[else
- $1])])
+[m4_ifnblank([$1],
+[else :
+ $1
+])])
m4_defun([AS_IF],
-[if $1; then
- m4_default([$2], [:])
+[if $1; then :
+ $2
m4_map_args_pair([_$0], [_$0_ELSE], m4_shift2($@))]dnl
[fi[]])# AS_IF
AS_CASE([`touch file; false`]) && test -f file && echo fifteen
dnl The next line is badly underquoted; don't intentionally copy this style.
AS_CASE([foo], [foo], m4_do(AS_CASE([bar], [bar], [echo sixteen])))
+dnl Handle blank arguments.
+AS_IF([false], [:], [ ]) && AS_CASE([foo], [foo], []
+) && echo seventeen
+m4_define([empty])AS_IF([false], [:], [empty]
+) && AS_CASE([foo], [foo], [empty]) && echo eighteen
# check that require works correctly
m4_for([n], 1, 9, [],
fourteen
fifteen
sixteen
+seventeen
+eighteen
foo1=1 bar1=1
foo2=2 bar2=
foo3=3 bar3=
AS_FOR([m4var], [shvar], [\'],
[echo "m4var $shvar"])
-# Syntax checks: cope with empty arguments.
+# Syntax checks: cope with empty/blank arguments.
set f g
AS_FOR([], [shvar], [],
[echo "m4_defn([]) $shvar"])
rm -f file
AS_FOR([], [shvar], [`touch file`])
test -f file || exit 1
+AS_FOR([], [shvar], [], [ ])
+m4_define([empty])AS_FOR([], [shvar], [], [empty])
# Check that break works.
while :