Advertisement
Guest User

Untitled

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