#!/bin/sh
#
# browser-call script for the PROGRES-System.
#
# Initial version for the FFGraph library.  03/12/96 by ajw.
#

#
# This file sets appropriate environment variables, creates an independant
# TMPGRAS directory, and starts the browser.
#
# Calling Scheme: FFHostScript <PoolName> <GraphName>
# (parameter for set-up file possible (compare EdgeHostStyle file).) 
#

# Determine which operating system version the host has
osver=`uname -a`
case $osver in
SunOS*5.*)    # Solaris 2.x
        PLATFORM=sol2
        OSACCESSDIR=SOL2;;
SunOS*4.1.*)  # SunOS 4.1.x
        PLATFORM=sunos4
        OSACCESSDIR=SUNOS4;;
Linux*2.*.*)  # Linux 2.0.x
        PLATFORM=linuxlibc6
        OSACCESSDIR=LINUXLIBC6;;
*)      echo 'unknown os version' ;;  
esac
export PLATFORM OSACCESSDIR
 
#
# Create an independant TMPGRAS directory, so we don't get conflicts
# with the one used by the PROGRES-System
#
TMPGRAS="`date +/usr/tmp/HGraph$USER%H%M%S`"
export TMPGRAS
mkdir $TMPGRAS
chmod go+rwx $TMPGRAS

#
# Setting of the GRAS environment variables:
#
GRASALLOC=500
export GRASALLOC

#
# Bug fix for icon load path
EDGE_ICON_PATH=${EDGE_ICON_PATH:-$GRASBROWSERLOADPATH/etc}
export EDGE_ICON_PATH

# Path to Tk/Tcl/Tix installation 
# (Tcl 7.6, Tk 4.2, and Tix 4.1 files 
# are shipped together with Progres).
TCL_LIBRARY=$PROGRESROOT/lib/${OSACCESSDIR}/tcl8.0
TK_LIBRARY=$PROGRESROOT/lib/${OSACCESSDIR}/tk8.0
TIX_LIBRARY=$PROGRESROOT/lib/${OSACCESSDIR}/tix4.1
export TCL_LIBRARY 
export TK_LIBRARY
export TIX_LIBRARY

# path for all tcl scripts
TCL_PATH=$PROGRESROOT/browser
export TCL_PATH

# path for generared code. must be NULL for the browser
GENDIR=${DATAROOT}/gras/SessionSettings
export GENDIR

if [ -d $GENDIR ]
then
  # If there is already a SessionSettings directory then decide whether
  # it should be kept or not:

  case $PROGRESSESSIONSETTINGS in
  keep)
    echo "Keeping old Session Settings...";;
  *)
    echo "Deleting old Session Settings..."
    rm -rf $GENDIR;;
  esac
fi

#
# extend ld_librarypath
#
LD_LIBRARY_PATH="$GRASBROWSERLIBPATH/lib/${OSACCESSDIR}:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH

#
# Call the browser with PoolName and GraphName
# 
# ACHTUNG: Hier den Aufruf von ProgHostView gegen GBrowser ausgetauscht
# Der alte Aufruf findet sich in EdgeRHostScript.old 
#
echo
echo "Invoking browser ... " $GRASBROWSERLOADPATH/bin/${OSACCESSDIR}/FFBrowser $PROJECT ${1} ${2}
#echo "  - $PROJECT"
#echo "  - $1"
#echo "  - $2"

$GRASBROWSERLOADPATH/bin/${OSACCESSDIR}/FFBrowser $PROJECT ${1} ${2}


# After closing the browser  persistent layout information is removed
# for unnamed interpreter sessions.
# i.e. the information of node positions (NoName.PGCM_disp.label) 
# and the information set in global settings 
# (${DATAROOT}/gras/${PROJECT}/NoName.PGCM_ecu.g)

#if [ -f ${DATAROOT}/gras/${PROJECT}/NoName.PGCM_disp.label ]
#  then 
#    rm -rf ${DATAROOT}/gras/${PROJECT}/NoName.PGCM_disp.label
#fi

#if [ -f ${DATAROOT}/gras/${PROJECT}/NoName.PGCM_ecu.g ]
#  then 
#    rm -rf ${DATAROOT}/gras/${PROJECT}/NoName.PGCM_ecu.g 
#fi

#
# Kill the browse-graph from the pool.
#
# !! W A R N I N G !!
# If you start more than one browser simultanously on the same graph, 
# later terminating browsers will crash (due to missing graph).
#
#
# Kill the specially created TMPGRAS directory, since we do not change
# the graph, we have no further use for it.
#
rm -rf $TMPGRAS

