/tget { 3 2 roll exch 3 mod get exch 3 mod get } def
/tgetchk
{ /ya exch def /xa exch def /ttta exch def /ret 0 def
xa 0 lt {/ret 45 def} if
xa 2 gt {/ret 45 def} if
ya 0 lt {/ret 45 def} if
ya 2 gt {/ret 45 def} if
ret 0 eq {/ret ttta xa ya tget def } if
ret
} def
/tset { 3 2 roll exch 3 mod get exch 3 mod 88 put } def
/dxy [1 0 1 1 0 1 -1 1] def
/tst [1 2 -1 -2 1 -1] def
{
/ttt [
(%stdin) (r) file 999 string readline pop
(%stdin) (r) file 999 string readline pop
(%stdin) (r) file 999 string readline pop
] def
0 1 2 {
/y exch def
0 1 2 {
/x exch def
/flag false def
ttt x y tget 45 eq { % "-"
0 2 6 {
/dir exch def
0 2 4 {
/t exch def
/flag true def
0 1 1 {
/d exch def
/xx x dxy dir get tst t d add get mul add def
/yy y dxy dir 1 add get tst t d add get mul add def
ttt xx yy tgetchk 88 ne {/flag false def} if
} for
flag {ttt x y tset exit} if
} for
flag {exit} if
} for
} if
flag {exit} if
} for
flag {exit} if
} for
0 1 2 { ttt exch get = } for
(%stdin) (r) file 999 string readline not { exit } if
(\n) print
} loop
Note that non-ascii characters in the above source code will be escaped (such as \x9f).