# running) bc.
-# Test for SunOS 5.[78] bc bug (or missing bc)
-SunOStest() {
-if [ 0 != "`${1} <<\EOF
+IFS=:
+try_without_dir=true
+# First we try "bc", then "$dir/bc" for each item in $PATH.
+for dir in dummy:$PATH; do
+ if [ "$try_without_dir" = true ]; then
+ # first iteration
+ bc=bc
+ try_without_dir=false
+ else
+ # second and later iterations
+ bc="$dir/bc"
+ if [ ! -f "$bc" ]; then # '-x' is not available on Ultrix
+ bc=''
+ fi
+ fi
+
+ if [ ! "$bc" = '' ]; then
+ failure=none
+
+
+ # Test for SunOS 5.[78] bc bug
+ "$bc" >tmp.bctest <<\EOF
obase=16
ibase=16
a=AD88C418F31B3FC712D0425001D522B3AE9134FF3A98C13C1FCC1682211195406C1A6C66C6A\
8B3CD64126E1A82E190228020C05B91C8B141F1110086FC2A4C6ED631EBA129D04BB9A19FC53D\
3ED0E2017D60A68775B75481449
(a/b)*b + (a%b) - a
-EOF`" ]
-then
-# echo "bc does not work. Consider installing GNU bc." >&2
-# echo "cat >/dev/null"
- return 1
-fi
-}
+EOF
+ if [ 0 != "`cat tmp.bctest`" ]; then
+ failure=SunOStest
+ fi
+
-# Test for SCO bc bug.
-SCOtest() {
-if [ "0
-0" != "`${1} <<\EOF
+ if [ "$failure" = none ]; then
+ # Test for SCO bc bug.
+ "$bc" >tmp.bctest <<\EOF
obase=16
ibase=16
-FFDD63BA1A4648F0D804F8A1C66C53F0D2110590E8A3907EC73B4AEC6F15AC177F176F2274D2\
9E8DB6A8C3B1B9986D57ED5419C2E855F7D5469E35E76334BB42F4C43E3F3A31B9697C171DAC4\
D97935A7E1A14AD209D6CF811F55C6DB83AA9E6DFECFCD6669DED7171EE22A40C6181615CAF3F\
5296964
-EOF`" ]
-then
-# echo "bc does not work. Consider installing GNU bc." >&2
-# echo "cat >/dev/null"
- return 1
-fi
-}
+EOF
+ if [ "0
+0" != "`cat tmp.bctest`" ]; then
+ failure=SCOtest
+ fi
+ 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" = "`${1} 2>/dev/null <<\EOF
-print \"OK\"
-EOF`" ]
-then
- echo "${1}"
-else
- echo "sed 's/print.*//' | ${1}"
-fi
+ if [ "$failure" = none ]; then
+ # bc works; now check if it knows the 'print' command.
+ if [ "OK" = "`echo 'print \"OK\"' | $bc 2>/dev/null`" ]
+ then
+ echo "$bc"
+ else
+ echo "sed 's/print.*//' | $bc"
+ fi
+ exit 0
+ fi
-exit 0
-}
-
-for BC in `findBc`
-do
- if SunOStest ${BC} && SCOtest ${BC}
- then
- Printtest ${BC}
- fi
+ echo "$bc does not work properly ('$failure' failed). Looking for another bc ..." >&2
+ fi
done
-echo "bc does not work. Consider installing GNU bc." >&2
-echo "cat >/dev/null"
+echo "No working bc found. Consider installing GNU bc." >&2
+if [ "$1" = ignore ]; then
+ echo "cat >/dev/null"
+ exit 0
+fi
exit 1