#!/bin/sh

PATH="/home/comp210/bin:.:$PATH"
export PATH

MRED="/home/scheme/bin/mred"
PENTE="/net/course-a/comp210/public_html/01fall/Assignments/Connect5/Bin/pente-gui.ss"


SIZE=""
TIME=""
QUIET="verbose"
PLAYONE=""
PLAYTWO=""
TYPEONE="scheme"
TYPETWO="scheme"
USERFILE_PREFIX="/home/"
USERFILE_SUFFIX="/comp210/connect5/connect5.ss"

while [ -n "$1" ]; do
  case "$1" in

    -n | --size )
       SIZE="$2"
       shift ; shift ;;

    -t | --time )
       TIME="$2"
       shift ; shift ;;

    -q | --quiet )
       QUIET="quiet"
       shift ;;

    -p1 | --player1 )
       PLAYONE="$2"
       shift ; shift ;;

    -p2 | --player2 )
       PLAYTWO="$2"
       shift ; shift ;;

    -f1 | --format1 )
       TYPEONE="$2"
       shift ; shift ;;

    -f2 | --format2 )
       TYPETWO="$2"
       shift ; shift ;;

    * )
       case "$1" in
         -h | -help | --help ) ;;
         * ) echo "Unknown option: $1" ;;
       esac
       echo "The command line options are:"
       echo " -n <num> : sets size of board"
       echo " -t <num> : sets the time per move in seconds"
       echo " -p1 <file> : sets player 1"
       echo " -p2 <file> : sets player 2"
       echo " -q : suppress all output except final result"
       echo "A file ending in .ss implicitly sets type to scheme"
       echo "unless overridden by -f flag.  Any options not set"
       echo "on the command line are prompted for."
       exit ;;

  esac
done

while [ -z "$SIZE" ]; do 
  echo "Enter the size of the board: "
  read SIZE FOO
done

while [ -z "$TIME" ]; do
  echo "Enter the time limit per move in seconds: "
  read TIME FOO
done

while [ -z "$PLAYONE" ]; do
  echo "Enter an owlnet username, or an absolute pathname, for Player 1: "
  read PLAYONE FOO
done
if [ ! -r "$PLAYONE" ] ; then PLAYONE=$USERFILE_PREFIX$PLAYONE$USERFILE_SUFFIX ; fi

while [ -z "$PLAYTWO" ]; do
  echo "Enter an owlnet username, or an absolute pathname, for Player 2: "
  read PLAYTWO FOO
done
if [ ! -r "$PLAYTWO" ] ; then PLAYTWO=$USERFILE_PREFIX$PLAYTWO$USERFILE_SUFFIX ; fi


export SIZE
export TIME
export QUIET
export PLAYONE
export PLAYTWO
export TYPEONE
export TYPETWO

CURDIR=`pwd`
export CURDIR

echo "Starting Connect5 window (please wait) ..."

#exec $MRED -ub -- -f $PENTE
exec $MRED  -f $PENTE
