annotate src/search.c @ 112364:42e22c4f06b7

Move all DEFVAR'd globals into a structure -- threading infrastructure * globals.h: New file. * xterm.h (Vx_pixel_size_width_font_regexp): Remove declaration. * window.h (Vinitial_window_system, Vminibuf_scroll_window) (Vwindow_system_version): Remove declaration. * w32term.h (Vw32_enable_palette) (Vx_pixel_size_width_font_regexp): Remove declaration. * w32menu.c (Voverriding_local_map) (Voverriding_local_map_menu_flag): Remove declaration. * w32inevt.c (Vw32_alt_is_meta, Vw32_apps_modifier) (Vw32_capslock_is_shiftlock, Vw32_enable_caps_lock) (Vw32_enable_num_lock, Vw32_lwindow_modifier) (Vw32_pass_lwindow_to_system, Vw32_pass_rwindow_to_system) (Vw32_phantom_key_code, Vw32_recognize_altgr) (Vw32_rwindow_modifier, Vw32_scroll_lock_modifier) (w32_use_full_screen_buffer): Remove declaration. * w32.c (Vsystem_configuration, Vw32_downcase_file_names) (Vw32_generate_fake_inodes, Vw32_get_true_file_attributes) (w32_num_mouse_buttons, w32_pipe_read_delay): Remove declaration. * termopts.h (Vtruncate_partial_width_windows, inverse_video) (no_redraw_on_reenter, visible_bell): Remove declaration. * sysdep.c (Vsystem_name): Remove declaration. * syntax.h (parse_sexp_lookup_properties): Remove declaration. * menu.h (Vmenu_updating_frame): Remove declaration. * macros.h (Vexecuting_kbd_macro, executing_kbd_macro_index): Remove declaration. * lisp.h (Vafter_init_time, Vafter_load_alist) (Vauto_save_list_file_name, Vbefore_init_time, Vcommand_history) (Vcompletion_regexp_list, Vcurrent_load_list) (Vcurrent_prefix_arg, Vdata_directory, Vdebug_on_error) (Vdoc_directory, Vdoc_file_name, Vdynamic_library_alist) (Vexec_directory, Vexec_path, Vexec_suffixes) (Vface_font_rescale_alist, Vface_ignored_fonts, Vfeatures) (Vhelp_form, Vhistory_length, Vinhibit_field_text_motion) (Vinhibit_quit, Vinhibit_read_only, Vinhibit_redisplay) (Vinstallation_directory, Vinvocation_directory) (Vinvocation_name, Vload_file_rep_suffixes, Vload_history) (Vload_suffixes, Vmark_even_if_inactive, Vmemory_full) (Vmessage_log_max, Vobarray, Vprint_length, Vprint_level) (Vpurify_flag, Vquit_flag, Vsaved_region_selection) (Vscalable_fonts_allowed, Vselect_active_regions) (Vshell_file_name, Vstandard_input, Vstandard_output) (Vsystem_name, Vtemporary_file_directory, Vthrow_on_input) (Vtop_level, Vtty_erase_char, Vundo_outer_limit) (Vuser_login_name, Vwindow_scroll_functions) (Vwindow_system_version, Vx_no_window_manager) (Vx_resource_class, Vx_resource_name, baud_rate) (completion_ignore_case, debug_on_next_call, gc_cons_threshold) (history_delete_duplicates, inhibit_x_resources) (last_nonmenu_event, load_in_progress, max_specpdl_size) (minibuffer_auto_raise, print_escape_newlines, scroll_margin) (use_dialog_box, use_file_dialog): Remove declaration. Include globals.h. * keymap.h (Voverriding_local_map) (Voverriding_local_map_menu_flag, meta_prefix_char): Remove declaration. * keyboard.h (Vdouble_click_time, Vfunction_key_map) (Vinput_method_function, Vkey_translation_map) (Vlucid_menu_bar_dirty_flag, Vthis_original_command) (do_mouse_tracking, extra_keyboard_modifiers) (num_nonmacro_input_events): Remove declaration. * intervals.h (Vchar_property_alias_alist) (Vdefault_text_properties, Vinhibit_point_motion_hooks) (Vtext_property_default_nonsticky): Remove declaration. * gtkutil.h (x_gtk_file_dialog_help_text) (x_gtk_show_hidden_files, x_gtk_use_old_file_dialog) (x_gtk_whole_detached_tool_bar): Remove declaration. * frame.h (Vdefault_frame_alist, Vframe_alpha_lower_limit) (Vmenu_bar_mode, Vmouse_highlight, Vterminal_frame) (Vtool_bar_mode, Vx_resource_class, Vx_resource_name) (focus_follows_mouse): Remove declaration. * fontset.h (Valternate_fontname_alist, Vfontset_alias_alist) (Vignore_relative_composition, Votf_script_alist) (Vuse_default_ascent, Vvertical_centering_font_regexp): Remove declaration. * font.h (Vfont_log): Remove declaration. * dosfns.h (Vdos_display_scancodes, Vdos_version) (Vdos_windows_version, dos_codepage, dos_country_code) (dos_decimal_point, dos_hyper_key, dos_keyboard_layout) (dos_keypad_mode, dos_super_key, dos_timezone_offset): Remove declaration. * disptab.h (Vglyph_table, Vstandard_display_table): Remove declaration. * dispextern.h (Vface_remapping_alist, Vglyphless_char_display) (Vmouse_autoselect_window, Voverflow_newline_into_fringe) (Vshow_trailing_whitespace, Vtool_bar_button_margin) (Vtool_bar_style, cursor_in_echo_area, display_hourglass_p) (inverse_video, mode_line_in_non_selected_windows) (tool_bar_button_relief, tool_bar_max_label_size) (underline_minimum_offset) (unibyte_display_via_language_environment, x_stretch_cursor_p): Remove declaration. * composite.h (Vauto_composition_function) (Vcomposition_function_table): Remove declaration. * commands.h (Vexecuting_kbd_macro) (Vminibuffer_local_completion_map) (Vminibuffer_local_filename_completion_map) (Vminibuffer_local_filename_must_match_map) (Vminibuffer_local_map, Vminibuffer_local_must_match_map) (Vminibuffer_local_ns_map, Vthis_command) (Vunread_command_events, cursor_in_echo_area) (last_command_event, last_nonmenu_event, unread_command_char): Remove declaration. * coding.h (Vcoding_system_for_read, Vcoding_system_for_write) (Vdefault_file_name_coding_system) (Vdefault_process_coding_system, Vfile_name_coding_system) (Vlast_coding_system_used, Vlocale_coding_system) (Vselect_safe_coding_system_function) (Vtranslation_table_for_input, coding_system_require_warning) (eol_mnemonic_dos, eol_mnemonic_mac, eol_mnemonic_undecided) (eol_mnemonic_unix, inherit_process_coding_system): Remove declaration. * charset.h (Vcharset_list, Vcurrent_iso639_language): Remove declaration. * character.h (Vauto_fill_chars, Vchar_direction_table) (Vchar_script_table, Vchar_width_table, Vprintable_chars) (Vscript_representative_chars, Vtranslation_table_vector) (Vunicode_category_table): Remove declaration. * ccl.h (Vfont_ccl_encoder_alist): Remove declaration. * buffer.h (Vafter_change_functions, Vbefore_change_functions) (Vdeactivate_mark, Vfirst_change_hook, Vtransient_mark_mode) (inhibit_modification_hooks): Remove declaration. * xterm.c (syms_of_xterm): Update. (Vx_alt_keysym, Vx_hyper_keysym, Vx_keysym_table) (Vx_meta_keysym, Vx_super_keysym, Vx_toolkit_scroll_bars) (x_mouse_click_focus_ignore_position) (x_underline_at_descent_line) (x_use_underline_position_properties): Remove. * xsmfns.c (syms_of_xsmfns): Update. (Vx_session_id, Vx_session_previous_id): Remove. * xsettings.c (syms_of_xsettings): Update. (Vxft_settings, use_system_font): Remove. * xselect.c (syms_of_xselect): Update. (Vselection_converter_alist, Vx_lost_selection_functions) (Vx_sent_selection_functions, x_selection_timeout): Remove. * xfns.c (syms_of_xfns): Update. (Vgtk_version_string, Vmotif_version_string) (Vx_cursor_fore_pixel, Vx_hourglass_pointer_shape) (Vx_max_tooltip_size, Vx_mode_pointer_shape) (Vx_no_window_manager, Vx_nontext_pointer_shape) (Vx_pixel_size_width_font_regexp, Vx_pointer_shape) (Vx_sensitive_text_pointer_shape) (Vx_window_horizontal_drag_shape, x_gtk_file_dialog_help_text) (x_gtk_show_hidden_files, x_gtk_use_old_file_dialog) (x_gtk_use_system_tooltips, x_gtk_whole_detached_tool_bar): Remove. * xfaces.c (syms_of_xfaces): Update. (Vface_default_stipple, Vface_font_rescale_alist) (Vface_ignored_fonts, Vface_new_frame_defaults) (Vface_remapping_alist, Vfont_list_limit) (Vscalable_fonts_allowed, Vtty_defined_color_alist): Remove. * xdisp.c (syms_of_xdisp): Update. (Vauto_resize_tool_bars, Vblink_cursor_alist) (Vdisplay_pixels_per_inch, Vfontification_functions) (Vframe_title_format, Vglobal_mode_string) (Vglyphless_char_display, Vhourglass_delay, Vhscroll_step) (Vicon_title_format, Vinhibit_redisplay) (Vline_number_display_limit, Vline_prefix) (Vmax_mini_window_height, Vmenu_bar_update_hook) (Vmenu_updating_frame, Vmessage_log_max) (Vmouse_autoselect_window, Vnobreak_char_display) (Voverlay_arrow_position, Voverlay_arrow_string) (Voverlay_arrow_variable_list, Vredisplay_end_trigger_functions) (Vresize_mini_windows, Vshow_trailing_whitespace) (Vtool_bar_border, Vtool_bar_button_margin, Vtool_bar_style) (Vtruncate_partial_width_windows, Vvoid_text_area_pointer) (Vwindow_scroll_functions, Vwindow_size_change_functions) (Vwindow_text_change_functions, Vwrap_prefix) (auto_raise_tool_bar_buttons_p, automatic_hscrolling_p) (debug_end_pos, display_hourglass_p, emacs_scroll_step) (highlight_nonselected_windows, hscroll_margin) (inhibit_eval_during_redisplay, inhibit_free_realized_faces) (inhibit_menubar_update, inhibit_try_cursor_movement) (inhibit_try_window_id, inhibit_try_window_reusing) (line_number_display_limit_width) (make_cursor_line_fully_visible_p, message_truncate_lines) (mode_line_inverse_video, multiple_frames, overline_margin) (scroll_conservatively, scroll_margin, tool_bar_button_relief) (tool_bar_max_label_size, underline_minimum_offset) (unibyte_display_via_language_environment, x_stretch_cursor_p): Remove. * window.c (syms_of_window): Update. (Vminibuf_scroll_window, Vother_window_scroll_buffer) (Vrecenter_redisplay, Vscroll_preserve_screen_position) (Vtemp_buffer_show_function, Vwindow_configuration_change_hook) (Vwindow_point_insertion_type, auto_window_vscroll_p) (mode_line_in_non_selected_windows, next_screen_context_lines) (window_min_height, window_min_width): Remove. (scroll_margin): Remove declaration. * w32term.c (syms_of_w32term): Update. (Vw32_capslock_is_shiftlock, Vw32_grab_focus_on_raise) (Vw32_recognize_altgr, Vw32_swap_mouse_buttons) (Vx_toolkit_scroll_bars, w32_num_mouse_buttons) (w32_use_visible_system_caret, x_underline_at_descent_line) (x_use_underline_position_properties): Remove. (Vcommand_line_args, Vsystem_name, extra_keyboard_modifiers): Remove declaration. * w32select.c (syms_of_w32select): Update. (Vnext_selection_coding_system, Vselection_coding_system): Remove. * w32proc.c (syms_of_ntproc): Update. (Vw32_downcase_file_names, Vw32_generate_fake_inodes) (Vw32_get_true_file_attributes, Vw32_quote_process_args) (Vw32_start_process_inherit_error_mode) (Vw32_start_process_share_console) (Vw32_start_process_show_window, w32_pipe_read_delay): Remove. (Vsystem_name): Remove declaration. * w32font.c (syms_of_w32font): Update. (Vw32_charset_info_alist): Remove. * w32fns.c (globals_of_w32fns, syms_of_w32fns): Update. (Vw32_alt_is_meta, Vw32_apps_modifier, Vw32_bdf_filename_alist) (Vw32_color_map, Vw32_enable_caps_lock, Vw32_enable_num_lock) (Vw32_enable_palette, Vw32_lwindow_modifier) (Vw32_pass_alt_to_system, Vw32_pass_lwindow_to_system) (Vw32_pass_rwindow_to_system, Vw32_phantom_key_code) (Vw32_rwindow_modifier, Vw32_scroll_lock_modifier) (Vx_cursor_fore_pixel, Vx_hourglass_pointer_shape) (Vx_max_tooltip_size, Vx_mode_pointer_shape) (Vx_no_window_manager, Vx_nontext_pointer_shape) (Vx_pixel_size_width_font_regexp, Vx_pointer_shape) (Vx_sensitive_text_pointer_shape) (Vx_window_horizontal_drag_shape, w32_ansi_code_page) (w32_enable_synthesized_fonts, w32_mouse_button_tolerance) (w32_mouse_move_interval) (w32_pass_extra_mouse_buttons_to_system) (w32_pass_multimedia_buttons_to_system, w32_quit_key) (w32_strict_fontnames, w32_strict_painting): Remove. (Vhourglass_delay, Vmenu_bar_mode, Vtool_bar_mode) (Vw32_recognize_altgr, Vwindow_system_version) (w32_num_mouse_buttons, w32_use_visible_system_caret): Remove declaration. * w32console.c (syms_of_ntterm): Update. (w32_use_full_screen_buffer): Remove. (Vtty_defined_color_alist): Remove declaration. * w16select.c (syms_of_win16select): Update. (Vnext_selection_coding_system, Vselection_coding_system): Remove. * undo.c (syms_of_undo): Update. (Vundo_outer_limit, Vundo_outer_limit_function) (undo_inhibit_record_point, undo_limit, undo_strong_limit): Remove. * textprop.c (syms_of_textprop): Update. (Vchar_property_alias_alist, Vdefault_text_properties) (Vinhibit_point_motion_hooks, Vtext_property_default_nonsticky): Remove. * terminal.c (syms_of_terminal): Update. (Vdelete_terminal_functions, Vring_bell_function): Remove. * term.c (syms_of_term): Update. (Vresume_tty_functions, Vsuspend_tty_functions) (no_redraw_on_reenter, system_uses_terminfo, visible_cursor): Remove. * syntax.c (syms_of_syntax): Update. (Vfind_word_boundary_function_table, multibyte_syntax_as_symbol) (open_paren_in_column_0_is_defun_start) (parse_sexp_ignore_comments, parse_sexp_lookup_properties) (words_include_escapes): Remove. * search.c (syms_of_search): Update. (Vinhibit_changing_match_data, Vsearch_spaces_regexp): Remove. * process.c (syms_of_process): Update. (Vprocess_adaptive_read_buffering, Vprocess_connection_type) (delete_exited_processes): Remove. * print.c (syms_of_print): Update. (Vfloat_output_format, Vprint_charset_text_property) (Vprint_circle, Vprint_continuous_numbering, Vprint_gensym) (Vprint_length, Vprint_level, Vprint_number_table) (Vstandard_output, print_escape_multibyte) (print_escape_newlines, print_escape_nonascii, print_quoted): Remove. * msdos.c (syms_of_msdos): Update. (Vdos_unsupported_char_glyph): Remove. (unibyte_display_via_language_environment): Remove declaration. * minibuf.c (syms_of_minibuf): Update. (Vcompletion_regexp_list, Vhistory_add_new_input) (Vhistory_length, Vminibuffer_completing_file_name) (Vminibuffer_completion_confirm) (Vminibuffer_completion_predicate, Vminibuffer_completion_table) (Vminibuffer_exit_hook, Vminibuffer_help_form) (Vminibuffer_history_position, Vminibuffer_history_variable) (Vminibuffer_prompt_properties, Vminibuffer_setup_hook) (Vread_buffer_function, Vread_expression_map) (completion_ignore_case, enable_recursive_minibuffers) (history_delete_duplicates, minibuffer_allow_text_properties) (minibuffer_auto_raise, read_buffer_completion_ignore_case): Remove. * marker.c (syms_of_marker): Update. (byte_debug_flag): Remove. * macros.c (syms_of_macros): Update. (Vexecuting_kbd_macro, executing_kbd_macro_index): Remove. * lread.c (syms_of_lread): Update. (Vafter_load_alist, Vbyte_boolean_vars) (Vbytecomp_version_regexp, Vcurrent_load_list) (Veval_buffer_list, Vload_file_name, Vload_file_rep_suffixes) (Vload_history, Vload_path, Vload_read_function) (Vload_source_file_function, Vload_suffixes, Vobarray) (Vold_style_backquotes, Vpreloaded_file_list, Vread_circle) (Vread_symbol_positions_list, Vread_with_symbol_positions) (Vsource_directory, Vstandard_input, Vuser_init_file, Vvalues) (force_load_messages, load_convert_to_unibyte) (load_dangerous_libraries, load_force_doc_strings) (load_in_progress): Remove. * keymap.c (syms_of_keymap): Update. (Vdefine_key_rebound_commands, Vemulation_mode_map_alists) (Vminibuffer_local_completion_map) (Vminibuffer_local_filename_completion_map) (Vminibuffer_local_filename_must_match_map) (Vminibuffer_local_map, Vminibuffer_local_must_match_map) (Vminibuffer_local_ns_map, Vminor_mode_map_alist) (Vminor_mode_overriding_map_alist, Vwhere_is_preferred_modifier): Remove. * keyboard.c (syms_of_keyboard): Update. (Vauto_save_timeout, Vcommand_error_function) (Vcommand_hook_internal, Vdeactivate_mark) (Vdeferred_action_function, Vdeferred_action_list) (Vdisable_point_adjustment, Vdouble_click_time) (Vecho_keystrokes, Venable_disabled_menus_and_buttons) (Vfunction_key_map, Vglobal_disable_point_adjustment) (Vhelp_char, Vhelp_event_list, Vhelp_form) (Vinput_method_function, Vinput_method_previous_message) (Vkey_translation_map, Vlast_event_frame) (Vlucid_menu_bar_dirty_flag, Vmenu_bar_final_items) (Vminibuffer_message_timeout, Voverriding_local_map) (Voverriding_local_map_menu_flag, Vpost_command_hook) (Vpre_command_hook, Vprefix_help_command) (Vsaved_region_selection, Vselect_active_regions) (Vshow_help_function, Vspecial_event_map, Vsuggest_key_bindings) (Vthis_command, Vthis_command_keys_shift_translated) (Vthis_original_command, Vthrow_on_input, Vtimer_idle_list) (Vtimer_list, Vtool_bar_separator_image_expression, Vtop_level) (Vtty_erase_char, Vunread_command_events) (Vunread_input_method_events, Vunread_post_input_method_events) (auto_save_interval, cannot_suspend, do_mouse_tracking) (double_click_fuzz, extra_keyboard_modifiers) (inhibit_local_menu_bar_menus, last_command_event) (last_input_event, last_nonmenu_event, menu_prompt_more_char) (menu_prompting, meta_prefix_char, num_input_keys) (num_nonmacro_input_events, polling_period, unread_command_char): Remove. * insdel.c (syms_of_insdel): Update. (Vcombine_after_change_calls, check_markers_debug_flag): Remove. * indent.c (syms_of_indent): Update. (indent_tabs_mode): Remove. * image.c (syms_of_image): Update. (Vimage_cache_eviction_delay, Vimage_types) (Vimagemagick_render_type, Vmax_image_size, Vx_bitmap_file_path) (cross_disabled_images): Remove. * fringe.c (syms_of_fringe): Update. (Vfringe_bitmaps, Voverflow_newline_into_fringe): Remove. * frame.c (syms_of_frame): Update. (Vdefault_frame_alist, Vdefault_frame_scroll_bars) (Vdelete_frame_functions, Vframe_alpha_lower_limit) (Vmake_pointer_invisible, Vmenu_bar_mode, Vmouse_highlight) (Vmouse_position_function, Vterminal_frame, Vtool_bar_mode) (Vx_resource_class, Vx_resource_name, focus_follows_mouse): Remove. * fontset.c (syms_of_fontset): Update. (Valternate_fontname_alist, Vfont_encoding_charset_alist) (Vfontset_alias_alist, Vignore_relative_composition) (Votf_script_alist, Vuse_default_ascent) (Vvertical_centering_font_regexp): Remove. * font.c (syms_of_font): Update. (Vfont_encoding_alist, Vfont_log, Vfont_slant_table) (Vfont_weight_table, Vfont_width_table): Remove. * fns.c (syms_of_fns): Update. (Vfeatures, use_dialog_box, use_file_dialog): Remove. * filelock.c (syms_of_filelock): Update. (Vtemporary_file_directory): Remove. * fileio.c (syms_of_fileio): Update. (Vafter_insert_file_functions, Vauto_save_include_big_deletions) (Vauto_save_list_file_name, Vauto_save_visited_file_name) (Vdefault_file_name_coding_system, Vfile_name_coding_system) (Vfile_name_handler_alist, Vinhibit_file_name_handlers) (Vinhibit_file_name_operation, Vset_auto_coding_function) (Vwrite_region_annotate_functions) (Vwrite_region_annotations_so_far) (Vwrite_region_post_annotation_function) (delete_by_moving_to_trash, write_region_inhibit_fsync): Remove. (Vw32_get_true_file_attributes): Remove declaration. * eval.c (syms_of_eval): Update. (Vdebug_ignored_errors, Vdebug_on_error, Vdebug_on_signal) (Vdebugger, Vinhibit_quit, Vmacro_declaration_function) (Vquit_flag, Vsignal_hook_function, Vstack_trace_on_error) (debug_on_next_call, debug_on_quit, debugger_may_continue) (max_lisp_eval_depth, max_specpdl_size): Remove. * emacs.c (syms_of_emacs): Update. (Vafter_init_time, Vbefore_init_time, Vcommand_line_args) (Vdynamic_library_alist, Vemacs_copyright, Vemacs_version) (Vinstallation_directory, Vinvocation_directory) (Vinvocation_name, Vkill_emacs_hook, Vpath_separator) (Vprevious_system_messages_locale, Vprevious_system_time_locale) (Vsystem_configuration, Vsystem_configuration_options) (Vsystem_messages_locale, Vsystem_time_locale, Vsystem_type) (inhibit_x_resources, noninteractive1): Remove. * editfns.c (syms_of_editfns): Update. (Vbuffer_access_fontified_property) (Vbuffer_access_fontify_functions, Vinhibit_field_text_motion) (Voperating_system_release, Vsystem_name, Vuser_full_name) (Vuser_login_name, Vuser_real_login_name): Remove. * dosfns.c (syms_of_dosfns): Update. (Vdos_display_scancodes, Vdos_version, Vdos_windows_version) (dos_codepage, dos_country_code, dos_decimal_point) (dos_hyper_key, dos_keyboard_layout, dos_keypad_mode) (dos_super_key, dos_timezone_offset): Remove. * doc.c (syms_of_doc): Update. (Vbuild_files, Vdoc_file_name): Remove. * dispnew.c (syms_of_display): Update. (Vglyph_table, Vinitial_window_system) (Vredisplay_preemption_period, Vstandard_display_table) (Vwindow_system_version, baud_rate, cursor_in_echo_area) (inverse_video, redisplay_dont_pause, visible_bell): Remove. * dired.c (syms_of_dired): Update. (Vcompletion_ignored_extensions): Remove. (Vw32_get_true_file_attributes): Remove declaration. * dbusbind.c (syms_of_dbusbind): Update. (Vdbus_debug, Vdbus_registered_buses) (Vdbus_registered_objects_table): Remove. * data.c (syms_of_data): Update. (Vmost_negative_fixnum, Vmost_positive_fixnum): Remove. * composite.c (syms_of_composite): Update. (Vauto_composition_function, Vauto_composition_mode) (Vcompose_chars_after_function, Vcomposition_function_table): Remove. * coding.c (syms_of_coding): Update. (Vcharset_revision_table, Vcoding_category_list) (Vcoding_system_alist, Vcoding_system_for_read) (Vcoding_system_for_write, Vcoding_system_list) (Vdefault_process_coding_system, Venable_character_translation) (Vfile_coding_system_alist, Vlast_code_conversion_error) (Vlast_coding_system_used, Vlatin_extra_code_table) (Vlocale_coding_system, Vnetwork_coding_system_alist) (Vprocess_coding_system_alist) (Vselect_safe_coding_system_function) (Vstandard_translation_table_for_decode) (Vstandard_translation_table_for_encode) (Vtranslation_table_for_input, coding_system_require_warning) (eol_mnemonic_dos, eol_mnemonic_mac, eol_mnemonic_undecided) (eol_mnemonic_unix, inherit_process_coding_system) (inhibit_eol_conversion, inhibit_iso_escape_detection) (inhibit_null_byte_detection): Remove. * cmds.c (syms_of_cmds): Update. (Vpost_self_insert_hook): Remove. * charset.c (syms_of_charset): Update. (Vcharset_list, Vcharset_map_path, Vcurrent_iso639_language) (inhibit_load_charset_map): Remove. * character.c (syms_of_character): Update. (Vauto_fill_chars, Vchar_direction_table, Vchar_script_table) (Vchar_width_table, Vprintable_chars) (Vscript_representative_chars, Vtranslation_table_vector) (Vunicode_category_table): Remove. * ccl.c (syms_of_ccl): Update. (Vcode_conversion_map_vector, Vfont_ccl_encoder_alist) (Vtranslation_hash_table_vector): Remove. * category.c (syms_of_category): Update. (Vword_combining_categories, Vword_separating_categories): Remove. * callproc.c (syms_of_callproc): Update. (Vconfigure_info_directory, Vdata_directory, Vdoc_directory) (Vexec_directory, Vexec_path, Vexec_suffixes) (Vinitial_environment, Vprocess_environment) (Vshared_game_score_directory, Vshell_file_name): Remove. * callint.c (syms_of_callint): Update. (Vcommand_debug_status, Vcommand_history, Vcurrent_prefix_arg) (Vmark_even_if_inactive, Vmouse_leave_buffer_hook): Remove. * bytecode.c (syms_of_bytecode): Update. (Vbyte_code_meter, byte_metering_on): Remove. * buffer.c (syms_of_buffer): Update. (Vafter_change_functions, Vbefore_change_functions) (Vchange_major_mode_hook, Vfirst_change_hook) (Vinhibit_read_only, Vkill_buffer_query_functions) (Vtransient_mark_mode, inhibit_modification_hooks): Remove. * alloc.c (syms_of_alloc): Update. (Vgc_cons_percentage, Vgc_elapsed, Vmemory_full) (Vmemory_signal_data, Vpost_gc_hook, Vpurify_flag) (cons_cells_consed, floats_consed, garbage_collection_messages) (gc_cons_threshold, gcs_done, intervals_consed) (misc_objects_consed, pure_bytes_used, string_chars_consed) (strings_consed, symbols_consed, vector_cells_consed): Remove. * lisp.h (DEFVAR_LISP, DEFVAR_LISP_NOPRO, DEFVAR_BOOL) (DEFVAR_INT): Assume global is in `globals'. * alloc.c (globals): Define.
author Tom Tromey <tromey@redhat.com>
date Tue, 18 Jan 2011 13:45:37 -0700
parents ef719132ddfa
children 9de5a68b57e1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* String search routines for GNU Emacs.
75227
e90d04cd455a Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents: 74917
diff changeset
2 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1997, 1998, 1999, 2001, 2002,
112218
376148b31b5e Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents: 108933
diff changeset
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
79759
fc2bcd2a8aad Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 79443
diff changeset
4 Free Software Foundation, Inc.
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 This file is part of GNU Emacs.
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7
94963
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93758
diff changeset
8 GNU Emacs is free software: you can redistribute it and/or modify
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
94963
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93758
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93758
diff changeset
11 (at your option) any later version.
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 GNU Emacs is distributed in the hope that it will be useful,
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 GNU General Public License for more details.
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
94963
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93758
diff changeset
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 4635
diff changeset
22 #include <config.h>
105669
68dd71358159 * alloc.c: Do not define struct catchtag.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 105661
diff changeset
23 #include <setjmp.h>
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 #include "lisp.h"
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 #include "syntax.h"
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
26 #include "category.h"
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 #include "buffer.h"
88388
e9a23b7c1feb Include "character.h" instead of "charset.h".
Kenichi Handa <handa@m17n.org>
parents: 41389
diff changeset
28 #include "character.h"
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
29 #include "charset.h"
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
30 #include "region-cache.h"
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 #include "commands.h"
2439
b6c62e4abf59 Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents: 2393
diff changeset
32 #include "blockinput.h"
20347
d8e5f3c1618b Include "intervals.h" for prototypes.
Andreas Schwab <schwab@suse.de>
parents: 19541
diff changeset
33 #include "intervals.h"
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
34
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 #include <sys/types.h>
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 #include "regex.h"
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37
16275
a4bcfdc9bb66 (REGEXP_CACHE_SIZE): Increase to 20.
Richard M. Stallman <rms@gnu.org>
parents: 16152
diff changeset
38 #define REGEXP_CACHE_SIZE 20
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
40 /* If the regexp is non-nil, then the buffer contains the compiled form
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
41 of that regexp, suitable for searching. */
16275
a4bcfdc9bb66 (REGEXP_CACHE_SIZE): Increase to 20.
Richard M. Stallman <rms@gnu.org>
parents: 16152
diff changeset
42 struct regexp_cache
a4bcfdc9bb66 (REGEXP_CACHE_SIZE): Increase to 20.
Richard M. Stallman <rms@gnu.org>
parents: 16152
diff changeset
43 {
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
44 struct regexp_cache *next;
58330
5be8a633ec57 (struct regexp_cache): New element whitespace_regexp.
Richard M. Stallman <rms@gnu.org>
parents: 58326
diff changeset
45 Lisp_Object regexp, whitespace_regexp;
73002
b3a72607819d * search.c (struct regexp_cache): New entry syntax_table.
Chong Yidong <cyd@stupidchicken.com>
parents: 72945
diff changeset
46 /* Syntax table for which the regexp applies. We need this because
73230
20801e603746 (compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73096
diff changeset
47 of character classes. If this is t, then the compiled pattern is valid
20801e603746 (compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73096
diff changeset
48 for any syntax-table. */
73002
b3a72607819d * search.c (struct regexp_cache): New entry syntax_table.
Chong Yidong <cyd@stupidchicken.com>
parents: 72945
diff changeset
49 Lisp_Object syntax_table;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
50 struct re_pattern_buffer buf;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
51 char fastmap[0400];
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
52 /* Nonzero means regexp was compiled to do full POSIX backtracking. */
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
53 char posix;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
54 };
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
56 /* The instances of that struct. */
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
57 struct regexp_cache searchbufs[REGEXP_CACHE_SIZE];
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
59 /* The head of the linked list; points to the most recently used buffer. */
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
60 struct regexp_cache *searchbuf_head;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
61
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
63 /* Every call to re_match, etc., must pass &search_regs as the regs
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
64 argument unless you can show it is unnecessary (i.e., if re_match
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
65 is certainly going to be called again before region-around-match
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
66 can be called).
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
67
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
68 Since the registers are now dynamically allocated, we need to make
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
69 sure not to refer to the Nth register before checking that it has
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
70 been allocated by checking search_regs.num_regs.
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
72 The regex code keeps track of whether it has allocated the search
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
73 buffer using bits in the re_pattern_buffer. This means that whenever
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
74 you compile a new pattern, it completely forgets whether it has
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
75 allocated any registers, and will allocate new registers the next
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
76 time you call a searching or matching function. Therefore, we need
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
77 to call re_set_registers after compiling a new pattern or after
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
78 setting the match registers, so that the regex functions will be
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
79 able to free or re-allocate it properly. */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 static struct re_registers search_regs;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
82 /* The buffer in which the last search was performed, or
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
83 Qt if the last search was done in a string;
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
84 Qnil if no searching has been done yet. */
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
85 static Lisp_Object last_thing_searched;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86
14036
621a575db6f7 Comment fixes.
Karl Heuer <kwzh@gnu.org>
parents: 13295
diff changeset
87 /* error condition signaled when regexp compile_pattern fails */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 Lisp_Object Qinvalid_regexp;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90
71987
6dd00de34fff (compile_pattern_1): Use xsignal1.
Kim F. Storm <storm@cua.dk>
parents: 71841
diff changeset
91 /* Error condition used for failing searches */
6dd00de34fff (compile_pattern_1): Use xsignal1.
Kim F. Storm <storm@cua.dk>
parents: 71841
diff changeset
92 Lisp_Object Qsearch_failed;
6dd00de34fff (compile_pattern_1): Use xsignal1.
Kim F. Storm <storm@cua.dk>
parents: 71841
diff changeset
93
109100
2bc9a0c04c87 Remove __P and P_ from .c and .m files and definition of P_
Jan D <jan.h.d@swipnet.se>
parents: 108933
diff changeset
94 static void set_search_regs (EMACS_INT, EMACS_INT);
2bc9a0c04c87 Remove __P and P_ from .c and .m files and definition of P_
Jan D <jan.h.d@swipnet.se>
parents: 108933
diff changeset
95 static void save_search_regs (void);
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
96 static EMACS_INT simple_search (EMACS_INT, unsigned char *, EMACS_INT,
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
97 EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT,
109100
2bc9a0c04c87 Remove __P and P_ from .c and .m files and definition of P_
Jan D <jan.h.d@swipnet.se>
parents: 108933
diff changeset
98 EMACS_INT, EMACS_INT);
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
99 static EMACS_INT boyer_moore (EMACS_INT, unsigned char *, EMACS_INT, EMACS_INT,
109100
2bc9a0c04c87 Remove __P and P_ from .c and .m files and definition of P_
Jan D <jan.h.d@swipnet.se>
parents: 108933
diff changeset
100 Lisp_Object, Lisp_Object,
2bc9a0c04c87 Remove __P and P_ from .c and .m files and definition of P_
Jan D <jan.h.d@swipnet.se>
parents: 108933
diff changeset
101 EMACS_INT, EMACS_INT,
2bc9a0c04c87 Remove __P and P_ from .c and .m files and definition of P_
Jan D <jan.h.d@swipnet.se>
parents: 108933
diff changeset
102 EMACS_INT, EMACS_INT, int);
2bc9a0c04c87 Remove __P and P_ from .c and .m files and definition of P_
Jan D <jan.h.d@swipnet.se>
parents: 108933
diff changeset
103 static EMACS_INT search_buffer (Lisp_Object, EMACS_INT, EMACS_INT,
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
104 EMACS_INT, EMACS_INT, EMACS_INT, int,
109100
2bc9a0c04c87 Remove __P and P_ from .c and .m files and definition of P_
Jan D <jan.h.d@swipnet.se>
parents: 108933
diff changeset
105 Lisp_Object, Lisp_Object, int);
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
106 static void matcher_overflow (void) NO_RETURN;
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
107
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 static void
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
109 matcher_overflow (void)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 error ("Stack overflow in regexp matcher");
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
114 /* Compile a regexp and signal a Lisp error if anything goes wrong.
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
115 PATTERN is the pattern to compile.
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
116 CP is the place to put the result.
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
117 TRANSLATE is a translation table for ignoring case, or nil for none.
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
118 REGP is the structure that says where to store the "register"
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
119 values that will result from matching this pattern.
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
120 If it is 0, we should compile the pattern not to record any
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
121 subexpression bounds.
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
122 POSIX is nonzero if we want full backtracking (POSIX style)
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
123 for this pattern. 0 means backtrack only enough to get a valid match.
58330
5be8a633ec57 (struct regexp_cache): New element whitespace_regexp.
Richard M. Stallman <rms@gnu.org>
parents: 58326
diff changeset
124
58348
623ffd21f0ff (Vsearch_spaces_regexp):
Richard M. Stallman <rms@gnu.org>
parents: 58330
diff changeset
125 The behavior also depends on Vsearch_spaces_regexp. */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
127 static void
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
128 compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, Lisp_Object translate, struct re_registers *regp, int posix)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 {
18762
12c0de0113af (compile_pattern_1): Don't declare val with CONST.
Richard M. Stallman <rms@gnu.org>
parents: 18193
diff changeset
130 char *val;
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
131 reg_syntax_t old;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
133 cp->regexp = Qnil;
21531
5811a3129878 (compile_pattern, compile_pattern_1): Fix mixing of
Andreas Schwab <schwab@suse.de>
parents: 21514
diff changeset
134 cp->buf.translate = (! NILP (translate) ? translate : make_number (0));
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
135 cp->posix = posix;
89062
be059fb97bac (compile_pattern_1): Don't adjust the multibyteness of
Kenichi Handa <handa@m17n.org>
parents: 89028
diff changeset
136 cp->buf.multibyte = STRING_MULTIBYTE (pattern);
90760
656ca684d326 Include "charset.h".
Kenichi Handa <handa@m17n.org>
parents: 90737
diff changeset
137 cp->buf.charset_unibyte = charset_unibyte;
93758
abcbb8375c30 (compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents: 91762
diff changeset
138 if (STRINGP (Vsearch_spaces_regexp))
abcbb8375c30 (compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents: 91762
diff changeset
139 cp->whitespace_regexp = Vsearch_spaces_regexp;
abcbb8375c30 (compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents: 91762
diff changeset
140 else
abcbb8375c30 (compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents: 91762
diff changeset
141 cp->whitespace_regexp = Qnil;
abcbb8375c30 (compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents: 91762
diff changeset
142
73096
2f768f0aab61 (compile_pattern_1): Don't BLOCK_INPUT.
Richard M. Stallman <rms@gnu.org>
parents: 73002
diff changeset
143 /* rms: I think BLOCK_INPUT is not needed here any more,
2f768f0aab61 (compile_pattern_1): Don't BLOCK_INPUT.
Richard M. Stallman <rms@gnu.org>
parents: 73002
diff changeset
144 because regex.c defines malloc to call xmalloc.
2f768f0aab61 (compile_pattern_1): Don't BLOCK_INPUT.
Richard M. Stallman <rms@gnu.org>
parents: 73002
diff changeset
145 Using BLOCK_INPUT here means the debugger won't run if an error occurs.
2f768f0aab61 (compile_pattern_1): Don't BLOCK_INPUT.
Richard M. Stallman <rms@gnu.org>
parents: 73002
diff changeset
146 So let's turn it off. */
2f768f0aab61 (compile_pattern_1): Don't BLOCK_INPUT.
Richard M. Stallman <rms@gnu.org>
parents: 73002
diff changeset
147 /* BLOCK_INPUT; */
27692
bb0e45f6ca86 * regex.h (RE_SYNTAX_EMACS): Add RE_CHAR_CLASSES and RE_INTERVALS
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27592
diff changeset
148 old = re_set_syntax (RE_SYNTAX_EMACS
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
149 | (posix ? 0 : RE_NO_POSIX_BACKTRACKING));
93758
abcbb8375c30 (compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents: 91762
diff changeset
150
abcbb8375c30 (compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents: 91762
diff changeset
151 if (STRINGP (Vsearch_spaces_regexp))
abcbb8375c30 (compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents: 91762
diff changeset
152 re_set_whitespace_regexp (SDATA (Vsearch_spaces_regexp));
abcbb8375c30 (compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents: 91762
diff changeset
153 else
abcbb8375c30 (compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents: 91762
diff changeset
154 re_set_whitespace_regexp (NULL);
58326
0cc0d3274d68 (Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 57735
diff changeset
155
89483
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
156 val = (char *) re_compile_pattern ((char *) SDATA (pattern),
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
157 SBYTES (pattern), &cp->buf);
58326
0cc0d3274d68 (Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 57735
diff changeset
158
73230
20801e603746 (compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73096
diff changeset
159 /* If the compiled pattern hard codes some of the contents of the
20801e603746 (compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73096
diff changeset
160 syntax-table, it can only be reused with *this* syntax table. */
20801e603746 (compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73096
diff changeset
161 cp->syntax_table = cp->buf.used_syntax ? current_buffer->syntax_table : Qt;
20801e603746 (compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73096
diff changeset
162
58326
0cc0d3274d68 (Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 57735
diff changeset
163 re_set_whitespace_regexp (NULL);
0cc0d3274d68 (Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 57735
diff changeset
164
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
165 re_set_syntax (old);
73096
2f768f0aab61 (compile_pattern_1): Don't BLOCK_INPUT.
Richard M. Stallman <rms@gnu.org>
parents: 73002
diff changeset
166 /* UNBLOCK_INPUT; */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 if (val)
71987
6dd00de34fff (compile_pattern_1): Use xsignal1.
Kim F. Storm <storm@cua.dk>
parents: 71841
diff changeset
168 xsignal1 (Qinvalid_regexp, build_string (val));
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
169
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
170 cp->regexp = Fcopy_sequence (pattern);
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
171 }
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
172
22221
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
173 /* Shrink each compiled regexp buffer in the cache
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
174 to the size actually used right now.
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
175 This is called from garbage collection. */
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
176
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
177 void
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
178 shrink_regexp_cache (void)
22221
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
179 {
34966
23a62cf7d0eb (shrink_regexp_cache): Remove unused variable `cpp'.
Eli Zaretskii <eliz@gnu.org>
parents: 33052
diff changeset
180 struct regexp_cache *cp;
22221
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
181
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
182 for (cp = searchbuf_head; cp != 0; cp = cp->next)
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
183 {
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
184 cp->buf.allocated = cp->buf.used;
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
185 cp->buf.buffer
51544
a0c2b39160e9 (shrink_regexp_cache): Use xrealloc.
Dave Love <fx@gnu.org>
parents: 49761
diff changeset
186 = (unsigned char *) xrealloc (cp->buf.buffer, cp->buf.used);
22221
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
187 }
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
188 }
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
189
73232
5f8a28d018b2 (compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73230
diff changeset
190 /* Clear the regexp cache w.r.t. a particular syntax table,
5f8a28d018b2 (compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73230
diff changeset
191 because it was changed.
72945
d4ecc69b8d2e * search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents: 72725
diff changeset
192 There is no danger of memory leak here because re_compile_pattern
d4ecc69b8d2e * search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents: 72725
diff changeset
193 automagically manages the memory in each re_pattern_buffer struct,
d4ecc69b8d2e * search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents: 72725
diff changeset
194 based on its `allocated' and `buffer' values. */
d4ecc69b8d2e * search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents: 72725
diff changeset
195 void
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
196 clear_regexp_cache (void)
72945
d4ecc69b8d2e * search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents: 72725
diff changeset
197 {
d4ecc69b8d2e * search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents: 72725
diff changeset
198 int i;
d4ecc69b8d2e * search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents: 72725
diff changeset
199
d4ecc69b8d2e * search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents: 72725
diff changeset
200 for (i = 0; i < REGEXP_CACHE_SIZE; ++i)
105400
ba465c0bd0c3 (clear_regexp_cache): Fix a typo in a comment.
Eli Zaretskii <eliz@gnu.org>
parents: 105399
diff changeset
201 /* It's tempting to compare with the syntax-table we've actually changed,
105401
791bb3c2ca7d (clear_regexp_cache): Fix a typo in a comment.
Eli Zaretskii <eliz@gnu.org>
parents: 105400
diff changeset
202 but it's not sufficient because char-table inheritance means that
73232
5f8a28d018b2 (compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73230
diff changeset
203 modifying one syntax-table can change others at the same time. */
5f8a28d018b2 (compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73230
diff changeset
204 if (!EQ (searchbufs[i].syntax_table, Qt))
5f8a28d018b2 (compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73230
diff changeset
205 searchbufs[i].regexp = Qnil;
72945
d4ecc69b8d2e * search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents: 72725
diff changeset
206 }
d4ecc69b8d2e * search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents: 72725
diff changeset
207
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
208 /* Compile a regexp if necessary, but first check to see if there's one in
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
209 the cache.
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
210 PATTERN is the pattern to compile.
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
211 TRANSLATE is a translation table for ignoring case, or nil for none.
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
212 REGP is the structure that says where to store the "register"
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
213 values that will result from matching this pattern.
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
214 If it is 0, we should compile the pattern not to record any
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
215 subexpression bounds.
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
216 POSIX is nonzero if we want full backtracking (POSIX style)
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
217 for this pattern. 0 means backtrack only enough to get a valid match. */
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
218
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
219 struct re_pattern_buffer *
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
220 compile_pattern (Lisp_Object pattern, struct re_registers *regp, Lisp_Object translate, int posix, int multibyte)
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
221 {
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
222 struct regexp_cache *cp, **cpp;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
223
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
224 for (cpp = &searchbuf_head; ; cpp = &cp->next)
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
225 {
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
226 cp = *cpp;
27592
5cd59d1800ad * search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents: 26985
diff changeset
227 /* Entries are initialized to nil, and may be set to nil by
5cd59d1800ad * search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents: 26985
diff changeset
228 compile_pattern_1 if the pattern isn't valid. Don't apply
46444
c7158c721fef comment update
Ken Raeburn <raeburn@raeburn.org>
parents: 46432
diff changeset
229 string accessors in those cases. However, compile_pattern_1
c7158c721fef comment update
Ken Raeburn <raeburn@raeburn.org>
parents: 46432
diff changeset
230 is only applied to the cache entry we pick here to reuse. So
c7158c721fef comment update
Ken Raeburn <raeburn@raeburn.org>
parents: 46432
diff changeset
231 nil should never appear before a non-nil entry. */
28507
b6f06a755c7d make_number/XINT/XUINT conversions; EQ/== fixes; ==Qnil -> NILP
Ken Raeburn <raeburn@raeburn.org>
parents: 28387
diff changeset
232 if (NILP (cp->regexp))
27592
5cd59d1800ad * search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents: 26985
diff changeset
233 goto compile_it;
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
234 if (SCHARS (cp->regexp) == SCHARS (pattern)
31486
a3dc5f987e8f (compile_pattern): Check the multibyteness of cached
Kenichi Handa <handa@m17n.org>
parents: 29335
diff changeset
235 && STRING_MULTIBYTE (cp->regexp) == STRING_MULTIBYTE (pattern)
16275
a4bcfdc9bb66 (REGEXP_CACHE_SIZE): Increase to 20.
Richard M. Stallman <rms@gnu.org>
parents: 16152
diff changeset
236 && !NILP (Fstring_equal (cp->regexp, pattern))
21531
5811a3129878 (compile_pattern, compile_pattern_1): Fix mixing of
Andreas Schwab <schwab@suse.de>
parents: 21514
diff changeset
237 && EQ (cp->buf.translate, (! NILP (translate) ? translate : make_number (0)))
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
238 && cp->posix == posix
73230
20801e603746 (compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73096
diff changeset
239 && (EQ (cp->syntax_table, Qt)
20801e603746 (compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73096
diff changeset
240 || EQ (cp->syntax_table, current_buffer->syntax_table))
90760
656ca684d326 Include "charset.h".
Kenichi Handa <handa@m17n.org>
parents: 90737
diff changeset
241 && !NILP (Fequal (cp->whitespace_regexp, Vsearch_spaces_regexp))
656ca684d326 Include "charset.h".
Kenichi Handa <handa@m17n.org>
parents: 90737
diff changeset
242 && cp->buf.charset_unibyte == charset_unibyte)
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
243 break;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
244
27592
5cd59d1800ad * search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents: 26985
diff changeset
245 /* If we're at the end of the cache, compile into the nil cell
5cd59d1800ad * search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents: 26985
diff changeset
246 we found, or the last (least recently used) cell with a
5cd59d1800ad * search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents: 26985
diff changeset
247 string value. */
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
248 if (cp->next == 0)
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
249 {
27592
5cd59d1800ad * search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents: 26985
diff changeset
250 compile_it:
90760
656ca684d326 Include "charset.h".
Kenichi Handa <handa@m17n.org>
parents: 90737
diff changeset
251 compile_pattern_1 (cp, pattern, translate, regp, posix);
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
252 break;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
253 }
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
254 }
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
255
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
256 /* When we get here, cp (aka *cpp) contains the compiled pattern,
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
257 either because we found it in the cache or because we just compiled it.
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
258 Move it to the front of the queue to mark it as most recently used. */
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
259 *cpp = cp->next;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
260 cp->next = searchbuf_head;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
261 searchbuf_head = cp;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
262
10141
afe81fd385eb (compile_pattern): Call re_set_registers here.
Richard M. Stallman <rms@gnu.org>
parents: 10128
diff changeset
263 /* Advise the searching functions about the space we have allocated
afe81fd385eb (compile_pattern): Call re_set_registers here.
Richard M. Stallman <rms@gnu.org>
parents: 10128
diff changeset
264 for register data. */
afe81fd385eb (compile_pattern): Call re_set_registers here.
Richard M. Stallman <rms@gnu.org>
parents: 10128
diff changeset
265 if (regp)
afe81fd385eb (compile_pattern): Call re_set_registers here.
Richard M. Stallman <rms@gnu.org>
parents: 10128
diff changeset
266 re_set_registers (&cp->buf, regp, regp->num_regs, regp->start, regp->end);
afe81fd385eb (compile_pattern): Call re_set_registers here.
Richard M. Stallman <rms@gnu.org>
parents: 10128
diff changeset
267
108933
b465aa3255ed Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 106815
diff changeset
268 /* The compiled pattern can be used both for multibyte and unibyte
90760
656ca684d326 Include "charset.h".
Kenichi Handa <handa@m17n.org>
parents: 90737
diff changeset
269 target. But, we have to tell which the pattern is used for. */
656ca684d326 Include "charset.h".
Kenichi Handa <handa@m17n.org>
parents: 90737
diff changeset
270 cp->buf.target_multibyte = multibyte;
656ca684d326 Include "charset.h".
Kenichi Handa <handa@m17n.org>
parents: 90737
diff changeset
271
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
272 return &cp->buf;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
276 static Lisp_Object
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
277 looking_at_1 (Lisp_Object string, int posix)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 Lisp_Object val;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 unsigned char *p1, *p2;
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
281 EMACS_INT s1, s2;
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
282 register EMACS_INT i;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
283 struct re_pattern_buffer *bufp;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
285 if (running_asynch_code)
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
286 save_search_regs ();
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
287
72725
ef0421dfce16 (looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents: 71987
diff changeset
288 /* This is so set_image_of_range_1 in regex.c can find the EQV table. */
ef0421dfce16 (looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents: 71987
diff changeset
289 XCHAR_TABLE (current_buffer->case_canon_table)->extras[2]
ef0421dfce16 (looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents: 71987
diff changeset
290 = current_buffer->case_eqv_table;
ef0421dfce16 (looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents: 71987
diff changeset
291
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
292 CHECK_STRING (string);
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
293 bufp = compile_pattern (string,
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
294 (NILP (Vinhibit_changing_match_data)
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
295 ? &search_regs : NULL),
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
296 (!NILP (current_buffer->case_fold_search)
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
297 ? current_buffer->case_canon_table : Qnil),
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
298 posix,
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
299 !NILP (current_buffer->enable_multibyte_characters));
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 immediate_quit = 1;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 QUIT; /* Do a pending quit right away, to avoid paradoxical behavior */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 /* Get pointers and sizes of the two strings
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 that make up the visible portion of the buffer. */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 p1 = BEGV_ADDR;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
308 s1 = GPT_BYTE - BEGV_BYTE;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 p2 = GAP_END_ADDR;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
310 s2 = ZV_BYTE - GPT_BYTE;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 if (s1 < 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 p2 = p1;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
314 s2 = ZV_BYTE - BEGV_BYTE;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 s1 = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 if (s2 < 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 {
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
319 s1 = ZV_BYTE - BEGV_BYTE;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 s2 = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 }
17463
bb9ae80d22e2 (looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents: 17284
diff changeset
322
bb9ae80d22e2 (looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents: 17284
diff changeset
323 re_match_object = Qnil;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
324
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
325 i = re_match_2 (bufp, (char *) p1, s1, (char *) p2, s2,
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
326 PT_BYTE - BEGV_BYTE,
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
327 (NILP (Vinhibit_changing_match_data)
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
328 ? &search_regs : NULL),
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
329 ZV_BYTE - BEGV_BYTE);
26985
1121a5da20a5 (looking_at_1): Reset immediate_quit before modifying
Gerd Moellmann <gerd@gnu.org>
parents: 26982
diff changeset
330 immediate_quit = 0;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
331
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 if (i == -2)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 matcher_overflow ();
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 val = (0 <= i ? Qt : Qnil);
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
336 if (NILP (Vinhibit_changing_match_data) && i >= 0)
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
337 for (i = 0; i < search_regs.num_regs; i++)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
338 if (search_regs.start[i] >= 0)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
339 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
340 search_regs.start[i]
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
341 = BYTE_TO_CHAR (search_regs.start[i] + BEGV_BYTE);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
342 search_regs.end[i]
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
343 = BYTE_TO_CHAR (search_regs.end[i] + BEGV_BYTE);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
344 }
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
345
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
346 /* Set last_thing_searched only when match data is changed. */
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
347 if (NILP (Vinhibit_changing_match_data))
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
348 XSETBUFFER (last_thing_searched, current_buffer);
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
349
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 return val;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
353 DEFUN ("looking-at", Flooking_at, Slooking_at, 1, 1, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
354 doc: /* Return t if text after point matches regular expression REGEXP.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
355 This function modifies the match data that `match-beginning',
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
356 `match-end' and `match-data' access; save and restore the match
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
357 data if you want to preserve them. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
358 (Lisp_Object regexp)
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
359 {
11213
d0811ba886f8 (Flooking_at, Fposix_looking_at): Change arg name.
Richard M. Stallman <rms@gnu.org>
parents: 10250
diff changeset
360 return looking_at_1 (regexp, 0);
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
361 }
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
362
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
363 DEFUN ("posix-looking-at", Fposix_looking_at, Sposix_looking_at, 1, 1, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
364 doc: /* Return t if text after point matches regular expression REGEXP.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
365 Find the longest match, in accord with Posix regular expression rules.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
366 This function modifies the match data that `match-beginning',
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
367 `match-end' and `match-data' access; save and restore the match
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
368 data if you want to preserve them. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
369 (Lisp_Object regexp)
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
370 {
11213
d0811ba886f8 (Flooking_at, Fposix_looking_at): Change arg name.
Richard M. Stallman <rms@gnu.org>
parents: 10250
diff changeset
371 return looking_at_1 (regexp, 1);
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
372 }
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
373
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
374 static Lisp_Object
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
375 string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start, int posix)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 int val;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
378 struct re_pattern_buffer *bufp;
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
379 EMACS_INT pos, pos_byte;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
380 int i;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
382 if (running_asynch_code)
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
383 save_search_regs ();
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
384
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
385 CHECK_STRING (regexp);
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
386 CHECK_STRING (string);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 if (NILP (start))
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
389 pos = 0, pos_byte = 0;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 else
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 {
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
392 EMACS_INT len = SCHARS (string);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
394 CHECK_NUMBER (start);
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
395 pos = XINT (start);
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
396 if (pos < 0 && -pos <= len)
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
397 pos = len + pos;
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
398 else if (0 > pos || pos > len)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 args_out_of_range (string, start);
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
400 pos_byte = string_char_to_byte (string, pos);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402
72725
ef0421dfce16 (looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents: 71987
diff changeset
403 /* This is so set_image_of_range_1 in regex.c can find the EQV table. */
ef0421dfce16 (looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents: 71987
diff changeset
404 XCHAR_TABLE (current_buffer->case_canon_table)->extras[2]
ef0421dfce16 (looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents: 71987
diff changeset
405 = current_buffer->case_eqv_table;
ef0421dfce16 (looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents: 71987
diff changeset
406
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
407 bufp = compile_pattern (regexp,
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
408 (NILP (Vinhibit_changing_match_data)
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
409 ? &search_regs : NULL),
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
410 (!NILP (current_buffer->case_fold_search)
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
411 ? current_buffer->case_canon_table : Qnil),
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
412 posix,
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
413 STRING_MULTIBYTE (string));
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 immediate_quit = 1;
17463
bb9ae80d22e2 (looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents: 17284
diff changeset
415 re_match_object = string;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
416
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
417 val = re_search (bufp, (char *) SDATA (string),
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
418 SBYTES (string), pos_byte,
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
419 SBYTES (string) - pos_byte,
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
420 (NILP (Vinhibit_changing_match_data)
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
421 ? &search_regs : NULL));
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 immediate_quit = 0;
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
423
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
424 /* Set last_thing_searched only when match data is changed. */
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
425 if (NILP (Vinhibit_changing_match_data))
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
426 last_thing_searched = Qt;
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
427
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 if (val == -2)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 matcher_overflow ();
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 if (val < 0) return Qnil;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
431
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
432 if (NILP (Vinhibit_changing_match_data))
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
433 for (i = 0; i < search_regs.num_regs; i++)
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
434 if (search_regs.start[i] >= 0)
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
435 {
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
436 search_regs.start[i]
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
437 = string_byte_to_char (string, search_regs.start[i]);
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
438 search_regs.end[i]
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
439 = string_byte_to_char (string, search_regs.end[i]);
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
440 }
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
441
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
442 return make_number (string_byte_to_char (string, val));
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 }
842
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
444
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
445 DEFUN ("string-match", Fstring_match, Sstring_match, 2, 3, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
446 doc: /* Return index of start of first match for REGEXP in STRING, or nil.
66200
568d40ba6f52 Fix prev change.
Richard M. Stallman <rms@gnu.org>
parents: 66193
diff changeset
447 Matching ignores case if `case-fold-search' is non-nil.
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
448 If third arg START is non-nil, start search at that index in STRING.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
449 For index of first char beyond the match, do (match-end 0).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
450 `match-end' and `match-beginning' also give indices of substrings
48528
467b0e57d985 (Fstring_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 47692
diff changeset
451 matched by parenthesis constructs in the pattern.
467b0e57d985 (Fstring_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 47692
diff changeset
452
467b0e57d985 (Fstring_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 47692
diff changeset
453 You can use the function `match-string' to extract the substrings
467b0e57d985 (Fstring_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 47692
diff changeset
454 matched by the parenthesis constructions in REGEXP. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
455 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start)
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
456 {
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
457 return string_match_1 (regexp, string, start, 0);
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
458 }
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
459
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
460 DEFUN ("posix-string-match", Fposix_string_match, Sposix_string_match, 2, 3, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
461 doc: /* Return index of start of first match for REGEXP in STRING, or nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
462 Find the longest match, in accord with Posix regular expression rules.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
463 Case is ignored if `case-fold-search' is non-nil in the current buffer.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
464 If third arg START is non-nil, start search at that index in STRING.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
465 For index of first char beyond the match, do (match-end 0).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
466 `match-end' and `match-beginning' also give indices of substrings
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
467 matched by parenthesis constructs in the pattern. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
468 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start)
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
469 {
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
470 return string_match_1 (regexp, string, start, 1);
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
471 }
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
472
842
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
473 /* Match REGEXP against STRING, searching all of STRING,
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
474 and return the index of the match, or negative on failure.
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
475 This does not clobber the match data. */
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
476
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
477 int
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
478 fast_string_match (Lisp_Object regexp, Lisp_Object string)
842
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
479 {
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
480 int val;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
481 struct re_pattern_buffer *bufp;
842
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
482
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
483 bufp = compile_pattern (regexp, 0, Qnil,
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
484 0, STRING_MULTIBYTE (string));
842
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
485 immediate_quit = 1;
17463
bb9ae80d22e2 (looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents: 17284
diff changeset
486 re_match_object = string;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
487
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
488 val = re_search (bufp, (char *) SDATA (string),
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
489 SBYTES (string), 0,
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
490 SBYTES (string), 0);
842
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
491 immediate_quit = 0;
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
492 return val;
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
493 }
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
494
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
495 /* Match REGEXP against STRING, searching all of STRING ignoring case,
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
496 and return the index of the match, or negative on failure.
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
497 This does not clobber the match data.
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
498 We assume that STRING contains single-byte characters. */
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
499
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
500 int
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
501 fast_c_string_match_ignore_case (Lisp_Object regexp, const char *string)
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
502 {
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
503 int val;
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
504 struct re_pattern_buffer *bufp;
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
505 size_t len = strlen (string);
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
506
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
507 regexp = string_make_unibyte (regexp);
18193
4e4c8edb56da (fast_c_string_match_ignore_case):
Richard M. Stallman <rms@gnu.org>
parents: 18124
diff changeset
508 re_match_object = Qt;
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
509 bufp = compile_pattern (regexp, 0,
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
510 Vascii_canon_table, 0,
20671
be91d6130341 (compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents: 20588
diff changeset
511 0);
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
512 immediate_quit = 1;
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
513 val = re_search (bufp, string, len, 0, len, 0);
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
514 immediate_quit = 0;
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
515 return val;
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
516 }
57572
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
517
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
518 /* Like fast_string_match but ignore case. */
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
519
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
520 int
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
521 fast_string_match_ignore_case (Lisp_Object regexp, Lisp_Object string)
57572
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
522 {
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
523 int val;
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
524 struct re_pattern_buffer *bufp;
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
525
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
526 bufp = compile_pattern (regexp, 0, Vascii_canon_table,
57572
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
527 0, STRING_MULTIBYTE (string));
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
528 immediate_quit = 1;
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
529 re_match_object = string;
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
530
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
531 val = re_search (bufp, (char *) SDATA (string),
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
532 SBYTES (string), 0,
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
533 SBYTES (string), 0);
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
534 immediate_quit = 0;
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
535 return val;
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
536 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537
105399
2f74d2880f10 (fast_looking_at): Fix a typo in the commentary.
Eli Zaretskii <eliz@gnu.org>
parents: 103001
diff changeset
538 /* Match REGEXP against the characters after POS to LIMIT, and return
101966
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
539 the number of matched characters. If STRING is non-nil, match
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
540 against the characters in it. In that case, POS and LIMIT are
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
541 indices into the string. This function doesn't modify the match
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
542 data. */
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
543
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
544 EMACS_INT
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
545 fast_looking_at (Lisp_Object regexp, EMACS_INT pos, EMACS_INT pos_byte, EMACS_INT limit, EMACS_INT limit_byte, Lisp_Object string)
101966
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
546 {
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
547 int multibyte;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
548 struct re_pattern_buffer *buf;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
549 unsigned char *p1, *p2;
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
550 EMACS_INT s1, s2;
101966
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
551 EMACS_INT len;
108933
b465aa3255ed Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 106815
diff changeset
552
101966
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
553 if (STRINGP (string))
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
554 {
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
555 if (pos_byte < 0)
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
556 pos_byte = string_char_to_byte (string, pos);
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
557 if (limit_byte < 0)
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
558 limit_byte = string_char_to_byte (string, limit);
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
559 p1 = NULL;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
560 s1 = 0;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
561 p2 = SDATA (string);
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
562 s2 = SBYTES (string);
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
563 re_match_object = string;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
564 multibyte = STRING_MULTIBYTE (string);
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
565 }
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
566 else
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
567 {
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
568 if (pos_byte < 0)
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
569 pos_byte = CHAR_TO_BYTE (pos);
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
570 if (limit_byte < 0)
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
571 limit_byte = CHAR_TO_BYTE (limit);
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
572 pos_byte -= BEGV_BYTE;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
573 limit_byte -= BEGV_BYTE;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
574 p1 = BEGV_ADDR;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
575 s1 = GPT_BYTE - BEGV_BYTE;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
576 p2 = GAP_END_ADDR;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
577 s2 = ZV_BYTE - GPT_BYTE;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
578 if (s1 < 0)
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
579 {
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
580 p2 = p1;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
581 s2 = ZV_BYTE - BEGV_BYTE;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
582 s1 = 0;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
583 }
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
584 if (s2 < 0)
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
585 {
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
586 s1 = ZV_BYTE - BEGV_BYTE;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
587 s2 = 0;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
588 }
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
589 re_match_object = Qnil;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
590 multibyte = ! NILP (current_buffer->enable_multibyte_characters);
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
591 }
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
592
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
593 buf = compile_pattern (regexp, 0, Qnil, 0, multibyte);
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
594 immediate_quit = 1;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
595 len = re_match_2 (buf, (char *) p1, s1, (char *) p2, s2,
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
596 pos_byte, NULL, limit_byte);
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
597 immediate_quit = 0;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
598
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
599 return len;
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
600 }
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
601
43952e9a02cd (fast_looking_at): New function.
Kenichi Handa <handa@m17n.org>
parents: 100951
diff changeset
602
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
603 /* The newline cache: remembering which sections of text have no newlines. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
604
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
605 /* If the user has requested newline caching, make sure it's on.
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
606 Otherwise, make sure it's off.
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
607 This is our cheezy way of associating an action with the change of
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
608 state of a buffer-local variable. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
609 static void
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
610 newline_cache_on_off (struct buffer *buf)
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
611 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
612 if (NILP (buf->cache_long_line_scans))
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
613 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
614 /* It should be off. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
615 if (buf->newline_cache)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
616 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
617 free_region_cache (buf->newline_cache);
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
618 buf->newline_cache = 0;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
619 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
620 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
621 else
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
622 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
623 /* It should be on. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
624 if (buf->newline_cache == 0)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
625 buf->newline_cache = new_region_cache ();
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
626 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
627 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
628
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
629
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
630 /* Search for COUNT instances of the character TARGET between START and END.
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
631
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
632 If COUNT is positive, search forwards; END must be >= START.
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
633 If COUNT is negative, search backwards for the -COUNTth instance;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
634 END must be <= START.
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
635 If COUNT is zero, do anything you please; run rogue, for all I care.
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
636
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
637 If END is zero, use BEGV or ZV instead, as appropriate for the
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
638 direction indicated by COUNT.
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 639
diff changeset
639
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 639
diff changeset
640 If we find COUNT instances, set *SHORTAGE to zero, and return the
57735
82bd283dbbf8 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 57572
diff changeset
641 position past the COUNTth match. Note that for reverse motion
1413
527af9fa8676 Comment fix.
Richard M. Stallman <rms@gnu.org>
parents: 842
diff changeset
642 this is not the same as the usual convention for Emacs motion commands.
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 639
diff changeset
643
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
644 If we don't find COUNT instances before reaching END, set *SHORTAGE
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
645 to the number of TARGETs left unfound, and return END.
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 639
diff changeset
646
5756
a54c236b43c6 (scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents: 5556
diff changeset
647 If ALLOW_QUIT is non-zero, set immediate_quit. That's good to do
a54c236b43c6 (scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents: 5556
diff changeset
648 except when inside redisplay. */
a54c236b43c6 (scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents: 5556
diff changeset
649
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
650 EMACS_INT
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
651 scan_buffer (register int target, EMACS_INT start, EMACS_INT end,
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
652 EMACS_INT count, int *shortage, int allow_quit)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
653 {
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
654 struct region_cache *newline_cache;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
655 int direction;
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 639
diff changeset
656
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
657 if (count > 0)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
658 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
659 direction = 1;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
660 if (! end) end = ZV;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
661 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
662 else
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
663 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
664 direction = -1;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
665 if (! end) end = BEGV;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
666 }
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 639
diff changeset
667
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
668 newline_cache_on_off (current_buffer);
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
669 newline_cache = current_buffer->newline_cache;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
670
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
671 if (shortage != 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
672 *shortage = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
673
5756
a54c236b43c6 (scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents: 5556
diff changeset
674 immediate_quit = allow_quit;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
675
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 639
diff changeset
676 if (count > 0)
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
677 while (start != end)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
678 {
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
679 /* Our innermost scanning loop is very simple; it doesn't know
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
680 about gaps, buffer ends, or the newline cache. ceiling is
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
681 the position of the last character before the next such
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
682 obstacle --- the last character the dumb search loop should
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
683 examine. */
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
684 EMACS_INT ceiling_byte = CHAR_TO_BYTE (end) - 1;
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
685 EMACS_INT start_byte = CHAR_TO_BYTE (start);
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
686 EMACS_INT tem;
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
687
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
688 /* If we're looking for a newline, consult the newline cache
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
689 to see where we can avoid some scanning. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
690 if (target == '\n' && newline_cache)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
691 {
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
692 EMACS_INT next_change;
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
693 immediate_quit = 0;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
694 while (region_cache_forward
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
695 (current_buffer, newline_cache, start_byte, &next_change))
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
696 start_byte = next_change;
9452
76f75b9091f1 (scan_buffer): After temporarily turning immediate_quit off, turn it
Jim Blandy <jimb@redhat.com>
parents: 9410
diff changeset
697 immediate_quit = allow_quit;
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
698
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
699 /* START should never be after END. */
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
700 if (start_byte > ceiling_byte)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
701 start_byte = ceiling_byte;
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
702
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
703 /* Now the text after start is an unknown region, and
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
704 next_change is the position of the next known region. */
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
705 ceiling_byte = min (next_change - 1, ceiling_byte);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
706 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
707
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
708 /* The dumb loop can only scan text stored in contiguous
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
709 bytes. BUFFER_CEILING_OF returns the last character
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
710 position that is contiguous, so the ceiling is the
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
711 position after that. */
21457
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
712 tem = BUFFER_CEILING_OF (start_byte);
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
713 ceiling_byte = min (tem, ceiling_byte);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
714
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
715 {
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
716 /* The termination address of the dumb loop. */
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
717 register unsigned char *ceiling_addr
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
718 = BYTE_POS_ADDR (ceiling_byte) + 1;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
719 register unsigned char *cursor
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
720 = BYTE_POS_ADDR (start_byte);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
721 unsigned char *base = cursor;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
722
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
723 while (cursor < ceiling_addr)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
724 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
725 unsigned char *scan_start = cursor;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
726
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
727 /* The dumb loop. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
728 while (*cursor != target && ++cursor < ceiling_addr)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
729 ;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
730
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
731 /* If we're looking for newlines, cache the fact that
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
732 the region from start to cursor is free of them. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
733 if (target == '\n' && newline_cache)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
734 know_region_cache (current_buffer, newline_cache,
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
735 start_byte + scan_start - base,
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
736 start_byte + cursor - base);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
737
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
738 /* Did we find the target character? */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
739 if (cursor < ceiling_addr)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
740 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
741 if (--count == 0)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
742 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
743 immediate_quit = 0;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
744 return BYTE_TO_CHAR (start_byte + cursor - base + 1);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
745 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
746 cursor++;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
747 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
748 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
749
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
750 start = BYTE_TO_CHAR (start_byte + cursor - base);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
751 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
752 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
753 else
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
754 while (start > end)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
755 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
756 /* The last character to check before the next obstacle. */
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
757 EMACS_INT ceiling_byte = CHAR_TO_BYTE (end);
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
758 EMACS_INT start_byte = CHAR_TO_BYTE (start);
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
759 EMACS_INT tem;
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
760
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
761 /* Consult the newline cache, if appropriate. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
762 if (target == '\n' && newline_cache)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
763 {
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
764 EMACS_INT next_change;
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
765 immediate_quit = 0;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
766 while (region_cache_backward
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
767 (current_buffer, newline_cache, start_byte, &next_change))
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
768 start_byte = next_change;
9452
76f75b9091f1 (scan_buffer): After temporarily turning immediate_quit off, turn it
Jim Blandy <jimb@redhat.com>
parents: 9410
diff changeset
769 immediate_quit = allow_quit;
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
770
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
771 /* Start should never be at or before end. */
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
772 if (start_byte <= ceiling_byte)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
773 start_byte = ceiling_byte + 1;
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
774
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
775 /* Now the text before start is an unknown region, and
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
776 next_change is the position of the next known region. */
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
777 ceiling_byte = max (next_change, ceiling_byte);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
778 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
779
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
780 /* Stop scanning before the gap. */
21457
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
781 tem = BUFFER_FLOOR_OF (start_byte - 1);
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
782 ceiling_byte = max (tem, ceiling_byte);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
783
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
784 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
785 /* The termination address of the dumb loop. */
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
786 register unsigned char *ceiling_addr = BYTE_POS_ADDR (ceiling_byte);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
787 register unsigned char *cursor = BYTE_POS_ADDR (start_byte - 1);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
788 unsigned char *base = cursor;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
789
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
790 while (cursor >= ceiling_addr)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
791 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
792 unsigned char *scan_start = cursor;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
793
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
794 while (*cursor != target && --cursor >= ceiling_addr)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
795 ;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
796
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
797 /* If we're looking for newlines, cache the fact that
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
798 the region from after the cursor to start is free of them. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
799 if (target == '\n' && newline_cache)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
800 know_region_cache (current_buffer, newline_cache,
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
801 start_byte + cursor - base,
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
802 start_byte + scan_start - base);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
803
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
804 /* Did we find the target character? */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
805 if (cursor >= ceiling_addr)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
806 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
807 if (++count >= 0)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
808 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
809 immediate_quit = 0;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
810 return BYTE_TO_CHAR (start_byte + cursor - base);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
811 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
812 cursor--;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
813 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
814 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
815
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
816 start = BYTE_TO_CHAR (start_byte + cursor - base);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
817 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
818 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
819
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
820 immediate_quit = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
821 if (shortage != 0)
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 639
diff changeset
822 *shortage = count * direction;
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
823 return start;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
824 }
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
825
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
826 /* Search for COUNT instances of a line boundary, which means either a
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
827 newline or (if selective display enabled) a carriage return.
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
828 Start at START. If COUNT is negative, search backwards.
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
829
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
830 We report the resulting position by calling TEMP_SET_PT_BOTH.
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
831
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
832 If we find COUNT instances. we position after (always after,
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
833 even if scanning backwards) the COUNTth match, and return 0.
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
834
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
835 If we don't find COUNT instances before reaching the end of the
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
836 buffer (or the beginning, if scanning backwards), we return
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
837 the number of line boundaries left unfound, and position at
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
838 the limit we bumped up against.
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
839
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
840 If ALLOW_QUIT is non-zero, set immediate_quit. That's good to do
20547
07053199a368 (scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents: 20545
diff changeset
841 except in special cases. */
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
842
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
843 EMACS_INT
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
844 scan_newline (EMACS_INT start, EMACS_INT start_byte,
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
845 EMACS_INT limit, EMACS_INT limit_byte,
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
846 register EMACS_INT count, int allow_quit)
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
847 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
848 int direction = ((count > 0) ? 1 : -1);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
849
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
850 register unsigned char *cursor;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
851 unsigned char *base;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
852
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
853 EMACS_INT ceiling;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
854 register unsigned char *ceiling_addr;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
855
20547
07053199a368 (scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents: 20545
diff changeset
856 int old_immediate_quit = immediate_quit;
07053199a368 (scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents: 20545
diff changeset
857
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
858 /* The code that follows is like scan_buffer
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
859 but checks for either newline or carriage return. */
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
860
20547
07053199a368 (scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents: 20545
diff changeset
861 if (allow_quit)
07053199a368 (scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents: 20545
diff changeset
862 immediate_quit++;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
863
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
864 start_byte = CHAR_TO_BYTE (start);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
865
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
866 if (count > 0)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
867 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
868 while (start_byte < limit_byte)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
869 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
870 ceiling = BUFFER_CEILING_OF (start_byte);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
871 ceiling = min (limit_byte - 1, ceiling);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
872 ceiling_addr = BYTE_POS_ADDR (ceiling) + 1;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
873 base = (cursor = BYTE_POS_ADDR (start_byte));
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
874 while (1)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
875 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
876 while (*cursor != '\n' && ++cursor != ceiling_addr)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
877 ;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
878
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
879 if (cursor != ceiling_addr)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
880 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
881 if (--count == 0)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
882 {
20547
07053199a368 (scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents: 20545
diff changeset
883 immediate_quit = old_immediate_quit;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
884 start_byte = start_byte + cursor - base + 1;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
885 start = BYTE_TO_CHAR (start_byte);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
886 TEMP_SET_PT_BOTH (start, start_byte);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
887 return 0;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
888 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
889 else
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
890 if (++cursor == ceiling_addr)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
891 break;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
892 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
893 else
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
894 break;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
895 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
896 start_byte += cursor - base;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
897 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
898 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
899 else
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
900 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
901 while (start_byte > limit_byte)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
902 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
903 ceiling = BUFFER_FLOOR_OF (start_byte - 1);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
904 ceiling = max (limit_byte, ceiling);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
905 ceiling_addr = BYTE_POS_ADDR (ceiling) - 1;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
906 base = (cursor = BYTE_POS_ADDR (start_byte - 1) + 1);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
907 while (1)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
908 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
909 while (--cursor != ceiling_addr && *cursor != '\n')
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
910 ;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
911
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
912 if (cursor != ceiling_addr)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
913 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
914 if (++count == 0)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
915 {
20547
07053199a368 (scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents: 20545
diff changeset
916 immediate_quit = old_immediate_quit;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
917 /* Return the position AFTER the match we found. */
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
918 start_byte = start_byte + cursor - base + 1;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
919 start = BYTE_TO_CHAR (start_byte);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
920 TEMP_SET_PT_BOTH (start, start_byte);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
921 return 0;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
922 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
923 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
924 else
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
925 break;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
926 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
927 /* Here we add 1 to compensate for the last decrement
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
928 of CURSOR, which took it past the valid range. */
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
929 start_byte += cursor - base + 1;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
930 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
931 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
932
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
933 TEMP_SET_PT_BOTH (limit, limit_byte);
20547
07053199a368 (scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents: 20545
diff changeset
934 immediate_quit = old_immediate_quit;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
935
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
936 return count * direction;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
937 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
938
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
939 EMACS_INT
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
940 find_next_newline_no_quit (EMACS_INT from, EMACS_INT cnt)
7891
7d8e0f338e4a (find_next_newline_no_quit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7856
diff changeset
941 {
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
942 return scan_buffer ('\n', from, 0, cnt, (int *) 0, 0);
7891
7d8e0f338e4a (find_next_newline_no_quit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7856
diff changeset
943 }
7d8e0f338e4a (find_next_newline_no_quit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7856
diff changeset
944
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
945 /* Like find_next_newline, but returns position before the newline,
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
946 not after, and only search up to TO. This isn't just
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
947 find_next_newline (...)-1, because you might hit TO. */
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
948
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
949 EMACS_INT
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
950 find_before_next_newline (EMACS_INT from, EMACS_INT to, EMACS_INT cnt)
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
951 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
952 int shortage;
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
953 EMACS_INT pos = scan_buffer ('\n', from, to, cnt, &shortage, 1);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
954
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
955 if (shortage == 0)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
956 pos--;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
957
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
958 return pos;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
959 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
960
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
961 /* Subroutines of Lisp buffer search functions. */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
962
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
963 static Lisp_Object
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
964 search_command (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror,
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
965 Lisp_Object count, int direction, int RE, int posix)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
966 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
967 register int np;
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
968 EMACS_INT lim, lim_byte;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
969 int n = direction;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
970
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
971 if (!NILP (count))
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
972 {
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
973 CHECK_NUMBER (count);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
974 n *= XINT (count);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
975 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
976
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
977 CHECK_STRING (string);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
978 if (NILP (bound))
20824
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
979 {
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
980 if (n > 0)
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
981 lim = ZV, lim_byte = ZV_BYTE;
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
982 else
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
983 lim = BEGV, lim_byte = BEGV_BYTE;
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
984 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
985 else
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
986 {
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
987 CHECK_NUMBER_COERCE_MARKER (bound);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
988 lim = XINT (bound);
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15667
diff changeset
989 if (n > 0 ? lim < PT : lim > PT)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
990 error ("Invalid search bound (wrong side of point)");
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
991 if (lim > ZV)
20824
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
992 lim = ZV, lim_byte = ZV_BYTE;
20924
eda7e44ef9d9 (search_command): Check LIM in valid range
Karl Heuer <kwzh@gnu.org>
parents: 20898
diff changeset
993 else if (lim < BEGV)
20824
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
994 lim = BEGV, lim_byte = BEGV_BYTE;
20924
eda7e44ef9d9 (search_command): Check LIM in valid range
Karl Heuer <kwzh@gnu.org>
parents: 20898
diff changeset
995 else
eda7e44ef9d9 (search_command): Check LIM in valid range
Karl Heuer <kwzh@gnu.org>
parents: 20898
diff changeset
996 lim_byte = CHAR_TO_BYTE (lim);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
997 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
998
72725
ef0421dfce16 (looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents: 71987
diff changeset
999 /* This is so set_image_of_range_1 in regex.c can find the EQV table. */
ef0421dfce16 (looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents: 71987
diff changeset
1000 XCHAR_TABLE (current_buffer->case_canon_table)->extras[2]
ef0421dfce16 (looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents: 71987
diff changeset
1001 = current_buffer->case_eqv_table;
ef0421dfce16 (looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents: 71987
diff changeset
1002
20824
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
1003 np = search_buffer (string, PT, PT_BYTE, lim, lim_byte, n, RE,
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1004 (!NILP (current_buffer->case_fold_search)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1005 ? current_buffer->case_canon_table
20875
4fac9830041a (search_command): Fix call to search_buffer.
Richard M. Stallman <rms@gnu.org>
parents: 20869
diff changeset
1006 : Qnil),
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1007 (!NILP (current_buffer->case_fold_search)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1008 ? current_buffer->case_eqv_table
20875
4fac9830041a (search_command): Fix call to search_buffer.
Richard M. Stallman <rms@gnu.org>
parents: 20869
diff changeset
1009 : Qnil),
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
1010 posix);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1011 if (np <= 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1012 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1013 if (NILP (noerror))
71987
6dd00de34fff (compile_pattern_1): Use xsignal1.
Kim F. Storm <storm@cua.dk>
parents: 71841
diff changeset
1014 xsignal1 (Qsearch_failed, string);
6dd00de34fff (compile_pattern_1): Use xsignal1.
Kim F. Storm <storm@cua.dk>
parents: 71841
diff changeset
1015
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1016 if (!EQ (noerror, Qt))
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1017 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1018 if (lim < BEGV || lim > ZV)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1019 abort ();
20824
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
1020 SET_PT_BOTH (lim, lim_byte);
1878
1c26d0049d4f (search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents: 1877
diff changeset
1021 return Qnil;
1c26d0049d4f (search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents: 1877
diff changeset
1022 #if 0 /* This would be clean, but maybe programs depend on
1c26d0049d4f (search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents: 1877
diff changeset
1023 a value of nil here. */
1877
7786f61ec635 (search_command): When moving to LIM on failure, return LIM.
Richard M. Stallman <rms@gnu.org>
parents: 1684
diff changeset
1024 np = lim;
1878
1c26d0049d4f (search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents: 1877
diff changeset
1025 #endif
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1026 }
1877
7786f61ec635 (search_command): When moving to LIM on failure, return LIM.
Richard M. Stallman <rms@gnu.org>
parents: 1684
diff changeset
1027 else
7786f61ec635 (search_command): When moving to LIM on failure, return LIM.
Richard M. Stallman <rms@gnu.org>
parents: 1684
diff changeset
1028 return Qnil;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1029 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1030
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1031 if (np < BEGV || np > ZV)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1032 abort ();
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1033
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1034 SET_PT (np);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1035
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1036 return make_number (np);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1037 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1038
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1039 /* Return 1 if REGEXP it matches just one constant string. */
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1040
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1041 static int
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
1042 trivial_regexp_p (Lisp_Object regexp)
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1043 {
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1044 EMACS_INT len = SBYTES (regexp);
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1045 unsigned char *s = SDATA (regexp);
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1046 while (--len >= 0)
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1047 {
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1048 switch (*s++)
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1049 {
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1050 case '.': case '*': case '+': case '?': case '[': case '^': case '$':
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1051 return 0;
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1052 case '\\':
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1053 if (--len < 0)
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1054 return 0;
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1055 switch (*s++)
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1056 {
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1057 case '|': case '(': case ')': case '`': case '\'': case 'b':
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1058 case 'B': case '<': case '>': case 'w': case 'W': case 's':
55689
f4a937a898f4 (trivial_regexp_p): \_ is no longer a trivial regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53719
diff changeset
1059 case 'S': case '=': case '{': case '}': case '_':
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
1060 case 'c': case 'C': /* for categoryspec and notcategoryspec */
12069
505dc29a68cf (trivial_regexp_p): = is special after \.
Karl Heuer <kwzh@gnu.org>
parents: 11678
diff changeset
1061 case '1': case '2': case '3': case '4': case '5':
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1062 case '6': case '7': case '8': case '9':
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1063 return 0;
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1064 }
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1065 }
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1066 }
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1067 return 1;
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1068 }
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1069
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1070 /* Search for the n'th occurrence of STRING in the current buffer,
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1071 starting at position POS and stopping at position LIM,
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
1072 treating STRING as a literal string if RE is false or as
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1073 a regular expression if RE is true.
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1074
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1075 If N is positive, searching is forward and LIM must be greater than POS.
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1076 If N is negative, searching is backward and LIM must be less than POS.
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1077
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1078 Returns -x if x occurrences remain to be found (x > 0),
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1079 or else the position at the beginning of the Nth occurrence
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
1080 (if searching backward) or the end (if searching forward).
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1081
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
1082 POSIX is nonzero if we want full backtracking (POSIX style)
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
1083 for this pattern. 0 means backtrack only enough to get a valid match. */
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
1084
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1085 #define TRANSLATE(out, trt, d) \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1086 do \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1087 { \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1088 if (! NILP (trt)) \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1089 { \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1090 Lisp_Object temp; \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1091 temp = Faref (trt, make_number (d)); \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1092 if (INTEGERP (temp)) \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1093 out = XINT (temp); \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1094 else \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1095 out = d; \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1096 } \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1097 else \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1098 out = d; \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1099 } \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1100 while (0)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1101
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1102 /* Only used in search_buffer, to record the end position of the match
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1103 when searching regexps and SEARCH_REGS should not be changed
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1104 (i.e. Vinhibit_changing_match_data is non-nil). */
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1105 static struct re_registers search_regs_1;
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1106
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
1107 static EMACS_INT
109364
89a16701cde1 Convert old-style definitions
Andreas Schwab <schwab@linux-m68k.org>
parents: 109179
diff changeset
1108 search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte,
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1109 EMACS_INT lim, EMACS_INT lim_byte, EMACS_INT n,
109364
89a16701cde1 Convert old-style definitions
Andreas Schwab <schwab@linux-m68k.org>
parents: 109179
diff changeset
1110 int RE, Lisp_Object trt, Lisp_Object inverse_trt, int posix)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1111 {
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1112 EMACS_INT len = SCHARS (string);
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1113 EMACS_INT len_byte = SBYTES (string);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1114 register int i;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1115
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
1116 if (running_asynch_code)
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
1117 save_search_regs ();
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
1118
22082
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
1119 /* Searching 0 times means don't move. */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1120 /* Null string is found at starting position. */
22082
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
1121 if (len == 0 || n == 0)
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1122 {
35831
dc8b618615ea (search_buffer): Call set_search_regs with a byte
Gerd Moellmann <gerd@gnu.org>
parents: 34966
diff changeset
1123 set_search_regs (pos_byte, 0);
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1124 return pos;
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1125 }
4299
7a2e1d7362c5 (search_buffer): If n is 0, just return POS.
Richard M. Stallman <rms@gnu.org>
parents: 3615
diff changeset
1126
58348
623ffd21f0ff (Vsearch_spaces_regexp):
Richard M. Stallman <rms@gnu.org>
parents: 58330
diff changeset
1127 if (RE && !(trivial_regexp_p (string) && NILP (Vsearch_spaces_regexp)))
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1128 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1129 unsigned char *p1, *p2;
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1130 EMACS_INT s1, s2;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
1131 struct re_pattern_buffer *bufp;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
1132
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1133 bufp = compile_pattern (string,
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1134 (NILP (Vinhibit_changing_match_data)
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1135 ? &search_regs : &search_regs_1),
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1136 trt, posix,
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1137 !NILP (current_buffer->enable_multibyte_characters));
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1138
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1139 immediate_quit = 1; /* Quit immediately if user types ^G,
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1140 because letting this function finish
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1141 can take too long. */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1142 QUIT; /* Do a pending quit right away,
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1143 to avoid paradoxical behavior */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1144 /* Get pointers and sizes of the two strings
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1145 that make up the visible portion of the buffer. */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1146
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1147 p1 = BEGV_ADDR;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1148 s1 = GPT_BYTE - BEGV_BYTE;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1149 p2 = GAP_END_ADDR;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1150 s2 = ZV_BYTE - GPT_BYTE;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1151 if (s1 < 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1152 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1153 p2 = p1;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1154 s2 = ZV_BYTE - BEGV_BYTE;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1155 s1 = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1156 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1157 if (s2 < 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1158 {
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1159 s1 = ZV_BYTE - BEGV_BYTE;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1160 s2 = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1161 }
17463
bb9ae80d22e2 (looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents: 17284
diff changeset
1162 re_match_object = Qnil;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
1163
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1164 while (n < 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1165 {
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1166 EMACS_INT val;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
1167 val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2,
20792
f0aa5cc14e8a (fast_string_match): Give re_search byte size of
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
1168 pos_byte - BEGV_BYTE, lim_byte - pos_byte,
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1169 (NILP (Vinhibit_changing_match_data)
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1170 ? &search_regs : &search_regs_1),
2475
052bbdf1b817 (search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents: 2439
diff changeset
1171 /* Don't allow match past current point */
20792
f0aa5cc14e8a (fast_string_match): Give re_search byte size of
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
1172 pos_byte - BEGV_BYTE);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1173 if (val == -2)
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1174 {
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1175 matcher_overflow ();
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1176 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1177 if (val >= 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1178 {
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1179 if (NILP (Vinhibit_changing_match_data))
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1180 {
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1181 pos_byte = search_regs.start[0] + BEGV_BYTE;
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1182 for (i = 0; i < search_regs.num_regs; i++)
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1183 if (search_regs.start[i] >= 0)
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1184 {
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1185 search_regs.start[i]
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1186 = BYTE_TO_CHAR (search_regs.start[i] + BEGV_BYTE);
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1187 search_regs.end[i]
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1188 = BYTE_TO_CHAR (search_regs.end[i] + BEGV_BYTE);
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1189 }
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1190 XSETBUFFER (last_thing_searched, current_buffer);
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1191 /* Set pos to the new position. */
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1192 pos = search_regs.start[0];
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1193 }
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1194 else
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1195 {
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1196 pos_byte = search_regs_1.start[0] + BEGV_BYTE;
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1197 /* Set pos to the new position. */
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1198 pos = BYTE_TO_CHAR (search_regs_1.start[0] + BEGV_BYTE);
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1199 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1200 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1201 else
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1202 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1203 immediate_quit = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1204 return (n);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1205 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1206 n++;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1207 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1208 while (n > 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1209 {
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1210 EMACS_INT val;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
1211 val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2,
20792
f0aa5cc14e8a (fast_string_match): Give re_search byte size of
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
1212 pos_byte - BEGV_BYTE, lim_byte - pos_byte,
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1213 (NILP (Vinhibit_changing_match_data)
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1214 ? &search_regs : &search_regs_1),
20792
f0aa5cc14e8a (fast_string_match): Give re_search byte size of
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
1215 lim_byte - BEGV_BYTE);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1216 if (val == -2)
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1217 {
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1218 matcher_overflow ();
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1219 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1220 if (val >= 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1221 {
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1222 if (NILP (Vinhibit_changing_match_data))
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1223 {
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1224 pos_byte = search_regs.end[0] + BEGV_BYTE;
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1225 for (i = 0; i < search_regs.num_regs; i++)
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1226 if (search_regs.start[i] >= 0)
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1227 {
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1228 search_regs.start[i]
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1229 = BYTE_TO_CHAR (search_regs.start[i] + BEGV_BYTE);
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1230 search_regs.end[i]
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1231 = BYTE_TO_CHAR (search_regs.end[i] + BEGV_BYTE);
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1232 }
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1233 XSETBUFFER (last_thing_searched, current_buffer);
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1234 pos = search_regs.end[0];
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1235 }
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1236 else
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1237 {
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1238 pos_byte = search_regs_1.end[0] + BEGV_BYTE;
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1239 pos = BYTE_TO_CHAR (search_regs_1.end[0] + BEGV_BYTE);
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1240 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1241 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1242 else
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1243 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1244 immediate_quit = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1245 return (0 - n);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1246 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1247 n--;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1248 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1249 immediate_quit = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1250 return (pos);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1251 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1252 else /* non-RE case */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1253 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1254 unsigned char *raw_pattern, *pat;
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1255 EMACS_INT raw_pattern_size;
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1256 EMACS_INT raw_pattern_size_byte;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1257 unsigned char *patbuf;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1258 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
66751
e1496b6cebc3 (search_buffer): No need to initialize base_pat.
Kim F. Storm <storm@cua.dk>
parents: 66259
diff changeset
1259 unsigned char *base_pat;
66078
2fe97fc2ee41 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 64770
diff changeset
1260 /* Set to positive if we find a non-ASCII char that need
2fe97fc2ee41 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 64770
diff changeset
1261 translation. Otherwise set to zero later. */
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1262 int char_base = -1;
23876
8d2f38338c81 (search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents: 23790
diff changeset
1263 int boyer_moore_ok = 1;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1264
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1265 /* MULTIBYTE says whether the text to be searched is multibyte.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1266 We must convert PATTERN to match that, or we will not really
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1267 find things right. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1268
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1269 if (multibyte == STRING_MULTIBYTE (string))
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1270 {
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1271 raw_pattern = (unsigned char *) SDATA (string);
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1272 raw_pattern_size = SCHARS (string);
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1273 raw_pattern_size_byte = SBYTES (string);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1274 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1275 else if (multibyte)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1276 {
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1277 raw_pattern_size = SCHARS (string);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1278 raw_pattern_size_byte
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1279 = count_size_as_multibyte (SDATA (string),
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1280 raw_pattern_size);
21915
8f1159b417c2 (search_buffer): Fix casts when assigning raw_pattern.
Richard M. Stallman <rms@gnu.org>
parents: 21887
diff changeset
1281 raw_pattern = (unsigned char *) alloca (raw_pattern_size_byte + 1);
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1282 copy_text (SDATA (string), raw_pattern,
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1283 SCHARS (string), 0, 1);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1284 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1285 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1286 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1287 /* Converting multibyte to single-byte.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1288
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1289 ??? Perhaps this conversion should be done in a special way
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1290 by subtracting nonascii-insert-offset from each non-ASCII char,
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1291 so that only the multibyte chars which really correspond to
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1292 the chosen single-byte character set can possibly match. */
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1293 raw_pattern_size = SCHARS (string);
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1294 raw_pattern_size_byte = SCHARS (string);
21915
8f1159b417c2 (search_buffer): Fix casts when assigning raw_pattern.
Richard M. Stallman <rms@gnu.org>
parents: 21887
diff changeset
1295 raw_pattern = (unsigned char *) alloca (raw_pattern_size + 1);
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1296 copy_text (SDATA (string), raw_pattern,
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1297 SBYTES (string), 1, 0);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1298 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1299
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1300 /* Copy and optionally translate the pattern. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1301 len = raw_pattern_size;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1302 len_byte = raw_pattern_size_byte;
89130
e18339404909 (search_buffer): Fix case-fold-search of multibyte
Kenichi Handa <handa@m17n.org>
parents: 89062
diff changeset
1303 patbuf = (unsigned char *) alloca (len * MAX_MULTIBYTE_LENGTH);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1304 pat = patbuf;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1305 base_pat = raw_pattern;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1306 if (multibyte)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1307 {
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1308 /* Fill patbuf by translated characters in STRING while
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1309 checking if we can use boyer-moore search. If TRT is
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1310 non-nil, we can use boyer-moore search only if TRT can be
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1311 represented by the byte array of 256 elements. For that,
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1312 all non-ASCII case-equivalents of all case-senstive
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1313 characters in STRING must belong to the same charset and
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1314 row. */
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1315
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1316 while (--len >= 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1317 {
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1318 unsigned char str_base[MAX_MULTIBYTE_LENGTH], *str;
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1319 int c, translated, inverse;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1320 int in_charlen, charlen;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1321
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1322 /* If we got here and the RE flag is set, it's because we're
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1323 dealing with a regexp known to be trivial, so the backslash
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1324 just quotes the next character. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1325 if (RE && *base_pat == '\\')
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1326 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1327 len--;
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1328 raw_pattern_size--;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1329 len_byte--;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1330 base_pat++;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1331 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1332
106185
f2cea199b0c4 * character.h (STRING_CHAR, STRING_CHAR_AND_LENGTH): Remove
Andreas Schwab <schwab@linux-m68k.org>
parents: 105877
diff changeset
1333 c = STRING_CHAR_AND_LENGTH (base_pat, in_charlen);
23876
8d2f38338c81 (search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents: 23790
diff changeset
1334
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1335 if (NILP (trt))
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1336 {
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1337 str = base_pat;
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1338 charlen = in_charlen;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1339 }
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1340 else
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1341 {
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1342 /* Translate the character. */
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1343 TRANSLATE (translated, trt, c);
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1344 charlen = CHAR_STRING (translated, str_base);
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1345 str = str_base;
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1346
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1347 /* Check if C has any other case-equivalents. */
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1348 TRANSLATE (inverse, inverse_trt, c);
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1349 /* If so, check if we can use boyer-moore. */
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1350 if (c != inverse && boyer_moore_ok)
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1351 {
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1352 /* Check if all equivalents belong to the same
90137
e465b832ab21 (search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents: 90136
diff changeset
1353 group of characters. Note that the check of C
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1354 itself is done by the last iteration. */
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1355 int this_char_base = -1;
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1356
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1357 while (boyer_moore_ok)
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1358 {
66078
2fe97fc2ee41 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 64770
diff changeset
1359 if (ASCII_BYTE_P (inverse))
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1360 {
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1361 if (this_char_base > 0)
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1362 boyer_moore_ok = 0;
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1363 else
97759
99656f6b55ce (search_buffer): Set char_base to zero only at the end.
Andreas Schwab <schwab@suse.de>
parents: 94963
diff changeset
1364 this_char_base = 0;
66078
2fe97fc2ee41 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 64770
diff changeset
1365 }
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1366 else if (CHAR_BYTE8_P (inverse))
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1367 /* Boyer-moore search can't handle a
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1368 translation of an eight-bit
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1369 character. */
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1370 boyer_moore_ok = 0;
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1371 else if (this_char_base < 0)
66078
2fe97fc2ee41 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 64770
diff changeset
1372 {
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1373 this_char_base = inverse & ~0x3F;
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1374 if (char_base < 0)
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1375 char_base = this_char_base;
97759
99656f6b55ce (search_buffer): Set char_base to zero only at the end.
Andreas Schwab <schwab@suse.de>
parents: 94963
diff changeset
1376 else if (this_char_base != char_base)
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1377 boyer_moore_ok = 0;
66078
2fe97fc2ee41 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 64770
diff changeset
1378 }
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1379 else if ((inverse & ~0x3F) != this_char_base)
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1380 boyer_moore_ok = 0;
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1381 if (c == inverse)
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1382 break;
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1383 TRANSLATE (inverse, inverse_trt, inverse);
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1384 }
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1385 }
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1386 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1387
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1388 /* Store this character into the translated pattern. */
109165
750db9f3e6d8 Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents: 109126
diff changeset
1389 memcpy (pat, str, charlen);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1390 pat += charlen;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1391 base_pat += in_charlen;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1392 len_byte -= in_charlen;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1393 }
97759
99656f6b55ce (search_buffer): Set char_base to zero only at the end.
Andreas Schwab <schwab@suse.de>
parents: 94963
diff changeset
1394
99656f6b55ce (search_buffer): Set char_base to zero only at the end.
Andreas Schwab <schwab@suse.de>
parents: 94963
diff changeset
1395 /* If char_base is still negative we didn't find any translated
99656f6b55ce (search_buffer): Set char_base to zero only at the end.
Andreas Schwab <schwab@suse.de>
parents: 94963
diff changeset
1396 non-ASCII characters. */
99656f6b55ce (search_buffer): Set char_base to zero only at the end.
Andreas Schwab <schwab@suse.de>
parents: 94963
diff changeset
1397 if (char_base < 0)
99656f6b55ce (search_buffer): Set char_base to zero only at the end.
Andreas Schwab <schwab@suse.de>
parents: 94963
diff changeset
1398 char_base = 0;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1399 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1400 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1401 {
23876
8d2f38338c81 (search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents: 23790
diff changeset
1402 /* Unibyte buffer. */
90137
e465b832ab21 (search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents: 90136
diff changeset
1403 char_base = 0;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1404 while (--len >= 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1405 {
23876
8d2f38338c81 (search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents: 23790
diff changeset
1406 int c, translated;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1407
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1408 /* If we got here and the RE flag is set, it's because we're
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1409 dealing with a regexp known to be trivial, so the backslash
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1410 just quotes the next character. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1411 if (RE && *base_pat == '\\')
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1412 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1413 len--;
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1414 raw_pattern_size--;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1415 base_pat++;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1416 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1417 c = *base_pat++;
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1418 TRANSLATE (translated, trt, c);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1419 *pat++ = translated;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1420 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1421 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1422
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1423 len_byte = pat - patbuf;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1424 len = raw_pattern_size;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1425 pat = base_pat = patbuf;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1426
23876
8d2f38338c81 (search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents: 23790
diff changeset
1427 if (boyer_moore_ok)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1428 return boyer_moore (n, pat, len, len_byte, trt, inverse_trt,
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1429 pos, pos_byte, lim, lim_byte,
90137
e465b832ab21 (search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents: 90136
diff changeset
1430 char_base);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1431 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1432 return simple_search (n, pat, len, len_byte, trt,
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1433 pos, pos_byte, lim, lim_byte);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1434 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1435 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1436
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1437 /* Do a simple string search N times for the string PAT,
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1438 whose length is LEN/LEN_BYTE,
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1439 from buffer position POS/POS_BYTE until LIM/LIM_BYTE.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1440 TRT is the translation table.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1441
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1442 Return the character position where the match is found.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1443 Otherwise, if M matches remained to be found, return -M.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1444
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1445 This kind of search works regardless of what is in PAT and
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1446 regardless of what is in TRT. It is used in cases where
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1447 boyer_moore cannot work. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1448
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
1449 static EMACS_INT
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1450 simple_search (EMACS_INT n, unsigned char *pat,
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1451 EMACS_INT len, EMACS_INT len_byte, Lisp_Object trt,
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1452 EMACS_INT pos, EMACS_INT pos_byte,
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1453 EMACS_INT lim, EMACS_INT lim_byte)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1454 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1455 int multibyte = ! NILP (current_buffer->enable_multibyte_characters);
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1456 int forward = n > 0;
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1457 /* Number of buffer bytes matched. Note that this may be different
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1458 from len_byte in a multibyte buffer. */
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1459 EMACS_INT match_byte;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1460
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1461 if (lim > pos && multibyte)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1462 while (n > 0)
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1463 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1464 while (1)
20671
be91d6130341 (compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents: 20588
diff changeset
1465 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1466 /* Try matching at position POS. */
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
1467 EMACS_INT this_pos = pos;
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
1468 EMACS_INT this_pos_byte = pos_byte;
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1469 EMACS_INT this_len = len;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1470 unsigned char *p = pat;
90671
140d663891af (simple_search): Fix sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents: 90667
diff changeset
1471 if (pos + len > lim || pos_byte + len_byte > lim_byte)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1472 goto stop;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1473
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1474 while (this_len > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1475 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1476 int charlen, buf_charlen;
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1477 int pat_ch, buf_ch;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1478
106185
f2cea199b0c4 * character.h (STRING_CHAR, STRING_CHAR_AND_LENGTH): Remove
Andreas Schwab <schwab@linux-m68k.org>
parents: 105877
diff changeset
1479 pat_ch = STRING_CHAR_AND_LENGTH (p, charlen);
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1480 buf_ch = STRING_CHAR_AND_LENGTH (BYTE_POS_ADDR (this_pos_byte),
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1481 buf_charlen);
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1482 TRANSLATE (buf_ch, trt, buf_ch);
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1483
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1484 if (buf_ch != pat_ch)
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1485 break;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1486
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1487 this_len--;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1488 p += charlen;
20671
be91d6130341 (compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents: 20588
diff changeset
1489
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1490 this_pos_byte += buf_charlen;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1491 this_pos++;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1492 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1493
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1494 if (this_len == 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1495 {
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1496 match_byte = this_pos_byte - pos_byte;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1497 pos += len;
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1498 pos_byte += match_byte;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1499 break;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1500 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1501
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1502 INC_BOTH (pos, pos_byte);
20671
be91d6130341 (compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents: 20588
diff changeset
1503 }
be91d6130341 (compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents: 20588
diff changeset
1504
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1505 n--;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1506 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1507 else if (lim > pos)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1508 while (n > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1509 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1510 while (1)
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1511 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1512 /* Try matching at position POS. */
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
1513 EMACS_INT this_pos = pos;
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1514 EMACS_INT this_len = len;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1515 unsigned char *p = pat;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1516
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1517 if (pos + len > lim)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1518 goto stop;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1519
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1520 while (this_len > 0)
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1521 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1522 int pat_ch = *p++;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1523 int buf_ch = FETCH_BYTE (this_pos);
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1524 TRANSLATE (buf_ch, trt, buf_ch);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1525
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1526 if (buf_ch != pat_ch)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1527 break;
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1528
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1529 this_len--;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1530 this_pos++;
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1531 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1532
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1533 if (this_len == 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1534 {
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1535 match_byte = len;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1536 pos += len;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1537 break;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1538 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1539
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1540 pos++;
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1541 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1542
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1543 n--;
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1544 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1545 /* Backwards search. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1546 else if (lim < pos && multibyte)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1547 while (n < 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1548 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1549 while (1)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1550 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1551 /* Try matching at position POS. */
106193
234022ddfcd1 (simple_search): Avoid CHAR_TO_BYTE in inner loop when
Andreas Schwab <schwab@linux-m68k.org>
parents: 106185
diff changeset
1552 EMACS_INT this_pos = pos;
234022ddfcd1 (simple_search): Avoid CHAR_TO_BYTE in inner loop when
Andreas Schwab <schwab@linux-m68k.org>
parents: 106185
diff changeset
1553 EMACS_INT this_pos_byte = pos_byte;
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1554 EMACS_INT this_len = len;
106285
4248d7c5bed0 serach.c (simple_search): Remove warning by making *p const.
Jan Djärv <jan.h.d@swipnet.se>
parents: 106193
diff changeset
1555 const unsigned char *p = pat + len_byte;
106193
234022ddfcd1 (simple_search): Avoid CHAR_TO_BYTE in inner loop when
Andreas Schwab <schwab@linux-m68k.org>
parents: 106185
diff changeset
1556
234022ddfcd1 (simple_search): Avoid CHAR_TO_BYTE in inner loop when
Andreas Schwab <schwab@linux-m68k.org>
parents: 106185
diff changeset
1557 if (this_pos - len < lim || (pos_byte - len_byte) < lim_byte)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1558 goto stop;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1559
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1560 while (this_len > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1561 {
106193
234022ddfcd1 (simple_search): Avoid CHAR_TO_BYTE in inner loop when
Andreas Schwab <schwab@linux-m68k.org>
parents: 106185
diff changeset
1562 int charlen;
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1563 int pat_ch, buf_ch;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1564
106193
234022ddfcd1 (simple_search): Avoid CHAR_TO_BYTE in inner loop when
Andreas Schwab <schwab@linux-m68k.org>
parents: 106185
diff changeset
1565 DEC_BOTH (this_pos, this_pos_byte);
234022ddfcd1 (simple_search): Avoid CHAR_TO_BYTE in inner loop when
Andreas Schwab <schwab@linux-m68k.org>
parents: 106185
diff changeset
1566 PREV_CHAR_BOUNDARY (p, pat);
234022ddfcd1 (simple_search): Avoid CHAR_TO_BYTE in inner loop when
Andreas Schwab <schwab@linux-m68k.org>
parents: 106185
diff changeset
1567 pat_ch = STRING_CHAR (p);
234022ddfcd1 (simple_search): Avoid CHAR_TO_BYTE in inner loop when
Andreas Schwab <schwab@linux-m68k.org>
parents: 106185
diff changeset
1568 buf_ch = STRING_CHAR (BYTE_POS_ADDR (this_pos_byte));
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1569 TRANSLATE (buf_ch, trt, buf_ch);
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1570
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1571 if (buf_ch != pat_ch)
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1572 break;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1573
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1574 this_len--;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1575 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1576
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1577 if (this_len == 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1578 {
106193
234022ddfcd1 (simple_search): Avoid CHAR_TO_BYTE in inner loop when
Andreas Schwab <schwab@linux-m68k.org>
parents: 106185
diff changeset
1579 match_byte = pos_byte - this_pos_byte;
234022ddfcd1 (simple_search): Avoid CHAR_TO_BYTE in inner loop when
Andreas Schwab <schwab@linux-m68k.org>
parents: 106185
diff changeset
1580 pos = this_pos;
234022ddfcd1 (simple_search): Avoid CHAR_TO_BYTE in inner loop when
Andreas Schwab <schwab@linux-m68k.org>
parents: 106185
diff changeset
1581 pos_byte = this_pos_byte;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1582 break;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1583 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1584
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1585 DEC_BOTH (pos, pos_byte);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1586 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1587
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1588 n++;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1589 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1590 else if (lim < pos)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1591 while (n < 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1592 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1593 while (1)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1594 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1595 /* Try matching at position POS. */
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
1596 EMACS_INT this_pos = pos - len;
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1597 EMACS_INT this_len = len;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1598 unsigned char *p = pat;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1599
90671
140d663891af (simple_search): Fix sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents: 90667
diff changeset
1600 if (this_pos < lim)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1601 goto stop;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1602
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1603 while (this_len > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1604 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1605 int pat_ch = *p++;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1606 int buf_ch = FETCH_BYTE (this_pos);
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1607 TRANSLATE (buf_ch, trt, buf_ch);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1608
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1609 if (buf_ch != pat_ch)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1610 break;
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1611 this_len--;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1612 this_pos++;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1613 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1614
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1615 if (this_len == 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1616 {
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1617 match_byte = len;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1618 pos -= len;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1619 break;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1620 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1621
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1622 pos--;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1623 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1624
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1625 n++;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1626 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1627
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1628 stop:
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1629 if (n == 0)
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1630 {
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1631 if (forward)
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1632 set_search_regs ((multibyte ? pos_byte : pos) - match_byte, match_byte);
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1633 else
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1634 set_search_regs (multibyte ? pos_byte : pos, match_byte);
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1635
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1636 return pos;
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1637 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1638 else if (n > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1639 return -n;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1640 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1641 return n;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1642 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1643
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1644 /* Do Boyer-Moore search N times for the string BASE_PAT,
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1645 whose length is LEN/LEN_BYTE,
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1646 from buffer position POS/POS_BYTE until LIM/LIM_BYTE.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1647 DIRECTION says which direction we search in.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1648 TRT and INVERSE_TRT are translation tables.
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1649 Characters in PAT are already translated by TRT.
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1650
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1651 This kind of search works if all the characters in BASE_PAT that
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1652 have nontrivial translation are the same aside from the last byte.
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1653 This makes it possible to translate just the last byte of a
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1654 character, and do so after just a simple test of the context.
91005
424b655804ca Merge from emacs--devo--0
Miles Bader <miles@gnu.org>
parents: 90996 82365
diff changeset
1655 CHAR_BASE is nonzero if there is such a non-ASCII character.
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1656
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1657 If that criterion is not satisfied, do not call this function. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1658
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
1659 static EMACS_INT
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1660 boyer_moore (EMACS_INT n, unsigned char *base_pat,
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1661 EMACS_INT len, EMACS_INT len_byte,
109364
89a16701cde1 Convert old-style definitions
Andreas Schwab <schwab@linux-m68k.org>
parents: 109179
diff changeset
1662 Lisp_Object trt, Lisp_Object inverse_trt,
89a16701cde1 Convert old-style definitions
Andreas Schwab <schwab@linux-m68k.org>
parents: 109179
diff changeset
1663 EMACS_INT pos, EMACS_INT pos_byte,
89a16701cde1 Convert old-style definitions
Andreas Schwab <schwab@linux-m68k.org>
parents: 109179
diff changeset
1664 EMACS_INT lim, EMACS_INT lim_byte, int char_base)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1665 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1666 int direction = ((n > 0) ? 1 : -1);
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1667 register EMACS_INT dirlen;
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
1668 EMACS_INT limit;
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
1669 int stride_for_teases = 0;
102999
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1670 int BM_tab[0400];
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
1671 register unsigned char *cursor, *p_limit;
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1672 register EMACS_INT i;
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
1673 register int j;
21945
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1674 unsigned char *pat, *pat_end;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1675 int multibyte = ! NILP (current_buffer->enable_multibyte_characters);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1676
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1677 unsigned char simple_translate[0400];
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1678 /* These are set to the preceding bytes of a byte to be translated
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1679 if char_base is nonzero. As the maximum byte length of a
90137
e465b832ab21 (search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents: 90136
diff changeset
1680 multibyte character is 5, we have to check at most four previous
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1681 bytes. */
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1682 int translate_prev_byte1 = 0;
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1683 int translate_prev_byte2 = 0;
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1684 int translate_prev_byte3 = 0;
90137
e465b832ab21 (search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents: 90136
diff changeset
1685 int translate_prev_byte4 = 0;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1686
102999
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1687 /* The general approach is that we are going to maintain that we know
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1688 the first (closest to the present position, in whatever direction
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1689 we're searching) character that could possibly be the last
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1690 (furthest from present position) character of a valid match. We
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1691 advance the state of our knowledge by looking at that character
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1692 and seeing whether it indeed matches the last character of the
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1693 pattern. If it does, we take a closer look. If it does not, we
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1694 move our pointer (to putative last characters) as far as is
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1695 logically possible. This amount of movement, which I call a
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1696 stride, will be the length of the pattern if the actual character
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1697 appears nowhere in the pattern, otherwise it will be the distance
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1698 from the last occurrence of that character to the end of the
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1699 pattern. If the amount is zero we have a possible match. */
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1700
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1701 /* Here we make a "mickey mouse" BM table. The stride of the search
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1702 is determined only by the last character of the putative match.
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1703 If that character does not match, we will stride the proper
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1704 distance to propose a match that superimposes it on the last
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1705 instance of a character that matches it (per trt), or misses
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1706 it entirely if there is none. */
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1707
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1708 dirlen = len_byte * direction;
21945
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1709
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1710 /* Record position after the end of the pattern. */
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1711 pat_end = base_pat + len_byte;
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1712 /* BASE_PAT points to a character that we start scanning from.
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1713 It is the first character in a forward search,
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1714 the last character in a backward search. */
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1715 if (direction < 0)
21945
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1716 base_pat = pat_end - 1;
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1717
102999
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1718 /* A character that does not appear in the pattern induces a
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1719 stride equal to the pattern length. */
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1720 for (i = 0; i < 0400; i++)
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1721 BM_tab[i] = dirlen;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1722
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1723 /* We use this for translation, instead of TRT itself.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1724 We fill this in to handle the characters that actually
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1725 occur in the pattern. Others don't matter anyway! */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1726 for (i = 0; i < 0400; i++)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1727 simple_translate[i] = i;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1728
90137
e465b832ab21 (search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents: 90136
diff changeset
1729 if (char_base)
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1730 {
90137
e465b832ab21 (search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents: 90136
diff changeset
1731 /* Setup translate_prev_byte1/2/3/4 from CHAR_BASE. Only a
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1732 byte following them are the target of translation. */
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1733 unsigned char str[MAX_MULTIBYTE_LENGTH];
90137
e465b832ab21 (search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents: 90136
diff changeset
1734 int len = CHAR_STRING (char_base, str);
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1735
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1736 translate_prev_byte1 = str[len - 2];
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1737 if (len > 2)
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1738 {
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1739 translate_prev_byte2 = str[len - 3];
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1740 if (len > 3)
90137
e465b832ab21 (search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents: 90136
diff changeset
1741 {
e465b832ab21 (search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents: 90136
diff changeset
1742 translate_prev_byte3 = str[len - 4];
e465b832ab21 (search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents: 90136
diff changeset
1743 if (len > 4)
e465b832ab21 (search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents: 90136
diff changeset
1744 translate_prev_byte4 = str[len - 5];
e465b832ab21 (search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents: 90136
diff changeset
1745 }
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1746 }
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1747 }
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1748
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1749 i = 0;
102999
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1750 while (i != dirlen)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1751 {
21945
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1752 unsigned char *ptr = base_pat + i;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1753 i += direction;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1754 if (! NILP (trt))
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1755 {
61682
0015a00ccb5a (boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 61189
diff changeset
1756 /* If the byte currently looking at is the last of a
0015a00ccb5a (boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 61189
diff changeset
1757 character to check case-equivalents, set CH to that
0015a00ccb5a (boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 61189
diff changeset
1758 character. An ASCII character and a non-ASCII character
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1759 matching with CHAR_BASE are to be checked. */
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1760 int ch = -1;
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1761
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1762 if (ASCII_BYTE_P (*ptr) || ! multibyte)
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1763 ch = *ptr;
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1764 else if (char_base
66259
d0daa61f9e6f (boyer_moore): Surround the '||' part of expression in
Kenichi Handa <handa@m17n.org>
parents: 66200
diff changeset
1765 && ((pat_end - ptr) == 1 || CHAR_HEAD_P (ptr[1])))
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1766 {
61682
0015a00ccb5a (boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 61189
diff changeset
1767 unsigned char *charstart = ptr - 1;
0015a00ccb5a (boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 61189
diff changeset
1768
0015a00ccb5a (boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 61189
diff changeset
1769 while (! (CHAR_HEAD_P (*charstart)))
0015a00ccb5a (boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 61189
diff changeset
1770 charstart--;
106185
f2cea199b0c4 * character.h (STRING_CHAR, STRING_CHAR_AND_LENGTH): Remove
Andreas Schwab <schwab@linux-m68k.org>
parents: 105877
diff changeset
1771 ch = STRING_CHAR (charstart);
90137
e465b832ab21 (search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents: 90136
diff changeset
1772 if (char_base != (ch & ~0x3F))
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1773 ch = -1;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1774 }
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1775
91762
5a41bb37f0ee (boyer_moore): Fix incorrect synching of the trunk and
Kenichi Handa <handa@m17n.org>
parents: 91327
diff changeset
1776 if (ch >= 0200)
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1777 j = (ch & 0x3F) | 0200;
61682
0015a00ccb5a (boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 61189
diff changeset
1778 else
0015a00ccb5a (boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 61189
diff changeset
1779 j = *ptr;
0015a00ccb5a (boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 61189
diff changeset
1780
102999
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1781 if (i == dirlen)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1782 stride_for_teases = BM_tab[j];
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1783
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1784 BM_tab[j] = dirlen - i;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1785 /* A translation table is accompanied by its inverse -- see */
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
1786 /* comment following downcase_table for details */
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1787 if (ch >= 0)
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1788 {
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1789 int starting_ch = ch;
61682
0015a00ccb5a (boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 61189
diff changeset
1790 int starting_j = j;
0015a00ccb5a (boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 61189
diff changeset
1791
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1792 while (1)
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1793 {
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1794 TRANSLATE (ch, inverse_trt, ch);
91762
5a41bb37f0ee (boyer_moore): Fix incorrect synching of the trunk and
Kenichi Handa <handa@m17n.org>
parents: 91327
diff changeset
1795 if (ch >= 0200)
90245
7dd79b4dd8a5 (search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents: 90224
diff changeset
1796 j = (ch & 0x3F) | 0200;
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1797 else
90137
e465b832ab21 (search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents: 90136
diff changeset
1798 j = ch;
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1799
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1800 /* For all the characters that map into CH,
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1801 set up simple_translate to map the last byte
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1802 into STARTING_J. */
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1803 simple_translate[j] = starting_j;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1804 if (ch == starting_ch)
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1805 break;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1806 BM_tab[j] = dirlen - i;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1807 }
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1808 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1809 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1810 else
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1811 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1812 j = *ptr;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1813
102999
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1814 if (i == dirlen)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1815 stride_for_teases = BM_tab[j];
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1816 BM_tab[j] = dirlen - i;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1817 }
102999
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1818 /* stride_for_teases tells how much to stride if we get a
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1819 match on the far character but are subsequently
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1820 disappointed, by recording what the stride would have been
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1821 for that character if the last character had been
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1822 different. */
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1823 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1824 pos_byte += dirlen - ((direction > 0) ? direction : 0);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1825 /* loop invariant - POS_BYTE points at where last char (first
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1826 char if reverse) of pattern would align in a possible match. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1827 while (n != 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1828 {
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
1829 EMACS_INT tail_end;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1830 unsigned char *tail_end_ptr;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1831
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1832 /* It's been reported that some (broken) compiler thinks that
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1833 Boolean expressions in an arithmetic context are unsigned.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1834 Using an explicit ?1:0 prevents this. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1835 if ((lim_byte - pos_byte - ((direction > 0) ? 1 : 0)) * direction
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1836 < 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1837 return (n * (0 - direction));
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1838 /* First we do the part we can by pointers (maybe nothing) */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1839 QUIT;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1840 pat = base_pat;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1841 limit = pos_byte - dirlen + direction;
21457
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1842 if (direction > 0)
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1843 {
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1844 limit = BUFFER_CEILING_OF (limit);
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1845 /* LIMIT is now the last (not beyond-last!) value POS_BYTE
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1846 can take on without hitting edge of buffer or the gap. */
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1847 limit = min (limit, pos_byte + 20000);
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1848 limit = min (limit, lim_byte - 1);
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1849 }
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1850 else
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1851 {
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1852 limit = BUFFER_FLOOR_OF (limit);
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1853 /* LIMIT is now the last (not beyond-last!) value POS_BYTE
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1854 can take on without hitting edge of buffer or the gap. */
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1855 limit = max (limit, pos_byte - 20000);
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1856 limit = max (limit, lim_byte);
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1857 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1858 tail_end = BUFFER_CEILING_OF (pos_byte) + 1;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1859 tail_end_ptr = BYTE_POS_ADDR (tail_end);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1860
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1861 if ((limit - pos_byte) * direction > 20)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1862 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1863 unsigned char *p2;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1864
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1865 p_limit = BYTE_POS_ADDR (limit);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1866 p2 = (cursor = BYTE_POS_ADDR (pos_byte));
102999
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1867 /* In this loop, pos + cursor - p2 is the surrogate for pos. */
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1868 while (1) /* use one cursor setting as long as i can */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1869 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1870 if (direction > 0) /* worth duplicating */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1871 {
102999
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1872 while (cursor <= p_limit)
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1873 {
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1874 if (BM_tab[*cursor] == 0)
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1875 goto hit;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1876 cursor += BM_tab[*cursor];
102999
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1877 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1878 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1879 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1880 {
102999
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1881 while (cursor >= p_limit)
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1882 {
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1883 if (BM_tab[*cursor] == 0)
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1884 goto hit;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1885 cursor += BM_tab[*cursor];
102999
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1886 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1887 }
102999
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1888 /* If you are here, cursor is beyond the end of the
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1889 searched region. You fail to match within the
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1890 permitted region and would otherwise try a character
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1891 beyond that region. */
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1892 break;
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1893
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1894 hit:
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1895 i = dirlen - direction;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1896 if (! NILP (trt))
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1897 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1898 while ((i -= direction) + direction != 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1899 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1900 int ch;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1901 cursor -= direction;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1902 /* Translate only the last byte of a character. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1903 if (! multibyte
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1904 || ((cursor == tail_end_ptr
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1905 || CHAR_HEAD_P (cursor[1]))
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1906 && (CHAR_HEAD_P (cursor[0])
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1907 /* Check if this is the last byte of
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1908 a translable character. */
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1909 || (translate_prev_byte1 == cursor[-1]
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1910 && (CHAR_HEAD_P (translate_prev_byte1)
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1911 || (translate_prev_byte2 == cursor[-2]
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1912 && (CHAR_HEAD_P (translate_prev_byte2)
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
1913 || (translate_prev_byte3 == cursor[-3]))))))))
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1914 ch = simple_translate[*cursor];
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1915 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1916 ch = *cursor;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1917 if (pat[i] != ch)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1918 break;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1919 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1920 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1921 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1922 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1923 while ((i -= direction) + direction != 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1924 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1925 cursor -= direction;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1926 if (pat[i] != *cursor)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1927 break;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1928 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1929 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1930 cursor += dirlen - i - direction; /* fix cursor */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1931 if (i + direction == 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1932 {
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
1933 EMACS_INT position, start, end;
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
1934
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1935 cursor -= direction;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1936
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1937 position = pos_byte + cursor - p2 + ((direction > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1938 ? 1 - len_byte : 0);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1939 set_search_regs (position, len_byte);
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
1940
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1941 if (NILP (Vinhibit_changing_match_data))
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1942 {
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1943 start = search_regs.start[0];
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1944 end = search_regs.end[0];
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1945 }
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1946 else
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1947 /* If Vinhibit_changing_match_data is non-nil,
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1948 search_regs will not be changed. So let's
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1949 compute start and end here. */
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1950 {
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1951 start = BYTE_TO_CHAR (position);
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1952 end = BYTE_TO_CHAR (position + len_byte);
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1953 }
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1954
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1955 if ((n -= direction) != 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1956 cursor += dirlen; /* to resume search */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1957 else
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
1958 return direction > 0 ? end : start;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1959 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1960 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1961 cursor += stride_for_teases; /* <sigh> we lose - */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1962 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1963 pos_byte += cursor - p2;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1964 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1965 else
102999
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1966 /* Now we'll pick up a clump that has to be done the hard
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1967 way because it covers a discontinuity. */
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1968 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1969 limit = ((direction > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1970 ? BUFFER_CEILING_OF (pos_byte - dirlen + 1)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1971 : BUFFER_FLOOR_OF (pos_byte - dirlen - 1));
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1972 limit = ((direction > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1973 ? min (limit + len_byte, lim_byte - 1)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1974 : max (limit - len_byte, lim_byte));
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1975 /* LIMIT is now the last value POS_BYTE can have
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1976 and still be valid for a possible match. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1977 while (1)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1978 {
102999
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1979 /* This loop can be coded for space rather than
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1980 speed because it will usually run only once.
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1981 (the reach is at most len + 21, and typically
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1982 does not exceed len). */
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1983 while ((limit - pos_byte) * direction >= 0)
102999
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1984 {
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1985 int ch = FETCH_BYTE (pos_byte);
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1986 if (BM_tab[ch] == 0)
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1987 goto hit2;
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1988 pos_byte += BM_tab[ch];
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1989 }
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1990 break; /* ran off the end */
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1991
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1992 hit2:
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
1993 /* Found what might be a match. */
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1994 i = dirlen - direction;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1995 while ((i -= direction) + direction != 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1996 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1997 int ch;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1998 unsigned char *ptr;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1999 pos_byte -= direction;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2000 ptr = BYTE_POS_ADDR (pos_byte);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2001 /* Translate only the last byte of a character. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2002 if (! multibyte
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2003 || ((ptr == tail_end_ptr
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2004 || CHAR_HEAD_P (ptr[1]))
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2005 && (CHAR_HEAD_P (ptr[0])
61189
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
2006 /* Check if this is the last byte of a
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
2007 translable character. */
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
2008 || (translate_prev_byte1 == ptr[-1]
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
2009 && (CHAR_HEAD_P (translate_prev_byte1)
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
2010 || (translate_prev_byte2 == ptr[-2]
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
2011 && (CHAR_HEAD_P (translate_prev_byte2)
91ba6c641a60 (looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents: 58567
diff changeset
2012 || translate_prev_byte3 == ptr[-3])))))))
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2013 ch = simple_translate[*ptr];
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2014 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2015 ch = *ptr;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2016 if (pat[i] != ch)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2017 break;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2018 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2019 /* Above loop has moved POS_BYTE part or all the way
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2020 back to the first pos (last pos if reverse).
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2021 Set it once again at the last (first if reverse) char. */
102999
4dbc3b20d83b (boyer_moore): Use zero as marker value for a possible
Andreas Schwab <schwab@linux-m68k.org>
parents: 102978
diff changeset
2022 pos_byte += dirlen - i - direction;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2023 if (i + direction == 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2024 {
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
2025 EMACS_INT position, start, end;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2026 pos_byte -= direction;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2027
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2028 position = pos_byte + ((direction > 0) ? 1 - len_byte : 0);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2029 set_search_regs (position, len_byte);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2030
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2031 if (NILP (Vinhibit_changing_match_data))
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2032 {
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2033 start = search_regs.start[0];
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2034 end = search_regs.end[0];
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2035 }
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2036 else
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2037 /* If Vinhibit_changing_match_data is non-nil,
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2038 search_regs will not be changed. So let's
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2039 compute start and end here. */
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2040 {
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2041 start = BYTE_TO_CHAR (position);
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2042 end = BYTE_TO_CHAR (position + len_byte);
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2043 }
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2044
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2045 if ((n -= direction) != 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2046 pos_byte += dirlen; /* to resume search */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2047 else
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2048 return direction > 0 ? end : start;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2049 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2050 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2051 pos_byte += stride_for_teases;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2052 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2053 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2054 /* We have done one clump. Can we continue? */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2055 if ((lim_byte - pos_byte) * direction < 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2056 return ((0 - n) * direction);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2057 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
2058 return BYTE_TO_CHAR (pos_byte);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2059 }
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
2060
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
2061 /* Record beginning BEG_BYTE and end BEG_BYTE + NBYTES
22082
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
2062 for the overall match just found in the current buffer.
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
2063 Also clear out the match data for registers 1 and up. */
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
2064
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
2065 static void
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
2066 set_search_regs (EMACS_INT beg_byte, EMACS_INT nbytes)
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
2067 {
22082
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
2068 int i;
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
2069
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2070 if (!NILP (Vinhibit_changing_match_data))
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2071 return;
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
2072
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
2073 /* Make sure we have registers in which to store
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
2074 the match position. */
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
2075 if (search_regs.num_regs == 0)
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
2076 {
10250
422c3b96efda (set_search_regs): Really set search_regs.start and .end.
Richard M. Stallman <rms@gnu.org>
parents: 10141
diff changeset
2077 search_regs.start = (regoff_t *) xmalloc (2 * sizeof (regoff_t));
422c3b96efda (set_search_regs): Really set search_regs.start and .end.
Richard M. Stallman <rms@gnu.org>
parents: 10141
diff changeset
2078 search_regs.end = (regoff_t *) xmalloc (2 * sizeof (regoff_t));
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
2079 search_regs.num_regs = 2;
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
2080 }
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
2081
22082
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
2082 /* Clear out the other registers. */
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
2083 for (i = 1; i < search_regs.num_regs; i++)
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
2084 {
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
2085 search_regs.start[i] = -1;
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
2086 search_regs.end[i] = -1;
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
2087 }
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
2088
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
2089 search_regs.start[0] = BYTE_TO_CHAR (beg_byte);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
2090 search_regs.end[0] = BYTE_TO_CHAR (beg_byte + nbytes);
9278
f2138d548313 (Flooking_at, skip_chars, search_buffer, set_search_regs, Fstore_match_data):
Karl Heuer <kwzh@gnu.org>
parents: 9113
diff changeset
2091 XSETBUFFER (last_thing_searched, current_buffer);
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
2092 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2093
98347
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2094 /* Given STRING, a string of words separated by word delimiters,
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2095 compute a regexp that matches those exact words separated by
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2096 arbitrary punctuation. If LAX is nonzero, the end of the string
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2097 need not match a word boundary unless it ends in whitespace. */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2098
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2099 static Lisp_Object
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
2100 wordify (Lisp_Object string, int lax)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2101 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2102 register unsigned char *p, *o;
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
2103 register EMACS_INT i, i_byte, len, punct_count = 0, word_count = 0;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2104 Lisp_Object val;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2105 int prev_c = 0;
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
2106 EMACS_INT adjust;
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
2107 int whitespace_at_end;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2108
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
2109 CHECK_STRING (string);
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
2110 p = SDATA (string);
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
2111 len = SCHARS (string);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2112
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2113 for (i = 0, i_byte = 0; i < len; )
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2114 {
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2115 int c;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
2116
89062
be059fb97bac (compile_pattern_1): Don't adjust the multibyteness of
Kenichi Handa <handa@m17n.org>
parents: 89028
diff changeset
2117 FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2118
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2119 if (SYNTAX (c) != Sword)
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2120 {
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2121 punct_count++;
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2122 if (i > 0 && SYNTAX (prev_c) == Sword)
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2123 word_count++;
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2124 }
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2125
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2126 prev_c = c;
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2127 }
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2128
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2129 if (SYNTAX (prev_c) == Sword)
98347
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2130 {
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2131 word_count++;
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2132 whitespace_at_end = 0;
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2133 }
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2134 else
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2135 whitespace_at_end = 1;
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2136
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2137 if (!word_count)
81279
326992131788 (wordify): Use empty_unibyte_string.
Juanma Barranquero <lekktu@gmail.com>
parents: 75227
diff changeset
2138 return empty_unibyte_string;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2139
98347
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2140 adjust = - punct_count + 5 * (word_count - 1)
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2141 + ((lax && !whitespace_at_end) ? 2 : 4);
22640
929ad308aba6 (wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents: 22533
diff changeset
2142 if (STRING_MULTIBYTE (string))
929ad308aba6 (wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents: 22533
diff changeset
2143 val = make_uninit_multibyte_string (len + adjust,
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
2144 SBYTES (string)
22640
929ad308aba6 (wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents: 22533
diff changeset
2145 + adjust);
929ad308aba6 (wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents: 22533
diff changeset
2146 else
929ad308aba6 (wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents: 22533
diff changeset
2147 val = make_uninit_string (len + adjust);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2148
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
2149 o = SDATA (val);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2150 *o++ = '\\';
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2151 *o++ = 'b';
21887
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2152 prev_c = 0;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2153
21887
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2154 for (i = 0, i_byte = 0; i < len; )
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2155 {
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2156 int c;
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
2157 EMACS_INT i_byte_orig = i_byte;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
2158
89062
be059fb97bac (compile_pattern_1): Don't adjust the multibyteness of
Kenichi Handa <handa@m17n.org>
parents: 89028
diff changeset
2159 FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte);
21887
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2160
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2161 if (SYNTAX (c) == Sword)
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2162 {
109165
750db9f3e6d8 Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents: 109126
diff changeset
2163 memcpy (o, SDATA (string) + i_byte_orig, i_byte - i_byte_orig);
21887
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2164 o += i_byte - i_byte_orig;
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2165 }
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2166 else if (i > 0 && SYNTAX (prev_c) == Sword && --word_count)
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2167 {
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2168 *o++ = '\\';
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2169 *o++ = 'W';
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2170 *o++ = '\\';
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2171 *o++ = 'W';
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2172 *o++ = '*';
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2173 }
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2174
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2175 prev_c = c;
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
2176 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2177
98347
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2178 if (!lax || whitespace_at_end)
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2179 {
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2180 *o++ = '\\';
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2181 *o++ = 'b';
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2182 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2183
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2184 return val;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2185 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2186
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2187 DEFUN ("search-backward", Fsearch_backward, Ssearch_backward, 1, 4,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2188 "MSearch backward: ",
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2189 doc: /* Search backward from point for STRING.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2190 Set point to the beginning of the occurrence found, and return point.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2191 An optional second argument bounds the search; it is a buffer position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2192 The match found must not extend before that position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2193 Optional third argument, if t, means if fail just return nil (no error).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2194 If not nil and not t, position at limit of search and return nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2195 Optional fourth argument is repeat count--search for successive occurrences.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2196
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2197 Search case-sensitivity is determined by the value of the variable
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2198 `case-fold-search', which see.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2199
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2200 See also the functions `match-beginning', `match-end' and `replace-match'. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
2201 (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2202 {
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2203 return search_command (string, bound, noerror, count, -1, 0, 0);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2204 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2205
19541
e7876a076881 (Fsearch_backward): Inherit the current input method on
Kenichi Handa <handa@m17n.org>
parents: 18762
diff changeset
2206 DEFUN ("search-forward", Fsearch_forward, Ssearch_forward, 1, 4, "MSearch: ",
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2207 doc: /* Search forward from point for STRING.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2208 Set point to the end of the occurrence found, and return point.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2209 An optional second argument bounds the search; it is a buffer position.
74917
898edc583814 (Fsearch_forward): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 74756
diff changeset
2210 The match found must not extend after that position. A value of nil is
74756
c751765838ca (Fsearch_forward): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 74033
diff changeset
2211 equivalent to (point-max).
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2212 Optional third argument, if t, means if fail just return nil (no error).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2213 If not nil and not t, move to limit of search and return nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2214 Optional fourth argument is repeat count--search for successive occurrences.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2215
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2216 Search case-sensitivity is determined by the value of the variable
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2217 `case-fold-search', which see.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2218
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2219 See also the functions `match-beginning', `match-end' and `replace-match'. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
2220 (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2221 {
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2222 return search_command (string, bound, noerror, count, 1, 0, 0);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2223 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2224
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2225 DEFUN ("word-search-backward", Fword_search_backward, Sword_search_backward, 1, 4,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2226 "sWord search backward: ",
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2227 doc: /* Search backward from point for STRING, ignoring differences in punctuation.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2228 Set point to the beginning of the occurrence found, and return point.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2229 An optional second argument bounds the search; it is a buffer position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2230 The match found must not extend before that position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2231 Optional third argument, if t, means if fail just return nil (no error).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2232 If not nil and not t, move to limit of search and return nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2233 Optional fourth argument is repeat count--search for successive occurrences. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
2234 (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2235 {
98347
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2236 return search_command (wordify (string, 0), bound, noerror, count, -1, 1, 0);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2237 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2238
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2239 DEFUN ("word-search-forward", Fword_search_forward, Sword_search_forward, 1, 4,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2240 "sWord search: ",
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2241 doc: /* Search forward from point for STRING, ignoring differences in punctuation.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2242 Set point to the end of the occurrence found, and return point.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2243 An optional second argument bounds the search; it is a buffer position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2244 The match found must not extend after that position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2245 Optional third argument, if t, means if fail just return nil (no error).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2246 If not nil and not t, move to limit of search and return nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2247 Optional fourth argument is repeat count--search for successive occurrences. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
2248 (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2249 {
98347
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2250 return search_command (wordify (string, 0), bound, noerror, count, 1, 1, 0);
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2251 }
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2252
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2253 DEFUN ("word-search-backward-lax", Fword_search_backward_lax, Sword_search_backward_lax, 1, 4,
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2254 "sWord search backward: ",
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2255 doc: /* Search backward from point for STRING, ignoring differences in punctuation.
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2256 Set point to the beginning of the occurrence found, and return point.
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2257
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2258 Unlike `word-search-backward', the end of STRING need not match a word
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2259 boundary unless it ends in whitespace.
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2260
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2261 An optional second argument bounds the search; it is a buffer position.
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2262 The match found must not extend before that position.
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2263 Optional third argument, if t, means if fail just return nil (no error).
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2264 If not nil and not t, move to limit of search and return nil.
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2265 Optional fourth argument is repeat count--search for successive occurrences. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
2266 (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
98347
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2267 {
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2268 return search_command (wordify (string, 1), bound, noerror, count, -1, 1, 0);
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2269 }
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2270
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2271 DEFUN ("word-search-forward-lax", Fword_search_forward_lax, Sword_search_forward_lax, 1, 4,
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2272 "sWord search: ",
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2273 doc: /* Search forward from point for STRING, ignoring differences in punctuation.
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2274 Set point to the end of the occurrence found, and return point.
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2275
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2276 Unlike `word-search-forward', the end of STRING need not match a word
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2277 boundary unless it ends in whitespace.
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2278
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2279 An optional second argument bounds the search; it is a buffer position.
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2280 The match found must not extend after that position.
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2281 Optional third argument, if t, means if fail just return nil (no error).
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2282 If not nil and not t, move to limit of search and return nil.
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2283 Optional fourth argument is repeat count--search for successive occurrences. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
2284 (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
98347
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2285 {
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
2286 return search_command (wordify (string, 1), bound, noerror, count, 1, 1, 0);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2287 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2288
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2289 DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2290 "sRE search backward: ",
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2291 doc: /* Search backward from point for match for regular expression REGEXP.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2292 Set point to the beginning of the match, and return point.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2293 The match found is the one starting last in the buffer
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2294 and yet ending before the origin of the search.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2295 An optional second argument bounds the search; it is a buffer position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2296 The match found must start at or after that position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2297 Optional third argument, if t, means if fail just return nil (no error).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2298 If not nil and not t, move to limit of search and return nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2299 Optional fourth argument is repeat count--search for successive occurrences.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2300 See also the functions `match-beginning', `match-end', `match-string',
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2301 and `replace-match'. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
2302 (Lisp_Object regexp, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2303 {
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2304 return search_command (regexp, bound, noerror, count, -1, 1, 0);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2305 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2306
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2307 DEFUN ("re-search-forward", Fre_search_forward, Sre_search_forward, 1, 4,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2308 "sRE search: ",
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2309 doc: /* Search forward from point for regular expression REGEXP.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2310 Set point to the end of the occurrence found, and return point.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2311 An optional second argument bounds the search; it is a buffer position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2312 The match found must not extend after that position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2313 Optional third argument, if t, means if fail just return nil (no error).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2314 If not nil and not t, move to limit of search and return nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2315 Optional fourth argument is repeat count--search for successive occurrences.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2316 See also the functions `match-beginning', `match-end', `match-string',
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2317 and `replace-match'. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
2318 (Lisp_Object regexp, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2319 {
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2320 return search_command (regexp, bound, noerror, count, 1, 1, 0);
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2321 }
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2322
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2323 DEFUN ("posix-search-backward", Fposix_search_backward, Sposix_search_backward, 1, 4,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2324 "sPosix search backward: ",
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2325 doc: /* Search backward from point for match for regular expression REGEXP.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2326 Find the longest match in accord with Posix regular expression rules.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2327 Set point to the beginning of the match, and return point.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2328 The match found is the one starting last in the buffer
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2329 and yet ending before the origin of the search.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2330 An optional second argument bounds the search; it is a buffer position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2331 The match found must start at or after that position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2332 Optional third argument, if t, means if fail just return nil (no error).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2333 If not nil and not t, move to limit of search and return nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2334 Optional fourth argument is repeat count--search for successive occurrences.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2335 See also the functions `match-beginning', `match-end', `match-string',
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2336 and `replace-match'. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
2337 (Lisp_Object regexp, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2338 {
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2339 return search_command (regexp, bound, noerror, count, -1, 1, 1);
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2340 }
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2341
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2342 DEFUN ("posix-search-forward", Fposix_search_forward, Sposix_search_forward, 1, 4,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2343 "sPosix search: ",
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2344 doc: /* Search forward from point for regular expression REGEXP.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2345 Find the longest match in accord with Posix regular expression rules.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2346 Set point to the end of the occurrence found, and return point.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2347 An optional second argument bounds the search; it is a buffer position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2348 The match found must not extend after that position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2349 Optional third argument, if t, means if fail just return nil (no error).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2350 If not nil and not t, move to limit of search and return nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2351 Optional fourth argument is repeat count--search for successive occurrences.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2352 See also the functions `match-beginning', `match-end', `match-string',
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2353 and `replace-match'. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
2354 (Lisp_Object regexp, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2355 {
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2356 return search_command (regexp, bound, noerror, count, 1, 1, 1);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2357 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2358
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2359 DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 5, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2360 doc: /* Replace text matched by last search with NEWTEXT.
45217
4383b69f181b (Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 41389
diff changeset
2361 Leave point at the end of the replacement text.
4383b69f181b (Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 41389
diff changeset
2362
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2363 If second arg FIXEDCASE is non-nil, do not alter case of replacement text.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2364 Otherwise maybe capitalize the whole text, or maybe just word initials,
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2365 based on the replaced text.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2366 If the replaced text has only capital letters
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2367 and has at least one multiletter word, convert NEWTEXT to all caps.
45217
4383b69f181b (Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 41389
diff changeset
2368 Otherwise if all words are capitalized in the replaced text,
4383b69f181b (Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 41389
diff changeset
2369 capitalize each word in NEWTEXT.
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2370
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2371 If third arg LITERAL is non-nil, insert NEWTEXT literally.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2372 Otherwise treat `\\' as special:
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2373 `\\&' in NEWTEXT means substitute original matched text.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2374 `\\N' means substitute what matched the Nth `\\(...\\)'.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2375 If Nth parens didn't match, substitute nothing.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2376 `\\\\' means insert one `\\'.
45217
4383b69f181b (Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 41389
diff changeset
2377 Case conversion does not apply to these substitutions.
4383b69f181b (Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 41389
diff changeset
2378
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2379 FIXEDCASE and LITERAL are optional arguments.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2380
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2381 The optional fourth argument STRING can be a string to modify.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2382 This is meaningful when the previous match was done against STRING,
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2383 using `string-match'. When used this way, `replace-match'
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2384 creates and returns a new string made by copying STRING and replacing
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2385 the part of STRING that was matched.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2386
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2387 The optional fifth argument SUBEXP specifies a subexpression;
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2388 it says to replace just that subexpression with NEWTEXT,
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2389 rather than replacing the entire matched text.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2390 This is, in a vague sense, the inverse of using `\\N' in NEWTEXT;
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2391 `\\N' copies subexp N into NEWTEXT, but using N as SUBEXP puts
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2392 NEWTEXT in place of subexp N.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2393 This is useful only after a regular expression search or match,
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2394 since only regular expressions have distinguished subexpressions. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
2395 (Lisp_Object newtext, Lisp_Object fixedcase, Lisp_Object literal, Lisp_Object string, Lisp_Object subexp)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2396 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2397 enum { nochange, all_caps, cap_initial } case_action;
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
2398 register EMACS_INT pos, pos_byte;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2399 int some_multiletter_word;
2393
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2400 int some_lowercase;
7674
947d24fefd9e (Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents: 7673
diff changeset
2401 int some_uppercase;
8526
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2402 int some_nonuppercase_initial;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2403 register int c, prevc;
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2404 int sub;
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
2405 EMACS_INT opoint, newpoint;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2406
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
2407 CHECK_STRING (newtext);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2408
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2409 if (! NILP (string))
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
2410 CHECK_STRING (string);
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2411
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2412 case_action = nochange; /* We tried an initialization */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2413 /* but some C compilers blew it */
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2414
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2415 if (search_regs.num_regs <= 0)
63702
6d4accecc80c (Freplace_match): Follow error conventions.
Juanma Barranquero <lekktu@gmail.com>
parents: 63666
diff changeset
2416 error ("`replace-match' called before any match found");
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2417
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2418 if (NILP (subexp))
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2419 sub = 0;
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2420 else
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2421 {
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
2422 CHECK_NUMBER (subexp);
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2423 sub = XINT (subexp);
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2424 if (sub < 0 || sub >= search_regs.num_regs)
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2425 args_out_of_range (subexp, make_number (search_regs.num_regs));
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2426 }
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2427
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2428 if (NILP (string))
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2429 {
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2430 if (search_regs.start[sub] < BEGV
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2431 || search_regs.start[sub] > search_regs.end[sub]
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2432 || search_regs.end[sub] > ZV)
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2433 args_out_of_range (make_number (search_regs.start[sub]),
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2434 make_number (search_regs.end[sub]));
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2435 }
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2436 else
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2437 {
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2438 if (search_regs.start[sub] < 0
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2439 || search_regs.start[sub] > search_regs.end[sub]
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
2440 || search_regs.end[sub] > SCHARS (string))
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2441 args_out_of_range (make_number (search_regs.start[sub]),
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2442 make_number (search_regs.end[sub]));
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2443 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2444
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2445 if (NILP (fixedcase))
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2446 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2447 /* Decide how to casify by examining the matched text. */
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
2448 EMACS_INT last;
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2449
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2450 pos = search_regs.start[sub];
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2451 last = search_regs.end[sub];
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2452
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
2453 if (NILP (string))
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2454 pos_byte = CHAR_TO_BYTE (pos);
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
2455 else
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2456 pos_byte = string_char_to_byte (string, pos);
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
2457
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2458 prevc = '\n';
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2459 case_action = all_caps;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2460
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2461 /* some_multiletter_word is set nonzero if any original word
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2462 is more than one letter long. */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2463 some_multiletter_word = 0;
2393
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2464 some_lowercase = 0;
8526
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2465 some_nonuppercase_initial = 0;
7674
947d24fefd9e (Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents: 7673
diff changeset
2466 some_uppercase = 0;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2467
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2468 while (pos < last)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2469 {
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2470 if (NILP (string))
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2471 {
89062
be059fb97bac (compile_pattern_1): Don't adjust the multibyteness of
Kenichi Handa <handa@m17n.org>
parents: 89028
diff changeset
2472 c = FETCH_CHAR_AS_MULTIBYTE (pos_byte);
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2473 INC_BOTH (pos, pos_byte);
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2474 }
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2475 else
89062
be059fb97bac (compile_pattern_1): Don't adjust the multibyteness of
Kenichi Handa <handa@m17n.org>
parents: 89028
diff changeset
2476 FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, pos, pos_byte);
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2477
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2478 if (LOWERCASEP (c))
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2479 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2480 /* Cannot be all caps if any original char is lower case */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2481
2393
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2482 some_lowercase = 1;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2483 if (SYNTAX (prevc) != Sword)
8526
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2484 some_nonuppercase_initial = 1;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2485 else
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2486 some_multiletter_word = 1;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2487 }
68200
5fc4d9faaa2f (Freplace_match): Use UPPERCASEP instead of !NOCASEP.
Andreas Schwab <schwab@suse.de>
parents: 66751
diff changeset
2488 else if (UPPERCASEP (c))
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2489 {
7674
947d24fefd9e (Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents: 7673
diff changeset
2490 some_uppercase = 1;
2393
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2491 if (SYNTAX (prevc) != Sword)
6679
490b7e2db978 (Freplace_match): Don't capitalize unless all matched words are capitalized.
Karl Heuer <kwzh@gnu.org>
parents: 6543
diff changeset
2492 ;
2393
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2493 else
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2494 some_multiletter_word = 1;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2495 }
8526
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2496 else
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2497 {
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2498 /* If the initial is a caseless word constituent,
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2499 treat that like a lowercase initial. */
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2500 if (SYNTAX (prevc) != Sword)
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2501 some_nonuppercase_initial = 1;
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2502 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2503
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2504 prevc = c;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2505 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2506
2393
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2507 /* Convert to all caps if the old text is all caps
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2508 and has at least one multiletter word. */
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2509 if (! some_lowercase && some_multiletter_word)
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2510 case_action = all_caps;
6679
490b7e2db978 (Freplace_match): Don't capitalize unless all matched words are capitalized.
Karl Heuer <kwzh@gnu.org>
parents: 6543
diff changeset
2511 /* Capitalize each word, if the old text has all capitalized words. */
8526
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2512 else if (!some_nonuppercase_initial && some_multiletter_word)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2513 case_action = cap_initial;
8526
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2514 else if (!some_nonuppercase_initial && some_uppercase)
7674
947d24fefd9e (Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents: 7673
diff changeset
2515 /* Should x -> yz, operating on X, give Yz or YZ?
947d24fefd9e (Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents: 7673
diff changeset
2516 We'll assume the latter. */
947d24fefd9e (Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents: 7673
diff changeset
2517 case_action = all_caps;
2393
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2518 else
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2519 case_action = nochange;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2520 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2521
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2522 /* Do replacement in a string. */
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2523 if (!NILP (string))
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2524 {
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2525 Lisp_Object before, after;
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2526
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2527 before = Fsubstring (string, make_number (0),
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2528 make_number (search_regs.start[sub]));
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2529 after = Fsubstring (string, make_number (search_regs.end[sub]), Qnil);
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2530
17225
739e41eed8b6 (Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents: 17102
diff changeset
2531 /* Substitute parts of the match into NEWTEXT
739e41eed8b6 (Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents: 17102
diff changeset
2532 if desired. */
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2533 if (NILP (literal))
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2534 {
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
2535 EMACS_INT lastpos = 0;
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
2536 EMACS_INT lastpos_byte = 0;
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2537 /* We build up the substituted string in ACCUM. */
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2538 Lisp_Object accum;
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2539 Lisp_Object middle;
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
2540 int length = SBYTES (newtext);
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2541
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2542 accum = Qnil;
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2543
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2544 for (pos_byte = 0, pos = 0; pos_byte < length;)
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2545 {
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
2546 EMACS_INT substart = -1;
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
2547 EMACS_INT subend = 0;
12148
a1c38b9b0f73 (Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents: 12147
diff changeset
2548 int delbackslash = 0;
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2549
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2550 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte);
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2551
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2552 if (c == '\\')
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2553 {
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2554 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte);
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
2555
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2556 if (c == '&')
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2557 {
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2558 substart = search_regs.start[sub];
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2559 subend = search_regs.end[sub];
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2560 }
53719
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2561 else if (c >= '1' && c <= '9')
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2562 {
53719
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2563 if (search_regs.start[c - '0'] >= 0
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2564 && c <= search_regs.num_regs + '0')
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2565 {
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2566 substart = search_regs.start[c - '0'];
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2567 subend = search_regs.end[c - '0'];
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2568 }
53719
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2569 else
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2570 {
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2571 /* If that subexp did not match,
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2572 replace \\N with nothing. */
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2573 substart = 0;
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2574 subend = 0;
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2575 }
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2576 }
12148
a1c38b9b0f73 (Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents: 12147
diff changeset
2577 else if (c == '\\')
a1c38b9b0f73 (Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents: 12147
diff changeset
2578 delbackslash = 1;
17225
739e41eed8b6 (Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents: 17102
diff changeset
2579 else
739e41eed8b6 (Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents: 17102
diff changeset
2580 error ("Invalid use of `\\' in replacement text");
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2581 }
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2582 if (substart >= 0)
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2583 {
21988
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2584 if (pos - 2 != lastpos)
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2585 middle = substring_both (newtext, lastpos,
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2586 lastpos_byte,
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2587 pos - 2, pos_byte - 2);
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2588 else
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2589 middle = Qnil;
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2590 accum = concat3 (accum, middle,
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2591 Fsubstring (string,
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2592 make_number (substart),
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2593 make_number (subend)));
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2594 lastpos = pos;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2595 lastpos_byte = pos_byte;
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2596 }
12148
a1c38b9b0f73 (Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents: 12147
diff changeset
2597 else if (delbackslash)
a1c38b9b0f73 (Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents: 12147
diff changeset
2598 {
21988
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2599 middle = substring_both (newtext, lastpos,
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2600 lastpos_byte,
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2601 pos - 1, pos_byte - 1);
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2602
12148
a1c38b9b0f73 (Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents: 12147
diff changeset
2603 accum = concat2 (accum, middle);
a1c38b9b0f73 (Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents: 12147
diff changeset
2604 lastpos = pos;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2605 lastpos_byte = pos_byte;
12148
a1c38b9b0f73 (Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents: 12147
diff changeset
2606 }
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2607 }
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2608
21988
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2609 if (pos != lastpos)
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2610 middle = substring_both (newtext, lastpos,
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2611 lastpos_byte,
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2612 pos, pos_byte);
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2613 else
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2614 middle = Qnil;
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2615
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2616 newtext = concat2 (accum, middle);
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2617 }
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2618
17225
739e41eed8b6 (Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents: 17102
diff changeset
2619 /* Do case substitution in NEWTEXT if desired. */
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2620 if (case_action == all_caps)
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2621 newtext = Fupcase (newtext);
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2622 else if (case_action == cap_initial)
12092
b932b2ed40f5 (Freplace_match): Calls to upcase_initials and upcase_initials_region changed
Karl Heuer <kwzh@gnu.org>
parents: 12069
diff changeset
2623 newtext = Fupcase_initials (newtext);
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2624
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2625 return concat3 (before, newtext, after);
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2626 }
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2627
39487
b21317213c81 (trivial_regexp_p): Catch \{N,M\} as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 35831
diff changeset
2628 /* Record point, then move (quietly) to the start of the match. */
23790
c1dbb92db43e (Freplace_match): Set OPOINT clearly for the case
Richard M. Stallman <rms@gnu.org>
parents: 22640
diff changeset
2629 if (PT >= search_regs.end[sub])
18077
27a0ced43e7e (Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents: 17463
diff changeset
2630 opoint = PT - ZV;
23790
c1dbb92db43e (Freplace_match): Set OPOINT clearly for the case
Richard M. Stallman <rms@gnu.org>
parents: 22640
diff changeset
2631 else if (PT > search_regs.start[sub])
c1dbb92db43e (Freplace_match): Set OPOINT clearly for the case
Richard M. Stallman <rms@gnu.org>
parents: 22640
diff changeset
2632 opoint = search_regs.end[sub] - ZV;
18077
27a0ced43e7e (Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents: 17463
diff changeset
2633 else
27a0ced43e7e (Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents: 17463
diff changeset
2634 opoint = PT;
27a0ced43e7e (Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents: 17463
diff changeset
2635
40922
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2636 /* If we want non-literal replacement,
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2637 perform substitution on the replacement string. */
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2638 if (NILP (literal))
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2639 {
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
2640 EMACS_INT length = SBYTES (newtext);
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2641 unsigned char *substed;
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
2642 EMACS_INT substed_alloc_size, substed_len;
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2643 int buf_multibyte = !NILP (current_buffer->enable_multibyte_characters);
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2644 int str_multibyte = STRING_MULTIBYTE (newtext);
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2645 Lisp_Object rev_tbl;
40922
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2646 int really_changed = 0;
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2647
89483
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
2648 rev_tbl = Qnil;
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2649
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2650 substed_alloc_size = length * 2 + 100;
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2651 substed = (unsigned char *) xmalloc (substed_alloc_size + 1);
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2652 substed_len = 0;
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2653
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2654 /* Go thru NEWTEXT, producing the actual text to insert in
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2655 SUBSTED while adjusting multibyteness to that of the current
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2656 buffer. */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2657
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2658 for (pos_byte = 0, pos = 0; pos_byte < length;)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2659 {
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2660 unsigned char str[MAX_MULTIBYTE_LENGTH];
109726
64732fa6188a Use const char* instead of char*.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109637
diff changeset
2661 const unsigned char *add_stuff = NULL;
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
2662 EMACS_INT add_len = 0;
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2663 int idx = -1;
2655
594a33ffed85 * search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents: 2475
diff changeset
2664
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2665 if (str_multibyte)
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2666 {
29018
2f43c508a9b5 (wordify): Use FETCH_STRING_CHAR_ADVANCE
Kenichi Handa <handa@m17n.org>
parents: 28886
diff changeset
2667 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, newtext, pos, pos_byte);
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2668 if (!buf_multibyte)
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2669 c = multibyte_char_to_unibyte (c, rev_tbl);
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2670 }
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2671 else
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2672 {
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2673 /* Note that we don't have to increment POS. */
46432
a4697b0a338e * search.c (wordify): Use SDATA.
Ken Raeburn <raeburn@raeburn.org>
parents: 46370
diff changeset
2674 c = SREF (newtext, pos_byte++);
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2675 if (buf_multibyte)
105661
bac26aa40069 Remove leftover table unibyte_to_multibyte_table.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 105401
diff changeset
2676 MAKE_CHAR_MULTIBYTE (c);
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2677 }
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2678
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2679 /* Either set ADD_STUFF and ADD_LEN to the text to put in SUBSTED,
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2680 or set IDX to a match index, which means put that part
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2681 of the buffer text into SUBSTED. */
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2682
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2683 if (c == '\\')
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2684 {
40922
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2685 really_changed = 1;
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2686
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2687 if (str_multibyte)
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2688 {
29018
2f43c508a9b5 (wordify): Use FETCH_STRING_CHAR_ADVANCE
Kenichi Handa <handa@m17n.org>
parents: 28886
diff changeset
2689 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, newtext,
2f43c508a9b5 (wordify): Use FETCH_STRING_CHAR_ADVANCE
Kenichi Handa <handa@m17n.org>
parents: 28886
diff changeset
2690 pos, pos_byte);
89213
b0d3fa30523c (Freplace_match): Check C by ASCII_CHAR_P, not by
Kenichi Handa <handa@m17n.org>
parents: 89130
diff changeset
2691 if (!buf_multibyte && !ASCII_CHAR_P (c))
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2692 c = multibyte_char_to_unibyte (c, rev_tbl);
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2693 }
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2694 else
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2695 {
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
2696 c = SREF (newtext, pos_byte++);
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2697 if (buf_multibyte)
105661
bac26aa40069 Remove leftover table unibyte_to_multibyte_table.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 105401
diff changeset
2698 MAKE_CHAR_MULTIBYTE (c);
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2699 }
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2700
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2701 if (c == '&')
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2702 idx = sub;
7856
9687141f6264 (Freplace_match): Be sure not to treat non-digit like digit.
Richard M. Stallman <rms@gnu.org>
parents: 7674
diff changeset
2703 else if (c >= '1' && c <= '9' && c <= search_regs.num_regs + '0')
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2704 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2705 if (search_regs.start[c - '0'] >= 1)
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2706 idx = c - '0';
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2707 }
17225
739e41eed8b6 (Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents: 17102
diff changeset
2708 else if (c == '\\')
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2709 add_len = 1, add_stuff = "\\";
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2710 else
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2711 {
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2712 xfree (substed);
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2713 error ("Invalid use of `\\' in replacement text");
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2714 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2715 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2716 else
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2717 {
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2718 add_len = CHAR_STRING (c, str);
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2719 add_stuff = str;
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2720 }
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2721
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2722 /* If we want to copy part of a previous match,
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2723 set up ADD_STUFF and ADD_LEN to point to it. */
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2724 if (idx >= 0)
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2725 {
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
2726 EMACS_INT begbyte = CHAR_TO_BYTE (search_regs.start[idx]);
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2727 add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte;
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2728 if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx])
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2729 move_gap (search_regs.start[idx]);
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2730 add_stuff = BYTE_POS_ADDR (begbyte);
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2731 }
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2732
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2733 /* Now the stuff we want to add to SUBSTED
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2734 is invariably ADD_LEN bytes starting at ADD_STUFF. */
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2735
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2736 /* Make sure SUBSTED is big enough. */
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2737 if (substed_len + add_len >= substed_alloc_size)
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2738 {
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2739 substed_alloc_size = substed_len + add_len + 500;
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2740 substed = (unsigned char *) xrealloc (substed,
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2741 substed_alloc_size + 1);
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2742 }
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2743
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2744 /* Now add to the end of SUBSTED. */
28886
3f60536745bd (Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents: 28507
diff changeset
2745 if (add_stuff)
3f60536745bd (Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents: 28507
diff changeset
2746 {
109165
750db9f3e6d8 Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents: 109126
diff changeset
2747 memcpy (substed + substed_len, add_stuff, add_len);
28886
3f60536745bd (Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents: 28507
diff changeset
2748 substed_len += add_len;
3f60536745bd (Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents: 28507
diff changeset
2749 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2750 }
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2751
40922
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2752 if (really_changed)
53587
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2753 {
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2754 if (buf_multibyte)
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2755 {
110507
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
2756 EMACS_INT nchars =
875202ac5b45 Fix use of int instead of EMACS_INT in search.c and region-cache.c.
Eli Zaretskii <eliz@gnu.org>
parents: 109726
diff changeset
2757 multibyte_chars_in_text (substed, substed_len);
53587
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2758
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2759 newtext = make_multibyte_string (substed, nchars, substed_len);
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2760 }
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2761 else
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2762 newtext = make_unibyte_string (substed, substed_len);
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2763 }
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2764 xfree (substed);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2765 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2766
40922
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2767 /* Replace the old text with the new in the cleanest possible way. */
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2768 replace_range (search_regs.start[sub], search_regs.end[sub],
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2769 newtext, 1, 0, 1);
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
2770 newpoint = search_regs.start[sub] + SCHARS (newtext);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2771
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2772 if (case_action == all_caps)
40922
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2773 Fupcase_region (make_number (search_regs.start[sub]),
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2774 make_number (newpoint));
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2775 else if (case_action == cap_initial)
40922
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2776 Fupcase_initials_region (make_number (search_regs.start[sub]),
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2777 make_number (newpoint));
18081
300068b4fcef (Freplace_match): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 18077
diff changeset
2778
47686
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2779 /* Adjust search data for this change. */
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2780 {
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
2781 EMACS_INT oldend = search_regs.end[sub];
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
2782 EMACS_INT oldstart = search_regs.start[sub];
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
2783 EMACS_INT change = newpoint - search_regs.end[sub];
47686
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2784 int i;
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2785
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2786 for (i = 0; i < search_regs.num_regs; i++)
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2787 {
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2788 if (search_regs.start[i] >= oldend)
47686
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2789 search_regs.start[i] += change;
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2790 else if (search_regs.start[i] > oldstart)
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2791 search_regs.start[i] = oldstart;
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2792 if (search_regs.end[i] >= oldend)
47686
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2793 search_regs.end[i] += change;
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2794 else if (search_regs.end[i] > oldstart)
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2795 search_regs.end[i] = oldstart;
47686
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2796 }
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2797 }
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2798
18077
27a0ced43e7e (Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents: 17463
diff changeset
2799 /* Put point back where it was in the text. */
18124
6f2c80d2425a (Freplace_match): If opoint is 0, that's relative to ZV.
Richard M. Stallman <rms@gnu.org>
parents: 18112
diff changeset
2800 if (opoint <= 0)
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
2801 TEMP_SET_PT (opoint + ZV);
18077
27a0ced43e7e (Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents: 17463
diff changeset
2802 else
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
2803 TEMP_SET_PT (opoint);
18077
27a0ced43e7e (Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents: 17463
diff changeset
2804
27a0ced43e7e (Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents: 17463
diff changeset
2805 /* Now move point "officially" to the start of the inserted replacement. */
18081
300068b4fcef (Freplace_match): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 18077
diff changeset
2806 move_if_not_intangible (newpoint);
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
2807
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2808 return Qnil;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2809 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2810
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2811 static Lisp_Object
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
2812 match_limit (Lisp_Object num, int beginningp)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2813 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2814 register int n;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2815
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
2816 CHECK_NUMBER (num);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2817 n = XINT (num);
56175
b53351ef3125 (match_limit): Cleaner err msg when no match data available.
Richard M. Stallman <rms@gnu.org>
parents: 56022
diff changeset
2818 if (n < 0)
56294
aaa6a4ecea38 (match_limit, Fmatch_data, Fset_match_data): YAILOM.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 56276
diff changeset
2819 args_out_of_range (num, make_number (0));
56175
b53351ef3125 (match_limit): Cleaner err msg when no match data available.
Richard M. Stallman <rms@gnu.org>
parents: 56022
diff changeset
2820 if (search_regs.num_regs <= 0)
b53351ef3125 (match_limit): Cleaner err msg when no match data available.
Richard M. Stallman <rms@gnu.org>
parents: 56022
diff changeset
2821 error ("No match data, because no search succeeded");
56022
e63446aad5a3 (match_limit): Don't flag an error if match-data
David Kastrup <dak@gnu.org>
parents: 55689
diff changeset
2822 if (n >= search_regs.num_regs
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2823 || search_regs.start[n] < 0)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2824 return Qnil;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2825 return (make_number ((beginningp) ? search_regs.start[n]
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2826 : search_regs.end[n]));
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2827 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2828
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2829 DEFUN ("match-beginning", Fmatch_beginning, Smatch_beginning, 1, 1, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2830 doc: /* Return position of start of text matched by last search.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2831 SUBEXP, a number, specifies which parenthesized expression in the last
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2832 regexp.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2833 Value is nil if SUBEXPth pair didn't match, or there were less than
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2834 SUBEXP pairs.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2835 Zero means the entire text matched by the whole regexp or whole string. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
2836 (Lisp_Object subexp)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2837 {
14086
a410808fda15 (Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
2838 return match_limit (subexp, 1);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2839 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2840
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2841 DEFUN ("match-end", Fmatch_end, Smatch_end, 1, 1, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2842 doc: /* Return position of end of text matched by last search.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2843 SUBEXP, a number, specifies which parenthesized expression in the last
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2844 regexp.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2845 Value is nil if SUBEXPth pair didn't match, or there were less than
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2846 SUBEXP pairs.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2847 Zero means the entire text matched by the whole regexp or whole string. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
2848 (Lisp_Object subexp)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2849 {
14086
a410808fda15 (Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
2850 return match_limit (subexp, 0);
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
2851 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2852
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2853 DEFUN ("match-data", Fmatch_data, Smatch_data, 0, 3, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2854 doc: /* Return a list containing all info on what the last search matched.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2855 Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2856 All the elements are markers or nil (nil if the Nth pair didn't match)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2857 if the last match was on a buffer; integers or nil if a string was matched.
102978
ff07912acca7 (match-data): Refer to `set-match-data' rather than `store-match-data'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101966
diff changeset
2858 Use `set-match-data' to reinstate the data in this list.
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2859
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2860 If INTEGERS (the optional first argument) is non-nil, always use
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2861 integers \(rather than markers) to represent buffer positions. In
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2862 this case, and if the last match was in a buffer, the buffer will get
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2863 stored as one additional element at the end of the list.
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2864
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2865 If REUSE is a list, reuse it as part of the value. If REUSE is long
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2866 enough to hold all the values, and if INTEGERS is non-nil, no consing
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2867 is done.
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2868
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2869 If optional third arg RESEAT is non-nil, any previous markers on the
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2870 REUSE list will be modified to point to nowhere.
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2871
49761
3d562e7ebf97 (Fmatch_data): Doc fix. Explicitly state that
Kim F. Storm <storm@cua.dk>
parents: 49600
diff changeset
2872 Return value is undefined if the last search failed. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
2873 (Lisp_Object integers, Lisp_Object reuse, Lisp_Object reseat)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2874 {
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2875 Lisp_Object tail, prev;
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2876 Lisp_Object *data;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2877 int i, len;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2878
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2879 if (!NILP (reseat))
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2880 for (tail = reuse; CONSP (tail); tail = XCDR (tail))
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2881 if (MARKERP (XCAR (tail)))
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2882 {
63666
e0dd6fa42c85 (Fmatch_data): Remove evaporate option.
Kim F. Storm <storm@cua.dk>
parents: 63152
diff changeset
2883 unchain_marker (XMARKER (XCAR (tail)));
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2884 XSETCAR (tail, Qnil);
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2885 }
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2886
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2887 if (NILP (last_thing_searched))
15667
9531c03134b6 (Fmatch_data): If no matching done yet, return Qnil.
Karl Heuer <kwzh@gnu.org>
parents: 14186
diff changeset
2888 return Qnil;
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2889
31829
43566b0aec59 Avoid some more compiler warnings.
Gerd Moellmann <gerd@gnu.org>
parents: 31486
diff changeset
2890 prev = Qnil;
43566b0aec59 Avoid some more compiler warnings.
Gerd Moellmann <gerd@gnu.org>
parents: 31486
diff changeset
2891
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2892 data = (Lisp_Object *) alloca ((2 * search_regs.num_regs + 1)
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2893 * sizeof (Lisp_Object));
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2894
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2895 len = 0;
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2896 for (i = 0; i < search_regs.num_regs; i++)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2897 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2898 int start = search_regs.start[i];
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2899 if (start >= 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2900 {
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2901 if (EQ (last_thing_searched, Qt)
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2902 || ! NILP (integers))
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2903 {
9319
7969182b6cc6 (skip_chars, Fmatch_data, Fstore_match_data): Don't use XFASTINT as an lvalue.
Karl Heuer <kwzh@gnu.org>
parents: 9278
diff changeset
2904 XSETFASTINT (data[2 * i], start);
7969182b6cc6 (skip_chars, Fmatch_data, Fstore_match_data): Don't use XFASTINT as an lvalue.
Karl Heuer <kwzh@gnu.org>
parents: 9278
diff changeset
2905 XSETFASTINT (data[2 * i + 1], search_regs.end[i]);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2906 }
9113
766b6288e0f2 (Fmatch_data, Fstore_match_data): Use type test macros.
Karl Heuer <kwzh@gnu.org>
parents: 9029
diff changeset
2907 else if (BUFFERP (last_thing_searched))
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2908 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2909 data[2 * i] = Fmake_marker ();
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2910 Fset_marker (data[2 * i],
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2911 make_number (start),
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2912 last_thing_searched);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2913 data[2 * i + 1] = Fmake_marker ();
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2914 Fset_marker (data[2 * i + 1],
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
2915 make_number (search_regs.end[i]),
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2916 last_thing_searched);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2917 }
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2918 else
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2919 /* last_thing_searched must always be Qt, a buffer, or Qnil. */
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2920 abort ();
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2921
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2922 len = 2 * i + 2;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2923 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2924 else
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2925 data[2 * i] = data[2 * i + 1] = Qnil;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2926 }
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2927
56294
aaa6a4ecea38 (match_limit, Fmatch_data, Fset_match_data): YAILOM.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 56276
diff changeset
2928 if (BUFFERP (last_thing_searched) && !NILP (integers))
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2929 {
56294
aaa6a4ecea38 (match_limit, Fmatch_data, Fset_match_data): YAILOM.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 56276
diff changeset
2930 data[len] = last_thing_searched;
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2931 len++;
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2932 }
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2933
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2934 /* If REUSE is not usable, cons up the values and return them. */
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2935 if (! CONSP (reuse))
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2936 return Flist (len, data);
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2937
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2938 /* If REUSE is a list, store as many value elements as will fit
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2939 into the elements of REUSE. */
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2940 for (i = 0, tail = reuse; CONSP (tail);
25663
a5eaace0fa01 Use XCAR and XCDR instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25441
diff changeset
2941 i++, tail = XCDR (tail))
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2942 {
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2943 if (i < len)
39973
579177964efa Avoid (most) uses of XCAR/XCDR as lvalues, for flexibility in experimenting
Ken Raeburn <raeburn@raeburn.org>
parents: 39805
diff changeset
2944 XSETCAR (tail, data[i]);
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2945 else
39973
579177964efa Avoid (most) uses of XCAR/XCDR as lvalues, for flexibility in experimenting
Ken Raeburn <raeburn@raeburn.org>
parents: 39805
diff changeset
2946 XSETCAR (tail, Qnil);
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2947 prev = tail;
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2948 }
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2949
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2950 /* If we couldn't fit all value elements into REUSE,
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2951 cons up the rest of them and add them to the end of REUSE. */
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2952 if (i < len)
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2953 XSETCDR (prev, Flist (len - i, data + i));
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2954
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2955 return reuse;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2956 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2957
79443
fc388b33b46d (Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78501
diff changeset
2958 /* We used to have an internal use variant of `reseat' described as:
fc388b33b46d (Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78501
diff changeset
2959
fc388b33b46d (Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78501
diff changeset
2960 If RESEAT is `evaporate', put the markers back on the free list
fc388b33b46d (Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78501
diff changeset
2961 immediately. No other references to the markers must exist in this
fc388b33b46d (Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78501
diff changeset
2962 case, so it is used only internally on the unwind stack and
fc388b33b46d (Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78501
diff changeset
2963 save-match-data from Lisp.
fc388b33b46d (Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78501
diff changeset
2964
fc388b33b46d (Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78501
diff changeset
2965 But it was ill-conceived: those supposedly-internal markers get exposed via
fc388b33b46d (Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78501
diff changeset
2966 the undo-list, so freeing them here is unsafe. */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2967
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2968 DEFUN ("set-match-data", Fset_match_data, Sset_match_data, 1, 2, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2969 doc: /* Set internal data on last search match from elements of LIST.
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2970 LIST should have been created by calling `match-data' previously.
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
2971
63666
e0dd6fa42c85 (Fmatch_data): Remove evaporate option.
Kim F. Storm <storm@cua.dk>
parents: 63152
diff changeset
2972 If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
2973 (register Lisp_Object list, Lisp_Object reseat)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2974 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2975 register int i;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2976 register Lisp_Object marker;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2977
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2978 if (running_asynch_code)
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2979 save_search_regs ();
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2980
71841
0b34cf45daa8 (Fset_match_data): Use CHECK_LIST.
Kim F. Storm <storm@cua.dk>
parents: 71063
diff changeset
2981 CHECK_LIST (list);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2982
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2983 /* Unless we find a marker with a buffer or an explicit buffer
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2984 in LIST, assume that this match data came from a string. */
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2985 last_thing_searched = Qt;
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2986
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2987 /* Allocate registers if they don't already exist. */
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2988 {
1523
bd61aaa7828b * search.c (Fstore_match_data): Don't assume Flength returns an
Jim Blandy <jimb@redhat.com>
parents: 1413
diff changeset
2989 int length = XFASTINT (Flength (list)) / 2;
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2990
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2991 if (length > search_regs.num_regs)
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2992 {
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2993 if (search_regs.num_regs == 0)
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2994 {
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2995 search_regs.start
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2996 = (regoff_t *) xmalloc (length * sizeof (regoff_t));
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2997 search_regs.end
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2998 = (regoff_t *) xmalloc (length * sizeof (regoff_t));
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2999 }
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
3000 else
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
3001 {
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
3002 search_regs.start
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
3003 = (regoff_t *) xrealloc (search_regs.start,
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
3004 length * sizeof (regoff_t));
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
3005 search_regs.end
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
3006 = (regoff_t *) xrealloc (search_regs.end,
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
3007 length * sizeof (regoff_t));
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
3008 }
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
3009
33052
9ec478daa468 (Fset_match_data): Be sure to make search_regs always sane.
Kenichi Handa <handa@m17n.org>
parents: 32387
diff changeset
3010 for (i = search_regs.num_regs; i < length; i++)
9ec478daa468 (Fset_match_data): Be sure to make search_regs always sane.
Kenichi Handa <handa@m17n.org>
parents: 32387
diff changeset
3011 search_regs.start[i] = -1;
9ec478daa468 (Fset_match_data): Be sure to make search_regs always sane.
Kenichi Handa <handa@m17n.org>
parents: 32387
diff changeset
3012
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
3013 search_regs.num_regs = length;
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
3014 }
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3015
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3016 for (i = 0; CONSP (list); i++)
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3017 {
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3018 marker = XCAR (list);
56294
aaa6a4ecea38 (match_limit, Fmatch_data, Fset_match_data): YAILOM.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 56276
diff changeset
3019 if (BUFFERP (marker))
56276
b04610e283ce (Fset_match_data): Allow buffer before end of list
David Kastrup <dak@gnu.org>
parents: 56224
diff changeset
3020 {
56294
aaa6a4ecea38 (match_limit, Fmatch_data, Fset_match_data): YAILOM.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 56276
diff changeset
3021 last_thing_searched = marker;
56276
b04610e283ce (Fset_match_data): Allow buffer before end of list
David Kastrup <dak@gnu.org>
parents: 56224
diff changeset
3022 break;
b04610e283ce (Fset_match_data): Allow buffer before end of list
David Kastrup <dak@gnu.org>
parents: 56224
diff changeset
3023 }
b04610e283ce (Fset_match_data): Allow buffer before end of list
David Kastrup <dak@gnu.org>
parents: 56224
diff changeset
3024 if (i >= length)
b04610e283ce (Fset_match_data): Allow buffer before end of list
David Kastrup <dak@gnu.org>
parents: 56224
diff changeset
3025 break;
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3026 if (NILP (marker))
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3027 {
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3028 search_regs.start[i] = -1;
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3029 list = XCDR (list);
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3030 }
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3031 else
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3032 {
103001
6b3176775d00 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 102999
diff changeset
3033 EMACS_INT from;
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3034 Lisp_Object m;
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3035
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3036 m = marker;
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3037 if (MARKERP (marker))
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3038 {
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3039 if (XMARKER (marker)->buffer == 0)
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3040 XSETFASTINT (marker, 0);
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3041 else
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3042 XSETBUFFER (last_thing_searched, XMARKER (marker)->buffer);
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3043 }
58567
47729f2cb184 (syms_of_search) <search-spaces-regexp>: Move 'doc:'
Kim F. Storm <storm@cua.dk>
parents: 58348
diff changeset
3044
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3045 CHECK_NUMBER_COERCE_MARKER (marker);
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3046 from = XINT (marker);
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3047
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3048 if (!NILP (reseat) && MARKERP (m))
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3049 {
79443
fc388b33b46d (Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78501
diff changeset
3050 unchain_marker (XMARKER (m));
63152
3f80de0be046 (Fset_match_data): Fix last change.
Kim F. Storm <storm@cua.dk>
parents: 63145
diff changeset
3051 XSETCAR (list, Qnil);
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3052 }
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3053
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3054 if ((list = XCDR (list), !CONSP (list)))
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3055 break;
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3056
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3057 m = marker = XCAR (list);
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3058
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3059 if (MARKERP (marker) && XMARKER (marker)->buffer == 0)
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3060 XSETFASTINT (marker, 0);
58567
47729f2cb184 (syms_of_search) <search-spaces-regexp>: Move 'doc:'
Kim F. Storm <storm@cua.dk>
parents: 58348
diff changeset
3061
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3062 CHECK_NUMBER_COERCE_MARKER (marker);
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3063 search_regs.start[i] = from;
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3064 search_regs.end[i] = XINT (marker);
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3065
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3066 if (!NILP (reseat) && MARKERP (m))
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3067 {
79443
fc388b33b46d (Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78501
diff changeset
3068 unchain_marker (XMARKER (m));
63152
3f80de0be046 (Fset_match_data): Fix last change.
Kim F. Storm <storm@cua.dk>
parents: 63145
diff changeset
3069 XSETCAR (list, Qnil);
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3070 }
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3071 }
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3072 list = XCDR (list);
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3073 }
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3074
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3075 for (; i < search_regs.num_regs; i++)
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3076 search_regs.start[i] = -1;
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
3077 }
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
3078
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
3079 return Qnil;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3080 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3081
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3082 /* If non-zero the match data have been saved in saved_search_regs
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3083 during the execution of a sentinel or filter. */
10128
59ccd063e016 (search_regs_saved): Delete initializer.
Richard M. Stallman <rms@gnu.org>
parents: 10055
diff changeset
3084 static int search_regs_saved;
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3085 static struct re_registers saved_search_regs;
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3086 static Lisp_Object saved_last_thing_searched;
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3087
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3088 /* Called from Flooking_at, Fstring_match, search_buffer, Fstore_match_data
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3089 if asynchronous code (filter or sentinel) is running. */
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3090 static void
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
3091 save_search_regs (void)
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3092 {
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3093 if (!search_regs_saved)
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3094 {
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3095 saved_search_regs.num_regs = search_regs.num_regs;
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3096 saved_search_regs.start = search_regs.start;
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3097 saved_search_regs.end = search_regs.end;
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3098 saved_last_thing_searched = last_thing_searched;
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3099 last_thing_searched = Qnil;
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3100 search_regs.num_regs = 0;
10250
422c3b96efda (set_search_regs): Really set search_regs.start and .end.
Richard M. Stallman <rms@gnu.org>
parents: 10141
diff changeset
3101 search_regs.start = 0;
422c3b96efda (set_search_regs): Really set search_regs.start and .end.
Richard M. Stallman <rms@gnu.org>
parents: 10141
diff changeset
3102 search_regs.end = 0;
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3103
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3104 search_regs_saved = 1;
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3105 }
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3106 }
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3107
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3108 /* Called upon exit from filters and sentinels. */
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3109 void
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
3110 restore_search_regs (void)
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3111 {
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3112 if (search_regs_saved)
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3113 {
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3114 if (search_regs.num_regs > 0)
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3115 {
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3116 xfree (search_regs.start);
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3117 xfree (search_regs.end);
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3118 }
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3119 search_regs.num_regs = saved_search_regs.num_regs;
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3120 search_regs.start = saved_search_regs.start;
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3121 search_regs.end = saved_search_regs.end;
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3122 last_thing_searched = saved_last_thing_searched;
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
3123 saved_last_thing_searched = Qnil;
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3124 search_regs_saved = 0;
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3125 }
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3126 }
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
3127
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3128 static Lisp_Object
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
3129 unwind_set_match_data (Lisp_Object list)
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3130 {
79443
fc388b33b46d (Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78501
diff changeset
3131 /* It is NOT ALWAYS safe to free (evaporate) the markers immediately. */
fc388b33b46d (Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78501
diff changeset
3132 return Fset_match_data (list, Qt);
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3133 }
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3134
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3135 /* Called to unwind protect the match data. */
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3136 void
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
3137 record_unwind_save_match_data (void)
63145
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3138 {
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3139 record_unwind_protect (unwind_set_match_data,
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3140 Fmatch_data (Qnil, Qnil, Qnil));
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3141 }
73d9b884e8c8 (Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents: 61682
diff changeset
3142
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3143 /* Quote a string to inactivate reg-expr chars */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3144
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3145 DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
3146 doc: /* Return a regexp string which matches exactly STRING and nothing else. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109165
diff changeset
3147 (Lisp_Object string)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3148 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3149 register unsigned char *in, *out, *end;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3150 register unsigned char *temp;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
3151 int backslashes_added = 0;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3152
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
3153 CHECK_STRING (string);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3154
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
3155 temp = (unsigned char *) alloca (SBYTES (string) * 2);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3156
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3157 /* Now copy the data into the new string, inserting escapes. */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3158
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
3159 in = SDATA (string);
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
3160 end = in + SBYTES (string);
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
3161 out = temp;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3162
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3163 for (; in != end; in++)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3164 {
69238
de924a86ee65 (Fregexp_quote): Do not precede a literal `]' with two backslashes to
Luc Teirlinck <teirllm@auburn.edu>
parents: 68651
diff changeset
3165 if (*in == '['
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3166 || *in == '*' || *in == '.' || *in == '\\'
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3167 || *in == '?' || *in == '+'
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3168 || *in == '^' || *in == '$')
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
3169 *out++ = '\\', backslashes_added++;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3170 *out++ = *in;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3171 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3172
21248
aba5e1c3328b (Fregexp_quote): Use make_specified_string.
Richard M. Stallman <rms@gnu.org>
parents: 21244
diff changeset
3173 return make_specified_string (temp,
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
3174 SCHARS (string) + backslashes_added,
21248
aba5e1c3328b (Fregexp_quote): Use make_specified_string.
Richard M. Stallman <rms@gnu.org>
parents: 21244
diff changeset
3175 out - temp,
aba5e1c3328b (Fregexp_quote): Use make_specified_string.
Richard M. Stallman <rms@gnu.org>
parents: 21244
diff changeset
3176 STRING_MULTIBYTE (string));
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3177 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
3178
21514
fa9ff387d260 Fix -Wimplicit warnings.
Andreas Schwab <schwab@suse.de>
parents: 21457
diff changeset
3179 void
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
3180 syms_of_search (void)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3181 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3182 register int i;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3183
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
3184 for (i = 0; i < REGEXP_CACHE_SIZE; ++i)
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
3185 {
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
3186 searchbufs[i].buf.allocated = 100;
51544
a0c2b39160e9 (shrink_regexp_cache): Use xrealloc.
Dave Love <fx@gnu.org>
parents: 49761
diff changeset
3187 searchbufs[i].buf.buffer = (unsigned char *) xmalloc (100);
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
3188 searchbufs[i].buf.fastmap = searchbufs[i].fastmap;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
3189 searchbufs[i].regexp = Qnil;
58330
5be8a633ec57 (struct regexp_cache): New element whitespace_regexp.
Richard M. Stallman <rms@gnu.org>
parents: 58326
diff changeset
3190 searchbufs[i].whitespace_regexp = Qnil;
73002
b3a72607819d * search.c (struct regexp_cache): New entry syntax_table.
Chong Yidong <cyd@stupidchicken.com>
parents: 72945
diff changeset
3191 searchbufs[i].syntax_table = Qnil;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
3192 staticpro (&searchbufs[i].regexp);
64318
a64663d06985 (syms_of_search): Staticpro searchbuf.whitespace_regexp.
Kim F. Storm <storm@cua.dk>
parents: 64084
diff changeset
3193 staticpro (&searchbufs[i].whitespace_regexp);
73002
b3a72607819d * search.c (struct regexp_cache): New entry syntax_table.
Chong Yidong <cyd@stupidchicken.com>
parents: 72945
diff changeset
3194 staticpro (&searchbufs[i].syntax_table);
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
3195 searchbufs[i].next = (i == REGEXP_CACHE_SIZE-1 ? 0 : &searchbufs[i+1]);
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
3196 }
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
3197 searchbuf_head = &searchbufs[0];
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3198
105877
21bdda3ded62 * xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 105669
diff changeset
3199 Qsearch_failed = intern_c_string ("search-failed");
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3200 staticpro (&Qsearch_failed);
105877
21bdda3ded62 * xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 105669
diff changeset
3201 Qinvalid_regexp = intern_c_string ("invalid-regexp");
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3202 staticpro (&Qinvalid_regexp);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3203
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3204 Fput (Qsearch_failed, Qerror_conditions,
105877
21bdda3ded62 * xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 105669
diff changeset
3205 pure_cons (Qsearch_failed, pure_cons (Qerror, Qnil)));
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3206 Fput (Qsearch_failed, Qerror_message,
105877
21bdda3ded62 * xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 105669
diff changeset
3207 make_pure_c_string ("Search failed"));
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3208
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3209 Fput (Qinvalid_regexp, Qerror_conditions,
105877
21bdda3ded62 * xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 105669
diff changeset
3210 pure_cons (Qinvalid_regexp, pure_cons (Qerror, Qnil)));
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3211 Fput (Qinvalid_regexp, Qerror_message,
105877
21bdda3ded62 * xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 105669
diff changeset
3212 make_pure_c_string ("Invalid regexp"));
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3213
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
3214 last_thing_searched = Qnil;
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
3215 staticpro (&last_thing_searched);
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
3216
56429
65eb0cb0f21f (syms_of_search): staticpro
David Kastrup <dak@gnu.org>
parents: 56294
diff changeset
3217 saved_last_thing_searched = Qnil;
65eb0cb0f21f (syms_of_search): staticpro
David Kastrup <dak@gnu.org>
parents: 56294
diff changeset
3218 staticpro (&saved_last_thing_searched);
65eb0cb0f21f (syms_of_search): staticpro
David Kastrup <dak@gnu.org>
parents: 56294
diff changeset
3219
112364
42e22c4f06b7 Move all DEFVAR'd globals into a structure -- threading infrastructure
Tom Tromey <tromey@redhat.com>
parents: 112278
diff changeset
3220 DEFVAR_LISP ("search-spaces-regexp", Vsearch_spaces_regexp,
58567
47729f2cb184 (syms_of_search) <search-spaces-regexp>: Move 'doc:'
Kim F. Storm <storm@cua.dk>
parents: 58348
diff changeset
3221 doc: /* Regexp to substitute for bunches of spaces in regexp search.
58326
0cc0d3274d68 (Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 57735
diff changeset
3222 Some commands use this for user-specified regexps.
0cc0d3274d68 (Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 57735
diff changeset
3223 Spaces that occur inside character classes or repetition operators
0cc0d3274d68 (Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 57735
diff changeset
3224 or other such regexp constructs are not replaced with this.
0cc0d3274d68 (Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 57735
diff changeset
3225 A value of nil (which is the normal value) means treat spaces literally. */);
58348
623ffd21f0ff (Vsearch_spaces_regexp):
Richard M. Stallman <rms@gnu.org>
parents: 58330
diff changeset
3226 Vsearch_spaces_regexp = Qnil;
58326
0cc0d3274d68 (Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 57735
diff changeset
3227
112364
42e22c4f06b7 Move all DEFVAR'd globals into a structure -- threading infrastructure
Tom Tromey <tromey@redhat.com>
parents: 112278
diff changeset
3228 DEFVAR_LISP ("inhibit-changing-match-data", Vinhibit_changing_match_data,
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
3229 doc: /* Internal use only.
86900
a65aa1e9a34b (syms_of_search) <inhibit-changing-match-data>: Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 86275
diff changeset
3230 If non-nil, the primitive searching and matching functions
a65aa1e9a34b (syms_of_search) <inhibit-changing-match-data>: Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 86275
diff changeset
3231 such as `looking-at', `string-match', `re-search-forward', etc.,
a65aa1e9a34b (syms_of_search) <inhibit-changing-match-data>: Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 86275
diff changeset
3232 do not set the match data. The proper way to use this variable
a65aa1e9a34b (syms_of_search) <inhibit-changing-match-data>: Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 86275
diff changeset
3233 is to bind it with `let' around a small expression. */);
81780
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
3234 Vinhibit_changing_match_data = Qnil;
54b5d7bec019 (Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 81279
diff changeset
3235
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
3236 defsubr (&Slooking_at);
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
3237 defsubr (&Sposix_looking_at);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3238 defsubr (&Sstring_match);
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
3239 defsubr (&Sposix_string_match);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3240 defsubr (&Ssearch_forward);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3241 defsubr (&Ssearch_backward);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3242 defsubr (&Sword_search_forward);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3243 defsubr (&Sword_search_backward);
98347
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
3244 defsubr (&Sword_search_forward_lax);
0a71297a00f9 (wordify): New argument for lax word-ends.
Chong Yidong <cyd@stupidchicken.com>
parents: 97759
diff changeset
3245 defsubr (&Sword_search_backward_lax);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3246 defsubr (&Sre_search_forward);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3247 defsubr (&Sre_search_backward);
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
3248 defsubr (&Sposix_search_forward);
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
3249 defsubr (&Sposix_search_backward);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3250 defsubr (&Sreplace_match);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3251 defsubr (&Smatch_beginning);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3252 defsubr (&Smatch_end);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3253 defsubr (&Smatch_data);
21171
60f6085df198 (Fset_match_data): Renamed from Fstore_match_data.
Richard M. Stallman <rms@gnu.org>
parents: 21117
diff changeset
3254 defsubr (&Sset_match_data);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3255 defsubr (&Sregexp_quote);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3256 }
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 51544
diff changeset
3257