?? NEWTITLE := 'NOS/VE Basic Access Method : Tape Attribute Merging' ??
MODULE bam$merge_tape_attributes;
?? RIGHT := 110 ??

{ PURPOSE:
{   This module contains the routine used to merge tape attributes during an open.

?? NEWTITLE := 'Global Declarations', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc bat$static_label_attributes
*copyc fst$file_cycle_attributes
*copyc fst$tape_attachment_information
*copyc ost$positive_integers
*copyc ost$status
?? POP ??
?? TITLE := '[XDCL] bap$merge_tape_attributes', EJECT ??

  PROCEDURE [XDCL] bap$merge_tape_attributes
    (    default_creation_attributes: ^fst$file_cycle_attributes;
         mandated_creation_attributes: ^fst$file_cycle_attributes;
     VAR merged_tape_attributes: {input, output} fst$tape_attachment_information;
     VAR static_label_attributes: {input, output} bat$static_label_attributes);

?? NEWTITLE := 'merge_mandated_creation_attrib', EJECT ??

    PROCEDURE merge_mandated_creation_attrib;

      VAR
        attributes_p: ^fst$file_cycle_attribute,
        index: ost$positive_integers;

      FOR index := 1 TO UPPERBOUND (mandated_creation_attributes^) DO
        attributes_p := ^mandated_creation_attributes^ [index];
        CASE attributes_p^.selector OF
        = fsc$block_type =
          merged_tape_attributes.block_type := attributes_p^.block_type;
          merged_tape_attributes.block_type_source := fsc$tape_open_request;
          static_label_attributes.block_type := attributes_p^.block_type;
          static_label_attributes.block_type_source := amc$open_request;
        = fsc$character_conversion =
          merged_tape_attributes.character_conversion := attributes_p^.character_conversion;
          merged_tape_attributes.character_conversion_source := fsc$tape_open_request;
          static_label_attributes.character_conversion := attributes_p^.character_conversion;
          static_label_attributes.character_conversion_source := amc$open_request;
        = fsc$internal_code =
          merged_tape_attributes.character_set := attributes_p^.internal_code;
          merged_tape_attributes.character_set_source := fsc$tape_open_request;
          static_label_attributes.internal_code := attributes_p^.internal_code;
          static_label_attributes.internal_code_source := amc$open_request;
        = fsc$max_block_length =
          merged_tape_attributes.max_block_length := attributes_p^.max_block_length;
          merged_tape_attributes.max_block_length_source := fsc$tape_open_request;
          static_label_attributes.max_block_length := attributes_p^.max_block_length;
          static_label_attributes.max_block_length_source := amc$open_request;
        = fsc$max_record_length =
          merged_tape_attributes.max_record_length := attributes_p^.max_record_length;
          merged_tape_attributes.max_record_length_source := fsc$tape_open_request;
          static_label_attributes.max_record_length := attributes_p^.max_record_length;
          static_label_attributes.max_record_length_source := amc$open_request;
        = fsc$padding_character =
          merged_tape_attributes.padding_character := attributes_p^.padding_character;
          merged_tape_attributes.padding_character_source := fsc$tape_open_request;
          static_label_attributes.padding_character := attributes_p^.padding_character;
          static_label_attributes.padding_character_source := amc$open_request;
        = fsc$record_type =
          merged_tape_attributes.record_type := attributes_p^.record_type;
          merged_tape_attributes.record_type_source := fsc$tape_open_request;
          static_label_attributes.record_type := attributes_p^.record_type;
          static_label_attributes.record_type_source := amc$open_request;
        ELSE
        CASEND;
      FOREND;

    PROCEND merge_mandated_creation_attrib;

?? TITLE := 'store_tape_attrib_in_static_lbl', EJECT ??

    PROCEDURE store_tape_attrib_in_static_lbl;

      IF (static_label_attributes.block_type_source <> amc$open_request) AND
            ((merged_tape_attributes.block_type_source = fsc$tape_label_attr_command) OR
            (merged_tape_attributes.block_type_source = fsc$tape_open_tape_attachment)) THEN
        static_label_attributes.block_type := merged_tape_attributes.block_type;
        static_label_attributes.block_type_source := amc$open_request;
      IFEND;
      IF (static_label_attributes.character_conversion_source <> amc$open_request) AND
            ((merged_tape_attributes.character_conversion_source = fsc$tape_label_attr_command) OR
            (merged_tape_attributes.character_conversion_source = fsc$tape_open_tape_attachment)) THEN
        static_label_attributes.character_conversion := merged_tape_attributes.character_conversion;
        static_label_attributes.character_conversion_source := amc$open_request;
      IFEND;
      IF (static_label_attributes.internal_code_source <> amc$open_request) AND
            ((merged_tape_attributes.character_set_source = fsc$tape_label_attr_command) OR
            (merged_tape_attributes.character_set_source = fsc$tape_open_tape_attachment)) THEN
        static_label_attributes.internal_code := merged_tape_attributes.character_set;
        static_label_attributes.internal_code_source := amc$open_request;
      IFEND;
      IF (static_label_attributes.max_block_length_source <> amc$open_request) AND
            ((merged_tape_attributes.max_block_length_source = fsc$tape_label_attr_command) OR
            (merged_tape_attributes.max_block_length_source = fsc$tape_open_tape_attachment)) THEN
        static_label_attributes.max_block_length := merged_tape_attributes.max_block_length;
        static_label_attributes.max_block_length_source := amc$open_request;
      IFEND;
      IF (static_label_attributes.max_record_length_source <> amc$open_request) AND
            ((merged_tape_attributes.max_record_length_source = fsc$tape_label_attr_command) OR
            (merged_tape_attributes.max_record_length_source = fsc$tape_open_tape_attachment)) THEN
        static_label_attributes.max_record_length := merged_tape_attributes.max_record_length;
        static_label_attributes.max_record_length_source := amc$open_request;
      IFEND;
      IF (static_label_attributes.padding_character_source <> amc$open_request) AND
            ((merged_tape_attributes.padding_character_source = fsc$tape_label_attr_command) OR
            (merged_tape_attributes.padding_character_source = fsc$tape_open_tape_attachment)) THEN
        static_label_attributes.padding_character := merged_tape_attributes.padding_character;
        static_label_attributes.padding_character_source := amc$open_request;
      IFEND;
      IF (static_label_attributes.record_type_source <> amc$open_request) AND
            ((merged_tape_attributes.record_type_source = fsc$tape_label_attr_command) OR
            (merged_tape_attributes.record_type_source = fsc$tape_open_tape_attachment)) THEN
        static_label_attributes.record_type := merged_tape_attributes.record_type;
        static_label_attributes.record_type_source := amc$open_request;
      IFEND;
    PROCEND store_tape_attrib_in_static_lbl;

?? TITLE := 'store_setfa_in_tape_attributes', EJECT ??

    PROCEDURE store_setfa_in_tape_attributes;

      IF (static_label_attributes.block_type_source = amc$file_command) AND
            (merged_tape_attributes.block_type_source = fsc$tape_label_attr_default) THEN
        merged_tape_attributes.block_type := static_label_attributes.block_type;
        merged_tape_attributes.block_type_source := fsc$tape_file_command;
      IFEND;
      IF (static_label_attributes.character_conversion_source = amc$file_command) AND
            (merged_tape_attributes.character_conversion_source = fsc$tape_label_attr_default) THEN
        merged_tape_attributes.character_conversion := static_label_attributes.character_conversion;
        merged_tape_attributes.character_conversion_source := fsc$tape_file_command;
      IFEND;
      IF (static_label_attributes.internal_code_source = amc$file_command) AND
            (merged_tape_attributes.character_set_source = fsc$tape_label_attr_default) THEN
        merged_tape_attributes.character_set := static_label_attributes.internal_code;
        merged_tape_attributes.character_set_source := fsc$tape_file_command;
      IFEND;
      IF (static_label_attributes.max_block_length_source = amc$file_command) AND
            (merged_tape_attributes.max_block_length_source = fsc$tape_label_attr_default) THEN
        merged_tape_attributes.max_block_length := static_label_attributes.max_block_length;
        merged_tape_attributes.max_block_length_source := fsc$tape_file_command;
      IFEND;
      IF (static_label_attributes.max_record_length_source = amc$file_command) AND
            (merged_tape_attributes.max_record_length_source = fsc$tape_label_attr_default) THEN
        merged_tape_attributes.max_record_length := static_label_attributes.max_record_length;
        merged_tape_attributes.max_record_length_source := fsc$tape_file_command;
      IFEND;
      IF (static_label_attributes.padding_character_source = amc$file_command) AND
            (merged_tape_attributes.padding_character_source = fsc$tape_label_attr_default) THEN
        merged_tape_attributes.padding_character := static_label_attributes.padding_character;
        merged_tape_attributes.padding_character_source := fsc$tape_file_command;
      IFEND;
      IF (static_label_attributes.record_type_source = amc$file_command) AND
            (merged_tape_attributes.record_type_source = fsc$tape_label_attr_default) THEN
        merged_tape_attributes.record_type := static_label_attributes.record_type;
        merged_tape_attributes.record_type_source := fsc$tape_file_command;
      IFEND;
    PROCEND store_setfa_in_tape_attributes;

?? TITLE := 'merge_default_creation_attrib', EJECT ??

    PROCEDURE merge_default_creation_attrib;

      VAR
        attributes_p: ^fst$file_cycle_attribute,
        index: ost$positive_integers;

      FOR index := 1 TO UPPERBOUND (default_creation_attributes^) DO
        attributes_p := ^default_creation_attributes^ [index];
        CASE attributes_p^.selector OF
        = fsc$block_type =
          IF (static_label_attributes.block_type_source = amc$undefined_attribute) OR
                (static_label_attributes.block_type_source > amc$file_command) THEN
            merged_tape_attributes.block_type := attributes_p^.block_type;
            merged_tape_attributes.block_type_source := fsc$tape_open_request;
            static_label_attributes.block_type := attributes_p^.block_type;
            static_label_attributes.block_type_source := amc$open_request;
          IFEND;
        = fsc$character_conversion =
          IF (static_label_attributes.character_conversion_source = amc$undefined_attribute) OR
                (static_label_attributes.character_conversion_source > amc$file_command) THEN
            merged_tape_attributes.character_conversion := attributes_p^.character_conversion;
            merged_tape_attributes.character_conversion_source := fsc$tape_open_request;
            static_label_attributes.character_conversion := attributes_p^.character_conversion;
            static_label_attributes.character_conversion_source := amc$open_request;
          IFEND;
        = fsc$internal_code =
          IF (static_label_attributes.internal_code_source = amc$undefined_attribute) OR
                (static_label_attributes.internal_code_source > amc$file_command) THEN
            merged_tape_attributes.character_set := attributes_p^.internal_code;
            merged_tape_attributes.character_set_source := fsc$tape_open_request;
            static_label_attributes.internal_code := attributes_p^.internal_code;
            static_label_attributes.internal_code_source := amc$open_request;
          IFEND;
        = fsc$max_block_length =
          IF (static_label_attributes.max_block_length_source = amc$undefined_attribute) OR
                (static_label_attributes.max_block_length_source > amc$file_command) THEN
            merged_tape_attributes.max_block_length := attributes_p^.max_block_length;
            merged_tape_attributes.max_block_length_source := fsc$tape_open_request;
            static_label_attributes.max_block_length := attributes_p^.max_block_length;
            static_label_attributes.max_block_length_source := amc$open_request;
          IFEND;
        = fsc$max_record_length =
          IF (static_label_attributes.max_record_length_source = amc$undefined_attribute) OR
                (static_label_attributes.max_record_length_source > amc$file_command) THEN
            merged_tape_attributes.max_record_length := attributes_p^.max_record_length;
            merged_tape_attributes.max_record_length_source := fsc$tape_open_request;
            static_label_attributes.max_record_length := attributes_p^.max_record_length;
            static_label_attributes.max_record_length_source := amc$open_request;
          IFEND;
        = fsc$padding_character =
          IF (static_label_attributes.padding_character_source = amc$undefined_attribute) OR
                (static_label_attributes.padding_character_source > amc$file_command) THEN
            merged_tape_attributes.padding_character := attributes_p^.padding_character;
            merged_tape_attributes.padding_character_source := fsc$tape_open_request;
            static_label_attributes.padding_character := attributes_p^.padding_character;
            static_label_attributes.padding_character_source := amc$open_request;
          IFEND;
        = fsc$record_type =
          IF (static_label_attributes.record_type_source = amc$undefined_attribute) OR
                (static_label_attributes.record_type_source > amc$file_command) THEN
            merged_tape_attributes.record_type := attributes_p^.record_type;
            merged_tape_attributes.record_type_source := fsc$tape_open_request;
            static_label_attributes.record_type := attributes_p^.record_type;
            static_label_attributes.record_type_source := amc$open_request;
          IFEND;
        ELSE
        CASEND;
      FOREND;

    PROCEND merge_default_creation_attrib;

?? TITLE := 'default_tape_attr_to_static_lbl', EJECT ??

    PROCEDURE default_tape_attr_to_static_lbl;

      IF merged_tape_attributes.block_type_source = fsc$tape_label_attr_default THEN
        merged_tape_attributes.block_type := static_label_attributes.block_type;
      IFEND;
      IF merged_tape_attributes.character_conversion_source = fsc$tape_label_attr_default THEN
        merged_tape_attributes.character_conversion := static_label_attributes.character_conversion;
      IFEND;
      IF merged_tape_attributes.character_set_source = fsc$tape_label_attr_default THEN
        merged_tape_attributes.character_set := static_label_attributes.internal_code;
      IFEND;
      IF merged_tape_attributes.max_block_length_source = fsc$tape_label_attr_default THEN
        merged_tape_attributes.max_block_length := static_label_attributes.max_block_length;
      IFEND;
      IF merged_tape_attributes.max_record_length_source = fsc$tape_label_attr_default THEN
        merged_tape_attributes.max_record_length := static_label_attributes.max_record_length;
      IFEND;
      IF merged_tape_attributes.padding_character_source = fsc$tape_label_attr_default THEN
        merged_tape_attributes.padding_character := static_label_attributes.padding_character;
      IFEND;
      IF merged_tape_attributes.record_type_source = fsc$tape_label_attr_default THEN
        merged_tape_attributes.record_type := static_label_attributes.record_type;
      IFEND;

    PROCEND default_tape_attr_to_static_lbl;
?? OLDTITLE, EJECT ??

    IF mandated_creation_attributes <> NIL THEN
      merge_mandated_creation_attrib;
    IFEND;

    store_tape_attrib_in_static_lbl;
    store_setfa_in_tape_attributes;

    IF default_creation_attributes <> NIL THEN
      merge_default_creation_attrib;
    IFEND;

    default_tape_attr_to_static_lbl;

  PROCEND bap$merge_tape_attributes;
MODEND bam$merge_tape_attributes;
