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

[global] 
procedure write_topic_directory;

{Write the topic directory beginning with topic marked with topic_start.}

var
  total_message_string,new_message_string,topic_count_string : string;

begin 
  if (topic_start^.next <> nil) then      
    smg$begin_pasteboard_update(pasteboard);      

  {Write header information for chosen category.}
  smg$erase_display(header_display);
  smg$put_chars(header_display,' CCF BULLETIN BOARD ',1,31,,smg$m_bold);
  smg$put_chars(header_display,'#',3,4,,
                smg$m_bold+smg$m_underline+smg$m_reverse);
  smg$put_chars(header_display,' Topic ',3,7,,
                smg$m_bold+smg$m_underline+smg$m_reverse);
  smg$put_chars(header_display,' Description ',3,24,,
                smg$m_bold+smg$m_underline+smg$m_reverse);
  smg$put_chars(header_display,'  Total | New  ',3,64,,
                smg$m_bold+smg$m_underline+smg$m_reverse);
  smg$paste_virtual_display(header_display,pasteboard,1,1);
  smg$erase_display(main_display);

  {Write topic information for category.}
  topic_list := topic_start;
  if (topic_list^.next <> nil) then
    begin
      count := 1;
      repeat
        topic_list := topic_list^.next;
        {Internal write form string for each topic for totals.}
	writev(topic_count_string,abs(topic_list^.number):4);
	writev(total_message_string,
               abs(topic_list^.message_counters.total_message):3);
	writev(new_message_string,
               abs(topic_list^.message_counters.new_message):3);
	smg$put_line(main_display,topic_count_string+'  '+
	       pad(topic_list^.topic,' ',17)+pad(topic_list^.subject,' ',44)+
               total_message_string+' |   '+new_message_string);
	count := count + 1;
      until (count > display_height) or (topic_list^.next = nil);

      if (topic_list^.next <> nil) then 
        begin
          smg$put_chars(main_display,' More topics ',18,34,,smg$m_reverse);
          if bb_manager then
            smg$set_physical_cursor(pasteboard,23,59)
          else
            smg$set_physical_cursor(pasteboard,23,47)
        end
      else
        begin
	  smg$put_chars(main_display,' End of topics ',18,33,,smg$m_reverse);
          if bb_manager then
            smg$set_physical_cursor(pasteboard,23,59)
          else
            smg$set_physical_cursor(pasteboard,23,47);
        end;
      smg$end_pasteboard_update(pasteboard);
    end
  else
    write_error('No topics exist.');
end;        
   
end.
