#! /bin/csh -f

# set echo 

# The time+increment for any seek or match commands.
set minutes   = 15
set increment = 3

# Should we start ICS mode in automatic mode or manual mode?
set manual = 0

# Should the games played be mailed to someone (anyone)?
set mail = 0

foreach arg ($argv)
    if ($arg == "man" || $arg == "manual") then
	set manual = 1
    endif
    if ($arg == "mail") then
	set mail = 1
    endif
end

while (1)
    # Ensure that there are no other versions of the engine running 
    set engs = `ps auxww | grep djinn | grep -v "grep" | awk '{print $2}' | sort -n`
    if ($#engs > 0) then
        kill -9 $engs
    endif
    # Invoke the expect script that handles the interface to ICS.
    if ($manual) then
	if ($mail) then
	    ./jinx-expect mail
	else 
	    ./jinx-expect 
	endif
    else
	if ($mail) then
	    ./jinx-expect mail $minutes $increment
	else
	    ./jinx-expect $minutes $increment
	endif
    endif
    sleep 5
end
