Jump to content

Recommended Posts

Posted

I'm trying to create a list of all occurrences of variables in an Autoit file. Unfortunately, my regex skills suck badly.

I found a snippet elsewhere here, which at first glance, works pretty well...

$aArray = StringRegExp($varFileContents, "(\$\w{1,50})(?:\s|\[)", 3)

...but doesn't grab variables in situations like this:

_ArraySort($aBefore)

or

_ArrayDelete($aSkills, 0)

Appreciate any help. Here's the code so far:

#include <Array.au3>

; Select file
While 1
$filename = FileOpenDialog("Select a file", @DesktopCommonDir, "AU3 files (*.au3)", 1)
If $filename <> "" Then
ExitLoop
Else
$answer = MsgBox(36, "Check Variables", "No file selected. Exit Program?")
If $answer = 6 Then Exit
EndIf
WEnd

$varFileContents = FileRead($filename)
$aArray = StringRegExp($varFileContents, "(\$\w{1,50})(?:\s|\[)", 3)
_ArraySort($aArray)
_ArrayDisplay($aArray)
Posted

Have you tried Tidy? It can generate a cross reference listing of variables and functions.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Have you tried Tidy? It can generate a cross reference listing of variables and functions.

Yes, in fact I have, but the results don't seem to be correct: I put this at the top of a file:
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Run_Tidy=y
#Tidy_Parameters=/gd /gds
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

And here's the results:

#### indicates that this specific variable only occurs one time in the script.
---- indicates that this specific variable isn't declared with Dim/Local/Global/Const.
== Variables ======================================================================================================
Variable name            Dim Used in Row(s)
========================= ===== ===================================================================================
$UsedOnce                ----- 00011
$aBefore                 ----- 00019 00020
$aSkills                 ----- 00023
$filename                ----- 00012 00017
$myfile              ----- 00022
$test1               ----- 00010
$test2               ----- 00013
$whiz                    ----- 00017 00019

There are several variables that only appear once, as shown above, but they're not indicated with "####", as I would expect. As well, in my test I have this line: "Global $test1[1]", and the Tidy report shows it as not being declared with "Dim/Local/Global/Const".

Perhaps I'm misunderstanding the output.

Posted

Which version of Tidy do you run? This information is displayed in the Scite output pane.

Tidy AutoIt3 v2.2.2.0 Copyright © Jos van der Zande February 19, 2012

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

Yes, a quick test seems to indicate that's what I need. Thanks!!

Variables inside quotes and comments would create a problem

Check this out

#include <Array.au3>


$FileContents = FileRead(@ScriptFullPath)
_ListVars( $FileContents )


Func _ListVars($sString)
$sString = Strip_Comments_Quotes($FileContents)

$aArray = StringRegExp($sString, "(\$\w+)", 3)

;Comment the following two lines for receiving the number of times the vars occured
$aArray = _ArrayUnique( $aArray )
_ArrayDelete( $aArray, 0 )

_ArraySort($aArray)
_ArrayDisplay($aArray)
EndFunc ;==>_ListVars

Func Strip_Comments_Quotes($sString)

Local $Ret, $Comment = False
Local $aArray = StringRegExp($sString, '(?m)(?:[^\r\n]+[\r\n]|[^\r\n]+$)', 3)
;_ArrayDisplay( $aArray )
For $a = 0 To UBound($aArray) - 1
$sString = $aArray[$a]

;Replace the Quotes
$aRet = StringRegExpReplace($sString, '(?s)([''"])(.*?\1)', '')

;Number of Semi-Colon in comments
StringRegExpReplace($aRet, ';', '')
$Comment = @extended

;Replace the Comments
$aRet = StringRegExpReplace($aRet, '(?m)(;.*?$)', '')

;Check Comments
If $Comment Then
;Replace the first semicolon which starts the comment
$sString = StringRegExpReplace($sString, '(.*)(;[^;\r\n]*){' & $Comment & '}', '\1')
EndIf
$Ret &= $sString
Next

Return $Ret
EndFunc ;==>Strip_Comments_Quotes
Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Posted

SciTE Jump can provide a list as well.

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Posted

Which version of Tidy do you run? This information is displayed in the Scite output pane.

Tidy AutoIt3 v2.2.2.0 Copyright © Jos van der Zande February 19, 2012

I was one version back with SciTE, but have since updated.

Here's the output from SciTE

>Running Tidy (2.2.2.0) from:C:\Program Files\AutoIt3\SciTE\tidy
Documentation file:D:\AutoIt\AutoIt scripts\TOOLS\CountVariables\CountVariables_tidy.txt
+>12:53:52 Tidy ended.rc:0

The file created by Tidy shows the output I quoted earlier. The line I don't understand is

"#### indicates that this specific variable only occurs one time in the script."

In the output, there are variables that do only exist once, but they aren't indicated by "####"

Perhaps I don't understand how to tell via the xxxx_tidy.txt which variables occur only once, other than by counting the rows that the vars appear in.

Posted (edited)

SciTE Jump can provide a list as well.

Thanks. I have it in my Tools dropdown, but when I call it up, the list says "No jump data found" is all I see. It's either not installed properly, or more likely, I don't know how to use it.

It definitely helps to run it with an app that has functions. :-)

I don't see how to generate a variables list though.

Edited by VelvetElvis

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
×
×
  • Create New...