ListFunctions.bat This list all "functions" in a .bat file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
shodan
Posts: 53
Joined: 01 May 2023 01:49

ListFunctions.bat This list all "functions" in a .bat file

#1 Post by shodan » 25 Mar 2024 03:47

Usage ListFunctions.bat batchfile.bat

Will list all functions found in that batch file, minus a pre-defined list of exclusions

Example
cmd_YFVGop7naG.png
cmd_YFVGop7naG.png (102.92 KiB) Viewed 434 times
The exclusion are one of the following words, when the function name is tokenized, in the last position
As well as any function that starts with "EndOf_"

main setup 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

You can specify a different set by adding it as a string when calling "Call :IsFunctionLabelExcluded"

listfunctions.zip
(2.15 KiB) Downloaded 28 times
batchsample.zip
(41.66 KiB) Downloaded 20 times

shodan
Posts: 53
Joined: 01 May 2023 01:49

Re: ListFunctions.bat This list all "functions" in a .bat file

#2 Post by shodan » 25 Mar 2024 04:54

And now ListFunctionRows.bat

This new version lists every function and it's row number in the file.

The definition of a function here is,

At least one empty row before
A label
Either an "exit" or a label that starts with EndOf_ and then the label name
then another empty row

There is a minor bug with functions that have aliases or overload (that is, no space between)
ListFunctionRows.zip
(6.08 KiB) Downloaded 23 times
revised batchsample.bat
batchsample.zip
(41.69 KiB) Downloaded 21 times

Next step will be a function which you specify a file and one or more functions, and an output file where all these functions will be copied too.

Also a function, which retrieves all functions called by a function.

The goal is to quickly create function library.

Or to populate a batch file with all the batch function dependencies it needs.
Attachments
cmd_ziBbvhPzta.png
cmd_ziBbvhPzta.png (204.92 KiB) Viewed 428 times

Post Reply