I had another idea to speed up the file creation.
The first time the following batch is executed it is slow as it uses an old version (slightly variated) of the algorithm: You may add the later one instead.
But it also extends the batch file to contain all binary data values (except NUL).
On the second run it loads these precomputed binary data and uses it to create the files (for most except 0x0A, 0x0D) in a (hopefully) faster way (at least on the pcs i've tested it).
This is mainly thought to be used by batch applications that only needs the binary data for internal use, so i declared the (fast) creation of the files as an "example application":
Code: Select all
@echo off
setlocal
call :_loadTable
if defined error (
echo %error%
goto :eof
)
:: Be careful by manually editing the upper part.
:: #############################################################################
:: Feel free to edit this part under these restrictions:
:: - Occupied labels; do not (re)define: _binaryTable, _loadTable, eof.
:: - Occupied labels; do not use : _binaryTable, _loadTable.
:: - Occupied file names, do not use: "t.tmp", "temp.tmp", "characters\00.chr", ..., "characters\FF.chr".
:: - Occupied path names, do not use: ".\characters"
:: - Occupied character, do not use the special key with the code: 0x1A
:: example application: create each file of these "characters\00.chr", ..., "characters\FF.chr" if not exist.
md characters 2> nul
pushd "characters"
:: values (characters) won't work (at least under; has to be tested on other windows versions):
:: - 00 (NUL), 22 ("), 3D (=) (win xp x64)
:: - 09 (HT), 0A (LF), 0B (VT), 0C (FF), 0D (CR), 20 (SP), FF (FN)
setlocal enableDelayedExpansion
REM This code creates files containing one single Byte each 0x0A until 0x0D
REM Teamwork of carlos, penpen, aGerman, dbenham
REM Tested under Win2000, XP, Win7, Win8
>"t.tmp" type nul
for %%a in (0A 0D) do if not exist "%%a.chr" for /L %%N in (0x%%a, 1, 0x%%a) do (
makecab /d compress=off /d reserveperfoldersize=%%N /d reserveperdatablocksize=26 "t.tmp" "%%a.chr"
type "%%a.chr" | ((for /l %%N in (1 1 38) do pause)&(findstr "^">"temp.tmp"))
copy /y "temp.tmp" /a "%%a.chr" /b
) > nul
REM now simpler created Byte values per file
for %%a in (09 0B 0C 20 3D FF) do if not exist "%%a.chr" (
cmd /D /A /C echo(!table:~0x%%a,1!!table:~0x1A,1! < nul > "temp.tmp"
copy /Y "temp.tmp" /A "%%a.chr" /B > nul
) > nul
for %%h in (0 1 2 3 4 5 6 7 8 9 A B C D E F) do for %%l in (0 1 2 3 4 5 6 7 8 9 A B C D E F) do if not exist "%%h%%l.chr" (
if "%%h%%l" == "00" (
cmd /D /U /C set /P "=a" < nul > "00.chr"
copy /y "00.chr" + nul "00.chr" > nul
type "00.chr" | ((pause > nul) & (findstr "^">"temp.tmp"))
copy /y "temp.tmp" /a "00.chr" /b > nul
) else if "%%h%%l" == "22" (
cmd /D /A /C echo("!table:~0x1A,1!" < nul > "temp.tmp"
copy /Y "temp.tmp" /A "22.chr" /B > nul
) else (
set /P "=!table:~0x%%h%%l,1!" < nul > "%%h%%l.chr"
)
)
del "t.tmp" "temp.tmp"
:next
endlocal
popd
:: #############################################################################
:: Be careful by manually editing the below part.
endlocal
goto :eof
:_binaryTable
set "error=Unknown error occured: Binary part could not be appended - maybe write protected."
echo The binary data is created and appended to this file, this may take a while.
md "characters" 2>nul
pushd "characters"
:: #####################################
:: This is an older version in an slightly different variation.
:: I, m not sure what is the fastest version, so i took this one, as it would only speed up the first run (normally).
:: It may be replaced by any newer (== faster) version.
:: In addition i have used the actual directory ".", instead of ".\characters", as i have "pushed" it above
REM This code creates 256 files containing one single Byte each from 0x00 until 0xFF
REM Teamwork of carlos, penpen, aGerman, dbenham
REM Tested under Win2000, XP, Win7, Win8
>"t.tmp" type nul
(
for %%A in (0 1 2 3 4 5 6 7 8 9 A B C D E F) do for %%B in (0 1 2 3 4 5 6 7 8 9 A B C D E F) do for /L %%N in (0x%%A%%B, 1, 0x%%A%%B) do (
makecab /d compress=off /d reserveperfoldersize=%%N /d reserveperdatablocksize=26 "t.tmp" "%%A%%B.chr"
type "%%A%%B.chr" | ((for /l %%I in (1 1 38) do pause)&(findstr "^">"temp.tmp"))
copy /y "temp.tmp" /a "%%A%%B.chr" /b
)
copy /y nul + nul /a "1A.chr" /a
) > nul
del "t.tmp" "temp.tmp"
:: #####################################
:: ensure no binary data following 0x1A is used; if needed remove all data after the SUB character (0x1A)
copy "%~dpf0" /A "t.tmp" /B > nul
:: Append: binary data starting with 0x1A
for %%c in (1A 0D 0A 20) do ( copy "t.tmp" /B + "%%~c.chr" /B + "t.tmp" /B > nul )
for %%l in (1 2 3 4 5 6 7 8 9 A B C D E F) do ( copy "t.tmp" /B + "0%%~l.chr" /B + "t.tmp" /B > nul)
for %%h in (1 2 3 4 5 6 7 8 9 A B C D E F) do for %%l in (0 1 2 3 4 5 6 7 8 9 A B C D E F) do ( copy "t.tmp" /B + "%%~h%%~l.chr" /B + "t.tmp" /B > nul)
for %%c in (0D 0A 0D 0A) do ( copy "t.tmp" /B + "%%~c.chr" /B + "t.tmp" /B > nul )
:: Append: loading part; ensure line is not defined
set "line="
(
cmd /D /A /C echo :_binaryTable
cmd /D /A /C echo for /F "tokens=1 delims=:" %%%%a in ('findstr /N "^" "%%~dpf0"'^) do set /A "line=%%%%a-13"
cmd /D /A /C echo if defined line (
cmd /D /A /C echo for /L %%%%b in (1,1,%%line%%^) do (
cmd /D /A /C echo set "table="
cmd /D /A /C echo set /P "table="
cmd /D /A /C echo ^)
cmd /D /A /C echo ^) ^^^< "%%~dpf0"
cmd /D /A /C echo if not defined table goto :_binaryTable
cmd /D /A /C echo :: the next line must be the last to ensure that all data is appended.
cmd /D /A /C echo set "error="
) >> t.tmp
:: Replace the actual batch file, saving binary data, deleting temporary data
copy /Z "t.tmp" /B "%~dpf0" /B > nul
del "t.tmp"
popd
:: Own loading part to avoid endless loop.
for /F "tokens=1 delims=:" %%a in ('findstr /N "^" "%~dpf0"') do set /A "line=%%a-13"
if defined line (
for /L %%b in (1,1,%line%) do (
set "table="
set /P "table="
)
) < "%~dpf0"
if "%table:~64,16%" == "@ABCDEFGHIJKLMNO" if NOT "%table:~255%" == "" set error=
goto :eof
:_loadTable
set "error=Unknown error occured: Environment variable table not loaded properly."
for %%a in (table line) do set "%%~a="
goto :_binaryTable
:: if no binary table data is available this is the eof, else the next line contains the binary data.
I hope you find this useful, too.
penpen