Function SRP_Scan_Sysproc_History(void)

/******************************************************************************************************** 

    This program is proprietary and is not to be used by or disclosed to others, nor is it to
    be copied without written permission from SRP Computer Solutions, Inc.

    Name        :   SRP Scan Sysproc History

    Description :   

	Tags		:	[SRP]

    Parameters  :

    History (Date, Initials, Notes)
        01/29/10    fjt     Initial development
        06/03/10	fjt		Last updated

********************************************************************************************************/

$insert SRP_APP_INSERTS

Equ Crlf$ to Char(13):Char(10)

Declare function SRP_Sort_Array, SRP_Rotate_Array

z = 0
Loop
    z += 1
    On z GoSub Init, Select, SP, Done
Until (Err or Done)
Repeat

Return List


!----- PROCESS ROUTINES ---------------------------------------------------------------------------------


Init:
    Err = ""
    App = @APPID<1>
    Done = No$
return


Select:
    Open "SYSPROCS" to hSP else Err = Yes$
   	Select hSP
return


SP:
	Ans = ""
	List = ""
	EOL = No$
	
    Loop
        Readnext Key else EOL = Yes$
    Until EOL
        If Field(Key, "*", 2) EQ App then
            Read Rec from hSP, Key then
                GoSub Find_Comment_Block
                If Block then GoSub Find_Data
            end
        end
    Repeat
    
    GoSub Sort
    
    OSWrite Ans to "C:\Revsoft\sysproc_history.txt"
    OSWrite List to "C:\Revsoft\sysproc_list.txt"
return

    
Done:
    Done = Yes$
return


!----- INTERNAL -----------------------------------------------------------------------------------------


Sort:
    Ans = SRP_Sort_Array(Ans, "DL1", Yes$)
    Ans = SRP_Rotate_Array(Ans)
    Ans<1> = Oconv(Ans<1>, "D4/")
    Ans = SRP_Rotate_Array(Ans)
    Swap @VM with Tab$:Tab$ in Ans
    Swap @FM with Crlf$ in Ans
    
    List = SRP_Sort_Array(List, "DR1", Yes$)
	List = SRP_Rotate_Array(List)
    List<1> = Oconv(List<1>, "D2/")
    List = SRP_Rotate_Array(List)
    List = @FM:List
    Swap @VM with Tab$:Tab$ in List
    Swap @FM with Crlf$ in List
return


Find_Comment_Block:
    Swap "/*" with @RM in Rec
    Swap "*/" with @RM in Rec
    
    Proc = Field(Rec, @RM, 1)<1>
    Cmt  = Field(Rec, @RM, 2)
    Swap Tab$ with Space(1) in Cmt
    Cmt  = Trim(Cmt)
    Cnt  = Count(Cmt, @FM) + (Cmt NE "")
    
    Block = Yes$
    Begin Case
        Case Cmt<1>[1,10] EQ Str("-", 10)
        Case Cmt<1>[1,10] EQ Str("*", 10)
        Case Otherwise$ ; Block = No$
    End Case
return


Find_Data:
	// Default name
	Swap "Compile " with "" in Proc
	Swap Space(1) with @FM in Proc
	Swap "(" with @FM in Proc
	Proc = Proc<2>
	Swap "_"	with " " in Proc
	Swap "NDW " with "" in Proc
	Swap "DBW " with "" in Proc
	Proc = Oconv(Proc, "[FIRST_CAPS]")
	
	// Tag
	If Index(Cmt, "[SRP]", 1) then
					
		// Custom name
		Name = ""
		For i = 1 to Cnt
			Row = Trim(Cmt<i>)
			If Index(Row, "Name :", 1) then
				Name = Trim(Field(Row, ":", 2))
			end
		Until Name GT ""
		Next i
		
		If Name else Name = Proc
		Current = ""
		// History
		For i = (Cnt-1) to 1 Step -1
			Row  = Trim(Cmt<i>)
		Until Index(Row, "History", 1)
			Date = Field(Row, " ", 1)
			Init = Field(Row, " ", 2)
			Swap Date with "" in Row
			Swap Init with "" in Row
			Date.i = Iconv(Date, "D")
	
			If Date and Trim(Row) then
				If Current EQ "" then Current = Date.i
				Ans := Date.i :@VM: Name :@VM: Trim(Row) :@FM
			end
		Next i
		
		List := Current :@VM: Name :@FM
	
	end
return

