/*******************************************/
/* TraapDoor Log Stats Utility             */
/* (c) 1992-94 - Roger Clark               */
/* The Hotel California BBS                */
/* 1:382/105.0@fidonet 40:201/1.0@amiganet */
/* Official USA Excelsior! Support Board   */
/*******************************************/

options results

/*******************************************/
/* Change these to show your configuration */
/*******************************************/
NodeNumber = "1:382/105.0"
Path       = "Logs:TrapDoor.Log"
Report     = "Logs:TrapReport"
/*******************************************/

MaxNodes = 0
USent.0 = 0
URcvd.0 = 0
ISent.0 = 0
IRcvd.0 = 0

call open('input',path,'R')
  do forever
    getdate = readln('input')
    if length(getdate) >1 then leave
  end
  startdate = word(getdate,2)
  starttime = word(getdate,3)
call close('input')

call open('input',path,'R')
  do until eof('input')
    temp = readln('input')
    if length(temp) < 2 then iterate
    enddate = word(temp,2)
    endtime = word(temp,3)
    action = word(temp,4)
    select
      when action = "Incoming" then Flag = "In"
      when action = "Calling" then Flag = "Out"
      when action = "Name:" then call GetNode
      when action = "Sending" then call Sending
      when action = "Receiving" then call Receiving
      when action = "T-Send" then call Sending
      when action = "T-Recv" then call Receiving
      otherwise iterate
    end
  end
call close('input')

Report:
  Call open('output',Report,'W')
   call writeln('output','TrapDoor Log Statistics for Node 'NodeNumber)
   call writeln('output','-------------------------------------------------------')
   call writeln('output','')
   call writeln('output','Calls Made:')
   call writeln('output','')
   call writeln('output','Node Number       Bytes Rcvd   Bytes Sent   Total Bytes')
   call writeln('output','---------------   ----------   ----------   -----------')
   do a = 1 to MaxNodes
     call writeln('output',left(Nodes.a,15)||right(addcomma(IRcvd.a),13)||right(addcomma(ISent.a),13)||right((addcomma(IRcvd.a + ISent.a)),14))
   end
   call writeln('output','---------------   ----------   ----------   -----------')
   call writeln('output',left("Totals:",15)||right(addcomma(IRcvd.0),13)||right(addcomma(ISent.0),13)||right((addcomma(IRcvd.0 + ISent.0)),14))
   call writeln('output','')
   call writeln('output','')
   call writeln('output','Calls Received:')
   call writeln('output','')
   call writeln('output','Node Number       Bytes Rcvd   Bytes Sent   Total Bytes')
   call writeln('output','---------------   ----------   ----------   -----------')
   do a = 1 to MaxNodes
     call writeln('output',left(Nodes.a,15)||right(addcomma(URcvd.a),13)||right(addcomma(USent.a),13)||right((addcomma(URcvd.a + USent.a)),14))
   end
   call writeln('output','---------------   ----------   ----------   -----------')
   call writeln('output',left("Totals:",15)||right(addcomma(URcvd.0),13)||right(addcomma(USent.0),13)||right((addcomma(URcvd.0 + USent.0)),14))
   call writeln('output','')
   call writeln('output','Report dates: 'startdate||' '||starttime||' to '||enddate||' 'endtime)
  call close('output')
exit

GetNode:
  NumWords = words(temp)
  CurrNode = word(temp,NumWords)
  L = length(CurrNode)
  CurrNode = Left(CurrNode,(L - 1))
  L = L - 1
  CurrNode = Right(CurrNode,(L - 1))
  found = 0 ; Node = 0
  if MaxNodes > 0 then do
    do a = 1 to MaxNodes
      if CurrNode = Nodes.a then do
        found = 1
        Node = a 
      end
      if found = 1 then Leave
    end
  end
  if found = 0 then do
    MaxNodes = MaxNodes + 1
    Nodes.MaxNodes = CurrNode
    Node = MaxNodes
    USent.Node = '0' 
    URcvd.Node = '0'
    ISent.Node = '0' 
    IRcvd.Node = '0'
  end
  Return

Sending:
  If Flag = "In" then do
    USendB = word(temp,6)
    if USendB = "failed" then do
      USent.Node = USent.Node - USendL
      USent.0 = USent.0 - USendL
      Return
    end
    L = length(USendB)
    USendB = right(USendB,(L - 1))
    USent.Node = USent.Node + USendB
    USent.0 = USent.0 + USendB
    USendL = USendB
    Return
  End
  If Flag = "Out" then do
    ISendB = word(temp,6)
    if ISendB = "failed" then do
      ISent.Node = ISent.Node - ISendL
      ISent.0 = ISent.0 - ISendL
      Return
    end
    L = length(ISendB)
    ISendB = right(ISendB,(L - 1))
    ISent.Node = ISent.Node + ISendB
    ISent.0 = ISent.0 + ISendB
    ISendL = ISendB
    Return
  End

Receiving:
  If Flag = "In" then do
    URcvdB = word(temp,6)
    if URcvdB = "failed" then do
      URcvd.Node = URcvd.Node - URcvdL
      URcvd.0 = URcvd.0 - URcvdL
      Return
    end
    L = length(URcvdB)
    URcvdB = right(URcvdB,(L - 1))
    URcvd.Node = URcvd.Node + URcvdB
    URcvd.0 = URcvd.0 + URcvdB
    URcvdL = URcvdB
    Return
  End
  If Flag = "Out" then do
    IRcvdB = word(temp,6)
    if IRcvdB = "failed" then do
      IRcvd.Node = IRcvd.Node - IRcvdL
      IRcvd.0 = IRcvd.0 - IRcvdL
      Return
    end
    L = length(IRcvdB)
    IRcvdB = right(IRcvdB,(L - 1))
    IRcvd.Node = IRcvd.Node + IRcvdB
    IRcvd.0 = IRcvd.0 + IRcvdB
    IRcvdL = IRcvdB
    Return
  End

AddComma: Procedure
  Arg String
  NewString = ""
  If Length(String) < 4 Then Return String
  String = Reverse(String)
  Do Loop = 1 to Length(String) By 3
    NewString = NewString||SubStr(String,Loop,3)||","
  End
  NewString = Reverse(NewString)
  NewString = Strip(NewString,"L",",")
  NewString = Strip(NewString)
  Return NewString
