]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
* acgeneral.m4 (_AC_INIT_PARSE_ARGS): Don't use negated character
authorAkim Demaille <akim@epita.fr>
Thu, 25 May 2000 07:49:39 +0000 (07:49 +0000)
committerAkim Demaille <akim@epita.fr>
Thu, 25 May 2000 07:49:39 +0000 (07:49 +0000)
classes with `case'.  Use `expr' instead.
Suggested by Paul Eggert.
* doc/autoconf.texi (Limitations of Builtins): Explain expr, the
`x' trick, and negated character classes.

ChangeLog
acgeneral.m4
doc/autoconf.texi
lib/autoconf/general.m4

index ab9e40b1fa35d0c83bcdeab3528bb65b42966936..c7eb7a6223c46a6444b21b96606474f2ac58b5e7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2000-05-25  Akim Demaille  <akim@epita.fr>
+
+       * acgeneral.m4 (_AC_INIT_PARSE_ARGS): Don't use negated character
+       classes with `case'.  Use `expr' instead.
+       Suggested by Paul Eggert.
+       * doc/autoconf.texi (Limitations of Builtins): Explain expr, the
+       `x' trick, and negated character classes.
+
 2000-05-24  Didier Verna  <didier@lrde.epita.fr>
 
        * acgeneral.m4 (AC_INIT): Call _AC_PACKAGE before _AC_INIT.
index b3285ccfe0fcf3e5253e53c1994400e5fc516555..8cd9715c1d192e0629e8588ca77be1b14bdcda3a 100644 (file)
@@ -1016,18 +1016,16 @@ do
   -disable-* | --disable-*)
     ac_feature=`echo "$ac_option" |sed -e 's/-*disable-//'`
     # Reject names that are not valid shell variable names.
-    case $ac_feature in
-      *[[^-a-zA-Z0-9_]]*) AC_MSG_ERROR([invalid feature: $ac_feature]);;
-    esac
+    expr "x$ac_feature" : "[.*[^-a-zA-Z0-9_]]" >/dev/null &&
+      AC_MSG_ERROR([invalid feature name: $ac_feature])
     ac_feature=`echo $ac_feature | sed 's/-/_/g'`
     eval "enable_$ac_feature=no" ;;
 
   -enable-* | --enable-*)
     ac_feature=`echo "$ac_option" | sed -e 's/-*enable-//;s/=.*//'`
     # Reject names that are not valid shell variable names.
-    case $ac_feature in
-      [*[^-a-zA-Z0-9_]*]) AC_MSG_ERROR([invalid feature: $ac_feature]);;
-    esac
+    expr "x$ac_feature" : "[.*[^-a-zA-Z0-9_]]" >/dev/null &&
+      AC_MSG_ERROR([invalid feature name: $ac_feature])
     ac_feature=`echo $ac_feature | sed 's/-/_/g'`
     case "$ac_option" in
       *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
@@ -1209,9 +1207,8 @@ do
   -with-* | --with-*)
     ac_package=`echo "$ac_option"|sed -e 's/-*with-//;s/=.*//'`
     # Reject names that are not valid shell variable names.
-    case $ac_package in
-      [*[^-a-zA-Z0-9_]*]) AC_MSG_ERROR([invalid package: $ac_package]);;
-    esac
+    expr "x$ac_package" : "[.*[^-a-zA-Z0-9_]]" >/dev/null &&
+      AC_MSG_ERROR([invalid package name: $ac_package])
     ac_package=`echo $ac_package| sed 's/-/_/g'`
     case "$ac_option" in
       *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
@@ -1222,9 +1219,8 @@ do
   -without-* | --without-*)
     ac_package=`echo "$ac_option" |sed -e 's/-*without-//'`
     # Reject names that are not valid shell variable names.
-    case $ac_package in
-      [*[^-a-zA-Z0-9_]*]) AC_MSG_ERROR([invalid package: $ac_package]);;
-    esac
+    expr "x$ac_package" : "[.*[^-a-zA-Z0-9_]]" >/dev/null &&
+      AC_MSG_ERROR([invalid package name: $ac_package])
     ac_package=`echo $ac_package | sed 's/-/_/g'`
     eval "with_${ac_package}=no" ;;
 
@@ -1253,18 +1249,16 @@ Try `configure --help' for more information.])
   *=*)
     ac_envvar=`echo "$ac_option" | sed -e 's/=.*//'`
     # Reject names that are not valid shell variable names.
