Advertisement
Guest User

Untitled

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