#!/bin/sh

# Copyright (c) 1994 by Waterloo Maple Software
# All rights reserved. Unauthorized duplication prohibited.
# Permission is granted to modify this file to be appropriate for use at the
# installation for which Maple was purchased.

# This script is used to start both the TTY and Motif versions of Maple V
# Release 3. The script parses all the command line options and determines
# whether they should be passed to the kernel (Maple options) or to the
# Iris (X Window options).

# Set the MAPLE environment variable. This variable is needed both by this
# script (to find various files), and by the Maple kernel and Iris. Change
# the following line appropriately for your site if you did not install
# Maple in the directory indicated.
MAPLE=/usr/local/maple
export MAPLE

# For Solaris 2.3 users, you may need to uncomment the following two lines
# XKEYSYMDB=/usr/openwin/lib/XKeysymDB
# export XKEYSYMDB

# For HP9000/7xx and HP9000/8xx users, you many need to uncomment the
# following two lines and set the path for XKeysymDB correctly.
# XKEYSYMDB=/usr/lib/X11/XKeysymDB
# export XKeysymDB

# Parse all command line parameters. Parameters are collected into kernel
# and Iris parameters. The special parameter -x is used to start the X
# Window (Motif) interface.
KPARAM=
IPARAM=
XMAPLE=
UMAPLE=
INSTALL=
while [ x$1 != x ]
do
    case $1 in
    -b|-e|-g|-w|-L)
	KPARAM="$KPARAM $1 $2"
	shift
	;;
    -u)
	KPARAM="$KPARAM $1 $2"
	UMAPLE=1
	shift
	;;
    -f|-q|-s|-t)
	KPARAM="$KPARAM $1"
	;;
    -I)
	INSTALL=1
	KPARAM="$KPARAM $1"
	;;
    -x)
	XMAPLE=1
	;;
    -p|-k)
	echo "$0: $1 can only be generated internally"
	exit 1
	;;
    *)
	IPARAM="$IPARAM $1"
	;;
    esac
    shift
done

# Check for illegal combinations namely:
# 	-User interface option (-u) and X interface option (-x)
# 	-Install option (-I) and X interface option (-x)
if [ "$XMAPLE" -a "$UMAPLE" ]
then	
    echo "$0: -x and -u cannot both be used"
    exit 1
fi
if [ "$INSTALL" -a "$XMAPLE" ]
then	
    echo "$0: cannot install while using X11 interface"
    exit 1
fi

# This variable tells Maple's Motif interface where to find its resource
# files. This should be set even if TTY Maple is being run, as the user
# might still open a Motif plot window.
XAPPLRESDIR=$MAPLE/X11_defaults
export XAPPLRESDIR

# On some machines, it may be necessary to uncomment the following two lines
# so that Maple can find its resources. The Silicon Graphics Iris is one
# such machine where this is known to be the case.
# XFILESEARCHPATH=$MAPLE/X11_defaults/Maple
# export XFILESEARCHPATH

# Set the PATH so that Maple can find its various auxiliary programs.
PATH=$MAPLE/bin:$PATH
export PATH

# Start the Motif version of Maple if -x was specified. Otherwise start
# the TTY version (which might in turn start the Motif interface). Iris
# parameters are not allowed if the TTY version is started.
if [ "$XMAPLE" ]
then
    irisVxm -k "mapleV $KPARAM" $IPARAM
else
    if [ "$IPARAM" ]
    then
	echo "$0: invalid parameters ($IPARAM)"
    else
	mapleV $KPARAM
    fi
fi
