*copyc osd$default_pragmats

MODULE fmm$expand_file_label;

{    This module expands a label, if it is in the V1 sequence format,
{ into the record format of bat$static_label_attributes.  It also
{ returns the values of the file's ring_attributes and the pointer to
{ the job routing label if one exists.

?? NEWTITLE := 'Global Declarations', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc ame$attribute_validation_errors
*copyc bat$static_label_attributes
*copyc fmc$unique_label_id
*copyc fmt$basic_file_label
*copyc fmt$file_attribute_keys
*copyc fmt$file_label
*copyc fmt$static_label_item
*copyc fmt$static_label_header
*copyc fmt$label_headers
*copyc fmv$system_file_attributes
*copyc jmt$system_label_info_length
*copyc osp$set_status_abnormal
*copyc ost$status
?? POP ??

?? TITLE := '[XDCL] fmp$expand_file_label', EJECT ??

  PROCEDURE [XDCL] fmp$expand_file_label (file_label_p:
    fmt$p_file_label;
        expand_label: boolean;
    VAR job_label: ^SEQ ( * );
    VAR job_label_size: jmt$system_label_info_length;
    VAR ring_attributes: amt$ring_attributes;
    VAR ring_attributes_source: amt$attribute_source;
    VAR file_previously_opened: boolean;
    VAR expanded_label: bat$static_label_attributes;
    VAR status: ost$status);

    VAR
      p_file_label: ^SEQ ( * ),
      job_label_header: ^fmt$job_label_header,
      label_header: ^fmt$static_label_header,
      static_info: ^fmt$basic_file_label,
      static_label: ^SEQ ( * ),
      static_label_size: integer,
      v1_header: ^fmt$static_bam_label_header;

    p_file_label := file_label_p; {assign seq ptr to local variable}

    job_label := NIL;
    RESET p_file_label;
    static_label_size := #SIZE (p_file_label^) - #SIZE (fmt$static_label_header);
    NEXT label_header IN p_file_label;
    IF (label_header <> NIL) AND (label_header^.unique_character = fmc$unique_label_id) THEN
      file_previously_opened := label_header^.file_previously_opened;
      IF file_previously_opened THEN
        ring_attributes := label_header^.ring_attributes;
        ring_attributes_source := label_header^.ring_attributes_source;
      ELSE
        ring_attributes := fmv$system_file_attributes.static_label.
              ring_attributes;
        ring_attributes_source := fmv$system_file_attributes.static_label.
              ring_attributes_source;
      IFEND;
      job_label_size := label_header^.job_routing_label_size;
      IF job_label_size > 0 THEN
        static_label_size := static_label_size - job_label_size;
        IF static_label_size > 0 THEN
          NEXT static_label: [[REP static_label_size OF cell]] IN p_file_label;
          IF static_label = NIL THEN
            osp$set_status_abnormal (amc$access_method_id,
                  ame$damaged_file_attributes,
                  'STATIC LABEL is NIL in fmp$expand_file_label', status);
            RETURN;
          IFEND;
        IFEND;
        NEXT job_label: [[REP job_label_size OF cell]] IN p_file_label;
        IF job_label = NIL THEN
          osp$set_status_abnormal (amc$access_method_id,
                ame$damaged_file_attributes,
                'JOB LABEL is NIL in fmp$expand_file_label', status);
          RETURN;
        IFEND;
      IFEND;
    ELSE { possible v1 label }
      RESET p_file_label;
      NEXT v1_header IN p_file_label;
      IF v1_header = NIL THEN
        osp$set_status_abnormal (amc$access_method_id,
              ame$damaged_file_attributes,
              'V1_HEADER is NIL in fmp$expand_file_label', status);
        RETURN;
      IFEND;
      IF v1_header^.name <> 'BAM_STATIC_LABEL' THEN
        osp$set_status_abnormal (amc$access_method_id,
              ame$damaged_file_attributes,
              'INVALID STATIC LABEL NAME DETECTED in fmp$expand_file_label',
              status);
        RETURN;
      ELSE
        NEXT static_info IN p_file_label;
        IF static_info = NIL THEN
          osp$set_status_abnormal (amc$access_method_id,
                ame$damaged_file_attributes,
                'STATIC_INFO is NIL in fmp$expand_file_label', status);
          RETURN;
        IFEND;
        IF expand_label THEN
          fmp$expand_v1_label (static_info, expanded_label, file_previously_opened,
                status);
          ring_attributes := expanded_label.ring_attributes;
          ring_attributes_source := expanded_label.ring_attributes_source;
        ELSE
          file_previously_opened := static_info^. existing_file;
          ring_attributes := static_info^. ring_attributes;
          ring_attributes_source := static_info^. ring_attributes_source;
        IFEND;
      IFEND;
      NEXT job_label_header IN p_file_label;
      IF job_label_header^.name <> 'BAM_JOB_LABEL' THEN
        osp$set_status_abnormal (amc$access_method_id,
              ame$damaged_file_attributes,
              'INVALID JOB LABEL NAME DETECTED in fmp$expand_file_label',
              status);
        RETURN;
      IFEND;
      job_label_size := job_label_header^.size;
      IF job_label_size > 0 THEN
        NEXT job_label: [[REP job_label_size OF cell]] IN p_file_label;
      IFEND;
    IFEND;

  PROCEND fmp$expand_file_label;

  PROCEDURE [XDCL] fmp$expand_v1_label (v1_label: ^fmt$basic_file_label;
    VAR expanded_label: bat$static_label_attributes;
    VAR file_previously_opened: boolean;
    VAR status: ost$status);

    expanded_label := fmv$system_file_attributes.static_label;
    file_previously_opened := v1_label^.existing_file;
    expanded_label.block_type := v1_label^.block_type;
    expanded_label.block_type_source := v1_label^.block_type_source;
    expanded_label.character_conversion := v1_label^.character_conversion;
    expanded_label.character_conversion_source := v1_label^.
          character_conversion_source;
    expanded_label.clear_space := v1_label^.clear_space;
    expanded_label.clear_space_source := v1_label^.clear_space_source;
    expanded_label.file_access_procedure := v1_label^.
          file_access_procedure;
    expanded_label.file_access_procedure_source := v1_label^.
          file_access_procedure_source;
    expanded_label.file_contents := v1_label^.file_contents;
    expanded_label.file_contents_source := v1_label^.file_contents_source;
    expanded_label.file_limit := v1_label^.file_limit;
    expanded_label.file_limit_source := v1_label^.file_limit_source;
    expanded_label.file_organization := v1_label^.file_organization;
    expanded_label.file_organization_source := v1_label^.
          file_organization_source;
    expanded_label.file_processor := v1_label^.file_processor;
    expanded_label.file_processor_source := v1_label^.
          file_processor_source;
    expanded_label.file_structure := v1_label^.file_structure;
    expanded_label.file_structure_source := v1_label^.
          file_structure_source;
    expanded_label.forced_write := v1_label^.forced_write;
    expanded_label.forced_write_source := v1_label^.forced_write_source;
    expanded_label.internal_code := v1_label^.internal_code;
    expanded_label.internal_code_source := v1_label^.internal_code_source;
    expanded_label.label_type := v1_label^.label_type;
    expanded_label.label_type_source := v1_label^.label_type_source;
    IF (v1_label^.line_number.length < LOWERVALUE (amt$line_number_length)) OR
          (v1_label^.line_number.length > UPPERVALUE (amt$line_number_length)) THEN
      expanded_label.line_number.length := fmv$system_file_attributes.
            static_label.line_number.length;
    ELSE
      expanded_label.line_number.length := v1_label^.line_number.length;
    IFEND;
    IF (v1_label^.line_number.location < LOWERVALUE (amt$line_number_location))
          OR (v1_label^.line_number.location > UPPERVALUE (amt$line_number_location)) THEN
      expanded_label.line_number.location := fmv$system_file_attributes.
            static_label.line_number.location;
    ELSE
      expanded_label.line_number.location := v1_label^.line_number.location;
    IFEND;
    expanded_label.line_number_source := v1_label^.line_number_source;
    expanded_label.max_block_length := v1_label^.max_block_length;
    expanded_label.max_block_length_source := v1_label^.
          max_block_length_source;
    expanded_label.max_record_length := v1_label^.max_record_length;
    expanded_label.max_record_length_source := v1_label^.
          max_record_length_source;
    expanded_label.min_block_length := v1_label^.min_block_length;
    expanded_label.min_block_length_source := v1_label^.
          min_block_length_source;
    expanded_label.min_record_length := v1_label^.min_record_length;
    expanded_label.min_record_length_source := v1_label^.
          min_record_length_source;
    expanded_label.padding_character := v1_label^.padding_character;
    expanded_label.padding_character_source := v1_label^.
          padding_character_source;
    expanded_label.page_format := v1_label^.page_format;
    expanded_label.page_format_source := v1_label^.page_format_source;
    expanded_label.page_length := v1_label^.page_length;
    expanded_label.page_length_source := v1_label^.page_length_source;
    expanded_label.page_width := v1_label^.page_width;
    expanded_label.page_width_source := v1_label^.page_width_source;
    expanded_label.preset_value := v1_label^.preset_value;
    expanded_label.preset_value_source := v1_label^.preset_value_source;
    expanded_label.record_type := v1_label^.record_type;
    expanded_label.record_type_source := v1_label^.record_type_source;
    expanded_label.ring_attributes := v1_label^.ring_attributes;
    expanded_label.ring_attributes_source := v1_label^.
          ring_attributes_source;
    IF (v1_label^.statement_identifier.length < LOWERVALUE
          (amt$statement_id_length)) OR (v1_label^.statement_identifier.length
          > UPPERVALUE (amt$statement_id_length)) THEN
      expanded_label.statement_identifier.length := fmv$system_file_attributes.
            static_label.statement_identifier.length;
    ELSE
      expanded_label.statement_identifier.length := v1_label^.statement_identifier.length;
    IFEND;
    IF (v1_label^.statement_identifier.location < LOWERVALUE
          (amt$statement_id_location)) OR (v1_label^.statement_identifier.
          location > UPPERVALUE (amt$statement_id_location)) THEN
      expanded_label.statement_identifier.location := fmv$system_file_attributes.
            static_label.statement_identifier.location;
    ELSE
      expanded_label.statement_identifier.location := v1_label^.statement_identifier.location;
    IFEND;
    expanded_label.statement_identifier_source := v1_label^.
          statement_identifier_source;
    expanded_label.user_info := v1_label^.user_info;
    expanded_label.user_info_source := v1_label^.user_info_source;
    expanded_label.vertical_print_density := v1_label^.
          vertical_print_density;
    expanded_label.vertical_print_density_source := v1_label^.
          vertical_print_density_source;
    IF (v1_label^.average_record_length < LOWERVALUE (amt$average_record_length))
          OR (v1_label^.average_record_length > UPPERVALUE (amt$average_record_length)) THEN
      expanded_label.average_record_length := fmv$system_file_attributes.
            static_label.average_record_length;
    ELSE
      expanded_label.average_record_length := v1_label^.
            average_record_length;
    IFEND;
    expanded_label.average_record_length_source := v1_label^.
          average_record_length_source;
    expanded_label.collate_table := v1_label^.collate_table;
    expanded_label.collate_table_source := v1_label^.collate_table_source;
    expanded_label.collate_table_name := v1_label^.collate_table_name;
    expanded_label.collate_table_name_source := v1_label^.
          collate_table_name_source;
    expanded_label.data_padding := v1_label^.data_padding;
    expanded_label.data_padding_source := v1_label^.data_padding_source;
    expanded_label.embedded_key := v1_label^.embedded_key;
    expanded_label.embedded_key_source := v1_label^.embedded_key_source;
    expanded_label.estimated_record_count := v1_label^.
          estimated_record_count;
    expanded_label.estimated_record_count_source := v1_label^.
          estimated_record_count_source;
    expanded_label.index_levels := v1_label^.index_levels;
    expanded_label.index_levels_source := v1_label^.index_levels_source;
    expanded_label.index_padding := v1_label^.index_padding;
    expanded_label.index_padding_source := v1_label^.index_padding_source;
    IF (v1_label^.key_length < LOWERVALUE (amt$key_length)) OR
          (v1_label^.key_length > UPPERVALUE (amt$key_length)) THEN
      expanded_label.key_length := fmv$system_file_attributes.static_label.
            key_length;
    ELSE
      expanded_label.key_length := v1_label^.key_length;
    IFEND;
    expanded_label.key_length_source := v1_label^.key_length_source;
    expanded_label.key_position := v1_label^.key_position;
    expanded_label.key_position_source := v1_label^.key_position_source;
    expanded_label.key_type := v1_label^.key_type;
    expanded_label.key_type_source := v1_label^.key_type_source;
    IF (v1_label^.record_limit < LOWERVALUE (amt$record_limit)) OR
          (v1_label^.record_limit > UPPERVALUE (amt$record_limit)) THEN
      expanded_label.record_limit := fmv$system_file_attributes.static_label.
            record_limit;
    ELSE
      expanded_label.record_limit := v1_label^.record_limit;
    IFEND;
    expanded_label.record_limit_source := v1_label^.record_limit_source;
    IF (v1_label^.records_per_block < LOWERVALUE (amt$records_per_block)) OR
          (v1_label^.records_per_block > UPPERVALUE (amt$records_per_block)) THEN
      expanded_label.records_per_block := fmv$system_file_attributes.
            static_label.records_per_block;
    ELSE
      expanded_label.records_per_block := v1_label^.records_per_block;
    IFEND;
    expanded_label.records_per_block_source := v1_label^.
          records_per_block_source;

  PROCEND fmp$expand_v1_label;

MODEND fmm$expand_file_label;
