#!/bin/sh
#
# Shell script that starts up the Java Pxgraph plotter
# Author:  Christopher Hylands
# Version: $Id: ptplot.in,v 1.11 1999/08/20 01:19:50 cxh Exp $
#
# Copyright (c) 1998-1999 The Regents of the University of California.
# 	All Rights Reserved.
#
# Permission is hereby granted, without written agreement and without
# license or royalty fees, to use, copy, modify, and distribute this
# software and its documentation for any purpose, provided that the
# above copyright notice and the following two paragraphs appear in all
# copies of this software.
#
# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
# FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
# ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
# THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
# PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
# CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
# ENHANCEMENTS, OR MODIFICATIONS.
#
# 						PT_COPYRIGHT_VERSION_2
# 						COPYRIGHTENDKEY

# If this script is named 'ptplot', 'pxgraph', or 'histogram' don't edit it!
# instead, edit ptplot.in and run configure
# 
# configure substitutes in variables that are surrounded with @,
#

# Location of the Ptolemy II tree.  The plot directory should be found
# at $PTIIDEFAULT/ptolemy/plot
PTII_DEFAULT=@PTII_DEFAULT@
PTJAVA_DIR=@PTJAVA_DIR@

################
# You probably don't want to edit below here

if [ -z "$PTII" ]; then
    if [ -d "$PTII_DEFAULT" ]; then
	PTII="$PTII_DEFAULT"
	export PTII
    fi
    if [ ! -d "$PTII/ptolemy/plot" ]; then
	echo "$0: Could not find '$PTII/ptolemy/plot'.  Perhaps your PTII"
	echo " variable is not set properly?"
    fi	
fi

# We can start up either PxgraphApplication, EditablePlotMLApplication, or
# HistogramMLApplication here
if [ "`basename $0`" = "pxgraph" ]; then
    javastartupclass=ptolemy.plot.compat.PxgraphApplication

else 
    if [ "`basename $0`" = "histogram" ]; then
        javastartupclass=ptolemy.plot.plotml.HistogramMLApplication

    else
        # javastartupclass=ptolemy.plot.PlotApplication
        javastartupclass=ptolemy.plot.plotml.EditablePlotMLApplication
    fi
fi

windows=no

case "${OSTYPE-no}" in
    [Ll]inux)
    if [ "${JAVA_HOME-no}" != "no" ]; then
	JAVAHOME="$JAVA_HOME"
	export JAVAHOME
    fi;;
    cygwin32*)
	windows=yes;;
esac

if [ -z "$JAVAHOME" ]; then
    if [ -d "$PTJAVA_DIR" ]; then
	JAVAHOME="$PTJAVA_DIR"
	export JAVAHOME
    else
	if [ "$windows" = "yes" ]; then
	    searchfile=javac.exe
	else
	    searchfile=javac
	fi
	oldifs="$IFS"; IFS=":"
	for i in $PATH
	do
	    if [ -x "$i/$searchfile" -a ! -d "$i/$searchfile" ]; then
		JAVAHOME=`dirname $i`
		export JAVAHOME
		break
	    fi
	done
	IFS="$oldifs"
    fi
    if [ -z "$JAVAHOME" ]; then
	if [ -d "/usr/eesww/lang/jdk1.1latest" ]; then
		# Locally, Java can sometimes be found here.
		JAVAHOME=/usr/eesww/lang/jdk1.1latest
	fi
    fi
    if [ -z "$JAVAHOME" ]; then
	echo "$0: Could not find $searchfile in your \$PATH"
	echo " Please set \$JAVAHOME to the directory that contains your"
	echo " Java distribution"
	exit 3
    fi
fi

if [ "$windows" = "yes" ]; then
    # Windows via Cygwin32
    # chdir prints the current directory in DOS format.
    # The tr command deletes the \r at the end
    WINPTII=`(cd $PTII; cmd /c chdir) | tr -d '\r'`
    $JAVAHOME/bin/java -classpath $WINPTII\;$JAVAHOME\\lib\\classes.zip $javastartupclass ${1+"$@"}
elif [ "$PTARCH" = "alpha4" ]; then
    CLASSPATH=$PTIIo
    export CLASSPATH
    java $javastartupclass ${1+"$@"}
else
    if [ -f $PTII/ptolemy/plot/plotapplication.jar ]; then
	CLASSPATH="${PTII}/ptolemy/plot/plotapplication.jar:$(PTII)"
    else
	CLASSPATH=$PTII
    fi	
    export CLASSPATH
    $JAVAHOME/bin/java -verbose:class $javastartupclass ${1+"$@"}
fi
