(_AS_CASE): Private helper macro.
* tests/m4sh.at: Basic tests for AS_IF and AS_CASE.
* doc/autoconf.texi (Programming in M4sh): Document AS_CASE.
Fix syntax of AS_IF description
(Prerequisite Macros): Mention AS_IF and AS_CASE as workarounds
for the AC_REQUIRE mess.
* NEWS: Mention AS_CASE, AS_BOURNE_COMPATIBLE, and
AS_SHELL_SANITIZE.
+2006-02-15 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
+
+ * lib/m4sugar/m4sh.m4 (AS_CASE): New macro.
+ (_AS_CASE): Private helper macro.
+ * tests/m4sh.at: Basic tests for AS_IF and AS_CASE.
+ * doc/autoconf.texi (Programming in M4sh): Document AS_CASE.
+ Fix syntax of AS_IF description
+ (Prerequisite Macros): Mention AS_IF and AS_CASE as workarounds
+ for the AC_REQUIRE mess.
+ * NEWS: Mention AS_CASE, AS_BOURNE_COMPATIBLE, and
+ AS_SHELL_SANITIZE.
+
2006-02-14 Paul Eggert <eggert@cs.ucla.edu>
* doc/autoconf.texi: Minor style cleanup.
** AS_HELP_STRING
The macro correctly handles quadrigraphs now.
+** AS_BOURNE_COMPATIBLE, AS_SHELL_SANITIZE, AS_CASE
+ These macros are new or published now.
+
** AT_COPYRIGHT
New macro for copyright notices in testsuite files.
implementation-specific actions.
@end defmac
+@defmac AS_CASE (@var{word}, @ovar{pattern1}, @ovar{if-matched1}, @dots{}, @ovar{default})
+@asindex{CASE}
+Expand into a shell @samp{case} statement, where @var{word} is matched
+against one or more patterns. @var{if-matched} is run if the
+corresponding pattern matched @var{word}, else @var{default} is run.
+@end defmac
+
@defmac AS_DIRNAME (@var{file-name})
@asindex{DIRNAME}
Return the directory portion of @var{file-name}, using the algorithm
@command{dirname} command.
@end defmac
-@defmac AS_IF (@var{test}, @ovar{RUN-IF-TRUE}, @ovar{RUN-IF-FALSE})
+@defmac AS_IF (@var{test}, @ovar{run-if-true}, @ovar{run-if-false})
@asindex{IF}
-Run shell code TEST@. If TEST exits with a zero status then run shell code
-RUN-IF-TRUE, else run shell code RUN-IF-FALSE, with simplifications if either
-RUN-IF-TRUE or RUN-IF-FALSE is empty.
+Run shell code @var{test}. If @var{test} exits with a zero status then
+run shell code @var{run-if-true}, else run shell code @var{run-if-false},
+with simplifications if either @var{run-if-true} or @var{run-if-false}
+is empty.
@end defmac
@defmac AS_MKDIR_P (@var{file-name})
@end group
@end example
-
-You are encouraged to put all @code{AC_REQUIRE}s at the beginning of a
-macro. You can use @code{dnl} to avoid the empty lines they leave.
+The helper macros @code{AS_IF} and @code{AS_CASE} may be used to
+enforce expansion of required macros outside of shell conditional
+constructs. You are furthermore encouraged to put all @code{AC_REQUIRE}s
+at the beginning of a macro. You can use @code{dnl} to avoid the empty
+lines they leave.
@node Suggested Ordering
@subsection Suggested Ordering
])# AS_IF
+# AS_CASE(WORD, [PATTERN1], [IF-MATCHED1]...[DEFAULT])
+# ----------------------------------------------------
+# Expand into
+# | case WORD in
+# | PATTERN1) IF-MATCHED1 ;;
+# | ...
+# | *) DEFAULT ;;
+# | esac
+m4_define([_AS_CASE],
+[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
+ [$#], 1, [ *) $1 ;;],
+ [$#], 2, [ $1) m4_default([$2], [:]) ;;],
+ [ $1) m4_default([$2], [:]) ;;
+$0(m4_shiftn(2, $@))])dnl
+])
+m4_defun([AS_CASE],
+[m4_ifval([$2$3],
+[case $1 in
+_AS_CASE(m4_shift($@))
+esac
+])dnl
+])# AS_CASE
+
+
# _AS_UNSET_PREPARE
# -----------------
# AS_UNSET depends upon $as_unset: compute it.
]])
AT_CLEANUP
+
+
+## ------------------- ##
+## AS_IF and AS_CASE. ##
+## ------------------- ##
+
+AT_SETUP([AS@&t@_IF and AS@&t@_CASE])
+
+AT_DATA_M4SH([script.as], [[dnl
+AS_INIT
+# Syntax checks: cope with empty arguments.
+AS_IF([:], [], [echo wrong])
+AS_IF([:], [:], [echo wrong])
+AS_IF([false], [echo wrong], [:])
+AS_IF([false], [echo wrong])
+AS_CASE([foo])
+AS_CASE([foo], [:])
+AS_CASE([foo],
+ [foo], [:],
+ [echo wrong])
+AS_CASE([foo],
+ [foo], [:],
+ [*], [echo wrong])
+AS_CASE([foo],
+ [bar], [echo wrong],
+ [foo], [:],
+ [*], [echo wrong])
+]])
+
+AT_CHECK_M4SH
+AT_CHECK([./script])
+
+AT_CLEANUP