guinness Posted February 11, 2013 Share Posted February 11, 2013 (edited) I'm working on my "next project" and was wondering could someone test out the code below. It will basically list all the includes that are being used in a script file. Notice how it looks inside other UDFs to determine the includes used there as well. Magic! Thanks. expandcollapse popup#include <Array.au3> #include <Constants.au3> #include <File.au3> #include <WinAPIEx.au3> Global Const $STR_NOCASESENSEBASIC = 2 ; #include "myIncludes\Example.au3" ; For testing relative paths. Example() Func Example() ; Set the include folder path to the environment variable %PATH%. Local Const $sIncludePath = StringLeft(@AutoItExe, StringInStr(@AutoItExe, '\', $STR_NOCASESENSEBASIC, -1) - 1) & '\Include' _SetCurrentPath($sIncludePath) ; Set the Script folder path to the environment variable %PATH%. _SetCurrentPath(@ScriptDir) Local Const $aIncludes = _GetIncludes(@ScriptFullPath) _ArrayDisplay($aIncludes) EndFunc ;==>Example Func _GetIncludes($sFilePath) Local $aReturn[2] = [1, $sFilePath], _ $aArray = 0, $iAPIIndex = 0, $iCount = 1, $iIndex = 0, $sIncludesString = '|' Local Const $sFileFolder = StringLeft($sFilePath, StringInStr($sFilePath, '\', $STR_NOCASESENSEBASIC, -1) - 1) ; I would use WinAPIEx's _WinAPI_PathRemoveFileSpec. While Not ($iIndex = $iCount) $aArray = StringRegExp('#include <Count.au3>' & @CRLF & FileRead($aReturn[$iIndex + 1]), '(?im)^#include\h+[<"'']([^*?"''<>|]+)', 3) $aArray[0] = UBound($aArray) - 1 $iAPIIndex = $aReturn[0] + 1 ReDim $aReturn[$aArray[0] + $iAPIIndex] For $i = 1 To $aArray[0] $aReturn[$iAPIIndex] = _WinAPI_PathFindOnPath($aArray[$i]) If @error Then $aReturn[$iAPIIndex] = _PathFull($aReturn[$iAPIIndex], $sFileFolder) ; I would use WinAPIEx's _WinAPI_GetFullPathName. EndIf If StringInStr($sIncludesString, '|' & $aReturn[$iAPIIndex] & '|') Then $aReturn[$iAPIIndex] = '' Else $sIncludesString &= $aReturn[$iAPIIndex] & '|' $aReturn[0] += 1 $iAPIIndex += 1 EndIf Next $iCount = $aReturn[0] $iIndex += 1 WEnd $sIncludesString = '' Return $aReturn EndFunc ;==>_GetIncludes Func _SetCurrentPath($sFilePath) Return EnvSet('PATH', EnvGet('PATH') & ';' & $sFilePath) EndFunc ;==>_SetCurrentPath Edited February 11, 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...
BrewManNH Posted February 11, 2013 Share Posted February 11, 2013 Where do I find this variable declared? $STR_NOCASESENSEBASIC If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
guinness Posted February 11, 2013 Author Share Posted February 11, 2013 Oh, I'm using the beta version of the Includes and Mat added that to Constants.au3, it's number 2. Global Const $STR_NOCASESENSEBASIC = 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...
guinness Posted February 11, 2013 Author Share Posted February 11, 2013 Fixed regular expression. An error occurred when parsing includes that used a single quote. 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...
Mun Posted February 11, 2013 Share Posted February 11, 2013 Look good. expandcollapse popup[0]|47 [1]|C:\Users\Mun\Desktop\ProjectX\_Snip\ProjectX.au3 [2]|C:\Program Files (x86)\AutoIt3\Include\WindowsConstants.au3 [3]|C:\Program Files (x86)\AutoIt3\Include\StaticConstants.au3 [4]|C:\Program Files (x86)\AutoIt3\Include\ButtonConstants.au3 [5]|C:\Program Files (x86)\AutoIt3\Include\ComboConstants.au3 [6]|C:\Program Files (x86)\AutoIt3\Include\GUIConstants.au3 [7]|C:\Program Files (x86)\AutoIt3\Include\GuiImageList.au3 [8]|C:\Program Files (x86)\AutoIt3\Include\GUIListView.au3 [9]|C:\Program Files (x86)\AutoIt3\Include\WinAPIEx.au3 [10]|C:\Program Files (x86)\AutoIt3\Include\GuiEdit.au3 [11]|C:\Program Files (x86)\AutoIt3\Include\WinAPI.au3 [12]|C:\Program Files (x86)\AutoIt3\Include\GuiTab.au3 [13]|C:\Program Files (x86)\AutoIt3\Include\Array.au3 [14]|C:\Program Files (x86)\AutoIt3\Include\Excel.au3 [15]|C:\Program Files (x86)\AutoIt3\Include\Crypt.au3 [16]|C:\Users\Mun\Desktop\ProjectX\_Snip\Includes\_SQL.au3 [17]|C:\Users\Mun\Desktop\ProjectX\_Snip\Includes\Queries.au3 [18]|C:\Users\Mun\Desktop\ProjectX\_Snip\Includes\_Addons.au3 [19]|C:\Users\Mun\Desktop\ProjectX\_Snip\Includes\Resources.au3 [20]|C:\Users\Mun\Desktop\ProjectX\_Snip\Includes\_LargeFileCopy.au3 [21]|C:\Users\Mun\Desktop\ProjectX\_Snip\Includes\RecFileListToArray.au3 [22]|C:\Program Files (x86)\AutoIt3\Include\Constants.au3 [23]|C:\Program Files (x86)\AutoIt3\Include\File.au3 [24]|C:\Program Files (x86)\AutoIt3\Include\GUIConstantsEx.au3 [25]|C:\Program Files (x86)\AutoIt3\Include\ImageListConstants.au3 [26]|C:\Program Files (x86)\AutoIt3\Include\StructureConstants.au3 [27]|C:\Program Files (x86)\AutoIt3\Include\ColorConstants.au3 [28]|C:\Program Files (x86)\AutoIt3\Include\ListViewConstants.au3 [29]|C:\Program Files (x86)\AutoIt3\Include\GuiHeader.au3 [30]|C:\Program Files (x86)\AutoIt3\Include\Memory.au3 [31]|C:\Program Files (x86)\AutoIt3\Include\SendMessage.au3 [32]|C:\Program Files (x86)\AutoIt3\Include\UDFGlobalID.au3 [33]|C:\Program Files (x86)\AutoIt3\Include\EditConstants.au3 [34]|C:\Program Files (x86)\AutoIt3\Include\GuiStatusBar.au3 [35]|C:\Program Files (x86)\AutoIt3\Include\FileConstants.au3 [36]|C:\Program Files (x86)\AutoIt3\Include\Security.au3 [37]|C:\Program Files (x86)\AutoIt3\Include\WinAPIError.au3 [38]|C:\Program Files (x86)\AutoIt3\Include\TabConstants.au3 [39]|C:\Program Files (x86)\AutoIt3\Include\GDIPlus.au3 [40]|C:\Users\Mun\Desktop\ProjectX\_Snip\_FileEx.au3 [41]|C:\Program Files (x86)\AutoIt3\Include\ProcessConstants.au3 [42]|C:\Program Files (x86)\AutoIt3\Include\DirConstants.au3 [43]|C:\Program Files (x86)\AutoIt3\Include\HeaderConstants.au3 [44]|C:\Program Files (x86)\AutoIt3\Include\MemoryConstants.au3 [45]|C:\Program Files (x86)\AutoIt3\Include\StatusBarConstants.au3 [46]|C:\Program Files (x86)\AutoIt3\Include\SecurityConstants.au3 [47]|C:\Program Files (x86)\AutoIt3\Include\GDIPlusConstants.au3 Link to comment Share on other sites More sharing options...
Shaggi Posted February 11, 2013 Share Posted February 11, 2013 Nice, Can i ask why you didn't use recursion for such a job? Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
jchd Posted February 11, 2013 Share Posted February 11, 2013 (edited) Good start. There are nonetheless a couple of points to consider: #includes inside #-style comments are not ignored (would need really hard work to fix!) you definitely need recursion: the relative path is lost when parsing "returns" to the caller from an include file also using relative path. Edited February 11, 2013 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
guinness Posted February 11, 2013 Author Share Posted February 11, 2013 (edited) #includes inside #-style comments are not ignored (would need really hard work to fix!) Not if comments are formatted with Tidy. #cs #include <GUIListView.au3> #ce But I use this to remove comment blocks. $sData = StringRegExpReplace($sData, '(?ms:^\h*#(?:cs|comment-start).+?#(?:ce|comment-end))', '') ; Remove comment blocks to avoid unintended matches. Nice, Can i ask why you didn't use recursion for such a job? I will have a look at recursion in this case. Ideas are welcome before I proceed. Edited February 11, 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...
Shaggi Posted February 11, 2013 Share Posted February 11, 2013 This uses an per-line iterative approach, scanning for #include guards, and recursively scan sub includes to any level (not beyond recursion limit though, can this actually be a concern?). You would need to add a switch that determines whether the current line is a comment or inside a comment block. But this is the basic skeleton of an recursive approach. Func FindIncludes($File) $FileContents = StringSplit(FileRead($File), @CRLF,2) ;Read in the filecontents in a array Local $IncludeArray[1] = [0] ;Holds all include files so far with [0] being the count For $Line in $FileContents ;Loop through all lines in the script $IncludeFile = GetIncludeFileName($Line) ;Is the current line an #include guard - if so catch and process the file If Not @Error Then _ArrayAdd($IncludeArray, $IncludeFile) ;Add the current processed include to the return result $IncludeArray[0] += 1 Local $RetArr = FindIncludes($IncludeFile) ; Get an array for all includes in the current include file If Not @Error Then ;If no error then we add all include names to our current return result. For $i = 0 to $RetArr[0] _ArrayAdd($IncludeArray, $RetArr[$i]) $IncludeArray[0] += 1 Next EndIf EndIf Next Return $IncludeArray EndIf Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
guinness Posted February 11, 2013 Author Share Posted February 11, 2013 Thanks, but there are a couple of issues with that skeleton code. You''re detecting @error but it's never being set if an error occurs. Was this just an idea or was it meant to be working code? 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 February 11, 2013 Author Share Posted February 11, 2013 This is what I was working towards, this is fully working. expandcollapse popup#include <Array.au3> #include <Constants.au3> #include <File.au3> #include <WinAPI.au3> ; #include "myIncludes\Example.au3" ; For testing relative paths. Example() Func Example() ; Set the include folder path to the environment variable %PATH%. Local Const $sIncludePath = StringLeft(@AutoItExe, StringInStr(@AutoItExe, '\', $STR_NOCASESENSEBASIC, -1) - 1) & '\Include' _SetCurrentPath($sIncludePath) ; Au3 Script. Local Const $sFilePath = @ScriptFullPath ; Create a string variable to hold includes found. Local $sIncludesString = '' _GetIncludes($sFilePath, $sIncludesString) ; Display string variable data. MsgBox($MB_SYSTEMMODAL, '', $sIncludesString) ; Strip | from the string. $sIncludesString = StringTrimLeft($sIncludesString, StringLen('|')) $sIncludesString = StringTrimRight($sIncludesString, StringLen('|')) ; Split the string. Local Const $aIncludes = StringSplit($sIncludesString, '|') _ArrayDisplay($aIncludes) EndFunc ;==>Example Func _GetIncludes($sFilePath, ByRef $sIncludesString) If $sIncludesString == '' Then $sIncludesString &= '|' EndIf Local $aArray = 0 Local Const $sFileFolder = StringLeft($sFilePath, StringInStr($sFilePath, '\', $STR_NOCASESENSEBASIC, -1) - 1) ; I would use WinAPIEx's _WinAPI_PathRemoveFileSpec. $aArray = StringRegExp('#include <IncludeCount.au3>' & @CRLF & FileRead($sFilePath), '(?im)^#include\h+[<"'']([^*?"''<>|]+)', 3) $aArray[0] = UBound($aArray) - 1 For $i = 1 To $aArray[0] $aArray[$i] = _WinAPI_PathFindOnPath($aArray[$i]) If @error Then $aArray[$i] = _PathFull($aArray[$i], $sFileFolder) ; I would use WinAPIEx's _WinAPI_GetFullPathName. EndIf If Not StringInStr($sIncludesString, '|' & $aArray[$i] & '|') Then $sIncludesString &= $aArray[$i] & '|' _GetIncludes($aArray[$i], $sIncludesString) EndIf Next EndFunc ;==>_GetIncludes Func _SetCurrentPath($sFilePath) Local Static $fTidiedPath = False, $sPathEnv = '' If Not $fTidiedPath Then $fTidiedPath = True $sPathEnv = EnvGet('PATH') Local Const $aPathEnv = StringSplit($sPathEnv, ';') $sPathEnv = '' For $i = 1 To $aPathEnv[0] $sPathEnv &= StringRegExpReplace($aPathEnv[$i], '[\\/]+\z', '') & ';' Next $sPathEnv = StringTrimRight($sPathEnv, StringLen(';')) EnvSet('PATH', $sPathEnv) EndIf If Not StringInStr(';' & $sPathEnv & ';', ';' & $sFilePath & ';') Then $sPathEnv &= ';' & $sFilePath Return EnvSet('PATH', $sPathEnv) EndFunc ;==>_SetCurrentPath 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...
Shaggi Posted February 11, 2013 Share Posted February 11, 2013 Thanks, but there are a couple of issues with that skeleton code. You''re detecting @error but it's never being set if an error occurs. Was this just an idea or was it meant to be working code?Just an idea @Error should be set by either FindIncludes or GetIncludeFilename (obviously they arent) if any errors occur. Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
guinness Posted February 11, 2013 Author Share Posted February 11, 2013 (edited) Just an idea @Error should be set by either FindIncludes or GetIncludeFilename (obviously they arent) if any errors occur.Did you see my code above? That seems to work in the testing I've conducted. Edited February 11, 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...
Shaggi Posted February 11, 2013 Share Posted February 11, 2013 Did you see my code above? That seems to work in the testing I've conducted.I didnt try it, but it seems good - and better Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
guinness Posted February 11, 2013 Author Share Posted February 11, 2013 OK. I hope someone does, as I have an amazing idea/plan for SciTE Jump. 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 February 11, 2013 Author Share Posted February 11, 2013 (not beyond recursion limit though, can this actually be a concern?).After some tests the recursion level goes down to about 4 or 5 levels deep, so I have very little to worry about of ever hitting the recursion limit. 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...
DXRW4E Posted February 11, 2013 Share Posted February 11, 2013 (edited) Hi guinness, Thanks Again, I had not mentioned the use _WinAPI_PathFindOnPath (very useful), however for personal use, I have always used this expandcollapse popup#include <Array.au3> Local $test = _GetIncludeEx(@ScriptFullPath, 121) ;124 FileDelete(StringRegExpReplace(@ScriptFullPath & " ", "(\h\(\d+\))?(\.[^\.\\]*)?(\h)$", "_Test$2")) FileWrite(StringRegExpReplace(@ScriptFullPath & " ", "(\h\(\d+\))?(\.[^\.\\]*)?(\h)$", "_Test$2"), $test) ;;ConsoleWrite($test & @lF) exit ;Global $sIncludeDir = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Include\" ; #FUNCTION# ==================================================================================================================== ; Name...........: _GetIncludeEx ; Description ...: Gell all Include ; Syntax.........: _GetIncludeEx($sFilePath[, $iFlags = 1]) ; Parameters ....: $sFilePath - Path and filename of the file to be read. ; $iFlags - Optional: (add the flags together for multiple operations): ; |$iFlags = 1 Remove Comment (#cs or #comment-start & #ce or #comment-end) ; |$iFlags = 2 Remove Comment (;comment ect ect) ; |$iFlags = 4 strip all leading white space ; |$iFlags = 8 strip all trailing white space ; |$iFlags = 16 Remove Line empty ; |$iFlags = 32 Remove Line empty or contain only whitespace character ; |$iFlags = 64 Remove #Region or #EndRegion Lines ; |$iFlags = 128 Return 2D Array List ; Return values .: String Data or 2D Array List ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _GetIncludeEx($sFilePath, $iFlags = 127) If $iFlags Then Global $aInclude[1955][4] = [[1,1,@LF,1953],[$sFilePath,"",StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 1, -1)) & "Include\"]] $aInclude[$aInclude[0][0]][1] = @CRLF & StringRegExpReplace(FileRead($sFilePath), '\r(?!\n)', @CRLF) Local $acInclude = StringRegExp($aInclude[$aInclude[0][0]][1], '(?is)\n\h*#include\h*[<"' & "']+\h*([^'<>" & '"]+)', 3) If Not @Error Then For $i = 0 To UBound($acInclude) - 1 If StringInStr($aInclude[0][2], @LF & $acInclude[$i] & @LF, 2) Then ContinueLoop $aInclude[0][2] &= $acInclude[$i] & @LF If $aInclude[0][0] = $aInclude[0][3] Then If $aInclude[0][3] = 3999744 Then ExitLoop $aInclude[0][3] *= 2 ReDim $aInclude[$aInclude[0][3] + 2][2] EndIf $aInclude[0][0] += 1 $aInclude[$aInclude[0][0]][0] = $aInclude[1][2] & $acInclude[$i] If Not FileExists($aInclude[$aInclude[0][0]][0]) Then $aInclude[$aInclude[0][0]][0] = StringRegExpReplace($sFilePath, "(.*[\\/]).*", "$1") & $acInclude[$i] _GetIncludeEx($aInclude[$aInclude[0][0]][0], 0) Next EndIf If Not $iFlags Then Return If BitAND($iFlags, 128) = 128 Then ReDim $aInclude[$aInclude[0][0] + 1][2] $acInclude = $aInclude Else $aInclude[0][1] = $aInclude[1][1] $aInclude[1][0] = StringReplace($aInclude[0][2], @LF, @CRLF & ";") $aInclude[1][1] = @CRLF For $i = 2 To $aInclude[0][0] If StringRight($aInclude[$i][0], 13) = "Constants.au3" Then $aInclude[1][0] &= $aInclude[$i][1] & @CRLF Else $aInclude[1][1] &= $aInclude[$i][1] & @CRLF EndIf Next $acInclude = StringRegExpReplace($aInclude[1][0] & $aInclude[1][1] & $aInclude[0][1], '(?is)\n\h*#include\h*[^\n]*', "") If BitAND($iFlags, 1) = 1 Then $acInclude = StringRegExpReplace($acInclude, "(?is)(\n\h*#(?:cs|comments?-start)[^\n]*\n.*?\n\h*#(?:ce|comments?-end)[^\n]*)", @LF) If BitAND($iFlags, 2) = 2 Then $acInclude = StringRegExpReplace($acInclude, "\n\h*;[^\n]*", "") If BitAND($iFlags, 4) = 4 Then $acInclude = StringRegExpReplace($acInclude, "\n\h+", @LF) If BitAND($iFlags, 8) = 8 Then $acInclude = StringRegExpReplace($acInclude, "\h+(?=[\r\n])", "") If BitAND($iFlags, 16) = 16 Then $acInclude = StringRegExpReplace($acInclude, "\n[\r\n]*\n", @LF) If BitAND($iFlags, 32) = 32 Then $acInclude = StringRegExpReplace($acInclude, "\n\s*\n", @LF) If BitAND($iFlags, 64) = 64 Then $acInclude = StringRegExpReplace($acInclude, "(?i)\n\h*(?:#Region|#EndRegion)(?!\w)[^\n]*\n", @LF) EndIf $aInclude = "" Return $acInclude EndFunc Edited February 11, 2013 by DXRW4E Link to comment Share on other sites More sharing options...
guinness Posted February 11, 2013 Author Share Posted February 11, 2013 Thanks, it works very well. Do you have any other tips I could use for parsing AutoIt scripts? 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...
Developers Jos Posted February 11, 2013 Developers Share Posted February 11, 2013 (edited) This is a version I wrote a while ago which will generate the same format as the script included in an compiled script: expandcollapse popup#AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Res_Comment=Generate a single scriptfile adding all included files equal to what is stored in the compiled script. #AutoIt3Wrapper_Res_Description=Generate a single scriptfile adding all included files. #AutoIt3Wrapper_Res_Fileversion=1.0.0.0 #AutoIt3Wrapper_Res_LegalCopyright=Copyright © 2013 Jos van der Zande ://////=__= #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <file.au3> Global $InComment = 0 Global $ToTalSavedRec = "" Global $SourceFileName If $CmdLine[0] > 0 And FileExists($CmdLine[1]) Then $SourceFileName = $CmdLine[1] Else $SourceFileName = FileOpenDialog("Specify the file to be expanded", @ScriptDir, "AutoIt3 Script (*.au3)", 3) If @error Then Exit EndIf FileChangeDir($SourceFileName) Global $OutPutFileName = StringReplace($SourceFileName, ".au3", "_extended.au3") ; ; Get Include Paths ; Global $User_IncludeDirs = StringSplit(RegRead("HKCU\Software\AutoIt v3\Autoit", "Include"), ";") Global $IncludeDirs[2 + UBound($User_IncludeDirs) - 1] Global $IncludeFiles[500], $IncludeFilesCnt = 1 $IncludeFiles[$IncludeFilesCnt] = $SourceFileName ; First store the AutoIt3 directory to the search table $IncludeDirs[0] = "C:\Program Files (x86)\AutoIt3\Include" Global $I_Cnt = 1 ; Add User Include Directories to the table For $x = 1 To $User_IncludeDirs[0] If StringStripWS($User_IncludeDirs[$x], 3) <> "" And FileExists($User_IncludeDirs[$x]) Then $IncludeDirs[$I_Cnt] = StringReplace($User_IncludeDirs[$x], '"', '') $I_Cnt += 1 EndIf Next ; Add the scriptpath as last entry to the table Global $szDrive, $szDir, $szFName, $szExt _PathSplit($SourceFileName, $szDrive, $szDir, $szFName, $szExt) $IncludeDirs[$I_Cnt] = _PathFull($szDrive & $szDir) ; ; Add \ at the end of the Include dirs in the search table For $x = 0 To $I_Cnt If StringRight($IncludeDirs[$x], 1) <> "\" Then $IncludeDirs[$x] &= "\" EndIf Next ; ; Process scriptfile ; Global $TempRec, $t_TempRec, $Include_Once, $InIncludeCnt Global $H_Inp = FileOpen($SourceFileName, 0) If @error Then MsgBox(0, "error", " Unable to open Sourcefile:" & $SourceFileName) Exit EndIf Global $H_Out = FileOpen($OutPutFileName, 2) If @error Then MsgBox(0, "error", " Unable to open Ouputfile:" & $OutPutFileName) Exit EndIf ; read main scriptfile While 1 $TempRec = FileReadLine($H_Inp) If @error Then ExitLoop $t_TempRec = StringStripWS(StringLeft($TempRec, 50), 3) If $InComment Or StringLeft($TempRec, 8) <> "#include" Then If StringLeft($t_TempRec, 3) = "#cs" Or StringLeft($t_TempRec, 13) = "#commentstart" Then $InComment += 1 ElseIf StringLeft($t_TempRec, 3) = "#ce" Or StringLeft($t_TempRec, 11) = "#commentend" Then $InComment -= 1 ElseIf StringLeft($t_TempRec, 1) = "#" Or StringLeft($t_TempRec, 1) = ";" Then ; Skip this record Else If Not $InComment And $t_TempRec <> "" Then $ToTalSavedRec &= StripComment($TempRec) If StringRight($ToTalSavedRec, 1) = "_" Then $ToTalSavedRec = StringStripWS(StringTrimRight($ToTalSavedRec, 1), 3) & " " Else FileWriteLine($H_Out, $ToTalSavedRec) $ToTalSavedRec = "" EndIf EndIf EndIf Else If StringLeft($t_TempRec, 13) = "#include-once" Then $Include_Once = 1 Else Add_Include($TempRec) EndIf EndIf WEnd FileClose($H_Inp) FileClose($H_Out) ConsoleWrite($OutPutFileName & " (1,1) : Outputfile created." & @CRLF) ;========================================================= ; Add all #Include files to the outputfile - recursively ;========================================================= Func Add_Include($Include_Rec, $source = "Main") Local $TempRec, $ChkInclude, $Include_Once = 0, $NeedsIncluded, $IncludeFile, $IncludeFileFound = 0 Local $H_Incl ; Find the proper path $IncludeFile = StringMid(StringStripWS($Include_Rec, 3), 9) $IncludeFile = StringStripWS($IncludeFile, 3) ; Determine the Path sequence to scan for include files If StringLeft($IncludeFile, 1) = "<" Then $IncludeFile = StringReplace($IncludeFile, ">", "") $IncludeFile = StringReplace($IncludeFile, "<", "") $IncludeFile = StringStripWS($IncludeFile, 3) For $x = 0 To $I_Cnt If $IncludeDirs[$x] <> "" And FileExists($IncludeDirs[$x] & $IncludeFile) Then $IncludeFile = $IncludeDirs[$x] & $IncludeFile $IncludeFileFound = 1 ExitLoop EndIf Next Else $IncludeFile = StringReplace($IncludeFile, "'", "") $IncludeFile = StringReplace($IncludeFile, '"', "") $IncludeFile = StringStripWS($IncludeFile, 3) For $x = $I_Cnt To 0 Step -1 If $IncludeDirs[$x] <> "" And FileExists($IncludeDirs[$x] & $IncludeFile) Then $IncludeFile = $IncludeDirs[$x] & $IncludeFile $IncludeFileFound = 1 ExitLoop EndIf Next EndIf ; If File is found then determine if it still needs to be included If $IncludeFileFound Then ; Check for #Include_once $TempRec = FileRead($IncludeFile) If StringInStr($TempRec, "#include-once") Then $Include_Once = 1 ; check If include is already included $NeedsIncluded = 1 If $Include_Once = 1 Then For $ChkInclude = 1 To $IncludeFilesCnt If $IncludeFiles[$ChkInclude] = $IncludeFile Then $NeedsIncluded = 0 ExitLoop EndIf Next Else ;TraceLog("==> *** Needs to be included since no #include-once is found.") EndIf ; If $NeedsIncluded = 1 Then TraceLog("+ ==> IncludeOnce=" & $Include_Once & " Including:" & $IncludeFile & " Include by:" & $source) ;~ FileWriteLine($H_Out, ";*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*") ;~ FileWriteLine($H_Out, ";* Start Include:" & $IncludeFile & " Include by:" & $source) ;~ FileWriteLine($H_Out, ";*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*") $InIncludeCnt = 0 $IncludeFilesCnt += 1 $IncludeFiles[$IncludeFilesCnt] = $IncludeFile $H_Incl = FileOpen($IncludeFile, 0) While 1 $TempRec = FileReadLine($H_Incl) If @error Then ExitLoop $t_TempRec = StringStripWS(StringLeft($TempRec, 50), 3) If $InComment Or StringLeft($TempRec, 8) <> "#include" Then If StringLeft($t_TempRec, 3) = "#cs" Or StringLeft($t_TempRec, 13) = "#commentstart" Then $InComment += 1 ElseIf StringLeft($t_TempRec, 3) = "#ce" Or StringLeft($t_TempRec, 11) = "#commentend" Then $InComment -= 1 ElseIf StringLeft($t_TempRec, 1) = "#" Or StringLeft($t_TempRec, 1) = ";" Then ; Skip this record Else If Not $InComment And $t_TempRec <> "" Then $ToTalSavedRec &= StripComment($TempRec) If StringRight($ToTalSavedRec, 1) = "_" Then $ToTalSavedRec = StringStripWS(StringTrimRight($ToTalSavedRec, 1), 3) & " " Else FileWriteLine($H_Out, $ToTalSavedRec) $ToTalSavedRec = "" EndIf EndIf EndIf Else If StringLeft($t_TempRec, 13) <> "#include-once" Then Add_Include($TempRec, $IncludeFile) EndIf EndIf WEnd ;~ FileWriteLine($H_Out, ";*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*") ;~ FileWriteLine($H_Out, ";* End Include:" & $IncludeFile & " Include by:" & $source) ;~ FileWriteLine($H_Out, ";*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*") FileClose($H_Incl) Else TraceLog(" ==> Skipped, Already included:" & $IncludeFile) $IncludeFile = "" EndIf Else TraceLog("!==> *** ERROR: include file not found :" & $Include_Rec) EndIf EndFunc ;==>Add_Include ; Func TraceLog($text) Return ConsoleWrite($text & @CRLF) EndFunc ;==>TraceLog ; ; Func StripComment($IStr) Local $Save_Tstr, $CM_Pos, $Temp_CM_Pos, $FSQ, $FDQ, $FCO, $TS ; split code and comment part If StringInStr($IStr, ";") = 0 Then Return StringStripWS($IStr, 3) EndIf ; split code and comment part $Save_Tstr = $IStr $Save_Tstr = StringReplace($Save_Tstr, '""', ' ') ; remove the double double quotes $Save_Tstr = StringReplace($Save_Tstr, "''", " ") ; remove the double single quotes ; if there are no literals in the code then get the comment start pos else ensure that the ; isn't in a literal If StringInStr($Save_Tstr, '"') = 0 And StringInStr($Save_Tstr, "'") = 0 Then $CM_Pos = StringInStr($Save_Tstr, ';') ; remove the comment portion during processing Return StringStripWS(StringLeft($IStr, $CM_Pos - 1), 3) EndIf ; find the first ; thats not within a literal String. $CM_Pos = 0 $Temp_CM_Pos = 0 While 1 $FSQ = StringInStr($Save_Tstr, "'") $FDQ = StringInStr($Save_Tstr, '"') $FCO = StringInStr($Save_Tstr, ';') ; only ; within literal found ... not comments If $FCO = 0 Then $CM_Pos = StringLen($IStr) + 1 ExitLoop EndIf ; determine if literal starts before ; and set current character to that position $Temp_CM_Pos = $FCO If $FSQ <> 0 And $FSQ < $Temp_CM_Pos Then $Temp_CM_Pos = $FSQ If $FDQ <> 0 And $FDQ < $Temp_CM_Pos Then $Temp_CM_Pos = $FDQ $TS = StringMid($Save_Tstr, $Temp_CM_Pos, 1) $CM_Pos = $CM_Pos + $Temp_CM_Pos ; if current pos is ; then Comment FOUND If $TS = ";" Then ExitLoop ; else trim code line and get the end of the literal, trim there and start over... $Save_Tstr = StringTrimLeft($Save_Tstr, $Temp_CM_Pos) $Temp_CM_Pos = StringInStr($Save_Tstr, $TS) ;find Next "/' to speed up $Save_Tstr = StringTrimLeft($Save_Tstr, $Temp_CM_Pos) $CM_Pos = $CM_Pos + $Temp_CM_Pos WEnd ;~ $testRec = StringRegExp($IStr," ; Split the code line in the 2 portions Return StringStripWS(StringLeft($IStr, $CM_Pos - 1), 3) EndFunc ;==>StripComment Jos edit: No idea what the extra line is in the header that isn't in the posted source ..... interesting forum glitch. Edited February 11, 2013 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
guinness Posted February 11, 2013 Author Share Posted February 11, 2013 Thanks Jos. My final code using WinAPIEx. I will have a look at the examples provided and see what can be updated. expandcollapse popup#include <Array.au3> #include <Constants.au3> #include <FileConstants.au3> #include <WinAPIEx.au3> ; #include "myIncludes\Example.au3" ; For testing relative paths. Example() Func Example() ; Au3 Script. Local Const $sFilePath = @ScriptFullPath ; Create a string variable to hold includes found. Local $sDuplicateString = '', $sIncludesString = '' If _GetIncludes($sFilePath, $sIncludesString, $sDuplicateString, False) Then ; Split the string. Local Const $aIncludes = StringSplit($sIncludesString, '|') _ArrayDisplay($aIncludes) EndIf EndFunc ;==>Example Func _GetIncludes($sFilePath, ByRef $sIncludesString, ByRef $sDuplicateString, $fUserDefinedOnly = Default) Local Static $iRecursionCall = 0, $sIncludePath = _WinAPI_PathRemoveFileSpec(@AutoItExe) & '\Include', _ $sWorkingDir = @WorkingDir Local $sIncludeStart = '<' If $fUserDefinedOnly Or $fUserDefinedOnly = Default Then $sIncludeStart = '' EndIf Local Const $sFileFolder = _WinAPI_PathRemoveFileSpec($sFilePath) ; StringLeft($sFilePath, StringInStr($sFilePath, '\', $STR_NOCASESENSEBASIC, -1) - 1) Local $aArray = StringRegExp('#include "IncludeCount.au3"' & @CRLF & FileRead($sFilePath), '(?im)^#include\h+[' & $sIncludeStart & '"'']([^*?"''<>|]+)', 3) $aArray[0] = UBound($aArray) - 1 For $i = 1 To $aArray[0] $aArray[$i] = StringStripWS($aArray[$i], $STR_STRIPLEADING + $STR_STRIPTRAILING) $aArray[$i] = _WinAPI_PathFindOnPath($aArray[$i], $sIncludePath, ';') If @error Then FileChangeDir($sFileFolder) $aArray[$i] = _WinAPI_GetFullPathName($aArray[$i]) ; $aArray[$i] = _PathFull($aArray[$i], $sFileFolder) EndIf If Not StringInStr('|' & $sIncludesString, '|' & $aArray[$i] & '|') Then $iRecursionCall += 1 $sIncludesString &= $aArray[$i] & '|' _GetIncludes($aArray[$i], $sIncludesString, $sDuplicateString, $fUserDefinedOnly) $iRecursionCall -= 1 Else $sDuplicateString &= $aArray[$i] & '|' & $sFilePath & @CRLF EndIf Next If Not $iRecursionCall Then $sDuplicateString = StringTrimRight($sDuplicateString, StringLen('|')) $sIncludesString = StringTrimRight($sIncludesString, StringLen('|')) FileChangeDir($sWorkingDir) $sWorkingDir = @WorkingDir EndIf Return Not ($sIncludesString == '') EndFunc ;==>_GetIncludes 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...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now