Sometimes I wondered how many keywords were used in my particular script. When I was trying to persuade one of my friends to learn coding, I told him that a few hundred words were all he had to learn to speak a decent computer language, while he had to learn several thousand words to speak a decent English as a foreign language. As a proof I counted the number of keywords used in my zPlayer.au3 with the following code and it was 185. As only standard UDF files were used in the script, I think this is a pretty close count.
My question: Is there a simpler and more accurate way of counting the number of keywords used in a script, especially when external UDFs are included, in which case the function names are not listed in au3.keywrods.properties file?
#include <Array.au3>
$sPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\autoit3.exe", "")
$allKeywords = FileReadToArray(StringReplace($sPath, "autoit3.exe", "SciTE\au3.keywords.properties"))
$sScript = FileRead("d:\zplayer\zplayer.au3")
Local $aKeywordsUsed[1]
For $i = 1 To UBound($allKeywords)-1
$sLine = StringStripWS($allKeywords[$i], 3)
If StringInStr($sLine, "=") Then
$sLine = StringMid($sLine, StringInStr($sLine, "=")+1)
EndIf
$sLine = StringReplace($sLine, " \", "")
$aLine = StringSplit($sLine, " ")
For $j = 1 To $aLine[0]
If StringInStr($sScript, $aLine[$j]) Then
_ArrayAdd($aKeywordsUsed, $aLine[$j])
EndIf
Next
Next
$aKeywordsUsed[0] = UBound($aKeywordsUsed)-1
_ArraySort($aKeywordsUsed, 0, 1)
_ArrayDisplay($aKeywordsUsed)