#!/bin/sh
#
# Determine JAVA_HOME
#

CLASSPATH="$CLASSPATH"
export CLASSPATH

if [ -z "$JAVA_HOME" ] ; then
    JAVA_HOME=`dirname $0`
    JAVA_HOME=`cd $JAVA_HOME/.. ; /bin/pwd`
fi

if [ ! -d "$JAVA_HOME" ] ; then
    echo "Invalid JAVA_HOME: $JAVA_HOME" 1>&2 
    exit 1
fi

if [ ! -r "$JAVA_HOME/lib/classes.zip" ] ; then
    if [ ! -d "$JAVA_HOME/classes" ] ; then
       echo "Invalid JAVA_HOME: $JAVA_HOME" 1>&2 
       exit 1
    fi
fi

#
# Parse arguments, treating -classpath specially and passing arguments prefixed
# with '-J' directly to the interpreter
#

java_args= app_args=
while [ $# -gt 0 ]; do
  case "$1" in
    -classpath)  shift; java_args="$java_args -classpath $1" ;;
    -J*)         java_args="$java_args `expr "$1" : '-J\(..*\)'`" ;;
    *)           app_args="$app_args $1" ;;
  esac
  shift
done


#
# Run javadoc
#

eval exec $JAVA_HOME/bin/java -ms8m $java_args sun.tools.javadoc.Main $app_args
