!BAT

# translates strings in a file or (md)0xnnn memory contents and appends to (md)0x3000+0x50
# used to translate $$STRxxxx strings

# set DDIR to mainmenu (should not be used anyway)
set MDIR=%1
set DDIR=/_ISO/MAINMENU

if "%MDIR%"=="" goto :EOF
if not exist %MDIR% pause No file %MDIR% && goto :EOF

:XLATE
::set DDIR=%DIR%
:: get rid of leading ()
if "%DDIR:~0,2%"=="()" set DDIR=%DDIR:~2%
if "%DD%"=="1" echo Changing all $HOME$ strings in file %MDIR% to %DDIR%
echo > (md)0x3100+0x20
set ST=0
set END=0
:XLOOP
if "%DD%"=="1" echo Start=%ST%
cat --skip=%ST% --locate=$HOME$ --number=1 %MDIR% > nul
set /a END=%?% > nul
if  "%END%"=="0" goto :nohome
set /a LENGTH=%END%-%ST% > nul
cat --skip=%ST% --length=%LENGTH% %MDIR% >> (md)0x3100+0x20
echo -n %DDIR% >> (md)0x3100+0x20
set /a ST=%END%+6 > nul
goto :XLOOP

:nohome
cat --skip=%ST% %MDIR% >> (md)0x3100+0x20
echo >> (md)0x3100+0x20
::cat (md)0x3100+0x50
::pause
:: copy to menu

:: check for $$STR in (md)0x3100+0x20
call :XLATE9
set DD=

set LENGTH=
set END=
set ST=
set DDIR=
set MDIR=
goto :EOF

:: -- $$STR substitution

:XLATE9
set MDIR=(md)0x3100+0x20
if "%DD%"=="1" echo Changing all $$STR strings in file %MDIR%
echo -n > (md)0x3300+0x20
set ST=0
set END=0

:XLOOP9
if "%DD%"=="1" echo Looking for $$STR starting at %ST%
cat --skip=%ST% --locate="$$STR" --number=1 %MDIR% > nul
set /a END=%?% > nul
if  "%END%"=="0" goto :nohome9
set /a LENGTH=%END%-%ST% > nul
cat --skip=%ST% --length=%LENGTH% %MDIR% >> (md)0x3300+0x20
cat --skip=%END% --length=9 %MDIR% | echo -e !BAT\nset A= > (md)0x3200+1
call (md)0x3200+1
if "%DD%"=="1" echo Found %A%

:: now find A in (md)0x880+0x80
cat --locate=%A% --number=1 (md)0x880+0x80 > nul
set /a ALOC=%?% > nul
if "%ALOC%"=="0" echo $[0104]ERROR %A% NOT FOUND IN STRINGS.TXT FILE! && pause
if "%ALOC%"=="0" echo -n %A% >> (md)0x3300+1 && goto :badstr
set /a ALOC=%ALOC%+10 > nul
:: get end of line
cat --locate=\x0a --skip=%ALOC% --number=1 (md)0x880+0x80 > nul
set /a LL=%?%-%ALOC%-1 > nul
cat --skip=%ALOC% --length=%LL% (md)0x880+0x80 >> (md)0x3300+0x20
if "%DD%"=="1" echo Replacing with
if "%DD%"=="1" cat --skip=%ALOC% --length=%LL% (md)0x880+0x80 && echo 
set A=
set ALOC=
set LL=
:badstr

# move past string and CR\LF
set /a ST=%END%+9 > nul

goto :XLOOP9

:nohome9
if "%DD%"=="1" echo NOHOME9
cat --skip=%ST% %MDIR% >> (md)0x3300+0x20
echo -n >> (md)0x3300+0x20
:: copy to menu
cat (md)0x3300+0x20 >> (md)0x3000+0x50

set ALOC=
set A=
set LL=
set LENGTH=
set END=
set ST=
set DDIR=
goto :EOF

:: ----


