?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE SCL interpreter : Display Command List Entry' ??
MODULE clm$display_command_list_entry;

{
{ PURPOSE:
{   This module contains the processor for the display_command_list_entry command.
{

?? NEWTITLE := 'Global Declarations', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc clc$compiling_for_test_harness
*IF $true(osv$unix)
*copyc cle$ecc_utilities
*IFEND
*copyc cle$work_area_overflow
*copyc clt$command_list
*copyc clt$data_value
*copyc clt$parameter_list
*copyc clt$path_display_chunks
*copyc clt$work_area
*IF $true(osv$unix)
*copyc cyt$mips_signal_handler
*ELSE
*copyc fsc$compiling_for_test_harness
*copyc fst$path_handle_name
*copyc oss$job_paged_literal
*copyc ost$caller_identifier
*IFEND
*copyc ost$name_reference
*IF NOT $true(osv$unix)
*copyc pfe$error_condition_codes
*IFEND
?? POP ??
*copyc clp$build_path_subtitle
*copyc clp$build_standard_title
*copyc clp$close_command_library
*copyc clp$close_display
*copyc clp$convert_integer_to_string
*IF NOT $true(osv$unix)
*copyc clp$convert_string_to_file
*copyc clp$convert_string_to_file_ref
*IFEND
*copyc clp$evaluate_parameters
*IF NOT $true(osv$unix)
*copyc clp$find_command_entries
*IFEND
*copyc clp$find_command_list
*copyc clp$find_current_block
*copyc clp$get_work_area
*copyc clp$horizontal_tab_display
*copyc clp$make_command_ref_value
*copyc clp$make_list_value
*copyc clp$make_name_value
*copyc clp$new_display_line
*copyc clp$new_display_page
*IF NOT $true(osv$unix)
*copyc clp$open_command_library
*IFEND
*copyc clp$open_display_reference
*copyc clp$put_display
*copyc clp$put_partial_display
*copyc clp$reset_for_next_display_page
*copyc clp$trimmed_string_size
*copyc clv$intrinsic_commands
*copyc clv$nil_display_control
*IF NOT $true(osv$unix)
*copyc clv$operator_commands
*copyc clv$system_commands
*IFEND
*copyc clv$system_functions
*copyc clv$system_functions_v0
*IF NOT $true(osv$unix)
  ?IF fsc$compiling_for_test_harness AND clc$compiling_for_test_harness THEN
*copyc fsv$test_harness_cmnds
*copyc fsv$test_harness_fnctns
  ?IFEND
*copyc jmp$system_job
*copyc osp$disestablish_cond_handler
*copyc osp$enforce_exception_policies
*copyc osp$establish_block_exit_hndlr
*copyc osp$file_access_condition
*IFEND
*copyc osp$set_status_abnormal
*IF NOT $true(osv$unix)
*copyc osv$initial_exception_context
*IFEND
*copyc osv$upper_to_lower
?? EJECT ??

  TYPE
    entry_type = record
      name: ost$name,
      class: clt$named_entry_class,
      availability: clt$named_entry_availability,
      ordinal: clt$named_entry_ordinal,
    recend;

  TYPE
    entry_array = array [1 .. * ] of entry_type;

  TYPE
    option_type = record
      all_entries: boolean,
      first: boolean,
      control_statements: boolean,
      commands: boolean,
      functions: boolean,
      names: boolean,
      all_names: boolean,
      advanced_usage: boolean,
      starting_procedures: boolean,
    recend;

  TYPE
    individual_entry_type = record
      case kind: (system_entry, utility_entry, file_entry) of
      = system_entry =
        ,
      = utility_entry =
        utility_name: clt$utility_name,
        utility_info: ^clt$utility_command_environment,
      = file_entry =
        path_handle_name: fst$path_handle_name,
      casend,
    recend;

?? TITLE := 'clp$_display_command_list_entry', EJECT ??

  PROCEDURE [XDCL] clp$_display_command_list_entry
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

*IF NOT $true(osv$unix)
{ PROCEDURE (osm$discle) display_command_list_entry, display_command_list_entries, discle (
{   entry, entries, e: list of any of
{       key
{         all
{         (control_statements, control_statement, cs)
{         (first, f)
{         $system
{       keyend
{       name
{       file
{     anyend = first
{   display_options, display_option, do: list of key
{       all
{       (all_names, all_name, an)
{       (commands, command, c)
{       (functions, function, f)
{       (names, name, n)
{       (advanced_usage, au)
{       (starting_procedures, starting_procedure, sp)
{     keyend = osd$discle_display_options, (commands, names)
{   output, o: file = $output
{   status)

?? PUSH (LISTEXT := ON) ??
?? FMT (FORMAT := OFF) ??

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 9] of clt$pdt_parameter_name,
      parameters: array [1 .. 4] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        qualifier: clt$list_type_qualifier_v2,
        element_type_spec: record
          header: clt$type_specification_header,
          qualifier: clt$union_type_qualifier,
          type_size_1: clt$type_specification_size,
          element_type_spec_1: record
            header: clt$type_specification_header,
            qualifier: clt$keyword_type_qualifier,
            keyword_specs: array [1 .. 7] of clt$keyword_specification,
          recend,
          type_size_2: clt$type_specification_size,
          element_type_spec_2: record
            header: clt$type_specification_header,
            qualifier: clt$name_type_qualifier,
          recend,
          type_size_3: clt$type_specification_size,
          element_type_spec_3: record
            header: clt$type_specification_header,
          recend,
        recend,
        default_value: string (5),
      recend,
      type2: record
        header: clt$type_specification_header,
        qualifier: clt$list_type_qualifier_v2,
        element_type_spec: record
          header: clt$type_specification_header,
          qualifier: clt$keyword_type_qualifier,
          keyword_specs: array [1 .. 18] of clt$keyword_specification,
        recend,
        default_name: string (26),
        default_value: string (17),
      recend,
      type3: record
        header: clt$type_specification_header,
        default_value: string (7),
      recend,
      type4: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [90, 2, 21, 16, 15, 43, 681],
    clc$command, 9, 4, 0, 0, 0, 0, 4, 'OSM$DISCLE'], [
    ['DISPLAY_OPTION                 ',clc$alias_entry, 2],
    ['DISPLAY_OPTIONS                ',clc$nominal_entry, 2],
    ['DO                             ',clc$abbreviation_entry, 2],
    ['E                              ',clc$abbreviation_entry, 1],
    ['ENTRIES                        ',clc$alias_entry, 1],
    ['ENTRY                          ',clc$nominal_entry, 1],
    ['O                              ',clc$abbreviation_entry, 3],
    ['OUTPUT                         ',clc$nominal_entry, 3],
    ['STATUS                         ',clc$nominal_entry, 4]],
    [
{ PARAMETER 1
    [6, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation, clc$standard_parameter_checking, 314,
  clc$optional_default_parameter, 0, 5],
{ PARAMETER 2
    [2, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation, clc$standard_parameter_checking, 689,
  clc$optional_default_parameter, 26, 17],
{ PARAMETER 3
    [8, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation, clc$standard_parameter_checking, 3,
  clc$optional_default_parameter, 0, 7],
{ PARAMETER 4
    [9, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_reference, clc$immediate_evaluation, clc$standard_parameter_checking, 3,
  clc$optional_parameter, 0, 0]],
{ PARAMETER 1
    [[1, 0, clc$list_type], [298, 1, clc$max_list_size, 0, FALSE, FALSE],
      [[1, 0, clc$union_type], [[clc$file_type, clc$keyword_type, clc$name_type],
      FALSE, 3],
      266, [[1, 0, clc$keyword_type], [7], [
        ['$SYSTEM                        ', clc$nominal_entry, clc$normal_usage_entry, 4],
        ['ALL                            ', clc$nominal_entry, clc$normal_usage_entry, 1],
        ['CONTROL_STATEMENT              ', clc$alias_entry, clc$normal_usage_entry, 2],
        ['CONTROL_STATEMENTS             ', clc$nominal_entry, clc$normal_usage_entry, 2],
        ['CS                             ', clc$abbreviation_entry, clc$normal_usage_entry, 2],
        ['F                              ', clc$abbreviation_entry, clc$normal_usage_entry, 3],
        ['FIRST                          ', clc$nominal_entry, clc$normal_usage_entry, 3]]
        ],
      5, [[1, 0, clc$name_type], [1, osc$max_name_size]],
      3, [[1, 0, clc$file_type]]
      ]
    ,
    'first'],
{ PARAMETER 2
    [[1, 0, clc$list_type], [673, 1, clc$max_list_size, 0, FALSE, FALSE],
      [[1, 0, clc$keyword_type], [18], [
      ['ADVANCED_USAGE                 ', clc$nominal_entry, clc$normal_usage_entry, 6],
      ['ALL                            ', clc$nominal_entry, clc$normal_usage_entry, 1],
      ['ALL_NAME                       ', clc$alias_entry, clc$normal_usage_entry, 2],
      ['ALL_NAMES                      ', clc$nominal_entry, clc$normal_usage_entry, 2],
      ['AN                             ', clc$abbreviation_entry, clc$normal_usage_entry, 2],
      ['AU                             ', clc$abbreviation_entry, clc$normal_usage_entry, 6],
      ['C                              ', clc$abbreviation_entry, clc$normal_usage_entry, 3],
      ['COMMAND                        ', clc$alias_entry, clc$normal_usage_entry, 3],
      ['COMMANDS                       ', clc$nominal_entry, clc$normal_usage_entry, 3],
      ['F                              ', clc$abbreviation_entry, clc$normal_usage_entry, 4],
      ['FUNCTION                       ', clc$alias_entry, clc$normal_usage_entry, 4],
      ['FUNCTIONS                      ', clc$nominal_entry, clc$normal_usage_entry, 4],
      ['N                              ', clc$abbreviation_entry, clc$normal_usage_entry, 5],
      ['NAME                           ', clc$alias_entry, clc$normal_usage_entry, 5],
      ['NAMES                          ', clc$nominal_entry, clc$normal_usage_entry, 5],
      ['SP                             ', clc$abbreviation_entry, clc$normal_usage_entry, 7],
      ['STARTING_PROCEDURE             ', clc$alias_entry, clc$normal_usage_entry, 7],
      ['STARTING_PROCEDURES            ', clc$nominal_entry, clc$normal_usage_entry, 7]]
      ]
    ,
    'OSD$DISCLE_DISPLAY_OPTIONS',
    '(commands, names)'],
{ PARAMETER 3
    [[1, 0, clc$file_type],
    '$output'],
{ PARAMETER 4
    [[1, 0, clc$status_type]]];

?? FMT (FORMAT := ON) ??
?? POP ??

    CONST
      p$entry = 1,
      p$display_options = 2,
      p$output = 3,
      p$status = 4;

    VAR
      pvt: array [1 .. 4] of clt$parameter_value;
*ELSE
{ PROCEDURE (osm$discle) display_command_list_entry, display_command_list_entr..
{ ies, discle (
{   entry, entries, e: list of any of
{       key
{         all
{         (control_statements, control_statement, cs)
{         (first, f)
{       keyend
{       name
{     anyend = first
{   display_options, display_option, do: list of key
{       all
{       (all_names, all_name, an)
{       (commands, command, c)
{       (functions, function, f)
{       (names, name, n)
{       (advanced_usage, au)
{     keyend = (commands, names)
{   output, o: file = $output
{   status)



?? PUSH (LISTEXT := ON) ??
?? FMT (FORMAT := OFF) ??

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 9] of clt$pdt_parameter_name,
      parameters: array [1 .. 4] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        qualifier: clt$list_type_qualifier_v2,
        element_type_spec: record
          header: clt$type_specification_header,
          qualifier: clt$union_type_qualifier_v2,
          type_size_1: clt$type_specification_size,
          element_type_spec_1: record
            header: clt$type_specification_header,
            qualifier: clt$keyword_type_qualifier,
            keyword_specs: array [1 .. 6] of clt$keyword_specification,
          recend,
          type_size_2: clt$type_specification_size,
          element_type_spec_2: record
            header: clt$type_specification_header,
            qualifier: clt$name_type_qualifier,
          recend,
        recend,
        default_value: ALIGNED [0 MOD 4] string (5),
      recend,
      type2: record
        header: clt$type_specification_header,
        qualifier: clt$list_type_qualifier_v2,
        element_type_spec: record
          header: clt$type_specification_header,
          qualifier: clt$keyword_type_qualifier,
          keyword_specs: array [1 .. 15] of clt$keyword_specification,
        recend,
        default_value: ALIGNED [0 MOD 4] string (17),
      recend,
      type3: record
        header: clt$type_specification_header,
        default_value: ALIGNED [0 MOD 4] string (7),
      recend,
      type4: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [2,
    [91, 9, 16, 8, 48, 24, 0],
    clc$command, 9, 4, 0, 0, 0, 0, 4, 'OSM$DISCLE'], [
    ['DISPLAY_OPTION                 ',clc$alias_entry, 2],
    ['DISPLAY_OPTIONS                ',clc$nominal_entry, 2],
    ['DO                             ',clc$abbreviation_entry, 2],
    ['E                              ',clc$abbreviation_entry, 1],
    ['ENTRIES                        ',clc$alias_entry, 1],
    ['ENTRY                          ',clc$nominal_entry, 1],
    ['O                              ',clc$abbreviation_entry, 3],
    ['OUTPUT                         ',clc$nominal_entry, 3],
    ['STATUS                         ',clc$nominal_entry, 4]],
    [
{ PARAMETER 1
    [6, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 306, clc$optional_default_parameter, 0, 5],
{ PARAMETER 2
    [2, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 636, clc$optional_default_parameter, 0, 17],
{ PARAMETER 3
    [8, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 3, clc$optional_default_parameter, 0, 7],
{ PARAMETER 4
    [9, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_reference, clc$immediate_evaluation,
  clc$standard_parameter_checking, 3, clc$optional_parameter, 0, 0]],
{ PARAMETER 1
    [[2, 0, clc$list_type], [278, 1, clc$max_list_size, 0, FALSE, FALSE],
      [[2, 0, clc$union_type], [[clc$keyword_type,
      clc$name_type],
      FALSE, 2],
      248, [[2, 0, clc$keyword_type], [6], [
        ['ALL                            ', clc$nominal_entry,
  clc$normal_usage_entry, 1],
        ['CONTROL_STATEMENT              ', clc$alias_entry,
  clc$normal_usage_entry, 2],
        ['CONTROL_STATEMENTS             ', clc$nominal_entry,
  clc$normal_usage_entry, 2],
        ['CS                             ', clc$abbreviation_entry,
  clc$normal_usage_entry, 2],
        ['F                              ', clc$abbreviation_entry,
  clc$normal_usage_entry, 3],
        ['FIRST                          ', clc$nominal_entry,
  clc$normal_usage_entry, 3]]
        ],
      6, [[2, 0, clc$name_type], [1, osc$max_name_size]]
      ]
    ,
    'first'],
{ PARAMETER 2
    [[2, 0, clc$list_type], [608, 1, clc$max_list_size, 0, FALSE, FALSE],
      [[2, 0, clc$keyword_type], [15], [
      ['ADVANCED_USAGE                 ', clc$nominal_entry,
  clc$normal_usage_entry, 6],
      ['ALL                            ', clc$nominal_entry,
  clc$normal_usage_entry, 1],
      ['ALL_NAME                       ', clc$alias_entry,
  clc$normal_usage_entry, 2],
      ['ALL_NAMES                      ', clc$nominal_entry,
  clc$normal_usage_entry, 2],
      ['AN                             ', clc$abbreviation_entry,
  clc$normal_usage_entry, 2],
      ['AU                             ', clc$abbreviation_entry,
  clc$normal_usage_entry, 6],
      ['C                              ', clc$abbreviation_entry,
  clc$normal_usage_entry, 3],
      ['COMMAND                        ', clc$alias_entry,
  clc$normal_usage_entry, 3],
      ['COMMANDS                       ', clc$nominal_entry,
  clc$normal_usage_entry, 3],
      ['F                              ', clc$abbreviation_entry,
  clc$normal_usage_entry, 4],
      ['FUNCTION                       ', clc$alias_entry,
  clc$normal_usage_entry, 4],
      ['FUNCTIONS                      ', clc$nominal_entry,
  clc$normal_usage_entry, 4],
      ['N                              ', clc$abbreviation_entry,
  clc$normal_usage_entry, 5],
      ['NAME                           ', clc$alias_entry,
  clc$normal_usage_entry, 5],
      ['NAMES                          ', clc$nominal_entry,
  clc$normal_usage_entry, 5]]
      ]
    ,
    '(commands, names)'],
{ PARAMETER 3
    [[2, 0, clc$file_type],
    '$output'],
{ PARAMETER 4
    [[2, 0, clc$status_type]]];

?? FMT (FORMAT := ON) ??
?? POP ??

    CONST
      p$entry = 1,
      p$display_options = 2,
      p$output = 3,
      p$status = 4;

    VAR
      pvt: array [1 .. 4] of clt$parameter_value;
*IFEND

*copyc clv$display_variables

    CONST
      minimum_all_names_line_size = minimum_line_size + osc$max_name_size + 1,
      minimum_display_line = osc$max_name_size + 3,
      minimum_line_size = osc$max_name_size + 3,
      display_name_size = osc$max_name_size + 2;

    TYPE
      control_type = record
        put_subtitle_header: boolean,
        file_name: ^fst$file_reference,
        entry_name: ost$name,
        entry_kind: ost$name,
      recend;

    VAR
      block: ^clt$block,
      command_list: ^clt$command_list,
      command_reference: clt$command_reference,
      current_node: ^clt$data_value,
*IF NOT $true(osv$unix)
      default_ring_attributes: amt$ring_attributes,
*IFEND
      display_control: clt$display_control,
*IF NOT $true(osv$unix)
      effective_search_mode: clt$command_search_modes,
*IFEND
      end_of_list: ^clt$command_list_entry,
      file: clt$file,
*IF $true(osv$unix)
      handler_established: boolean,
*IFEND
      ignore_cmnd_list_found_in_task: boolean,
      individual_entries: ^array [1 .. * ] of individual_entry_type,
      individual_entry_count: integer,
      individual_file_reference: ^fst$file_reference,
      line_size: amt$page_width,
      local_status: ost$status,
      names_per_line: integer,
      options: option_type,
      output_control: control_type,
      start_of_list: ^clt$command_list_entry,
      utility_info: ^clt$utility_command_environment,
      work_area: ^^clt$work_area;

?? NEWTITLE := 'abort_handler', EJECT ??

    PROCEDURE abort_handler
*IF $true(osv$unix)
      (    signal_no: integer;
           code: integer;
           p_sigcontext: ^cyt$mips_sigcontext);

      VAR
        ignore_status: ost$status;

      clp$close_display (display_control, ignore_status);
*ELSE
      (    condition: pmt$condition;
           condition_information: ^pmt$condition_information;
           save_area: ^ost$stack_frame_save_area;
       VAR handler_status: ost$status);


      clp$close_display (display_control, handler_status);
      handler_status.normal := TRUE;
*IFEND

    PROCEND abort_handler;
*copyc clp$new_page_procedure
?? TITLE := 'put_subtitle', EJECT ??

    PROCEDURE put_subtitle
      (VAR display_control: clt$display_control;
       VAR status: ost$status);

      CONST
        header = 'ENTRY  ';

      VAR
        chunk_count: 0 .. fsc$max_path_elements,
        display_chunks: clt$path_display_chunks,
        header_length: integer;


      status.normal := TRUE;
      IF output_control.put_subtitle_header THEN
        put_partial_display (header, clc$no_trim, amc$continue);
        header_length := STRLENGTH (header);
      ELSE
        header_length := 0;
      IFEND;

      IF output_control.file_name <> NIL THEN
        clp$build_path_subtitle (output_control.file_name^,
              clp$trimmed_string_size (output_control.file_name^), line_size - header_length, chunk_count,
              display_chunks);
        put_path_chunks (output_control.file_name^, display_chunks, chunk_count, header_length + 1, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;

      ELSEIF output_control.entry_name <> '' THEN
        put_partial_display (output_control.entry_name, clc$trim, amc$terminate);
      IFEND;

      IF output_control.entry_kind <> '' THEN
        clv$subtitles_built := FALSE;
        put_partial_display (output_control.entry_kind, clc$trim, amc$terminate);
      IFEND;

    PROCEND put_subtitle;
?? TITLE := 'put_path_chunks', EJECT ??

    PROCEDURE put_path_chunks
      (    path_name: fst$file_reference;
           display_chunks: clt$path_display_chunks;
           chunk_count: 0 .. fsc$max_path_elements;
           column: amt$page_width;
       VAR status: ost$status);

      VAR
        i: 0 .. fsc$max_path_elements,
        terminate_string: string (2);


      terminate_string := '..';
      FOR i := 1 TO chunk_count DO
        clp$horizontal_tab_display (display_control, column, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
        IF i = chunk_count THEN
          terminate_string := '  ';
        IFEND;
        put_partial_display (path_name (display_chunks [i].position, display_chunks [i].length),
              clc$trim, amc$continue);
        put_partial_display (terminate_string, clc$trim, amc$terminate);
      FOREND;

    PROCEND put_path_chunks;
?? TITLE := 'put_partial_display', EJECT ??

    PROCEDURE [INLINE] put_partial_display
      (    str: string ( * );
           trim_option: clt$trim_display_text_option;
           term_option: amt$term_option);


      clp$put_partial_display (display_control, str, trim_option, term_option, status);
      IF NOT status.normal THEN
        EXIT clp$_display_command_list_entry;
      IFEND;

    PROCEND put_partial_display;
?? TITLE := 'display_command_list_entries', EJECT ??

    PROCEDURE display_command_list_entries;

*IF NOT $true(osv$unix)
      VAR
        control_statements: [STATIC, READ, oss$job_paged_literal] array [1 .. 30] of entry_type := [
              {} ['BLOCK / BLOCKEND               ', clc$nominal_entry, clc$normal_usage_entry, 1],
              {} ['CANCEL                         ', clc$nominal_entry, clc$normal_usage_entry, 2],
              {} ['CASE / selector / ELSE / CASEND', clc$nominal_entry, clc$hidden_entry, 3],
              {} ['CAUSE                          ', clc$nominal_entry, clc$normal_usage_entry, 4],
              {} ['CHECK / CHECKEND               ', clc$nominal_entry, clc$hidden_entry, 5],
              {} ['COLLECT_TEXT                   ', clc$nominal_entry, clc$normal_usage_entry, 6],
              {} ['COLT                           ', clc$abbreviation_entry, clc$normal_usage_entry, 6],
              {} ['CONTINUE                       ', clc$nominal_entry, clc$normal_usage_entry, 7],
              {} ['CYCLE                          ', clc$nominal_entry, clc$normal_usage_entry, 8],
              {} ['EXIT                           ', clc$nominal_entry, clc$normal_usage_entry, 9],
              {} ['EXIT_PROC                      ', clc$nominal_entry, clc$hidden_entry, 10],
              {} ['FOR / FOREND                   ', clc$nominal_entry, clc$normal_usage_entry, 11],
              {} ['FUNCTION / FUNCEND             ', clc$nominal_entry, clc$hidden_entry, 12],
              {} ['IF / ELSEIF / ELSE / IFEND     ', clc$nominal_entry, clc$normal_usage_entry, 13],
              {} ['JOB / JOBEND                   ', clc$nominal_entry, clc$normal_usage_entry, 14],
              {} ['LOCK                           ', clc$nominal_entry, clc$hidden_entry, 15],
              {} ['LOOP / LOOPEND                 ', clc$nominal_entry, clc$normal_usage_entry, 16],
              {} ['PIPE / PIPEND                  ', clc$nominal_entry, clc$hidden_entry, 17],
              {} ['POP                            ', clc$nominal_entry, clc$normal_usage_entry, 18],
              {} ['PROCEDURE / PROCEND            ', clc$nominal_entry, clc$normal_usage_entry, 19],
              {} ['PUSH                           ', clc$nominal_entry, clc$normal_usage_entry, 20],
              {} ['PUSH_COMMANDS                  ', clc$nominal_entry, clc$normal_usage_entry, 21],
              {} ['REPEAT / UNTIL                 ', clc$nominal_entry, clc$normal_usage_entry, 22],
              {} ['TASK / TASKEND                 ', clc$nominal_entry, clc$normal_usage_entry, 23],
              {} ['TYPE / TYPEND                  ', clc$nominal_entry, clc$normal_usage_entry, 24],
              {} ['UNLOCK                         ', clc$nominal_entry, clc$hidden_entry, 25],
              {} ['UTILITY / UTILITYEND           ', clc$nominal_entry, clc$normal_usage_entry, 26],
              {} ['VAR / VAREND                   ', clc$nominal_entry, clc$normal_usage_entry, 27],
              {} ['WHEN / WHENEND                 ', clc$nominal_entry, clc$normal_usage_entry, 28],
              {} ['WHILE / WHILEND                ', clc$nominal_entry, clc$normal_usage_entry, 29]];
*IFEND

      VAR
        command_entries: ^entry_array,
        current_entry: ^clt$command_list_entry,
        function_entries: ^entry_array,
        i: integer,
        library_accessable: boolean,
        original_work_area: ^clt$work_area,
        system_entry_found: boolean;

?? NEWTITLE := 'display_all_names', EJECT ??

      PROCEDURE display_all_names
        (    entries: entry_array);

        VAR
          abbrev_count: 0 .. clc$max_command_table_size,
          abbreviations: ^entry_array,
          alias_count: 0 .. clc$max_command_table_size,
          aliases: ^entry_array,
          i: 1 .. clc$max_command_table_size,
          index: 1 .. clc$max_command_table_size,
          j: 1 .. clc$max_command_table_size,
          k: 1 .. clc$max_command_table_size,
          name_count: 0 .. clc$max_command_table_size,
          names: ^array [1 .. * ] of ost$name,
          nominal_count: 0 .. clc$max_command_table_size,
          nominals: ^entry_array,
          number_of_entries: 0 .. clc$max_command_table_size;

?? NEWTITLE := 'put_names', EJECT ??

        PROCEDURE put_names;

          CONST
            tab_over = osc$max_name_size + 2;

          VAR
            index: 2 .. clc$max_command_table_size,
            nominal_name: string (osc$max_name_size + 1),
            seperator: string (3),
            term_option: amt$term_option,
            trim_option: clt$trim_display_text_option;


          nominal_name := names^ [1];
          seperator := ',  ';

          IF name_count = 1 THEN
            put_name (names^ [1], clc$trim, amc$terminate);
          ELSE
            put_name (nominal_name, clc$no_trim, amc$start);

            trim_option := clc$trim;
            term_option := amc$continue;

            FOR index := 2 TO name_count DO
              IF (display_control.column_number + clp$trimmed_string_size (names^ [index]) + 2) >
                    line_size THEN
                clp$new_display_line (display_control, clc$next_display_line, status);
                IF NOT status.normal THEN
                  EXIT clp$_display_command_list_entry;
                IFEND;
                clp$horizontal_tab_display (display_control, tab_over, status);
                IF NOT status.normal THEN
                  EXIT clp$_display_command_list_entry;
                IFEND;
              IFEND;

              put_name (names^ [index], trim_option, term_option);
              IF index = name_count THEN
                term_option := amc$terminate;
                seperator := '   ';
              IFEND;

              put_partial_display (seperator, clc$no_trim, term_option);
            FOREND;
          IFEND;

        PROCEND put_names;
?? OLDTITLE, EJECT ??

        nominal_count := 0;
        alias_count := 0;
        abbrev_count := 0;

        number_of_entries := UPPERBOUND (entries);

        PUSH nominals: [1 .. number_of_entries];
        PUSH aliases: [1 .. number_of_entries];
        PUSH abbreviations: [1 .. number_of_entries];

        FOR index := 1 TO number_of_entries DO
          IF (entries [index].availability = clc$normal_usage_entry) OR
                ((entries [index].availability = clc$advanced_usage_entry) AND options.advanced_usage) THEN
            IF entries [index].class = clc$nominal_entry THEN
              nominal_count := nominal_count + 1;
              nominals^ [nominal_count] := entries [index];
            ELSEIF entries [index].class = clc$alias_entry THEN
              alias_count := alias_count + 1;
              aliases^ [alias_count] := entries [index];
            ELSE
              abbrev_count := abbrev_count + 1;
              abbreviations^ [abbrev_count] := entries [index];
            IFEND;
          IFEND;
        FOREND;

        PUSH names: [1 .. number_of_entries];
        FOR i := 1 TO nominal_count DO
          name_count := 1;
          names^ [name_count] := nominals^ [i].name;
          FOR j := 1 TO alias_count DO
            IF aliases^ [j].ordinal = nominals^ [i].ordinal THEN
              name_count := name_count + 1;
              names^ [name_count] := aliases^ [j].name;
            IFEND;
          FOREND;
          FOR k := 1 TO abbrev_count DO
            IF abbreviations^ [k].ordinal = nominals^ [i].ordinal THEN
              name_count := name_count + 1;
              names^ [name_count] := abbreviations^ [k].name;
            IFEND;
          FOREND;
          put_names;
        FOREND;

      PROCEND display_all_names;
*IF NOT $true(osv$unix)
?? TITLE := 'display_catalog_entries', EJECT ??

      PROCEDURE display_catalog_entries;


        output_control.file_name := ^command_reference.catalog;
        output_control.entry_name := '';
        output_control.entry_kind := '';

        IF options.commands THEN
          reset_display;
          put_partial_display ('--  Potential commands within a catalog are not shown.', clc$no_trim,
                amc$terminate);
        IFEND;

        IF options.functions THEN
          reset_display;
          put_partial_display ('--  Catalogs do not contain functions.', clc$no_trim, amc$terminate);
        IFEND;

      PROCEND display_catalog_entries;
*IFEND
?? TITLE := 'display_command_entries', EJECT ??

      PROCEDURE display_command_entries;


        IF command_entries = NIL THEN
          output_control.entry_kind := '';
          reset_display;
          put_partial_display ('--  No commands.', clc$no_trim, amc$terminate);
        ELSE
          output_control.entry_kind := 'Commands';
          reset_display;
          IF options.all_names THEN
            display_all_names (command_entries^);
          ELSE
            display_nominal_names (command_entries^);
          IFEND;
        IFEND;

      PROCEND display_command_entries;
?? TITLE := 'display_control_entries', EJECT ??

      PROCEDURE display_control_entries
        (    name: ost$name_reference;
             entries: entry_array);


        output_control.put_subtitle_header := FALSE;
        output_control.file_name := NIL;
        output_control.entry_kind := '';
        output_control.entry_name := name;
        reset_display;

        IF options.all_names THEN
          display_all_names (entries);
        ELSE
          display_nominal_names (entries);
        IFEND;

      PROCEND display_control_entries;
*IF NOT $true(osv$unix)
?? TITLE := 'display_fence', EJECT ??

      PROCEDURE [INLINE] display_fence;


        output_control.file_name := NIL;
        output_control.entry_name := 'fence';
        output_control.entry_kind := '';

        reset_display;
        put_partial_display ('--  Exclusive or restricted command searches do not go beyond this entry.',
              clc$no_trim, amc$terminate);

      PROCEND display_fence;
*IFEND
?? TITLE := 'display_function_entries', EJECT ??

      PROCEDURE display_function_entries;


        IF function_entries = NIL THEN
          output_control.entry_kind := '';
          reset_display;
          put_partial_display ('--  No functions.', clc$no_trim, amc$terminate);
        ELSE
          output_control.entry_kind := 'Functions';
          reset_display;
          IF options.all_names THEN
            display_all_names (function_entries^);
          ELSE
            display_nominal_names (function_entries^);
          IFEND;
        IFEND;

      PROCEND display_function_entries;
*IF NOT $true(osv$unix)
?? TITLE := 'display_library_entries', EJECT ??

      PROCEDURE [INLINE] display_library_entries;


        output_control.file_name := ^command_reference.library_or_catalog;
        output_control.entry_name := '';

        IF library_accessable THEN
          IF options.commands THEN
            display_command_entries;
          IFEND;

          IF options.functions THEN
            display_function_entries;
          IFEND;

        ELSE
          output_control.entry_kind := '';
          reset_display;

{         put_partial_display ('--  Requestor does not have sufficient privilege to read this file.',
{               clc$no_trim, amc$terminate);

          put_partial_display ('--  Requestor currently does not have sufficient privilege to read this file',
                clc$no_trim, amc$terminate);
          put_partial_display ('    or the file is currently unavailable.', clc$no_trim, amc$terminate);
        IFEND;

      PROCEND display_library_entries;
*IFEND
?? TITLE := 'display_nominal_names', EJECT ??

      PROCEDURE display_nominal_names
        (    entries: entry_array);

        VAR
          desired_entries: integer,
          display_name: string (display_name_size),
          index: integer,
          number_of_entries: integer,
          term_option: amt$term_option,
          trim: clt$trim_display_text_option;


        term_option := amc$continue;
        number_of_entries := UPPERBOUND (entries);
        desired_entries := 0;

        FOR index := 1 TO number_of_entries DO
          IF (entries [index].class = clc$nominal_entry) AND
                ((entries [index].availability = clc$normal_usage_entry) OR
                ((entries [index].availability = clc$advanced_usage_entry) AND options.advanced_usage)) THEN
            desired_entries := desired_entries + 1;
            IF (desired_entries MOD names_per_line) = 0 THEN
              term_option := amc$terminate;
              trim := clc$trim;
            ELSE
              term_option := amc$continue;
              trim := clc$no_trim;
            IFEND;
            display_name := entries [index].name;
            put_name (display_name, trim, term_option);
          IFEND;
        FOREND;

      PROCEND display_nominal_names;
?? TITLE := 'display_system_entries', EJECT ??

      PROCEDURE [INLINE] display_system_entries;


        system_entry_found := TRUE;

        output_control.file_name := NIL;
        output_control.entry_name := '$system';

        IF options.commands THEN
          display_command_entries;
        IFEND;

        IF options.functions THEN
          display_function_entries;
        IFEND;

      PROCEND display_system_entries;
?? TITLE := 'display_utility_entries', EJECT ??

      PROCEDURE [INLINE] display_utility_entries
        (    name: ost$name);


        output_control.file_name := NIL;
        #TRANSLATE (osv$upper_to_lower, name, output_control.entry_name);

        IF options.commands THEN
          display_command_entries;
        IFEND;

        IF options.functions THEN
          display_function_entries;
        IFEND;

      PROCEND display_utility_entries;
?? TITLE := 'put_name', EJECT ??

      PROCEDURE [INLINE] put_name
        (    name: string ( * <= display_name_size);
             trim_option: clt$trim_display_text_option;
             term_option: amt$term_option);

        VAR
          translated_name: string (display_name_size);


        #TRANSLATE (osv$upper_to_lower, name, translated_name);

        put_partial_display (translated_name (1, STRLENGTH (name)), trim_option, term_option);

      PROCEND put_name;
?? TITLE := 'reset_display', EJECT ??

      PROCEDURE reset_display;


        IF (display_control.page_format = amc$continuous_form) OR
              (display_control.page_format = amc$untitled_form) THEN
          clp$new_display_line (display_control, 3, status);
          IF NOT status.normal THEN
            EXIT clp$_display_command_list_entry;
          IFEND;
          put_subtitle (display_control, status);
          IF NOT status.normal THEN
            EXIT clp$_display_command_list_entry;
          IFEND;
          clp$new_display_line (display_control, 1, status);
        ELSE
          clp$new_display_page (display_control, status);
        IFEND;
        IF NOT status.normal THEN
          EXIT clp$_display_command_list_entry;
        IFEND;

      PROCEND reset_display;
?? OLDTITLE, EJECT ??

      current_entry := start_of_list;
      system_entry_found := FALSE;
      original_work_area := work_area^;


*IF NOT $true(osv$unix)
      IF options.control_statements AND options.commands THEN
        display_control_entries ('Control Statements', control_statements);
      IFEND;
*IFEND

      IF options.first OR options.all_entries THEN
        output_control.put_subtitle_header := TRUE;

        WHILE current_entry <> end_of_list DO
          clv$subtitles_built := FALSE;
          get_command_and_func_entries (options, command_list, current_entry, NIL, FALSE, TRUE, work_area^,
                command_entries, function_entries, command_reference, library_accessable, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;

          CASE current_entry^.kind OF
*IF NOT $true(osv$unix)
          = clc$library_commands =
            display_library_entries;
          = clc$catalog_commands, clc$working_catalog_commands =
            display_catalog_entries;
*IFEND
          = clc$system_commands =
            display_system_entries;
          = clc$sub_commands =
            display_utility_entries (current_entry^.utility_name);
*IF NOT $true(osv$unix)
          = clc$command_list_fence =
            display_fence;
*IFEND
          CASEND;

          work_area^ := original_work_area;
          IF options.first THEN
            current_entry := end_of_list;
          ELSE
            current_entry := current_entry^.next_entry;
          IFEND;
        WHILEND;
      IFEND;

      IF individual_entry_count > 0 THEN
        output_control.put_subtitle_header := TRUE;

        FOR i := 1 TO individual_entry_count DO
          get_command_and_func_entries (options, command_list, NIL, ^individual_entries^ [i], FALSE, FALSE,
                work_area^, command_entries, function_entries, command_reference, library_accessable, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;

          CASE individual_entries^ [i].kind OF
          = system_entry =
            display_system_entries;
          = utility_entry =
            display_utility_entries (individual_entries^ [i].utility_name);
*IF NOT $true(osv$unix)
          = file_entry =
            IF command_reference.form = clc$file_cycle_command_ref THEN
              display_catalog_entries;
            ELSE
              display_library_entries;
            IFEND;
*IFEND
          CASEND;

          work_area^ := original_work_area;
        FOREND;
      IFEND;

      IF options.control_statements THEN
        get_command_and_func_entries (options, command_list, NIL, NIL, FALSE, FALSE, work_area^,
              command_entries, function_entries, command_reference, library_accessable, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;

        IF options.commands THEN
          display_control_entries ('Control Commands', command_entries^);
        IFEND;
        IF options.functions AND (NOT system_entry_found) THEN
          display_control_entries ('System Supplied Functions', function_entries^);
        IFEND;

        work_area^ := original_work_area;

*IF NOT $true(osv$unix)
        ?IF fsc$compiling_for_test_harness AND clc$compiling_for_test_harness THEN
          get_command_and_func_entries (options, command_list, NIL, NIL, TRUE, FALSE, work_area^,
                command_entries, function_entries, command_reference, library_accessable, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;

          IF options.commands THEN
            display_control_entries ('Test Harness Commands', command_entries^);
          IFEND;
          IF options.functions THEN
            display_control_entries ('Test Harness Functions', function_entries^);
          IFEND;

          work_area^ := original_work_area;
        ?IFEND
*IFEND
      IFEND;

    PROCEND display_command_list_entries;
?? OLDTITLE, EJECT ??

    clp$evaluate_parameters (parameter_list, #SEQ (pdt), NIL, ^pvt, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    clp$find_command_list (command_list, ignore_cmnd_list_found_in_task);
    clp$find_current_block (block);
    start_of_list := command_list^.entries.first_entry;
*IF NOT $true(osv$unix)
    IF block^.previous_block^.use_command_search_mode THEN
      effective_search_mode := command_list^.search_mode;
    ELSE
      effective_search_mode := clc$global_command_search;
    IFEND;
    IF effective_search_mode = clc$exclusive_command_search THEN
      end_of_list := command_list^.entries.entry_after_fence;
    ELSE
*IFEND
      end_of_list := NIL;
*IF NOT $true(osv$unix)
    IFEND;
*IFEND

    options.all_entries := FALSE;
    options.first := FALSE;
    options.control_statements := FALSE;
    options.commands := FALSE;
    options.functions := FALSE;
    options.names := FALSE;
    options.all_names := FALSE;
    options.advanced_usage := FALSE;
    options.starting_procedures := FALSE;

    display_control := clv$nil_display_control;
    #SPOIL (display_control);

    individual_entry_count := 0;
    current_node := pvt [p$entry].value;
    WHILE current_node <> NIL DO
      IF (current_node^.element_value^.kind <> clc$keyword) OR (current_node^.element_value^.keyword_value =
            '$SYSTEM') THEN
        individual_entry_count := individual_entry_count + 1;
      IFEND;
      current_node := current_node^.link;
    WHILEND;
    IF individual_entry_count = 0 THEN
      individual_entries := NIL;
    ELSE
      PUSH individual_entries: [1 .. individual_entry_count];
    IFEND;

    individual_entry_count := 0;
    current_node := pvt [p$entry].value;
    WHILE current_node <> NIL DO

    /get_entry/
      BEGIN
        CASE current_node^.element_value^.kind OF

        = clc$keyword =
          IF current_node^.element_value^.keyword_value = 'ALL' THEN
            options.control_statements := TRUE;
            options.all_entries := TRUE;
          ELSEIF current_node^.element_value^.keyword_value = 'CONTROL_STATEMENTS' THEN
            options.control_statements := TRUE;
          ELSEIF current_node^.element_value^.keyword_value = 'FIRST' THEN
            options.first := TRUE;
          ELSE {$SYSTEM}
            individual_entry_count := individual_entry_count + 1;
            individual_entries^ [individual_entry_count].kind := system_entry;
          IFEND;
          EXIT /get_entry/;

        = clc$name =
          utility_info := utility_command_environment (start_of_list,
                current_node^.element_value^.name_value);
          IF utility_info <> NIL THEN
            individual_entry_count := individual_entry_count + 1;
            individual_entries^ [individual_entry_count].kind := utility_entry;
            individual_entries^ [individual_entry_count].utility_name :=
                  current_node^.element_value^.name_value;
            individual_entries^ [individual_entry_count].utility_info := utility_info;
            EXIT /get_entry/;
*IF $true(osv$unix)
          ELSEIF current_node^.element_value^.name_value = '$SYSTEM' THEN
            individual_entry_count := individual_entry_count + 1;
            individual_entries^ [individual_entry_count].kind := system_entry;
          ELSE
            osp$set_status_abnormal ('CL', cle$unknown_utility, current_node^.element_value^.name_value,
                  status);
            RETURN;
*IFEND
          IFEND;
          individual_file_reference := ^current_node^.element_value^.name_value;

        ELSE {clc$file}
*IF NOT $true(osv$unix)
          individual_file_reference := current_node^.element_value^.file_value;
*IFEND
        CASEND;

*IF NOT $true(osv$unix)
        individual_entry_count := individual_entry_count + 1;
        individual_entries^ [individual_entry_count].kind := file_entry;
        clp$convert_string_to_file (individual_file_reference^, file, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
        individual_entries^ [individual_entry_count].path_handle_name := file.local_file_name;
*IFEND
      END /get_entry/;

      #SPOIL (individual_entries^ [individual_entry_count]);
      current_node := current_node^.link;
    WHILEND;
    #SPOIL (individual_entry_count, individual_entries);

    current_node := pvt [p$display_options].value;
    WHILE current_node <> NIL DO
      IF current_node^.element_value^.keyword_value = 'ALL_NAMES' THEN
        options.all_names := TRUE;
      ELSEIF current_node^.element_value^.keyword_value = 'ADVANCED_USAGE' THEN
        options.advanced_usage := TRUE;
      ELSEIF current_node^.element_value^.keyword_value = 'COMMANDS' THEN
        options.commands := TRUE;
      ELSEIF current_node^.element_value^.keyword_value = 'FUNCTIONS' THEN
        options.functions := TRUE;
      ELSEIF current_node^.element_value^.keyword_value = 'NAMES' THEN
        options.names := TRUE;
*IF NOT $true(osv$unix)
      ELSEIF current_node^.element_value^.keyword_value = 'STARTING_PROCEDURES' THEN
        options.starting_procedures := TRUE;
*IFEND
      ELSE {ALL}
        options.all_names := TRUE;
        options.advanced_usage := TRUE;
        options.commands := TRUE;
        options.functions := TRUE;
        options.starting_procedures := TRUE;
      IFEND;
      current_node := current_node^.link;
    WHILEND;

    IF NOT (options.commands OR options.functions) THEN
      options.commands := TRUE;
    IFEND;
    IF NOT (options.names OR options.all_names) THEN
      options.names := TRUE;
    IFEND;

*IF NOT $true(osv$unix)
    clp$get_work_area (#RING (^work_area), work_area, status);
*ELSE
    clp$get_work_area (osc$user_ring, work_area, status);
*IFEND
    IF NOT status.normal THEN
      RETURN;
    IFEND;

*IF $true(osv$unix)
    handler_established := #establish_condition_handler (-1, ^abort_handler);
*ELSE
    osp$establish_block_exit_hndlr (^abort_handler);
*IFEND

  /display_entries/
    BEGIN
*IF NOT $true(osv$unix)
*IF NOT $true(osv$unix)
      default_ring_attributes.r1 := #RING (^default_ring_attributes);
      default_ring_attributes.r2 := #RING (^default_ring_attributes);
      default_ring_attributes.r3 := #RING (^default_ring_attributes);
*ELSE
      default_ring_attributes.r1 := osc$user_ring;
      default_ring_attributes.r2 := osc$user_ring;
      default_ring_attributes.r3 := osc$user_ring;
*IFEND

      clp$open_display_reference (pvt [p$output].value^.file_value^, ^clp$new_page_procedure, fsc$list,
            default_ring_attributes, display_control, status);
*ELSE
      clp$open_display_reference (pvt [p$output].value^.file_value^, ^clp$new_page_procedure,
            fsc$list,
            display_control, status);
*IFEND
      IF NOT status.normal THEN
        EXIT /display_entries/;
      IFEND;
      clv$titles_built := FALSE;
      clv$command_name := 'display_command_list_entry';

      IF display_control.page_width < clc$narrow_page_width THEN
        clv$page_width := clc$narrow_page_width;
      ELSEIF display_control.page_width > clc$wide_page_width THEN
        clv$page_width := clc$wide_page_width;
      ELSE
        clv$page_width := display_control.page_width;
      IFEND;

      IF options.all_names THEN
        IF display_control.page_width < minimum_all_names_line_size THEN
          line_size := minimum_all_names_line_size;
        ELSE
          line_size := display_control.page_width;
        IFEND;
      ELSEIF display_control.page_width < minimum_display_line THEN
        line_size := minimum_line_size;
      ELSE
        line_size := display_control.page_width;
      IFEND;
      names_per_line := line_size DIV display_name_size;

      display_command_list_entries;

      clp$close_display (display_control, local_status);
      IF status.normal AND (NOT local_status.normal) THEN
        status := local_status;
      IFEND;

    END /display_entries/;

*IF $true(osv$unix)
    IF handler_established THEN
      handler_established := NOT #disestablish_condition_handler (-1);
    IFEND;
*ELSE
    osp$disestablish_cond_handler;
*IFEND

  PROCEND clp$_display_command_list_entry;
*IF NOT $true(osv$unix)
?? TITLE := 'clp$$command_list_entry', EJECT ??

  PROCEDURE [XDCL] clp$$command_list_entry
    (    parameter_list: clt$parameter_list;
     VAR work_area: ^clt$work_area;
     VAR result: ^clt$data_value;
     VAR status: ost$status);

{ FUNCTION (osm$$comle) $command_list_entry (
{   entry: any of
{       key
{         (first, f)
{         $system
{       keyend
{       name
{       file
{     anyend = first
{   commands_or_functions: key
{       (commands, command, c)
{       (command_references, command_reference, cr)
{       (functions, function, f)
{     keyend = commands
{   options: list rest of key
{       (aliases, alias, abbreviation, a)
{       (advanced_usage, au)
{       (starting_procedures, starting_procedure, sp)
{     keyend = $optional
{   )

?? PUSH (LISTEXT := ON) ??
?? FMT (FORMAT := OFF) ??

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 3] of clt$pdt_parameter_name,
      parameters: array [1 .. 3] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        qualifier: clt$union_type_qualifier,
        type_size_1: clt$type_specification_size,
        element_type_spec_1: record
          header: clt$type_specification_header,
          qualifier: clt$keyword_type_qualifier,
          keyword_specs: array [1 .. 3] of clt$keyword_specification,
        recend,
        type_size_2: clt$type_specification_size,
        element_type_spec_2: record
          header: clt$type_specification_header,
          qualifier: clt$name_type_qualifier,
        recend,
        type_size_3: clt$type_specification_size,
        element_type_spec_3: record
          header: clt$type_specification_header,
        recend,
        default_value: string (5),
      recend,
      type2: record
        header: clt$type_specification_header,
        qualifier: clt$keyword_type_qualifier,
        keyword_specs: array [1 .. 9] of clt$keyword_specification,
        default_value: string (8),
      recend,
      type3: record
        header: clt$type_specification_header,
        qualifier: clt$list_type_qualifier_v2,
        element_type_spec: record
          header: clt$type_specification_header,
          qualifier: clt$keyword_type_qualifier,
          keyword_specs: array [1 .. 9] of clt$keyword_specification,
        recend,
      recend,
    recend := [
    [1,
    [90, 2, 21, 16, 25, 55, 891],
    clc$function, 3, 3, 0, 0, 0, 0, 0, 'OSM$$COMLE'], [
    ['COMMANDS_OR_FUNCTIONS          ',clc$nominal_entry, 2],
    ['ENTRY                          ',clc$nominal_entry, 1],
    ['OPTIONS                        ',clc$nominal_entry, 3]],
    [
{ PARAMETER 1
    [2, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation, clc$standard_parameter_checking, 150,
  clc$optional_default_parameter, 0, 5],
{ PARAMETER 2
    [1, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation, clc$standard_parameter_checking, 340,
  clc$optional_default_parameter, 0, 8],
{ PARAMETER 3
    [3, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation, clc$standard_parameter_checking, 356,
  clc$optional_parameter, 0, 0]],
{ PARAMETER 1
    [[1, 0, clc$union_type], [[clc$file_type, clc$keyword_type, clc$name_type],
    FALSE, 3],
    118, [[1, 0, clc$keyword_type], [3], [
      ['$SYSTEM                        ', clc$nominal_entry, clc$normal_usage_entry, 2],
      ['F                              ', clc$abbreviation_entry, clc$normal_usage_entry, 1],
      ['FIRST                          ', clc$nominal_entry, clc$normal_usage_entry, 1]]
      ],
    5, [[1, 0, clc$name_type], [1, osc$max_name_size]],
    3, [[1, 0, clc$file_type]]
    ,
    'first'],
{ PARAMETER 2
    [[1, 0, clc$keyword_type], [9], [
    ['C                              ', clc$abbreviation_entry, clc$normal_usage_entry, 1],
    ['COMMAND                        ', clc$alias_entry, clc$normal_usage_entry, 1],
    ['COMMANDS                       ', clc$nominal_entry, clc$normal_usage_entry, 1],
    ['COMMAND_REFERENCE              ', clc$alias_entry, clc$normal_usage_entry, 2],
    ['COMMAND_REFERENCES             ', clc$nominal_entry, clc$normal_usage_entry, 2],
    ['CR                             ', clc$abbreviation_entry, clc$normal_usage_entry, 2],
    ['F                              ', clc$abbreviation_entry, clc$normal_usage_entry, 3],
    ['FUNCTION                       ', clc$alias_entry, clc$normal_usage_entry, 3],
    ['FUNCTIONS                      ', clc$nominal_entry, clc$normal_usage_entry, 3]]
    ,
    'commands'],
{ PARAMETER 3
    [[1, 0, clc$list_type], [340, 1, clc$max_list_size, 0, FALSE, TRUE],
      [[1, 0, clc$keyword_type], [9], [
      ['A                              ', clc$abbreviation_entry, clc$normal_usage_entry, 1],
      ['ABBREVIATION                   ', clc$alias_entry, clc$normal_usage_entry, 1],
      ['ADVANCED_USAGE                 ', clc$nominal_entry, clc$normal_usage_entry, 2],
      ['ALIAS                          ', clc$alias_entry, clc$normal_usage_entry, 1],
      ['ALIASES                        ', clc$nominal_entry, clc$normal_usage_entry, 1],
      ['AU                             ', clc$abbreviation_entry, clc$normal_usage_entry, 2],
      ['SP                             ', clc$abbreviation_entry, clc$normal_usage_entry, 3],
      ['STARTING_PROCEDURE             ', clc$alias_entry, clc$normal_usage_entry, 3],
      ['STARTING_PROCEDURES            ', clc$nominal_entry, clc$normal_usage_entry, 3]]
      ]
    ]];

?? FMT (FORMAT := ON) ??
?? POP ??

    CONST
      p$entry = 1,
      p$commands_or_functions = 2,
      p$options = 3;

    VAR
      pvt: array [1 .. 3] of clt$parameter_value;


    VAR
      command_entries: ^entry_array,
      command_list: ^clt$command_list,
      command_reference: clt$command_reference,
      current_node: ^clt$data_value,
      entries: ^entry_array,
      file: clt$file,
      function_entries: ^entry_array,
      ignore_cmnd_list_found_in_task: boolean,
      ignore_library_accessable: boolean,
      individual_entry: ^individual_entry_type,
      individual_file_reference: ^fst$file_reference,
      local_status: ost$status,
      options: option_type,
      result_node: ^^clt$data_value,
      return_command_references: boolean,
      start_of_list: ^clt$command_list_entry,
      utility_info: ^clt$utility_command_environment;

?? NEWTITLE := 'append_name_to_result', EJECT ??

    PROCEDURE append_name_to_result
      (    name: ost$name;
       VAR node {input, output} : ^^clt$data_value);


      clp$make_list_value (work_area, node^);
      IF node^ = NIL THEN
        osp$set_status_abnormal ('CL', cle$work_area_overflow, '', status);
        EXIT clp$$command_list_entry;
      IFEND;

      IF return_command_references THEN
        command_reference.name := name;
        clp$make_command_ref_value (^command_reference, work_area, node^^.element_value);
      ELSE
        clp$make_name_value (name, work_area, node^^.element_value);
      IFEND;

      IF node^^.element_value = NIL THEN
        osp$set_status_abnormal ('CL', cle$work_area_overflow, '', status);
        EXIT clp$$command_list_entry;
      IFEND;

      node := ^node^^.link;

    PROCEND append_name_to_result;
?? TITLE := 'return_all_names', EJECT ??

    PROCEDURE return_all_names;

      VAR
        abbrev_count: integer,
        abbreviations: ^entry_array,
        alias_count: integer,
        aliases: ^entry_array,
        i: integer,
        index: integer,
        j: integer,
        k: integer,
        nominal_count: integer,
        nominals: ^entry_array,
        result_sub_node: ^^clt$data_value;


      nominal_count := 0;
      alias_count := 0;
      abbrev_count := 0;

      PUSH nominals: [1 .. UPPERBOUND (entries^)];
      PUSH aliases: [1 .. UPPERBOUND (entries^)];
      PUSH abbreviations: [1 .. UPPERBOUND (entries^)];

      FOR index := 1 TO UPPERBOUND (entries^) DO
        IF (entries^ [index].availability = clc$normal_usage_entry) OR
              ((entries^ [index].availability = clc$advanced_usage_entry) AND options.advanced_usage) THEN
          IF entries^ [index].class = clc$nominal_entry THEN
            nominal_count := nominal_count + 1;
            nominals^ [nominal_count] := entries^ [index];
          ELSEIF entries^ [index].class = clc$alias_entry THEN
            alias_count := alias_count + 1;
            aliases^ [alias_count] := entries^ [index];
          ELSE
            abbrev_count := abbrev_count + 1;
            abbreviations^ [abbrev_count] := entries^ [index];
          IFEND;
        IFEND;
      FOREND;

      FOR i := 1 TO nominal_count DO
        clp$make_list_value (work_area, result_node^);
        IF result_node^ = NIL THEN
          osp$set_status_abnormal ('CL', cle$work_area_overflow, '', status);
          EXIT clp$$command_list_entry;
        IFEND;
        result_sub_node := ^result_node^^.element_value;
        result_node := ^result_node^^.link;

        append_name_to_result (nominals^ [i].name, result_sub_node);
        FOR j := 1 TO alias_count DO
          IF aliases^ [j].ordinal = nominals^ [i].ordinal THEN
            append_name_to_result (aliases^ [j].name, result_sub_node);
          IFEND;
        FOREND;
        FOR k := 1 TO abbrev_count DO
          IF abbreviations^ [k].ordinal = nominals^ [i].ordinal THEN
            append_name_to_result (abbreviations^ [k].name, result_sub_node);
          IFEND;
        FOREND;
      FOREND;

    PROCEND return_all_names;
?? TITLE := 'return_nominal_names', EJECT ??

    PROCEDURE return_nominal_names;

      VAR
        index: integer;


      FOR index := 1 TO UPPERBOUND (entries^) DO
        IF (entries^ [index].class = clc$nominal_entry) AND
              ((entries^ [index].availability = clc$normal_usage_entry) OR
              ((entries^ [index].availability = clc$advanced_usage_entry) AND options.advanced_usage)) THEN
          append_name_to_result (entries^ [index].name, result_node);
        IFEND;
      FOREND;

    PROCEND return_nominal_names;
?? OLDTITLE, EJECT ??

    clp$evaluate_parameters (parameter_list, #SEQ (pdt), NIL, ^pvt, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    clp$find_command_list (command_list, ignore_cmnd_list_found_in_task);
    start_of_list := command_list^.entries.first_entry;

    options.all_entries := FALSE;
    options.first := FALSE;
    options.control_statements := FALSE;
    options.commands := FALSE;
    options.functions := FALSE;
    options.names := TRUE;
    options.all_names := FALSE;
    options.advanced_usage := FALSE;
    options.starting_procedures := FALSE;
    return_command_references := FALSE;

    IF (pvt [p$entry].value^.kind <> clc$keyword) OR (pvt [p$entry].value^.keyword_value = '$SYSTEM') THEN
      PUSH individual_entry;
    ELSE
      individual_entry := NIL;
    IFEND;

  /get_entry/
    BEGIN
      CASE pvt [p$entry].value^.kind OF

      = clc$keyword =
        IF pvt [p$entry].value^.keyword_value = 'FIRST' THEN
          options.first := TRUE;
        ELSE {$SYSTEM}
          individual_entry^.kind := system_entry;
        IFEND;
        EXIT /get_entry/;

      = clc$name =
        utility_info := utility_command_environment (start_of_list, pvt [p$entry].value^.name_value);
        IF utility_info <> NIL THEN
          individual_entry^.kind := utility_entry;
          individual_entry^.utility_name := pvt [p$entry].value^.name_value;
          individual_entry^.utility_info := utility_info;
          EXIT /get_entry/;
        IFEND;
        individual_file_reference := ^pvt [p$entry].value^.name_value;

      ELSE {clc$file}
        individual_file_reference := pvt [p$entry].value^.file_value;
      CASEND;

      individual_entry^.kind := file_entry;
      clp$convert_string_to_file (individual_file_reference^, file, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
      individual_entry^.path_handle_name := file.local_file_name;
    END /get_entry/;

    #SPOIL (individual_entry);

    IF pvt [p$commands_or_functions].value^.keyword_value = 'COMMANDS' THEN
      options.commands := TRUE;
    ELSEIF pvt [p$commands_or_functions].value^.keyword_value = 'COMMAND_REFERENCES' THEN
      options.commands := TRUE;
      return_command_references := TRUE;
    ELSE {FUNCTIONS}
      options.functions := TRUE;
    IFEND;

    current_node := pvt [p$options].value;
    WHILE current_node <> NIL DO
      IF current_node^.element_value^.keyword_value = 'ALIASES' THEN
        options.all_names := TRUE;
      ELSEIF current_node^.element_value^.keyword_value = 'STARTING_PROCEDURES' THEN
        options.starting_procedures := TRUE;
      ELSE {ADVANCED_USAGE}
        options.advanced_usage := TRUE;
      IFEND;
      current_node := current_node^.link;
    WHILEND;

    result_node := ^result;

    IF (individual_entry <> NIL) OR (options.first AND (start_of_list <> NIL)) THEN
      get_command_and_func_entries (options, command_list, start_of_list, individual_entry, FALSE,
            options.first, work_area, command_entries, function_entries, command_reference,
            ignore_library_accessable, status);
      IF NOT status.normal THEN
        RETURN;
      ELSEIF options.commands AND (command_entries <> NIL) THEN
        entries := command_entries;
      ELSEIF options.functions AND (function_entries <> NIL) THEN
        entries := function_entries;
      ELSE
        entries := NIL;
      IFEND;

      IF entries <> NIL THEN
        IF options.all_names THEN
          return_all_names;
        ELSE
          return_nominal_names;
        IFEND;
      IFEND;
    IFEND;

    IF result = NIL THEN
      clp$make_list_value (work_area, result);
      IF result = NIL THEN
        osp$set_status_abnormal ('CL', cle$work_area_overflow, '', status);
        RETURN;
      IFEND;
    IFEND;

  PROCEND clp$$command_list_entry;
*IFEND
?? TITLE := 'get_command_and_func_entries', EJECT ??

  PROCEDURE get_command_and_func_entries
    (    options: option_type;
         command_list: ^clt$command_list;
         list_entry: ^clt$command_list_entry;
         individual_entry: ^individual_entry_type;
         test_harness: boolean;
         searching_command_list: boolean;
     VAR work_area {input, output} : ^clt$work_area;
     VAR command_entries: ^entry_array;
     VAR function_entries: ^entry_array;
     VAR command_reference: clt$command_reference;
     VAR library_accessable: boolean;
     VAR status: ost$status);

    VAR
*IF NOT $true(osv$unix)
      caller_id: ost$caller_identifier,
*IFEND
      i: integer,
      ignore_library_list_entry: ^clt$command_library_list_entry,
      individual_entry_open: boolean,
*IF NOT $true(osv$unix)
      local_file_name: amt$local_file_name,
      ring_attributes: amt$ring_attributes;
*ELSE
      local_file_name: amt$local_file_name;
*IFEND

*IF NOT $true(osv$unix)
?? NEWTITLE := 'abort_handler', EJECT ??

    PROCEDURE abort_handler
      (    condition: pmt$condition;
           condition_information: ^pmt$condition_information;
           save_area: ^ost$stack_frame_save_area;
       VAR handler_status: ost$status);


      IF individual_entry_open THEN
        clp$close_command_library (local_file_name, handler_status);
        individual_entry_open := FALSE;
        handler_status.normal := TRUE;
      IFEND;

    PROCEND abort_handler;
*IFEND
?? TITLE := 'convert_command_dictionary', EJECT ??

    PROCEDURE convert_command_dictionary
      (    commands: llt$command_dictionary;
       VAR largest_ordinal: clt$named_entry_ordinal;
       VAR converted_commands: ^entry_array);

      VAR
        index: integer;


      NEXT converted_commands: [1 .. UPPERBOUND (commands)] IN work_area;
      IF converted_commands = NIL THEN
        osp$set_status_abnormal ('CL', cle$work_area_overflow, '', status);
        EXIT get_command_and_func_entries;
      IFEND;

      largest_ordinal := 1;

      FOR index := 1 TO UPPERBOUND (commands) DO
        converted_commands^ [index].name := commands [index].name;
        converted_commands^ [index].class := commands [index].class;
        IF (commands [index].kind = llc$local_to_library) OR
*IF NOT $true(osv$unix)
              ((commands [index].kind = llc$entry_point) AND (ring_attributes.r2 < caller_id.ring)) OR
*ELSE
              ((commands [index].kind = llc$entry_point)) OR
*IFEND
              ((commands [index].module_kind = llc$load_module) AND (NOT options.starting_procedures)) THEN
          converted_commands^ [index].availability := clc$hidden_entry;
        ELSE
          converted_commands^ [index].availability := commands [index].availability;
        IFEND;
        converted_commands^ [index].ordinal := commands [index].ordinal;
        IF commands [index].ordinal > largest_ordinal THEN
          largest_ordinal := commands [index].ordinal;
        IFEND;
      FOREND;

    PROCEND convert_command_dictionary;
?? TITLE := 'convert_command_table', EJECT ??

    PROCEDURE convert_command_table
      (    commands: clt$command_table;
       VAR largest_ordinal: clt$named_entry_ordinal;
       VAR converted_commands: ^entry_array);

      VAR
        index: integer;


      NEXT converted_commands: [1 .. UPPERBOUND (commands)] IN work_area;
      IF converted_commands = NIL THEN
        osp$set_status_abnormal ('CL', cle$work_area_overflow, '', status);
        EXIT get_command_and_func_entries;
      IFEND;

      largest_ordinal := 1;

      FOR index := 1 TO UPPERBOUND (commands) DO
        converted_commands^ [index].name := commands [index].name;
        converted_commands^ [index].class := commands [index].class;
        converted_commands^ [index].availability := commands [index].availability;
        converted_commands^ [index].ordinal := commands [index].ordinal;
        IF commands [index].ordinal > largest_ordinal THEN
          largest_ordinal := commands [index].ordinal;
        IFEND;
      FOREND;

    PROCEND convert_command_table;
?? TITLE := 'convert_function_dictionary', EJECT ??

    PROCEDURE convert_function_dictionary
      (    functions: llt$function_dictionary;
       VAR largest_ordinal: clt$named_entry_ordinal;
       VAR converted_functions: ^entry_array);

      VAR
        index: integer;


      NEXT converted_functions: [1 .. UPPERBOUND (functions)] IN work_area;
      IF converted_functions = NIL THEN
        osp$set_status_abnormal ('CL', cle$work_area_overflow, '', status);
        EXIT get_command_and_func_entries;
      IFEND;

      largest_ordinal := 1;

      FOR index := 1 TO UPPERBOUND (functions) DO
        converted_functions^ [index].name := functions [index].name;
        converted_functions^ [index].class := functions [index].class;
        IF functions [index].kind = llc$local_to_library THEN
          converted_functions^ [index].availability := clc$hidden_entry;
        ELSE
          converted_functions^ [index].availability := functions [index].availability;
        IFEND;
        converted_functions^ [index].ordinal := functions [index].ordinal;
        IF functions [index].ordinal > largest_ordinal THEN
          largest_ordinal := functions [index].ordinal;
        IFEND;
      FOREND;

    PROCEND convert_function_dictionary;
?? TITLE := 'convert_function_proc_table', EJECT ??

    PROCEDURE convert_function_proc_table
      (    functions: clt$function_processor_table;
       VAR largest_ordinal: clt$named_entry_ordinal;
       VAR converted_functions: ^entry_array);

      VAR
        index: integer;


      NEXT converted_functions: [1 .. UPPERBOUND (functions)] IN work_area;
      IF converted_functions = NIL THEN
        osp$set_status_abnormal ('CL', cle$work_area_overflow, '', status);
        EXIT get_command_and_func_entries;
      IFEND;

      largest_ordinal := 1;

      FOR index := 1 TO UPPERBOUND (functions) DO
        converted_functions^ [index].name := functions [index].name;
        converted_functions^ [index].class := functions [index].class;
        converted_functions^ [index].availability := functions [index].availability;
        converted_functions^ [index].ordinal := functions [index].ordinal;
        IF functions [index].ordinal > largest_ordinal THEN
          largest_ordinal := functions [index].ordinal;
        IFEND;
      FOREND;

    PROCEND convert_function_proc_table;
?? TITLE := 'convert_function_table', EJECT ??

    PROCEDURE convert_function_table
      (    functions: clt$function_table;
       VAR largest_ordinal: clt$named_entry_ordinal;
       VAR converted_functions: ^entry_array);

      VAR
        index: integer;


      NEXT converted_functions: [1 .. UPPERBOUND (functions)] IN work_area;
      IF converted_functions = NIL THEN
        osp$set_status_abnormal ('CL', cle$work_area_overflow, '', status);
        EXIT get_command_and_func_entries;
      IFEND;

      largest_ordinal := 1;

      FOR index := 1 TO UPPERBOUND (functions) DO
        converted_functions^ [index].name := functions [index].name;
        converted_functions^ [index].class := functions [index].class;
        converted_functions^ [index].availability := functions [index].availability;
        converted_functions^ [index].ordinal := functions [index].ordinal;
        IF functions [index].ordinal > largest_ordinal THEN
          largest_ordinal := functions [index].ordinal;
        IFEND;
      FOREND;

    PROCEND convert_function_table;
*IF NOT $true(osv$unix)
?? TITLE := 'get_catalog_entries', EJECT ??

    PROCEDURE get_catalog_entries
      (    local_file_name: amt$local_file_name);

      VAR
        parsed_file_reference: fst$parsed_file_reference;


      command_reference.form := clc$file_cycle_command_ref;
      clp$convert_string_to_file_ref (local_file_name, parsed_file_reference, status);
      IF NOT status.normal THEN
        EXIT get_command_and_func_entries;
      IFEND;
      command_reference.catalog := parsed_file_reference.path (1, parsed_file_reference.file_path_size);
      command_reference.cycle_number := 1 {not used} ;

{ No entries are returned for a catalog.

    PROCEND get_catalog_entries;
*IFEND
?? TITLE := 'get_intrinsic_entries', EJECT ??

    PROCEDURE get_intrinsic_entries;

      VAR
        function_dictionary: ^llt$function_dictionary,
        ignore_command_dictionary: ^llt$command_dictionary,
        largest_primary_ordinal: clt$named_entry_ordinal,
        largest_secondary_ordinal: clt$named_entry_ordinal,
        primary_entries: ^entry_array,
        secondary_entries: ^entry_array;

*IF NOT $true(osv$unix)
      VAR
        context: ^ost$ecp_exception_context;

      context := NIL;
*IFEND

      command_reference.form := clc$system_command_ref;

      IF options.commands THEN
        convert_command_table (clv$intrinsic_commands^, largest_primary_ordinal, command_entries);
      IFEND;

      IF options.functions THEN
        convert_function_proc_table (clv$system_functions^, largest_primary_ordinal, primary_entries);
        convert_function_table (clv$system_functions_v0^, largest_secondary_ordinal, secondary_entries);
        merge_entries (primary_entries^, largest_primary_ordinal, secondary_entries^, function_entries);
*IF NOT $true(osv$unix)
        IF (command_list^.system_command_library_lfn <> osc$null_name) AND
              command_list^.system_library_contains.functions THEN
          REPEAT
            clp$find_command_entries (command_list^.system_command_library_lfn, work_area, ring_attributes,
                  ignore_command_dictionary, function_dictionary, status);
            IF osp$file_access_condition (status) THEN
              IF context = NIL THEN
                PUSH context;
                context^ := osv$initial_exception_context;
                context^.file.selector := osc$ecp_file_reference;
                context^.file.file_reference := ^command_list^.system_command_library_lfn;
              IFEND;
              context^.condition_status := status;
              osp$enforce_exception_policies (context^);
              status := context^.condition_status;
            IFEND;
          UNTIL status.normal OR (NOT osp$file_access_condition (status)) OR (NOT context^.wait);
          library_accessable := TRUE;
          IF NOT status.normal THEN
            EXIT get_command_and_func_entries;
          IFEND;
          IF function_dictionary <> NIL THEN
            secondary_entries := function_entries;
            convert_function_dictionary (function_dictionary^, largest_primary_ordinal, primary_entries);
            merge_entries (primary_entries^, largest_primary_ordinal, secondary_entries^, function_entries);
          IFEND;
        IFEND;
*IFEND
      IFEND;

    PROCEND get_intrinsic_entries;
*IF NOT $true(osv$unix)
?? TITLE := 'get_library_entries', EJECT ??

    PROCEDURE get_library_entries
      (    local_file_name: amt$local_file_name);

      VAR
        command_dictionary: ^llt$command_dictionary,
        context: ^ost$ecp_exception_context,
        function_dictionary: ^llt$function_dictionary,
        ignore_largest_ordinal: clt$named_entry_ordinal,
        parsed_file_reference: fst$parsed_file_reference;

      context := NIL;

      command_reference.form := clc$module_or_file_command_ref;
      clp$convert_string_to_file_ref (local_file_name, parsed_file_reference, status);
      IF NOT status.normal THEN
        EXIT get_command_and_func_entries;
      IFEND;
      command_reference.library_or_catalog := parsed_file_reference.
            path (1, parsed_file_reference.file_path_size);

      REPEAT
        clp$find_command_entries (local_file_name, work_area, ring_attributes, command_dictionary,
              function_dictionary, status);
        IF osp$file_access_condition (status) THEN
          IF context = NIL THEN
            PUSH context;
            context^ := osv$initial_exception_context;
            context^.file.selector := osc$ecp_file_reference;
            context^.file.file_reference := ^local_file_name;
          IFEND;
          context^.condition_status := status;
          osp$enforce_exception_policies (context^);
          status := context^.condition_status;
        IFEND;
      UNTIL status.normal OR (NOT osp$file_access_condition (status)) OR (NOT context^.wait);
      IF NOT status.normal THEN
        IF searching_command_list THEN
          library_accessable := FALSE;
          status.normal := TRUE;
        IFEND;
        RETURN;
      ELSEIF caller_id.ring > ring_attributes.r3 THEN
        library_accessable := FALSE;
      IFEND;

      IF options.commands AND (command_dictionary <> NIL) THEN
        convert_command_dictionary (command_dictionary^, ignore_largest_ordinal, command_entries);
      IFEND;
      IF options.functions AND (function_dictionary <> NIL) THEN
        convert_function_dictionary (function_dictionary^, ignore_largest_ordinal, function_entries);
      IFEND;

    PROCEND get_library_entries;
*IFEND
?? TITLE := 'get_system_entries', EJECT ??

    PROCEDURE get_system_entries;

      VAR
        command_dictionary: ^llt$command_dictionary,
        function_dictionary: ^llt$function_dictionary,
        largest_primary_ordinal: clt$named_entry_ordinal,
        largest_secondary_ordinal: clt$named_entry_ordinal,
        primary_entries: ^entry_array,
        secondary_entries: ^entry_array;

*IF NOT $true(osv$unix)
      VAR
        context: ^ost$ecp_exception_context;

      context := NIL;

*IFEND

      command_reference.form := clc$system_command_ref;

*IF NOT $true(osv$unix)
      IF command_list^.system_command_library_lfn = osc$null_name THEN
*IFEND
        command_dictionary := NIL;
        function_dictionary := NIL;
*IF NOT $true(osv$unix)
      ELSE
        REPEAT
          clp$find_command_entries (command_list^.system_command_library_lfn, work_area, ring_attributes,
                command_dictionary, function_dictionary, status);
          IF osp$file_access_condition (status) THEN
            IF context = NIL THEN
              PUSH context;
              context^ := osv$initial_exception_context;
              context^.file.selector := osc$ecp_file_reference;
              context^.file.file_reference := ^command_list^.system_command_library_lfn;
            IFEND;

            context^.condition_status := status;
            osp$enforce_exception_policies (context^);
            status := context^.condition_status;
          IFEND;
        UNTIL status.normal OR (NOT osp$file_access_condition (status)) OR (NOT context^.wait);
        library_accessable := TRUE;
        IF NOT status.normal THEN
          EXIT get_command_and_func_entries;
        IFEND;
      IFEND;
*IFEND

      IF options.commands THEN
*IF NOT $true(osv$unix)
{Add this back in when we have a real $SYSTEM
        convert_command_table (clv$system_commands^, largest_secondary_ordinal, command_entries);
*ELSE
        command_entries := NIL;
*IFEND
        IF command_dictionary <> NIL THEN
          secondary_entries := command_entries;
          convert_command_dictionary (command_dictionary^, largest_primary_ordinal, primary_entries);
          merge_entries (primary_entries^, largest_primary_ordinal, secondary_entries^, command_entries);
*IF NOT $true(osv$unix)
          IF jmp$system_job () THEN
            secondary_entries := command_entries;
            convert_command_table (clv$operator_commands^, largest_primary_ordinal, primary_entries);
            merge_entries (primary_entries^, largest_primary_ordinal, secondary_entries^, command_entries);
          IFEND;
*IFEND
        IFEND;
      IFEND;

      IF options.functions THEN
*IF NOT $true(osv$unix)
{Add this back in when have real $SYSTEM entry
        convert_function_proc_table (clv$system_functions^, largest_primary_ordinal, primary_entries);
        convert_function_table (clv$system_functions_v0^, largest_secondary_ordinal, secondary_entries);
        merge_entries (primary_entries^, largest_primary_ordinal, secondary_entries^, function_entries);
        IF function_dictionary <> NIL THEN
          secondary_entries := function_entries;
          convert_function_dictionary (function_dictionary^, largest_primary_ordinal, primary_entries);
          merge_entries (primary_entries^, largest_primary_ordinal, secondary_entries^, function_entries);
        IFEND;
*ELSE
        function_entries := NIL;
*IFEND
      IFEND;

    PROCEND get_system_entries;
*IF NOT $true(osv$unix)
?? TITLE := 'get_test_harness_entries', EJECT ??

    ?IF fsc$compiling_for_test_harness AND clc$compiling_for_test_harness THEN



      PROCEDURE get_test_harness_entries;

        VAR
          ignore_largest_ordinal: clt$named_entry_ordinal;


        command_reference.form := clc$system_command_ref;

        IF options.commands THEN
          convert_command_table (fsv$test_harness_cmnds^, ignore_largest_ordinal, command_entries);
        IFEND;

        IF options.functions THEN
          convert_function_table (fsv$test_harness_fnctns^, ignore_largest_ordinal, function_entries);
        IFEND;

      PROCEND get_test_harness_entries;

    ?IFEND
*IFEND
?? TITLE := 'get_utility_entries', EJECT ??

    PROCEDURE get_utility_entries
      (    utility_name: clt$utility_name;
           utility_info: clt$utility_command_environment);

      VAR
        largest_primary_ordinal: clt$named_entry_ordinal,
        largest_secondary_ordinal: clt$named_entry_ordinal,
        primary_entries: ^entry_array,
        secondary_entries: ^entry_array;


      command_reference.form := clc$utility_command_ref;
      command_reference.utility := utility_name;

      IF options.commands THEN
        IF utility_info.commands <> NIL THEN
          convert_command_table (utility_info.commands^, largest_primary_ordinal, command_entries);
        ELSE
          command_entries := NIL;
        IFEND;

        IF utility_info.dialog_info.commands <> NIL THEN
          convert_command_table (utility_info.dialog_info.commands^, largest_secondary_ordinal,
                secondary_entries);
          IF command_entries <> NIL THEN
            primary_entries := command_entries;
            merge_entries (primary_entries^, largest_primary_ordinal, secondary_entries^, command_entries);
          IFEND;
        IFEND;
      IFEND;

      IF options.functions THEN
        IF utility_info.contemporary_functions = NIL THEN
          primary_entries := NIL;
        ELSE
          convert_function_proc_table (utility_info.contemporary_functions^, largest_primary_ordinal,
                primary_entries);
        IFEND;
        IF utility_info.original_functions = NIL THEN
          secondary_entries := NIL;
        ELSE
          convert_function_table (utility_info.original_functions^, largest_secondary_ordinal,
                secondary_entries);
        IFEND;
        IF primary_entries <> NIL THEN
          IF secondary_entries <> NIL THEN
            merge_entries (primary_entries^, largest_primary_ordinal, secondary_entries^, function_entries);
            largest_primary_ordinal := largest_primary_ordinal + largest_secondary_ordinal;
          ELSE
            function_entries := primary_entries;
          IFEND;
        ELSEIF secondary_entries <> NIL THEN
          function_entries := secondary_entries;
          largest_primary_ordinal := largest_secondary_ordinal;
        IFEND;

        IF utility_info.dialog_info.functions <> NIL THEN
          convert_function_proc_table (utility_info.dialog_info.functions^, largest_secondary_ordinal,
                secondary_entries);
          IF function_entries <> NIL THEN
            primary_entries := function_entries;
            merge_entries (primary_entries^, largest_primary_ordinal, secondary_entries^, function_entries);
          ELSE
            function_entries := secondary_entries;
          IFEND;
        IFEND;
      IFEND;

    PROCEND get_utility_entries;
*IF NOT $true(osv$unix)
?? TITLE := 'get_working_catalog_entries', EJECT ??

    PROCEDURE [INLINE] get_working_catalog_entries;


      command_reference.form := clc$file_cycle_command_ref;
      command_reference.catalog := ':$WORKING_CATALOG';
      command_reference.cycle_number := 1 {not used} ;

{ No entries are returned for a catalog.

    PROCEND get_working_catalog_entries;
*IFEND
?? TITLE := 'merge_entries', EJECT ??

    PROCEDURE merge_entries
      (    primary_entries: entry_array;
           largest_primary_ordinal: clt$named_entry_ordinal;
           secondary_entries: entry_array;
       VAR merged_entries: ^entry_array);

      VAR
        i: integer,
        j: integer,
        k: integer;


      NEXT merged_entries: [1 .. UPPERBOUND (primary_entries) + UPPERBOUND (secondary_entries)] IN work_area;
      IF merged_entries = NIL THEN
        osp$set_status_abnormal ('CL', cle$work_area_overflow, '', status);
        EXIT get_command_and_func_entries;
      IFEND;

      j := 1;
      k := 1;
      FOR i := 1 TO UPPERBOUND (merged_entries^) DO
        IF (k > UPPERBOUND (secondary_entries)) OR ((j <= UPPERBOUND (primary_entries)) AND
              (primary_entries [j].name <= secondary_entries [k].name)) THEN
          merged_entries^ [i].name := primary_entries [j].name;
          merged_entries^ [i].class := primary_entries [j].class;
          merged_entries^ [i].availability := primary_entries [j].availability;
          merged_entries^ [i].ordinal := primary_entries [j].ordinal;
          j := j + 1;
        ELSE
          merged_entries^ [i].name := secondary_entries [k].name;
          merged_entries^ [i].class := secondary_entries [k].class;
          IF (i > 1) AND (merged_entries^ [i].name = merged_entries^ [i - 1].name) THEN
            merged_entries^ [i].availability := clc$hidden_entry;
          ELSE
            merged_entries^ [i].availability := secondary_entries [k].availability;
          IFEND;
          merged_entries^ [i].ordinal := secondary_entries [k].ordinal + largest_primary_ordinal;
          k := k + 1;
        IFEND;
      FOREND;

    PROCEND merge_entries;
?? OLDTITLE, EJECT ??
*IF NOT $true(osv$unix)
    VAR
      context: ^ost$ecp_exception_context;
*IFEND

    status.normal := TRUE;
*IF NOT $true(osv$unix)
    #CALLER_ID (caller_id);

    context := NIL;

*IFEND
    library_accessable := TRUE;
    command_entries := NIL;
    function_entries := NIL;

    IF individual_entry <> NIL THEN
      CASE individual_entry^.kind OF
      = system_entry =
        get_system_entries;
      = utility_entry =
        get_utility_entries (individual_entry^.utility_name, individual_entry^.utility_info^);
*IF NOT $true(osv$unix)
      = file_entry =
        REPEAT
          clp$open_command_library (caller_id.ring, individual_entry^.path_handle_name,
                ignore_library_list_entry, local_file_name, status);
          IF osp$file_access_condition (status) THEN
            IF context = NIL THEN
              PUSH context;
              context^.file.selector := osc$ecp_file_reference;
              context^.file.file_reference := ^individual_entry^.path_handle_name;
            IFEND;
            context^.condition_status := status;
            osp$enforce_exception_policies (context^);
            status := context^.condition_status;
          IFEND;
        UNTIL status.normal OR (NOT osp$file_access_condition (status)) OR (NOT context^.wait);
        IF NOT status.normal THEN
          IF (status.condition = pfe$path_too_short) OR (status.condition = pfe$name_not_permanent_file) THEN
            status.normal := TRUE;
            get_catalog_entries (individual_entry^.path_handle_name);
          IFEND;
        ELSE

          individual_entry_open := TRUE;
          #SPOIL (individual_entry_open);
          osp$establish_block_exit_hndlr (^abort_handler);
          get_library_entries (local_file_name);
          REPEAT
            clp$close_command_library (local_file_name, status);
            IF osp$file_access_condition (status) THEN
              IF context = NIL THEN
                PUSH context;
                context^.file.selector := osc$ecp_file_reference;
                context^.file.file_reference := ^local_file_name;
              IFEND;
              context^.condition_status := status;
              osp$enforce_exception_policies (context^);
              status := context^.condition_status;
            IFEND;
          UNTIL status.normal OR (NOT osp$file_access_condition (status)) OR (NOT context^.wait);
          individual_entry_open := FALSE;
          #SPOIL (individual_entry_open);
          osp$disestablish_cond_handler;
        IFEND;
*IFEND
      CASEND;

    ELSEIF list_entry <> NIL THEN
      CASE list_entry^.kind OF
*IF NOT $true(osv$unix)
      = clc$library_commands =
        get_library_entries (list_entry^.local_file_name);
      = clc$catalog_commands =
        get_catalog_entries (list_entry^.local_file_name);
      = clc$working_catalog_commands =
        get_working_catalog_entries;
*IFEND
      = clc$system_commands =
        get_system_entries;
      = clc$sub_commands =
        get_utility_entries (list_entry^.utility_name, list_entry^.utility_info^);
      ELSE {clc$command_list_fence}
        ;
      CASEND;

*IF NOT $true(osv$unix)
    ELSEIF test_harness THEN
      ?IF fsc$compiling_for_test_harness AND clc$compiling_for_test_harness THEN
        get_test_harness_entries;
      ?IFEND
*IFEND

    ELSE
      get_intrinsic_entries;
    IFEND;


  PROCEND get_command_and_func_entries;
?? TITLE := 'utility_command_environment', EJECT ??

  FUNCTION [INLINE] utility_command_environment
    (    start_of_list: ^clt$command_list_entry;
         candidate_name: ost$name): ^clt$utility_command_environment;

    VAR
      current_entry: ^clt$command_list_entry;


    current_entry := start_of_list;
    WHILE current_entry <> NIL DO
      IF (current_entry^.kind = clc$sub_commands) AND (candidate_name = current_entry^.utility_name) THEN

        utility_command_environment := current_entry^.utility_info;
        RETURN;

      IFEND;
      current_entry := current_entry^.next_entry;
    WHILEND;

    utility_command_environment := NIL;

  FUNCEND utility_command_environment;

MODEND clm$display_command_list_entry;
