#!/bin/sh
#
# runtest -- basically all this script does is find the proper expect shell and then
#            run DejaGnu. <rob@cygnus.com>
#

#
# Get the execution path to this script and the current directory.
#
execpath=`expr ${0-.}'/' : '\(/\)[^/]*//*$' \| ${0-.}'/' : '\(.*[^/]\)//*[^/][^/]*//*$' \| .`
rootme=`pwd`
#
# set some default values
#
args=$@
srcdir=.

#
# Find the right expect binary to use. If a variable EXPECT exists,
# it takes precedence over all other tests. Otherwise look for a freshly
# built one, and then use one in the path.
#
if [ ! "$EXPECT" ]; then
  if [ -f ${rootme}/../../expect/expect ] ; then
    expectbin=${rootme}/../../expect/expect ;
  else \
    if [ -f ${rootme}/../expect/expect ] ; then
      expectbin=${rootme}/../expect/expect ;
    else \
      expectbin=expect ; \
    fi; \
  fi
else
  expectbin=$EXPECT
fi

# just to be safe...
if [ ! "$expectbin" ]; then
  echo "ERROR: No expect shell found"
  exit 1
fi

#
# Extract the srcdir and target from the option list.
#
#while [ "$1" ] ; do
#  case $1 in
#    -sr*|--sr*|+sr*|++s*) shift ; srcdir=$1 ;;
#    -t*|--t*|+t*|++t*) shift ; target=$1 ;;
#  esac
#  shift
#done

if [ ! -f $execpath/runtest.exp ] ; then
  execpath=$execpath/../lib/dejagnu
  if [ ! -f $execpath/runtest.exp ] ; then
    echo "Runtest.exp does not exist"
    exit 1
  fi
fi

exec $expectbin -- $execpath/runtest.exp $args
