
  PROCEDURE {[INLINE]} bai$skip_to_next_ansi_rcw;

?? RIGHT := 110 ??

    VAR
      binary_length: clt$integer,
      os_status: ost$error;

    CONST
      ebcdic_zero = $CHAR (0F0(16));

  /find_header/
    WHILE TRUE DO
      manually_advance_to_next_block := FALSE;

      IF rhl <= block_info^.residual_block_length THEN
        next_record_header_p := ^tape_descriptor^.get_tape_block_buffer^
              [block_info^.current_block_byte_address + 1];

{ If the record header was recorded in EBCDIC and character conversion is requested,
{ convert the record header to ASCII.  This code assumes that any value greater
{ than or equal to EBCDIC zero indicates an EBCDIC representation for the control word.

        IF (state_info^.character_set = amc$ebcdic) AND state_info^.character_conversion AND
              (next_record_header_p^.length (1, 1) >= ebcdic_zero) THEN
          osp$translate_bytes (#LOC (next_record_header_p^), rhl, #LOC (next_record_header_p^),
                rhl, ^osv$ebcdic_to_ascii, os_status);
        IFEND;

        IF next_record_header_p^.length = bac$ansi_block_padding_chars THEN
          residual_data_length := 0;
          block_info^.current_block_byte_address := block_info^.current_block_byte_address +
                block_info^.residual_block_length;
          block_info^.residual_block_length := block_info^.residual_block_length -
                block_info^.residual_block_length;
          CYCLE /find_header/; {----->

        ELSE
          clp$convert_string_to_integer (next_record_header_p^.length, binary_length, status);
          IF NOT status.normal THEN
            manually_advance_to_next_block := TRUE;
            no_header_read := TRUE;
            amp$set_file_instance_abnormal (file_identifier, ame$improper_record_header, call_block.operation,
                  ' ', status);
            EXIT /find_header/; {----->
          IFEND;

          IF (binary_length.value <= UPPERVALUE (bat$rcw_length_value_range)) AND
                (binary_length.value >= LOWERVALUE (bat$rcw_length_value_range)) AND
                (binary_length.value <= block_info^.residual_block_length) THEN

            last_record_header_p := next_record_header_p;
            residual_data_length := binary_length.value - rhl;
            block_info^.current_block_byte_address := block_info^.current_block_byte_address + rhl;
            block_info^.residual_block_length := block_info^.residual_block_length - rhl;
            EXIT /find_header/; {----->

          ELSE
            manually_advance_to_next_block := TRUE;
            no_header_read := TRUE;
            amp$set_file_instance_abnormal (file_identifier, ame$improper_record_header, call_block.operation,
                  ' ', status);
            EXIT /find_header/; {----->

          IFEND;
        IFEND;

      ELSE
        get_data (file_identifier, operation, #LOC (rh), rhl, FALSE, {start_new_block=} TRUE,
              {convert_if_ebcdic =} FALSE, status);

{ If the record header was recorded in EBCDIC and character conversion is requested,
{ convert the record header to ASCII.  This code assumes that any value greater
{ than or equal to EBCDIC zero indicates an EBCDIC representation for the control word.

        IF (state_info^.character_set = amc$ebcdic) AND state_info^.character_conversion AND
              (rh.length (1, 1) >= ebcdic_zero) THEN
          osp$translate_bytes (#LOC (rh), rhl, #LOC (rh), rhl, ^osv$ebcdic_to_ascii, os_status);
        IFEND;

        IF NOT status.normal THEN
          manually_advance_to_next_block := TRUE;
          no_header_read := TRUE;
          EXIT /find_header/; {----->
        IFEND;

        IF gfi^.positioning_info.record_info.transfer_count < rhl THEN
          residual_data_length := 0;
          IF (tape_descriptor^.volume_position = amc$eov) OR
                (tape_descriptor^.volume_position = amc$after_tapemark) THEN
            no_header_read := TRUE;
          ELSE
            { ! ERROR IN BLOCK
            manually_advance_to_next_block := TRUE;
            no_header_read := TRUE;
            amp$set_file_instance_abnormal (file_identifier, ame$improper_record_header, call_block.operation,
                  ' ', status);
          IFEND;
          EXIT /find_header/; {----->
        IFEND;

        IF rh.length = bac$ansi_block_padding_chars THEN
          residual_data_length := 0;
          block_info^.current_block_byte_address := block_info^.current_block_byte_address +
                block_info^.residual_block_length;
          block_info^.residual_block_length := block_info^.residual_block_length -
                block_info^.residual_block_length;
          CYCLE /find_header/; {----->

        ELSE
          clp$convert_string_to_integer (rh.length, binary_length, status);
          IF NOT status.normal THEN
            manually_advance_to_next_block := TRUE;
            no_header_read := TRUE;
            amp$set_file_instance_abnormal (file_identifier, ame$improper_record_header, call_block.operation,
                  ' ', status);
            EXIT /find_header/; {----->
          IFEND;

          IF (binary_length.value <= UPPERVALUE (bat$rcw_length_value_range)) AND
                (binary_length.value >= LOWERVALUE (bat$rcw_length_value_range)) AND
                (binary_length.value - rhl <= block_info^.residual_block_length) THEN

            last_record_header_p := ^tape_descriptor^.get_tape_block_buffer^
                  [block_info^.current_block_byte_address + 1 - rhl];
            residual_data_length := binary_length.value - rhl;
            EXIT /find_header/; {----->

          ELSE
            manually_advance_to_next_block := TRUE;
            no_header_read := TRUE;
            amp$set_file_instance_abnormal (file_identifier, ame$improper_record_header, call_block.operation,
                  ' ', status);
            EXIT /find_header/; {----->
          IFEND;
        IFEND;
      IFEND;

    WHILEND /find_header/;

    gfi^.positioning_info.record_info.transfer_count := 0;

    IF manually_advance_to_next_block THEN
      residual_data_length := 0;
      block_info^.current_block_byte_address := block_info^.current_block_byte_address +
            block_info^.residual_block_length;
      block_info^.residual_block_length := block_info^.residual_block_length -
            block_info^.residual_block_length;
      gfi^.positioning_info.record_info.file_position := amc$mid_record;
    IFEND;

  PROCEND bai$skip_to_next_ansi_rcw;
