?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE SCL Interpreter : Display Command List' ??
MODULE clm$display_command_list;

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

?? NEWTITLE := 'Global Declarations', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc cle$work_area_overflow
*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
*IFEND
*copyc oss$job_paged_literal
*copyc ost$status
?? POP ??
*copyc clp$build_path_subtitle
*copyc clp$build_standard_title
*copyc clp$close_display
*copyc clp$convert_integer_to_string
*copyc clp$evaluate_parameters
*copyc clp$find_command_list
*copyc clp$find_current_block
*IF NOT $true(osv$unix)
*copyc clp$get_command_search_mode
*copyc clp$get_path_name
*IFEND
*copyc clp$horizontal_tab_display
*copyc clp$make_file_value
*copyc clp$make_keyword_value
*copyc clp$make_list_value
*copyc clp$make_name_value
*copyc clp$new_display_line
*copyc clp$new_display_page
*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$nil_display_control
*IF NOT $true(osv$unix)
*copyc osp$disestablish_cond_handler
*copyc osp$establish_block_exit_hndlr
*IFEND
*copyc osp$set_status_abnormal
*copyc osv$upper_to_lower

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

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

*IF NOT $true(osv$unix)
{ PROCEDURE (osm$discl) display_command_list, discl (
{   display_options, display_option, do: list of key
{       all
{       (entries, entry, e)
{       (search_mode, sm)
{     keyend = entries
{   output, o: file = $output
{   status)

?? PUSH (LISTEXT := ON) ??

    VAR
      pdt: [STATIC, READ, cls$declaration_section] record
        header: clt$pdt_header,
        names: array [1 .. 6] of clt$pdt_parameter_name,
        parameters: array [1 .. 3] of clt$pdt_parameter,
        type1: record
          header: clt$type_specification_header,
          qualifier: clt$list_type_qualifier,
          element_type_spec: record
            header: clt$type_specification_header,
            qualifier: clt$keyword_type_qualifier,
            keyword_specs: array [1 .. 6] of clt$keyword_specification,
          recend,
          default_value: string (7),
        recend,
        type2: record
          header: clt$type_specification_header,
          default_value: string (7),
        recend,
        type3: record
          header: clt$type_specification_header,
        recend,
      recend := [[1, [87, 10, 20, 13, 54, 55, 895], clc$command, 6, 3, 0, 0, 0, 0, 3, 'OSM$DISCL'],
            [['DISPLAY_OPTION                 ', clc$alias_entry, 1],
            ['DISPLAY_OPTIONS                ', clc$nominal_entry, 1],
            ['DO                             ', clc$abbreviation_entry, 1],
            ['O                              ', clc$abbreviation_entry, 2],
            ['OUTPUT                         ', clc$nominal_entry, 2],
            ['STATUS                         ', clc$nominal_entry, 3]], [

{ PARAMETER 1

      [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, 245, clc$optional_default_parameter, 0, 7],

{ PARAMETER 2

      [5, 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 3

      [6, 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], [229, 1, clc$max_list_size, FALSE],
            [[1, 0, clc$keyword_type], [6], [['ALL                            ', clc$nominal_entry,
            clc$normal_usage_entry, 1], ['E                              ', clc$abbreviation_entry,
            clc$normal_usage_entry, 2], ['ENTRIES                        ', clc$nominal_entry,
            clc$normal_usage_entry, 2], ['ENTRY                          ', clc$alias_entry,
            clc$normal_usage_entry, 2], ['SEARCH_MODE                    ', clc$nominal_entry,
            clc$normal_usage_entry, 3], ['SM                             ', clc$abbreviation_entry,
            clc$normal_usage_entry, 3]]], 'entries'],

{ PARAMETER 2

      [[1, 0, clc$file_type], '$output'],

{ PARAMETER 3

      [[1, 0, clc$status_type]]];

?? POP ??

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

    VAR
      pvt: array [1 .. 3] of clt$parameter_value;
*ELSE
{ PROCEDURE (osm$discl) display_command_list, discl (
{   display_options, display_option, do: list of key
{       all
{       (entries, entry, e)
{     keyend = entries
{   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 .. 6] of clt$pdt_parameter_name,
      parameters: array [1 .. 3] 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$keyword_type_qualifier,
          keyword_specs: array [1 .. 4] of clt$keyword_specification,
        recend,
        default_value: ALIGNED [0 MOD 4] string (7),
      recend,
      type2: record
        header: clt$type_specification_header,
        default_value: ALIGNED [0 MOD 4] string (7),
      recend,
      type3: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [2,
    [91, 8, 1, 8, 20, 33, 0],
    clc$command, 6, 3, 0, 0, 0, 0, 3, 'OSM$DISCL'], [
    ['DISPLAY_OPTION                 ',clc$alias_entry, 1],
    ['DISPLAY_OPTIONS                ',clc$nominal_entry, 1],
    ['DO                             ',clc$abbreviation_entry, 1],
    ['O                              ',clc$abbreviation_entry, 2],
    ['OUTPUT                         ',clc$nominal_entry, 2],
    ['STATUS                         ',clc$nominal_entry, 3]],
    [
{ PARAMETER 1
    [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, 196, clc$optional_default_parameter, 0, 7],
{ PARAMETER 2
    [5, 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 3
    [6, 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], [168, 1, clc$max_list_size, 0, FALSE, FALSE],
      [[2, 0, clc$keyword_type], [4], [
      ['ALL                            ', clc$nominal_entry,
  clc$normal_usage_entry, 1],
      ['E                              ', clc$abbreviation_entry,
  clc$normal_usage_entry, 2],
      ['ENTRIES                        ', clc$nominal_entry,
  clc$normal_usage_entry, 2],
      ['ENTRY                          ', clc$alias_entry,
  clc$normal_usage_entry, 2]]
      ]
    ,
    'entries'],
{ PARAMETER 2
    [[2, 0, clc$file_type],
    '$output'],
{ PARAMETER 3
    [[2, 0, clc$status_type]]];

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

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

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

*copyc clv$display_variables

    CONST
      minimum_display_line = osc$max_name_size + 3,
      minimum_line_size = osc$max_name_size + 3,
      brief_header_length = 13,
      full_header_length = 7,
      system_entry_length = 7,
      subentry_column = 3,
      entry_name_size = osc$max_name_size + 1;

?? 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_partial_display', EJECT ??

    PROCEDURE 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;
      IFEND;

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

    PROCEDURE put_path_chunks
      (    path_name: string ( * );
           display_chunks: clt$path_display_chunks;
           chunk_count: 0 .. fsc$max_path_elements;
           column: amt$page_width);

      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
          EXIT clp$_display_command_list;
        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_subtitle', EJECT ??

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

{ The display_command_list command has no subtitles,
{ this is merely a dummy routine used to keep
{ the module consistent with those that do produce subtitles.

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

    PROCEDURE display_entry_names
      (    start_of_list: ^clt$command_list_entry;
           end_of_list: ^clt$command_list_entry;
       VAR status: ost$status);

      CONST
        unaccessible = '     "UNACCESSIBLE"';

      VAR
        chunk_count: 0 .. fsc$max_path_elements,
        current_entry: ^clt$command_list_entry,
        display_chunks: clt$path_display_chunks,
        display_line: ^string (*),
        display_line_length: integer,
        entries_written: boolean,
        line_size: amt$page_width,
        utility_name: clt$utility_name;


      status.normal := TRUE;
      current_entry := start_of_list;
      IF display_control.page_width < minimum_display_line THEN
        line_size := minimum_line_size;
      ELSE
        line_size := display_control.page_width;
      IFEND;
      entries_written := FALSE;

      WHILE current_entry <> end_of_list DO
        IF NOT entries_written THEN
          put_partial_display ('Entries are', clc$no_trim, amc$continue);
        IFEND;

        CASE current_entry^.kind OF

*IF NOT $true(osv$unix)
        = clc$catalog_commands, clc$library_commands =
          clp$get_path_name (current_entry^.local_file_name, osc$full_message_level, file_reference);
          display_line_length := clp$trimmed_string_size (file_reference);
          IF current_entry^.unaccessible_entry THEN
            PUSH display_line: [display_line_length + STRLENGTH (unaccessible)];
            STRINGREP (display_line^, display_line_length, file_reference (1,display_line_length),
                  unaccessible);
          ELSE
            display_line := ^file_reference;
          IFEND;
          clp$build_path_subtitle (display_line^, display_line_length,
                (line_size - brief_header_length), chunk_count, display_chunks);
          put_path_chunks (display_line^, display_chunks, chunk_count, brief_header_length + 1);

        = clc$working_catalog_commands =
          clp$horizontal_tab_display (display_control, brief_header_length + 1, status);
          IF NOT status.normal THEN
            EXIT clp$_display_command_list;
          IFEND;
          put_partial_display (':$working_catalog', clc$trim, amc$terminate);
*IFEND

        = clc$system_commands =
          clp$horizontal_tab_display (display_control, brief_header_length + 1, status);
          IF NOT status.normal THEN
            EXIT clp$_display_command_list;
          IFEND;
          put_partial_display ('$system', clc$trim, amc$terminate);

        = clc$sub_commands =
          clp$horizontal_tab_display (display_control, brief_header_length + 1, status);
          IF NOT status.normal THEN
            EXIT clp$_display_command_list;
          IFEND;
          #TRANSLATE (osv$upper_to_lower, current_entry^.utility_name, utility_name);
          put_partial_display (utility_name, clc$trim, amc$terminate);

        = clc$command_list_fence =
          clp$horizontal_tab_display (display_control, brief_header_length + 1, status);
          IF NOT status.normal THEN
            EXIT clp$_display_command_list;
          IFEND;
          put_partial_display ('fence', clc$trim, amc$terminate);

        ELSE
          ;
        CASEND;

        entries_written := TRUE;

        current_entry := current_entry^.next_entry;
      WHILEND;

      IF NOT entries_written THEN
        put_partial_display ('The command list is empty.', clc$no_trim, amc$terminate);
      IFEND;

    PROCEND display_entry_names;
?? OLDTITLE, EJECT ??

    VAR
      block: ^clt$block,
      command_list: ^clt$command_list,
      current_node: ^clt$data_value,
*IF NOT $true(osv$unix)
      default_ring_attributes: amt$ring_attributes,
*IFEND
      display_control: clt$display_control,
      effective_search_mode: clt$command_search_modes,
      end_of_list: ^clt$command_list_entry,
      entries: boolean,
      file_reference: fst$path,
*IF $true(osv$unix)
      handler_established: boolean,
*IFEND
      index: integer,
      ignore_cmnd_list_found_in_task: boolean,
      local_status: ost$status,
      search: boolean,
*IF NOT $true(osv$unix)
      search_modes: [STATIC, READ, oss$job_paged_literal] array [clt$command_search_modes] of string (10) :=
            ['global', 'restricted', 'exclusive'],
*IFEND
      start_of_list: ^clt$command_list_entry;


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

    entries := FALSE;
    search := FALSE;

    current_node := pvt [p$display_options].value;
    WHILE current_node <> NIL DO
      IF current_node^.element_value^.keyword_value = 'ENTRIES' THEN
        entries := TRUE;
      ELSEIF current_node^.element_value^.keyword_value = 'SEARCH_MODE' THEN
        search := TRUE;
      ELSE {ALL}
        entries := TRUE;
        search := TRUE;
      IFEND;
      current_node := current_node^.link;
    WHILEND;

    display_control := clv$nil_display_control;
    #SPOIL (display_control);
*IF NOT $true(osv$unix)
    osp$establish_block_exit_hndlr (^abort_handler);

*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
    handler_established := #establish_condition_handler (-1, ^abort_handler);

    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
*IF $true(osv$unix)
      IF handler_established THEN
        handler_established := NOT #disestablish_condition_handler (-1);
      IFEND;
*ELSE
      osp$disestablish_cond_handler;
*IFEND
      RETURN;
    IFEND;
    clv$titles_built := FALSE;
    clv$command_name := 'display_command_list';

    clp$find_command_list (command_list, ignore_cmnd_list_found_in_task);

*IF NOT $true(osv$unix)
    IF search THEN
      put_partial_display ('Search Mode is ', clc$no_trim, amc$start);
      put_partial_display (search_modes [command_list^.search_mode], clc$trim, amc$terminate);
    IFEND;
*IFEND

    IF entries THEN
      clp$find_current_block (block);
      start_of_list := command_list^.entries.first_entry;
      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
        end_of_list := NIL;
      IFEND;
      display_entry_names (start_of_list, end_of_list, status);
    IFEND;

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

*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;
*IF NOT $true(osv$unix)
?? TITLE := 'clp$$command_list', EJECT ??

  PROCEDURE [XDCL] clp$$command_list
    (    parameter_list: clt$parameter_list;
     VAR work_area {input, output} : ^clt$work_area;
     VAR result: ^clt$data_value;
     VAR status: ost$status);

{ FUNCTION (osm$$coml) $command_list

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

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
    recend := [
    [1,
    [89, 3, 30, 15, 15, 19, 104],
    clc$function, 0, 0, 0, 0, 0, 0, 0, 'OSM$$COML']];

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

    VAR
      command_list: ^clt$command_list,
      current_entry: ^clt$command_list_entry,
      file_reference: fst$path,
      ignore_cmnd_list_found_in_task: boolean,
      result_node: ^^clt$data_value;


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

    clp$find_command_list (command_list, ignore_cmnd_list_found_in_task);

    current_entry := command_list^.entries.first_entry;
    result_node := ^result;

    WHILE current_entry <> NIL DO
      clp$make_list_value (work_area, result_node^);
      IF result_node^ = NIL THEN
        osp$set_status_abnormal ('CL', cle$work_area_overflow, '', status);
        RETURN;
      IFEND;

      CASE current_entry^.kind OF
      = clc$catalog_commands, clc$library_commands =
        clp$get_path_name (current_entry^.local_file_name, osc$full_message_level, file_reference);
        clp$make_file_value (file_reference (1, clp$trimmed_string_size (file_reference)), work_area,
              result_node^^.element_value);
      = clc$working_catalog_commands =
        clp$make_file_value (':$WORKING_CATALOG', work_area, result_node^^.element_value);
      = clc$system_commands =
        clp$make_keyword_value ('$SYSTEM', work_area, result_node^^.element_value);
      = clc$sub_commands =
        clp$make_name_value (current_entry^.utility_name, work_area, result_node^^.element_value);
      = clc$command_list_fence =
        clp$make_keyword_value ('FENCE', work_area, result_node^^.element_value);
      ELSE
        ;
      CASEND;

      IF result_node^^.element_value = NIL THEN
        osp$set_status_abnormal ('CL', cle$work_area_overflow, '', status);
        RETURN;
      IFEND;

      result_node := ^result_node^^.link;
      current_entry := current_entry^.next_entry;
    WHILEND;

    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;
?? TITLE := 'clp$$command_search_mode', EJECT ??

  PROCEDURE [XDCL] clp$$command_search_mode
    (    parameter_list: clt$parameter_list;
     VAR work_area {input, output} : ^clt$work_area;
     VAR result: ^clt$data_value;
     VAR status: ost$status);

{ FUNCTION (osm$$comsm) $command_search_mode

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

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
    recend := [
    [1,
    [89, 3, 30, 15, 15, 19, 104],
    clc$function, 0, 0, 0, 0, 0, 0, 0, 'OSM$$COMSM']];

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

    VAR
      result_node: ^^clt$data_value,
      search_mode: clt$command_search_modes,
      search_modes: [STATIC, READ, oss$job_paged_literal] array [clt$command_search_modes] of string (10) :=
            ['GLOBAL', 'RESTRICTED', 'EXCLUSIVE'];


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

    clp$get_command_search_mode (search_mode);

    clp$make_keyword_value (search_modes [search_mode], work_area, result);
    IF result = NIL THEN
      osp$set_status_abnormal ('CL', cle$work_area_overflow, '', status);
    IFEND;

  PROCEND clp$$command_search_mode;
*IFEND

MODEND clm$display_command_list;