-    case $ac_envvar in
-      [*[^a-zA-Z0-9_]*]) AC_MSG_ERROR([invalid variable name: $ac_envvar]);;
-    esac
+    expr "x$ac_envvar" : "[.*[^a-zA-Z0-9_]]" >/dev/null &&
+      AC_MSG_ERROR([invalid variable name: $ac_envvar])
     ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`
     eval "$ac_envvar='$ac_optarg'"
     export $ac_envvar ;;
 
   *)
-    case $ac_option in
-      [*[^-a-zA-Z0-9.]*]) AC_MSG_WARN([invalid host type: $ac_option]);;
-    esac
     AC_MSG_WARN([you should use --build, --host, --target])
+    expr "x$ac_option" : "[.*[^a-zA-Z0-9.]]" >/dev/null &&
+      AC_MSG_WARN([invalid host type: $ac_option])
     : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
     ;;
 
index 6505aeadca64434ba27cbda289bd6813e36e1b78..bafed6fcaa2aebe3fecc40667fc16919e2259adb 100644 (file)
@@ -4726,6 +4726,13 @@ inside double-quoted backquoted expressions (Pfew!).
 
 No no, we are serious: some shells do have limitations :)
 
+You should always keep in mind that any built-in or command may support
+options, and therefore have a very different behavior with arguments
+starting with a dash.  For instance, the innocent @samp{echo "$word"}
+can give unexpected results when @code{word} starts with a dash.  It is
+often possible to avoid this problem using @samp{echo "x$word"}, taking
+the @samp{x} into account later in the pipe.
+
 @table @asis
 @item @command{case}
 @cindex @command{case}
@@ -4861,6 +4868,29 @@ case $ac_feature in
 esac
 @end example
 
+Alas, negated character classes are not portable (some old shells
+support the @samp{[!...]} syntax, some modern shells such as
+@command{zsh} support only the more recent syntax @samp{[^...]}).  One
+solution can be:
+
+@example
+expr "$ac_feature" : ".*[^-a-zA-Z0-9_]" >/dev/null &&
+  @var{action}
+@end example
+
+@noindent
+or better yet
+
+@example
+expr "x$ac_feature" : ".*[^-a-zA-Z0-9_]" >/dev/null &&
+  @var{action}
+@end example
+
+It is somewhat more robust than the @samp{echo | grep} solution which
+suffers the limitations of @command{echo}: its argument should be too
+special (containing backslashes).
+
+
 @item @command{unset}
 @cindex @command{unset}
 You cannot assume the support of @command{unset}, nevertheless, because
@@ -4911,6 +4941,15 @@ foo
 
 @command{egrep} also suffers the limitations of @command{grep}.
 
+@item @command{expr}
+@cindex @command{expr}
+Don't use @samp{\?}, @samp{\+} and @samp{\|} which are not supported by
+Solaris.
+
+There is no known command of @command{expr} starting with @samp{x}, so
+using @samp{expr x"@var{word}" : '@var{regex}'} avoids problems if
+@var{word} happens to have a meaning for @command{expr}.
+
 @item @command{grep}
 @cindex @command{grep}
 Don't use @samp{grep -s} to suppress output, because @samp{grep -s} on
index b3285ccfe0fcf3e5253e53c1994400e5fc516555..8cd9715c1d192e0629e8588ca77be1b14bdcda3a 100644 (file)
@@ -1016,18 +1016,16 @@ do
   -disable-* | --disable-*)
     ac_feature=`echo "$ac_option" |sed -e 's/-*disable-//'`
     # Reject names that are not valid shell variable names.
-    case $ac_feature in
-      *[[^-a-zA-Z0-9_]]*) AC_MSG_ERROR([invalid feature: $ac_feature]);;
-    esac
+    expr "x$ac_feature" : "[.*[^-a-zA-Z0-9_]]" >/dev/null &&
+      AC_MSG_ERROR([invalid feature name: $ac_feature])
     ac_feature=`echo $ac_feature | sed 's/-/_/g'`
     eval "enable_$ac_feature=no" ;;
 
   -enable-* | --enable-*)
     ac_feature=`echo "$ac_option" | sed -e 's/-*enable-//;s/=.*//'`
     # Reject names that are not valid shell variable names.
-    case $ac_feature in
-      [*[^-a-zA-Z0-9_]*]) AC_MSG_ERROR([invalid feature: $ac_feature]);;
-    esac
+    expr "x$ac_feature" : "[.*[^-a-zA-Z0-9_]]" >/dev/null &&
+      AC_MSG_ERROR([invalid feature name: $ac_feature])
     ac_feature=`echo $ac_feature | sed 's/-/_/g'`
     case "$ac_option" in
       *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
@@ -1209,9 +1207,8 @@ do
   -with-* | --with-*)
     ac_package=`echo "$ac_option"|sed -e 's/-*with-//;s/=.*//'`
     # Reject names that are not valid shell variable names.
-    case $ac_package in
-      [*[^-a-zA-Z0-9_]*]) AC_MSG_ERROR([invalid package: $ac_package]);;
-    esac
+    expr "x$ac_package" : "[.*[^-a-zA-Z0-9_]]" >/dev/null &&
+      AC_MSG_ERROR([invalid package name: $ac_package])
     ac_package=`echo $ac_package| sed 's/-/_/g'`
     case "$ac_option" in
       *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
@@ -1222,9 +1219,8 @@ do
   -without-* | --without-*)
     ac_package=`echo "$ac_option" |sed -e 's/-*without-//'`
     # Reject names that are not valid shell variable names.
-    case $ac_package in
-      [*[^-a-zA-Z0-9_]*]) AC_MSG_ERROR([invalid package: $ac_package]);;
-    esac
+    expr "x$ac_package" : "[.*[^-a-zA-Z0-9_]]" >/dev/null &&
+      AC_MSG_ERROR([invalid package name: $ac_package])
     ac_package=`echo $ac_package | sed 's/-/_/g'`
     eval "with_${ac_package}=no" ;;
 
@@ -1253,18 +1249,16 @@ Try `configure --help' for more information.])
   *=*)
     ac_envvar=`echo "$ac_option" | sed -e 's/=.*//'`
     # Reject names that are not valid shell variable names.
-    case $ac_envvar in
-      [*[^a-zA-Z0-9_]*]) AC_MSG_ERROR([invalid variable name: $ac_envvar]);;
-    esac
+    expr "x$ac_envvar" : "[.*[^a-zA-Z0-9_]]" >/dev/null &&
+      AC_MSG_ERROR([invalid variable name: $ac_envvar])
     ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`
     eval "$ac_envvar='$ac_optarg'"
     export $ac_envvar ;;
 
   *)
-    case $ac_option in
-      [*[^-a-zA-Z0-9.]*]) AC_MSG_WARN([invalid host type: $ac_option]);;
-    esac
     AC_MSG_WARN([you should use --build, --host, --target])
+    expr "x$ac_option" : "[.*[^a-zA-Z0-9.]]" >/dev/null &&
+      AC_MSG_WARN([invalid host type: $ac_option])
     : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
     ;;