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

[global] procedure select_topic;

{Query user for topic number to select}

var
  topic : packed array [1..topic_length] of char;
  select_number : integer;
  convert_line : string;
  ch : char;

begin
  t_menu := false;  {Flag for topic menu box}

  repeat
    select_first_time := true;  {Sets flag so new messages are listed first
      when topic is first chosen.}
    write_menu('','Number of topic to select <CR> | <CR> for menu: ');
    readstr(line);

    {Check validity of user entry.}
    if ((length(line) <> 0) and (line <> key_exit)) then
      begin
	ch := line[1];
	if ((ch in ['1'..'9']) and (length(line) < 3)) then
          begin
       	    convert_line := line;
            readv(convert_line,select_number);

            if (select_number in [1..topic_counter]) then
              begin
                if (topic_root^.next <> nil) then
                  topic_list := topic_root^.next;
                while ((select_number <> topic_list^.number) and 
                      (topic_list^.next <> nil)) do
 	          topic_list := topic_list^.next;
                if (topic_list <> nil) then 
                  topic := topic_list^.topic;
              end
            else
              write_error('Topic '+substr(line,1,length(line))+' does not exist.');
	  end;

        findk(bbfile,0,null_date+topic,eql,error:=continue);
        if (not(ufb(bbfile))) then
          begin
            current_topic := topic;
	    protected_topic_board; {Is current topic protected?}
          end;
      end;
  until (not ufb(bbfile)) or (length(line) = 0) or (line = key_exit);

  smg$unpaste_virtual_display(error_display,pasteboard);
end;

end.
