@echo off
setlocal
set errorlevel=0
set errorlevel=

if [%1]==[] goto INCORRECT_CALL
if "%~1"=="" goto INCORRECT_CALL
if not [%2]==[] goto INCORRECT_CALL

set ScriptFile$$=%~1
set ScriptFileName$$=%~nx1

if /i not "%~x1"==".SQL" goto NOT_SQL_FILE

set InvocationBatchFileName$$=InvokeSqlTrans.cmd
set InvocationBatchFile$$=%~dp0%InvocationBatchFileName$$%

if not exist "%InvocationBatchFile$$%" goto INVOCATION_BATCH_NOT_FOUND

call :EXEC_CMD start /max "SQL-translation utility - [%ScriptFileName$$%]" /I CMD /C ""%InvocationBatchFile$$%" "%ScriptFile$$%""
rem call :EXEC_CMD start /max "SQL-translation utility - [%ScriptFileName$$%]" /I CMD /C "mode con: cols=1001 && "%InvocationBatchFile$$%" "%ScriptFile$$%""
if %errorlevel% neq 0 goto ERROR

EXIT
::==================================================================================================

:INCORRECT_CALL
echo.
echo ## Incorrect call of "StartSqlTrans.cmd" (special batch).
goto ERROR

:NOT_SQL_FILE
echo.
echo ## The script must have .SQL file extension ($SqlTrans-utility): "%ScriptFile$$%".
goto ERROR

:INVOCATION_BATCH_NOT_FOUND
echo.
echo ## SqlTrans-utility invocation batch not found: "%InvocationBatchFile$$%".
goto ERROR

::==================================================================================================
:EXEC_CMD
set errorlevel=0
set errorlevel=
echo ^>^> %* ...
%*
goto :EOF
::==================================================================================================
:ERROR
echo 
pause
EXIT 255
::==================================================================================================
