An enhanced bctest submitted by Tim Rice <tim@multitalents.net>.
authorRichard Levitte <levitte@openssl.org>
Fri, 16 Mar 2001 09:13:11 +0000 (09:13 +0000)
committerRichard Levitte <levitte@openssl.org>
Fri, 16 Mar 2001 09:13:11 +0000 (09:13 +0000)
It now looks along $PATH for a working bc and returns the absolute
path to one that does work.

CHANGES
test/bctest

diff --git a/CHANGES b/CHANGES
index 764f8f648e6da1b5732e93cfcdecca2a22e6cb89..7940b565ffe2681ab6263d1ac6d935e2e6e6e0e1 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,10 @@
 
  Changes between 0.9.6 and 0.9.7  [xx XXX 2000]
 
+  *) Enhance bctest to search for a working bc along $PATH and print
+     it when found.
+     [Tim Rice <tim@multitalents.net> via Richard Levitte]
+
   *) Add a 'copy_extensions' option to the 'ca' utility. This copies
      extensions from a certificate request to the certificate.
      [Steve Henson]
index 6fa0663bb008e515e00234983bb4f07bdadb2bcd..3a5e912079de4bcb57854e7f638988043912b54a 100755 (executable)
@@ -12,7 +12,8 @@
 
 
 # Test for SunOS 5.[78] bc bug (or missing bc)
-if [ 0 != "`bc <<\EOF
+SunOStest() {
+if [ 0 != "`${1} <<\EOF
 obase=16
 ibase=16
 a=AD88C418F31B3FC712D0425001D522B3AE9134FF3A98C13C1FCC1682211195406C1A6C66C6A\
@@ -28,15 +29,16 @@ b=DCE91E7D120B983EA9A104B5A96D634DD644C37657B1C7860B45E6838999B3DCE5A555583C6\
 (a/b)*b + (a%b) - a
 EOF`" ]
 then
-  echo "bc does not work.  Consider installing GNU bc." >&2
-  echo "cat >/dev/null"
-  exit 1
+#  echo "bc does not work.  Consider installing GNU bc." >&2
+#  echo "cat >/dev/null"
+  return 1
 fi
-
+}
 
 # Test for SCO bc bug.
+SCOtest() {
 if [ "0
-0" != "`bc <<\EOF
+0" != "`${1} <<\EOF
 obase=16
 ibase=16
 -FFDD63BA1A4648F0D804F8A1C66C53F0D2110590E8A3907EC73B4AEC6F15AC177F176F2274D2\
@@ -64,21 +66,46 @@ D97935A7E1A14AD209D6CF811F55C6DB83AA9E6DFECFCD6669DED7171EE22A40C6181615CAF3F\
 5296964
 EOF`" ]
 then
-  echo "bc does not work.  Consider installing GNU bc." >&2
-  echo "cat >/dev/null"
-  exit 1
+#  echo "bc does not work.  Consider installing GNU bc." >&2
+#  echo "cat >/dev/null"
+  return 1
 fi
+}
 
+#
+# Find the full pathname(s) of bc
+#
+findBc()
+{
+    IFS=:
+    for i in $PATH; do
+       eval  test -x $i/bc  -a  ! -d $i/bc && { echo $i/bc ; }
+    done
+}
 
+Printtest() {
 # bc works, good.
 # Now check if it knows the 'print' command.
-if [ "OK" = "`bc 2>/dev/null <<\EOF
+if [ "OK" = "`${1} 2>/dev/null <<\EOF
 print \"OK\"
 EOF`" ]
 then
-    echo "bc"
+    echo "${1}"
 else
-    echo "sed 's/print.*//' | bc"
+    echo "sed 's/print.*//' | ${1}"
 fi
 
 exit 0
+}
+
+for BC in `findBc`
+do
+       if SunOStest ${BC} && SCOtest ${BC}
+       then
+               Printtest ${BC}
+       fi
+done
+
+echo "bc does not work.  Consider installing GNU bc." >&2
+echo "cat >/dev/null"
+exit 1