PROCEDURE (tum$distm) display_terminal_model, display_terminal_models, ..
distm (
  terminal_model, tm: any of
      key
        all
      keyend
      string
      name
    anyend = $terminal_model
  output, o: file = $output
  display_option, display_options, do: key
      (name, names, n)
      (help, h)
    keyend = $optional
  library, l: file = $system.tdu.terminal_definitions
  status)

  "$FORMAT=OFF"
  VAR
    ign_status: status
    one_line_summary: boolean = false
    output_line: list of string
    prefix_string: string = ' '
    scratch: file = $unique(:$local)
    terminal_names: list 0..$max_list of string
  VAREND
  "$FORMAT=ON"

" Display HELP if requested or unspecified and one terminal model.

  IF ((NOT $specified(display_option)) AND (terminal_model <> 'ALL') AND ..
        (terminal_model <> '')) THEN
    IF ($job(mode) = 'INTERACTIVE') AND ..
          ($strrep($path(output last)) = '$OUTPUT') THEN
      prefix_string = ' HELP for '
    ELSE
      prefix_string = '1HELP for '
    IFEND
  ELSEIF ($specified(display_option)) AND (display_option = help) THEN
    IF ($job(mode) = 'INTERACTIVE') AND ..
          ($strrep($path(output last)) = '$OUTPUT') THEN
      prefix_string = ' HELP for '
    ELSE
      prefix_string = '1HELP for '
    IFEND
  IFEND

  PUSH command_list
  create_command_list_entry e=library status=ign_status

  IF (terminal_model = 'ALL') OR (terminal_model = '') THEN
    set_file_attributes f=scratch fc=legible pf=continuous
    display_object_library l=library do=none ao=yes o=scratch
    get_lines i=scratch v=terminal_names
    delete_file f=scratch
    terminal_names = $select(terminal_names (($size(x)>4) and (x(1 4)=..
'CSM$')))
  ELSE
    terminal_names = 'CSM$'//terminal_model
  IFEND

  IF prefix_string = ' ' THEN
    one_line_summary = true
  IFEND

  FOR EACH terminal IN terminal_names DO
    output_line = prefix_string//terminal(5 all)
    IF one_line_summary THEN
      IF $condition_code($name('CSE$'//terminal(5 all)))<> 0 THEN
        terminal_help = $status_message(..
              $status(false 'CS' $name('CSE$'//terminal(5 all))) 80 brief)
        output_line = $justify(output_line(1) 31 left) //..
$trim(terminal_help(1)(3 all) ' ' l)
        IF terminal_help(2)<>' ' THEN
          second_line = $trim(terminal_help(2) ' ' l)
          output_line = $join(output_line ..
                $justify(second_line $size(second_line)+31 right))
        IFEND
      ELSE
        output_line = $justify(output_line(1) 31 left) //..
'No documentation for terminal model'
      IFEND
    IFEND
    put_line l=output_line o=output.$eoi
    IF prefix_string <> ' ' THEN
      IF $condition_code($name('CSE$'//terminal(5 all)))<> 0 THEN
        put_lines l=$status_message(..
              $status(false 'CS' $name('CSE$'//terminal(5 all))) 80 brief) ..
              o=output.$eoi
      ELSE
        put_lines ..
              l=' No documentation for terminal model '//terminal(5 all) ..
              o=output.$eoi
      IFEND
    IFEND
  FOREND

PROCEND display_terminal_model
