#!/bin/sh
#
# usage: testml [options]
#
# where options are
#
#	-load <name>		- specify the prefix of the heap image to load
#
# all other options are passed to runtime system
#


this=$0
cmddir=`dirname $0`
cmddir=`cd "$cmddir"; pwd`
bindir=`cd "$cmddir/../bin"; pwd`

ARGS=""

HEAP_IMAGE=sml

# Process command-line arguments
#
while [ "$#" != "0" ] ; do
    arg=$1; shift
    case $arg in
    -load)
	if [ "$#" = "0" ]; then
	    echo "$this: missing argument for \"-load\" option"
	    exit 1
	fi
	HEAP_IMAGE="$1"; shift
	;;
    *)
	ARGS="$ARGS $arg"
	;;
    esac
done

#
# use the arch-n-opsys script to determine the ARCH/OS if possible
#
if [ -f $twoup/bin/.arch-n-opsys ]; then
    ARCH_N_OPSYS=`"$bindir/.arch-n-opsys"`
    if [ "$?" = "0" ]; then
	eval $ARCH_N_OPSYS
    fi
fi

heapdir=`dirname $HEAP_IMAGE`
[ -f "$heapdir/$HEAP_IMAGE.$HEAP_SUFFIX" ] || heapdir="$cmddir/$heapdir"
HEAP_IMAGE=`cd "$heapdir"; pwd`/$HEAP_IMAGE

LIB_DIR="${HEAP_IMAGE}.lib"
LPC="${LIB_DIR}/local_pathconfig"

rm -f "$LPC"
cp ../config/extrapathconfig "$LPC"

CM_PATHCONFIG="$LIB_DIR/pathconfig" CM_LOCAL_PATHCONFIG="$LPC" \
    "$bindir/sml" @SMLload="$HEAP_IMAGE" "$@"
