@echo off

set infile="%1"
shift
set outfile="%1"
shift
for /f %%i in ('mktemp.bat') do set tempfile=%%i
if %errorlevel% neq 0 (
	goto fail
)

set "args="
:parse
if "%~1" neq "" (
	if "%~1" neq "--" (
		set args=%args% %1
		shift
		goto :parse
	) else (
		shift
	)
)
set "args1="
:parse1
if "%~1" neq "" (
	set args1=%args1% %1
	shift
	goto :parse1
)

rem echo %args%
rem echo %args1%

echo on
ExpandCLIncludes.exe -i %infile% -o "%tempfile%" %args%
@echo off
if %errorlevel% neq 0 (
	goto fail
)

echo on
FileToHeader.exe "%tempfile%" %outfile% --name-after %infile% %args1%
@echo off
if %errorlevel% neq 0 (
	goto fail
)

del "%tempfile%"

exit /B 0
:fail

del "%tempfile%"

exit /B 1
