[INHERIT('sys$library:starlet','lib$spawn','smgdefs','smg$repaint_line',
'BB.PEN')]
module put_local;

[global] 
procedure put_local;

{Post the current message to the local bulletin board.}

begin
  $setprv(1,prv$m_sysprv);

  open(bbwrtfile,file_location+chosen_file,history:=old,
       access_method:=keyed,organization:=indexed,sharing:=readwrite,
       error:=continue);

  write_menu('','Adding message to local bulletin board...');

  reset(ifile);
  if (status(ifile) = 0) then
    with current_record do
      {Input file and data base file open.  This section formats the
       message and puts records into the data base file.}
      begin
        count := 0;

        repeat
          if (count > display_height) then
            begin
              data := line + chr(13) + chr(10);
              count := (length(line) div (display_width + 1)) + 1;
            end
          else
            begin
              data := '';
              count := 0;
            end;

          repeat
            readln(ifile,line);
            if (status(ifile) < 1) then
              begin
                count := count + (length(line) div (display_width + 1)) + 1;
                if (count <= display_height) then 
                  data := data + line + chr(13) + chr(10);
              end;
          until (count >= display_height) or (status(ifile) <> 0);
          write(bbwrtfile,current_record,error:=continue);
          continuation := true;
        until (status(ifile) <> 0);

        {Add one to the topic_list^.message_counters.new}
        if (status(bbwrtfile) > 0) then
           write_error('Unable to write to database.')
        else
           begin
             if (topic_root^.next <> nil) then
               topic_list := topic_root^.next;

             while (current_record.topic <> topic_list^.topic) and 
                   (topic_list^.next <> nil) do
	       topic_list := topic_list^.next;

             with topic_list^ do  {Adjust counts in topic menu.}
               begin{with topic_list}
                 if (topic_list <> nil) then 
                   begin
                     message_counters.new_message := 
                                          message_counters.new_message + 1;
                     message_counters.total_message :=  
                                          message_counters.read_message + 
		                          message_counters.new_message +
					  message_counters.skipped_message;

                     {Update user's file so this user may delete this message.}
                     log_message;
                     adjust := true;
                   end;
               end;{with topic_list}
           end;
      end;

  close(ifile,error:=continue);  
  close(bbwrtfile,error:=continue);            
  $setprv(0,prv$m_sysprv);
end;

end.
