Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ECHO is off.
- @echo off
- ECHO is off.
- :setup
- ECHO is off.
- REM set "_IFLE_ExclusionList=main setup macro end loop loop2 loop3 loop4 skip skip1 skip2 skip2 skip3 skip4 test test1 test2 test3 cleanup argument params args next prev iteration pre post 0 1 2 3 4 5 6 7 8 9 subloop matchfound nomatch found index list arguments preamble test4 test5 test6 start reset"
- ECHO is off.
- :main
- ECHO is off.
- if "[%~n0]" EQU "[bfw]" ( Call :ShiftedArgumentCaller %* ) else ( Call :%~n0 %* )
- ECHO is off.
- :end
- ECHO is off.
- REM set "_IFLE_ExclusionList="
- ECHO is off.
- GoTo :EOF
- ECHO is off.
- :ShiftedArgumentCaller
- set _ShiftedArgumentCaller_function=%~1
- shift
- GoTo :EOF
- ECHO is off.
- objective create bfw.bat
- that contains everything to make bfw.bat
- ECHO is off.
- REM :CoreFunctionCopier
- REM :AddFunctionToBatch
- REM :ListFunctions
- ECHO is off.
- REM :install
- REM :uninstall
- REM :update
- ECHO is off.
- REM :listfunction
- REM :getfunctionlist
- REM :createnakedfunction
- REM :shortcutify
- REM :symlinkify
- REM :hardlinkify
- ECHO is off.
- REM Call :AddFunctionToBatch bfw.new.bat testsource.bat AddFunctionToBatch GetFunctionRows GetLabelRow GetFunctionExit GetFunctionPreambleRow GetFunctionPostscriptRow ClearVariablesByPrefix GetFunctionName GetNextExitRow GetNextFunctionName GetPreviousExitRow GetEOFrow countLines IsFunctionLabelExcluded AppendFileLineToFile
- ECHO is off.
- ECHO is off.
- REM source function should be able to be invoked by
- REM sourcebatch then function name
- REM relativepath\sourcebatch.bat:FunctionName
- REM bfw\lib\section\sourcebatch.bat:FunctionName .bat is optional bfw\lib\section can be omitted to just bfw\sourcebatch
- REM just the FunctionName if not found in the current sourcebatch, then search all files in bfw\lib\
- REM FOR NOW JUST MATCH FILE AND FUNCTION
- :: NOPREAMBLE NOPOSTSCRIPT PREAMBLEONLY POSTSCRIPTONLY FUNCTIONONLY UNPACK PLUSDEPENDENCIES
- ::Usage Call :AddFunctionToBatch DestinationBatch SourceBatch FunctionName1 FunctionName2 ... FunctionNameN
- :AddFunctionToBatch
- set "_AddFunctionToBatch_prefix=_AFTB
- set "_AFTB_output=%~1"
- :AddFunctionToBatch-args
- Call :ClearVariablesByPrefix _AFTB_FunctionRows
- REM if defined bfw.root
- REM determine quel fichier
- REM ficher dans repertoire courrant
- REM ou fichier dans bfw\lib ?
- Call :GetFunctionRows "%_AFTB_SourceBatch%" "%_AFTB_FunctionName%" _AFTB_FunctionRows
- :AddFunctionToBatch-end
- Call :AppendFileLineToFile "%_AFTB_SourceBatch%" "%_AFTB_output%" %_AFTB_FunctionRows.preamble%-%_AFTB_FunctionRows.postscript%
- ECHO is off.
- ::Usage Call :GetLastToken InputString OutputLastToken
- :GetLastToken
- for %%a in (%~1) do set %~2=%%a
- GoTo :EOF
- ECHO is off.
- ::Usage Call :IsLastToken InputString SearchString optional OutputValue
- :IsLastToken
- set "_IsLastToken_result=false"
- if defined %~1 call set _IsLastToken_input=%%%~1%%
- if not defined _IsLastToken_input set "_IsLastToken_input=%~1"
- set "_IsLastToken_input=%_IsLastToken_input:-= %"
- set "_IsLastToken_input=%_IsLastToken_input::= %"
- for %%a in (%_IsLastToken_input%) do if "[%%a]" EQU "[%~2]" set "_IsLastToken_result=true"
- ECHO is off.
- REM for AddFunctionToBatch
- ::Usage Call :AddFunctionToBatch DestinationBatch SourceBatch FunctionName1 FunctionName2 ... FunctionNameN
- set destination
- for each argument
- if argument is a .bat, set as sourcebatch shift+next
- if argument starts with bfw\, source is in %bfw.root%\lib\ set sourcebatch shift+next
- search source batch for function rows
- copy (append) function rows content to destination batch
- ECHO is off.
- ECHO is off.
- ::Usage Call :GetLabels BatchFile LabelObjectArray optional RowsArray
- :GetLabelsOnly
- set "_GetLabels_output=%~2"
- if "[%~3]" EQU "[]" ( set "_GetLabels_output_rows=%_GetLabels_output%.rows" ) else ( set "_GetLabels_output_rows=%~3" )
- for /f delims= eol= %%a in ('%SystemRoot%\System32\findstr /N "^:[^:]" "%~1" | findstr /N "^"') do (
- REM for /f "tokens=1,2,3* delims=:" %%f in ("%%a") do set %_GetLabels_output_rows%[%%g].type=label
- for /f "tokens=1,2,3* delims=:" %%f in ("%%a") do for /f "tokens=1,2*" %%z in ("%%h") do set %_GetLabels_output%[%%f].name=%%~z
- REM for /f "tokens=1,2,3* delims=:" %%f in ("%%a") do for /f "tokens=1,2*" %%z in ("%%h") do set %_GetLabels_output%.name[%%~z]=%%g
- REM for /f "tokens=1,2,3* delims=:" %%f in ("%%a") do for /f "tokens=1,2*" %%z in ("%%h") do set %_GetLabels_output_rows%[%%g]=%%~z
- )
- GoTo :EOF
- ECHO is off.
- ECHO is off.
- REM FindFunction ?
- REM ::Usage Call :GetFunction batchfile OutputArray optional FunctionSearchPattern
- REM :GetFunction
- REM set "_GetFunction_prefix=_GF"
- REM for /f delims= eol= %%a in ('%SystemRoot%\System32\findstr /N "^:[^:]" "%~1" | findstr /N "^"') do (
- REM )
- REM GoTo :EOF
- ECHO is off.
- :IsFile
- set "_IsFile_buffer=%~1"
- set "_IsFile_buffer="
- :IsFile-loop
- set "_IsFile_Filename=%~a1"
- if "[%_IsFile_Filename:~0,1%]" EQU "[-]" ( set "_IsFile_result=true" ) else ( set "_IsFile_result=false" )
- if "[%_IsFile_output%]" NEQ "[]" set "%_IsFile_output%=%_IsFile_result%"
- ECHO is off.
- ::Usage Call :GetFunctionRows BatchFile FunctionName OutputObject
- :GetFunctionRows
- set "_GetFunctionRows_prefix=_GFR"
- set "_GFR_BatchFile=%~1"
- set "_GFR_FunctionName=%~2"
- set "_GFR_OutputObject=%~3"
- Set "%_GFR_OutputObject%.name=%_GFR_FunctionName%"
- Call :GetLabelRow "%_GFR_BatchFile%" %_GFR_FunctionName% %_GFR_OutputObject%.start
- Call :GetFunctionExit "%_GFR_BatchFile%" %%%_GFR_OutputObject%.start%% %_GFR_OutputObject%.exit
- Call :GetFunctionPreambleRow "%_GFR_BatchFile%" %%%_GFR_OutputObject%.start%% %_GFR_OutputObject%.preamble
- Call :GetFunctionPostscriptRow "%_GFR_BatchFile%" %%%_GFR_OutputObject%.start%% %_GFR_OutputObject%.postscript
- ECHO is off.
- ::Usage Call :GetLabelRow BatchFile FunctionName optional OutputRow
- :GetLabelRow
- exit /b 0
- ECHO is off.
- ::Usage Call :GetFunctionExit BatchFile FunctionName or Row optional OutputRow
- :GetFunctionExit
- set "_GetFunctionExit_prefix=_GFE"
- set "_GFE_BatchFile=%~1"
- set "_GFE_Function=%~2"
- set "_GFE_Output=%~3"
- Call :GetNextExitRow %_GFE_BatchFile% %_GFE_Function% _GFE_FunctionNextExit
- Call :GetNextFunctionRow %_GFE_BatchFile% %_GFE_FunctionNextExit% _GFE_FunctionNextFunction
- Call :GetPreviousExitRow %_GFE_BatchFile% %_GFE_FunctionNextFunction% _GFE_FunctionExit
- if %_GFE_FunctionEOFExit% GTR 0 set /a _GFE_FunctionExit=%_GFE_FunctionEOFExit%
- if defined _GFE_Output set /a %_GFE_Output%=%_GFE_FunctionExit%
- ECHO is off.
- ::Usage Call :GetFunctionPreambleRow BatchFile FunctionNameOrRow optional OutputRow
- :GetFunctionPreambleRow
- Call :GetPreviousEmptyRow "%~1" "%~2" "%~3"
- exit /b %errorlevel%
- ECHO is off.
- ::Usage Call :GetFunctionPostscriptRow BatchFile FunctionNameOrRow optional OutputRow
- :GetFunctionPostscriptRow
- Call :GetFunctionExit "%~1" "%~2" _GFPR_ExitRow
- Call :GetNextEmptyRow "%~1" "%_GFPR_ExitRow%" "%~3"
- ECHO is off.
- :: Usage Call :ClearVariablesByPrefix myPrefix
- :ClearVariablesByPrefix
- if "[%~1]" NEQ "[]" for /f "tokens=1 delims==" %%a in ('set "%~1" 2>nul') do set %%a=
- GoTo :EOF
- ECHO is off.
- ::Usage Call :GetFunctionName File LineNumber OutputValue
- :GetFunctionName
- exit /b 1
- ECHO is off.
- ::Usage Call :GetBatchCore File optional OutputValue
- ::Returns core function final line number
- :GetBatchCore
- Call :GetLabelRow "%~1" End _GetBatchCore_EndRow
- Call :GetNextFunctionRow "%~1" %_GetBatchCore_EndRow% _GetBatchCore_FirstFunction
- Call :GetPreviousExitRow "%~1" %_GetBatchCore_FirstFunction% _GetBatchCore_FirstFunctionExit
- Call :GetNextEmptyRow "%~1" %_GetBatchCore_FirstFunctionExit% _GetBatchCore_CorePostscript
- ECHO is off.
- ::Usage Call :GetNextExitRow BatchFile StartRow optional OutputRow
- :GetNextExitRow
- exit /b 0
- ECHO is off.
- :ListFunctions BatchFile optional OutputVariable BatchFile2 ... BatchFileN
- set "_ListFunctions_prefix=_LF"
- set "_LF_InputFile=%~1"
- :ListFunctions-args
- :ListFunctions-end
- if defined _LF_Output ( set "%_LF_Output%=%_LF_FunctionList:~1%" ) else ( echo.%_LF_FunctionList:~1% )
- ECHO is off.
- ECHO is off.
- ::Usage Call :GetNextFunctionName BatchFile StartRow optional OutputRow
- ::Usage Call :GetNextFunctionRow BatchFile StartRow optional OutputRow
- :GetNextFunctionName
- set "_GNFR_ReturnName=true"
- :GetNextFunctionRow
- set "_GetNextFunctionRow_prefix=_GNFR"
- set "_GNFR_BatchFile=%~1"
- set "_GNFR_StartRow=%~2"
- set "_GNFR_Output=%~3"
- :GetNextFunctionRow-args
- Call :countLines _GNFR_current "%_GNFR_BatchFile%"
- :GetNextFunctionRow-exit-loop
- Call :GetFunctionName "%~1" %_GNFR_current% _GNFR_current_FunctionName
- :GetNextFunctionRow-skip
- if "[%~3]" NEQ "[]" set "%~3=%_GNFR_current%"
- if "[%_GNFR_ReturnName%]" EQU "[true]" set "%~3=%_GNFR_current_FunctionName%"
- ECHO is off.
- ::Usage Call :GetPreviousExitRow BatchFile StartRow optional OutputRow
- :GetPreviousExitRow
- set "_GPER_previous="
- :GetPreviousExitRow-exit-loop
- if "[%~3]" NEQ "[]" call set "%~3=%_GPER_previous%"
- ECHO is off.
- ::Usage Call :GetEOFrow BatchFile FunctionName optional OutputRow
- :GetEOFrow
- exit /b 0
- ECHO is off.
- ::Usage Call :countLines returnvariable filename
- ::counts the number of lines in a file
- :countLines result= "%file%"
- setLocal disableDelayedExpansion
- for /f "delims=:" %%N in ('
- cmd /d /a /c type "%~2" ^& <nul set /p "=#" | (
- 2>nul findStr /n "^" && echo() |
- 2>nul findStr /blv 1: | 2>nul findStr /lnxc:" "
- exit /b %errorLevel% %= countLines =%
- https://stackoverflow.com/a/49089494/6104460
- ECHO is off.
- :IsFunctionLabelExcluded
- set "_IsFunctionLabelExcluded_prefix=_IFLE"
- set /a _IFLE_exit=1
- if defined %~1 call set _IFLE_input=%%%~1%%
- if not defined _IFLE_input set "_IFLE_input=%~1"
- set "_IFLE_input=%_IFLE_input:-= %"
- set "_IFLE_input=%_IFLE_input::= %"
- set "_IFLE_ExclusionList=%~2"
- if "[%_IFLE_ExclusionList%]" EQU "[]" set "_IFLE_ExclusionList=main setup macro end loop loop2 loop3 loop4 skip skip1 skip2 skip2 skip3 skip4 test test1 test2 test3 cleanup argument params args next prev iteration pre post 0 1 2 3 4 5 6 7 8 9 subloop matchfound nomatch found index list arguments preamble test4 test5 test6 start reset"
- for %%a in (%_IFLE_input%) do set _IFLE_last_token=%%a
- REM set _IFLE
- :IsFunctionLabelExcluded-end
- ECHO is off.
- ::Usage Call :AppendFileLineToFile inputfile outputfile 3 4 50-75 5 6 7 ... N
- :AppendFileLineToFile
- set "_AppendFileLineToFile_prefix=_AFLTF"
- set "_AFLTF_InputFile=%~1"
- set "_AFLTF_OutputFile=%~2"
- :AppendFileLineToFile-arg
- if not defined _AFLTF_Stop set /a _AFLTF_Stop=%_AFLTF_Start%
- Setlocal enabledelayedexpansion
- if %_AFLTF_Start% GTR 1 set /a "_AFLTF_skip=%_AFLTF_Start%-1"
- if %_AFLTF_Start% GTR 1 ( set "_AFLTF_skip=skip^=%_AFLTF_skip%^" ) else ( set "_AFLTF_skip=" )
- for /f %_AFLTF_skip% delims= eol= %%a in (' ( type "%_AFLTF_InputFile%" | %SystemRoot%\System32\findstr /N /R /C:".*" ) 2>nul ') do (
- for /f "delims=:" %%f in ("%%a") do if %%f GTR %_AFLTF_Stop% GoTo :AppendFileLineToFile-end
- set _AFLTF_buffer=%%a
- if defined _AFLTF_buffer echo(!_AFLTF_buffer:*:=!
- )
- endlocal
- :AppendFileLineToFile-end
- ECHO is off.
- ::Usage Call :GetPreviousEmptyRow BatchFile StartRow optional OutputRow
- :GetPreviousEmptyRow
- set "_GPEW_previous="
- exit /b 0
- :GetPreviousEmptyRow-exit-loop
- if "[%~3]" NEQ "[]" call set "%~3=%_GPEW_previous%"
- ECHO is off.
- ::Usage Call :GetNextEmptyRow BatchFile StartRow optional OutputRow
- :GetNextEmptyRow
- Call :countLines _GetNextEmptyRow_lastrow "%~1"
- set /a _GetNextEmptyRow_lastrow+=1
- if "[%~3]" NEQ "[]" set "%~3=%_GetNextEmptyRow_lastrow%"
- exit /b %_GetNextEmptyRow_lastrow%
- ECHO is off.
- :BFWFunctionSwitcher-text
- @echo off
- ECHO is off.
- :setup
- ECHO is off.
- REM set "_IFLE_ExclusionList=main setup macro end loop loop2 loop3 loop4 skip skip1 skip2 skip2 skip3 skip4 test test1 test2 test3 cleanup argument params args next prev iteration pre post 0 1 2 3 4 5 6 7 8 9 subloop matchfound nomatch found index list arguments preamble test4 test5 test6 start reset"
- ECHO is off.
- :main
- ECHO is off.
- if "[%~n0]" EQU "[bfw]" ( Call :ShiftedArgumentCaller %* ) else ( Call :%~n0 %* )
- ECHO is off.
- :end
- ECHO is off.
- REM set "_IFLE_ExclusionList="
- ECHO is off.
- GoTo :EOF
- :EndOF_BFWFunctionSwitcher-text
- ECHO is off.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement