Extract a sorted list of functions

Post your working scripts, libraries and tools.
User avatar
DrReflex
Posts: 42
Joined: 25 May 2015, 02:57
Location: Greer, SC

Extract a sorted list of functions

04 Aug 2023, 19:14

It is often useful to have a sorted list of AHK functions. This is particularly useful for large libraries. Here is a simple function that will extract a list of functions that conform to the format: Function(parameters) { ... code lines ... } etc. It requires input and output file names (with full paths). It reads the input file, extracts all functions meeting the format noted above, and saves the sorted list of functions to the output file.

Code: Select all

;	NAME:			ExtractSortedFunctionList.v2.ahk
;	DESCRIPTION:	Strips functions from ahk program code and save it to a file.
;	NOTE:			Change FullPath, FileIn, and FileOut then execute
;=============================================================================
#Requires AutoHotkey >=2.0-<2.1
#SingleInstance Force				; Recommended so only one copy is runnnig at a time
SetWorkingDir A_ScriptDir  	; Ensures a consistent starting directory.
FullPath  := "D:\_AHK2\___SCRIPTS\GDIP\Buliasz_AHKv2-Gdip-master\"
FileIn		:= "Gdip_All_184.v2.ahk"
FileOut		:= "Gdip_All_184_SortedFunctionList.v2.txt"
FileInFP	:= FullPath . FileIn
FileOutFP := FullPath . FileOut
{
	ExtractSortedFunctionList(FileInFP,FileOutFP)
	ExitApp
}

ExtractSortedFunctionList(FIFP,FOFP)
{
	StrIn 	:= FileRead(FIFP)
	while ((PosSemi := InStr(StrIn,";")) > 0)
	{
		PosCR 	:= InStr(StrIn,"`n",0,(PosSemi+1))
		StrIn 	:= SubStr(StrIn,1,(PosSemi-1)) . SubStr(StrIn,(PosCR+1))
	}
	StrIn := StrReplace(StrIn,"`r`n","`n")
	StrIn := StrReplace(StrIn,"`n`n","`n")
	while ((PosCB := InStr(StrIn,"}")) > 0)
	{
		PosOB := InStr(StrIn,"{",0,-(StrLen(StrIn) - PosCB+1))
		StrIn := SubStr(StrIn,1,(PosOB-1)) . SubStr(StrIn,(PosCB+1))
	}
	StrIn := StrReplace(StrIn,"`n`n","`n")
	StrIn := StrReplace(StrIn,"`n`n","`n")
	StrIn := Sort(StrIn)
	if(FileExist(FOFP))
	{
		FileDelete FOFP
	}
	FileAppend StrIn, FOFP
	ExitApp
}

Esc::
{
	ExitApp
	Return
}
User avatar
thqby
Posts: 427
Joined: 16 Apr 2021, 11:18
Contact:

Re: Extract a sorted list of functions

04 Aug 2023, 22:41

This script has major limitations, and if the string in the script contains characters such as {};, the generated content will be cluttered.

You can export functions, classes, etc., using vscode's ahk v2 extension
image.png
image.png (313.82 KiB) Viewed 704 times
User avatar
emmanuel d
Posts: 90
Joined: 17 Nov 2013, 04:45

Re: Extract a sorted list of functions

17 Sep 2023, 11:08

Are functions not objects?
Why cant we do a for loop and get the all the custom and built in functions?

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: Descolada and 13 guests