#! /bin/sh

#--------------------------------------------------
# option
#

PLAYER=`which rcsslogplayer 2> /dev/null`
if test $? -eq 1; then
    echo "Error: rcsslogplayer can not be found in your PATH"
    echo ""
    exit 1
fi

LOG=$1
MON=self

if test $# -eq 1; then
    if test "$RCSSMONITOR"; then
        MON=`which "$RCSSMONITOR" 2> /dev/null`
        if test $? -eq 1; then
            echo "Error: cannot find the monitor specified by RCSSMONITOR: $RCSSMONITOR"
            echo ""
            MON=self
        fi
    else
        MON=`which rcssmonitor 2> /dev/null`
        if test $? -eq 1; then
            MON=`which rcssmonitor_classic 2> /dev/null`
            if test $? -eq 1; then
                echo "Error: No monitors can be found in your PATH and the"
                echo "       RCSSMONITOR environment variable is not set. Please"
                echo "       add rcssmonitor or rcssmonitor_classic to you PATH,"
                echo "       or set the RCSSMONITOR environment variable to the"
                echo "       executable you wish to use."
                echo ""
                MON=self
            fi
        fi
    fi
elif test $# -eq 2; then
    case "$1" in
        -standalone)
        MON=self
        ;;
        -frameview)
        MON=`which rcssmonitor 2> /dev/null`
        if test $? -eq 1; then
            echo "Error: rcssmonitor found in your PATH"
            echo ""
            MON=self
        fi
        ;;
        -classic)
        MON=`which rcssmonitor_classic 2> /dev/null`
        if test $? -eq 1; then
            echo "Error: rcssmonitor_classic found in your PATH"
            echo ""
            MON=self
        fi
        ;;
    esac
    LOG=$2
elif test $# -eq 0; then
    PROG=`basename $0`
    echo "Error: no log file"
    echo "Usage: $PROG [(-standalone)(-frameview)|(-classic)] <logfile>"
    echo ""
    exit 1
else
    PROG=`basename $0`
    echo "Error: too many options"
    echo "Usage: $ $PROG [(-standalone)(-frameview)|(-classic)] <logfile>"
    echo ""
    exit 1
fi


#--------------------------------------------------
# start logplayer with monitor
#

echo "Starting logplayer..."

$PLAYER --minimum-mode -m $MON $LOG
