#!/bin/csh -f

# xplor (wrapper) v. 22 Aug 1996, Dave Schweisguth <dcs@proton.chem.yale.edu>
# Moore lab version

### Setup

# Set priority

nice +19

# Initialize variables

set whatami	    = `basename $0`
set arch	    = `uname -m`
set version	    = ''
set versiond	    = 3.820
set lib		    = /usr/local/lib/xplor
unset seed
set seedfile	    = xplor.seed	#.$$

# Process switches

while ("$1" =~ -* || "$1" =~ +*)        # Can't use [-+]. Grrr.
    switch ("$1")
    case +s:
	unset seed
	breaksw
    case -s:
	set seed
	breaksw
    case -u:
	set exit=0
	goto usage
	breaksw
    case -v:
        if ("$2" == "") then
            echo "${whatami}: $1 requires a version number for an argument."
            exit 1
        else
            set version = "$2"
            shift
            breaksw
        endif
    default:
	echo "${whatami}: $1 is not an option."
	set exit=1
	goto usage
	breaksw
    endsw
    shift
end

# Set version to default if not already set

if ("$version" == '') set version = $versiond
if (! -d $lib/$version) then
    echo "${whatami}: Xplor version $version is not available."
    exit 1
endif

### Source ulogin.com

set ulogin = $lib/$version/sgi/ulogin.com
if (-r $ulogin) then
    source $ulogin
else
    echo "${whatami}: Can't source $ulogin\!"
    exit 1
endif

### Decide on architecture

switch ("$arch")
case '':
    echo "${whatami}: Can't determine machine architecture\!"
    exit 1
case IP6:
    set executable = xplor.exe.R3000
    breaksw
case IP20:
    set executable = xplor.exe.R4000
    breaksw
case IP28:
    set executable = xplor.exe.R4000
    breaksw
default:
    echo "${whatami}: Don't know which executable to use for $arch architecture."
    exit 1
    breaksw
endsw

### Run Xplor

if ($?seed) then
    perl -e 'srand(time ^ $$); print rand(127773);' > $seedfile
	# Tell me why I chose 127773 and win a prize
#    setenv SEEDFILE $seedfile
    $OBJ/$executable $*
    rm -f $seedfile
else
    exec $OBJ/$executable $*
endif

exit

### Subroutines

# Usage

usage:
    cat <<EOE
Usage: $whatami [-s] [-v version] [-u]
-s	    Generate temporary seed file, to be accessed from within Xplor
		with "set seed=@xplor.seed end"
+s	    Don't generate temporary seed file (default)
-v version  Use that version of Xplor (default: $versiond)
-u	    This message
EOE
    exit $exit
