]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
* lib/m4sugar/m4sh.m4 (AS_CASE): New macro.
authorRalf Wildenhues <Ralf.Wildenhues@gmx.de>
Wed, 15 Feb 2006 07:00:29 +0000 (07:00 +0000)
committerRalf Wildenhues <Ralf.Wildenhues@gmx.de>
Wed, 15 Feb 2006 07:00:29 +0000 (07:00 +0000)
(_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.

ChangeLog
NEWS
doc/autoconf.texi
lib/m4sugar/m4sh.m4
tests/m4sh.at

index 8662fa90c868566b16a23a321146642399d38989..ff4e014f24d9aee2b702f070a429bd9e90eed5e5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+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.
diff --git a/NEWS b/NEWS
index f82dad533ee97627607a666708bae35bccca9f74..57c277800154144f397c5614c39863bcf9811972 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -64,6 +64,9 @@
 ** 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.
 
index f1650a93a9aebe9d6eb49ac1d178c8e807d2e559..d88df12126b8c8ab0cddf83cb33142fe3e33d808 100644 (file)
@@ -9009,6 +9009,13 @@ environment variables, or setting options, or similar
 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
@@ -9017,11 +9024,12 @@ details about what this returns and why it is more portable than the
 @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})
@@ -9430,9 +9438,11 @@ SOME_CHECK
 @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
index c3cd7074a347c21ac54cb3786e36242853b93bf0..8521592c3cc91e0c35c2b9fa3e8360bf328b5b11 100644 (file)
@@ -460,6 +460,30 @@ fi
 ])# 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.
index be124ff19ea0471e321c0f4038b1af81cbddd33c..5879fa752158292ee9896ea51da99c105a014122 100644 (file)
@@ -533,3 +533,36 @@ AT_CHECK([./script], [0],
 ]])
 
 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