?? RIGHT := 110 ??
MODULE ram$insert_or_replace_corrector;
*copyc osd$default_pragmats
?? PUSH (LISTEXT := ON) ??
*copyc rav$elements
*copyc rav$corp
*copyc rav$correction_package_header
*copyc rat$element_descriptor
*copyc osd$virtual_address
*copyc amt$access_level
*copyc amt$attribute_source
*copyc amt$average_record_length
*copyc amt$block_type
*copyc amt$collate_table
*copyc amt$collation_value
*copyc amt$data_padding
*copyc amt$error_exit_procedure
*copyc amt$error_limit
*copyc amt$estimated_record_count
*copyc amt$file_access_selections
*copyc amt$file_attribute_keys
*copyc amt$file_attributes
*copyc amt$file_byte_address
*copyc amt$file_identifier
*copyc amt$file_length
*copyc amt$file_limit
*copyc amt$file_organization
*copyc amt$file_position
*copyc amt$forced_write
*copyc amt$global_file_position
*copyc amt$index_padding
*copyc amt$internal_code
*copyc amt$key_length
*copyc amt$key_position
*copyc amt$key_type
*copyc amt$label_exit_procedure
*copyc amt$label_options
*copyc amt$label_type
*copyc amt$local_file_name
*copyc amc$mau_length
*copyc amt$max_block_length
*copyc amt$max_record_length
*copyc amt$message_control
*copyc amt$min_block_length
*copyc amt$min_record_length
*copyc amt$padding_character
*copyc amt$record_limit
*copyc amt$record_type
*copyc amt$records_per_block
*copyc amt$return_option
*copyc amt$user_info
*copyc amt$vertical_print_density
*copyc ost$status
*copyc oct$corrector
*copyc rat$correction_package
*copyc i#move
?? POP ??

*copyc rah$insert_or_replace_corrector

  PROCEDURE [XDCL] rap$insert_or_replace_corrector (element: rat$element_descriptor;
        corrector: ^SEQ ( * );
        size: oct$corrector_size;
        user_info: amt$user_info);

    VAR
      temp: integer,
      correction: ^SEQ ( * ),
      found: boolean,
      hi: rat$element_index,
      i: rat$element_index,
      low: rat$element_index,
      mid: rat$element_index;

    hi := rav$correction_package_header^.number_of_elements;
    found := FALSE;
    low := 1;
    WHILE (low <= hi) AND NOT found DO
      temp := low + hi;
      mid := temp DIV 2;
      IF element.name = rav$elements^ [mid].name THEN
        found := TRUE;
      ELSEIF element.name < rav$elements^ [mid].name THEN
        hi := mid - 1;
      ELSE
        low := mid + 1;
      IFEND;
    WHILEND;
    IF found THEN
      NEXT correction: [[REP size OF cell]] IN rav$corp.sequence_pointer;
      rav$elements^ [mid].size := size;
      rav$elements^ [mid].user_info := user_info;
      rav$elements^ [mid].format := element.format;
      rav$elements^ [mid].class := element.class;
      rav$elements^ [mid].correction_package := #REL (correction, rav$corp.sequence_pointer^);
      rav$elements^ [mid].number_of_psrs := 0;
    ELSE
      i := rav$correction_package_header^.number_of_elements;
      WHILE (i >= 1) AND NOT found DO
        IF element.name < rav$elements^ [i].name THEN
          rav$elements^ [i + 1] := rav$elements^ [i];
          i := i - 1;
        ELSE
          found := TRUE;
        IFEND;
      WHILEND;
      NEXT correction: [[REP size OF cell]] IN rav$corp.sequence_pointer;
      rav$elements^ [i + 1].name := element.name;
      rav$elements^ [i + 1].size := size;
      rav$elements^ [i + 1].user_info := user_info;
      rav$elements^ [i + 1].number_of_psrs := 0;
      rav$elements^ [i + 1].format := element.format;
      rav$elements^ [i + 1].class := element.class;
      rav$elements^ [i + 1].correction_package := #REL (correction, rav$corp.sequence_pointer^);
      rav$correction_package_header^.number_of_elements := rav$correction_package_header^.number_of_elements +
            1;
    IFEND;
    i#move (corrector, correction, size);
  PROCEND rap$insert_or_replace_corrector;
MODEND ram$insert_or_replace_corrector;
