@echo off

CALL clean.cmd

set problem=dwarfs
set author=nn
rem you can set lang as dpr, java, cpp or python
set lang=java

echo Generating tests...
mkdir tests
pushd src
echo Compiling generator...

rmdir /S /Q __tmp 2> nul

mkdir __tmp
javac -sourcepath . -d __tmp TestsGen.java
pushd __tmp
mkdir META-INF
echo Main-Class: TestsGen> META-INF/manifest.1
call jar cfm TestsGen.jar META-INF/manifest.1 *.class
copy /Y TestsGen.jar .. > nul
popd
rmdir /S /Q __tmp

java -Xmx1G -Xss64M -jar -ea TestsGen.jar
if errorlevel 239 exit
popd

call compile.cmd

echo Generating answers...

if [%lang%]==[java] javac %problem%_%author%.java -encoding utf8
if [%lang%]==[cpp] g++ -DLOCAL -O2 %problem%_%author%.cpp -o %problem%_%author%.exe
if [%lang%]==[dpr] dcc32 -cc %problem%_%author%.dpr

for %%i in (tests\??) do (
    echo Test %%i
    copy %%i %problem%.in > nul
    if exist validate.jar (
    java -jar validate.jar < %problem%.in
    if errorlevel 1 (
        echo Validator rejects test %%i
        goto end
    )
    echo Validator accepts test %%i
    )

    if [%lang%]==[java] java -Xmx256M -Xss64M %problem%_%author%
    if [%lang%]==[cpp] %problem%_%author% 
    if [%lang%]==[dpr] %problem%_%author%
    if [%lang%]==[python] python %problem%_%author%.py

    copy %problem%.out %%i.a > nul
    echo Check %%i
    check.exe %%i %%i.a %%i.a
)

:end