#!/bin/sh
#
# @(#)$Id: genie.in 5791 2010-04-03 22:19:16Z Freddie Akeroyd $
#
# genie.  Generated from genie.in by configure.
#
# Usage: genie [options] [gcl initialisation file] [tcl initialisation file] [smalltalk image]
#
prefix=/home/faa59/GENIE/installroot/usr/local
exec_prefix=${prefix}
GENIE_DIR=${prefix}/genie
GENIESYS_DIR=${GENIE_DIR}/sys
GENIESYSLIB_DIR=${prefix}/lib
GENIE_BINDIR=${exec_prefix}/bin	# where genie executables are to be found
# set up PATH
PATH=${GENIE_DIR}:${GENIE_BINDIR}:${PATH}:/usr/local/bin:/usr/bin/X11
export PATH

LD_BIND_NOW=1	# force symbols to resolved at load time
export LD_BIND_NOW

# !!!IMPORTANT!!!
#
# If you define GENIE_LOGGING to "yes", GENIE will log a simple message
# on startup to ISIS. This message takes the form
#
#     Connection from isds9.nd.rl.ac.uk (130.246.49.1) at Tue Jun  3 09:40:25 1997
#     From user faa (Freddie Akeroyd)
#     Event = Starting Interactive
#     Session-id = 865327349
#     Environment = #isds9.nd.rl.ac.uk#RISC#ULTRIX#4.4#0
#     Version = @(#)Open GENIE V1.1 BUILD-27
#     [Linked] Tue Jun  3 09:16:51 BST 1997 [library version] 1.1
#
# And is only used for statistics purposes or for communicating
# problems with a version.
#
# If you do not like this, change the "yes" to "no"
# 
GENIE_LOGGING="no"
#

CXX=g++
TMPDIR=${TMPDIR-/tmp}
GENIE_TCL_DIR=${prefix}/genie/TkTcl
GENIE_LIBRARY_DIR=${GENIE_DIR}/library
GENIE_INCLUDE_DIR=${GENIE_DIR}/library/include
GENIE_EXAMPLES_DIR=${GENIE_DIR}/examples
GENIE_DOC_DIR=${GENIE_DIR}/doc
DEBUG_INIT=${TMPDIR}/genie_debug_init.$$
DEBUG_OUT=${TMPDIR}/genie_debug_out.$$
# Who to send the output of a "genie -debug" run to
#DEBUG_MAIL="Freddie.Akeroyd@rl.ac.uk"
DEBUG_MAIL="genie-bugs@isise.rl.ac.uk"

GENIE_ARGS="-l"
# parse args until first non-option
while true; do
    case $1 in
	-debug)
	    echo "Open GENIE will now be run in debugger and traceback information from a crash"
	    echo "will be mailed to the maintainers (${DEBUG_MAIL}). "
	    echo "Please now repeat whatever it was you did that caused Genie to crash."
	    echo
	    if test "$CXX" = "cxx"; then
	        DEBUG="ladebug -c $DEBUG_INIT"
	    else
	        DEBUG="gdb -batch -x $DEBUG_INIT"
            fi
	    GENIE_DEBUG_SIGNALS=1 # disable genie signal handlers - the debugger will use its own
	    export GENIE_DEBUG_SIGNALS
	    shift
	    ;;

	-B)
	    shift	# for backward compatability
	    ;;

	-l)
	    GENIE_ARGS="$GENIE_ARGS -l"
	    shift	# command line
	    ;;

	-k)
	    GENIE_ARGS="$GENIE_ARGS -k"
	    shift	# Tk
	    ;;

	-*)
	    echo "genie: invalid option $i"
	    shift
	    ;;

	'')
	    break
	    ;;

	*)
	    break
	    ;;
    esac
done

PGPLOT_FONT=${GENIE_DIR}/grfont.dat
PGPLOT_RGB=${GENIE_DIR}/rgb.txt
PGPLOT_DIR=${GENIE_DIR}
VISUAL=/usr/bin/X11/xedit

# set up shared library search path
if test X$LD_LIBRARY_PATH = X; then
    LD_LIBRARY_PATH=.:${GENIE_DIR}:${GENIESYS_DIR}:${GENIESYSLIB_DIR}:${GENIE_LIBRARY_DIR}:/sw/lib:/usr/local/lib
