#!/bin/sh
#ident "@(#) Appletviewer, Rev 1.3, 97/03/18"
#
#      Copyright (c) 1995-1997, Sun Microsystems, Inc.
#      All rights reserved.

##BEGIN TEMPLATE WRAPPER SHELL SCRIPT

# A variable to hold arguments after we strip OpenStep specific information
args=

# If you are debugging this script you might uncomment the following
# two lines.
#set -x
#echo input=$*

# Loop until argv ($#) is zero, each iteration will decrement (shift)
# argv/argc.
while [ $# != 0 ] ; do
  case $1 in
    # -NSOpen is an OpenStep standard command line flag which
    # lets the NSApplication know what file to open.
    -NSOpen)
        args="$args $2"
        shift             
        ;;
    # -NSOpenTemp is an OpenStep standard command line flag which
    # lets the NSApplication know what file to open and that it is
	# a temporary file and should be resaved somewhere else if edited.
    -NSOpenTemp)
        args="$args $2"
        shift
        ;;
    # -_NSMachLaunch is an undocumented additional flag to NSApplication.
    # We just ignore it here.
    -_NSMachLaunch)
        shift
        ;;
    *)
        args="$args $1"
        ;;
  esac
  shift
done

##END OF TEMPLATE WRAPPER SHELL SCRIPT

# This app handles .class and .html files.  To run a 
# java application, double click on the .class file
# that contains the 'main' method, or double click on
# a .html file with an applet tag in it.  Double
# clicking on anything else will fail.

if [ "$args" ]; then
  ext=`echo $args | awk -F. '{i = NF; print $i}'`
else
  ext=""
fi

case $ext in
	class)
		className=`basename $args | sed -e "s/\.class//"`
		applPath=`dirname $files`
		CLASSPATH=${CLASSPATH}:$applPath
		(cd $applPath; exec java $className)
	;;
	applet)
		CLASSPATH=${CLASSPATH}:$applPath
		(cd $applPath;exec appletviewer ./index.html)
	;;
	html)
		applPath=`dirname $files`
		CLASSPATH=${CLASSPATH}:$applPath
		(cd $applPath; exec appletviewer $args)
	;;
    *)
	;;
esac
  
