#!/bin/sh
#
# Shell script that starts up the Java Pxgraph plotter
# Author:  Christopher Hylands
# Version: @(#)pxgraph	1.7 10/03/97
#
# Copyright (c) 1990-1996 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

# This script attempts to determine the location of the
# Java Pxgraph class file and JAVAHOME.
#
# To run this script, you need to set the TYCHO and JAVAHOME
# environment variables.  If you do not set these variables
# then the script will guess values.
#
# If the Pxgraph class is at /users/ptdesign/tycho/java/ptplot/Pxgraph.class
# then the TYCHO variable should be set to /users/ptdesign/tycho
#
# Your JAVAHOME variable should be set to the directory that
# contains your Java distribution.  For example, your .cshrc could contain:
# setenv JAVAHOME /opt/jdk1.1.4
#
# See the Pxgraph class documentation for further instructions.
#
# These are the defaults that we use in the script below.
# If you are installing this script, feel free to edit these

PTDEFAULT=/users/ptdesign
TYDEFAULT=/users/ptdesign/tycho
JAVADEFAULT=/opt/jdk1.1.4

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

# We attempt to set the PTOLEMY variable so we can use  
# it if TYCHO is not set.
if [ -z "$PTOLEMY" ]; then 
    if [ "$TYCHO" -a -f "$TYCHO/../bin/ptarch" ]; then
	PTOLEMY="$TYCHO/.."
    elif [ -d "$PTDEFAULT" ]; then
	PTOLEMY="$PTDEFAULT"
    fi
    export PTOLEMY
fi

if [ -z "$TYCHO" ]; then
    if [ "$PTOLEMY" -a -f "$PTOLEMY/tycho/bin/ptarch" ]; then
	TYCHO="$PTOLEMY/tycho"
    elif [ -d "$TYDEFAULT" ]; then
	TYCHO="$TYDEFAULT"
    fi
    export TYCHO
fi

windows=no
if [  "`uname`" =  "CYGWIN32/NT"  ]; then 
    windows=yes
fi	

if [ -z "$JAVAHOME" ]; then
    if [ -d "$JAVADEFAULT" ]; then
	JAVAHOME="$JAVADEFAULT"
	export JAVAHOME
    else
	if [ "$windows" = "yes" ]; then 
	    searchfile=javac.exe
	else    
	    searchfile=javac
	fi    
	for i in `echo $PATH | sed -e 's/:/ /g'`
	do
	    if [ -x "$i/$searchfile" -a ! -d "$i/$searchfile" ]; then
		JAVAHOME=`dirname $i`
		export JAVAHOME
		break
	    fi
	done	
    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
    if [ ! -r "$JAVAHOME/lib/classes.zip" ]; then
	echo "$0: \$JAVAHOME == $JAVAHOME, but $JAVAHOME/lib/classes.zip"
	echo " does not exist or is not readable."
	echo " Please set \$JAVAHOME to the directory that contains your"
	echo " Java distribution"
	exit 3
    fi

fi

if [ "$windows" = "yes" ]; then 
    $JAVAHOME/bin/java -classpath $TYCHO/java\;$JAVAHOME/lib/classes.zip ptplot.Pxgraph ${1+"$@"}
else
    $JAVAHOME/bin/java -classpath $TYCHO/java:$JAVAHOME/lib/classes.zip ptplot.Pxgraph ${1+"$@"}
fi


