?? NEWTITLE := 'NOS/VE : Access Methods : Display Bam Tables' ??
MODULE amm$display_bam_tables;
?? RIGHT := 110 ??

{  PURPOSE:
{    This module contains the command parser for DISPLAY_BAM_TABLES.
{
{  DESIGN:
{    Open the output file, parse the command, and call the
{    appropriate procedures in BAM$DISPLAY_TABLES to display
{    the requested table to the output file.

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc bat$display_tables_indention
*copyc fmt$path_handle
*copyc fst$path_handle_name
*copyc fst$path_table_expansion_limit
*copyc ost$status
?? POP ??
*copyc amp$put_next
*copyc amp$return
*copyc bap$display_art
*copyc bap$display_files
*copyc bap$display_path_table
*copyc bap$display_pde_via_ph
*copyc bap$display_pt_stats
*copyc bap$display_task_file_table
*copyc bap$display_tfte_via_ph
*copyc bap$display_unused_paths
*copyc bap$process_pt_request
*copyc bap$validate_path_table_objects
*copyc clp$evaluate_file_reference
*copyc clp$evaluate_parameters
*copyc fsp$close_file
*copyc fsp$copy_file
*copyc fsp$open_file
*copyc osp$disestablish_cond_handler
*copyc osp$establish_block_exit_hndlr
*copyc pmp$get_unique_name
*copyc amv$nil_file_identifier
?? OLDTITLE ??
?? NEWTITLE := 'PROCEDURE [XDCL, #GATE] amp$display_bam_tables', EJECT ??

  PROCEDURE [XDCL, #GATE] amp$display_bam_tables
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE (amp$disbt) display_bam_tables, disbt (
{   file, f: file = $optional
{   table, tables, t: list of key
{       (path_table_statistics, pts)
{       (path_table_files, ptf)
{       (path_table_unused_paths, ptup)
{       (path_description_entry, pde)
{       (task_file_table_entry, task_file_table_entries, tfte)
{       (auxiliary_request_table, art)
{       (path_table, pt)
{       (task_file_table, tft)
{       all
{     keyend = path_description_entry
{   path_table_expansion_limit, d, depth, ptel: key
{       (path_description_entry, pde)
{       (cycle_description, cd)
{       all
{     keyend = cd
{   task_file_table_expansion, e, expansion, tfte: key
{       (brief, b)
{       (full, f)
{     keyend = brief
{   validate_path_table_objects, vpto: (BY_NAME) boolean = no
{   output, o: (BY_NAME) file = $output
{   status)

?? PUSH (LISTEXT := ON) ??

    VAR
      pdt: [STATIC, READ, cls$declaration_section] record
        header: clt$pdt_header,
        names: array [1 .. 18] of clt$pdt_parameter_name,
        parameters: array [1 .. 7] of clt$pdt_parameter,
        type1: record
          header: clt$type_specification_header,
        recend,
        type2: 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 .. 18] of clt$keyword_specification,
          recend,
          default_value: string (22),
        recend,
        type3: record
          header: clt$type_specification_header,
          qualifier: clt$keyword_type_qualifier,
          keyword_specs: array [1 .. 5] of clt$keyword_specification,
          default_value: string (2),
        recend,
        type4: record
          header: clt$type_specification_header,
          qualifier: clt$keyword_type_qualifier,
          keyword_specs: array [1 .. 4] of clt$keyword_specification,
          default_value: string (5),
        recend,
        type5: record
          header: clt$type_specification_header,
          default_value: string (2),
        recend,
        type6: record
          header: clt$type_specification_header,
          default_value: string (7),
        recend,
        type7: record
          header: clt$type_specification_header,
        recend,
      recend := [[1, [88, 4, 6, 12, 51, 44, 100], clc$command, 18, 7, 0, 0, 0, 0, 7, 'AMP$DISBT'],
            [['D                              ', clc$alias_entry, 3],
            ['DEPTH                          ', clc$alias_entry, 3],
            ['E                              ', clc$alias_entry, 4],
            ['EXPANSION                      ', clc$alias_entry, 4],
            ['F                              ', clc$abbreviation_entry, 1],
            ['FILE                           ', clc$nominal_entry, 1],
            ['O                              ', clc$abbreviation_entry, 6],
            ['OUTPUT                         ', clc$nominal_entry, 6],
            ['PATH_TABLE_EXPANSION_LIMIT     ', clc$nominal_entry, 3],
            ['PTEL                           ', clc$abbreviation_entry, 3],
            ['STATUS                         ', clc$nominal_entry, 7],
            ['T                              ', clc$abbreviation_entry, 2],
            ['TABLE                          ', clc$nominal_entry, 2],
            ['TABLES                         ', clc$alias_entry, 2],
            ['TASK_FILE_TABLE_EXPANSION      ', clc$nominal_entry, 4],
            ['TFTE                           ', clc$abbreviation_entry, 4],
            ['VALIDATE_PATH_TABLE_OBJECTS    ', clc$nominal_entry, 5],
            ['VPTO                           ', clc$abbreviation_entry, 5]], [
{ 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, 3, clc$optional_parameter, 0, 0],
{ PARAMETER 2
      [13, 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, 0, 22],
{ PARAMETER 3
      [9, 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, 192, clc$optional_default_parameter, 0, 2],
{ PARAMETER 4
      [15, 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, 155, clc$optional_default_parameter, 0, 5],
{ PARAMETER 5
      [17, clc$normal_usage_entry, clc$non_secure_parameter, $clt$parameter_spec_methods
            [clc$specify_by_name], clc$pass_by_value, clc$immediate_evaluation,
            clc$standard_parameter_checking, 3, clc$optional_default_parameter, 0, 2],
{ PARAMETER 6
      [8, clc$normal_usage_entry, clc$non_secure_parameter, $clt$parameter_spec_methods [clc$specify_by_name],
            clc$pass_by_value, clc$immediate_evaluation, clc$standard_parameter_checking, 3,
            clc$optional_default_parameter, 0, 7],
{ PARAMETER 7
      [11, 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$file_type]],
{ PARAMETER 2
      [[1, 0, clc$list_type], [673, 1, clc$max_list_size, FALSE],
            [[1, 0, clc$keyword_type], [18], [['ALL                            ', clc$nominal_entry,
            clc$normal_usage_entry, 9], ['ART                            ', clc$abbreviation_entry,
            clc$normal_usage_entry, 6], ['AUXILIARY_REQUEST_TABLE        ', clc$nominal_entry,
            clc$normal_usage_entry, 6], ['PATH_DESCRIPTION_ENTRY         ', clc$nominal_entry,
            clc$normal_usage_entry, 4], ['PATH_TABLE                     ', clc$nominal_entry,
            clc$normal_usage_entry, 7], ['PATH_TABLE_FILES               ', clc$nominal_entry,
            clc$normal_usage_entry, 2], ['PATH_TABLE_STATISTICS          ', clc$nominal_entry,
            clc$normal_usage_entry, 1], ['PATH_TABLE_UNUSED_PATHS        ', clc$nominal_entry,
            clc$normal_usage_entry, 3], ['PDE                            ', clc$abbreviation_entry,
            clc$normal_usage_entry, 4], ['PT                             ', clc$abbreviation_entry,
            clc$normal_usage_entry, 7], ['PTF                            ', clc$abbreviation_entry,
            clc$normal_usage_entry, 2], ['PTS                            ', clc$abbreviation_entry,
            clc$normal_usage_entry, 1], ['PTUP                           ', clc$abbreviation_entry,
            clc$normal_usage_entry, 3], ['TASK_FILE_TABLE                ', clc$nominal_entry,
            clc$normal_usage_entry, 8], ['TASK_FILE_TABLE_ENTRIES        ', clc$alias_entry,
            clc$normal_usage_entry, 5], ['TASK_FILE_TABLE_ENTRY          ', clc$nominal_entry,
            clc$normal_usage_entry, 5], ['TFT                            ', clc$abbreviation_entry,
            clc$normal_usage_entry, 8], ['TFTE                           ', clc$abbreviation_entry,
            clc$normal_usage_entry, 5]]], 'path_description_entry'],
{ PARAMETER 3
      [[1, 0, clc$keyword_type], [5], [['ALL                            ', clc$nominal_entry,
            clc$normal_usage_entry, 3], ['CD                             ', clc$abbreviation_entry,
            clc$normal_usage_entry, 2], ['CYCLE_DESCRIPTION              ', clc$nominal_entry,
            clc$normal_usage_entry, 2], ['PATH_DESCRIPTION_ENTRY         ', clc$nominal_entry,
            clc$normal_usage_entry, 1], ['PDE                            ', clc$abbreviation_entry,
            clc$normal_usage_entry, 1]], 'cd'],
{ PARAMETER 4
      [[1, 0, clc$keyword_type], [4], [['B                              ', clc$abbreviation_entry,
            clc$normal_usage_entry, 1], ['BRIEF                          ', clc$nominal_entry,
            clc$normal_usage_entry, 1], ['F                              ', clc$abbreviation_entry,
            clc$normal_usage_entry, 2], ['FULL                           ', clc$nominal_entry,
            clc$normal_usage_entry, 2]], 'brief'],
{ PARAMETER 5
      [[1, 0, clc$boolean_type], 'no'],
{ PARAMETER 6
      [[1, 0, clc$file_type], '$output'],
{ PARAMETER 7
      [[1, 0, clc$status_type]]];

?? POP ??

    CONST
      p$file = 1,
      p$table = 2,
      p$path_table_expansion_limit = 3,
      p$task_file_table_expansion = 4,
      p$validate_path_table_objects = 5,
      p$output = 6,
      p$status = 7;

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

    TYPE
      table_displays = set of (path_table_statistics, path_table_files, path_table_unused_paths,
            path_description_entry, task_file_table_entry, auxiliary_request_table, path_table,
            task_file_table);

    VAR
      attachment_options: array [1 .. 6] of fst$attachment_option,
      ba: amt$file_byte_address,
      default_creation_attributes: array [1 .. 1] of fst$file_cycle_attribute,
      evaluated_file_reference: fst$evaluated_file_reference,
      expand_task_file_table_entry: boolean,
      fid: amt$file_identifier,
      list: ^clt$data_value,
      output_length: integer,
      output_string: string (bat$display_tables_str_length),
      path_table_expansion_limit: fst$path_table_expansion_limit,
      process_pt_results: bat$process_pt_results,
      status_p: ^ost$status,
      tables_to_display: table_displays,
      unique_name: ost$name;

?? 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);

      VAR
        ignore_status: ost$status;

      fsp$close_file (fid, ignore_status);
      amp$return (unique_name, ignore_status);

    PROCEND abort_handler;
?? OLDTITLE ??
?? EJECT ??

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

    status_p := NIL;
    tables_to_display := $table_displays [];
    list := pvt [p$table].value;
    WHILE list <> NIL DO
      IF list^.element_value^.keyword_value = 'ALL' THEN
        tables_to_display := tables_to_display + $table_displays
              [path_table_statistics, path_table_files, path_table_unused_paths, auxiliary_request_table,
              path_table, task_file_table];
      ELSEIF (list^.element_value^.keyword_value = 'PATH_TABLE_STATISTICS') THEN
        tables_to_display := tables_to_display + $table_displays [path_table_statistics];
      ELSEIF (list^.element_value^.keyword_value = 'PATH_TABLE_FILES') THEN
        tables_to_display := tables_to_display + $table_displays [path_table_files];
      ELSEIF (list^.element_value^.keyword_value = 'PATH_TABLE_UNUSED_PATHS') THEN
        tables_to_display := tables_to_display + $table_displays [path_table_unused_paths];
      ELSEIF (list^.element_value^.keyword_value = 'PATH_DESCRIPTION_ENTRY') THEN
        tables_to_display := tables_to_display + $table_displays [path_description_entry];
      ELSEIF (list^.element_value^.keyword_value = 'TASK_FILE_TABLE_ENTRY') THEN
        tables_to_display := tables_to_display + $table_displays [task_file_table_entry];
      ELSEIF (list^.element_value^.keyword_value = 'AUXILIARY_REQUEST_TABLE') THEN
        tables_to_display := tables_to_display + $table_displays [auxiliary_request_table];
      ELSEIF (list^.element_value^.keyword_value = 'PATH_TABLE') THEN
        tables_to_display := tables_to_display + $table_displays [path_table];
      ELSEIF (list^.element_value^.keyword_value = 'TASK_FILE_TABLE') THEN
        tables_to_display := tables_to_display + $table_displays [task_file_table];
      IFEND;
      list := list^.link;
    WHILEND;

    IF (path_table IN tables_to_display) OR (path_description_entry IN tables_to_display) THEN
      IF pvt [p$path_table_expansion_limit].value^.keyword_value = 'PATH_DESCRIPTION_ENTRY' THEN
        path_table_expansion_limit := fsc$disbt_pde;
      ELSEIF pvt [p$path_table_expansion_limit].value^.keyword_value = 'CYCLE_DESCRIPTION' THEN
        path_table_expansion_limit := fsc$disbt_cd;
      ELSE
        path_table_expansion_limit := fsc$disbt_all;
      IFEND;
    IFEND;

    IF (task_file_table IN tables_to_display) OR (task_file_table_entry IN tables_to_display) THEN
      IF pvt [p$task_file_table_expansion].value^.keyword_value = 'FULL' THEN
        expand_task_file_table_entry := TRUE;
      ELSE
        expand_task_file_table_entry := FALSE;
      IFEND;
    IFEND;

    default_creation_attributes [1].selector := fsc$file_contents_and_processor;
    default_creation_attributes [1].file_contents := fsc$list;
    default_creation_attributes [1].file_processor := fsc$unknown_processor;
    attachment_options [1].selector := fsc$access_and_share_modes;
    attachment_options [1].access_modes.selector := fsc$specific_access_modes;
    attachment_options [1].access_modes.value := $fst$file_access_options [fsc$append, fsc$shorten];
    attachment_options [1].share_modes.selector := fsc$specific_share_modes;
    attachment_options [1].share_modes.value := $fst$file_access_options [];
    attachment_options [2].selector := fsc$access_and_share_modes;
    attachment_options [2].access_modes.selector := fsc$specific_access_modes;
    attachment_options [2].access_modes.value := $fst$file_access_options [fsc$append];
    attachment_options [2].share_modes.selector := fsc$specific_share_modes;
    attachment_options [2].share_modes.value := $fst$file_access_options [];
    attachment_options [3].selector := fsc$open_share_modes;
    attachment_options [3].open_share_modes := $fst$file_access_options [];
    attachment_options [4].selector := fsc$open_share_modes;
    attachment_options [4].open_share_modes := $fst$file_access_options
          [fsc$read, fsc$shorten, fsc$append, fsc$modify, fsc$execute];
    attachment_options [5].selector := fsc$sequential_access;
    attachment_options [5].sequential_access := TRUE;
    attachment_options [6].selector := fsc$delete_data;
    attachment_options [6].delete_data := TRUE;

    pmp$get_unique_name (unique_name, status);
    IF NOT status.normal THEN
      RETURN; {----->
    IFEND;

    fsp$open_file (unique_name, amc$record, ^attachment_options, ^default_creation_attributes, NIL, NIL, NIL,
          fid, status);
    IF NOT status.normal THEN
      RETURN; {----->
    IFEND;

    osp$establish_block_exit_hndlr (^abort_handler);

  /display_tables/
    BEGIN
      IF (path_description_entry IN tables_to_display) OR (task_file_table_entry IN tables_to_display) THEN
        IF pvt [p$file].specified THEN
          clp$evaluate_file_reference (pvt [p$file].value^.file_value^, $clt$file_ref_parsing_options [],
                {resolve_cycle_number = } FALSE, evaluated_file_reference, status);
          IF NOT status.normal THEN
            EXIT /display_tables/; {----->
          IFEND;
          bap$process_pt_request ($bat$process_pt_work_list [bac$resolve_to_catalog, bac$resolve_path],
                {local_file_name = } osc$null_name, evaluated_file_reference, process_pt_results, status);
          IF NOT status.normal THEN
            EXIT /display_tables/; {----->
          IFEND;
          IF NOT evaluated_file_reference.path_handle_info.path_handle_present THEN
            STRINGREP (output_string, output_length, ' ', pvt [p$file].value^.file_value^,
                  ' does not exist in the path table.');
            amp$put_next (fid, ^output_string, output_length, ba, status);
            EXIT /display_tables/; {----->
          IFEND;
        ELSE
          STRINGREP (output_string, output_length, ' ', 'The FILE parameter is required to display an entry.')
                ;
          amp$put_next (fid, ^output_string, output_length, ba, status);
          EXIT /display_tables/; {----->
        IFEND;
      IFEND;

      IF pvt [p$validate_path_table_objects].value^.boolean_value.value THEN
        bap$validate_path_table_objects (fid, status);
        IF NOT status.normal THEN
          EXIT /display_tables/; {----->
        IFEND;
      IFEND;

      IF path_table_statistics IN tables_to_display THEN
        bap$display_pt_stats (fid, status);
        IF NOT status.normal THEN
          EXIT /display_tables/; {----->
        IFEND;
      IFEND;
      IF path_table_files IN tables_to_display THEN
        bap$display_files (fid, status);
        IF NOT status.normal THEN
          EXIT /display_tables/; {----->
        IFEND;
      IFEND;
      IF path_table_unused_paths IN tables_to_display THEN
        bap$display_unused_paths (fid, status);
        IF NOT status.normal THEN
          EXIT /display_tables/; {----->
        IFEND;
      IFEND;
      IF path_description_entry IN tables_to_display THEN
        bap$display_pde_via_ph (fid, evaluated_file_reference.path_handle_info.path_handle,
              path_table_expansion_limit, status);
        IF NOT status.normal THEN
          EXIT /display_tables/; {----->
        IFEND;
      IFEND;
      IF task_file_table_entry IN tables_to_display THEN
        bap$display_tfte_via_ph (fid, evaluated_file_reference.path_handle_info.path_handle,
              expand_task_file_table_entry, status);
        IF NOT status.normal THEN
          EXIT /display_tables/; {----->
        IFEND;
      IFEND;
      IF auxiliary_request_table IN tables_to_display THEN
        bap$display_art (fid, status);
        IF NOT status.normal THEN
          EXIT /display_tables/; {----->
        IFEND;
      IFEND;
      IF path_table IN tables_to_display THEN
        bap$display_path_table (fid, path_table_expansion_limit, status);
        IF NOT status.normal THEN
          EXIT /display_tables/; {----->
        IFEND;
      IFEND;
      IF task_file_table IN tables_to_display THEN
        bap$display_task_file_table (fid, expand_task_file_table_entry, status);
      IFEND;
    END /display_tables/;

    IF status.normal THEN
      status_p := ^status;
    ELSE
      PUSH status_p;
    IFEND;

    fsp$close_file (fid, status_p^);

    IF status.normal THEN
      fsp$copy_file (unique_name, pvt [p$output].value^.file_value^, NIL, NIL, NIL, status);
    IFEND;

    IF (NOT status.normal) AND (status_p = ^status) THEN
      PUSH status_p;
    IFEND;

    amp$return (unique_name, status_p^);

    osp$disestablish_cond_handler;

  PROCEND amp$display_bam_tables;
?? OLDTITLE ??
MODEND amm$display_bam_tables;
