Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Parse all includes in a script file.

$
0
0
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.

[ autoit ]         
#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

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>