#!/bin/sh
#	$Id: woad,v 1.1 2000-06-09 18:00:42 steve Exp $
# WOAD launcher. 


### Find out where this command came from:
#	Resort to a kludge to get around the fact that "type foo"
#	returns something like "foo is xxx", but "type -p foo" is
#	not supported on Solaris.

if [ "$1" = "--kludge" ] ; then
    echo $4
    exit
fi

XXX=`type $0`
XXX_BIN=`$0 --kludge $XXX` >/dev/null 2>&1
PIA_BIN_DIR=`dirname $XXX_BIN`
if [ ! -x "$XXX_BIN" ] ; then
    echo "Cannot locate binary directory for the PIA."
    echo "Please put the PIA's binary directory in your $PATH"
    exit 1
fi
PIA_DIR=${PIA_DIR-$PIA_BIN_DIR/..}
export PIA_DIR

### Handle -v specially: 
#	it has to be the first option in order for pia_wrapper to see it.

if [ "$1" = "-v" ] ; then
    V="-v"
    shift
fi

if [ "$1" = "-debug" ] ; then
    D="-debug"
    shift
fi

# We will count on Pia to handle multiple occurrances of -root and so on,
#	so that arguments provided by the user will override anything
#	this script puts earlier in the argument list.

## We really want to run from PIA_DIR/src/java or else set the classpath ... 
## pia_wrapper will set classpath if dir is not $PIA_DIR/src/java;
if [ -z "$CLASSPATH" ] ; then

    if [ `/bin/pwd` != `(cd $PIA_DIR/src/java; /bin/pwd)` ] ; then
      if [ "-v" = "$V" ]; then
	echo "CLASSPATH is not set and the current directory is not the "
	echo "    PIA's Java source directory ($PIA_DIR/src/java)."
	echo "    We will make a guess at CLASSPATH; if you experience problems"
	echo "    try running from $PIA_DIR/src/java or setting your "
	echo "    CLASSPATH environment variable to include the standard java classes."
     fi
   fi
fi

exec $PIA_BIN_DIR/pia_wrapper $D org.risource.pia.Pia $V \
     -site $PIA_DIR/Apps/Woad/woad.xcf -root $HOME/.woad  $*
