#!/bin/sh

vnc=1
if test $vnc -gt 0; then
w=`vncserver 2>&1 | sed -n '/New /s/.*://p'`
export DISPLAY=:$w
fi

run() {
expect << EOF
log_user 0
set timeout 500000
set j "$*"
set empty "\\n"
set warning ""
set error ""
spawn paw
expect {
-re "Workstation type.*\$" { send "\\r"; exp_continue }
-re "Type .* to continue .*\$" { send "\\r"; exp_continue }
-re "PAW > \$" { send "\$j\\r"; set j "q\\r"; exp_continue }
timeout { set error "  Error: Connection timed out.\\n" }
eof
}
EOF
}

run 'exec a '$1
run 'exec a#c'

rm last.kumac*
if test $vnc -gt 0; then
vncserver -kill :$w
fi
