#!/bin/sh
#
#
######################################################
#
#  SaVi by Robert Thurman (thurman@geom.umn.edu) and
#          Patrick Worfolk (worfolk@alum.mit.edu).
#
#  Copyright (c) 1997 by The Geometry Center.
#  This file is part of SaVi.  SaVi is free software;
#  you can redistribute it and/or modify it only under
#  the terms given in the file COPYRIGHT which you should
#  have received along with this file.  SaVi may be
#  obtained by emailing savi@geom.umn.edu.
#
######################################################
#  
# Script for starting the SaVi executable
#
#

#
# If SAVI environment variable is not defined
# then set it to be the path of this file
#
# If you move this script away from the SaVi installation then
# you should uncomment the following line
#SAVI=/usr/local/savi
# and replace /usr/local/savi with the location of the SaVi installation.
#
: ${SAVI:=`dirname $0`}
export SAVI

#
# Default executable name
#
SAVIBIN=bin/savi

#
# Check for known machine types
#
if [ -f /vmlinuz -o -f /boot/vmlinuz ]; then
  SAVIBIN=bin/savi.linux
elif [ -d /devices ]; then
  SAVIBIN=bin/savi.sun
elif [ -d /usr/bsd -a -d /usr/sbin ]; then
  SAVIBIN=bin/savi.irix5
fi

if [ ! -f "${SAVI}/${SAVIBIN}" ]; then
  SAVIBIN=bin/savi
fi

#
# Find what directory this script was invoked from
#
OLDCWD=`pwd`; export OLDCWD


#
# Set locations of tcl and tk library code needed at runtime
#
TCL_LIBRARY=./tcl/lib/tcl7.4
TK_LIBRARY=./tcl/lib/tk4.0
export TCL_LIBRARY TK_LIBRARY

#
# Change directory
#
cd $SAVI

#
# Check to see if this will work!
#
if [ ! -d $TCL_LIBRARY ]; then
  echo "SaVi: $0 is not in the directory where SaVi was installed.
You must set the environment variable SAVI to the installation location." >&2
  exit
fi

#
# See if we need to add a -geomview flag
#
if [ -t 1 ]; then
  exec > /dev/null
else
  case "$*" in
    *-geomview*) ;;
    *) set -- -geomview $*;;
  esac

  # send SAVI env variable to geomview
  echo "(setenv SAVI $SAVI)"
fi

#
# Run binary
#
${SAVIBIN} $*
