{Program for checking if there is APM News}

%external %string (79) Copyright %alias "NEWS_(C)_CHECK_RMM_85" = -
   "Copyright (C) 1985 Richard M. Marshall"

%include "News.Inc"
%include "Inc:Util.Imp"
%include "Inc:FS.Imp"
%include "Inc:FSUtil.Imp"

%external %integer Home Host
%external %integer News Host
%external %string (12) News Server = "BRAVO::"

%begin
   %record (Topic fm) %name Actual Topics
   %record (Seen fm) %name Topics
   %record (Range fm) %name R
   %string (255) Param, Seen File
%record(finfof)frec
%string(31)ref,stamp
   %byte List, First

   {-YES THERE IS-}

   %routine Yes There Is (%string (255) Topic)
      Select Host (Home Host)
      Select Output (0)
      %if First = Yes %start
         Print String ("There is news")
         Print String (" in topic(s):") %if List = Yes
         New Line
      %finish
      First = No
      %if List = No %start
         Disconnect Host (News Host)
         Select Host (Home Host)
         %stop
      %finish
      Print String (Topic)
      Newline
   %end {Yes There Is}

%routine mangle(%string(31)%name d)
! assume D contains dd/mm/yyhh.mm
! swap about the yy and dd so that time stamp
! comparisons can be made using string comparison
%bytename d1,d2,y1,y2
%byte t1,t2
  d1 == charno(d,1)
  d2 == charno(d,2)
  y1 == charno(d,7)
  y2 == charno(d,8)
  t1 = d1; t2 = d2
  d1 = y1; d2 = y2
  y1 = t1; y2 = t2
%end

%predicate recent
! true iff the time stamp in STAMP is more recent than REF
  %trueif stamp>=ref
  %false
%end

   {--MAIN CODE OF CHECKNEWS--}

   %on %event 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 %start
!!!      Close News File      { Safe, even if not open }
      Disconnect Host (News Host)
      Select Host (Home Host)
      %if Event_Event = 15 %start
         Print String (Event_Message)
         New Line
      %else %if Event_Event # 3
         Print String ("Screwed up at line: ")
         Write (Event_Line, 0)
         Newline
         Signal (Event_Sub << 4 + Event_Event)      { Not literal indeed ! }
      %finish
      %stop
   %finish

   Param = Current User
   List = No
   First = Yes

   Define Param ("User",
                  Param,
                  PAM Major)
   Define Enum Param ("NOList,List", List, 0)

   Process Parameters (CLI Param)

   Home Host = Current Host
   News Host = Connect to Host (News Server)

   Actual Topics == Read Topics

   Select Host (Home Host)
   Seen File = Param . ":" . Seen File Name
   %if Exists (Seen File) %start
      Topics == Read Seen File (Seen File)
   %else
      List = No
      Yes There Is ("") %if Actual Topics ## Nil     {not read any at all}
   %finish

   Select Host (Home Host)
   unpackfinfo(ninfo(Seen File), frec)
   ref = frec_date.frec_time
   mangle(ref)

   %cycle
      %if Topics_Subscribed = Yes %start

!!!         %if Open News File (Topics_Topic, 0) %start
!!!            Close News File
!!!            R == Topics_Ranges
!!!            R == R_Next %while R_Next ## Nil
!!!            Yes There Is (Topics_Topic) %if Last Message > R_To
!!!         %else
!!!            Yes There Is (Topics_Topic)
!!!         %finish


         Select Host (News Host)
         unpackfinfo(ninfo("news:".Topics_Topic),frec)
         stamp = frec_date.frec_time
         mangle(stamp)
         %if recent %start
            Yes There Is (Topics_Topic)
         %finish

      %finish

      Actual Topics == Actual Topics_Next
      Topics == Topics_Next
   %repeat %until Topics == Nil

   Yes There Is (Actual Topics_Topic) %if Actual Topics ## Nil    {new topics}

   Disconnect Host (News Host)
   Select Host (Home Host)
%end
