]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Work around Solaris /bin/sh case bug.
authorEric Blake <ebb9@byu.net>
Thu, 30 Oct 2008 12:56:44 +0000 (06:56 -0600)
committerEric Blake <ebb9@byu.net>
Thu, 30 Oct 2008 13:40:59 +0000 (07:40 -0600)
* lib/m4sugar/m4sh.m4 (_AS_CASE, _AS_CASE_DEFAULT): Always provide
a non-empty command list.
(AS_CASE): Always guarantee that a case will match.
* doc/autoconf.texi (Limitations of Builtins) <case>: Document the
Solaris bug, and mention AS_CASE.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
doc/autoconf.texi
lib/m4sugar/m4sh.m4

index 8d2cd25960e8b1ef11f683945b7708a7f366d9c6..e19a3f6010c8603b370bb632e442af3c0fe70386 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-10-30  Eric Blake  <ebb9@byu.net>
+
+       Work around Solaris /bin/sh case bug.
+       * lib/m4sugar/m4sh.m4 (_AS_CASE, _AS_CASE_DEFAULT): Always provide
+       a non-empty command list.
+       (AS_CASE): Always guarantee that a case will match.
+       * doc/autoconf.texi (Limitations of Builtins) <case>: Document the
+       Solaris bug, and mention AS_CASE.
+
 2008-10-30  Paolo Bonzini  <bonzini@gnu.org>
 
        Require _AS_CR_PREPARE where appropriate.
index 1a2f748ff0683c835b3755341118b4c5df851755..d2997ef158cfa1744dedc9af1f8f597308c437a4 100644 (file)
@@ -14842,6 +14842,19 @@ ash-0.3.8 $ @kbd{case foo in esac;}
 @error{}Syntax error: ";" unexpected (expecting ")")
 @end example
 
+Posix requires @command{case} to give an exit status of 0 if no cases
+match.  However, @command{/bin/sh} in Solaris 10 does not obey this
+rule.  Meanwhile, it is unclear whether a case that matches, but
+contains no statements, must also change the exit status to 0.  The M4sh
+macro @code{AS_CASE} works around these inconsistencies.
+
+@example
+$ @kbd{bash -c 'case `false` in ?) ;; esac; echo $?'}
+0
+$ @kbd{/bin/sh -c 'case `false` in ?) ;; esac; echo $?'}
+255
+@end example
+
 
 @item @command{cd}
 @c ---------------
index a67c30d5181ae41a742002fe854394240b6f94b6..1f1f5999d5ac0a19c9233aa23aef9fb952cc375b 100644 (file)
@@ -492,16 +492,19 @@ _AS_UNSET_PREPARE
 # |   *) DEFAULT ;;
 # | esac
 # The shell comments are intentional, to work around people who don't
-# realize the impacts of using insufficient m4 quoting.
+# 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.
 m4_define([_AS_CASE],
 [ [@%:@(]
-  $1[)] $2 ;;])
+  $1[)] m4_default([$2], [:]) ;;])
 m4_define([_AS_CASE_DEFAULT],
 [ [@%:@(]
-  *[)] $1 ;;])
+  *[)] m4_default([$1], [:]) ;;])
 
 m4_defun([AS_CASE],
-[case $1 in[]m4_map_args_pair([_$0], [_$0_DEFAULT], m4_shift($@))
+[case $1 in[]m4_map_args_pair([_$0], [_$0_DEFAULT],
+   m4_shift($@m4_if(m4_eval([$# & 1]), [1], [,])))
 esac])# AS_CASE