#!/bin/sh

## JGR start script

# loader version
JGR_LOADER_VER=1.61

R_SHARE_DIR="$R_HOME/share"
export R_SHARE_DIR
R_INCLUDE_DIR="$R_HOME/include"
export R_INCLUDE_DIR
R_DOC_DIR="$R_HOME/doc"
export R_DOC_DIR

JRI_LD_PATH="$R_HOME/library/rJava/jri:${R_HOME}/lib:${R_HOME}/bin:$R_HOME/lib:/usr/local/lib:$JAVA_HOME/jre/lib/i386/server:$JAVA_HOME/jre/lib/i386:@JAVA_LD@:$R_HOME/library/rJava/jri"
if test -z "${LD_LIBRARY_PATH}"; then
  LD_LIBRARY_PATH="${JRI_LD_PATH}"
else
  LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${JRI_LD_PATH}"
fi
JAVA="/usr/java/default/bin/java"

if test -r "${HOME}/.JGRprefsrc"; then
    libs=`sed -e s/'><'/'>\n<'/g < $HOME/.JGRprefsrc  | grep entry |  grep InitialRLibraryPath | sed -e s/.*InitialRLibraryPath.*value=\"// -e s/\".*$//g`
    home=`sed -e s/'><'/'>\n<'/g < $HOME/.JGRprefsrc  | grep entry |  grep InitialRHome | sed -e s/.*InitialRHome.*value=\"// -e s/\".*$//g`

    if test -n "$home"; then
        R_HOME="$home"
    fi
    if test -n "$libs"; then
	if test -z "${R_LIBS}"; then
	    R_LIBS="${libs}"
	else
            R_LIBS="${R_LIBS}:${libs}"
	fi
	export R_LIBS
    fi
fi

NO_SIG=1
export NO_SIG
export LD_LIBRARY_PATH
## make sure Java doesn't screw up formatting of doubles
LC_NUMERIC=C
export LC_NUMERIC

"${JAVA}" -Xmx512m -Djgr.load.pkgs=yes -Djgr.loader.ver="${JGR_LOADER_VER}" -Djava.library.path=".:${LD_LIBRARY_PATH}" -classpath "$R_HOME/library/rJava/java/boot" -Drjava.path="$R_HOME/library/rJava" -Drjava.class.path="$R_HOME/library/rJava/jri/JRI.jar:$R_HOME/library/iplots/java/iplots.jar:$R_HOME/library/JGR/java/JGR.jar:$R_HOME/library/CADStat/java/CADStat.jar" -Dmain.class=org.rosuda.JGR.JGR RJavaClassLoader $*
