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

[global] 
procedure create_topic_dir_list;

{Create linked list of topics for chosen category.}

begin
  topic_curr := topic_root^.next;
  if not (topic_option in ['S',key_select]) then
    begin     {Dispose of previous topic list if there is one.}
      while (topic_curr <> nil) do
        begin
          topic_prev := topic_curr;
          topic_curr := topic_curr^.next;
          dispose(topic_prev);
        end;

      topic_curr:=topic_root;
      resetk(bbfile,0);
      topic_counter := 0;

      repeat 
        count := 0;
        repeat
          topic_counter := topic_counter + 1;
          read(bbfile,current_record,error:=continue);
          with current_record do
            begin
              if (date = null_date) and (status(bbfile) <= 0) then
                begin
                  count := count+1;
                  topic_prev := topic_curr;
                  new(topic_curr);
                  topic_prev^.next := topic_curr;
                  topic_curr^.previous := topic_prev;
                  topic_curr^.topic := topic;
                  topic_curr^.subject := subject;
        	  topic_curr^.number := topic_counter;
                 end;
            end;
        until (count = display_height) or (current_record.date <> null_date) or
               eof(bbfile) or (status(bbfile) > 0);
      until (current_record.date <> null_date) or
             eof(bbfile) or (status(bbfile) > 0);
      topic_curr^.next := nil;
    end;
  topic_list := topic_root;
  topic_start := topic_root;
  if (topic_counter > 1) then
    topic_counter := topic_counter - 1;
end;
end.
