%begin
%option "-nodiag-nonstandard"
%include "inc:util.imp"
%include "inc:fs.imp"

! Print information from $:PORTS and $:UNOS files relating to Gandalf-APMs

%constinteger max=4
%constintegerarray gandalf(1:max)=-
  16_3D,16_51,16_54,16_56
%recordformat f(%string(31)cdate,ctime, {connected}
                           pdate,ptime, {port used}
                           ldate,ltime, {logged on}
                           username)
%record(f)%array apm(1:max)
%record(f)%name r
%integer i
%string(31)today

today = date
apm(i) = 0 %for i = 1,1,max
printstring("Gandalf APM connections to filestore "); phex2(rdte)
printstring(" at ";time;" on ";today); newline

%begin {read $:PORTS file}
%integer i,port,mac,macport,junk
  %onevent 9 %start
    %return
  %finish
  openinput(1,"$:ports"); selectinput(1)
  %cycle
    read(port)
    rhex(mac)
    %for i = 1,1,max %cycle
      %if mac=gandalf(i) %start
        r == apm(i)
        read(macport)
        read(r_cdate; r_ctime; r_pdate; r_ptime)
      %finish
    %repeat
    readsymbol(junk) %until junk=nl
  %repeat
%end

%begin {read $:UNOS file}
%integer i,uno,port,mac,macport,junk
%string(31)sjunk
  %onevent 9 %start
    %return
  %finish
  openinput(1,"$:unos"); selectinput(1)
  %cycle
    read(uno)
    read(port)
    %if 0<port<256 %start
      rhex(mac)
      %for i = 1,1,max %cycle
        %if mac=gandalf(i) %start
          r == apm(i)
          read(macport)
          read(r_username; sjunk; r_ldate; r_ltime)
        %finish
      %repeat
    %finish
    readsymbol(junk) %until junk=nl
  %repeat
%end

%for i = 1,1,max %cycle
  r == apm(i)
  printstring("Machine "); phex2(gandalf(i))
  %if r_ctime="" %start
    printstring(" not connected")
  %else
    printstring(" connected")
    printstring(" ";r_cdate) %unless r_cdate=today
    printstring(" ";r_ctime;", last used")
    printstring(" ";r_pdate) %unless r_pdate=today
    printstring(" ";r_ptime)
    %unless r_username="" %start
      printstring(", ";r_username;" logged on")
      printstring(" ";r_ldate) %unless r_ldate=today
      printstring(" ";r_ltime)
    %finish
  %finish
  newline
%repeat

%end
