#! /bin/sh
if [ "`uname`" = "Linux" ]; then enable -n echo; fi
#*******************************************************************************
# E.S.O. - VLT project
#
# "@(#) $Id: jnps.sh,v 1.105 2010/05/30 20:13:00 vltsccm Exp $"
#
# who       when        what
# --------  ----------  --------------------------------------------------------
# nkornwei  2006/12/06  "port" to SunOS - fix test error message.
# pbaksai   2005/10/12  PPRS-17365: Removed support for pafchk
# pbaksai   2004/09/26  Override locale with english 
# pbaksai   2004/07/09  Removed search for jre
# dsalazar  2004/07/05  Rewrote the entire script
#                       Removed the included runtime environment things. 
#                       The java code now requires the JRE to be installed 
#                       individually
# pbaksai   2004/05/16  Added support for APR2004
# sskole    18/12/02    Added support for APR2003
# smarteau  26/06/02    Added "-expert" option
# marteau   26/06/00    created
#
#*******************************************************************************
#   NAME
#     jnps.sh - script to start the Java client for NAOS Preparation Software
#
#   SYNOPSIS
#     jnps.sh [-v] [-help] [-debug]
# 
#   DESCRIPTION
#     jnps.sh is a command line tool to start the Java client for NAOS
#     Preparation Software.
#
#   OPTIONS
#     -v      Load Java classes in verbose mode 
#     -help   Display this help text 
#     -debug  Display debugging information 
#     -expert Turns on advanced options for the PS
#
#   All other command line options will be ignored.
#
#   ENVIRONMENT
#     If defined, the JAVA_HOME variable may be used to determine the path to
#     the Java Runtime Environment.
#
#   RETURN VALUES
#
#   EXAMPLES
#
#   SEE ALSO
#
#   BUGS     
#
#-------------------------------------------------------------------------------
#

# signal trap (if any)



# Standard settings
#----------------------------------------
thisprog=`basename $0`
progdir=`dirname $0`
cd $progdir/..
BASE=`pwd`

# Usage strings
#----------------------------------------
usage0="usage: $thisprog <options>\nwhere <options> are:"

options0="\n\t-v
\n\t-help
\n\t-debug
\n\t-expert"

options1="\n\t-v\tLoad Java classes in verbose mode
\n\t-help\tDisplay this help text
\n\t-debug\tDisplay debugging information
\n\t-expert\tTurns on advanced options
\nAll other command line options will be ignored.
"

usage="$usage0$options0"
helptext="$usage0$options1"

# Set default options and process 
# command line switches
#----------------------------------------

optJRE=""
optDebug=N          # by default no debugging options
optExpert=""

options=$*          # save user options

while true; do      # Loop over input options
    case $1
        in
        -debug)  optDebug=Y ;;
        -expert) optExpert="-e";;	
        -v)      optJRE="-v $optJRE" ;;
        -help)   echo $helptext ; exit ;;
        -*)      echo $usage ; exit ;; # trap all other options
        *)  break ;;
    esac
    shift
done

# Give up if DISPLAY variable is not set
#----------------------------------------

if [ -z "$DISPLAY" ];  then
    echo "DISPLAY environment variable not set - exiting"
    exit 1
fi

# Set system-dependant options
#----------------------------------------

OS=`uname`
optJIT=""

case $OS in 
  
    SunOS) optJIT="-Djava.compiler=NONE" ;;
    Linux) optJIT="-nojit" ;;
    HP-UX) optJIT="-nojit" ;;

esac

if [ $optDebug = "N" ] ; then
    OUT_CHANNEL=">/dev/null 2>&1"
else
    OUT_CHANNEL=""
    optJRE="$optJRE -Ddebug.mode=true $optJIT"
fi


# Find a java runtime environment
# If not found, exit
#----------------------------------------


JRE=`which java`
if [ -z $JRE ] ; then
    echo "No Java Runtime Environment 1.4 or above found: exiting"
    exit 1
fi


JAVA_HOME=`dirname $JRE`/..
export JAVA_HOME


# Find the jnps.jar file
#----------------------------------------
if [ -f $INTROOT/lib/jnps.jar ] ; then
    jarFile=$INTROOT/lib/jnps.jar
elif [ -f $BASE/lib/jnps.jar ] ; then
    jarFile=$BASE/lib/jnps.jar
else
    echo "jnps.jar file not found: exiting"
    exit 1
fi



# Setup CLASSPATH for different
# runtime environments
#----------------------------------------
CLASSPATH=$JAVA_HOME/lib/classes.zip
CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/rt.jar
CLASSPATH=$CLASSPATH:$BASE/lib/swingall.jar
CLASSPATH=$CLASSPATH:$jarFile

export CLASSPATH

# Set shared library pathnames for
# all supported flavors of Unix
#----------------------------------------
SHLIB_PATH=$BASE/lib:$SHLIB_PATH
LD_LIBRARY_PATH=$BASE/lib:$LD_LIBRARY_PATH
export SHLIB_PATH
export LD_LIBRARY_PATH

# Override some localization settings to force using english
LANG=en_US
LC_ALL=en_US
export LANG
export LC_ALL

# Print out some useful information...
#----------------------------------------
if [ $optDebug = "Y" ] ; then
    echo "Starting NAOS PS with:"
    echo "options:      $options"
    echo "BASE:         $BASE"
    echo "JRE:          $JRE"
    echo "jarFile:      $jarFile"
    echo "JAVA_HOME:    $JAVA_HOME"
    echo "CLASSPATH:    $CLASSPATH"
    echo "optJRE:       $optJRE"
    echo "optExpert:    $optExpert"
    if [ -z "$RTAPENV" ] ; then
        r="<undefined>"
    else
        r=$RTAPENV
    fi
    echo "RTAPENV:      $r"
    echo "locale:       $LANG"
fi


eval $JRE -cp $jarFile jnps.JnpsMAIN $optJRE $optExpert $OUT_CHANNEL


#
# ___oOo___
