?? RIGHT := 110 ??
*copyc osd$default_pragmats
MODULE ram$isolate_isam_differences;
?? PUSH (LISTEXT := ON) ??
*copyc clt$path_name
*copyc rat$correction_package
*copyc rat$write_scl_commands
*copyc amp$close
*copyc amp$get_segment_pointer
*copyc amp$open
*copyc amp$put_next
*copyc amp$return
*copyc clp$scan_command_line
*copyc pmp$get_unique_name
*copyc rap$line_length

?? POP ??

*copyc rah$isolate_isam_differences

  PROCEDURE [XDCL] rap$isolate_isam_differences (old_file: clt$path_name;
        new_file: clt$path_name;
    VAR corrector: ^SEQ ( * );
    VAR size: rat$corrector_size;
    VAR status: ost$status);

    CONST
      number_of_commands = 11;

    VAR
      access_sel: amt$file_access_selections,
      ba: amt$file_byte_address,
      command: array [1 .. number_of_commands] of rat$write_scl_commands,
      command_fid: amt$file_identifier,
      command_file: ost$name,
      correction: ^SEQ ( * ),
      i: 1 .. number_of_commands + 1,
      ignore_status: ost$status,
      length: integer,
      new_length: integer,
      old_length: integer,
      temp_correction_fid: amt$file_identifier,
      temp_correction_file: ost$name,
      temp_correction: amt$segment_pointer,
      text: string (osc$max_string_size);



    status.normal := TRUE;

    pmp$get_unique_name (temp_correction_file, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    pmp$get_unique_name (command_file, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    amp$open (command_file, amc$record, NIL, command_fid, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    old_length := rap$line_length (old_file);
    new_length := rap$line_length (new_file);

    STRINGREP (command [1].command, command [1].size,
      ' IF $variable(compare_status, declared) <> ''LOCAL'' THEN');
    STRINGREP (command [2].command, command [2].size, '   create_variable compare_status k=status');
    STRINGREP (command [3].command, command [3].size, ' IFEND');
    STRINGREP (command [4].command, command [4].size, ' old_file = ''', old_file (1, old_length), '''');
    STRINGREP (command [5].command, command [5].size, ' new_file = ''', new_file (1, new_length), '''');
    STRINGREP (command [6].command, command [6].size, ' compare_file f=$fname(old_file)',
      ' w=$fname(new_file) o=$null status=compare_status');
    STRINGREP (command [7].command, command [7].size, ' IF NOT compare_status.normal THEN');
    STRINGREP (command [8].command, command [8].size, '   backup_permanent_file bf=', temp_correction_file,
          ' l=$null');
    STRINGREP (command [9].command, command [9].size, '   backup_file f=$fname(new_file)');
    STRINGREP (command [10].command, command [10].size, '   quit');
    STRINGREP (command [11].command, command [11].size, ' IFEND');

    FOR i := 1 TO number_of_commands DO
      amp$put_next (command_fid, ^command [i].command, command [i].size, ba, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
    FOREND;

    amp$close (command_fid, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    STRINGREP (text, length, ' include_file f=', command_file);
    clp$scan_command_line (text (1, length), status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    amp$return (command_file, ignore_status);

    PUSH access_sel: [1 .. 2];
    access_sel^ [1].key := amc$access_mode;
    access_sel^ [1].access_mode := $pft$usage_selections [pfc$read];
    access_sel^ [2].key := amc$return_option;
    access_sel^ [2].return_option := amc$return_at_close;

    amp$open (temp_correction_file, amc$segment, access_sel, temp_correction_fid, status);
    IF NOT status.normal THEN
      IF status.condition = ame$new_file_requires_append THEN
        { No correction generated files compared. }
        size := 0;
        status.normal := TRUE;
      IFEND;
      RETURN;
    IFEND;

    amp$get_segment_pointer (temp_correction_fid, amc$sequence_pointer, temp_correction, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    size := #SIZE (temp_correction.sequence_pointer^);

    IF size <> 0 THEN
      RESET temp_correction.sequence_pointer;
      RESET corrector;
      NEXT correction: [[REP size OF cell]] IN corrector;
      correction^ := temp_correction.sequence_pointer^;
    IFEND;

    amp$close (temp_correction_fid, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

  PROCEND rap$isolate_isam_differences;
MODEND ram$isolate_isam_differences;
