@echo off

for %%i in (.) do set problem=%%~ni

set author=%1

if "%1" == "" (
  echo No parameters
  goto End
)

set exec = echo No execution command

echo Compiling solution
if EXIST %problem%_%author%.dpr (
dcc32 -cc %problem%_%author%.dpr || goto CompSourceError
set exec=run -i %problem%.in -o %problem%.out -m 256M %problem%_%author%.exe
)
if EXIST %problem%_%author%.cpp (
g++ %problem%_%author%.cpp -o %problem%_%author%.exe || goto CompSourceError
set exec=run -i %problem%.in -o %problem%.out -m 256M %problem%_%author%.exe
)
if EXIST %problem%_%author%.java (
javac %problem%_%author%.java -encoding utf8 || goto CompSourceError
set exec=run -i %problem%.in -o %problem%.out -m 256M java -ea -Xss64M -Xmx256M %problem%_%author%
)
if EXIST %problem%_%author%.py (
set exec=run -i %problem%.in -o %problem%.out -m 256M python %problem%_%author%.py
)

call javac -classpath ../../lib/testlib4j.jar Check.java -encoding utf8 
call jar cf Check.jar *.class

echo Checking solution...
for %%i in (tests\??) do (
	echo running on test %%i
	copy %%i %problem%.in > nul

	%exec%

        java -Xmx256M -Xss64M -cp ../../lib/testlib4j.jar;Check.jar ru.ifmo.testlib.CheckerFramework Check %%i %problem%.out %%i.a
)

goto End

:CompSourcesError
  echo Cannot compile source
  goto End
:SourceRunningError
  echo Fail in running on tests

:End
