Hello,

On Sat, Apr 01, 2006 at 12:14:11PM -0700, Eric Blake wrote:
> [...] the addition of _AS_DIRNAME_PREPARE.

OK, I committed the patch autoconf-20060401-as-dirname-prepare.patch,
attached below.

That means I had to update my AS_CASE patch again; the updated version
is also attached to this mail, called autoconf-20060401-as-basename3.patch
(Not commmitted, waits after 2.60.)

Stepan
2006-04-01  Stepan Kasal  <[EMAIL PROTECTED]>

        * lib/m4sugar/m4sh.m4 (_AS_DIRNAME_PREPARE): New macro.
        (AS_DIRNAME): Use it.

Index: lib/m4sugar/m4sh.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/m4sugar/m4sh.m4,v
retrieving revision 1.170
diff -u -r1.170 m4sh.m4
--- lib/m4sugar/m4sh.m4 1 Apr 2006 19:38:07 -0000       1.170
+++ lib/m4sugar/m4sh.m4 1 Apr 2006 19:46:59 -0000
@@ -743,11 +743,23 @@
          s/.*/./; q']])
 
 m4_defun([AS_DIRNAME],
-[(dirname $1) 2>/dev/null ||
+[AS_REQUIRE([_$0_PREPARE])dnl
+$as_dirname $1 ||
 AS_DIRNAME_EXPR([$1]) 2>/dev/null ||
 AS_DIRNAME_SED([$1])])
 
 
+# _AS_DIRNAME_PREPARE
+# --------------------
+m4_defun([_AS_DIRNAME_PREPARE],
+[if (dirname /) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+])# _AS_DIRNAME_PREPARE
+
+
 # AS_EXECUTABLE_P
 # ---------------
 # Check whether a file is executable.
2006-04-01  Stepan Kasal  <[EMAIL PROTECTED]>

        * lib/m4sugar/m4sh.m4 (AS_DIRNAME): Reimplement using AS_CASE.
        (AS_BASENAME): Likewise.
        (AS_DIRNAME_EXPR, AS_DIRNAME_SED, AS_BASENAME_EXPR, AS_BASENAME_SED):
          Nuke.
        * tests/m4sh.at (AS_DIRNAME, AS_BASENAME): Do not test the removed
          macros.

Index: lib/m4sugar/m4sh.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/m4sugar/m4sh.m4,v
retrieving revision 1.169
diff -u -r1.169 m4sh.m4
--- lib/m4sugar/m4sh.m4 1 Apr 2006 18:32:10 -0000       1.169
+++ lib/m4sugar/m4sh.m4 1 Apr 2006 18:38:01 -0000
@@ -659,36 +659,28 @@
 # AS_BASENAME(FILE-NAME)
 # ----------------------
 # Simulate the command 'basename FILE-NAME'.  Not all systems have basename.
-# Also see the comments for AS_DIRNAME.
-
-m4_defun([AS_BASENAME_EXPR],
-[AS_REQUIRE([_AS_EXPR_PREPARE])dnl
-$as_expr X/[]$1 : '.*/\([[^/][^/]*]\)/*$' \| \
-        X[]$1 : 'X\(//\)$' \| \
-        X[]$1 : 'X\(/\)' \| \
-        .     : '\(.\)'])
-
-m4_defun([AS_BASENAME_SED],
-[echo X/[]$1 |
-    sed ['/^.*\/\([^/][^/]*\)\/*$/{
-           s//\1/
-           q
-         }
-         /^X\/\(\/\/\)$/{
-           s//\1/
-           q
-         }
-         /^X\/\(\/\).*/{
-           s//\1/
-           q
-         }
-         s/.*/./; q']])
-
+# Try to respect the platform specific behavior for // and the empty string.
+#
+# This macro must be usable from inside ` `.
+#
+# Prefer expr to echo|sed, since expr is usually faster and it handles
+# backslashes and newlines correctly.  However, older expr
+# implementations (e.g. SunOS 4 expr and Solaris 8 /usr/ucb/expr) have
+# a silly length limit that causes expr to fail if the matched
+# substring is longer than 120 bytes.  So fall back on echo|sed if
+# expr fails.
+#
 m4_defun([AS_BASENAME],
 [AS_REQUIRE([_$0_PREPARE])dnl
-$as_basename $1 ||
-AS_BASENAME_EXPR([$1]) 2>/dev/null ||
-AS_BASENAME_SED([$1])])
+AS_REQUIRE([_AS_EXPR_PREPARE])dnl
+AS_CASE([$1],
+  [[*[!/]*]],
+    [$as_basename $1 ||
+     $as_expr X/[]$1 : '.*/\([[^/][^/]*]\)/*$' 2>/dev/null ||
+     echo X/[]$1 | sed ['s|^.*/\([^/][^/]*\)/*$|\1|']],
+  [//], [$as_basename $1 || echo //],
+  [''], [$as_basename $1 || echo .],
+  [echo /])])
 
 
 # _AS_BASENAME_PREPARE
@@ -706,47 +698,21 @@
 # AS_DIRNAME(FILE-NAME)
 # ---------------------
 # Simulate the command 'dirname FILE-NAME'.  Not all systems have dirname.
-# This macro must be usable from inside ` `.
+# Try to respect the platform specific behavior for //*.
+#
+# Also see the comments for AS_DIRNAME.
 #
-# Prefer expr to echo|sed, since expr is usually faster and it handles
-# backslashes and newlines correctly.  However, older expr
-# implementations (e.g. SunOS 4 expr and Solaris 8 /usr/ucb/expr) have
-# a silly length limit that causes expr to fail if the matched
-# substring is longer than 120 bytes.  So fall back on echo|sed if
-# expr fails.
-m4_defun([AS_DIRNAME_EXPR],
-[AS_REQUIRE([_AS_EXPR_PREPARE])dnl
-$as_expr X[]$1 : 'X\(.*[[^/]]\)//*[[^/][^/]]*/*$' \| \
-        X[]$1 : 'X\(//\)[[^/]]' \| \
-        X[]$1 : 'X\(//\)$' \| \
-        X[]$1 : 'X\(/\)' \| \
-        .     : '\(.\)'])
-
-m4_defun([AS_DIRNAME_SED],
-[echo X[]$1 |
-    sed ['/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
-           s//\1/
-           q
-         }
-         /^X\(\/\/\)[^/].*/{
-           s//\1/
-           q
-         }
-         /^X\(\/\/\)$/{
-           s//\1/
-           q
-         }
-         /^X\(\/\).*/{
-           s//\1/
-           q
-         }
-         s/.*/./; q']])
-
 m4_defun([AS_DIRNAME],
-[AS_REQUIRE([_$0_PREPARE])dnl
-$as_dirname $1 ||
-AS_DIRNAME_EXPR([$1]) 2>/dev/null ||
-AS_DIRNAME_SED([$1])])
+[AS_REQUIRE([_AS_EXPR_PREPARE])dnl
+AS_CASE([$1],
+  [[*[!/]/*[!/]*]],
+    [$as_dirname $1 ||
+     $as_expr X[]$1 : 'X\(.*[[^/]]\)//*[[^/][^/]]*/*$' 2>/dev/null ||
+     echo X[]$1 | sed ['s|^X\(.*[^/]\)//*[^/][^/]*/*$|\1|p']],
+  [[//|//[!/]*]],
+    [$as_dirname $1 || echo //],
+  [/*], [echo /],
+  [echo .])])
 
 
 # _AS_DIRNAME_PREPARE
Index: tests/m4sh.at
===================================================================
RCS file: /cvsroot/autoconf/autoconf/tests/m4sh.at,v
retrieving revision 1.45
diff -u -r1.45 m4sh.at
--- tests/m4sh.at       21 Feb 2006 09:30:01 -0000      1.45
+++ tests/m4sh.at       1 Apr 2006 18:38:02 -0000
@@ -111,17 +111,7 @@
 [dir=`AS_DIRNAME([$1])`
 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
   echo "dirname($1) = $dir instead of $2" >&2
-
-if test "$as_expr" != false; then
-  dir=`AS_DIRNAME_EXPR([$1])`
-  test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
-    echo "dirname_expr($1) = $dir instead of $2" >&2
-fi
-
-dir=`AS_DIRNAME_SED([$1])`
-test "$dir" = "$2" ||
-test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
-  echo "dirname_sed($1) = $dir instead of $2" >&2])
+])
 
 DIRNAME_TEST([/],              [/])
 DIRNAME_TEST([//],             [//],   [/])
@@ -170,10 +160,7 @@
 [base=`AS_BASENAME([$1])`
 test "$base" = "$2" ||
   echo "basename($1) = $base instead of $2" >&2
-
-base=`AS_BASENAME_SED([$1])`
-test "$base" = "$2" ||
-  echo "basename_sed($1) = $base instead of $2" >&2])
+])
 
 BASENAME_TEST([//1],             [1])
 BASENAME_TEST([/1],              [1])

Reply via email to