guinness Posted June 28, 2013 Share Posted June 28, 2013 I think it's always great to share ideas/code and since my thread on 'Good coding practice' has been a success, I thought I would create a space for Au3 script related content. Note: Clean and workable code is recommended. 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 Link to comment Share on other sites More sharing options...
guinness Posted June 28, 2013 Author Share Posted June 28, 2013 (edited) Get all includes used in a Au3 Script file.expandcollapse popup#include <Array.au3> #include <Constants.au3> #include <WinAPIEx.au3> ; By Yashied. Example() Func Example() ; Au3 Script. Local Const $sFilePath = @ScriptFullPath ; Create a string variable to hold includes found. Local $sIncludeString = '' Local $hTimer = TimerInit() If _GetIncludes($sFilePath, $sIncludeString) Then ConsoleWrite(TimerDiff($hTimer) & @CRLF) ; Split the string. Local Const $aIncludes = StringSplit($sIncludeString, '|') _ArrayDisplay($aIncludes) EndIf EndFunc ;==>Example Func _GetIncludes($sFilePath, ByRef $sIncludeString) Local Static $iRecursionCall = 0, _ $sIncludePath = _WinAPI_PathRemoveFileSpec(@AutoItExe) & '\Include', $sUserIncludePath = '' If Not $iRecursionCall Then If $sUserIncludePath = '' Then $sUserIncludePath = RegRead('HKEY_CURRENT_USER\SOFTWARE\AutoIt v3\AutoIt', 'Include') If $sUserIncludePath = '' Then $sUserIncludePath = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt', 'Include') EndIf If Not ($sUserIncludePath = '') Then If StringLeft($sUserIncludePath, 1) == ';' Then $sUserIncludePath = StringTrimLeft($sUserIncludePath, 1) EndIf If Not (StringRight($sUserIncludePath, 1) == ';') Then $sUserIncludePath &= ';' EndIf EndIf EndIf $sIncludeString &= $sFilePath & '|' EndIf Local Const $sFileFolder = _WinAPI_PathRemoveFileSpec($sFilePath) ; StringLeft($sFilePath, StringInStr($sFilePath, '\', Default, -1) - 1) Local $fFileExists = False, _ $iAutoItInclude = 1 Local Const $aFilePaths[2] = [$sFileFolder, $sIncludePath] Local $aArray = StringRegExp(FileRead($sFilePath), '(?im)^#include\h*([<"''][^*?"''<>|]+)', 3) For $i = 0 To UBound($aArray) - 1 Switch StringLeft($aArray[$i], 1) Case '<' ; AutoIt includes, Registry, Relative path. $iAutoItInclude = 1 Case '''', '"' ; Relative path, Registry, AutoIt includes. $iAutoItInclude = 0 EndSwitch $aArray[$i] = StringStripWS(StringTrimLeft($aArray[$i], 1), $STR_STRIPLEADING + $STR_STRIPTRAILING) $fFileExists = FileExists($aArray[$i]) If Not (StringMid($aArray[$i], 2, 2) == ':\') Or Not $fFileExists Then $fFileExists = FileExists($aFilePaths[$iAutoItInclude] & '\' & $aArray[$i]) If $fFileExists Then $aArray[$i] = $aFilePaths[$iAutoItInclude] & '\' & $aArray[$i] Else $aIncludesSplit = StringSplit($sUserIncludePath & $aFilePaths[Int(Not $iAutoItInclude)], ';') For $j = 1 To $aIncludesSplit[0] $aIncludesSplit[$j] = _WinAPI_PathRemoveBackslash($aIncludesSplit[$j]) $aArray[$i] = $aIncludesSplit[$j] & '\' & $aArray[$i] $aArray[$i] = _WinAPI_GetFullPathName($aArray[$i]) $fFileExists = FileExists($aArray[$i]) If $fFileExists Then ExitLoop EndIf Next EndIf EndIf If $fFileExists And Not StringInStr('|' & $sIncludeString, '|' & $aArray[$i] & '|') Then $sIncludeString &= $aArray[$i] & '|' $iRecursionCall += 1 _GetIncludes($aArray[$i], $sIncludeString) $iRecursionCall -= 1 EndIf Next If Not $iRecursionCall Then $sIncludeString = StringTrimLeft($sIncludeString, StringInStr($sIncludeString, '|', Default, 1)) ; Remove the main script file. $sIncludeString = StringTrimRight($sIncludeString, StringLen('|')) EndIf Return Not ($sIncludeString == '') EndFunc ;==>_GetIncludes Edited June 28, 2013 by guinness mLipok and mesale0077 2 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 Link to comment Share on other sites More sharing options...
mesale0077 Posted June 28, 2013 Share Posted June 28, 2013 ; If Not $iRecursionCall Then ; $sIncludeString = StringTrimLeft($sIncludeString, StringInStr($sIncludeString, '|', $STR_NOCASESENSEBASIC, 1)) ; Remove the main script file. ; $sIncludeString = StringTrimRight($sIncludeString, StringLen('|')) ; EndIf line 89 error ? thank you Link to comment Share on other sites More sharing options...
guinness Posted June 28, 2013 Author Share Posted June 28, 2013 Fixed. Totally my own fault, I'm currently using a modified (beta) version of the Constants file. That variable is basically 2, but anyway Default for StringInStr is suffice. 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 Link to comment Share on other sites More sharing options...
guinness Posted June 28, 2013 Author Share Posted June 28, 2013 (edited) Strip an Au3 script of comments and whitespace.expandcollapse popupExample() Func Example() ; Au3 Script. Local Const $sFilePath = @ScriptFullPath ; Read the filepath. Local $sData = FileRead($sFilePath) _StripWhitespace($sData) ; Strip whitespace at the start and end of a line. _StripCommentLines($sData) ; Strip comment lines. _StripMerge($sData) ; Merge continuation lines e.g. 'Some string ' & _ _StripWhitespace($sData) ; Strip whitespace at the start and end of a line (leftover from stripping the comments.) _StripEmptyLines($sData) ; Strip empty lines. ConsoleWrite($sData & @CRLF) EndFunc ;==>Example Func _ConvertCRToCRLF(ByRef $sData) $sData = StringRegExpReplace(@LF & $sData, '\r(?!\n)', @CRLF) ; By DXRW4E. http://www.autoitscript.com/forum/topic/157255-regular-expression-challenge-for-stripping-single-comments/ EndFunc ;==>_ConvertCRToCRLF Func _StripCommentLines(ByRef $sData, $sReplace = Default) If $sReplace = Default Then $sReplace = '' EndIf _ConvertCRToCRLF($sData) $sData = StringTrimLeft(StringRegExpReplace($sData, '\n[^;"''\r\n]*(?:[^;"''\r\n]|''[^''\r\n]*''|"[^"\r\n]*")*\K;[^\r\n]*', ''), StringLen(@LF)) ; By DXRW4E. http://www.autoitscript.com/forum/topic/157255-regular-expression-challenge-for-stripping-single-comments/ $sData = StringRegExpReplace($sData, '(?ims:^\h*#(?:cs|comments-start)(?!\w).+?#(?:ce|comments-end)[^\r\n]*\R)', $sReplace) ; Strip comment blocks to avoid unintended matches. By Robjong $sData = StringRegExpReplace($sData, '(?im:^#(?:(?:end)?region)(?!\w)[^\r\n]+\R)', $sReplace) ; By DXRW4E. Fixed by guinness. $sData = StringRegExpReplace($sData, '(?im:^#(?!autoit|force(def|ref)|ignorefunc|include(-once)?|' & _ 'noautoit|notrayicon|onautoitstartregister|obfuscator|pragma|requireadmin|tidy)[^\r\n]*\R)', $sReplace) ; Strip user custom comments. By guinness. EndFunc ;==>_StripCommentLines Func _StripEmptyLines(ByRef $sData) $sData = StringRegExpReplace($sData, '(?m:^\h*\R)', '') ; Empty lines. By guinness. EndFunc ;==>_StripEmptyLines Func _StripMerge(ByRef $sData) $sData = StringRegExpReplace($sData, '(?:_\h*\R\h*)', '') ; Merge continuation lines that use _. By guinness. EndFunc ;==>_StripMerge Func _StripWhitespace(ByRef $sData) $sData = StringRegExpReplace($sData, '\h+(?=\R)', '') ; Trailing whitespace. By DXRW4E. $sData = StringRegExpReplace($sData, '\R\h+', @CRLF) ; Strip leading whitespace. By DXRW4E. EndFunc ;==>_StripWhitespace Edited January 15, 2014 by guinness 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 Link to comment Share on other sites More sharing options...
guinness Posted June 28, 2013 Author Share Posted June 28, 2013 (edited) List all the unique variables in an Au3 script.expandcollapse popup#include <Array.au3> Example() Func Example() ; Au3 Script. Local Const $sFilePath = @ScriptFullPath ; Read the filepath. Local $sData = FileRead($sFilePath) Local $aVariables = _GetUniqueVariableNames($sData) ; Get a list of unique variables used in the Au3 script. _ArrayDisplay($aVariables) EndFunc ;==>Example #Obfuscator_Off Func _AssociativeArray_Startup(ByRef $aArray, $fIsCaseSensitive = False) ; Idea from MilesAhead. Local $fReturn = False $aArray = ObjCreate('Scripting.Dictionary') ObjEvent('AutoIt.Error', '__AssociativeArray_Error') If IsObj($aArray) Then $aArray.CompareMode = Int(Not $fIsCaseSensitive) $fReturn = True EndIf Return $fReturn EndFunc ;==>_AssociativeArray_Startup #Obfuscator_On Func _GetUniqueVariableNames($sData, $fIsCount = Default) ; Return zeroth index with count. _StripStringLiterals($sData) ; Strip string literals, so they don't display possible variables matches. Local $aVariables = StringRegExp($sData, '(\$\w+)', 3), $hVariables = 0 _AssociativeArray_Startup($hVariables) If $fIsCount Then $hVariables('Count') = 'Count' For $i = 0 To UBound($aVariables) - 1 $hVariables($aVariables[$i]) = $aVariables[$i] Next $aVariables = $hVariables.Items() If $fIsCount Then $aVariables[0] = UBound($aVariables) - 1 Return $aVariables EndFunc ;==>_GetUniqueVariableNames Func _StripStringLiterals(ByRef $sData) $sData = StringRegExpReplace($sData, '([''"])\V*?\1', '') ; Strip string literals. By PhoenixXL & guinness. EndFunc ;==>_StripStringLiterals Edited January 15, 2014 by guinness Taskms4 and mesale0077 1 1 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 Link to comment Share on other sites More sharing options...
guinness Posted June 28, 2013 Author Share Posted June 28, 2013 (edited) Parse the au3.api file. This can be found in the SciTE directory.expandcollapse popup#include <Constants.au3> ParseAPI() Func ParseAPI() ; Idea by Mat and guinness Local $sFileRead = FileRead(@ProgramFilesDir & '\AutoIt3\SciTE\api\au3.api') Local $sClipPut = '#include-once' & @CRLF & @CRLF, $aDirectives = 0, $sDirectives = '' __ParseAPI($sFileRead, $aDirectives, $sDirectives, 'Directives', '(?m:^(\S+)\?[12])') $sClipPut &= $sDirectives & @CRLF ConsoleWrite($sDirectives & @CRLF) Local $aFunctions = 0, $sFunctions = '' __ParseAPI($sFileRead, $aFunctions, $sFunctions, 'Functions', '(?m:^((?!_)\w+)\s+\()') $sClipPut &= @CRLF & $sFunctions & @CRLF ConsoleWrite(@CRLF & $sFunctions & @CRLF) Local $aFunctionsUDF = 0, $sFunctionsUDF = '' __ParseAPI($sFileRead, $aFunctionsUDF, $sFunctionsUDF, 'FunctionsUDF', '(?m:^((?=_)\w+)\s+\()') $sClipPut &= @CRLF & $sFunctionsUDF & @CRLF ConsoleWrite(@CRLF & $sFunctionsUDF & @CRLF) Local $aKeywords = 0, $sKeywords = '' __ParseAPI($sFileRead, $aKeywords, $sKeywords, 'Keywords', '(?m:^(\w+)\?4)') $sClipPut &= @CRLF & $sKeywords & @CRLF ConsoleWrite(@CRLF & $sKeywords & @CRLF) Local $aMacros = 0, $sMacros = '' __ParseAPI($sFileRead, $aMacros, $sMacros, 'Macros', '(?m:^(@\w+)\?3)') $sClipPut &= @CRLF & $sMacros & @CRLF ConsoleWrite(@CRLF & $sMacros & @CRLF) ClipPut($sClipPut) EndFunc ;==>ParseAPI Func __ParseAPI(ByRef $sData, ByRef $aArray, ByRef $sString, $sParseName, $sParsePattern) $aArray = StringRegExp($sData, $sParsePattern, 3) _ArrayUniqueFast($aArray, 0, UBound($aArray) - 1) $sString = 'Func _' & $sParseName & 'Strings() ; Compiled using au3.api from v' & @AutoItVersion & '.' & @CRLF & @TAB & 'Local $s' & $sParseName & ' = ''' Local $sStringTemp = '' For $i = 1 To $aArray[0] If StringLen($sStringTemp) > 250 Then $sStringTemp = $sStringTemp & ''' & _' & @CRLF $sString &= $sStringTemp $sStringTemp = @TAB & @TAB & @TAB & '''' EndIf $sStringTemp &= $aArray[$i] & '|' Next If $sStringTemp Then $sString &= StringTrimRight($sStringTemp, StringLen('|')) & '''' EndIf $sString &= @CRLF & @TAB & 'Return $s' & $sParseName & @CRLF & 'EndFunc ;==>_' & $sParseName & 'Strings' EndFunc ;==>__ParseAPI #Obfuscator_Off Func _ArrayUniqueFast(ByRef $aArray, $iStart, $iEnd, $fIsCaseSensitive = False) ; By Yashied. Taken from: http://www.autoitscript.com/forum/topic/122192-arraysort-and-eliminate-duplicates/#entry849187 Local Const $sSep = ChrW(160) Local $hUnique = 0, _ $sOutput = '' _AssociativeArray_Startup($hUnique, $fIsCaseSensitive) For $i = $iStart To $iEnd If Not $hUnique.Exists($aArray[$i]) Then $hUnique.Item($aArray[$i]) $sOutput &= $aArray[$i] & $sSep EndIf Next $hUnique = 0 $sOutput = StringTrimRight($sOutput, StringLen($sSep)) $aArray = StringSplit($sOutput, $sSep, $STR_ENTIRESPLIT) EndFunc ;==>_ArrayUniqueFast #Obfuscator_On #Obfuscator_Off Func _AssociativeArray_Startup(ByRef $aArray, $fIsCaseSensitive = False) ; Idea from MilesAhead. Local $fReturn = False $aArray = ObjCreate('Scripting.Dictionary') ObjEvent('AutoIt.Error', '__AssociativeArray_Error') If IsObj($aArray) Then $aArray.CompareMode = Int(Not $fIsCaseSensitive) $fReturn = True EndIf Return $fReturn EndFunc ;==>_AssociativeArray_Startup #Obfuscator_On Edited December 24, 2013 by guinness 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 Link to comment Share on other sites More sharing options...
guinness Posted June 28, 2013 Author Share Posted June 28, 2013 Display lines that contain 4096+ characters. #include <Array.au3> #include <Constants.au3> Example() Func Example() ; Au3 Script. Local Const $sFilePath = @ScriptFullPath ; Read the filepath. Local $sData = FileRead($sFilePath) Local $aLongLines = _GetLongLines($sData) ; Will display an array of lines containing 4096+ characters. If @error Then MsgBox($MB_SYSTEMMODAL, '', 'All lines appear to be within the 4096 character limit.') Else _ArrayDisplay($aLongLines) EndIf EndFunc ;==>Example Func _GetLongLines($sData) Local $aLongLines = StringRegExp($sData, '(?m)^[^\r\n]{4096,}', 3) Return SetError(@error, @extended, $aLongLines) EndFunc ;==>_GetLongLines 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 Link to comment Share on other sites More sharing options...
Ascend4nt Posted June 29, 2013 Share Posted June 29, 2013 Nice collection of scripts, guinness My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
guinness Posted June 29, 2013 Author Share Posted June 29, 2013 Thanks. Just improving my knowledge of regular expressions and applying to practical usage. 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 Link to comment Share on other sites More sharing options...
Mat Posted June 29, 2013 Share Posted June 29, 2013 Theres a few things I've done based on this. I wrote a parser+lexer for AutoIt over a weekend. The code isn't the best quality, but maybe there are some good ideas there. AuLex_GenDb.au3 reads the SciTE api files and makes arrays of keywords and macros (just needs to be run once). Then AuLex.au3 is the lexer and AuParse.au3 is the parser. These were written very quickly, and are by no means complete, so aren't really of much use. There is also a lot of custom parsing code in Au3Int as well for using with variable declarations. AutoIt Project Listing Link to comment Share on other sites More sharing options...
guinness Posted June 29, 2013 Author Share Posted June 29, 2013 Fixed an error in post >#7, with parsing the au3.api file. A pipe bar was appended to the end of the continuation line. 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 Link to comment Share on other sites More sharing options...
guinness Posted June 29, 2013 Author Share Posted June 29, 2013 (edited) Display used functions in a script file. (Doesn't look in includes.)expandcollapse popup#include <Array.au3> #include <Constants.au3> Example() Func Example() ; Au3 Script. Local Const $sFilePath = @ScriptFullPath ; Read the filepath. Local $sData = FileRead($sFilePath) _StripStringLiterals($sData) ; Strip string literals. _StripWhitespace($sData) ; Strip whitespace at the start and end of a line. _StripCommentLines($sData) ; Strip comment lines. _StripDirectives($sData) ; Strip directive lines. _StripNativeFunctions($sData) ; Strip native functions. _StripMerge($sData) ; Merge continuation lines e.g. 'Some string ' & _ _StripWhitespace($sData) ; Strip whitespace at the start and end of a line (leftover from stripping the comments.) _StripEmptyLines($sData) ; Strip empty lines. Local $aUsedUDFs = _GetUsedUDFs($sData) ; Will display an array containing used functions. If @error Then MsgBox($MB_SYSTEMMODAL, '', 'An error occurred when finding the used functions in a script.') Else _ArrayDisplay($aUsedUDFs) EndIf EndFunc ;==>Example Func ThisIsAnUnusedFunction(); This function shouldn't display in the array. Return True EndFunc ;==>ThisIsAnUnusedFunction Func _ConvertCRToCRLF(ByRef $sData) $sData = StringRegExpReplace(@LF & $sData, '\r(?!\n)', @CRLF) ; By DXRW4E. http://www.autoitscript.com/forum/topic/157255-regular-expression-challenge-for-stripping-single-comments/ EndFunc ;==>_ConvertCRToCRLF Func _GetUsedUDFs($sData) Local $aUsedUDFs = StringRegExp($sData, '(?<!\.|#|\$|\@|Func\s)\b(\w+)\b\(', 3) Return SetError(@error, @extended, $aUsedUDFs) EndFunc ;==>_GetUsedUDFs Func _StripCommentLines(ByRef $sData, $sReplace = Default) If $sReplace = Default Then $sReplace = '' EndIf _ConvertCRToCRLF($sData) $sData = StringTrimLeft(StringRegExpReplace($sData, '\n[^;"''\r\n]*(?:[^;"''\r\n]|''[^''\r\n]*''|"[^"\r\n]*")*\K;[^\r\n]*', ''), StringLen(@LF)) ; By DXRW4E. http://www.autoitscript.com/forum/topic/157255-regular-expression-challenge-for-stripping-single-comments/ $sData = StringRegExpReplace($sData, '(?ims:^\h*#(?:cs|comments-start)(?!\w).+?#(?:ce|comments-end)[^\r\n]*\R)', $sReplace) ; Strip comment blocks to avoid unintended matches. By Robjong $sData = StringRegExpReplace($sData, '(?im:^#(?:(?:end)?region)(?!\w)[^\r\n]+\R)', $sReplace) ; By DXRW4E. Fixed by guinness. $sData = StringRegExpReplace($sData, '(?im:^#(?!autoit|force(def|ref)|ignorefunc|include(-once)?|' & _ 'noautoit|notrayicon|onautoitstartregister|obfuscator|pragma|requireadmin|tidy)[^\r\n]*\R)', $sReplace) ; Strip user custom comments. By guinness. EndFunc ;==>_StripCommentLines Func _StripDirectives(ByRef $sData) $sData = StringRegExpReplace($sData, '(?m:^#.*$)', '') ; Strip directives. By guinness. EndFunc ;==>_StripDirectives Func _StripEmptyLines(ByRef $sData) $sData = StringRegExpReplace($sData, '(?m:^\h*\R)', '') ; Empty lines. By guinness. EndFunc ;==>_StripEmptyLines Func _StripMerge(ByRef $sData) $sData = StringRegExpReplace($sData, '(?:_\h*\R\h*)', '') ; Merge continuation lines that use _. By guinness. EndFunc ;==>_StripMerge Func _StripNativeFunctions(ByRef $sData) $sData = StringRegExpReplace($sData, '(\b' & _FunctionsStrings() & '\b)\(', '') ; Strip native functons. By guinness. EndFunc ;==>_StripNativeFunctions Func _StripStringLiterals(ByRef $sData) $sData = StringRegExpReplace($sData, '([''"])\V*?\1', '') ; Strip string literals. By PhoenixXL & guinness. EndFunc ;==>_StripStringLiterals Func _StripWhitespace(ByRef $sData) $sData = StringRegExpReplace($sData, '\h+(?=\R)', '') ; Trailing whitespace. By DXRW4E. $sData = StringRegExpReplace($sData, '\R\h+', @CRLF) ; Strip leading whitespace. By DXRW4E. EndFunc ;==>_StripWhitespace Func _FunctionsStrings() ; Compiled using au3.api from v3.3.10.0. Local $sFunctions = 'Abs|ACos|AdlibRegister|AdlibUnRegister|Asc|AscW|ASin|Assign|ATan|AutoItSetOption|AutoItWinGetTitle|AutoItWinSetTitle|Beep|Binary|BinaryLen|BinaryMid|BinaryToString|BitAND|BitNOT|BitOR|BitRotate|BitShift|BitXOR|BlockInput|Break|Call|CDTray|Ceiling|Chr|' & _ 'ChrW|ClipGet|ClipPut|ConsoleRead|ConsoleWrite|ConsoleWriteError|ControlClick|ControlCommand|ControlDisable|ControlEnable|ControlFocus|ControlGetFocus|ControlGetHandle|ControlGetPos|ControlGetText|ControlHide|ControlListView|ControlMove|ControlSend|' & _ 'ControlSetText|ControlShow|ControlTreeView|Cos|Dec|DirCopy|DirCreate|DirGetSize|DirMove|DirRemove|DllCall|DllCallAddress|DllCallbackFree|DllCallbackGetPtr|DllCallbackRegister|DllClose|DllOpen|DllStructCreate|DllStructGetData|DllStructGetPtr|DllStructGetSize|' & _ 'DllStructSetData|DriveGetDrive|DriveGetFileSystem|DriveGetLabel|DriveGetSerial|DriveGetType|DriveMapAdd|DriveMapDel|DriveMapGet|DriveSetLabel|DriveSpaceFree|DriveSpaceTotal|DriveStatus|EnvGet|EnvSet|EnvUpdate|Eval|Execute|Exp|FileChangeDir|FileClose|' & _ 'FileCopy|FileCreateNTFSLink|FileCreateShortcut|FileDelete|FileExists|FileFindFirstFile|FileFindNextFile|FileFlush|FileGetAttrib|FileGetEncoding|FileGetLongName|FileGetPos|FileGetShortcut|FileGetShortName|FileGetSize|FileGetTime|FileGetVersion|FileInstall|' & _ 'FileMove|FileOpen|FileOpenDialog|FileRead|FileReadLine|FileReadToArray|FileRecycle|FileRecycleEmpty|FileSaveDialog|FileSelectFolder|FileSetAttrib|FileSetPos|FileSetTime|FileWrite|FileWriteLine|Floor|FtpSetProxy|FuncName|GUICreate|GUICtrlCreateAvi|' & _ 'GUICtrlCreateButton|GUICtrlCreateCheckbox|GUICtrlCreateCombo|GUICtrlCreateContextMenu|GUICtrlCreateDate|GUICtrlCreateDummy|GUICtrlCreateEdit|GUICtrlCreateGraphic|GUICtrlCreateGroup|GUICtrlCreateIcon|GUICtrlCreateInput|GUICtrlCreateLabel|GUICtrlCreateList|' & _ 'GUICtrlCreateListView|GUICtrlCreateListViewItem|GUICtrlCreateMenu|GUICtrlCreateMenuItem|GUICtrlCreateMonthCal|GUICtrlCreateObj|GUICtrlCreatePic|GUICtrlCreateProgress|GUICtrlCreateRadio|GUICtrlCreateSlider|GUICtrlCreateTab|GUICtrlCreateTabItem|GUICtrlCreateTreeView|' & _ 'GUICtrlCreateTreeViewItem|GUICtrlCreateUpdown|GUICtrlDelete|GUICtrlGetHandle|GUICtrlGetState|GUICtrlRead|GUICtrlRecvMsg|GUICtrlRegisterListViewSort|GUICtrlSendMsg|GUICtrlSendToDummy|GUICtrlSetBkColor|GUICtrlSetColor|GUICtrlSetCursor|GUICtrlSetData|' & _ 'GUICtrlSetDefBkColor|GUICtrlSetDefColor|GUICtrlSetFont|GUICtrlSetGraphic|GUICtrlSetImage|GUICtrlSetLimit|GUICtrlSetOnEvent|GUICtrlSetPos|GUICtrlSetResizing|GUICtrlSetState|GUICtrlSetStyle|GUICtrlSetTip|GUIDelete|GUIGetCursorInfo|GUIGetMsg|GUIGetStyle|' & _ 'GUIRegisterMsg|GUISetAccelerators|GUISetBkColor|GUISetCoord|GUISetCursor|GUISetFont|GUISetHelp|GUISetIcon|GUISetOnEvent|GUISetState|GUISetStyle|GUIStartGroup|GUISwitch|Hex|HotKeySet|HttpSetProxy|HttpSetUserAgent|HWnd|InetClose|InetGet|InetGetInfo|' & _ 'InetGetSize|InetRead|IniDelete|IniRead|IniReadSection|IniReadSectionNames|IniRenameSection|IniWrite|IniWriteSection|InputBox|Int|IsAdmin|IsArray|IsBinary|IsBool|IsDeclared|IsDllStruct|IsFloat|IsFunc|IsHWnd|IsInt|IsKeyword|IsNumber|IsObj|IsPtr|IsString|' & _ 'Log|MemGetStats|Mod|MouseClick|MouseClickDrag|MouseDown|MouseGetCursor|MouseGetPos|MouseMove|MouseUp|MouseWheel|MsgBox|Number|ObjCreate|ObjCreateInterface|ObjEvent|ObjGet|ObjName|OnAutoItExitRegister|OnAutoItExitUnRegister|Opt|Ping|PixelChecksum|PixelGetColor|' & _ 'PixelSearch|ProcessClose|ProcessExists|ProcessGetStats|ProcessList|ProcessSetPriority|ProcessWait|ProcessWaitClose|ProgressOff|ProgressOn|ProgressSet|Ptr|Random|RegDelete|RegEnumKey|RegEnumVal|RegRead|RegWrite|Round|Run|RunAs|RunAsWait|RunWait|Send|' & _ 'SendKeepActive|SetError|SetExtended|ShellExecute|ShellExecuteWait|Shutdown|Sin|Sleep|SoundPlay|SoundSetWaveVolume|SplashImageOn|SplashOff|SplashTextOn|Sqrt|SRandom|StatusbarGetText|StderrRead|StdinWrite|StdioClose|StdoutRead|String|StringAddCR|StringCompare|' & _ 'StringFormat|StringFromASCIIArray|StringInStr|StringIsAlNum|StringIsAlpha|StringIsASCII|StringIsDigit|StringIsFloat|StringIsInt|StringIsLower|StringIsSpace|StringIsUpper|StringIsXDigit|StringLeft|StringLen|StringLower|StringMid|StringRegExp|StringRegExpReplace|' & _ 'StringReplace|StringReverse|StringRight|StringSplit|StringStripCR|StringStripWS|StringToASCIIArray|StringToBinary|StringTrimLeft|StringTrimRight|StringUpper|Tan|TCPAccept|TCPCloseSocket|TCPConnect|TCPListen|TCPNameToIP|TCPRecv|TCPSend|TCPShutdown|' & _ 'TCPStartup|TimerDiff|TimerInit|ToolTip|TrayCreateItem|TrayCreateMenu|TrayGetMsg|TrayItemDelete|TrayItemGetHandle|TrayItemGetState|TrayItemGetText|TrayItemSetOnEvent|TrayItemSetState|TrayItemSetText|TraySetClick|TraySetIcon|TraySetOnEvent|TraySetPauseIcon|' & _ 'TraySetState|TraySetToolTip|TrayTip|UBound|UDPBind|UDPCloseSocket|UDPOpen|UDPRecv|UDPSend|UDPShutdown|UDPStartup|VarGetType|WinActivate|WinActive|WinClose|WinExists|WinFlash|WinGetCaretPos|WinGetClassList|WinGetClientSize|WinGetHandle|WinGetPos|WinGetProcess|' & _ 'WinGetState|WinGetText|WinGetTitle|WinKill|WinList|WinMenuSelectItem|WinMinimizeAll|WinMinimizeAllUndo|WinMove|WinSetOnTop|WinSetState|WinSetTitle|WinSetTrans|WinWait|WinWaitActive|WinWaitClose|WinWaitNotActive' Return $sFunctions EndFunc ;==>_FunctionsStrings Func ShouldNotDisplayInTheArray() ; This function shouldn't display in the array. Return True EndFunc ;==>ShouldNotDisplayInTheArray Edited January 15, 2014 by guinness 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 Link to comment Share on other sites More sharing options...
guinness Posted June 29, 2013 Author Share Posted June 29, 2013 (edited) Updated post >#5 and >#13, as I was stripping the #ignorefunc directive by mistake. Edit: It exists, though not documented nor used anymore. Edited June 29, 2013 by guinness 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 Link to comment Share on other sites More sharing options...
guinness Posted June 30, 2013 Author Share Posted June 30, 2013 Remove functions in an Au3 script file. (Note: The functions to retain are in the negative lookahead.): Example() Func Example() ; Read the file. Local $sData = FileRead(@ScriptFullPath) ; Strip functions not in the list e.g. retain Example and _ConsoleWrite. $sData = StringRegExpReplace($sData & @CRLF, '(?ims:^Func(?!\w)\h+(?!\bExample\b|\b_ConsoleWrite\b).*?(?<!\w|\$)EndFunc(?!\w)[^\r\n]*[\r\n]*)', '') _ConsoleWrite($sData) EndFunc Func _ThisWillBeDestroyed() ; Will be removed. EndFunc Func SoWillThis() ; Will be removed. EndFunc Func _ConsoleWrite($sData) Return ConsoleWrite($sData & @CRLF) EndFunc Func _ConsoleWriteEx($sData) ; Will be removed. Return ConsoleWrite($sData & @CRLF) EndFunc 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 Link to comment Share on other sites More sharing options...
guinness Posted July 1, 2013 Author Share Posted July 1, 2013 (edited) Despite comments (; & #) being stripped in post >#13, I was working on some code that didn't strip the functions and therefore changed the regular expression to exclude comments such as #ThisIsACommentThatShouldntBeAFunction(. Edited July 1, 2013 by guinness 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 Link to comment Share on other sites More sharing options...
guinness Posted July 29, 2013 Author Share Posted July 29, 2013 Parse strings literals in a script file. expandcollapse popup#include <Array.au3> #include <Constants.au3> Example() Func Example() ; Read the script file. Local $sData = FileRead(@ScriptFullPath) ; Convert strings to RANDOMSTRIG_STRINGS_RAND_STRINGS_RANDOMSTRIG. Local $hStrings = _Strings_Get($sData) If ClipPut($sData) Then MsgBox($MB_SYSTEMMODAL, '', 'Copied example of replaced strings to the clipboard. Paste to see the result(s).') ; Expand the strings back their original format. _Strings_Set($hStrings, $sData) If ClipPut($sData) Then MsgBox($MB_SYSTEMMODAL, '', 'Copied example of reverting strings to the clipboard. Paste to see the result(s).') EndFunc ;==>Example Func _Strings_Get(ByRef $sData) Local Enum $eStrings_AssociativeArray, $eStrings_Array, $eStrings_UniqueID, $eStrings_Max Local $aAPI[$eStrings_Max] ; Create a random ID. SRandom(@HOUR & @MIN & @MSEC) For $i = 1 To 10 $aAPI[$eStrings_UniqueID] &= Chr(Random(65, 90, 1)) Next ; Create an associative array object. Local Const $sStringsAfter = '_' & $aAPI[$eStrings_UniqueID] & '_STRINGS', $sStringsBefore = 'STRINGS_' & $aAPI[$eStrings_UniqueID] & '_', _ $sStringsPattern = '(([''"])\V*?\2)' _AssociativeArray_Startup($aAPI[$eStrings_AssociativeArray], True) ; Temporarily convert strings to a pre-defined format string. __PreProcessor_SRE($sData, $aAPI[$eStrings_Array], $aAPI[$eStrings_AssociativeArray], $sStringsPattern, $sStringsBefore, $sStringsAfter) Return $aAPI EndFunc ;==>_Strings_Get Func _Strings_Set(ByRef $aAPI, ByRef $sData) Local Enum $eStrings_AssociativeArray, $eStrings_Array, $eStrings_UniqueID, $eStrings_Max #forceref $eStrings_UniqueID, $eStrings_Max If UBound($aAPI) <> $eStrings_Max Then Return False EndIf ; Converting strings back to their original state. Return __PreProcessor_SRE_Replace($sData, $aAPI[$eStrings_Array], $aAPI[$eStrings_AssociativeArray]) EndFunc ;==>_Strings_Set #region Functions - Taken from various parsing scripts of mine. #Obfuscator_Off Func _AssociativeArray_Startup(ByRef $aArray, $fIsCaseSensitive = False) ; Idea from MilesAhead. $aArray = ObjCreate('Scripting.Dictionary') ObjEvent('AutoIt.Error', '__AssociativeArray_Error\\\') If IsObj($aArray) = 0 Then Return SetError(1, 0, 0) EndIf $aArray.CompareMode = Int(Not $fIsCaseSensitive) EndFunc ;==>_AssociativeArray_Startup #Obfuscator_On Func _GenerateUniqueIndex($iValue) ; Idea taken from __Array_Combinations. Local Const $UNIQUE_CHRS = 26 Local $iChrs = 0, $iStep = 0, $iTotal = 0 Do $iChrs = $UNIQUE_CHRS $iStep += 1 $iTotal = 1 For $i = $iStep To 1 Step -1 $iTotal *= ($iChrs / $i) $iChrs -= 1 Next Until $iValue <= $iTotal Return $iStep EndFunc ;==>_GenerateUniqueIndex Func _GenerateUniqueStrings($iSet = Default) ; By Beege, modified by guinness. 2011-2013. Local Static $fIsUniqueArray = False If $iSet = Default Then $iSet = 4 If Not $fIsUniqueArray Then $fIsUniqueArray = True Local Const $iSPUBound = 2 Local $aArray = StringSplit('A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z', '|', $iSPUBound) EndIf Local Static $aUnique = _ArrayCombinations($aArray, 4) Return $aUnique EndFunc ;==>_GenerateUniqueStrings Func _StringRegExpMetaCharacters($sString) Return StringRegExpReplace($sString, '([].|*?+(){}^$\\[])', '\\\1') EndFunc ;==>_StringRegExpMetaCharacters #endregion Functions - Taken from various parsing scripts of mine. #region Pre-Processor Functions Func __PreProcessor_SRE(ByRef $sData, ByRef $aArray, ByRef $hStrings, $sSREPattern, $sStringsBefore, $sStringsAfter, $sCheckBefore = Default, $sCheckAfter = Default, $iIndex = Default, $iStep = Default, $fExitFirstRound = Default) Local Enum $eStrings_Data, $eStrings_Index, $eStrings_Key, $eStrings_Max $iIndex = Int($iIndex) If $iIndex <= 0 Then $iIndex = 1 EndIf If $iStep = Default Then $iStep = 2 EndIf If $sCheckAfter = Default Then $sCheckAfter = '' If $sCheckBefore = Default Then $sCheckBefore = '' Local $aSRE = 0, $aUnique = _GenerateUniqueStrings(), _ $aStrings[1][$eStrings_Max] = [[0, $eStrings_Max]], _ $iCount = 1 Local $hStringsTemp = 0 _AssociativeArray_Startup($hStringsTemp, True) While 1 $aSRE = StringRegExp($sData, $sSREPattern, 3) If UBound($aSRE) = 0 Then ExitLoop ReDim $aStrings[$aStrings[0][0] + UBound($aSRE) + 1][$aStrings[0][1]] $iCount = $aStrings[0][0] + 1 For $i = 0 To UBound($aSRE) - 1 Step $iStep If Not $hStringsTemp.Exists($aSRE[$i]) Then $hStringsTemp($aSRE[$i]) = $aSRE[$i] $aStrings[0][0] += 1 $aStrings[$aStrings[0][0]][$eStrings_Data] = $aSRE[$i] $aStrings[$aStrings[0][0]][$eStrings_Index] = 0 $aStrings[$aStrings[0][0]][$eStrings_Key] = '' EndIf Next $hStringsTemp = 0 _AssociativeArray_Startup($hStringsTemp, True) For $i = $iCount To $aStrings[0][0] $aStrings[$i][$eStrings_Index] = $aUnique[$iIndex] $aStrings[$i][$eStrings_Key] = $sStringsBefore & $aStrings[$i][$eStrings_Index] & $sStringsAfter ; Replace the quote strings with temporary strings. ; '\Q' & $aStrings[$i][$eStrings_Data] & '\E' $sData = StringRegExpReplace($sData, $sCheckBefore & _StringRegExpMetaCharacters($aStrings[$i][$eStrings_Data]) & $sCheckAfter, $aStrings[$i][$eStrings_Key]) If @extended Then $hStrings($aStrings[$i][$eStrings_Key]) = $aStrings[$i][$eStrings_Data] Else $sData = StringReplace($sData, $aStrings[$i][$eStrings_Data], $aStrings[$i][$eStrings_Key]) ; For replacing \Q and \E. If @extended Then $hStrings($aStrings[$i][$eStrings_Key]) = $aStrings[$i][$eStrings_Data] Else $aStrings[$i][$eStrings_Data] = '' $aStrings[$i][$eStrings_Index] = 0 $aStrings[$i][$eStrings_Key] = '' EndIf EndIf $iIndex += 1 Next If $fExitFirstRound Then ExitLoop EndIf WEnd $aSRE = 0 ReDim $aStrings[$aStrings[0][0] + 1][$aStrings[0][1]] $aArray = $aStrings Return $iIndex EndFunc ;==>__PreProcessor_SRE Func __PreProcessor_SRE_Replace(ByRef $sData, ByRef $aStrings, ByRef $hStrings) Local Enum $eStrings_Data, $eStrings_Index, $eStrings_Key, $eStrings_Max #forceref $eStrings_Data, $eStrings_Max Local $iReplaced = 0 For $i = $aStrings[0][0] To 1 Step -1 If $aStrings[$i][$eStrings_Index] And $hStrings.Exists($aStrings[$i][$eStrings_Key]) Then $sData = StringReplace($sData, $aStrings[$i][$eStrings_Key], $hStrings($aStrings[$i][$eStrings_Key])) $iReplaced += @extended EndIf Next Return $aStrings[0][0] = $iReplaced EndFunc ;==>__PreProcessor_SRE_Replace #endregion Pre-Processor Functions 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 Link to comment Share on other sites More sharing options...
guinness Posted July 29, 2013 Author Share Posted July 29, 2013 Parse numbers in a script file. expandcollapse popup#include <Array.au3> #include <Constants.au3> Example() Func Example() ; Read the script file. Local $sData = FileRead(@ScriptFullPath) ; Convert numbers to RANDOMSTRIG_NUMBERS_RAND_NUMBERS_RANDOMSTRIG. Local $hNumbers = _Numbers_Get($sData) If ClipPut($sData) Then MsgBox($MB_SYSTEMMODAL, '', 'Copied example of replaced numbers to the clipboard. Paste to see the result(s).') ; Expand the numbers back their original format. _Numbers_Set($hNumbers, $sData) If ClipPut($sData) Then MsgBox($MB_SYSTEMMODAL, '', 'Copied example of reverting Numbers to the clipboard. Paste to see the result(s).') EndFunc ;==>Example Func _Numbers_Get(ByRef $sData) Local Enum $eNumbers_AssociativeArray, $eNumbers_Array, $eNumbers_UniqueID, $eNumbers_Max Local $aAPI[$eNumbers_Max] ; Create a random ID. SRandom(@HOUR & @MIN & @MSEC) For $i = 1 To 10 $aAPI[$eNumbers_UniqueID] &= Chr(Random(65, 90, 1)) Next ; Create an associative array object. Local Const $sNumbersAfter = '_' & $aAPI[$eNumbers_UniqueID] & '_NUMBERS', $sNumbersBefore = 'NUMBERS_' & $aAPI[$eNumbers_UniqueID] & '_', _ $sNumbersPattern = '(?i)((?<!\w)0x[A-F\d]+(?!\w)|(?<!\w)[+\-]?\d*\.?\d+e?[+\-]?\d*(?!\w))' _AssociativeArray_Startup($aAPI[$eNumbers_AssociativeArray], True) ; Temporarily convert numbers to a pre-defined format string. __PreProcessor_SRE($sData, $aAPI[$eNumbers_Array], $aAPI[$eNumbers_AssociativeArray], $sNumbersPattern, $sNumbersBefore, $sNumbersAfter) Return $aAPI EndFunc ;==>_Numbers_Get Func _Numbers_Set(ByRef $aAPI, ByRef $sData) Local Enum $eNumbers_AssociativeArray, $eNumbers_Array, $eNumbers_UniqueID, $eNumbers_Max #forceref $eNumbers_UniqueID, $eNumbers_Max If UBound($aAPI) <> $eNumbers_Max Then Return False EndIf ; Converting numbers back to their original state. Return __PreProcessor_SRE_Replace($sData, $aAPI[$eNumbers_Array], $aAPI[$eNumbers_AssociativeArray]) EndFunc ;==>_Numbers_Set #region Functions - Taken from various parsing scripts of mine. #Obfuscator_Off Func _AssociativeArray_Startup(ByRef $aArray, $fIsCaseSensitive = False) ; Idea from MilesAhead. $aArray = ObjCreate('Scripting.Dictionary') ObjEvent('AutoIt.Error', '__AssociativeArray_Error\\\') If IsObj($aArray) = 0 Then Return SetError(1, 0, 0) EndIf $aArray.CompareMode = Int(Not $fIsCaseSensitive) EndFunc ;==>_AssociativeArray_Startup #Obfuscator_On Func _GenerateUniqueIndex($iValue) ; Idea taken from __Array_Combinations. Local Const $UNIQUE_CHRS = 26 Local $iChrs = 0, $iStep = 0, $iTotal = 0 Do $iChrs = $UNIQUE_CHRS $iStep += 1 $iTotal = 1 For $i = $iStep To 1 Step -1 $iTotal *= ($iChrs / $i) $iChrs -= 1 Next Until $iValue <= $iTotal Return $iStep EndFunc ;==>_GenerateUniqueIndex Func _GenerateUniqueStrings($iSet = Default) ; By Beege, modified by guinness. 2011-2013. Local Static $fIsUniqueArray = False If $iSet = Default Then $iSet = 4 If Not $fIsUniqueArray Then $fIsUniqueArray = True Local Const $iSPUBound = 2 Local $aArray = StringSplit('A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z', '|', $iSPUBound) EndIf Local Static $aUnique = _ArrayCombinations($aArray, 4) Return $aUnique EndFunc ;==>_GenerateUniqueStrings Func _StringRegExpMetaCharacters($sString) Return StringRegExpReplace($sString, '([].|*?+(){}^$\\[])', '\\\1') EndFunc ;==>_StringRegExpMetaCharacters #endregion Functions - Taken from various parsing scripts of mine. #region Pre-Processor Functions Func __PreProcessor_SRE(ByRef $sData, ByRef $aArray, ByRef $hStrings, $sSREPattern, $sStringsBefore, $sStringsAfter, $sCheckBefore = Default, $sCheckAfter = Default, $iIndex = Default, $iStep = Default, $fExitFirstRound = Default) Local Enum $eStrings_Data, $eStrings_Index, $eStrings_Key, $eStrings_Max $iIndex = Int($iIndex) If $iIndex <= 0 Then $iIndex = 1 EndIf If $iStep = Default Then $iStep = 2 EndIf If $sCheckAfter = Default Then $sCheckAfter = '' If $sCheckBefore = Default Then $sCheckBefore = '' Local $aSRE = 0, $aUnique = _GenerateUniqueStrings(), _ $aStrings[1][$eStrings_Max] = [[0, $eStrings_Max]], _ $iCount = 1 Local $hStringsTemp = 0 _AssociativeArray_Startup($hStringsTemp, True) While 1 $aSRE = StringRegExp($sData, $sSREPattern, 3) If UBound($aSRE) = 0 Then ExitLoop ReDim $aStrings[$aStrings[0][0] + UBound($aSRE) + 1][$aStrings[0][1]] $iCount = $aStrings[0][0] + 1 For $i = 0 To UBound($aSRE) - 1 Step $iStep If Not $hStringsTemp.Exists($aSRE[$i]) Then $hStringsTemp($aSRE[$i]) = $aSRE[$i] $aStrings[0][0] += 1 $aStrings[$aStrings[0][0]][$eStrings_Data] = $aSRE[$i] $aStrings[$aStrings[0][0]][$eStrings_Index] = 0 $aStrings[$aStrings[0][0]][$eStrings_Key] = '' EndIf Next $hStringsTemp = 0 _AssociativeArray_Startup($hStringsTemp, True) For $i = $iCount To $aStrings[0][0] $aStrings[$i][$eStrings_Index] = $aUnique[$iIndex] $aStrings[$i][$eStrings_Key] = $sStringsBefore & $aStrings[$i][$eStrings_Index] & $sStringsAfter ; Replace the quote strings with temporary strings. ; '\Q' & $aStrings[$i][$eStrings_Data] & '\E' $sData = StringRegExpReplace($sData, $sCheckBefore & _StringRegExpMetaCharacters($aStrings[$i][$eStrings_Data]) & $sCheckAfter, $aStrings[$i][$eStrings_Key]) If @extended Then $hStrings($aStrings[$i][$eStrings_Key]) = $aStrings[$i][$eStrings_Data] Else $sData = StringReplace($sData, $aStrings[$i][$eStrings_Data], $aStrings[$i][$eStrings_Key]) ; For replacing \Q and \E. If @extended Then $hStrings($aStrings[$i][$eStrings_Key]) = $aStrings[$i][$eStrings_Data] Else $aStrings[$i][$eStrings_Data] = '' $aStrings[$i][$eStrings_Index] = 0 $aStrings[$i][$eStrings_Key] = '' EndIf EndIf $iIndex += 1 Next If $fExitFirstRound Then ExitLoop EndIf WEnd $aSRE = 0 ReDim $aStrings[$aStrings[0][0] + 1][$aStrings[0][1]] $aArray = $aStrings Return $iIndex EndFunc ;==>__PreProcessor_SRE Func __PreProcessor_SRE_Replace(ByRef $sData, ByRef $aStrings, ByRef $hStrings) Local Enum $eStrings_Data, $eStrings_Index, $eStrings_Key, $eStrings_Max #forceref $eStrings_Data, $eStrings_Max Local $iReplaced = 0 For $i = $aStrings[0][0] To 1 Step -1 If $aStrings[$i][$eStrings_Index] And $hStrings.Exists($aStrings[$i][$eStrings_Key]) Then $sData = StringReplace($sData, $aStrings[$i][$eStrings_Key], $hStrings($aStrings[$i][$eStrings_Key])) $iReplaced += @extended EndIf Next Return $aStrings[0][0] = $iReplaced EndFunc ;==>__PreProcessor_SRE_Replace #endregion Pre-Processor Functions 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 Link to comment Share on other sites
Recommended Posts