Help - Search - Members - Calendar
Full Version: Verify.mac
AC Tools Everything Macro > AC Tool Macros > Asheron's Call Macros
Ahk
QUOTE
1.01 Update:
-Added duplicate procedure detection.
-Index added so the calls/procedure listing in timestamps is sorted neatly.
-Output list sorted - this makes each file in it's own group, and sorted alphabetically to boot.


Cool little macro I just threw together, works beautifully.

Unfortunately "If FileExists .." does not work with lists for whatever reason, so you have to have it typed correctly or it will not run completely saying the file doesn't exist.

OutputFile can be made 0 and you can view the TimeStamps tab to see results, or give it a filename and the macro will launch the output in notepad.

Macro has a test line in itself to prove the concept, and I've already used it in a couple of my work macros, which I plan on modifying some procedure names.

Enjoy!

I cannot post the attachment, so here is the code.
CODE
(*
Purpose: Verify procedure calls before the macro is run.
Created: 11/2/06 by Ahk
Last modified: Same
Version: 1.01

1.01 Update:
-Added duplicate procedure detection.
-Index added so the calls/procedure listing in timestamps is sorted neatly.
-Output list sorted - this makes each file in it's own group, and sorted alphabetically to boot.

Notes:
This does not process Include lines, so don't count on it.  You have to add them to the macro list.

*)

//Macros to parse
ListAdd lstMacro, Verify.mac


//List Procs/Calls? 1=yes, other=no
SetConst ListItems = 1
//Save to file for output - 0 disables.
SetConst OutputFile = H:\Output.txt

//This is an example, though the macro will not ever hit the line, macro can see the problem.
If $Temp = Temp should never equal this unless you're fooling around!
  Call SomeBadProcedure
End

Constructs
  lstMacro = List
  lstParse = List
  lstTemp = List
  lstFilename = List
  lstOutput = List
End
DataSet Procs
  FileName = String 20
  Name = String 75
  Line = String 5
End
DataSet Calls
  FileName = String 20
  Name = String 75
  Line = String 5
End
DataSet Parse
  FileName = String 20
  Text = String 255
  Line = String 5
End
Constants
  cnt_lstMacro = 0
  cnt_lstTemp = 0
  cnt_DSParse = 0
  cnt_DSProcs = 0
  cnt_DSCalls = 0
  Trim = 0
  Temp = 0
  Offset = 0
  ListItems = 0
  OutputFile = 0
  FName = 0
End

Procedure Load Using FileName
  ListLoad lstTemp, $FileName
  ListCount lstTemp, $cnt_lstTemp
  
  //Parse shorter version of filename
  StringToList lstFileName, $FileName, \
  ListCount lstFileName, $Temp
  SetConst FName = lstFileName[$Temp]
  TimeStamp Loading $FName
  
  SetConst Offset = 0
  Loop $cnt_lstTemp
    //TimeStamp Add lstTemp[{loopno}]
    DSAppend Parse
    SetConst Parse[Text] = lstTemp[{loopno}]
    Compute Parse[Line] = {loopno} - $Offset
    SetConst Parse[FileName] = $FName
    DSPost Parse
  End
End

Procedure Init
    //This disables checking of lists/datasets brackets. This has to be on because the list
    //or dataset will NOT be in this macro, causing AcTool to try and parse a list/dset that does
    //not exist will create an error and halt the macro - it should on constants too, but it doesn't.
  IgnoreBracketErrors ON
  //Count of macros to load
  ListCount lstMacro, $cnt_lstMacro
  Loop $cnt_lstMacro //load each into lstParse
    Call Load lstMacro[{loopno}]
  End
  
  //Add indexes for name and filename (for sorting and faster searches with DSFindKey
  DSIndexAdd Calls, ndxName, Name
  DSIndexAdd Calls, ndxFile, FileName
  
  DSIndexAdd Procs, ndxName, Name
  DSIndexAdd Procs, ndxFile, FileName
  
  //Index these by name so parse can avoid adding duplicate calls
  DSIndex Calls, ndxName
  DSIndex Procs, ndxName
End
Procedure Parse
  DSFirst Parse
  DSCount Parse, $cnt_DSParse
  Loop $cnt_DSParse
    StrWord Temp = Parse[Text], 1
    If $Temp = Procedure
      StrWord Temp = Parse[Text], 2
      DSFindKey Procs, $Temp
      If EOF Procs
        //TimeStamp AddProc $Temp
        DSAppend Procs
        SetConst Procs[Name] = $Temp
        SetConst Procs[Line] = Parse[Line]
        SetConst Procs[FileName] = Parse[FileName]
        DSPost Procs
      Else
          TimeStamp Duplicate Procedures detected
                ListAdd lstOutput, Duplicate procedure detected - Parse[Text].  Definitions in Procs[FileName] on line Procs[Line] and Parse[FileName] on line Parse[Line]
      End
    Else
      If $Temp = Call
        StrWord Temp = Parse[Text], 2
        DSFindKey Calls, $Temp
        If EOF Calls
          //TimeStamp AddCall $Temp
          DSAppend Calls
          SetConst Calls[Name] = $Temp
          SetConst Calls[Line] = Parse[Line]
          SetConst Calls[FileName] = Parse[FileName]
          DSPost Calls
        End
      End
    End
    DSNext Parse
  End
End

Procedure ListItems Using DSet
  //Index by file so it's easier to read
  DSIndex $DSet, ndxFile
  DSCount $DSet, $cnt_DSProcs
  TimeStamp
  TimeStamp
  TimeStamp Listing $DSet
  TimeStamp
  DSFirst $DSet //First record
  Loop $cnt_DSProcs //loop through dataset
    TimeStamp $DSet[FileName] - $DSet[Name] on Line: $DSet[Line]
    DSNext $DSet //Next record after each loop
  End
  //Reset index by name so parse can run
  DSIndex $DSet, ndxName
End

Procedure Verify
  TimeStamp
  TimeStamp Verify procedure calls
  
  DSCount Calls, $cnt_DSCalls
  DSFirst Calls
  DSFirst Procs //probably not be necessary, but here anyways.
  //Loop through the Call dataset and try to find in procedures
  Loop $cnt_DSCalls
    DSFindKey Procs, Calls[Name] //Find Call [Name]
    If EOF Procs //Not found, invalid procedure
      TimeStamp Call to invalid procedure! Calls[FileName] - Calls[Name] on Line: Calls[Line]
      ListAdd lstOutput, BAD: Calls[FileName] : Call Calls[Name] on line Calls[Line]
    Else //Found - OK
      TimeStamp OK: Calls[FileName] - Calls[Name] on Line: Calls[Line
      ListAdd lstOutput, OK: Calls[FileName] : Call Calls[Name] on line Calls[Line]
    End
    //Next rec and repeat until done
    DSNext Calls
  End
End

Call Init
Call Parse
If $ListItems = 1
  Call ListItems Procs
  Call ListItems Calls
End
Call Verify
If $OutputFile <> 0
  ListSortOn lstOutput
  ListSave lstOutput, $OutputFile
  ExecProgram notepad.exe $OutputFile
End
Ahk
Updated already. I saw a need for some improvements!

QUOTE
1.01 Update:
-Added duplicate procedure detection.
-Index added so the calls/procedure listing in timestamps is sorted neatly.
-Output list sorted - this makes each file in it's own group, and sorted alphabetically to boot.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.