#!/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 from:
#  http://savi.sourceforge.net/
#  http://www.geom.uiuc.edu/locate/SaVi 
#
######################################################
#
# Script that is always used to launch the binary SaVi executable
#
# $Id: savi,v 1.9 2004/01/06 03:57:56 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
# your SaVi installation.
#
: ${SAVI:=`dirname $0`}
export SAVI

#
# Default executable name
#
SAVIBIN=bin/savi-bin

#
# Set locations of tcl and tk library code needed at runtime
# Cygwin is a special case, and we set for that further down
#
TCL_LIBRARY=/usr/local/lib/tcl8.4
TK_LIBRARY=/usr/local/lib/tk8.4

#
# 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"
elif [ -d /cygdrive ]; then
  SAVIBIN="$SAVIBIN.cygwin"
  TCL_LIBRARY=/usr/share/tcl8.0
  TK_LIBRARY=/usr/share/tk8.0
fi

#
# Default to filename without extension
#
if [ ! -f "${SAVI}/${SAVIBIN}" ]; then
  SAVIBIN=bin/savi-bin
fi

#
# Verify that tcl and tk directories exist
#
if [ ! -d "$TCL_LIBRARY" ]; then
  echo "SaVi: specified TCL_LIBRARY $TCL_LIBRARY was not found." >&2
fi

if [ ! -d "$TK_LIBRARY" ]; then
  echo "SaVi: specified TK_LIBRARY $TK_LIBRARY was not found." >&2
fi

export TCL_LIBRARY
export TK_LIBRARY

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

#
# Change directory
#
cd $SAVI

#
# 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} $*