else
    LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${GENIE_DIR}:${GENIESYS_DIR}:${GENIESYSLIB_DIR}:${GENIE_LIBRARY_DIR}:/sw/lib:/usr/local/lib
fi

# add any user libraries that may be defined.
if test X$GENIE_USER_LIBRARY_DIR != X; then
    LD_LIBRARY_PATH=${GENIE_USER_LIBRARY_DIR}:${LD_LIBRARY_PATH}
fi

BINDIR=${GENIE_BINDIR}
export GENIE_DIR GENIE_BINDIR PGPLOT_DIR PGPLOT_FONT PGPLOT_RGB VISUAL 
export LD_LIBRARY_PATH GENIE_TCL_DIR GENIE_INCLUDE_DIR
export GENIE_LOGGING GENIE_EXAMPLES_DIR GENIE_DOC_DIR BINDIR

if test X$GENIE_GCL_DIR = X; then
    export GENIE_GCL_DIR=$GENIE_DIR
fi

# for HP
if test X$SHLIB_PATH = X; then
    SHLIB_PATH=$LD_LIBRARY_PATH
else
    SHLIB_PATH=${LD_LIBRARY_PATH}:${SHLIB_PATH}
fi
export SHLIB_PATH

# for Darwin
if test X$DYLD_LIBRARY_PATH = X; then
    DYLD_LIBRARY_PATH=${LD_LIBRARY_PATH}
else
    DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:${LD_LIBRARY_PATH}
fi
export DYLD_LIBRARY_PATH

#TCL_LIBRARY=${GENIE_TCL_DIR}/tcl
#TK_LIBRARY=${GENIE_TCL_DIR}/tk
#TIX_LIBRARY=${GENIE_TCL_DIR}/tix
#ITCL_LIBRARY=${GENIE_TCL_DIR}/itcl
#ITK_LIBRARY=${GENIE_TCL_DIR}/itk
#export TCL_LIBRARY TK_LIBRARY TIX_LIBRARY ITCL_LIBRARY ITK_LIBRARY

# set resource limits
ulimit -c 0

if [ -z "$GENIE_GCL_INIT" ]; then
    if [ -r ${HOME}/genieinit.gcl ]; then
        GENIE_GCL_INIT=${HOME}/genieinit.gcl
    else
        GENIE_GCL_INIT=${GENIE_DIR}/default_genieinit.gcl
    fi
fi
if [ -z "$GENIE_TCL_INIT" ]; then
    if [ -r ${HOME}/genieinit.tcl ]; then
        GENIE_TCL_INIT=${HOME}/genieinit.tcl
    else
        GENIE_TCL_INIT=${GENIE_TCL_DIR}/interface.tcl
    fi
fi
if [ -z "$GENIE_SMALLTALK_IMAGE" ]; then
    GENIE_SMALLTALK_IMAGE=${GENIE_DIR}/genie.im
fi

# supersede these if values exist on the command line
if [ ! -z "$1" ]; then GENIE_GCL_INIT="$1"; fi
if [ ! -z "$2" ]; then GENIE_TCL_INIT="$2"; fi
if [ ! -z "$3" ]; then GENIE_SMALLTALK_IMAGE="$3"; fi

export GENIE_SMALLTALK_IMAGE GENIE_GCL_INIT GENIE_TCL_INIT

# if GENIE_DEFAULT environment variable set, change to this directory first
[ ! -z "$GENIE_DEFAULT" -a -d "$GENIE_DEFAULT" ] && cd $GENIE_DEFAULT

if test "$DEBUG" = ""; then
    ${GENIE_DIR}/gmain $GENIE_ARGS
else
    rm -f $DEBUG_INIT
    echo "run $GENIE_ARGS" >> $DEBUG_INIT
    echo "where" >> $DEBUG_INIT
    echo "quit" >> $DEBUG_INIT
    ${DEBUG} ${GENIE_DIR}/gmain 2>&1 | tee $DEBUG_OUT
    echo "Mailing traceback to $DEBUG_MAIL"
# No subject as "-s" may not be supported on all versions
    mail $DEBUG_MAIL < $DEBUG_OUT || \
	mailx $DEBUG_MAIL < $DEBUG_OUT || \
	echo "*** Mail command FAILED - please send the debug output to $DEBUG_MAIL ***"
fi

rm -f $DEBUG_INIT $DEBUG_OUT
