#!/bin/sh
#  pe-scam.sh
#  Copyright (C) 1992, 1993  J Dana Eckart
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 1, or (at your option)
#  any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with CELLULAR-3.0; see the file COPYING.  If not, write to the 
#  Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

LIB=/opt/games/lib/cellular
BIN=/opt/games/bin

USAGE="usage: ... | `basename $0` [-r timefile] [-c codefile] \
        	[-o | [-title string] (-iris | -x11 [-display connection])\
        	      [-p n] [-s n] [-map mapfile]) [-f n]\
                      [-dim [n|n..n]{,n|,n..n}]"

trap "exit" 0

CODEFILE="a.pe-scam"

while (test $# -gt 0)
do
	case $1 in
		'-o') 	if test -n "$X11" -o \
				-n "$IRIS" -o \
				-n "$X_DISPLAY" -o \
				-n "$MAPFILE" -o \
				-n "$PAUSE" -o \
				-n "$SIZE" -o \
				-n "$FIELD"
			then
				echo $USAGE
				exit 1
			else
				OUTPUT=yes
			fi
			;;
		'-c') 	CODEFILE=$2
			shift
			;;
		'-r') 	TIMEFILE="-r $2"
			shift
			;;
		'-title') if test -n "$OUTPUT"
			then
				echo $USAGE
				exit 1
			else
				TITLE="-title $2"
			fi
			shift
			;;
		'-x11')	if test -n "$OUTPUT"
			then
				echo $USAGE
				exit 1
			else
				X11=$1
			fi
			;;
		'-iris') if test -n "$OUTPUT"
			then
				echo $USAGE
				exit 1
			else
				IRIS=$1
			fi
			;;
		'-display') 
			if test -n "$OUTPUT"
			then
				echo $USAGE
				exit 1
			else
				X_DISPLAY="-display $2"
			fi
			shift
			;;
		'-map') if test -n "$OUTPUT"
			then
				echo $USAGE
				exit 1
			else
				MAPFILE="-map $2"
			fi
			shift
			;;
		'-p')   if test -n "$OUTPUT"
			then
				echo $USAGE
				exit 1
			else
				PAUSE="-p $2"
			fi
			shift
			;;
		'-s')   if test -n "$OUTPUT"
			then
				echo $USAGE
				exit 1
			else
				SIZE="-s $2"
			fi
			shift
			;;
		'-f')   if test -n "$OUTPUT"
			then
				echo $USAGE
				exit 1
			else
				FIELD="-f $2"
			fi
			shift
			;;
		'-dim') if test -n "$OUTPUT"
			then
				echo $USAGE
				exit 1
			else
				DIM="-dim $2"
			fi
			shift
			;;
		*) 	echo "Unknown flag, '$1'."
			echo $USAGE
			exit 1
			;;
	esac
	shift
done

#
# Make sure there is a valid codefile
#
if test ! -x $CODEFILE
then
	echo $USAGE
	exit 1
fi

#
# Make sure that CODEFILE is looked for in the proper place.
#
case $CODEFILE in
	'/'*) 	
		;;
	*) 	CODEFILE="./$CODEFILE"
		;;
esac


#
# Perform the pe-scam simulation.
#
if test "$OUTPUT" = "yes"
then
	$CODEFILE $TIMEFILE -o
else
	$CODEFILE $TIMEFILE \
		$TITLE $X11 $IRIS $MAPFILE $SIZE $PAUSE \
		$FIELD $X_DISPLAY $DIM
fi
