Guest User

Untitled

a guest
Apr 22nd, 2024
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.04 KB | None | 0 0
  1. @echo off
  2.  
  3. :setup
  4.  
  5. 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"
  6.  
  7. :main
  8.  
  9. for %%a in ( %* ) do ( for %%b in ( /h /? -h -? help --help ) do ( if "[%%a]" EQU "[%%b]" ( Call :%~n0-help & exit /b 1 ) ) )
  10. for %%a in ( %* ) do ( if "[%%a]" EQU "[demo]" ( Call :%~n0-demo & exit /b 1 ) )
  11. if "[%~1]" EQU "[]" ( echo %~n0 needs at least one argument & exit /b 1 )
  12. REM if "[%~1]" EQU "[]" if "[%~2]" EQU "[]" ( echo %~n0 needs at least two argument & exit /b 1 )
  13. if "[%~n0]" EQU "[bfw]" ( Call :ShiftedArgumentCaller %* ) else ( Call :%~n0 %* )
  14.  
  15. :end
  16.  
  17. REM set "_IFLE_ExclusionList="
  18.  
  19. GoTo :EOF
  20.  
  21.  
  22. :ShiftedArgumentCaller
  23. set _ShiftedArgumentCaller_function=%~1
  24. shift
  25. set "_ShiftedArgumentCaller_function=" & GoTo :%_ShiftedArgumentCaller_function%
  26. GoTo :EOF
  27.  
  28.  
  29. REM source function should be able to be invoked by
  30. REM sourcebatch then function name
  31. REM relativepath\sourcebatch.bat:FunctionName
  32. REM bfw\lib\section\sourcebatch.bat:FunctionName .bat is optional bfw\lib\section can be omitted to just bfw\sourcebatch
  33. REM just the FunctionName if not found in the current sourcebatch, then search all files in bfw\lib\
  34. REM FOR NOW JUST MATCH FILE AND FUNCTION
  35. :: NOPREAMBLE NOPOSTSCRIPT PREAMBLEONLY POSTSCRIPTONLY FUNCTIONONLY UNPACK PLUSDEPENDENCIES
  36. ::Usage Call :AddFunctionToBatch DestinationBatch SourceBatch FunctionName1 FunctionName2 ... FunctionNameN
  37. :AddFunctionToBatch
  38. set "_AddFunctionToBatch_prefix=_AFTB
  39. set "_AFTB_output=%~1"
  40. :AddFunctionToBatch-args
  41. if "[%~2]" EQU "[UNPACK]" ( set "_AFTB_Unpack=true" & shift & GoTo :AddFunctionToBatch-args )
  42. Call :ClearVariablesByPrefix _AFTB_FunctionRows
  43. Call :IsFile "%~2" && ( set "_AFTB_SourceBatch=%~2" & shift & GoTo :AddFunctionToBatch-args ) || set "_AFTB_FunctionName=%~2"
  44. REM if defined bfw.root
  45. REM determine quel fichier
  46. REM ficher dans repertoire courrant
  47. REM ou fichier dans bfw\lib ?
  48. if "[%_AFTB_FunctionName%]" EQU "[CORE]" ( Call :GetBatchCore "%_AFTB_SourceBatch%" _AFTB_FunctionRows & GoTo :AddFunctionToBatch-end )
  49. Call :GetFunctionRows "%_AFTB_SourceBatch%" "%_AFTB_FunctionName%" _AFTB_FunctionRows
  50. if "[%_AFTB_Unpack%]" EQU "[true]" ( set /a _AFTB_FunctionRows.preamble=%_AFTB_FunctionRows.start%+1 & set /a _AFTB_FunctionRows.postscript=%_AFTB_FunctionRows.exit%-1 & set "_AFTB_Unpack=" )
  51. :AddFunctionToBatch-end
  52. Call :AppendFileLineToFile "%_AFTB_SourceBatch%" "%_AFTB_output%" %_AFTB_FunctionRows.preamble%-%_AFTB_FunctionRows.postscript%
  53. if "[%~3]" NEQ "[]" ( shift & GoTo :AddFunctionToBatch-args )
  54. Call :ClearVariablesByPrefix %_AddFunctionToBatch_prefix% _AddFunctionToBatch_prefix & GoTo :EOF
  55.  
  56.  
  57. ::Usage Call :GetLastToken InputString OutputLastToken
  58. :GetLastToken
  59. for %%a in (%~1) do set %~2=%%a
  60. GoTo :EOF
  61.  
  62.  
  63. ::Usage Call :IsLastToken InputString SearchString optional OutputValue
  64. :IsLastToken
  65. set "_IsLastToken_result=false"
  66. if defined %~1 call set _IsLastToken_input=%%%~1%%
  67. if not defined _IsLastToken_input set "_IsLastToken_input=%~1"
  68. set "_IsLastToken_input=%_IsLastToken_input:-= %"
  69. set "_IsLastToken_input=%_IsLastToken_input::= %"
  70. for %%a in (%_IsLastToken_input%) do if "[%%a]" EQU "[%~2]" set "_IsLastToken_result=true"
  71. set "_IsLastToken_input=" & set "_IsLastToken_result=" & if "[%_IsLastToken_result%]" EQU "[true]" ( exit /b 0 ) else ( exit /b 1 )
  72.  
  73.  
  74. ::Usage Call :GetLabels BatchFile LabelObjectArray optional RowsArray
  75. :GetLabelsOnly
  76. set "_GetLabels_output=%~2"
  77. if "[%~3]" EQU "[]" ( set "_GetLabels_output_rows=%_GetLabels_output%.rows" ) else ( set "_GetLabels_output_rows=%~3" )
  78. for /f delims^=^ eol^= %%a in ('%SystemRoot%\System32\findstr /N "^:[^:]" "%~1" ^| findstr /N "^"') do (
  79. for /f "tokens=1,2,3* delims=:" %%f in ("%%a") do set /a "%_GetLabels_output%.ubound=%%f" & REM set %_GetLabels_output%[%%f]=%%g
  80. REM for /f "tokens=1,2,3* delims=:" %%f in ("%%a") do set %_GetLabels_output_rows%[%%g].type=label
  81. 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
  82. 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
  83. 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
  84. )
  85. set /a "%_GetLabels_output%.lbound=1" & set "_GetLabels_output=" & set "_GetLabels_output_rows="
  86. GoTo :EOF
  87.  
  88.  
  89. REM FindFunction ?
  90. REM ::Usage Call :GetFunction batchfile OutputArray optional FunctionSearchPattern
  91. REM :GetFunction
  92. REM set "_GetFunction_prefix=_GF"
  93. REM for /f delims^=^ eol^= %%a in ('%SystemRoot%\System32\findstr /N "^:[^:]" "%~1" ^| findstr /N "^"') do (
  94. REM )
  95. REM GoTo :EOF
  96.  
  97.  
  98. ::Usage Call :IsFile optional _OutputVar File1 File2 ... FileN && IsFile || IsNotFile
  99. :IsFile
  100. set "_IsFile_buffer=%~1"
  101. if /i "[%_IsFile_buffer:~0,10%]" EQU "[_OutputVar]" ( set "_IsFile_output=%~1" & shift )
  102. set "_IsFile_buffer="
  103. :IsFile-loop
  104. set "_IsFile_Filename=%~a1"
  105. if "[%_IsFile_Filename:~0,1%]" EQU "[-]" ( set "_IsFile_result=true" ) else ( set "_IsFile_result=false" )
  106. if "[%_IsFile_output%]" NEQ "[]" set "%_IsFile_output%=%_IsFile_result%"
  107. if "[%_IsFile_result%]" EQU "[true]" if "[%~2]" NEQ "[]" ( shift & GoTo :IsFile-loop )
  108. set "_IsFile_Filename=" & set "_IsFile_output=" & set "_IsFile_result=" & if "[%_IsFile_result%]" EQU "[true]" ( exit /b 0 ) else ( exit /b 1 )
  109.  
  110.  
  111. ::Usage Call :GetFunctionRows BatchFile FunctionName OutputObject
  112. :GetFunctionRows
  113. set "_GetFunctionRows_prefix=_GFR"
  114. set "_GFR_BatchFile=%~1"
  115. set "_GFR_FunctionName=%~2"
  116. set "_GFR_OutputObject=%~3"
  117. Set "%_GFR_OutputObject%.name=%_GFR_FunctionName%"
  118. Call :GetLabelRow "%_GFR_BatchFile%" %_GFR_FunctionName% %_GFR_OutputObject%.start
  119. Call :GetFunctionExit "%_GFR_BatchFile%" %%%_GFR_OutputObject%.start%% %_GFR_OutputObject%.exit
  120. Call :GetFunctionPreambleRow "%_GFR_BatchFile%" %%%_GFR_OutputObject%.start%% %_GFR_OutputObject%.preamble
  121. Call :GetFunctionPostscriptRow "%_GFR_BatchFile%" %%%_GFR_OutputObject%.start%% %_GFR_OutputObject%.postscript
  122. Call :ClearVariablesByPrefix %_GetFunctionRows_prefix% _GetFunctionRows_prefix & GoTo :EOF
  123.  
  124.  
  125. ::Usage Call :GetLabelRow BatchFile FunctionName optional OutputRow
  126. :GetLabelRow
  127. for /f delims=: tokens=1 %%a in ('%SystemRoot%\System32\findstr /I /N ":%~2" "%~1" | findstr /I /V "::%~2[a-zA-Z0-9\-\/\?\\_]"') do ( if "[%~3]" NEQ "[]" set "%~3=%%a" & exit /b %%a )
  128. exit /b 0
  129.  
  130.  
  131. ::Usage Call :GetFunctionExit BatchFile FunctionName or Row optional OutputRow
  132. :GetFunctionExit
  133. set "_GetFunctionExit_prefix=_GFE"
  134. set "_GFE_BatchFile=%~1"
  135. set "_GFE_Function=%~2"
  136. set "_GFE_Output=%~3"
  137. echo.%_GFE_Function%| findstr /r "[^0123456789]" >nul && ( set "_GFE_FunctionName=%_GFE_Function%" & Call :GetLabelRow %_GFE_BatchFile% %_GFE_Function% _GFE_Function ) || Call :GetFunctionName %_GFE_BatchFile% %_GFE_Function% _GFE_FunctionName
  138. Call :GetNextExitRow %_GFE_BatchFile% %_GFE_Function% _GFE_FunctionNextExit
  139. Call :GetNextFunctionRow %_GFE_BatchFile% %_GFE_FunctionNextExit% _GFE_FunctionNextFunction
  140. Call :GetPreviousExitRow %_GFE_BatchFile% %_GFE_FunctionNextFunction% _GFE_FunctionExit
  141. set /a _GFE_FunctionEOFExit=0 & Call :GetEOFrow %_GFE_BatchFile% %_GFE_FunctionName% _GFE_FunctionEOFExit
  142. if %_GFE_FunctionEOFExit% GTR 0 set /a _GFE_FunctionExit=%_GFE_FunctionEOFExit%
  143. if defined _GFE_Output set /a %_GFE_Output%=%_GFE_FunctionExit%
  144. Call :ClearVariablesByPrefix %_GetFunctionExit_prefix% _GetFunctionExit_prefix & exit /b %_GFE_FunctionExit%
  145.  
  146.  
  147. ::Usage Call :GetFunctionPreambleRow BatchFile FunctionNameOrRow optional OutputRow
  148. :GetFunctionPreambleRow
  149. Call :GetPreviousEmptyRow "%~1" "%~2" "%~3"
  150. exit /b %errorlevel%
  151.  
  152.  
  153. ::Usage Call :GetFunctionPostscriptRow BatchFile FunctionNameOrRow optional OutputRow
  154. :GetFunctionPostscriptRow
  155. Call :GetFunctionExit "%~1" "%~2" _GFPR_ExitRow
  156. Call :GetNextEmptyRow "%~1" "%_GFPR_ExitRow%" "%~3"
  157. set "_GFPR_ExitRow=" & exit /b %errorlevel%
  158.  
  159.  
  160. :: Usage Call :ClearVariablesByPrefix myPrefix
  161. :ClearVariablesByPrefix
  162. if "[%~1]" NEQ "[]" for /f "tokens=1 delims==" %%a in ('set "%~1" 2^>nul') do set %%a=
  163. if "[%~2]" NEQ "[]" shift & GoTo :ClearVariablesByPrefix
  164. GoTo :EOF
  165.  
  166.  
  167. ::Usage Call :GetFunctionName File LineNumber OutputValue
  168. :GetFunctionName
  169. for /F "usebackq eol= tokens=1,2 delims=(&:=+ " %%i in (`^(type %~1 ^| findstr /n /r /c:".*" ^| findstr /B /C:"%~2:" ^) 2^>nul`) do ( set "%~3=%%j" & exit /b 0 )
  170. REM proposed alternative for /F "tokens=2 delims=(&:=+ " %%i in ('%SystemRoot%\System32\findstr.exe /n "" "%~1" ^| %SystemRoot%\System32\findstr.exe /B /C:"%~2:"') do set "%~3=%%i" & exit /b 0
  171. exit /b 1
  172.  
  173.  
  174. ::Usage Call :GetBatchCore File optional OutputValue
  175. ::Returns core function final line number
  176. :GetBatchCore
  177. Call :GetLabelRow "%~1" End _GetBatchCore_EndRow
  178. Call :GetNextFunctionRow "%~1" %_GetBatchCore_EndRow% _GetBatchCore_FirstFunction
  179. Call :GetPreviousExitRow "%~1" %_GetBatchCore_FirstFunction% _GetBatchCore_FirstFunctionExit
  180. Call :GetNextEmptyRow "%~1" %_GetBatchCore_FirstFunctionExit% _GetBatchCore_CorePostscript
  181. if "[%~2]" NEQ "[]" ( set /a %~2.preamble=1 & set /a %~2.start=1 & set /a %~2.exit=%_GetBatchCore_FirstFunctionExit% & set /a %~2.postscript=%_GetBatchCore_CorePostscript% )
  182. set "_GetBatchCore_EndRow=" & set "_GetBatchCore_FirstFunction=" & set "_GetBatchCore_FirstFunctionExit=" & set "_GetBatchCore_CorePostscript=" & exit /b %_GetBatchCore_CorePostscript%
  183.  
  184.  
  185. ::Usage Call :GetNextExitRow BatchFile StartRow optional OutputRow
  186. :GetNextExitRow
  187. for /f delims^=:^ tokens^=1 %%a in ('%SystemRoot%\System32\findstr /N /I /C:"goto :EOF" /C:"exit /B" "%~1"') do ( if %%a GTR %~2 ( if "[%~3]" NEQ "[]" set "%~3=%%a" & exit /b %%a ) )
  188. exit /b 0
  189.  
  190.  
  191. :ListFunctions BatchFile optional OutputVariable BatchFile2 ... BatchFileN
  192. set "_ListFunctions_prefix=_LF"
  193. Call :IsFile "%~1" && set "_LF_InputFile=%~1" || ( set "_LF_Output=%~1" & if "[%~2]" NEQ "[]" ( shift & GoTo :ListFunctions ) else ( GoTo :ListFunctions-end ) )
  194. set "_LF_InputFile=%~1"
  195. :ListFunctions-args
  196. for /F "usebackq eol= tokens=2 delims=(&:=+ " %%a in (`^(type %_LF_InputFile% ^| findstr /n /r /c:"^:[^:]" ^) 2^>nul`) do ( Call :IsFunctionLabelExcluded %%a || call set "_LF_FunctionList=%%_LF_FunctionList%% %%a" )
  197. :ListFunctions-end
  198. if "[%~2]" NEQ "[]" ( shift & GoTo :ListFunctions )
  199. if defined _LF_Output ( set "%_LF_Output%=%_LF_FunctionList:~1%" ) else ( echo.%_LF_FunctionList:~1% )
  200. Call :ClearVariablesByPrefix %_ListFunctions_prefix% _ListFunctions_prefix & GoTo :EOF
  201.  
  202.  
  203. ::Usage Call :GetNextFunctionName BatchFile StartRow optional OutputRow
  204. ::Usage Call :GetNextFunctionRow BatchFile StartRow optional OutputRow
  205. :GetNextFunctionName
  206. set "_GNFR_ReturnName=true"
  207. :GetNextFunctionRow
  208. set "_GetNextFunctionRow_prefix=_GNFR"
  209. set "_GNFR_BatchFile=%~1"
  210. set "_GNFR_StartRow=%~2"
  211. set "_GNFR_Output=%~3"
  212. :GetNextFunctionRow-args
  213. for /f delims^=:^ tokens^=1 %%a in ('%SystemRoot%\System32\findstr /N "^:[^:]" "%_GNFR_BatchFile%"') do ( if %%a GTR %_GNFR_StartRow% ( set /a _GNFR_current=%%a & GoTo :GetNextFunctionRow-exit-loop ) )
  214. Call :countLines _GNFR_current "%_GNFR_BatchFile%" 2>nul
  215. set /a _GNFR_current-=1 & GoTo :GetNextFunctionRow-skip
  216. :GetNextFunctionRow-exit-loop
  217. Call :GetFunctionName "%~1" %_GNFR_current% _GNFR_current_FunctionName
  218. Call :IsFunctionLabelExcluded _GNFR_current_FunctionName && ( set /a _GNFR_StartRow=%_GNFR_current% & GoTo :GetNextFunctionRow-args )
  219. :GetNextFunctionRow-skip
  220. if "[%~3]" NEQ "[]" set "%~3=%_GNFR_current%"
  221. if "[%_GNFR_ReturnName%]" EQU "[true]" set "%~3=%_GNFR_current_FunctionName%"
  222. Call :ClearVariablesByPrefix %_GetNextFunctionRow_prefix% _GetNextFunctionRow_prefix & exit /b %_GNFR_current%
  223.  
  224.  
  225. ::Usage Call :GetPreviousExitRow BatchFile StartRow optional OutputRow
  226. :GetPreviousExitRow
  227. set "_GPER_previous="
  228. for /f delims^=:^ tokens^=1 %%a in ('%SystemRoot%\System32\findstr /N /I /C:"goto :EOF" /C:"exit /B" "%~1"') do ( ( if %%a LSS %~2 set /a _GPER_previous=%%a ) & if %%a GEQ %~2 ( GoTo :GetPreviousExitRow-exit-loop ) )
  229. :GetPreviousExitRow-exit-loop
  230. if "[%~3]" NEQ "[]" call set "%~3=%_GPER_previous%"
  231. set "_GPER_previous=" & exit /b %_GPER_previous%
  232.  
  233.  
  234. ::Usage Call :GetEOFrow BatchFile FunctionName optional OutputRow
  235. :GetEOFrow
  236. for /f delims^=:^ tokens^=1 %%a in ('%SystemRoot%\System32\findstr /N /I /C:"EndOf_%~2" "%~1"') do ( if "[%~3]" NEQ "[]" set "%~3=%%a" & exit /b %%a )
  237. exit /b 0
  238.  
  239.  
  240. ::Usage Call :countLines returnvariable filename
  241. ::counts the number of lines in a file
  242. :countLines result= "%file%"
  243. setLocal disableDelayedExpansion
  244. (set "lc=0" & call)
  245. for /f "delims=:" %%N in ('
  246. cmd /d /a /c type "%~2" ^^^& ^<nul set /p "=#" ^| (^
  247. 2^>nul findStr /n "^" ^&^& echo(^) ^| ^
  248. 2^>nul findStr /blv 1: ^| 2^>nul findStr /lnxc:" "
  249. ') do (set "lc=%%N" & call;) %= for /f =%
  250. endlocal & set "%1=%lc%"
  251. exit /b %errorLevel% %= countLines =%
  252. https://stackoverflow.com/a/49089494/6104460
  253.  
  254.  
  255. ::Usage Call :IsFunctionLabelExcluded FunctionLabel optional ExclusionList && IsExcluded || IsNotExcluded
  256. :IsFunctionLabelExcluded
  257. set "_IsFunctionLabelExcluded_prefix=_IFLE"
  258. set /a _IFLE_exit=1
  259. if defined %~1 call set _IFLE_input=%%%~1%%
  260. if not defined _IFLE_input set "_IFLE_input=%~1"
  261. set "_IFLE_input=%_IFLE_input:-= %"
  262. set "_IFLE_input=%_IFLE_input::= %"
  263. set "_IFLE_ExclusionList=%~2"
  264. 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"
  265. for %%a in (%_IFLE_input%) do set _IFLE_last_token=%%a
  266. REM set _IFLE
  267. for %%a in (%_IFLE_ExclusionList%) do if %%a EQU %_IFLE_last_token% ( set /a _IFLE_exit=0 & GoTo :IsFunctionLabelExcluded-end )
  268. if "[%_IFLE_input:~,6%]" EQU "[EndOf_]" ( set /a _IFLE_exit=0 & GoTo :IsFunctionLabelExcluded-end )
  269. :IsFunctionLabelExcluded-end
  270. Call :ClearVariablesByPrefix %_IsFunctionLabelExcluded_prefix% _IsFunctionLabelExcluded_prefix & exit /b %_IFLE_exit%
  271.  
  272.  
  273. ::Usage Call :AppendFileLineToFile inputfile outputfile 3 4 50-75 5 6 7 ... N
  274. :AppendFileLineToFile
  275. set "_AppendFileLineToFile_prefix=_AFLTF"
  276. set "_AFLTF_InputFile=%~1"
  277. set "_AFLTF_OutputFile=%~2"
  278. :AppendFileLineToFile-arg
  279. for /f "delims=- tokens=1,2" %%a in ("%~3") do ( set "_AFLTF_Start=%%a" & set "_AFLTF_Stop=%%b" )
  280. if not defined _AFLTF_Stop set /a _AFLTF_Stop=%_AFLTF_Start%
  281. Setlocal enabledelayedexpansion
  282. if %_AFLTF_Start% GTR 1 set /a "_AFLTF_skip=%_AFLTF_Start%-1"
  283. if %_AFLTF_Start% GTR 1 ( set "_AFLTF_skip=skip^=%_AFLTF_skip%^" ) else ( set "_AFLTF_skip=" )
  284. for /f %_AFLTF_skip% delims^=^ eol^= %%a in (' ^( type "%_AFLTF_InputFile%" ^| %SystemRoot%\System32\findstr /N /R /C:".*" ^) 2^>nul ') do (
  285. for /f "delims=:" %%f in ("%%a") do if %%f GTR %_AFLTF_Stop% GoTo :AppendFileLineToFile-end
  286. set _AFLTF_buffer=%%a
  287. if defined _AFLTF_buffer >>"%_AFLTF_OutputFile%" echo( set _AFLTF_buffer=%%a
  288. )
  289. endlocal
  290. :AppendFileLineToFile-end
  291. if "[%~4]" NEQ "[]" ( shift & GoTo :AppendFileLineToFile-arg )
  292. Call :ClearVariablesByPrefix %_AppendFileLineToFile_prefix% _AppendFileLineToFile_prefix & GoTo :EOF
  293.  
  294.  
  295. ::Usage Call :AppendFileLineToFile inputfile outputfile 3 4 50-75 5 6 7 ... N
  296. :AppendFileLineToFile
  297. set "_AppendFileLineToFile_prefix=_AFLTF"
  298. set "_AFLTF_InputFile=%~1"
  299. set "_AFLTF_OutputFile=%~2"
  300. :AppendFileLineToFile-arg
  301. for /f "delims=- tokens=1,2" %%a in ("%~3") do ( set "_AFLTF_Start=%%a" & set "_AFLTF_Stop=%%b" )
  302. if not defined _AFLTF_Stop set /a _AFLTF_Stop=%_AFLTF_Start%
  303. Setlocal enabledelayedexpansion
  304. if %_AFLTF_Start% GTR 1 set /a "_AFLTF_skip=%_AFLTF_Start%-1"
  305. if %_AFLTF_Start% GTR 1 ( set "_AFLTF_skip=skip^=%_AFLTF_skip%^" ) else ( set "_AFLTF_skip=" )
  306. for /f %_AFLTF_skip% delims^=^ eol^= %%a in (' ^( type "%_AFLTF_InputFile%" ^| %SystemRoot%\System32\findstr /N /R /C:".*" ^) 2^>nul ') do (
  307. for /f "delims=:" %%f in ("%%a") do if %%f GTR %_AFLTF_Stop% GoTo :AppendFileLineToFile-end
  308. set _AFLTF_buffer=%%a
  309. if defined _AFLTF_buffer >>"%_AFLTF_OutputFile%" echo( set _AFLTF_buffer=%%a
  310. )
  311. endlocal
  312. :AppendFileLineToFile-end
  313. if "[%~4]" NEQ "[]" ( shift & GoTo :AppendFileLineToFile-arg )
  314. Call :ClearVariablesByPrefix %_AppendFileLineToFile_prefix% _AppendFileLineToFile_prefix & GoTo :EOF
  315.  
  316.  
  317. ::Usage Call :GetPreviousEmptyRow BatchFile StartRow optional OutputRow
  318. :GetPreviousEmptyRow
  319. set "_GPEW_previous="
  320. for /f delims^=:^ tokens^=1 %%a in ('%SystemRoot%\System32\findstr /N "^$" "%~1"') do ( ( if %%a LSS %~2 set /a _GPEW_previous=%%a ) & if %%a GEQ %~2 ( GoTo :GetPreviousEmptyRow-exit-loop ) )
  321. exit /b 0
  322. :GetPreviousEmptyRow-exit-loop
  323. if "[%~3]" NEQ "[]" call set "%~3=%_GPEW_previous%"
  324. set "_GPEW_previous=" & exit /b %_GPEW_previous%
  325.  
  326.  
  327. ::Usage Call :GetNextEmptyRow BatchFile StartRow optional OutputRow
  328. :GetNextEmptyRow
  329. for /f delims^=:^ tokens^=1 %%a in ('%SystemRoot%\System32\findstr /N "^$" "%~1"' ) do ( if %%a GTR %~2 ( if "[%~3]" NEQ "[]" set "%~3=%%a" & exit /b %%a ) )
  330. Call :countLines _GetNextEmptyRow_lastrow "%~1"
  331. set /a _GetNextEmptyRow_lastrow+=1
  332. if "[%~3]" NEQ "[]" set "%~3=%_GetNextEmptyRow_lastrow%"
  333. exit /b %_GetNextEmptyRow_lastrow%
  334.  
  335.  
  336. :BFWFunctionSwitcher-text
  337. @echo off
  338.  
  339. :setup
  340.  
  341. 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"
  342.  
  343. :main
  344.  
  345. for %%a in ( %* ) do ( for %%b in ( /h /? -h -? help --help ) do ( if "[%%a]" EQU "[%%b]" ( Call :%~n0-help & exit /b 1 ) ) )
  346. for %%a in ( %* ) do ( if "[%%a]" EQU "[demo]" ( Call :%~n0-demo & exit /b 1 ) )
  347. if "[%~1]" EQU "[]" ( echo %~n0 needs at least one argument & exit /b 1 )
  348. REM if "[%~1]" EQU "[]" if "[%~2]" EQU "[]" ( echo %~n0 needs at least two argument & exit /b 1 )
  349. if "[%~n0]" EQU "[bfw]" ( Call :ShiftedArgumentCaller %* ) else ( Call :%~n0 %* )
  350.  
  351. :end
  352.  
  353. REM set "_IFLE_ExclusionList="
  354.  
  355. GoTo :EOF
  356. :EndOF_BFWFunctionSwitcher-text
  357.  
  358.  
Add Comment
Please, Sign In to add comment