?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE Dump Analyzer : Display Dump Record Command' ??
MODULE dum$display_dr_command;

{ PURPOSE:
{   This module contains the code for the display_dump_record command.

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc due$exception_condition_codes
?? POP ??
*copyc clp$close_display
*copyc clp$evaluate_parameters
*copyc clp$open_display_reference
*copyc dup$display_data
*copyc dup$find_record_list_entry
*copyc dup$new_page_procedure
*copyc osp$disestablish_cond_handler
*copyc osp$establish_block_exit_hndlr
*copyc osp$set_status_abnormal
?? EJECT ??
*copyc duv$dump_environment_p
*copyc duv$execution_environment
*copyc duv$title_data
?? OLDTITLE ??
?? NEWTITLE := 'dup$display_dr_command', EJECT ??

{ PURPOSE:
{   This procedure displays a dump record from the restart file.

  PROCEDURE [XDCL] dup$display_dr_command
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE display_dump_record, disdr (
{   record_identifier, ri: any of
{       string 1..3
{       integer
{       name
{     anyend = $required
{   offset, off: integer = 0
{   bytes, b: integer 0..500000
{   display_option, do: list 1..2 of key
{       (numeric n) (ascii a) (display_code dc)
{     keyend = (numeric ascii)
{   title, t: string 1..31 = 'display_dump_record'
{   radix, r: integer 8..16 = 16
{   output, o: file
{   status)

?? PUSH (LISTEXT := ON) ??
?? FMT (FORMAT := OFF) ??
  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 15] of clt$pdt_parameter_name,
      parameters: array [1 .. 8] 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$string_type_qualifier,
        recend,
        type_size_2: clt$type_specification_size,
        element_type_spec_2: record
          header: clt$type_specification_header,
          qualifier: clt$integer_type_qualifier,
        recend,
        type_size_3: clt$type_specification_size,
        element_type_spec_3: record
          header: clt$type_specification_header,
          qualifier: clt$name_type_qualifier,
        recend,
      recend,
      type2: record
        header: clt$type_specification_header,
        qualifier: clt$integer_type_qualifier,
        default_value: string (1),
      recend,
      type3: record
        header: clt$type_specification_header,
        qualifier: clt$integer_type_qualifier,
      recend,
      type4: 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 .. 6] of clt$keyword_specification,
        recend,
        default_value: string (15),
      recend,
      type5: record
        header: clt$type_specification_header,
        qualifier: clt$string_type_qualifier,
        default_value: string (21),
      recend,
      type6: record
        header: clt$type_specification_header,
        qualifier: clt$integer_type_qualifier,
        default_value: string (2),
      recend,
      type7: record
        header: clt$type_specification_header,
      recend,
      type8: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [92, 1, 22, 11, 36, 21, 819],
    clc$command, 15, 8, 1, 0, 0, 0, 8, ''], [
    ['B                              ',clc$abbreviation_entry, 3],
    ['BYTES                          ',clc$nominal_entry, 3],
    ['DISPLAY_OPTION                 ',clc$nominal_entry, 4],
    ['DO                             ',clc$abbreviation_entry, 4],
    ['O                              ',clc$abbreviation_entry, 7],
    ['OFF                            ',clc$abbreviation_entry, 2],
    ['OFFSET                         ',clc$nominal_entry, 2],
    ['OUTPUT                         ',clc$nominal_entry, 7],
    ['R                              ',clc$abbreviation_entry, 6],
    ['RADIX                          ',clc$nominal_entry, 6],
    ['RECORD_IDENTIFIER              ',clc$nominal_entry, 1],
    ['RI                             ',clc$abbreviation_entry, 1],
    ['STATUS                         ',clc$nominal_entry, 8],
    ['T                              ',clc$abbreviation_entry, 5],
    ['TITLE                          ',clc$nominal_entry, 5]],
    [
{ PARAMETER 1
    [11, 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, 57, clc$required_parameter,
  0, 0],
{ PARAMETER 2
    [7, 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, 20,
  clc$optional_default_parameter, 0, 1],
{ PARAMETER 3
    [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, 20, clc$optional_parameter,
  0, 0],
{ PARAMETER 4
    [3, 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, 15],
{ PARAMETER 5
    [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, 8,
  clc$optional_default_parameter, 0, 21],
{ PARAMETER 6
    [10, 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, 20,
  clc$optional_default_parameter, 0, 2],
{ PARAMETER 7
    [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_parameter, 0
  , 0],
{ PARAMETER 8
    [13, 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$union_type], [[clc$integer_type, clc$name_type, clc$string_type],
    TRUE, 3],
    8, [[1, 0, clc$string_type], [1, 3, FALSE]],
    20, [[1, 0, clc$integer_type], [clc$min_integer, clc$max_integer, 10]],
    5, [[1, 0, clc$name_type], [1, osc$max_name_size]]
    ],
{ PARAMETER 2
    [[1, 0, clc$integer_type], [clc$min_integer, clc$max_integer, 10],
    '0'],
{ PARAMETER 3
    [[1, 0, clc$integer_type], [0, 500000, 10]],
{ PARAMETER 4
    [[1, 0, clc$list_type], [229, 1, 2, 0, FALSE, FALSE],
      [[1, 0, clc$keyword_type], [6], [
      ['A                              ', clc$abbreviation_entry, clc$normal_usage_entry, 2],
      ['ASCII                          ', clc$nominal_entry, clc$normal_usage_entry, 2],
      ['DC                             ', clc$abbreviation_entry, clc$normal_usage_entry, 3],
      ['DISPLAY_CODE                   ', clc$nominal_entry, clc$normal_usage_entry, 3],
      ['N                              ', clc$abbreviation_entry, clc$normal_usage_entry, 1],
      ['NUMERIC                        ', clc$nominal_entry, clc$normal_usage_entry, 1]]
      ]
    ,
    '(numeric ascii)'],
{ PARAMETER 5
    [[1, 0, clc$string_type], [1, 31, FALSE],
    '''display_dump_record'''],
{ PARAMETER 6
    [[1, 0, clc$integer_type], [8, 16, 10],
    '16'],
{ PARAMETER 7
    [[1, 0, clc$file_type]],
{ PARAMETER 8
    [[1, 0, clc$status_type]]];
?? FMT (FORMAT := ON) ??
?? POP ??

    CONST
      p$record_identifier = 1,
      p$offset = 2,
      p$bytes = 3,
      p$display_option = 4,
      p$title = 5,
      p$radix = 6,
      p$output = 7,
      p$status = 8;

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

    VAR
      bytes: integer,
      cell_p: ^cell,
      display_control: clt$display_control,
      display_string: string (osc$max_string_size),
      end_of_input_file: boolean,
      entry_p: ^dut$de_other_record_entry,
      ignore_status: ost$status,
      output_display_opened: boolean,
      restart_file_seq_p: ^SEQ ( * ),
      ring_attributes: amt$ring_attributes,
      skip_data_p: ^SEQ ( * ),
      string_length: integer;

*copy dup$abort_handler
?? NEWTITLE := 'clean_up', EJECT ??

{ PURPOSE:
{   This procedure is called from the abort handler to close the file.

    PROCEDURE [INLINE] clean_up;

      VAR
        ignore_status: ost$status;

      IF output_display_opened THEN
        clp$close_display (display_control, ignore_status);
      IFEND;

    PROCEND clean_up;
?? OLDTITLE, EJECT ??

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

    IF duv$dump_environment_p = NIL THEN
      osp$set_status_abnormal (duc$dump_analyzer_id, due$no_restart_file, '', status);
      RETURN;  {---->
    IFEND;

    dup$find_record_list_entry (pvt [p$record_identifier].value^, entry_p);
    IF entry_p = NIL THEN
      osp$set_status_abnormal (duc$dump_analyzer_id, due$data_not_on_dump, 'The specified record is',
            status);
      RETURN;  {---->
    IFEND;

    IF entry_p^.record_type <> duc$de_ort_dump THEN
      osp$set_status_abnormal (duc$dump_analyzer_id, due$record_type_supported, 'DUMP', status);
      RETURN;  {---->
    IFEND;

    { Determine the number of bytes to display.

    IF (pvt [p$offset].value^.integer_value.value > entry_p^.size) THEN
      osp$set_status_abnormal (duc$dump_analyzer_id, due$invalid_offset, '', status);
      RETURN;  {---->
    IFEND;
    IF pvt [p$bytes].specified THEN
      bytes := pvt [p$bytes].value^.integer_value.value;
    ELSE
      bytes := entry_p^.size;
    IFEND;
    IF (bytes + pvt [p$offset].value^.integer_value.value) > entry_p^.size THEN
      bytes := entry_p^.size - pvt [p$offset].value^.integer_value.value;
    IFEND;

    output_display_opened := FALSE;
    osp$establish_block_exit_hndlr (^abort_handler);

   /display_opened/
    BEGIN

      { Prepare the output display file.

      IF pvt [p$output].specified THEN
        ring_attributes.r1 := #RING (^ring_attributes);
        ring_attributes.r2 := #RING (^ring_attributes);
        ring_attributes.r3 := #RING (^ring_attributes);
        clp$open_display_reference (pvt [p$output].value^.file_value^, ^dup$new_page_procedure, fsc$list,
              ring_attributes, display_control, status);
        IF NOT status.normal THEN
          EXIT /display_opened/;  {---->
        IFEND;
        output_display_opened := TRUE;
      ELSE
        display_control := duv$execution_environment.output_file.display_control;
        display_control.line_number := display_control.page_length + 1;
      IFEND;

      duv$title_data.build_title := TRUE;
      IF pvt [p$title].specified THEN
        duv$title_data.command_name := pvt [p$title].value^.string_value^;
      ELSE
        STRINGREP (display_string, string_length, 'display_dump_record :  ', entry_p^.name);
        duv$title_data.command_name := display_string (1, string_length);
      IFEND;

      IF bytes = 0 THEN
        EXIT /display_opened/;  {---->
      IFEND;

      { Skip to the desired offset in the record data.

      restart_file_seq_p := duv$execution_environment.data_file_p^.segment_pointer.sequence_pointer;
      cell_p := #ADDRESS (#RING (restart_file_seq_p), #SEGMENT (restart_file_seq_p), entry_p^.first_byte);
      RESET restart_file_seq_p TO cell_p;
      IF pvt [p$offset].value^.integer_value.value <> 0 THEN
        NEXT skip_data_p: [[REP pvt [p$offset].value^.integer_value.value OF cell]] IN restart_file_seq_p;
        IF skip_data_p = NIL THEN
          osp$set_status_abnormal (duc$dump_analyzer_id, due$nil_pointer, '', status);
          EXIT /display_opened/;  {---->
        IFEND;
      IFEND;

      { Display the data.

      dup$display_data (pvt [p$display_option].value, TRUE, pvt [p$radix].value^.integer_value.value,
            pvt [p$offset].value^.integer_value.value, bytes, display_control, restart_file_seq_p,
            end_of_input_file, status);

    END /display_opened/;

    IF output_display_opened THEN
      clp$close_display (display_control, ignore_status);
    IFEND;
    osp$disestablish_cond_handler;

  PROCEND dup$display_dr_command;
MODEND dum$display_dr_command;
