Advertisement
Guest User

Untitled

a guest
Aug 31st, 2023
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 60.46 KB | None | 0 0
  1. @echo off
  2.  
  3. :main
  4. Call :FileToArrayToFile-DEMO
  5. REM call :ArrayToFile-DEMO
  6. REM call :CopyArrayAdv-DEMO
  7. REM call :EchoArray-DEMO
  8. REM call :CopyObject-DEMO
  9. REM call :SortArray-DEMO
  10. REM call :GetArrayIndex-DEMO
  11. REM call :CopyArray-DEMO
  12. REM Call :GetBatchFileStructure-DEMO
  13. REM Call :GetFunctionExits-DEMO
  14. REM call :GetEndOfFunction-DEMO
  15. REM call :GetLabels-DEMO
  16. REM call :GetEmptyLines-DEMO
  17. REM call :GetIndexArray-simple-DEMO
  18. REM Call :GetIndexArray-DEMO
  19. GoTo :EOF
  20.  
  21. :FileToArrayToFile-DEMO
  22.  
  23. del FileToArrayToFile-DEMO.txt 2>nul
  24.  
  25. echo FileToArrayToFile start SimpleFileToArray %time%
  26.  
  27. Call :SimpleFileToArray CreateRandomFile-DEMO.txt ArrayOfLines
  28.  
  29. echo FileToArrayToFile mid SimpleFileToArray %time%
  30.  
  31. Call :ArrayToFile ArrayOfLines FileToArrayToFile-DEMO.txt
  32.  
  33. echo FileToArrayToFile end SimpleFileToArray %time%
  34.  
  35. fc /n CreateRandomFile-DEMO.txt FileToArrayToFile-DEMO.txt
  36.  
  37. GoTo :EOF
  38.  
  39.  
  40.  
  41. :SortArray-DEMO
  42.  
  43. set mytestarray[1]=text1
  44. set mytestarray[3]=text3
  45. set mytestarray[4]=text4
  46. set mytestarray[6]=text6
  47. set mytestarray[12]=text12
  48. set mytestarray[28]=text28
  49. set mytestarray[2]=text2
  50.  
  51. Call :GetArrayIndex mytestarray myindexarray
  52. Call :SortArray myindexarray mysortedarray
  53. Call :EchoArray mysortedarray LINENUMBERS
  54.  
  55. GoTo :EOF
  56.  
  57. :GetArrayIndex-DEMO
  58.  
  59. set mytestarray[1]=text1
  60. set mytestarray[3]=text3
  61. set mytestarray[4]=text4
  62. set mytestarray[6]=text6
  63. set mytestarray[12]=text12
  64. set mytestarray[28]=text28
  65. set mytestarray[2]=text2
  66.  
  67. Call :GetArrayIndex mytestarray myindexarray
  68.  
  69. Call :EchoArray myindexarray LINENUMBERS
  70.  
  71. GoTo :EOF
  72.  
  73. ::Usage Call :GetArrayIndex InputArray IndexArray
  74. :GetArrayIndex
  75. set "_GetArrayIndex_output=%~2"
  76. call set "_GetArrayIndex_ubound=%%%~2.ubound%%"
  77. if "[%_GetArrayIndex_ubound%]" EQU "[]" set /a "_GetArrayIndex_ubound=-1"
  78. set /a "_GetArrayIndex_index=%_GetArrayIndex_ubound%"
  79. for /f "tokens=1 delims==" %%a in ('set %~1[ 2^>nul') do for /f "tokens=2 delims=[]" %%b in ('set %%a 2^>nul') do call set /a "_GetArrayIndex_index+=1" & call set "%_GetArrayIndex_output%[%%_GetArrayIndex_index%%]=%%b"
  80. set /a "%_GetArrayIndex_output%.ubound=%_GetArrayIndex_index%"
  81. GoTo :EOF
  82.  
  83. :: Usage Call :IsArrayDefinedBySet Variable OutputValue
  84. :IsArrayDefinedBySet
  85. set /a _IsArrayDefinedBySet.index=0
  86. for /f "tokens=1* delims=" %%a in ('set %~1[ 2^>^&1') do ( call set _IsArrayDefinedBySet[%%_IsArrayDefinedBySet.index%%]=%%a & call set /a _IsArrayDefinedBySet.index+=1 )
  87. if not "[%_IsArrayDefinedBySet[0]%]"=="[%_IsArrayDefinedBySet[0]:Environment variable=%]" (
  88. if not "[%_IsArrayDefinedBySet[0]%]"=="[%_IsArrayDefinedBySet[0]:not defined=%]" set "_IsArrayDefinedBySet.IsDefined=false" ) else ( set "_IsArrayDefinedBySet.IsDefined=true" )
  89. if not "[%~2]"=="[]" set "%~2=%_IsArrayDefinedBySet.IsDefined%"
  90. Call :ClearVariablesByPrefix _IsArrayDefinedBySet & if "[%_IsArrayDefinedBySet.IsDefined%]"=="[true]" ( exit /b 0 ) else ( exit /b 1 )
  91. GoTo :EOF
  92.  
  93. REM :GetArrayIndex
  94. REM create array containing all index from an array, as output by set, or sorted, works with sub array var.array[1].suffix.myarray[]
  95. REM GoTo :EOF
  96.  
  97. :: This does not handle copying or even the presence of any suffixes in the array
  98. ::Usage Call :SortArray InputArray optional SortedArray
  99. :SortArray
  100. set "_SortArray_input=%~1"
  101. set "_SortArray_output=%~2"
  102. if "[%_SortArray_output%]" EQU "[]" set "_SortArray_output=%_SortArray_input%"
  103. Call :CopyArray %_SortArray_input% _SortArray_buffer
  104. setlocal enabledelayedexpansion
  105. set _SortArray_localscope=true
  106. set /a "_SortArray_sorted.ubound=-1"
  107. :SortArray-loop
  108. set "_SortArray_current_index="
  109. set /a "_SortArray_smallest=2147483647"
  110. for /f "tokens=1,2,3 delims=[]=" %%a in ('set _SortArray_buffer[ 2^>^&1') do if %%c LSS !_SortArray_smallest! set /a "_SortArray_current_index=%%b" & set /a "_SortArray_smallest=%%c"
  111. if "[%_SortArray_smallest%]" EQU "[!_SortArray_sorted[%_SortArray_sorted.ubound%]!]" set "_SortArray_buffer[%_SortArray_current_index%]=" & set "_SortArray_current_index="
  112. if "[%_SortArray_current_index%]" NEQ "[]" set /a "_SortArray_sorted.ubound+=1"
  113. if "[%_SortArray_current_index%]" NEQ "[]" set /a "_SortArray_sorted[%_SortArray_sorted.ubound%]=%_SortArray_smallest%" & set "_SortArray_buffer[%_SortArray_current_index%]="
  114. Call :IsArrayDefinedBySet _SortArray_buffer && GoTo :SortArray-loop
  115. for /f "delims=" %%a in ('set _SortArray_sorted 2^>nul') do (
  116. endlocal
  117. set %%a
  118. )
  119. if defined _SortArray_localscope endlocal
  120. Call :CopyArray _SortArray_sorted %_SortArray_output%
  121. Call :CopyObject _SortArray_sorted %_SortArray_output%
  122. Call :ClearVariablesByPrefix _SortArray
  123. REM copy the array
  124. REM create sorted index array from the copy based on the value stored inside the array elements of the copy
  125. REM copy array element, in the order of the sorted index array to the specified destination
  126. REM sorting algorithm, using for(set) loop, find the element with the lowest value, copy it into the next element of the sorted index array then delete it from the buffer array
  127. REM sort an array, ordered by value content
  128. REM alphanumeric or numeric sort
  129. REM destructive or not
  130. REM for loop, find lowest value, copy ([] [].suffix or [].*), delete that value
  131. GoTo :EOF
  132.  
  133. :CompactArray
  134.  
  135. close up all gaps in an array's index numbers
  136.  
  137.  
  138. from lbound to ubound,when find an empty spot, remember that "next spot" then continue looking until you find a populated array, copy and delete [] [].suffix or [].*
  139.  
  140. GoTo :EOF
  141.  
  142. :lbound and :ubound method using GetArrayIndex
  143.  
  144.  
  145. :GetBatchFileStructure-DEMO
  146.  
  147. Call :GetLabels batchsample.bat ListOfLabels batch.rows
  148. Call :GetEmptyLines batchsample.bat ListOfEmptyLines batch.rows
  149. Call :GetFunctionExits batchsample.bat ListEOfFunctionsExits batch.rows
  150. Call :GetEndOfFunction batchsample.bat ListEndOfFunctions batch.rows
  151. REM Call :EchoArray batch.rows
  152.  
  153.  
  154. REM Create an array representing all functions, preamble, postscript, cumulative of all previous work
  155.  
  156. GoTo :EOF
  157.  
  158. :GetFunctionStructure
  159.  
  160. For specified function
  161. return preamble start and end line (not defined means no preamble)
  162. return function name including line number, start line to end line of function
  163. return function postscript , return start line and endline of post script
  164.  
  165. preamble and post script are all the lines containing text up until the first blank line, before the function start line and after the function end line
  166.  
  167. interpret preamble function cards (name version description dependencivies last updated etc... ?)
  168.  
  169. should be aware of function alias, overloaded functions
  170.  
  171. should it be aware of function input parameters ?
  172.  
  173. GoTo :EOF
  174.  
  175. :GetFunctionLabels-DEMO
  176.  
  177. Returns a cleaned list of all real functions, not the internal labels, not main functions, not broken functions without exits
  178.  
  179. GoTo :EOF
  180.  
  181. :GetFunctionCalls-DEMO
  182.  
  183. Find every function call
  184. extract the name of every called function label
  185. there can be more than one call :label per line, find all like EndOf_Function
  186. If possible, include awareness of the current function name
  187. It should be easy to ask a function name and return all function call dependencies
  188.  
  189.  
  190. GoTo :EOF
  191.  
  192. :GetFunctionExits-DEMO
  193.  
  194. Call :GetFunctionExits batchsample.bat ListEOfFunctionsExits
  195.  
  196. Call :EchoArray ListEOfFunctionsExits
  197.  
  198. GoTo :EOF
  199.  
  200. :GetEndOfFunction-DEMO
  201.  
  202. Call :GetEndOfFunction batchsample.bat ListEndOfFunctions
  203. Call :EchoArray ListEndOfFunctions
  204. Call :EchoArray ListEndOfFunctions .name
  205. set ListEndOfFunctions
  206.  
  207. REM Call :ClearVariablesByPrefix ListEndOfFunctions
  208.  
  209.  
  210. GoTo :EOF
  211.  
  212. :GetLabels-DEMO
  213.  
  214. Call :GetLabels batchsample.bat ListOfLabels
  215. echo.& echo Print all line numbers with a label
  216. Call :EchoArray ListOfLabels
  217. echo.& echo Print all label names
  218. Call :EchoArray ListOfLabels .name
  219. echo.& echo showing actual values
  220. set ListOfLabels
  221.  
  222. REM Call :ClearVariablesByPrefix ListOfLabels
  223.  
  224. GoTo :EOF
  225.  
  226. :GetEmptyLines-DEMO
  227.  
  228. Call :GetEmptyLines batchsample.bat ListOfEmptyLines
  229. echo.& echo List empty lines
  230. Call :EchoArray ListOfEmptyLines
  231. echo.& echo List empty lines, show echoarray to show line numbers (printed number of lines)
  232. Call :EchoArray ListOfEmptyLines LINENUMBERS
  233. echo.& echo List empty lines, show echoarray to show name of printed variable
  234. Call :EchoArray ListOfEmptyLines SHOWVARNAME
  235. echo.& echo List empty lines, show echoarray to show name of printed variable and printed number of lines
  236. Call :EchoArray ListOfEmptyLines SHOWVARNAME LINENUMBERS
  237. echo.& echo List empty lines, show echoarray to print values in vertical direction (omit linefeed)
  238. Call :EchoArray ListOfEmptyLines VERTICALMODE
  239. echo.&echo.& echo List empty lines, show echoarray to print values in vertical direction (omit linefeed) and include number of lines
  240. Call :EchoArray ListOfEmptyLines VERTICALMODE LINENUMBERS
  241. echo.&echo.& echo List empty lines, show echoarray to print ' all dressed mode"
  242. Call :EchoArray ListOfEmptyLines VERTICALMODE SHOWVARNAME LINENUMBERS
  243. REM Call :ClearVariablesByPrefix ListOfEmptyLines
  244.  
  245.  
  246. echo.& echo repeat previous exercise but with range "1-3" "20,30-33,30" "99" "3-1" mytestindexarray
  247.  
  248. set mytestindexarray[3]=5
  249. set mytestindexarray[4]=6
  250. set mytestindexarray[5]=5
  251. set mytestindexarray.lbound=3
  252. set mytestindexarray.ubound=5
  253.  
  254. Call :GetEmptyLines batchsample.bat ListOfEmptyLines
  255. echo.& echo List empty lines with range limit ("1-3" "20,30-33,30" "99" "3-1" mytestindexarray)
  256. Call :EchoArray ListOfEmptyLines "1-3" "20,30-33,30" "99" "3-1" mytestindexarray
  257. echo.& echo List empty lines, show echoarray to show line numbers (printed number of lines) with range limit ("1-3" "20,30-33,30" "99" "3-1" mytestindexarray)
  258. Call :EchoArray ListOfEmptyLines LINENUMBERS "1-3" "20,30-33,30" "99" "3-1" mytestindexarray
  259. echo.& echo List empty lines, show echoarray to show name of printed variable with range limit ("1-3" "20,30-33,30" "99" "3-1" mytestindexarray)
  260. Call :EchoArray ListOfEmptyLines SHOWVARNAME "1-3" "20,30-33,30" "99" "3-1" mytestindexarray
  261. echo.& echo List empty lines, show echoarray to show name of printed variable and printed number of lines with range limit ("1-3" "20,30-33,30" "99" "3-1" mytestindexarray)
  262. Call :EchoArray ListOfEmptyLines SHOWVARNAME LINENUMBERS "1-3" "20,30-33,30" "99" "3-1" mytestindexarray
  263. echo.& echo List empty lines, show echoarray to print values in vertical direction (omit linefeed) with range limit ("1-3" "20,30-33,30" "99" "3-1" mytestindexarray)
  264. Call :EchoArray ListOfEmptyLines VERTICALMODE "1-3" "20,30-33,30" "99" "3-1" mytestindexarray
  265. echo.&echo.& echo List empty lines, show echoarray to print values in vertical direction (omit linefeed) and include number of lines with range limit ("1-3" "20,30-33,30" "99" "3-1" mytestindexarray)
  266. Call :EchoArray ListOfEmptyLines VERTICALMODE LINENUMBERS "1-3" "20,30-33,30" "99" "3-1" mytestindexarray
  267. echo.&echo.& echo List empty lines, show echoarray to print ' all dressed mode" with range limit ("1-3" "20,30-33,30" "99" "3-1" mytestindexarray)
  268. Call :EchoArray ListOfEmptyLines VERTICALMODE SHOWVARNAME LINENUMBERS "1-3" "20,30-33,30" "99" "3-1" mytestindexarray
  269. Call :ClearVariablesByPrefix ListOfEmptyLines
  270.  
  271. GoTo :EOF
  272.  
  273. :CopyArrayAdv-DEMO
  274. set mytestarray[-11]=text-11
  275. set mytestarray[-10]=text-10
  276. set mytestarray[-9]=text-9
  277. set mytestarray[-8]=text-8
  278. set mytestarray[-7]=text-7
  279. set mytestarray[-6]=text-6
  280. set mytestarray[-5]=text-5
  281. set mytestarray[-4]=text-4
  282. set mytestarray[-3]=text-3
  283. set mytestarray[-2]=text-2
  284. set mytestarray[-1]=text-1
  285. set mytestarray[0]=text0
  286. set mytestarray[1]=text1
  287. set mytestarray[2]=text2
  288. set mytestarray[3]=text3
  289. set mytestarray[4]=text4
  290. set mytestarray[5]=text5
  291. set mytestarray[6]=text6
  292. set mytestarray[7]=text7
  293. set mytestarray[8]=text8
  294. set mytestarray[9]=text9
  295. set mytestarray[10]=text10
  296. set mytestarray[11]=text11
  297.  
  298. echo.&echo contents of mytestarray
  299. set mytestarray
  300.  
  301. echo.&echo copyarray mytestarray myoutputarray 3-6
  302. Call :CopyArrayAdv mytestarray myoutputarray 3-6
  303. set myoutputarray & Call :ClearVariablesByPrefix myoutputarray
  304. echo.&echo copyarray mytestarray myoutputarray 6-3
  305. Call :CopyArrayAdv mytestarray myoutputarray 6-3
  306. set myoutputarray & Call :ClearVariablesByPrefix myoutputarray
  307. echo.&echo copyarray mytestarray myoutputarray 1,3,5
  308. Call :CopyArrayAdv mytestarray myoutputarray 1,3,5
  309. set myoutputarray & Call :ClearVariablesByPrefix myoutputarray
  310. echo.&echo copyarray mytestarray myoutputarray 1,3,5-7
  311. Call :CopyArrayAdv mytestarray myoutputarray 1,3,5-7
  312. set myoutputarray & Call :ClearVariablesByPrefix myoutputarray
  313. echo.&echo copyarray mytestarray myoutputarray 1-3,10,9,5-7
  314. Call :CopyArrayAdv mytestarray myoutputarray 1-3,10,9,5-7
  315. set myoutputarray & Call :ClearVariablesByPrefix myoutputarray
  316. echo.&echo copyarray mytestarray myoutputarray 1-2-2-5,3,2,1,3-1-3,9
  317. Call :CopyArrayAdv mytestarray myoutputarray 1-2-2-5,3,2,1,3-1-3,9
  318. set myoutputarray & Call :ClearVariablesByPrefix myoutputarray
  319. echo.&echo copyarray mytestarray myoutputarray VERTICALMODE 1-2-2-5,3,2,1,3-1-3,9
  320. Call :CopyArrayAdv mytestarray myoutputarray VERTICALMODE 1-2-2-5,3,2,1,3-1-3,9
  321. set myoutputarray & Call :ClearVariablesByPrefix myoutputarray
  322. GoTo :EOF
  323.  
  324.  
  325. :EchoArray-DEMO
  326. set mytestarray[-11]=text-11
  327. set mytestarray[-10]=text-10
  328. set mytestarray[-9]=text-9
  329. set mytestarray[-8]=text-8
  330. set mytestarray[-7]=text-7
  331. set mytestarray[-6]=text-6
  332. set mytestarray[-5]=text-5
  333. set mytestarray[-4]=text-4
  334. set mytestarray[-3]=text-3
  335. set mytestarray[-2]=text-2
  336. set mytestarray[-1]=text-1
  337. set mytestarray[0]=text0
  338. set mytestarray[1]=text1
  339. set mytestarray[2]=text2
  340. set mytestarray[3]=text3
  341. set mytestarray[4]=text4
  342. set mytestarray[5]=text5
  343. set mytestarray[6]=text6
  344. set mytestarray[7]=text7
  345. set mytestarray[8]=text8
  346. set mytestarray[9]=text9
  347. set mytestarray[10]=text10
  348. set mytestarray[11]=text11
  349.  
  350. echo.&echo contents of mytestarray
  351. set mytestarray
  352.  
  353. echo.&echo echo mytestarray 3-6
  354. Call :EchoArray mytestarray 3-6
  355. echo.&echo echo mytestarray 6-3
  356. Call :EchoArray mytestarray 6-3
  357. echo.&echo echo mytestarray 1,3,5
  358. Call :EchoArray mytestarray 1,3,5
  359. echo.&echo echo mytestarray 1,3,5-7
  360. Call :EchoArray mytestarray 1,3,5-7
  361. echo.&echo echo mytestarray 1-3,10,9,5-7
  362. Call :EchoArray mytestarray 1-3,10,9,5-7
  363. echo.&echo echo mytestarray 1-2-2-5,3,2,1,3-1-3,9
  364. Call :EchoArray mytestarray 1-2-2-5,3,2,1,3-1-3,9
  365. echo.&echo echo mytestarray VERTICALMODE 1-2-2-5,3,2,1,3-1-3,9
  366. Call :EchoArray mytestarray VERTICALMODE 1-2-2-5,3,2,1,3-1-3,9
  367. GoTo :EOF
  368.  
  369. :ArrayToFile-DEMO
  370. set mytestarray[-11]=text-11
  371. set mytestarray[-10]=text-10
  372. set mytestarray[-9]=text-9
  373. set mytestarray[-8]=text-8
  374. set mytestarray[-7]=text-7
  375. set mytestarray[-6]=text-6
  376. set mytestarray[-5]=text-5
  377. set mytestarray[-4]=text-4
  378. set mytestarray[-3]=text-3
  379. set mytestarray[-2]=text-2
  380. set mytestarray[-1]=text-1
  381. set mytestarray[0]=text0
  382. set mytestarray[1]=text1
  383. set mytestarray[2]=text2
  384. set mytestarray[3]=text3
  385. set mytestarray[4]=text4
  386. set mytestarray[5]=text5
  387. set mytestarray[6]=text6
  388. set mytestarray[7]=text7
  389. set mytestarray[8]=text8
  390. set mytestarray[9]=text9
  391. set mytestarray[10]=text10
  392. set mytestarray[11]=text11
  393.  
  394. echo.&echo contents of mytestarray
  395. set mytestarray
  396.  
  397. set "mytestfile=ArrayToFile-DEMO.txt"
  398.  
  399. echo.&echo echo mytestarray "%mytestfile%" 3-6
  400. Call :ArrayToFile mytestarray "%mytestfile%" 3-6
  401. echo.&echo echo mytestarray "%mytestfile%" 6-3
  402. Call :ArrayToFile mytestarray "%mytestfile%" 6-3
  403. echo.&echo echo mytestarray "%mytestfile%" 1,3,5
  404. Call :ArrayToFile mytestarray "%mytestfile%" 1,3,5
  405. echo.&echo echo mytestarray "%mytestfile%" 1,3,5-7
  406. Call :ArrayToFile mytestarray "%mytestfile%" 1,3,5-7
  407. echo.&echo echo mytestarray "%mytestfile%" 1-3,10,9,5-7
  408. Call :ArrayToFile mytestarray "%mytestfile%" 1-3,10,9,5-7
  409. echo.&echo echo mytestarray "%mytestfile%" 1-2-2-5,3,2,1,3-1-3,9
  410. Call :ArrayToFile mytestarray "%mytestfile%" 1-2-2-5,3,2,1,3-1-3,9
  411. echo.&echo echo mytestarray "%mytestfile%" VERTICALMODE 1-2-2-5,3,2,1,3-1-3,9
  412. Call :ArrayToFile mytestarray "%mytestfile%" VERTICALMODE 1-2-2-5,3,2,1,3-1-3,9
  413.  
  414. echo results of %ArrayToFile%
  415. type %ArrayToFile%
  416.  
  417. GoTo :EOF
  418.  
  419. :GetIndexArray-simple-DEMO
  420.  
  421. echo.&echo test1
  422. Call :GetIndexArray __GIADEMO_IndexArray "12"
  423. Call :EchoArray __GIADEMO_IndexArray & Call :ClearVariablesByPrefix __GIADEMO
  424.  
  425. echo.&echo test2
  426. Call :GetIndexArray __GIADEMO_IndexArray "12-18"
  427. Call :EchoArray __GIADEMO_IndexArray & Call :ClearVariablesByPrefix __GIADEMO
  428.  
  429. echo.&echo test3
  430. Call :GetIndexArray __GIADEMO_IndexArray "18-12"
  431. Call :EchoArray __GIADEMO_IndexArray & Call :ClearVariablesByPrefix __GIADEMO
  432.  
  433. echo.&echo test4
  434. Call :GetIndexArray __GIADEMO_IndexArray "6,18-12,7"
  435. Call :EchoArray __GIADEMO_IndexArray & Call :ClearVariablesByPrefix __GIADEMO
  436.  
  437. echo.&echo test5
  438. Call :GetIndexArray __GIADEMO_IndexArray "6,5-8,7"
  439. Call :EchoArray __GIADEMO_IndexArray & Call :ClearVariablesByPrefix __GIADEMO
  440.  
  441. echo.&echo test6
  442. Call :GetIndexArray __GIADEMO_IndexArray "6,7,8,9" "1,2,3,4" "99,98-94,93" "123098,124187,12098124"
  443. Call :EchoArray __GIADEMO_IndexArray & Call :ClearVariablesByPrefix __GIADEMO
  444.  
  445.  
  446. echo.&echo test7
  447. set __GIADEMO[0]=6,7
  448. set __GIADEMO[1]=8
  449. set __GIADEMO[2]=9-11
  450. set __GIADEMO[3]=12498,12875,2,1-0
  451. set __GIADEMO.ubound=3
  452.  
  453. Call :GetIndexArray __GIADEMO_IndexArray "6,7,8,9" __GIADEMO "1,2,3,4"
  454. Call :EchoArray __GIADEMO_IndexArray & Call :ClearVariablesByPrefix __GIADEMO
  455.  
  456. echo.&echo test8
  457. Call :GetIndexArray __GIADEMO_IndexArray "1,2,3"
  458. Call :GetIndexArray __GIADEMO_IndexArray "4-6" "7"
  459. Call :GetIndexArray __GIADEMO_IndexArray "8" "9-10" "00,11-14-15-15-15-15-20,39" "40"
  460. Call :EchoArray __GIADEMO_IndexArray & Call :ClearVariablesByPrefix __GIADEMO
  461.  
  462. GoTo :EOF
  463.  
  464. :GetIndexArray-DEMO
  465.  
  466. Call :ClearVariablesByPrefix _GIA __GIADEMO
  467. GoTo :GetIndexArray-DEMO-skip
  468. echo.
  469. set "__GIADEMO_range1="
  470. set "__GIADEMO_range2="
  471. set "__GIADEMO_range3="
  472. set "__GIADEMO_range4="
  473. echo GetIndexArray testing ranges "%__GIADEMO_range1%" "%__GIADEMO_range2%" "%__GIADEMO_range3%" "%__GIADEMO_range4%"
  474. Call :GetIndexArray __GIADEMO_IndexArray "%__GIADEMO_range1%" "%__GIADEMO_range2%" "%__GIADEMO_range3%" "%__GIADEMO_range4%"
  475. REM set __GIADEMO_IndexArray 2>nul
  476. Call :EchoArray __GIADEMO_IndexArray
  477. Call :ClearVariablesByPrefix __GIADEMO
  478.  
  479. :GetIndexArray-DEMO-skip
  480.  
  481. echo.
  482. set "__GIADEMO_range1=12"
  483. set "__GIADEMO_range2="
  484. set "__GIADEMO_range3="
  485. set "__GIADEMO_range4="
  486. echo GetIndexArray testing ranges "%__GIADEMO_range1%" "%__GIADEMO_range2%" "%__GIADEMO_range3%" "%__GIADEMO_range4%"
  487. Call :GetIndexArray __GIADEMO_IndexArray "%__GIADEMO_range1%" "%__GIADEMO_range2%" "%__GIADEMO_range3%" "%__GIADEMO_range4%"
  488. REM set __GIADEMO_IndexArray 2>nul
  489. Call :EchoArray __GIADEMO_IndexArray
  490. Call :ClearVariablesByPrefix __GIADEMO
  491.  
  492. echo.
  493. set "__GIADEMO_range1=12,28"
  494. set "__GIADEMO_range2="
  495. set "__GIADEMO_range3="
  496. set "__GIADEMO_range4="
  497. echo GetIndexArray testing ranges "%__GIADEMO_range1%" "%__GIADEMO_range2%" "%__GIADEMO_range3%" "%__GIADEMO_range4%"
  498. Call :GetIndexArray __GIADEMO_IndexArray "%__GIADEMO_range1%" "%__GIADEMO_range2%" "%__GIADEMO_range3%" "%__GIADEMO_range4%"
  499. REM set __GIADEMO_IndexArray 2>nul
  500. Call :EchoArray __GIADEMO_IndexArray
  501. Call :ClearVariablesByPrefix __GIADEMO
  502.  
  503. echo.
  504. set "__GIADEMO_range1=12,28"
  505. set "__GIADEMO_range2=32"
  506. set "__GIADEMO_range3="
  507. set "__GIADEMO_range4="
  508. echo GetIndexArray testing ranges "%__GIADEMO_range1%" "%__GIADEMO_range2%" "%__GIADEMO_range3%" "%__GIADEMO_range4%"
  509. Call :GetIndexArray __GIADEMO_IndexArray "%__GIADEMO_range1%" "%__GIADEMO_range2%" "%__GIADEMO_range3%" "%__GIADEMO_range4%"
  510. REM set __GIADEMO_IndexArray 2>nul
  511. Call :EchoArray __GIADEMO_IndexArray
  512. Call :ClearVariablesByPrefix __GIADEMO
  513.  
  514. echo.
  515. set "__GIADEMO_range1=12-18"
  516. set "__GIADEMO_range2="
  517. set "__GIADEMO_range3="
  518. set "__GIADEMO_range4="
  519. echo GetIndexArray testing ranges "%__GIADEMO_range1%" "%__GIADEMO_range2%" "%__GIADEMO_range3%" "%__GIADEMO_range4%"
  520. Call :GetIndexArray __GIADEMO_IndexArray "%__GIADEMO_range1%" "%__GIADEMO_range2%" "%__GIADEMO_range3%" "%__GIADEMO_range4%"
  521. REM set __GIADEMO_IndexArray 2>nul
  522. Call :EchoArray __GIADEMO_IndexArray
  523. Call :ClearVariablesByPrefix __GIADEMO
  524.  
  525. echo.
  526. set "__GIADEMO_range1=12-18"
  527. set "__GIADEMO_range2[7]=68"
  528. set "__GIADEMO_range2[8]=69"
  529. set "__GIADEMO_range2[9]=71"
  530. set "__GIADEMO_range2.lbound=7"
  531. set "__GIADEMO_range2.ubound=9"
  532. set "__GIADEMO_range3="
  533. set "__GIADEMO_range4="
  534. echo GetIndexArray testing ranges "%__GIADEMO_range1%" "__GIADEMO_range2" "%__GIADEMO_range3%" "%__GIADEMO_range4%"
  535. Call :GetIndexArray __GIADEMO_IndexArray "%__GIADEMO_range1%" "__GIADEMO_range2" "%__GIADEMO_range3%" "%__GIADEMO_range4%"
  536. REM set __GIADEMO_IndexArray 2>nul
  537. Call :EchoArray __GIADEMO_IndexArray
  538. Call :ClearVariablesByPrefix __GIADEMO
  539.  
  540. echo.
  541. set "__GIADEMO_range1=12-18"
  542. set "__GIADEMO_range2[7]=68"
  543. set "__GIADEMO_range2[8]=69"
  544. set "__GIADEMO_range2[9]=71"
  545. set "__GIADEMO_range2.lbound=7"
  546. set "__GIADEMO_range2.ubound=9"
  547. set "__GIADEMO_range3=100-105-99,299"
  548. set "__GIADEMO_range4="
  549. echo GetIndexArray testing ranges "%__GIADEMO_range1%" "__GIADEMO_range2" "%__GIADEMO_range3%" "%__GIADEMO_range4%"
  550. Call :GetIndexArray __GIADEMO_IndexArray "%__GIADEMO_range1%" "__GIADEMO_range2" "%__GIADEMO_range3%" "%__GIADEMO_range4%"
  551. REM set __GIADEMO_IndexArray 2>nul
  552. Call :EchoArray __GIADEMO_IndexArray
  553. Call :ClearVariablesByPrefix __GIADEMO
  554.  
  555. echo.
  556. set "__GIADEMO_range1=12-18"
  557. set "__GIADEMO_range2[7]=68"
  558. set "__GIADEMO_range2[8]=69"
  559. set "__GIADEMO_range2[9]=71"
  560. set "__GIADEMO_range2.lbound=7"
  561. set "__GIADEMO_range2.ubound=9"
  562. set "__GIADEMO_range3=100-105-105-105-99,299"
  563. set "__GIADEMO_range4[0]=1"
  564. set "__GIADEMO_range4[1]=3"
  565. set "__GIADEMO_range4[2]=5-7"
  566. set "__GIADEMO_range4[3]=11,13-15,8,7,6"
  567. set "__GIADEMO_range4.ubound=3"
  568. echo GetIndexArray testing ranges "%__GIADEMO_range1%" "__GIADEMO_range2" "%__GIADEMO_range3%" "__GIADEMO_range4"
  569. Call :GetIndexArray __GIADEMO_IndexArray "%__GIADEMO_range1%" "__GIADEMO_range2" "%__GIADEMO_range3%" "__GIADEMO_range4"
  570. REM set __GIADEMO_IndexArray 2>nul
  571. Call :EchoArray __GIADEMO_IndexArray
  572.  
  573. echo.
  574. echo mirroring previous results through :GetIndexArray a second time
  575. Call :GetIndexArray __GIADEMO_MirrorArray __GIADEMO_IndexArray
  576. Call :EchoArray __GIADEMO_MirrorArray
  577.  
  578. echo.
  579. echo Trying EchoArray IndexList Feature
  580. Call :EchoArray __GIADEMO_MirrorArray "25-28,36-35,29,34,30,0-1,31,2,32,3,33,4-6,7-9,23-16,10-15,24"
  581. REM set __GIADEMO_MirrorArray
  582. Call :ClearVariablesByPrefix __GIADEMO
  583.  
  584. GoTo :EOF
  585.  
  586. :SimpleFileToArray-DEMO
  587. Call :ClearVariablesByPrefix _FTA LinesArray
  588. echo start SimpleFileToArray %time%
  589. Call :SimpleFileToArray LinesArray batchsample.bat
  590. echo end SimpleFileToArray %time%
  591. GoTo :EOF
  592.  
  593.  
  594. REM :SimpleFileToArray OutputArray list of rows (2,3,6,34-59,4, start-5, start-end, 37-end) Filename
  595. REM :SimpleFileToArray OutputArray array containing list of rows Filename
  596.  
  597. REM :ArrayToFile OutputFile list of rows (variable or array)
  598.  
  599. ::Usage Call :SimpleFileToArray Filename OutputArray
  600. :SimpleFileToArray
  601. set /a "%~2.lbound=1"
  602. for /f delims^=^ eol^= %%a in ('%SystemRoot%\System32\findstr.exe /N "^" "%~1"') do (
  603. for /f "tokens=1,2* delims=:" %%f in ("%%a") do set /a "%~2.ubound=%%f" & set %~2[%%f]=%%a
  604. )
  605. set /a "_SFTA_index=1"
  606. call set /a "_SFTA_ubound=%%%~2.ubound%%"
  607. :SimpleFileToArray-loop
  608. Setlocal enabledelayedexpansion
  609. set _SFTA_localscope=true
  610. set %~2[%_SFTA_index%]=!%~2[%_SFTA_index%]:*:=!
  611. for /f "delims=" %%a in ('set %~2[%_SFTA_index%] 2^>nul') do (
  612. endlocal
  613. set %%a
  614. )
  615. if defined _SFTA_localscope endlocal & set %~2[%_SFTA_index%]=
  616. set /a "_SFTA_index+=1"
  617. if %_SFTA_index% LEQ %_SFTA_ubound% GoTo :SimpleFileToArray-loop
  618. GoTo :EOF
  619.  
  620. ::Usage Call :SimpleArrayToFile
  621. :SimpleArrayToFile
  622. call set "_SATF_lbound=%%
  623. find input array lbound
  624. from lbound to ubound
  625. echo array element to output file
  626. GoTo :EOF
  627.  
  628. REM finished ?
  629. ::Usage Call :GetIndexArray OutputIndexArray ListOfIndex1 ListOfIndex2 ... ListOfIndexN
  630. ::Lists of index are appended to the OutputIndexArray, Lists of index can contain
  631. ::single elements "18"
  632. ::comma or space separated elements "10,14,23" "10 14 23"
  633. ::single ranges "2-9"
  634. ::multiple ranges "45-47,48-94" "45-47 48-94"
  635. ::ranges can be in descending order "33-66 66-33"
  636. ::ranges can includes more than two end stops "33-67-66-99"
  637. ::or a mix of all the above
  638. ::not implemented keywords like start middle quarter third twothird threequarter "start-45,middle-end,third-twothird,start-end,1-end"
  639. ::not implemented percentages 10% 20% 33% 100% "10%-20%,0%-100%,start-100%"
  640. ::not implemented features would require knowing the starting and ending index of the reference array
  641. :GetIndexArray
  642. set "_GetIndexArray_prefix=_GIA"
  643. set "_GIA_output=%~1"
  644. if "[%_GIA_output%]" EQU "[]" GoTo :EOF
  645. if "[%_GIA_output%]" NEQ "[%_GIA_output:[]=%]" set "_GIA_output_suffix=%_GIA_output:*]=%" & set "_GIA_output=%_GIA_output:*[=%"
  646. call set "_GIA_output_lbound=%%%~1.lbound%%"
  647. call set "_GIA_output_ubound=%%%~1.ubound%%"
  648. if "[%_GIA_output_lbound%]" EQU "[]" set /a "_GIA_output_lbound=0"
  649. if "[%_GIA_output_ubound%]" EQU "[]" set /a "_GIA_output_ubound=%_GIA_output_lbound%-1"
  650. shift
  651. :GetIndexArray-arguments
  652. if "[%~1]" EQU "[]" GoTo :EOF
  653. Call :ClearVariablesByPrefix _GIA_current_list
  654. set "_GIA_current_list=%~1"
  655. set /a "_GIA_current_list_index=0"
  656. for /f %%a in ('set %_GIA_current_list%[ 2^>nul') do GoTo :GetIndexArray-isarray-arguments
  657. for %%a in (%_GIA_current_list:,= %) do ( call set "_GIA_current_list[%%_GIA_current_list_index%%]=%%a" & call set /a "_GIA_current_list_index+=1" )
  658. set /a "_GIA_current_list_ubound=%_GIA_current_list_index%-1" & set /a "_GIA_current_list_index=0"
  659. REM set _GIA_current_list
  660. GoTo :GetIndexArray-loop
  661. :GetIndexArray-isarray-arguments
  662. call set /a "_GIA_current_list_array_index=%%%_GIA_current_list%.lbound%%" 2>nul
  663. if not defined _GIA_current_list_array_index set /a "_GIA_current_list_array_index=0"
  664. call set /a "_GIA_current_list_array_ubound=%%%_GIA_current_list%.ubound%%" 2>nul
  665. :GetIndexArray-isarray-arguments-loop
  666. call set _GIA_current_list_array_element=%%%_GIA_current_list%[%_GIA_current_list_array_index%]%%
  667. for %%a in (%_GIA_current_list_array_element:,= %) do call set "_GIA_current_list[%%_GIA_current_list_index%%]=%%a" & call set /a "_GIA_current_list_index+=1"
  668. set /a "_GIA_current_list_array_index+=1"
  669. if %_GIA_current_list_array_index% LEQ %_GIA_current_list_array_ubound% GoTo :GetIndexArray-isarray-arguments-loop
  670. set /a "_GIA_current_list_ubound=%_GIA_current_list_index%-1" & set /a "_GIA_current_list_index=0"
  671. :GetIndexArray-loop
  672. REM set _GIA_current_list
  673. call set "_GIA_current_list_element=%%_GIA_current_list[%_GIA_current_list_index%]%%
  674. if "[%_GIA_current_list_element%]" EQU "[%_GIA_current_list_element:-=%]" GoTo :GetIndexArray-range-skip
  675. set /a "_GIA_current_list_element_index=0"
  676. REM echo for %%a in (%_GIA_current_list_element:-= %)
  677. for %%a in (%_GIA_current_list_element:-= %) do ( call set "_GIA_current_list_element[%%_GIA_current_list_element_index%%]=%%a" & call set /a "_GIA_current_list_element_index+=1" )
  678. REM set _GIA_current_list_element
  679. set /a "_GIA_current_list_element_ubound=%_GIA_current_list_element_index%-1" & set /a "_GIA_current_list_element_index=0"
  680. call set /a "_GIA_current_list_element_start=%%_GIA_current_list_element[%_GIA_current_list_element_index%]%%
  681. :GetIndexArray-range-loop
  682. call set /a "_GIA_current_list_element_end=%%_GIA_current_list_element[%_GIA_current_list_element_index%]%%
  683. if %_GIA_current_list_element_start% EQU %_GIA_current_list_element_end% ( call set /a "_GIA_output_ubound+=1" & call set "%_GIA_output%[%%_GIA_output_ubound%%]=%_GIA_current_list_element_start%" & GoTo :GetIndexArray-range-next)
  684. REM if %_GIA_current_list_element_start% EQU %_GIA_current_list_element_end% echo TEST II %_GIA_current_list_element_start% II& GoTo :GetIndexArray-range-next
  685. if %_GIA_current_list_element_start% GTR %_GIA_current_list_element_end% ( set "_GIA_current_list_element_direction=-" ) else ( set "_GIA_current_list_element_direction=+" )
  686. set /a "_GIA_current_list_element_start%_GIA_current_list_element_direction%=1"
  687. REM for /l %%a in (%_GIA_current_list_element_start%,%_GIA_current_list_element_direction%1,%_GIA_current_list_element_end%) do ( echo TEST II %%a II )
  688. for /l %%a in (%_GIA_current_list_element_start%,%_GIA_current_list_element_direction%1,%_GIA_current_list_element_end%) do ( call set /a "_GIA_output_ubound+=1" & call set "%_GIA_output%[%%_GIA_output_ubound%%]=%%a" )
  689. :GetIndexArray-range-next
  690. set /a "_GIA_current_list_element_start=%_GIA_current_list_element_end%"
  691. set /a "_GIA_current_list_element_index+=1"
  692. if %_GIA_current_list_element_index% LEQ %_GIA_current_list_element_ubound% GoTo :GetIndexArray-range-loop
  693. :GetIndexArray-range-skip
  694. REM if "[%_GIA_current_list_element%]" EQU "[%_GIA_current_list_element:-=%]" echo TEST JJ %_GIA_current_list_element% JJ
  695. if "[%_GIA_current_list_element%]" EQU "[%_GIA_current_list_element:-=%]" ( call set /a "_GIA_output_ubound+=1" & call set "%_GIA_output%[%%_GIA_output_ubound%%]=%_GIA_current_list_element%" )
  696. :GetIndexArray-loop-end
  697. Call :ClearVariablesByPrefix _GIA_current_list_element
  698. set /a "_GIA_current_list_index+=1"
  699. if %_GIA_current_list_index% LEQ %_GIA_current_list_ubound% GoTo :GetIndexArray-loop
  700. shift
  701. if "[%~1]" NEQ "[]" GoTo :GetIndexArray-arguments
  702. set /a "%_GIA_output%.ubound=%_GIA_output_ubound%"
  703. Call :ClearVariablesByPrefix %_GetIndexArray_prefix% _GetIndexArray
  704. GoTo :EOF
  705.  
  706. REM functional
  707. REM add echo array "verticalmode" (no LF between array elements)
  708. ::Usage Call :EchoArray InputArray optional LINENUMBERS optional SHOWVARNAME optional .Suffix optional IndexRange
  709. :EchoArray
  710. set "_EchoArray_input=%~1"
  711. call set /a "_EchoArray_lbound=%%%~1.lbound" 2>nul
  712. if "[%_EchoArray_lbound%]" EQU "[]" set /a "_EchoArray_lbound=0"
  713. call set /a "_EchoArray_ubound=%%%~1.ubound"
  714. set /a "_EchoArray_index=%_EchoArray_lbound%"
  715. shift
  716. :EchoArray-arguments
  717. set "_EchoArray_buffer=%~1"
  718. if not defined _EchoArray_buffer GoTo :EchoArray-arguments-end
  719. if "[%_EchoArray_buffer:~,1%]" EQU "[.]" ( set "_EchoArray_suffix=%_EchoArray_buffer%" & shift & GoTo :EchoArray-arguments )
  720. if "[%_EchoArray_buffer%]" EQU "[LINENUMBERS]" ( set "_EchoArray_showlinenumbers=true" & shift & GoTo :EchoArray-arguments )
  721. if "[%_EchoArray_buffer%]" EQU "[SHOWVARNAME]" ( set "_EchoArray_showvariablename=true" & shift & GoTo :EchoArray-arguments )
  722. if "[%_EchoArray_buffer%]" EQU "[VERTICALMODE]" ( set "_EchoArray_verticalmode=true" & shift & GoTo :EchoArray-arguments )
  723. REM if "[%~1]" NEQ "[]" if not defined _EchoArray_IndexList.lbound set /a "_EchoArray_IndexList.lbound=1"
  724. if "[%~1]" NEQ "[]" ( Call :GetIndexArray _EchoArray_IndexList "%~1" & shift & GoTo :EchoArray-arguments )
  725. :EchoArray-arguments-end
  726. if defined _EchoArray_IndexList.ubound set /a "_EchoArray_ubound=%_EchoArray_IndexList.ubound%"
  727. setlocal enabledelayedexpansion
  728. :EchoArray-loop
  729. if not defined _EchoArray_IndexList.ubound ( set "_EchoArray_index_actual=%_EchoArray_index%" ) else ( set "_EchoArray_index_actual=!_EchoArray_IndexList[%_EchoArray_index%]!" )
  730. if defined _EchoArray_showlinenumbers set _EchoArray_prefix=%_EchoArray_index%:
  731. if defined _EchoArray_showvariablename set _EchoArray_prefix=%_EchoArray_input%[%_EchoArray_index_actual%]:
  732. if defined _EchoArray_showvariablename if defined _EchoArray_showlinenumbers set _EchoArray_prefix=%_EchoArray_index%:%_EchoArray_input%[%_EchoArray_index_actual%]:
  733. if not defined _EchoArray_verticalmode GoTo :EchoArray-normalmode-loop-next
  734. <nul set /p =%_EchoArray_prefix%!%_EchoArray_input%[%_EchoArray_index_actual%]%_EchoArray_suffix%!
  735. GoTo :EchoArray-loop-next
  736. :EchoArray-normalmode-loop-next
  737. echo(%_EchoArray_prefix%!%_EchoArray_input%[%_EchoArray_index_actual%]%_EchoArray_suffix%!
  738. :EchoArray-loop-next
  739. set /a "_EchoArray_index+=1"
  740. if %_EchoArray_index% LEQ %_EchoArray_ubound% GoTo :EchoArray-loop
  741. :EchoArray-loop-end
  742. endlocal
  743. Call :ClearVariablesByPrefix _EchoArray
  744. GoTo :EOF
  745.  
  746. REM add echo array "verticalmode" (no LF between array elements)
  747. ::Usage Call :ArrayToFile InputArray OutputFile optional LINENUMBERS optional SHOWVARNAME optional .Suffix optional IndexRange
  748. :ArrayToFile
  749. set "_ArrayToFile_input=%~1"
  750. call set /a "_ArrayToFile_lbound=%%%~1.lbound" 2>nul
  751. if "[%_ArrayToFile_lbound%]" EQU "[]" set /a "_ArrayToFile_lbound=0"
  752. call set /a "_ArrayToFile_ubound=%%%~1.ubound"
  753. set /a "_ArrayToFile_index=%_ArrayToFile_lbound%"
  754. shift
  755. set "_ArrayToFile_output=%~1"
  756. REM call set /a "_CopyArrayAdv_output_lbound=%%%~1.lbound" 2>nul
  757. REM if "[%_CopyArrayAdv_output_lbound%]" EQU "[]" set /a "_CopyArrayAdv_output_lbound=0"
  758. REM call set /a "_CopyArrayAdv_output_ubound=%%%~1.ubound%%" 2>nul
  759. REM if "[%_CopyArrayAdv_output_ubound%]" EQU "[]" set /a "_CopyArrayAdv_output_ubound=-1"
  760. REM set /a "_CopyArrayAdv_output_index=%_CopyArrayAdv_output_lbound%"
  761. shift
  762. :ArrayToFile-arguments
  763. set "_ArrayToFile_buffer=%~1"
  764. if not defined _ArrayToFile_buffer GoTo :ArrayToFile-arguments-end
  765. if "[%_ArrayToFile_buffer:~,1%]" EQU "[.]" ( set "_ArrayToFile_suffix=%_ArrayToFile_buffer%" & shift & GoTo :ArrayToFile-arguments )
  766. if "[%_ArrayToFile_buffer%]" EQU "[LINENUMBERS]" ( set "_ArrayToFile_showlinenumbers=true" & shift & GoTo :ArrayToFile-arguments )
  767. if "[%_ArrayToFile_buffer%]" EQU "[SHOWVARNAME]" ( set "_ArrayToFile_showvariablename=true" & shift & GoTo :ArrayToFile-arguments )
  768. if "[%_ArrayToFile_buffer%]" EQU "[VERTICALMODE]" ( set "_ArrayToFile_verticalmode=true" & shift & GoTo :ArrayToFile-arguments )
  769. REM if "[%~1]" NEQ "[]" if not defined _ArrayToFile_IndexList.lbound set /a "_ArrayToFile_IndexList.lbound=1"
  770. if "[%~1]" NEQ "[]" ( Call :GetIndexArray _ArrayToFile_IndexList "%~1" & shift & GoTo :ArrayToFile-arguments )
  771. :ArrayToFile-arguments-end
  772. if defined _ArrayToFile_IndexList.ubound set /a "_ArrayToFile_ubound=%_ArrayToFile_IndexList.ubound%"
  773. setlocal enabledelayedexpansion
  774. :ArrayToFile-loop
  775. if not defined _ArrayToFile_IndexList.ubound ( set "_ArrayToFile_index_actual=%_ArrayToFile_index%" ) else ( set "_ArrayToFile_index_actual=!_ArrayToFile_IndexList[%_ArrayToFile_index%]!" )
  776. if defined _ArrayToFile_showlinenumbers set _ArrayToFile_prefix=%_ArrayToFile_index%:
  777. if defined _ArrayToFile_showvariablename set _ArrayToFile_prefix=%_ArrayToFile_input%[%_ArrayToFile_index_actual%]:
  778. if defined _ArrayToFile_showvariablename if defined _ArrayToFile_showlinenumbers set _ArrayToFile_prefix=%_ArrayToFile_index%:%_ArrayToFile_input%[%_ArrayToFile_index_actual%]:
  779. if not defined _ArrayToFile_verticalmode GoTo :ArrayToFile-normalmode-loop-next
  780. <nul set /p =%_ArrayToFile_prefix%!%_ArrayToFile_input%[%_ArrayToFile_index_actual%]%_ArrayToFile_suffix%!>>%_ArrayToFile_output%
  781. GoTo :ArrayToFile-loop-next
  782. :ArrayToFile-normalmode-loop-next
  783. echo(%_ArrayToFile_prefix%!%_ArrayToFile_input%[%_ArrayToFile_index_actual%]%_ArrayToFile_suffix%!>>%_ArrayToFile_output%
  784. :ArrayToFile-loop-next
  785. set /a "_ArrayToFile_index+=1"
  786. if %_ArrayToFile_index% LEQ %_ArrayToFile_ubound% GoTo :ArrayToFile-loop
  787. :ArrayToFile-loop-end
  788. endlocal
  789. Call :ClearVariablesByPrefix _ArrayToFile
  790. GoTo :EOF
  791.  
  792. REM functional
  793. REM add echo array "verticalmode" (no LF between array elements)
  794. ::Usage Call :CopyArrayAdv InputArray OutputArray optional LINENUMBERS optional SHOWVARNAME optional VERTICALMODE optional .Suffix optional IndexRange
  795. :CopyArrayAdv
  796. set "_CopyArrayAdv_input=%~1"
  797. call set /a "_CopyArrayAdv_lbound=%%%~1.lbound" 2>nul
  798. if "[%_CopyArrayAdv_lbound%]" EQU "[]" set /a "_CopyArrayAdv_lbound=0"
  799. call set /a "_CopyArrayAdv_ubound=%%%~1.ubound"
  800. set /a "_CopyArrayAdv_index=%_CopyArrayAdv_lbound%"
  801. shift
  802. set "_CopyArrayAdv_output=%~1"
  803. call set /a "_CopyArrayAdv_output_lbound=%%%~1.lbound" 2>nul
  804. if "[%_CopyArrayAdv_output_lbound%]" EQU "[]" set /a "_CopyArrayAdv_output_lbound=0"
  805. call set /a "_CopyArrayAdv_output_ubound=%%%~1.ubound%%" 2>nul
  806. if "[%_CopyArrayAdv_output_ubound%]" EQU "[]" set /a "_CopyArrayAdv_output_ubound=-1"
  807. set /a "_CopyArrayAdv_output_index=%_CopyArrayAdv_output_lbound%"
  808. shift
  809. :CopyArrayAdv-arguments
  810. set "_CopyArrayAdv_buffer=%~1"
  811. if not defined _CopyArrayAdv_buffer GoTo :CopyArrayAdv-arguments-end
  812. if "[%_CopyArrayAdv_buffer:~,1%]" EQU "[.]" ( set "_CopyArrayAdv_suffix=%_CopyArrayAdv_buffer%" & shift & GoTo :CopyArrayAdv-arguments )
  813. if "[%_CopyArrayAdv_buffer%]" EQU "[LINENUMBERS]" ( set "_CopyArrayAdv_showlinenumbers=true" & shift & GoTo :CopyArrayAdv-arguments )
  814. if "[%_CopyArrayAdv_buffer%]" EQU "[SHOWVARNAME]" ( set "_CopyArrayAdv_showvariablename=true" & shift & GoTo :CopyArrayAdv-arguments )
  815. if "[%_CopyArrayAdv_buffer%]" EQU "[VERTICALMODE]" ( set "_CopyArrayAdv_verticalmode=true" & shift & GoTo :CopyArrayAdv-arguments )
  816. REM if "[%~1]" NEQ "[]" if not defined _CopyArrayAdv_IndexList.lbound set /a "_CopyArrayAdv_IndexList.lbound=1"
  817. if "[%~1]" NEQ "[]" ( Call :GetIndexArray _CopyArrayAdv_IndexList "%~1" & shift & GoTo :CopyArrayAdv-arguments )
  818. :CopyArrayAdv-arguments-end
  819. if defined _CopyArrayAdv_IndexList.ubound set /a "_CopyArrayAdv_ubound=%_CopyArrayAdv_IndexList.ubound%"
  820. setlocal enabledelayedexpansion
  821. set _CopyArrayAdv_localscope=true
  822. :CopyArrayAdv-loop
  823. if not defined _CopyArrayAdv_IndexList.ubound ( set "_CopyArrayAdv_index_actual=%_CopyArrayAdv_index%" ) else ( set "_CopyArrayAdv_index_actual=!_CopyArrayAdv_IndexList[%_CopyArrayAdv_index%]!" )
  824. if defined _CopyArrayAdv_showlinenumbers set _CopyArrayAdv_prefix=%_CopyArrayAdv_index%:
  825. if defined _CopyArrayAdv_showvariablename set _CopyArrayAdv_prefix=%_CopyArrayAdv_input%[%_CopyArrayAdv_index_actual%]:
  826. if defined _CopyArrayAdv_showvariablename if defined _CopyArrayAdv_showlinenumbers set _CopyArrayAdv_prefix=%_CopyArrayAdv_index%:%_CopyArrayAdv_input%[%_CopyArrayAdv_index_actual%]:
  827. if not defined _CopyArrayAdv_verticalmode GoTo :CopyArrayAdv-normalmode-loop-next
  828. REM <nul set /p =%_CopyArrayAdv_prefix%!%_CopyArrayAdv_input%[%_CopyArrayAdv_index_actual%]%_CopyArrayAdv_suffix%!
  829. set %_CopyArrayAdv_output%=!%_CopyArrayAdv_output%! %_CopyArrayAdv_prefix%!%_CopyArrayAdv_input%[%_CopyArrayAdv_index_actual%]%_CopyArrayAdv_suffix%!
  830. GoTo :CopyArrayAdv-loop-next
  831. :CopyArrayAdv-normalmode-loop-next
  832. REM echo(%_CopyArrayAdv_prefix%!%_CopyArrayAdv_input%[%_CopyArrayAdv_index_actual%]%_CopyArrayAdv_suffix%!
  833. set /a "_CopyArrayAdv_output_ubound+=1"
  834. set %_CopyArrayAdv_output%[%_CopyArrayAdv_output_ubound%]=%_CopyArrayAdv_prefix%!%_CopyArrayAdv_input%[%_CopyArrayAdv_index_actual%]%_CopyArrayAdv_suffix%!
  835. :CopyArrayAdv-loop-next
  836. set /a "_CopyArrayAdv_index+=1"
  837. if %_CopyArrayAdv_index% LEQ %_CopyArrayAdv_ubound% GoTo :CopyArrayAdv-loop
  838. :CopyArrayAdv-loop-end
  839. REM if defined _CopyArrayAdv_verticalmode TRIM FIRST SPACE FROM OUTPUT
  840. if not defined _CopyArrayAdv_verticalmode set /a "%_CopyArrayAdv_output%.lbound=%_CopyArrayAdv_output_lbound%"
  841. if not defined _CopyArrayAdv_verticalmode set /a "%_CopyArrayAdv_output%.ubound=%_CopyArrayAdv_output_ubound%"
  842. for /f "delims=" %%a in ('set %_CopyArrayAdv_output% 2^>nul') do (
  843. endlocal
  844. set %%a
  845. )
  846. if defined _CopyArrayAdv_localscope endlocal
  847. Call :ClearVariablesByPrefix _CopyArrayAdv
  848. GoTo :EOF
  849.  
  850.  
  851. ::Usage Call :GetEmptyLines Filename OutputArray optional OutputRows
  852. :GetEmptyLines
  853. set "_GetEmptyLines_output=%~2"
  854. if "[%~3]" EQU "[]" ( set "_GetEmptyLines_output_rows=%_GetEmptyLines_output%.rows" ) else ( set "_GetEmptyLines_output_rows=%_GetEmptyLines_output%" )
  855. for /f delims^=^ eol^= %%a in ('%SystemRoot%\System32\findstr /N "^$" "%~1" ^| findstr /N "^"') do (
  856. for /f "tokens=1,2* delims=:" %%f in ("%%a") do set /a "%_GetEmptyLines_output%.ubound=%%f" & set %_GetEmptyLines_output%[%%f]=%%g
  857. for /f "tokens=1,2* delims=:" %%f in ("%%a") do set %_GetEmptyLines_output_rows%[%%g].type=EmptyLine
  858. )
  859. set /a "%_GetEmptyLines_output%.lbound=1" & set "_GetEmptyLines_output=" & set "_GetEmptyLines_output_rows="
  860. GoTo :EOF
  861.  
  862. ::Usage Call :GetLabels Filename OutputArray optional OutputRows
  863. :GetLabels
  864. set "_GetLabels_output=%~2"
  865. if "[%~3]" EQU "[]" ( set "_GetLabels_output_rows=%_GetLabels_output%.rows" ) else ( set "_GetLabels_output_rows=%~3" )
  866. for /f delims^=^ eol^= %%a in ('%SystemRoot%\System32\findstr /N "^:[^:]" "%~1" ^| findstr /N "^"') do (
  867. for /f "tokens=1,2,3* delims=:" %%f in ("%%a") do set /a "%_GetLabels_output%.ubound=%%f" & set %_GetLabels_output%[%%f]=%%g
  868. for /f "tokens=1,2,3* delims=:" %%f in ("%%a") do set %_GetLabels_output_rows%[%%g].type=label
  869. 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
  870. 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
  871. 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
  872. )
  873. set /a "%_GetLabels_output%.lbound=1" & set "_GetLabels_output=" & set "_GetLabels_output_rows="
  874. GoTo :EOF
  875.  
  876. ::Usage Call :GetEndOfFunction Filename OutputArray optional OutputRows
  877. :GetEndOfFunction
  878. set "_GetEndOfFunction_output=%~2"
  879. if "[%~3]" EQU "[]" ( set "_GetEndOfFunction_output_rows=%_GetEndOfFunction_output%.rows" ) else ( set "_GetEndOfFunction_output_rows=%~3" )
  880. for /f delims^=^ eol^= %%a in ('%SystemRoot%\System32\findstr /N /I /C:":EndOf_" "%~1" ^| findstr /N "^"') do (
  881. for /f "tokens=1,2,3* delims=:" %%f in ("%%a") do set /a "%_GetEndOfFunction_output%.ubound=%%f" & set %_GetEndOfFunction_output%[%%f]=%%g
  882. for /f "tokens=1,2,* delims=:" %%f in ("%%a") do set %_GetEndOfFunction_output%[%%f].text=:%%h
  883. for /f "tokens=1,2,* delims=:" %%f in ("%%a") do set %_GetEndOfFunction_output_rows%[%%g]=:%%h
  884. for /f "tokens=1,2,* delims=:" %%f in ("%%a") do set %_GetEndOfFunction_output_rows%[%%g].type=EndOf_Function
  885. for /f "tokens=1,2,3* delims=:" %%f in ("%%a") do for /f "tokens=*" %%z in ("%%h") do set %_GetEndOfFunction_output%[%%f].name=%%~z
  886. for /f "tokens=1,2,3* delims=:" %%f in ("%%a") do for /f "tokens=1,2*" %%z in ("%%h") do set %_GetEndOfFunction_output%.name[%%~z]=%%g
  887. for /f "tokens=2 delims=:" %%b in ("%%a") do for /f "tokens=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24 delims=:" %%c in ("%%a") do for %%A in (%%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m %%n %%o %%p %%q %%r %%s %%t %%u %%v %%w %%x %%y %%z) do (
  888. set _GetEndOfFunction_buffer=%%A
  889. setlocal enabledelayedexpansion
  890. if "[!_GetEndOfFunction_buffer:~,6!]" EQU "[EndOf_]" set _GetEndOfFunction_buffer2=!_GetEndOfFunction_buffer!
  891. for %%Z in (!_GetEndOfFunction_buffer2!) do endlocal & set %_GetEndOfFunction_output%.name[%%~Z]=%%b
  892. endlocal
  893. )
  894. )
  895. set /a "%_GetEndOfFunction_output%.lbound=1" & set "_GetEndOfFunction_output=" & set "_GetEndOfFunction_output_rows="
  896. GoTo :EOF
  897.  
  898. :CopyArray-DEMO
  899.  
  900. Call :SimpleFileToArray batchsample.bat __CopyArray_sample
  901. Call :ClearVariablesByPrefix __CopyArray_output
  902. Call :CopyArray __CopyArray_sample __CopyArray_output
  903.  
  904. set __CopyArray_output
  905.  
  906. REM Call :ClearVariablesByPrefix __CopyArray
  907.  
  908. GoTo :EOF
  909.  
  910. :CopyObject-DEMO
  911.  
  912. set "myobject.suffixa=bla"
  913. set "myobject.suffixb=bli"
  914. set "myobject.suffixc=blou"
  915.  
  916. echo.&echo we are going to copy myobject to myother object
  917. echo.&echo contents of myobject
  918. set myobject
  919. Call :CopyObject myobject myotherobject
  920. echo.&echo after copying, contents of myotherobject
  921. set myotherobject
  922.  
  923. GoTo :EOF
  924.  
  925. ::Usage Call :CopyObject oldroot newroot
  926. :: Will copy oldroot.suffixes=? to newroot.suffixes=?
  927. ::This function will lose any trailling "=" at the beginning of a variable
  928. :CopyObject
  929. for /f "tokens=1 delims==" %%a in ('set %~1. 2^>nul') do for /f "tokens=2 eol== delims=.=" %%b in ('set %%a 2^>nul') do for /f "tokens=2* delims==" %%c in ('set %%a 2^>nul') do set %~2.%%b=%%c
  930. GoTo :EOF
  931.  
  932.  
  933. ::Usage Call :CopyArray InputArray OutputArray
  934. :CopyArray
  935. for /f "tokens=1 delims==" %%a in ('set %~1[ 2^>nul') do for /f "tokens=2 delims=[]" %%b in ('set %%a 2^>nul') do for /f "tokens=2 delims=]" %%c in ('set %%a 2^>nul') do set %~2[%%b]%%c
  936. GoTo :EOF
  937.  
  938.  
  939. REM ::Usage Call :SimpleFileToArray Filename OutputArray
  940. REM :SimpleFileToArray
  941. REM set /a "%~2.lbound=%%f"
  942. REM for /f delims^=^ eol^= %%a in ('%SystemRoot%\System32\findstr.exe /N "^" "%~1"') do (
  943. REM for /f "tokens=1,2* delims=:" %%f in ("%%a") do set /a "%~2.ubound=%%f" & set %~2[%%f]=%%a
  944. REM )
  945. REM set /a "_SFTA_index=1"
  946. REM call set /a "_SFTA_ubound=%%%~2.ubound%%"
  947. REM :SimpleFileToArray-loop
  948. REM setlocal enabledelayedexpansion
  949. REM set _SFTA_localscope=true
  950. REM set %~2[%_SFTA_index%]=!%~2[%_SFTA_index%]:*:=!
  951. REM for /f "delims=" %%a in ('set %~2[%_SFTA_index%] 2^>nul') do (
  952. REM endlocal
  953. REM set %%a
  954. REM )
  955. REM if defined _SFTA_localscope endlocal & set %~2[%_SFTA_index%]=
  956. REM set /a "_SFTA_index+=1"
  957. REM if %_SFTA_index% LEQ %_SFTA_ubound% GoTo :SimpleFileToArray-loop
  958. REM GoTo :EOF
  959.  
  960.  
  961. ::Usage Call :GetArrayIndex InputArray ListOfIndexesArray (could be space separated string ? with ranges ?)
  962. :GetArrayIndex (create new array containing all indexes from an xyz.array[x].array)
  963.  
  964. for /f delims^=^ eol^= %%a in ('set %~1')
  965.  
  966. GoTo :EOF
  967.  
  968. ::SortArray (create new array from input array, array sorted alphanumerically based on the values inside the array elements) (forward/reverse) (numeric, alphanumeric, custom order maybe ?)
  969. :CompactArray (starting from lbound or ubound, (create new array or modify current) by moving array elements with empty index, so that indexes become contiguous) apply to abc.array[] , abc.array[].suffix and abc.array[].* depending on configuration)
  970.  
  971. :compact array form one
  972. find lbound or ubound (lbound if not specificed, if no lbound specified either find lbound or shift array lbound to 0 or 1 ? so many choice)
  973. from starting position, check every index until opposite array bound
  974. form 2
  975. get all array indexes from a set loop (sort numerically), for each element, copy single, single+suffix, all element to new array (with or without .oldindex in the new array)
  976. form 3
  977. destructive vs nondestructive (nondestructive starts with copying entire array)
  978. loopthrough set, find lowest value, copy over, erase that index, repeat, duration is factorial of the number of index elements
  979.  
  980. array of index could be outputted as a series of numbers "1 2 3" and it could detect contiguous numbers and range them "1-3"
  981.  
  982.  
  983. hybrid any language program that goes from two labels inside the current batch file, to something that outputs to CommandToArray in one function
  984.  
  985.  
  986. ::Usage Call :GetFunctionExits OutputArray Filename
  987. :GetFunctionExits
  988. set "_GetFunctionExits_output=%~2"
  989. if "[%~3]" EQU "[]" ( set "_GetFunctionExits_output_rows=%_GetFunctionExits_output%.rows" ) else ( set "_GetFunctionExits_output_rows=%~3" )
  990. for /f delims^=^ eol^= %%a in ('%SystemRoot%\System32\findstr /N /I /C:"goto :EOF" /C:"exit /B" "%~1" ^| findstr /N "^"') do (
  991. for /f "tokens=1,2,3* delims=:" %%f in ("%%a") do set /a "%_GetFunctionExits_output%.ubound=%%f" & set %_GetFunctionExits_output%[%%f]=%%g
  992. for /f "tokens=1,2,3* delims=:" %%f in ("%%a") do set %_GetFunctionExits_output_rows%[%%g].type=FunctionExit
  993. for /f "tokens=1,2,3* delims=:" %%f in ("%%a") do for /f "tokens=2,* delims=:" %%b in ("%%a") do set %_GetFunctionExits_output%[%%f].text=%%c
  994. for /f "tokens=1,2,3* delims=:" %%f in ("%%a") do for /f "tokens=2,* delims=:" %%b in ("%%a") do set %_GetFunctionExits_output_rows%[%%g].text=%%c
  995. )
  996. set /a "%_GetFunctionExits_output%.lbound=1" & set "_GetFunctionExits_output=" & set "_GetFunctionExits_output_rows="
  997. GoTo :EOF
  998.  
  999. :GetFunctionsFromLabels OutputFunctionsArray InputLabels
  1000. this function
  1001. remove using an exclusion list
  1002. all labels that have the excluded word in the last section of the name, as they are always internal function labels
  1003.  
  1004. loop loop2 loop3 loop# end skip skip2 skipn test test1 testn cleanup argument params args next prev iteration pre post
  1005. 0 1 2 3 4 5 6 7 8 9
  1006.  
  1007. in function name, treat _ - . the same
  1008.  
  1009. also remove main labels setup main exit macro setmacro etc..
  1010.  
  1011.  
  1012. GoTo :EOF
  1013.  
  1014. :GetBatchFileStructure BatchFileStructureArray EmptyLinesArray (LabelsArray or FunctionArray) (EndOfFunctionArray or ExitArray)
  1015. GoTo :EOF
  1016.  
  1017.  
  1018. the difference between a label is a function is that a function is a label with a corresponding "EndOfFunction" label, is not a lifecycle label name (main,setup,setmacro,exit etc..) is not an internal label (ends with -loop -skip -argument etc..)
  1019. BFS[element]=linenumber
  1020. BFS[element].type=EmptyLine/Label/Function/EndOfFunction/FunctionExit
  1021. BFS[element].emptyline=true
  1022. BFS[element].label=functionname
  1023. BFS[element].function=functionname
  1024. BFS[element].endoffunction=functionname(s)
  1025. BFS[element].functionexit=Exit line
  1026.  
  1027.  
  1028.  
  1029. :: Usage Call :ClearVariablesByPrefix myPrefix
  1030. :ClearVariablesByPrefix
  1031. if "[%~1]" NEQ "[]" for /f "tokens=1,2 delims==" %%a in ('set %~1 2^>nul') do set %%a=
  1032. if "[%~2]" NEQ "[]" shift & GoTo :ClearVariablesByPrefix
  1033. GoTo :EOF
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040. REM removed from AddEscapeCharacters.bat
  1041.  
  1042. :GetFunctionDefinition-DEMO
  1043.  
  1044. if "[%outputlabelarray.ubound%]" EQU "[]" Call :FindAllLabels-DEMO
  1045.  
  1046. echo GetFunctionDefinition %time%
  1047. Call :GetFunctionDefinition OutputArray OutputLabelArray OutputEmptylineArray OutputEndOf_Array "loop loop2 end skip cleanup argument params"
  1048. echo GetFunctionDefinition %time%
  1049.  
  1050.  
  1051. GoTo :EOF
  1052.  
  1053. ::Usage Call :GetFunctionDefinition OutputArray LabelsArray EmptyLinesArray EndOf_Array optional ExclusionList
  1054. :GetFunctionDefinition
  1055. set "_GetFunctionDefinition_prefix=_GFD"
  1056. REM loopthrough labels
  1057. REM copy only labels that don' t match the exclusion list
  1058. REM for each label find the EndOf_ line
  1059. REM for each label, find first empty row before label line number
  1060. REM for each label, find first empty row after label line number
  1061. if "[%~5]" EQU "[]" ( set "_GFD_label_exclusion=loop loop2 end skip cleanup argument params" ) else set ( "_GFD_label_exclusion=%~5" )
  1062. set "_GFD_output=%~1"
  1063. call set "_GFD_output_ubound=%%%~1.ubound%%"
  1064. if "[%_GFD_output_ubound%]" EQU "[]" set "_GFD_output_ubound=-1"
  1065. set "_GFD_labels=%~2"
  1066. call set "_GFD_labels_ubound=%%%~2.ubound%%"
  1067. set /a "_GFD_labels_index=0"
  1068. set "_GFD_empty=%~3"
  1069. call set "_GFD_empty_ubound=%%%~3.ubound%%"
  1070. echo setting _GFD_EndOf, it should eb OutputEndOf_Array
  1071. set "_GFD_EndOf=%~4"
  1072. echo _GFD_EndOf is %_GFD_EndOf%
  1073. call set "_GFD_EndOf_ubound=%%%~4.ubound%%"
  1074. :GetFunctionDefinition-loop
  1075. set "_GFD_EnfOfFunctionLine=" & set "_GFD_EmptyBeforeLine=" & set "_GFD_AfterBeforeLine="
  1076. echo calling GetFunctionDefinition_IsLabelAfunction
  1077. Call :GetFunctionDefinition_IsLabelAfunction %%%_GFD_labels%[%_GFD_labels_index%].labelname%% "%_GFD_label_exclusion%" || GoTo :GetFunctionDefinition-loop-skip
  1078. echo calling GetFunctionDefinition_FindEndOfFunctionLineNumber _GFD_EndOf %_GFD_EndOf%
  1079. Call :GetFunctionDefinition_FindEndOfFunctionLineNumber %%%_GFD_labels%[%_GFD_labels_index%].labelname%% %_GFD_EndOf% _GFD_EnfOfFunctionLine
  1080. if "[%_GFD_EnfOfFunctionLine%]" EQU "[]" GoTo :GetFunctionDefinition-loop-skip
  1081. REM if "[%_GFD_EnfOfFunctionLine%]" EQU "[]" Call :GetFunctionDefinition_FindUnmarkedFunctionEndLineNumber
  1082. echo calling GetFunctionDefinition_FindEmptyRowBeforeLineNumber
  1083. Call :GetFunctionDefinition_FindEmptyRowBeforeLineNumber %%%_GFD_labels%[%_GFD_labels_index%]%% %_GFD_empty% _GFD_EmptyBeforeLine
  1084. echo calling GetFunctionDefinition_FindEmptyRowAfterLineNumber
  1085. Call :GetFunctionDefinition_FindEmptyRowAfterLineNumber %_GFD_EnfOfFunctionLine% %_GFD_empty% _GFD_AfterBeforeLine
  1086. rem output %%%_GFD_labels%[%_GFD_labels_index%].labelname%% _GFD_EmptyBeforeLine _GFD_AfterBeforeLine _GFD_EnfOfFunctionLine
  1087. set /a "_GFD_output_ubound+=1"
  1088. call output %_GFD_EmptyBeforeLine% %%%_GFD_labels%[%_GFD_labels_index%].labelname%% %_GFD_EnfOfFunctionLine% %_GFD_AfterBeforeLine%
  1089. call set %_GFD_output%[%_GFD_output_ubound%].name=%%%_GFD_labels%[%_GFD_labels_index%].labelname%%
  1090. call set %_GFD_output%[%_GFD_output_ubound%].functionstart=%%%_GFD_labels%[%_GFD_labels_index%]%%
  1091. set %_GFD_output%[%_GFD_output_ubound%].functionend=%_GFD_EnfOfFunctionLine%
  1092. set %_GFD_output%[%_GFD_output_ubound%].commentstart=%_GFD_EmptyBeforeLine%
  1093. set %_GFD_output%[%_GFD_output_ubound%].commentend=%_GFD_AfterBeforeLine%
  1094. :GetFunctionDefinition-loop-skip
  1095. set /a "_GFD_labels_index+=1"
  1096. if %_GFD_labels_index% LEQ %_GFD_labels_ubound% GoTo :GetFunctionDefinition-loop
  1097. GoTo :EOF
  1098.  
  1099.  
  1100. ::Usage Call :GetFunctionDefinition_IsLabelAfunction LabelName optional ExclusionList
  1101. :GetFunctionDefinition_IsLabelAfunction
  1102. set "_GetFunctionDefinition_label_with_space=%~1" & set "_GetFunctionDefinition_exclusion_list=%~2"
  1103. set "_GetFunctionDefinition_label_with_space=%_GetFunctionDefinition_label_with_space:-= %
  1104. if "[%_GetFunctionDefinition_exclusion_list%]" EQU "[]" set "_GetFunctionDefinition_exclusion_list=loop loop2 skip end cleanup argument params"
  1105. REM for %%a in (%_GetFunctionDefinition_exclusion_list%) do ( for %%c in (%_GetFunctionDefinition_label_with_space%) do ( if "[%%a]" EQU "[%%c]" echo matching %%a and %%c ) )
  1106. for %%a in (%_GetFunctionDefinition_exclusion_list%) do ( for %%c in (%_GetFunctionDefinition_label_with_space%) do ( if "[%%a]" EQU "[%%c]" exit /b 1 ) )
  1107. exit /b 0
  1108. GoTo :EOF
  1109.  
  1110. ::Usage Call :GetFunctionDefinition_FindEmptyRowBeforeLineNumber LabelLineNumber EmptyLinesArray OutputLineNumber
  1111. :GetFunctionDefinition_FindEmptyRowBeforeLineNumber
  1112. set /a "_GFD_empty_index=0"
  1113. set "_GFD_empty=%~2"
  1114. call set "_GFD_empty_ubound=%%%~3.ubound%%"
  1115. set /a "_GFD_functionline=%~1"
  1116. set "_GFD_currentline="
  1117. set "_GFD_lastline="
  1118. :GetFunctionDefinition_FindEmptyRowBeforeLineNumber-loop
  1119. call set _GFD_currentline=%%%_GFD_empty%[%_GFD_empty_index%]%%
  1120. if %_GFD_currentline% LSS %_GFD_functionline% set "_GFD_lastline=%_GFD_currentline%"
  1121. if %_GFD_currentline% GEQ %_GFD_functionline% GoTo :GetFunctionDefinition_FindEmptyRowBeforeLineNumber-end
  1122. set /a "_GFD_empty_index+=1"
  1123. if %_GFD_empty_index% LEQ %_GFD_empty_ubound% GoTo :GetFunctionDefinition_FindEmptyRowBeforeLineNumber-loop
  1124. :GetFunctionDefinition_FindEmptyRowBeforeLineNumber-end
  1125. set /a "%~3=%_GFD_lastline%"
  1126. GoTo :EOF
  1127.  
  1128. ::Usage Call :GetFunctionDefinition_FindEmptyRowAfterLineNumber LabelLineNumber EmptyLinesArray OutputLineNumber
  1129. :GetFunctionDefinition_FindEmptyRowAfterLineNumber
  1130. set /a "_GFD_Empty_index=0"
  1131. set "_GFD_Empty=%~2"
  1132. call set "_GFD_Empty_ubound=%%%~3.ubound%%"
  1133. set /a "_GFD_FunctionLine=%~1"
  1134. set "_GFD_CurrentLine="
  1135. set "_GFD_LastLine="
  1136. :GetFunctionDefinition_FindEmptyRowAfterLineNumber-loop
  1137. call set _GFD_currentline=%%%_GFD_Empty%[%_GFD_Empty_index%]%%
  1138. if %_GFD_CurrentLine% GEQ %_GFD_FunctionLine% ( set "_GFD_LastLine=%_GFD_CurrentLine%" & GoTo :GetFunctionDefinition_FindEmptyRowAfterLineNumber-end )
  1139. set /a "_GFD_Empty_index+=1"
  1140. if %_GFD_Empty_index% LEQ %_GFD_LastLine% GoTo :GetFunctionDefinition_FindEmptyRowAfterLineNumber-loop
  1141. :GetFunctionDefinition_FindEmptyRowAfterLineNumber-end
  1142. set /a "%~3=%_GFD_LastLine%"
  1143. GoTo :EOF
  1144.  
  1145. ::Usage Call :GetFunctionDefinition_FindEndOfFunctionLineNumber FunctionName EndOfFunctionLinesArray OutputLineNumber
  1146. :GetFunctionDefinition_FindEndOfFunctionLineNumber
  1147. set "_GFD_Endof_currentname=" & set "_GFD_Endof_current_substitutions=" & set "_GFD_function_name="
  1148. set "_GFD_function_name=:EndOf_%~1"
  1149. set /a "_GFD_Endof_index=0"
  1150. set "_GFD_Endof_array=%~2"
  1151. echo "_GFD_Endof_ubound=%%%~2.ubound%%"
  1152. call echo "_GFD_Endof_ubound=%%%~2.ubound%%"
  1153. call set "_GFD_Endof_ubound=%%%~2.ubound%%"
  1154. set "_GFD_Endof_line="
  1155. :GetFunctionDefinition_FindEndOfFunctionLineNumber-loop
  1156. echo call set "_GFD_Endof_currentname=%%%_GFD_Endof_array%[%_GFD_Endof_index%].EndOf_name%%
  1157. call echo call set "_GFD_Endof_currentname=%%%_GFD_Endof_array%[%_GFD_Endof_index%].EndOf_name%%
  1158. call set "_GFD_Endof_currentname=%%%_GFD_Endof_array%[%_GFD_Endof_index%].EndOf_name%%
  1159. call set "_GFD_Endof_current_substitutions=%%_GFD_Endof_currentname:%_GFD_function_name%=%%
  1160. echo _GFD_Endof_currentname %_GFD_Endof_currentname% 11 %_GFD_Endof_array%[%_GFD_Endof_index%].EndOf_name 22 _GFD_function_name %_GFD_function_name%
  1161. if "[%_GFD_Endof_currentname%]" NEQ "[%_GFD_Endof_current_substitutions%]" ( call set /a "_GFD_Endof_line=%%%_GFD_Endof_array%[%_GFD_Endof_index%]%%" & GoTo :GetFunctionDefinition_FindEndOfFunctionLineNumber-end )
  1162. echo helo
  1163. set /a "_GFD_Endof_index+=1"
  1164. echo lohe if %_GFD_Endof_index% LEQ %_GFD_Endof_ubound%
  1165. if %_GFD_Endof_index% LEQ %_GFD_Endof_ubound% GoTo :GetFunctionDefinition_FindEndOfFunctionLineNumber-loop
  1166. echo lohe2
  1167. :GetFunctionDefinition_FindEndOfFunctionLineNumber-end
  1168. if defined _GFD_Endof_line set /a "%~3=%_GFD_Endof_line%"
  1169. GoTo :EOF
  1170.  
  1171.  
  1172. :FindAllLabels-DEMO
  1173. Call :ClearVariablesByPrefix _FAERFA OutputEndOf_Array
  1174. REM goto :FindAllLabels-DEMO-skip
  1175. Call :ClearVariablesByPrefix FileLines OutputLabelArray OutputEmptylineArray _FALFFLA _FAERFA
  1176. echo ClearVariablesByPrefix %time%
  1177. Call :FileToArray FileLines "batchsample.bat"
  1178. echo FileToArray %time%
  1179. REM Call :TrimBeforeCharArray ":" FileLines
  1180. REM echo TrimBeforeCharArray %time%
  1181.  
  1182. Call :FindAllLabelsFromFileLineArray FileLines OutputLabelArray
  1183. echo FindAllLabelsFromFileLineArray %time%
  1184.  
  1185. Call :FindAllEmptyRowsFromArray FileLines OutputEmptylineArray
  1186. echo FindAllEmptyRowsFromArray %time%
  1187. :FindAllLabels-DEMO-skip
  1188. Call :FindAllEndOf_rowsFromArray FileLines OutputEndOf_Array
  1189. echo FindAllEndOf_rowsFromArray %time%
  1190.  
  1191.  
  1192. REM Call :ClearVariablesByPrefix FileLines
  1193. REM echo ClearVariablesByPrefix %time%
  1194. GoTo :EOF
  1195.  
  1196.  
  1197. ::Usage Call :FindAllEndOf_rowsFromArray FileLineArray OutputEmptylineArray
  1198. :FindAllEndOf_rowsFromArray
  1199. set "_FindAllEndOf_rowsFromArray_prefix=_FAEORFA"
  1200. set "_FAEORFA_Lines=%~1"
  1201. call set /a "_FAEORFA_ubound=%%%_FAEORFA_Lines%.ubound%%"
  1202. call set /a "_FAEORFA_index=%%%_FAEORFA_Lines%.lbound%%"
  1203. set "_FAEORFA_Output=%~2"
  1204. call set /a "_FAEORFA_output_lbound=%%%_FAEORFA_Output%.lbound%%" 2>nul
  1205. call set /a "_FAEORFA_output_ubound=%%%_FAEORFA_Output%.ubound%%" 2>nul
  1206. if not defined _FAEORFA_output_lbound set /a "_FAEORFA_output_lbound=0"
  1207. if not defined _FAEORFA_output_ubound set /a "_FAEORFA_output_ubound=-1"
  1208. :FindAllEndOf_rowsFromArray-loop
  1209. Call :IsEndOfFunction _FAEORFA_IsEndOf_ %_FAEORFA_Lines%[%_FAEORFA_index%]
  1210. if "[%_FAEORFA_IsEndOf_%]" EQU "[true]" set /a "_FAEORFA_output_ubound+=1"
  1211. if "[%_FAEORFA_IsEndOf_%]" EQU "[true]" (
  1212. set "%_FAEORFA_Output%[%_FAEORFA_output_ubound%]=%_FAEORFA_index%"
  1213. Call :GetEndOfFunction %_FAEORFA_Output%[%_FAEORFA_output_ubound%].EndOf_name %_FAEORFA_Lines%[%_FAEORFA_index%]
  1214. )
  1215. set /a "_FAEORFA_index+=1"
  1216. if %_FAEORFA_index% LEQ %_FAEORFA_ubound% GoTo :FindAllEndOf_rowsFromArray-loop
  1217. set /a "%_FAEORFA_Output%.lbound=%_FAEORFA_output_lbound%"
  1218. set /a "%_FAEORFA_Output%.ubound=%_FAEORFA_output_ubound%"
  1219. Call :ClearVariablesByPrefix %_FindAllENDFUNCrowsFromArray_prefix% _FindAllEndOf_rowsFromArray
  1220. GoTo :EOF
  1221.  
  1222. ::Usage Call :FindAllEmptyRowsFromArray FileLineArray OutputEmptylineArray
  1223. :FindAllEmptyRowsFromArray
  1224. set "_FindAllEmptyRowsFromArray_prefix=_FAERFA"
  1225. set "_FAERFA_Lines=%~1"
  1226. call set /a "_FAERFA_ubound=%%%_FAERFA_Lines%.ubound%%"
  1227. call set /a "_FAERFA_index=%%%_FAERFA_Lines%.lbound%%"
  1228. set "_FAERFA_Output=%~2"
  1229. call set /a "_FAERFA_output_lbound=%%%_FAERFA_Output%.lbound%%" 2>nul
  1230. call set /a "_FAERFA_output_ubound=%%%_FAERFA_Output%.ubound%%" 2>nul
  1231. if not defined _FAERFA_output_lbound set /a "_FAERFA_output_lbound=0"
  1232. if not defined _FAERFA_output_ubound set /a "_FAERFA_output_ubound=-1"
  1233. set _FAERFA
  1234. :FindAllEmptyRowsFromArray-loop
  1235. if not defined %_FAERFA_Lines%[%_FAERFA_index%] set /a "_FAERFA_output_ubound+=1"
  1236. if not defined %_FAERFA_Lines%[%_FAERFA_index%] set "%_FAERFA_Output%[%_FAERFA_output_ubound%]=%_FAERFA_index%"
  1237. set /a "_FAERFA_index+=1"
  1238. if %_FAERFA_index% LEQ %_FAERFA_ubound% GoTo :FindAllEmptyRowsFromArray-loop
  1239. Call :ClearVariablesByPrefix %_FindAllEmptyRowsFromArray_prefix% _FindAllEmptyRowsFromArray
  1240. GoTo :EOF
  1241.  
  1242. ::Usage Call :FindAllLabelsFromFileLineArray FileLineArray OutputLabelArray
  1243. :FindAllLabelsFromFileLineArray
  1244. set "_FindAllLabelsFromFileLineArray_prefix=_FALFFLA"
  1245. set "_FALFFLA_Lines=%~1"
  1246. call set /a "_FALFFLA_ubound=%%%_FALFFLA_Lines%.ubound%%"
  1247. call set /a "_FALFFLA_index=%%%_FALFFLA_Lines%.lbound%%"
  1248. set "_FALFFLA_Output=%~2"
  1249. call set /a "_FALFFLA_output_lbound=%%%_FALFFLA_Output%.lbound%%" 2>nul
  1250. call set /a "_FALFFLA_output_ubound=%%%_FALFFLA_Output%.ubound%%" 2>nul
  1251. if not defined _FALFFLA_output_lbound set /a "_FALFFLA_output_lbound=0"
  1252. if not defined _FALFFLA_output_ubound set /a "_FALFFLA_output_ubound=-1"
  1253. :FindAllLabelsFromFileLineArray-loop
  1254. REM if %_FALFFLA_index%==2 echo %_FALFFLA_Lines%[%_FALFFLA_index%]
  1255. REM if %_FALFFLA_index%==2 call echo %%%_FALFFLA_Lines%[%_FALFFLA_index%]%%
  1256. REM Call :TrimBeforeChar %_FALFFLA_Lines%[%_FALFFLA_index%] : %_FALFFLA_Lines%[%_FALFFLA_index%]
  1257. Call :IsLabel _FALFFLA_IsLabel %_FALFFLA_Lines%[%_FALFFLA_index%]
  1258. if "[%_FALFFLA_IsLabel%]" EQU "[true]" set /a "_FALFFLA_output_ubound+=1"
  1259. if "[%_FALFFLA_IsLabel%]" EQU "[true]" (
  1260. set "%_FALFFLA_Output%[%_FALFFLA_output_ubound%]=%_FALFFLA_index%"
  1261. Call :GetLabel %_FALFFLA_Output%[%_FALFFLA_output_ubound%].labelname %_FALFFLA_Lines%[%_FALFFLA_index%]
  1262. )
  1263. REM if "[%_FALFFLA_IsLabel%]" EQU "[true]" call echo %%%_FALFFLA_Output%[%_FALFFLA_output_ubound%].labelname%%
  1264. REM echo falffla %_FALFFLA_index%
  1265. set /a "_FALFFLA_index+=1"
  1266. REM if %_FALFFLA_index% GTR 500 GoTo :FindAllLabelsFromFileLineArray-skip
  1267. if %_FALFFLA_index% LEQ %_FALFFLA_ubound% GoTo :FindAllLabelsFromFileLineArray-loop
  1268. REM :FindAllLabelsFromFileLineArray-skip
  1269. set /a "%_FALFFLA_Output%.lbound=%_FALFFLA_output_lbound%"
  1270. set /a "%_FALFFLA_Output%.ubound=%_FALFFLA_output_ubound%"
  1271. Call :ClearVariablesByPrefix %_FindAllLabelsFromFileLineArray_prefix% _FindAllLabelsFromFileLineArray
  1272. GoTo :EOF
  1273.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement