#!/bin/sh

Show=""
exejar_args=""
for arg in "$@" ; do
    case $arg in
        -echo)
            addarg=no
            set -x
            ;;
        -show)
            addarg=no
            Show=echo
            ;;
        -h|--h|-help|--help)
            addarg=yes
cat <<EOF
$0: Print the content of the clog file to stdout.

-h|-help    : Display this help message.
-echo       : Do set -x.
-show       : Print the actual command being execited by this script.

EOF
            exit 1  # exejar does not do anything with -h
            ;;
        *)
            addarg=yes
            ;;
    esac
    if [ $addarg = yes ] ; then
        exejar_args="$exejar_args $arg"
    fi
done

# Set JAVA environment
JVM=/etc/alternatives/java_sdk/bin/java
JVMOPTS=" "
# Assume user's environmental JVMFLAGS is better than what configure found.
JVMFLAGS=${JVMFLAGS:-${JVMOPTS}}

# Set PATH to the jar needed by the print program
GUI_LIBDIR=/usr/lib64/mpich2
GUI_HOME=${GUI_LIBDIR}/..
MAIN_LIB=${GUI_LIBDIR}/clogprint.jar

if [ -z "${GUI_LIBDIR}" -o "${GUI_LIBDIR}" = "/lib" ]; then
    echo "GUI_LIBDIR is NOT set!"
    exit 1
else
    echo "GUI_LIBDIR is set. GUI_LIBDIR = "${GUI_LIBDIR}
fi

case "$JVMFLAGS" in
    *-Xms*)
        ;;  # Do nothing
    *)
        JVMFLAGS="$JVMFLAGS -Xms32m"
        ;;
esac
case "$JVMFLAGS" in
    *-Xmx*)
        ;;  # Do nothing
    *)
        JVMFLAGS="$JVMFLAGS -Xmx96m"
        ;;
esac

$Show ${JVM} ${JVMFLAGS} -jar ${MAIN_LIB} ${exejar_args}
