Jump to content

How many keywords were used in my script?


CYCho
 Share

Recommended Posts

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)

 

Edited by CYCho
Link to comment
Share on other sites

CodeScanner will give you detailed lists of all functions, variables, and macros used in a script.

Link to comment
Share on other sites

3 hours ago, Nine said:

It all depends on what you call keywords.

This is exactly the crucial point (in my opinion).

@CYCho :

The base definition of keywords  in AutoIt will certainly not be sufficient for your project. Without the AutoIt functions it will hardly be possible to write a program. Therefore I would consider functions and possibly relevant constants as keywords.

I would create my own list of keywords (as a file - one keyword per line). As a basis I would use the au3.keywords.properties, just as you have already planned yourself. You can then enhance this list with function names of non-standard UDF's if required.

@CYCho EDIT : OK, you were faster ;)

BTW : If you analyze a script the following would be useful:

#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/MO

So all includes are contained in one file. Comments should also be ignored, because they may have keywords in them.

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

11 hours ago, CYCho said:

By keywords, I meant those entries in the AutoIt Help file and similar UDF function names which have not yet made it to the Help file. I found that au3.keywords.properties file in the SciTE folder contains all the current keywords satisfying my definition.

In that case, why not include all unique function calls used , regardless of source, and all @ macros used as well as any predefined $ constants.  Otherwise you are being arbitrary, imo.

Code hard, but don’t hard code...

Link to comment
Share on other sites

I think your definition of keywords is wrong.  The moment a UDF is adding a new function, you would need to modify your list.  Based on you definition, there is an unlimited number of keywords, which of course does not make sense.  You must want to talk of (instead of keywords) a dictionary of functions.  

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...