PROCEDURE prompt_for_port (
  port : (var) string = $optional
  status)

  create_variable input_string k=string
  create_variable integer_number k=integer
  create_variable conversion_status k=status

port_loop: ..
  LOOP
    put_line '0Enter the PORT number to which your terminal/printer is connected or ? for help:'
    accept_line input_string input p=''

    IF (input_string = '?') OR ($translate(lower_to_upper, input_string) = 'HELP') THEN
      put_line ('0Supply the PORT number to which your terminal/printer is connected.' ..
            ' This is a number from 0 to 7.  Look at the back of your DI.' ..
            ' Each async LIM has either 4 ports or 8 ports.'..
            ' The top PORT on each LIM is number 0.'..
            ' Find the line to your terminal/printer and enter its PORT number.', '  ')
    ELSEIF input_string = ' ' THEN
      IF ($value(port) <> ' ') THEN
        EXIT port_loop
      IFEND
    ELSEIF ($translate(lower_to_upper, input_string) = 'QUIT') OR ($translate(lower_to_upper, input_string) = 'QUI') THEN
      $value(port) = ' '
      EXIT port_loop
    ELSE
      include_line 'integer_number=$integer(input_string)' status=conversion_status
      IF conversion_status.normal THEN
        IF (integer_number >= 0) AND (integer_number <= 7) THEN
          $value(port) = input_string
          EXIT port_loop
        ELSE
          put_line ('0PORT number out of range, please correct.', '  ')
        IFEND
      ELSE
        put_line ('0Invalid PORT number, please correct.', '  ')
      IFEND
    IFEND
  LOOPEND port_loop

PROCEND prompt_for_port
