?? RIGHT := 110 ??
MODULE ram$copy_partition;

*copyc osd$default_pragmats
?? PUSH (LISTEXT := ON) ??
*copyc amp$get_next
*copyc amp$put_next
*copyc amp$write_end_partition
*copyc rat$170_record_definitions

?? POP ??

*copyc rah$copy_partition

  PROCEDURE [XDCL, #GATE] rap$copy_partition (input_fid: amt$file_identifier;
        output_fid: amt$file_identifier;
    VAR file_position: amt$file_position;
        starting_input_record: boolean;
        starting_output_record: boolean;
    VAR status: ost$status);


    VAR
      ba: amt$file_byte_address,
      partition_descriptor: [STATIC] integer := rac$eor_170,
      tc: amt$transfer_count,
      temp_rec: rat$record_170;


    IF NOT starting_output_record THEN
      { This is not the 1st record on the output file. }
      amp$write_end_partition (output_fid, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
      IF starting_input_record THEN
        { A partition descriptor must be added. }
        amp$put_next (output_fid, ^partition_descriptor, #SIZE (partition_descriptor), ba, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
      IFEND;

    ELSEIF NOT starting_input_record THEN
      { Since this is the 1st record on the output file the partition descriptor must be removed. }
      amp$get_next (input_fid, ^temp_rec.buffer, #SIZE (temp_rec.buffer), tc, ba, file_position, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
    IFEND;

{ Continue copying record to output file. }

    IF (file_position <> amc$eop) AND (file_position <> amc$eoi) THEN
      amp$get_next (input_fid, ^temp_rec.buffer, #SIZE (temp_rec.buffer), tc, ba, file_position, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
    IFEND;

    WHILE (file_position <> amc$eop) AND (file_position <> amc$eoi) DO

      amp$put_next (output_fid, ^temp_rec.buffer, tc, ba, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;

      amp$get_next (input_fid, ^temp_rec.buffer, #SIZE (temp_rec.buffer), tc, ba, file_position, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;

    WHILEND;

  PROCEND rap$copy_partition;
MODEND ram$copy_partition
