!**************************************** PROCEDURE EVE_EXCHANGE (CHANGE_PARAMETER_1, CHANGE_PARAMETER_2) !eve$arg1_exchange := "string"; !eve$arg2_exchange := "string"; ! ! Wildcard search and change procedure. Case-sensitivity of search is ! same as for the wildcard search routine. If case-insensitive, replacements ! are done to match case of current occurrence. Parameter 1 is wildcard ! for searching; parameter 2 is normal (not wildcard). ! ! Parameters: ! ! change_parameter_1 Old string - input ! change_parameter_2 New string - input local target, ! Local copy of change_parameter_1 replacement, ! Local copy of change_parameter_2 this_buffer, ! Current buffer this_mode, ! Keyword for current mode lowercase_target, ! Lowercase version of target string lowercase_replacement, ! Lowercase version of replacement string uppercase_target, ! Uppercase version of target string uppercase_replacement, ! Uppercase version of replacement string capital_target, ! Capitalized version of target string capital_replacement, ! Capitalized version of replacement string how_exact, ! Keyword to indicate case-sensitivity replace_range, ! Range of current occurrence highlight_range, ! Reverse-video version of replace_range replace_action, ! String reply to prompt action_length, ! Length of replace_action asking, ! True unless "all" option has been chosen this_occurrence, ! String of replace_range occurrences; ! Number of replacements made so far this_buffer := current_buffer; this_mode := get_info (current_buffer, "mode"); set (insert, this_buffer); asking := 1; if not (eve$prompt_string (change_parameter_1, target, "(Wildcard Search) Old string: ", "No string to replace")) then return; endif; replacement := change_parameter_2; if replacement = "" then ! empty string is ok here replacement := read_line ("New string: "); endif; lowercase_target := target; if get_info (lowercase_target, "type") = string then change_case (lowercase_target, lower); endif; lowercase_replacement := replacement; change_case (lowercase_replacement, lower); if (lowercase_target = target) and (lowercase_replacement = replacement) then how_exact := no_exact; uppercase_target := target; if get_info (uppercase_target, "type") = string then change_case (uppercase_target, upper); endif; capital_target := target; if get_info (capital_target, "type") = string then eve$capitalize_string (capital_target); endif; uppercase_replacement := replacement; change_case (uppercase_replacement, upper); capital_replacement := replacement; eve$capitalize_string (capital_replacement); else how_exact := exact; endif; loop replace_range := eve_search (target); exitif replace_range = 0; highlight_range := create_range (beginning_of (replace_range), end_of (replace_range), eve$x_highlighting); position (beginning_of (replace_range)); update (current_window); loop if asking then replace_action := read_line ("Replace? Type yes, no, all, last, or quit: "); change_case (replace_action, lower); else replace_action := "yes"; endif; action_length := length (replace_action); if (replace_action = substr ("yes", 1, action_length)) or (replace_action = substr ("all", 1, action_length)) or (replace_action = substr ("last", 1, action_length)) or (action_length = 0) then highlight_range := 0; this_occurrence := erase_character (length (replace_range)); if how_exact = exact then copy_text (replacement); else ! Make sure non-alphabetic target is replaced by lowercase if this_occurrence = lowercase_target then copy_text (lowercase_replacement); else if this_occurrence = uppercase_target then copy_text (uppercase_replacement); else if this_occurrence = capital_target then copy_text (capital_replacement); else copy_text (lowercase_replacement); endif; endif; endif; endif; if current_direction = reverse then move_horizontal (- length (replacement)); endif; occurrences := occurrences + 1; update (current_window); if (replace_action = substr ("all", 1, action_length)) and (action_length > 0) then asking := 0; message ("Replacing all occurrences..."); set (screen_update, off); endif; exitif 1; else if (replace_action = substr ("no", 1, action_length)) or (replace_action = substr ("quit", 1, action_length)) then highlight_range := 0; if current_direction = forward then position (end_of (replace_range)); move_horizontal (1); endif; update (current_window); exitif 1; endif; endif; endloop; exitif (action_length > 0) and ((replace_action = substr ("quit", 1, action_length)) or (replace_action = substr ("last", 1, action_length))); endloop; set (screen_update, on); message (fao ("Replaced !SL occurrence!%S", occurrences)); set (this_mode, this_buffer); ENDPROCEDURE;