#!/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
#
# $Id: savi,v 1.2 2002/04/14 19:13:57 lloydwood Exp $

#
# 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-bin


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

#
# Default to filename without extension
#
if [ ! -f "${SAVI}/${SAVIBIN}" ]; then
  SAVIBIN=$SAVIBIN
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=/usr/lib/tcl8.3
TK_LIBRARY=/usr/lib/tk8.3
export TCL_LIBRARY
export TK_LIBRARY

#
# Change directory
#
cd $SAVI

if [ ! -d "$TCL_LIBRARY" ]; then
  echo "SaVi: Your TCL_LIBRARY $TCL_LIBRARY not found." >&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} $*
