| From: Akim Demaille <[EMAIL PROTECTED]>
| Date: 01 Aug 2000 14:52:47 +0200
|
| Why don't we use AWK? I know it's not in the standards, but are
| there any good reasons for this?
|
| We could use AWK as a fallback if the standard tools fail. However, I
| think we can do it with the standard tools. The following works for
| me, using Solaris 8 /usr/ucb/expr (sorry, I no longer have a SunOS 4
| host to test with).
|
| # Prefer expr to sed, since it's usually faster and it handles
| # newlines correctly. However, SunOS 4 expr and Solaris
| # /usr/ucb/expr have a silly length limit that causes expr to
| # fail if the matched substring is longer than 128 bytes.
| # So use sed if expr fails.
| dirname=`expr "X$filename" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
| "X$filename" : 'X\(//\)[^/]' \| \
| "X$filename" : 'X\(//\)$' \| \
| "X$filename" : 'X\(/\)' \| \
| . : '\(.\)' \
| 2>/dev/null` ||
| dirname=`
| sed '
| /^\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/p; q; }
| /^\(\/\/\)[^/].*/{ s//\1/p; q; }
| /^\(\/\/\)$/{ s//\1/p; q; }
| /^\(\/\).*/{ s//\1/p; q; }
| s/.*/./p; q
| ' <<EOF
| $filename
| EOF
| `
We want to be able to use AC_SHELL_DIRNAME inside back quotes. And
I'm somewhat pessimistic on here docs embedded inside back quotes.
What do you think?
Here is my non heredoc proposal:
Index: ChangeLog
from Akim Demaille <[EMAIL PROTECTED]>
Solaris' /usr/ucb/expr, and SunOS' /usr/bin/expr fail with the `:'
operator when \(\) is used, and matches a string longer than 120
characters.
Reported by Geoff Keating.
* acgeneral.m4 (_AC_SHELL_DIRNAME): Fall back to echo|sed if expr
fails.
From Paul Eggert.
Index: acgeneral.m4
===================================================================
RCS file: /cvs/autoconf/acgeneral.m4,v
retrieving revision 1.540
diff -u -r1.540 acgeneral.m4
--- acgeneral.m4 2000/08/01 12:20:15 1.540
+++ acgeneral.m4 2000/08/03 09:31:42
@@ -816,7 +816,13 @@
X$1 : 'X\(//\)[[^/]]' \| \
X$1 : 'X\(//\)$' \| \
X$1 : 'X\(/\)' \| \
- . : '\(.\)'])
+ . : '\(.\)' 2>/dev/null ||
+echo "X$1" | sed '
+ /^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/p; q; }
+ /^X\(\/\/\)[^/].*/{ s//\1/p; q; }
+ /^X\(\/\/\)$/{ s//\1/p; q; }
+ /^X\(\/\).*/{ s//\1/p; q; }
+ s/.*/./p; q'])
## --------------------------------------------------- ##