[INHERIT('BB.PEN')]
module create_message_data_list;

[global] 
procedure create_message_data_list;

{Creates a linked list containing header information and the body of
 the message selected for reading.}

begin   

  {Dispose of old data nodes if there are any.}
  data_curr:=data_root^.next;
  while (data_curr <> nil) do
    begin
      data_prev := data_curr;
      data_curr := data_curr^.next;
      dispose(data_prev);
    end;

  data_curr := data_root;
  log_message;   {Write record into userfile to mark message as READ.}

  {Locate the message in the data base file and create the linked list.}
  findk(bbfile,1,dir_curr^.topic+dir_curr^.date,eql,error:=continue);
  if not ufb(bbfile) then
    begin

      repeat
        read(bbfile,current_record,error:=continue);
        if (current_record.date = dir_curr^.date) and (status(bbfile) <= 0) then
          begin
            data_prev := data_curr;
            new(data_curr);
            data_prev^.next := data_curr;
            data_curr^.previous := data_prev;
            data_curr^.data := current_record.data;
          end;
      until (current_record.date <> dir_curr^.date) or eof(bbfile) or
            (status(bbfile) > 0);
    end;

  data_curr^.next := nil;

end;
end.
