//TH-Header //***************************************************************************************** // Copyright (c) 2002 Michael Kurz // All rights reserved. // // $FileName : cDependencyScanner.pkg // $ProjectName : Codemax // $Authors : Michael Kurz // $Created : 06.02.2002 21:48 // // Contents: // //***************************************************************************************** //TH-RevisionStart //TH-RevisionEnd Use CSrcLineParser.pkg Use FindFile.pkg Use Tools\DependencyConf.SL Object oDependencyStatus is a ToolPanel Set locate_mode to CENTER_ON_SCREEN Set label to "Scan dependencies..." set size to 50 200 Object oLabel is a Textbox set location to 6 10 set label to "File:" End_Object Object oFile is a Textbox Set auto_size_state to FALSE set location to 5 25 Set size to 13 160 Set border_style to border_StaticEdge End_Object Procedure DoSetFile string sFile set value of (oFile(Self)) item 0 to (" "+sFile) End_Procedure End_Object Class cDependencyScanner is a Set //Insert your Properties here. Procedure Construct_Object Forward send Construct_Object Property integer piMaxLength 0 Property String psConfigFile "DependScan.ini" Property Integer piOutputMode 0 Property String psTextFile "" Property String psBatchFile "" Object oPaths is an Array End_Object Object oExtentions is a CSrcLineParser End_Object Object oLineParser is a CSrcLineParser End_Object Object oFilesToScan is a Set End_Object Object oFileNames is a Array End_Object Send DoLoadConfig End_Procedure // Stores a File to Scan. Procedure DoAddFileToScan string sFile integer iRet get Find_Element of (oFilesToScan(Self)) sFile to iRet If iRet lt 0 Set value of (oFilesToScan(Self)) item (Item_Count(oFilesToScan(Self))) to sFile End_Procedure // Adds a Path wich can contain dependencies of interest. Procedure AddExtention string sExt Set Value of (oExtentions(Self)) item (Item_Count(oExtentions(Self))) to sExt End_Procedure // Determine the filetypes which are scanned for dependencies. Procedure Set FileExtentions string sStr Send ParseLine to (oExtentions(Self)) sStr End_Procedure // Adds a Path wich can contain dependencies of interest. Procedure AddFilePath string sPath Set Value of (oPaths(Self)) item (Item_Count(oPaths(Self))) to sPath End_Procedure // Tries to complete a filename. Function GetFullFilePath string sFile returns string integer iC hoId iExist string sTmp move (oPaths(Self)) to hoId For iC From 0 to (Item_Count(hoId)-1) get value of hoId item iC to sTmp Append sTmp "\" sFile File_Exist sTmp iExist If iExist Function_Return sTmp End Function_Return "" End_Function // Scans a Files for the #include and use statements. Procedure ScanFile string sFile integer iSelect hoParser iRet string sLine sFile2 move (oLineParser(Self)) to hoParser Send DoSetFile to (oDependencyStatus(Self)) sFile Direct_Input sFile Repeat move 0 to iSelect ReadLn sLine If (Left(Uppercase(sLine),4)) eq "USE " move 1 to iSelect If (Left(Uppercase(sLine),9)) eq "#INCLUDE " move 1 to iSelect If iSelect Begin Send ParseLine to hoParser sLine get value of hoParser item 1 to sFile2 If sFile2 ne "" If NOT "." IN sFile2 Append sFile2 ".pkg" move (GetFullFilePath(Self,sFile2)) to sFile2 move (Lowercase(Trim(sFile2))) to sFile2 If sFile2 ne "" Begin get Find_Element sFile2 to iRet If iRet lt 0 Begin move (Item_Count(Self)) to iRet Set value item (Item_Count(Self)) to sFile2 If (Length(sFile2)) gt (piMaxLength(Self)) Set piMaxLength to (Length(sFile2)) End Set value of (oFileNames(Self)) item iRet to (Value(oFileNames(Self),iRet)+" "+FileFromPath(sFile)) Send DoAddFileToScan sFile2 End End Until [SEQEOF] Close_Input End_Procedure // Runs through all files with a given extention in a directory. Procedure RunDirectory String sExt integer iMsg integer hoId iRet If (Left(sExt,2)="*.") Move (Replace("*.",sExt,"")) To sExt // people pass extensions like "*.src" or ".src" If (Left(sExt,1)=".") Move (Replace(".",sExt,"")) To sExt // that should be allowed as it is common usage Move (Win32FindFirstFile(".\*."+sExt)) To hoId If hoId send iMsg hoId Else Procedure_Return Repeat Move (Win32FindNextFile(hoId)) To iRet If iRet send iMsg hoId Until (iRet<>1) Move (Win32FindClose(hoId)) To iRet End_Procedure // Scans a file out of the scaned directory. Procedure onNewFile integer hoId Send DoAddFileToScan (FullFileName(hoId)) // Send ScanFile (FullFileName(hoId)) End_Procedure // Scans all Files for #include and use statement. Procedure DoScan integer iC string sFile Send Activate to (oDependencyStatus(Self)) Send Delete_Data Send Delete_Data to (oFileNames(Self)) Send Delete_Data to (oFilesToScan(Self)) Set piMaxLength to 0 For iC From 0 to (Item_Count(oExtentions(Self))-1) Send RunDirectory (Value(oExtentions(Self),iC)) Msg_onNewFile End For iC from 0 to (Item_Count(oFilesToScan(Self))-1) Send ScanFile (Value(oFilesToScan(Self),iC)) End Send Close_Panel to (oDependencyStatus(Self)) End_Procedure Procedure DoWriteInt string sPraefix string sFile string sSuffix integer iExt integer iC If sFile eq "" Begin Error 200 ("Dependency Scanner: No File specified!") Procedure_Return End Direct_Output sFile For iC from 0 to (Item_Count(Self)-1) If iExt WriteLn sPraefix (Pad(Value(Self,iC),piMaxLength(Self))) sSuffix " " (Value(oFileNames(Self),iC)) Else WriteLn sPraefix (Pad(Value(Self,iC),piMaxLength(Self))) sSuffix End Close_Output End_Procedure Procedure DoWrite string sFile Send DoWriteInt "" sFile "" true End_Procedure Procedure DoWriteBatch string sFile Send DoWriteInt "Copy " sFile " %1" false End_Procedure Procedure DoWriteDefault If (piOutputMode(Self)) eq 0 Begin Send DoWrite (psTextFile(Self)) Send Info_Box ("Result was written to "+psTextFile(Self)) End If (piOutputMode(Self)) eq 1 Begin Send DoWriteBatch (psBatchFile(Self)) Send Info_Box ("Result was written to "+psBatchFile(Self)) End If (piOutputMode(Self)) eq 2 Begin Send DoWrite "Clipboard:" Send Info_Box ("Result was copied to the clipboard") End End_Procedure Procedure DoLoadConfig String sLine String sConfigFile Get psConfigFile to sConfigFile Direct_Input sConfigFile ReadLn sLine Set FileExtentions to sLine ReadLn sLine Set piOutputMode to sLine ReadLn sLine Set psTextFile to sLine ReadLn sLine Set psBatchFile to sLine Repeat ReadLn sLine [Not Seqeof] If sLine ne "" Send AddFilePath sLine Until [SEQEOF] Close_Input End_Procedure Procedure DoConfig integer iRet get DependencyConfig (psConfigFile(Self)) to iRet If iRet Begin Send DoLoadConfig End End_Procedure End_Class