/* script to get Messages from 'net send' */

call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs

msgfile = SysIni('ticker.ini', 'NETLOG', 'MLOG_MSGFILE')

if ((msgfile = 'FEHLER:') | (msgfile = 'ERROR:')) then 
  do
    /* search for messagefile in all local drives */
    msgfile = ''
    drives = SysDriveMap(,'LOCAL')
    do words(drives)
      parse var drives adrive drives
      call SysFileTree adrive'\messages.log', 'found', 'FSO'
      if (found.0 > 0) then 
      do
        msgfile = found.1
        /* save found messagefilename in ini for next time */
        SysIni('ticker.ini', 'NETLOG', 'MLOG_MSGFILE', msgfile)
        leave
      end
    end
  end

linenr = SysIni('ticker.ini', 'NETLOG', 'MLOG_LINENR')
if ((linenr = 'FEHLER:') | (linenr = 'ERROR:')) then linenr = 1

firstline = SysIni('ticker.ini', 'NETLOG', 'MLOG_FIRSTLINE')
if ((firstline = 'FEHLER:') | (firstline = 'ERROR:')) then firstline = 'NOT AVAILABLE'

actline = 0

do while lines(msgfile) 
  actline = actline + 1; 
  
  aline = linein(msgfile)

  /* check if messagefile was deleted since last read by this script */

  if ((actline = 0) & (\(aline = firstline))) then 
    linenr = 0

  /* check if message should be shown and then show it for 5 minutes */
  if ( \(linenr > actline) ) then
  do
    call addTicker ' 'aline' ', 'MLOG'actline, 300, red
  end
end

linenr = SysIni('ticker.ini', 'NETLOG', 'MLOG_LINENR', actline)
firstline = SysIni('ticker.ini', 'NETLOG', 'MLOG_FIRSTLINE', firstline)

exit
