?? RIGHT := 110 ??
MODULE ocm$apply_corrector;
*copyc osd$default_pragmats
?? PUSH (LISTEXT := ON) ??
*copyc occ$corrector
*copyc oct$corrector
*copyc oct$fill_sequence
?? POP ??

*copyc och$apply_corrector

  PROCEDURE [XDCL] ocp$apply_corrector
    (    p_corrector: ^SEQ ( * );
         p_int_ol: ^SEQ ( * );
     VAR result: ^SEQ ( * ));

    VAR
      byte_address: 0 .. 0ffffffff(16),
      corrector: ^SEQ ( * ),
      corrector_header: ^oct$corrector_header,
      corrector_header_v1_0: ^oct$corrector_header_v1_0,
      corrector_item: ^oct$corrector_item,
      delete_fill: ^oct$fill_sequence,
      i: oct$number_of_correctors,
      insert_fill: ^oct$fill_sequence,
      int_ol: ^SEQ ( * ),
      new_bytes: ^oct$new_bytes,
      new_fill: ^oct$fill_sequence,
      old_fill: ^oct$fill_sequence;

    corrector := p_corrector;
    int_ol := p_int_ol;

    RESET int_ol;
    RESET corrector;
    NEXT corrector_header IN corrector;

{ If the corrector header version is not the "current" version, convert it
{ to a local copy of the new version.

    IF (corrector_header = NIL) OR (corrector_header^.version <> occ$corrector_header_version) THEN
      RESET corrector;
      NEXT corrector_header_v1_0 IN corrector;
      PUSH corrector_header;
      corrector_header^.number_of_correctors := corrector_header_v1_0^.number_of_correctors;
      corrector_header^.size := corrector_header_v1_0^.size;
    IFEND;

    FOR i := 1 TO corrector_header^.number_of_correctors DO
      NEXT corrector_item IN corrector;

      IF corrector_item^.bytes_ok > 0 THEN
        NEXT old_fill: [1 .. corrector_item^.bytes_ok] IN int_ol;
        NEXT new_fill: [1 .. corrector_item^.bytes_ok] IN result;
        new_fill^ := old_fill^;
        byte_address := #OFFSET (new_fill);
      ELSE
        byte_address := 0;
      IFEND;

      IF corrector_item^.bytes_to_delete > 0 THEN
        NEXT delete_fill: [1 .. corrector_item^.bytes_to_delete] IN int_ol;
      IFEND;

      IF corrector_item^.bytes_to_insert > 0 THEN
        NEXT new_bytes: [1 .. corrector_item^.bytes_to_insert] IN corrector;
        NEXT insert_fill: [1 .. corrector_item^.bytes_to_insert] IN result;
        insert_fill^ := new_bytes^;
      IFEND;
    FOREND;
  PROCEND ocp$apply_corrector;
MODEND ocm$apply_corrector;
