#! /bin/sh

#
# Copyright (c) 1995 by Sun Microsystems, Inc.
#

dir=BASEDIR/RICHPse
if [ ! -d $dir ]; then
  while :
  do
    echo Where is RICHPse if not $dir \? \\c
    read dir
    if [ -n "$dir" ]; then
      if [ -d $dir ]; then
        if [ ! -f $dir/include/sysdepend.se ]; then
          echo $dir does not appear to be the correct pathname
        else
          break
        fi
      else
        echo $dir does not exist
      fi
    fi
  done
fi

max() {
  if [ $1 -gt $2 ]; then
    n=$1
  else
    n=$2
  fi
  echo `expr $n + 1`
}

PTI=/etc/path_to_inst
ARCH=`uname -p`
case $ARCH in
sparc)
  md1=`egrep 'sd@|ip@' $PTI | awk '{ print $NF }' | sort -n | tail -1`
  md2=`egrep 'sd@|ip@' $PTI | awk '{ print $NF }' | wc -l`
  mi1=`egrep 'le@|ie@|qe@|nf@|bf@|tr@' $PTI |
     awk '{ print $NF }' | sort -n | tail -1`
  mi2=`egrep 'le@|ie@|qe@|nf@|bf@|tr@' $PTI | awk '{ print $NF }' | wc -l`
  ;;
i386)
  md1=`egrep 'dk@' $PTI | awk '{ print $NF }' | sort -n | tail -1`
  md2=`egrep 'dk@' $PTI | awk '{ print $NF }' | wc -l`
  mi1=`egrep 'smc@' $PTI |
     awk '{ print $NF }' | sort -n | tail -1`
  mi2=`egrep 'smc@' $PTI | awk '{ print $NF }' | wc -l`
  ;;
*)
  echo unknown architecture: $ARCH
  exit 1
  ;;
esac

max_disk=`max $md1 $md2`
max_if=`max $mi1 $mi2`

cd "$dir"/include
trap "/bin/rm -f t$$ ; exit 1" 0 2 3 15
sed '/MAX_DISK/,$d' sysdepend.se > t$$
(
cat t$$
/bin/printf "#define %-19.19s %s\n" MAX_DISK $max_disk
/bin/printf "#define %-19.19s %s\n" MAX_IF $max_if
echo '\n#endif'
) > sysdepend.se
exit 0
