# Common shell routines for Java launcher scripts

## FindJVM
# Checks the JAVA_HOME environment variable.
# If the variable is not set, searches for a JRE installation
# among predefined paths and exports JAVA_HOME as appropriate.
FindJVM()
{
    test x"$JAVA_HOME" = x || return
    for d in '@LIBDIR@/j2se' '@LIBDIR@/jdk'; do
	if test -d "$d" && test -x "$d/jre/bin/java" -o -x "$d/bin/java"
	then
	    JAVA_HOME=$d
	    export JAVA_HOME
	    break
	fi
    done
}

## AddToClasspath
# Adds the list of specified names
# to the CLASSPATH environment variable.
# Names can be absolute or relative; if a relative name is specified, it is
# prefixed with the system Java library directory.
# Only the names that exist as files or directories will
# be added.
#
AddToClasspath()
{
    local javalibdir=@JAVADIR@

    for p in "$@"; do
	case "$p" in
	    /*) ;;
	    *)  p=$javalibdir/$p ;;
	esac
	if [ ! -e "$p" ]; then
	    continue
	fi
	if [ -n "$CLASSPATH" ]; then
	    CLASSPATH=$CLASSPATH:$p
	else
	    CLASSPATH=$p
	    export CLASSPATH
	fi
    done
}
