1 /* String search routines for GNU Emacs.
2 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1997, 1998, 1999, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
27 #include "character.h"
29 #include "region-cache.h"
31 #include "blockinput.h"
32 #include "intervals.h"
34 #include <sys/types.h>
37 #define REGEXP_CACHE_SIZE 20
39 /* If the regexp is non-nil, then the buffer contains the compiled form
40 of that regexp, suitable for searching. */
43 struct regexp_cache
*next
;
44 Lisp_Object regexp
, whitespace_regexp
;
45 /* Syntax table for which the regexp applies. We need this because
46 of character classes. If this is t, then the compiled pattern is valid
47 for any syntax-table. */
48 Lisp_Object syntax_table
;
49 struct re_pattern_buffer buf
;
51 /* Nonzero means regexp was compiled to do full POSIX backtracking. */
55 /* The instances of that struct. */
56 struct regexp_cache searchbufs
[REGEXP_CACHE_SIZE
];
58 /* The head of the linked list; points to the most recently used buffer. */
59 struct regexp_cache
*searchbuf_head
;
62 /* Every call to re_match, etc., must pass &search_regs as the regs
63 argument unless you can show it is unnecessary (i.e., if re_match
64 is certainly going to be called again before region-around-match
67 Since the registers are now dynamically allocated, we need to make
68 sure not to refer to the Nth register before checking that it has
69 been allocated by checking search_regs.num_regs.
71 The regex code keeps track of whether it has allocated the search
72 buffer using bits in the re_pattern_buffer. This means that whenever
73 you compile a new pattern, it completely forgets whether it has
74 allocated any registers, and will allocate new registers the next
75 time you call a searching or matching function. Therefore, we need
76 to call re_set_registers after compiling a new pattern or after
77 setting the match registers, so that the regex functions will be
78 able to free or re-allocate it properly. */
79 static struct re_registers search_regs
;
81 /* The buffer in which the last search was performed, or
82 Qt if the last search was done in a string;
83 Qnil if no searching has been done yet. */
84 static Lisp_Object last_thing_searched
;
86 /* error condition signaled when regexp compile_pattern fails */
88 Lisp_Object Qinvalid_regexp
;
90 /* Error condition used for failing searches */
91 Lisp_Object Qsearch_failed
;
93 Lisp_Object Vsearch_spaces_regexp
;
95 /* If non-nil, the match data will not be changed during call to
96 searching or matching functions. This variable is for internal use
98 Lisp_Object Vinhibit_changing_match_data
;
100 static void set_search_regs
P_ ((EMACS_INT
, EMACS_INT
));
101 static void save_search_regs
P_ ((void));
102 static EMACS_INT simple_search
P_ ((int, unsigned char *, int, int,
103 Lisp_Object
, EMACS_INT
, EMACS_INT
,
104 EMACS_INT
, EMACS_INT
));
105 static EMACS_INT boyer_moore
P_ ((int, unsigned char *, int, int,
106 Lisp_Object
, Lisp_Object
,
107 EMACS_INT
, EMACS_INT
,
108 EMACS_INT
, EMACS_INT
, int));
109 static EMACS_INT search_buffer
P_ ((Lisp_Object
, EMACS_INT
, EMACS_INT
,
110 EMACS_INT
, EMACS_INT
, int, int,
111 Lisp_Object
, Lisp_Object
, int));
112 static void matcher_overflow () NO_RETURN
;
117 error ("Stack overflow in regexp matcher");
120 /* Compile a regexp and signal a Lisp error if anything goes wrong.
121 PATTERN is the pattern to compile.
122 CP is the place to put the result.
123 TRANSLATE is a translation table for ignoring case, or nil for none.
124 REGP is the structure that says where to store the "register"
125 values that will result from matching this pattern.
126 If it is 0, we should compile the pattern not to record any
127 subexpression bounds.
128 POSIX is nonzero if we want full backtracking (POSIX style)
129 for this pattern. 0 means backtrack only enough to get a valid match.
131 The behavior also depends on Vsearch_spaces_regexp. */
134 compile_pattern_1 (cp
, pattern
, translate
, regp
, posix
)
135 struct regexp_cache
*cp
;
137 Lisp_Object translate
;
138 struct re_registers
*regp
;
145 cp
->buf
.translate
= (! NILP (translate
) ? translate
: make_number (0));
147 cp
->buf
.multibyte
= STRING_MULTIBYTE (pattern
);
148 cp
->buf
.charset_unibyte
= charset_unibyte
;
149 if (STRINGP (Vsearch_spaces_regexp
))
150 cp
->whitespace_regexp
= Vsearch_spaces_regexp
;
152 cp
->whitespace_regexp
= Qnil
;
154 /* rms: I think BLOCK_INPUT is not needed here any more,
155 because regex.c defines malloc to call xmalloc.
156 Using BLOCK_INPUT here means the debugger won't run if an error occurs.
157 So let's turn it off. */
159 old
= re_set_syntax (RE_SYNTAX_EMACS
160 | (posix
? 0 : RE_NO_POSIX_BACKTRACKING
));
162 if (STRINGP (Vsearch_spaces_regexp
))
163 re_set_whitespace_regexp (SDATA (Vsearch_spaces_regexp
));
165 re_set_whitespace_regexp (NULL
);
167 val
= (char *) re_compile_pattern ((char *) SDATA (pattern
),
168 SBYTES (pattern
), &cp
->buf
);
170 /* If the compiled pattern hard codes some of the contents of the
171 syntax-table, it can only be reused with *this* syntax table. */
172 cp
->syntax_table
= cp
->buf
.used_syntax
? current_buffer
->syntax_table
: Qt
;
174 re_set_whitespace_regexp (NULL
);
179 xsignal1 (Qinvalid_regexp
, build_string (val
));
181 cp
->regexp
= Fcopy_sequence (pattern
);
184 /* Shrink each compiled regexp buffer in the cache
185 to the size actually used right now.
186 This is called from garbage collection. */
189 shrink_regexp_cache ()
191 struct regexp_cache
*cp
;
193 for (cp
= searchbuf_head
; cp
!= 0; cp
= cp
->next
)
195 cp
->buf
.allocated
= cp
->buf
.used
;
197 = (unsigned char *) xrealloc (cp
->buf
.buffer
, cp
->buf
.used
);
201 /* Clear the regexp cache w.r.t. a particular syntax table,
202 because it was changed.
203 There is no danger of memory leak here because re_compile_pattern
204 automagically manages the memory in each re_pattern_buffer struct,
205 based on its `allocated' and `buffer' values. */
207 clear_regexp_cache ()
211 for (i
= 0; i
< REGEXP_CACHE_SIZE
; ++i
)
212 /* It's tempting to compare with the syntax-table we've actually changd,
213 but it's not sufficient because char-table inheritance mewans that
214 modifying one syntax-table can change others at the same time. */
215 if (!EQ (searchbufs
[i
].syntax_table
, Qt
))
216 searchbufs
[i
].regexp
= Qnil
;
219 /* Compile a regexp if necessary, but first check to see if there's one in
221 PATTERN is the pattern to compile.
222 TRANSLATE is a translation table for ignoring case, or nil for none.
223 REGP is the structure that says where to store the "register"
224 values that will result from matching this pattern.
225 If it is 0, we should compile the pattern not to record any
226 subexpression bounds.
227 POSIX is nonzero if we want full backtracking (POSIX style)
228 for this pattern. 0 means backtrack only enough to get a valid match. */
230 struct re_pattern_buffer
*
231 compile_pattern (pattern
, regp
, translate
, posix
, multibyte
)
233 struct re_registers
*regp
;
234 Lisp_Object translate
;
235 int posix
, multibyte
;
237 struct regexp_cache
*cp
, **cpp
;
239 for (cpp
= &searchbuf_head
; ; cpp
= &cp
->next
)
242 /* Entries are initialized to nil, and may be set to nil by
243 compile_pattern_1 if the pattern isn't valid. Don't apply
244 string accessors in those cases. However, compile_pattern_1
245 is only applied to the cache entry we pick here to reuse. So
246 nil should never appear before a non-nil entry. */
247 if (NILP (cp
->regexp
))
249 if (SCHARS (cp
->regexp
) == SCHARS (pattern
)
250 && STRING_MULTIBYTE (cp
->regexp
) == STRING_MULTIBYTE (pattern
)
251 && !NILP (Fstring_equal (cp
->regexp
, pattern
))
252 && EQ (cp
->buf
.translate
, (! NILP (translate
) ? translate
: make_number (0)))
253 && cp
->posix
== posix
254 && (EQ (cp
->syntax_table
, Qt
)
255 || EQ (cp
->syntax_table
, current_buffer
->syntax_table
))
256 && !NILP (Fequal (cp
->whitespace_regexp
, Vsearch_spaces_regexp
))
257 && cp
->buf
.charset_unibyte
== charset_unibyte
)
260 /* If we're at the end of the cache, compile into the nil cell
261 we found, or the last (least recently used) cell with a
266 compile_pattern_1 (cp
, pattern
, translate
, regp
, posix
);
271 /* When we get here, cp (aka *cpp) contains the compiled pattern,
272 either because we found it in the cache or because we just compiled it.
273 Move it to the front of the queue to mark it as most recently used. */
275 cp
->next
= searchbuf_head
;
278 /* Advise the searching functions about the space we have allocated
279 for register data. */
281 re_set_registers (&cp
->buf
, regp
, regp
->num_regs
, regp
->start
, regp
->end
);
283 /* The compiled pattern can be used both for mulitbyte and unibyte
284 target. But, we have to tell which the pattern is used for. */
285 cp
->buf
.target_multibyte
= multibyte
;
292 looking_at_1 (string
, posix
)
297 unsigned char *p1
, *p2
;
300 struct re_pattern_buffer
*bufp
;
302 if (running_asynch_code
)
305 /* This is so set_image_of_range_1 in regex.c can find the EQV table. */
306 XCHAR_TABLE (current_buffer
->case_canon_table
)->extras
[2]
307 = current_buffer
->case_eqv_table
;
309 CHECK_STRING (string
);
310 bufp
= compile_pattern (string
,
311 (NILP (Vinhibit_changing_match_data
)
312 ? &search_regs
: NULL
),
313 (!NILP (current_buffer
->case_fold_search
)
314 ? current_buffer
->case_canon_table
: Qnil
),
316 !NILP (current_buffer
->enable_multibyte_characters
));
319 QUIT
; /* Do a pending quit right away, to avoid paradoxical behavior */
321 /* Get pointers and sizes of the two strings
322 that make up the visible portion of the buffer. */
325 s1
= GPT_BYTE
- BEGV_BYTE
;
327 s2
= ZV_BYTE
- GPT_BYTE
;
331 s2
= ZV_BYTE
- BEGV_BYTE
;
336 s1
= ZV_BYTE
- BEGV_BYTE
;
340 re_match_object
= Qnil
;
342 i
= re_match_2 (bufp
, (char *) p1
, s1
, (char *) p2
, s2
,
344 (NILP (Vinhibit_changing_match_data
)
345 ? &search_regs
: NULL
),
346 ZV_BYTE
- BEGV_BYTE
);
352 val
= (0 <= i
? Qt
: Qnil
);
353 if (NILP (Vinhibit_changing_match_data
) && i
>= 0)
354 for (i
= 0; i
< search_regs
.num_regs
; i
++)
355 if (search_regs
.start
[i
] >= 0)
358 = BYTE_TO_CHAR (search_regs
.start
[i
] + BEGV_BYTE
);
360 = BYTE_TO_CHAR (search_regs
.end
[i
] + BEGV_BYTE
);
363 /* Set last_thing_searched only when match data is changed. */
364 if (NILP (Vinhibit_changing_match_data
))
365 XSETBUFFER (last_thing_searched
, current_buffer
);
370 DEFUN ("looking-at", Flooking_at
, Slooking_at
, 1, 1, 0,
371 doc
: /* Return t if text after point matches regular expression REGEXP.
372 This function modifies the match data that `match-beginning',
373 `match-end' and `match-data' access; save and restore the match
374 data if you want to preserve them. */)
378 return looking_at_1 (regexp
, 0);
381 DEFUN ("posix-looking-at", Fposix_looking_at
, Sposix_looking_at
, 1, 1, 0,
382 doc
: /* Return t if text after point matches regular expression REGEXP.
383 Find the longest match, in accord with Posix regular expression rules.
384 This function modifies the match data that `match-beginning',
385 `match-end' and `match-data' access; save and restore the match
386 data if you want to preserve them. */)
390 return looking_at_1 (regexp
, 1);
394 string_match_1 (regexp
, string
, start
, posix
)
395 Lisp_Object regexp
, string
, start
;
399 struct re_pattern_buffer
*bufp
;
400 EMACS_INT pos
, pos_byte
;
403 if (running_asynch_code
)
406 CHECK_STRING (regexp
);
407 CHECK_STRING (string
);
410 pos
= 0, pos_byte
= 0;
413 int len
= SCHARS (string
);
415 CHECK_NUMBER (start
);
417 if (pos
< 0 && -pos
<= len
)
419 else if (0 > pos
|| pos
> len
)
420 args_out_of_range (string
, start
);
421 pos_byte
= string_char_to_byte (string
, pos
);
424 /* This is so set_image_of_range_1 in regex.c can find the EQV table. */
425 XCHAR_TABLE (current_buffer
->case_canon_table
)->extras
[2]
426 = current_buffer
->case_eqv_table
;
428 bufp
= compile_pattern (regexp
,
429 (NILP (Vinhibit_changing_match_data
)
430 ? &search_regs
: NULL
),
431 (!NILP (current_buffer
->case_fold_search
)
432 ? current_buffer
->case_canon_table
: Qnil
),
434 STRING_MULTIBYTE (string
));
436 re_match_object
= string
;
438 val
= re_search (bufp
, (char *) SDATA (string
),
439 SBYTES (string
), pos_byte
,
440 SBYTES (string
) - pos_byte
,
441 (NILP (Vinhibit_changing_match_data
)
442 ? &search_regs
: NULL
));
445 /* Set last_thing_searched only when match data is changed. */
446 if (NILP (Vinhibit_changing_match_data
))
447 last_thing_searched
= Qt
;
451 if (val
< 0) return Qnil
;
453 if (NILP (Vinhibit_changing_match_data
))
454 for (i
= 0; i
< search_regs
.num_regs
; i
++)
455 if (search_regs
.start
[i
] >= 0)
458 = string_byte_to_char (string
, search_regs
.start
[i
]);
460 = string_byte_to_char (string
, search_regs
.end
[i
]);
463 return make_number (string_byte_to_char (string
, val
));
466 DEFUN ("string-match", Fstring_match
, Sstring_match
, 2, 3, 0,
467 doc
: /* Return index of start of first match for REGEXP in STRING, or nil.
468 Matching ignores case if `case-fold-search' is non-nil.
469 If third arg START is non-nil, start search at that index in STRING.
470 For index of first char beyond the match, do (match-end 0).
471 `match-end' and `match-beginning' also give indices of substrings
472 matched by parenthesis constructs in the pattern.
474 You can use the function `match-string' to extract the substrings
475 matched by the parenthesis constructions in REGEXP. */)
476 (regexp
, string
, start
)
477 Lisp_Object regexp
, string
, start
;
479 return string_match_1 (regexp
, string
, start
, 0);
482 DEFUN ("posix-string-match", Fposix_string_match
, Sposix_string_match
, 2, 3, 0,
483 doc
: /* Return index of start of first match for REGEXP in STRING, or nil.
484 Find the longest match, in accord with Posix regular expression rules.
485 Case is ignored if `case-fold-search' is non-nil in the current buffer.
486 If third arg START is non-nil, start search at that index in STRING.
487 For index of first char beyond the match, do (match-end 0).
488 `match-end' and `match-beginning' also give indices of substrings
489 matched by parenthesis constructs in the pattern. */)
490 (regexp
, string
, start
)
491 Lisp_Object regexp
, string
, start
;
493 return string_match_1 (regexp
, string
, start
, 1);
496 /* Match REGEXP against STRING, searching all of STRING,
497 and return the index of the match, or negative on failure.
498 This does not clobber the match data. */
501 fast_string_match (regexp
, string
)
502 Lisp_Object regexp
, string
;
505 struct re_pattern_buffer
*bufp
;
507 bufp
= compile_pattern (regexp
, 0, Qnil
,
508 0, STRING_MULTIBYTE (string
));
510 re_match_object
= string
;
512 val
= re_search (bufp
, (char *) SDATA (string
),
519 /* Match REGEXP against STRING, searching all of STRING ignoring case,
520 and return the index of the match, or negative on failure.
521 This does not clobber the match data.
522 We assume that STRING contains single-byte characters. */
524 extern Lisp_Object Vascii_downcase_table
;
527 fast_c_string_match_ignore_case (regexp
, string
)
532 struct re_pattern_buffer
*bufp
;
533 int len
= strlen (string
);
535 regexp
= string_make_unibyte (regexp
);
536 re_match_object
= Qt
;
537 bufp
= compile_pattern (regexp
, 0,
538 Vascii_canon_table
, 0,
541 val
= re_search (bufp
, string
, len
, 0, len
, 0);
546 /* Like fast_string_match but ignore case. */
549 fast_string_match_ignore_case (regexp
, string
)
550 Lisp_Object regexp
, string
;
553 struct re_pattern_buffer
*bufp
;
555 bufp
= compile_pattern (regexp
, 0, Vascii_canon_table
,
556 0, STRING_MULTIBYTE (string
));
558 re_match_object
= string
;
560 val
= re_search (bufp
, (char *) SDATA (string
),
567 /* Match REGEXP atainst the characters after POS to LIMIT, and return
568 the number of matched characters. If STRING is non-nil, match
569 against the characters in it. In that case, POS and LIMIT are
570 indices into the string. This function doesn't modify the match
574 fast_looking_at (regexp
, pos
, pos_byte
, limit
, limit_byte
, string
)
576 EMACS_INT pos
, pos_byte
, limit
, limit_byte
;
580 struct re_pattern_buffer
*buf
;
581 unsigned char *p1
, *p2
;
585 if (STRINGP (string
))
588 pos_byte
= string_char_to_byte (string
, pos
);
590 limit_byte
= string_char_to_byte (string
, limit
);
594 s2
= SBYTES (string
);
595 re_match_object
= string
;
596 multibyte
= STRING_MULTIBYTE (string
);
601 pos_byte
= CHAR_TO_BYTE (pos
);
603 limit_byte
= CHAR_TO_BYTE (limit
);
604 pos_byte
-= BEGV_BYTE
;
605 limit_byte
-= BEGV_BYTE
;
607 s1
= GPT_BYTE
- BEGV_BYTE
;
609 s2
= ZV_BYTE
- GPT_BYTE
;
613 s2
= ZV_BYTE
- BEGV_BYTE
;
618 s1
= ZV_BYTE
- BEGV_BYTE
;
621 re_match_object
= Qnil
;
622 multibyte
= ! NILP (current_buffer
->enable_multibyte_characters
);
625 buf
= compile_pattern (regexp
, 0, Qnil
, 0, multibyte
);
627 len
= re_match_2 (buf
, (char *) p1
, s1
, (char *) p2
, s2
,
628 pos_byte
, NULL
, limit_byte
);
635 /* The newline cache: remembering which sections of text have no newlines. */
637 /* If the user has requested newline caching, make sure it's on.
638 Otherwise, make sure it's off.
639 This is our cheezy way of associating an action with the change of
640 state of a buffer-local variable. */
642 newline_cache_on_off (buf
)
645 if (NILP (buf
->cache_long_line_scans
))
647 /* It should be off. */
648 if (buf
->newline_cache
)
650 free_region_cache (buf
->newline_cache
);
651 buf
->newline_cache
= 0;
656 /* It should be on. */
657 if (buf
->newline_cache
== 0)
658 buf
->newline_cache
= new_region_cache ();
663 /* Search for COUNT instances of the character TARGET between START and END.
665 If COUNT is positive, search forwards; END must be >= START.
666 If COUNT is negative, search backwards for the -COUNTth instance;
667 END must be <= START.
668 If COUNT is zero, do anything you please; run rogue, for all I care.
670 If END is zero, use BEGV or ZV instead, as appropriate for the
671 direction indicated by COUNT.
673 If we find COUNT instances, set *SHORTAGE to zero, and return the
674 position past the COUNTth match. Note that for reverse motion
675 this is not the same as the usual convention for Emacs motion commands.
677 If we don't find COUNT instances before reaching END, set *SHORTAGE
678 to the number of TARGETs left unfound, and return END.
680 If ALLOW_QUIT is non-zero, set immediate_quit. That's good to do
681 except when inside redisplay. */
684 scan_buffer (target
, start
, end
, count
, shortage
, allow_quit
)
686 EMACS_INT start
, end
;
691 struct region_cache
*newline_cache
;
702 if (! end
) end
= BEGV
;
705 newline_cache_on_off (current_buffer
);
706 newline_cache
= current_buffer
->newline_cache
;
711 immediate_quit
= allow_quit
;
716 /* Our innermost scanning loop is very simple; it doesn't know
717 about gaps, buffer ends, or the newline cache. ceiling is
718 the position of the last character before the next such
719 obstacle --- the last character the dumb search loop should
721 EMACS_INT ceiling_byte
= CHAR_TO_BYTE (end
) - 1;
722 EMACS_INT start_byte
= CHAR_TO_BYTE (start
);
725 /* If we're looking for a newline, consult the newline cache
726 to see where we can avoid some scanning. */
727 if (target
== '\n' && newline_cache
)
731 while (region_cache_forward
732 (current_buffer
, newline_cache
, start_byte
, &next_change
))
733 start_byte
= next_change
;
734 immediate_quit
= allow_quit
;
736 /* START should never be after END. */
737 if (start_byte
> ceiling_byte
)
738 start_byte
= ceiling_byte
;
740 /* Now the text after start is an unknown region, and
741 next_change is the position of the next known region. */
742 ceiling_byte
= min (next_change
- 1, ceiling_byte
);
745 /* The dumb loop can only scan text stored in contiguous
746 bytes. BUFFER_CEILING_OF returns the last character
747 position that is contiguous, so the ceiling is the
748 position after that. */
749 tem
= BUFFER_CEILING_OF (start_byte
);
750 ceiling_byte
= min (tem
, ceiling_byte
);
753 /* The termination address of the dumb loop. */
754 register unsigned char *ceiling_addr
755 = BYTE_POS_ADDR (ceiling_byte
) + 1;
756 register unsigned char *cursor
757 = BYTE_POS_ADDR (start_byte
);
758 unsigned char *base
= cursor
;
760 while (cursor
< ceiling_addr
)
762 unsigned char *scan_start
= cursor
;
765 while (*cursor
!= target
&& ++cursor
< ceiling_addr
)
768 /* If we're looking for newlines, cache the fact that
769 the region from start to cursor is free of them. */
770 if (target
== '\n' && newline_cache
)
771 know_region_cache (current_buffer
, newline_cache
,
772 start_byte
+ scan_start
- base
,
773 start_byte
+ cursor
- base
);
775 /* Did we find the target character? */
776 if (cursor
< ceiling_addr
)
781 return BYTE_TO_CHAR (start_byte
+ cursor
- base
+ 1);
787 start
= BYTE_TO_CHAR (start_byte
+ cursor
- base
);
793 /* The last character to check before the next obstacle. */
794 EMACS_INT ceiling_byte
= CHAR_TO_BYTE (end
);
795 EMACS_INT start_byte
= CHAR_TO_BYTE (start
);
798 /* Consult the newline cache, if appropriate. */
799 if (target
== '\n' && newline_cache
)
803 while (region_cache_backward
804 (current_buffer
, newline_cache
, start_byte
, &next_change
))
805 start_byte
= next_change
;
806 immediate_quit
= allow_quit
;
808 /* Start should never be at or before end. */
809 if (start_byte
<= ceiling_byte
)
810 start_byte
= ceiling_byte
+ 1;
812 /* Now the text before start is an unknown region, and
813 next_change is the position of the next known region. */
814 ceiling_byte
= max (next_change
, ceiling_byte
);
817 /* Stop scanning before the gap. */
818 tem
= BUFFER_FLOOR_OF (start_byte
- 1);
819 ceiling_byte
= max (tem
, ceiling_byte
);
822 /* The termination address of the dumb loop. */
823 register unsigned char *ceiling_addr
= BYTE_POS_ADDR (ceiling_byte
);
824 register unsigned char *cursor
= BYTE_POS_ADDR (start_byte
- 1);
825 unsigned char *base
= cursor
;
827 while (cursor
>= ceiling_addr
)
829 unsigned char *scan_start
= cursor
;
831 while (*cursor
!= target
&& --cursor
>= ceiling_addr
)
834 /* If we're looking for newlines, cache the fact that
835 the region from after the cursor to start is free of them. */
836 if (target
== '\n' && newline_cache
)
837 know_region_cache (current_buffer
, newline_cache
,
838 start_byte
+ cursor
- base
,
839 start_byte
+ scan_start
- base
);
841 /* Did we find the target character? */
842 if (cursor
>= ceiling_addr
)
847 return BYTE_TO_CHAR (start_byte
+ cursor
- base
);
853 start
= BYTE_TO_CHAR (start_byte
+ cursor
- base
);
859 *shortage
= count
* direction
;
863 /* Search for COUNT instances of a line boundary, which means either a
864 newline or (if selective display enabled) a carriage return.
865 Start at START. If COUNT is negative, search backwards.
867 We report the resulting position by calling TEMP_SET_PT_BOTH.
869 If we find COUNT instances. we position after (always after,
870 even if scanning backwards) the COUNTth match, and return 0.
872 If we don't find COUNT instances before reaching the end of the
873 buffer (or the beginning, if scanning backwards), we return
874 the number of line boundaries left unfound, and position at
875 the limit we bumped up against.
877 If ALLOW_QUIT is non-zero, set immediate_quit. That's good to do
878 except in special cases. */
881 scan_newline (start
, start_byte
, limit
, limit_byte
, count
, allow_quit
)
882 EMACS_INT start
, start_byte
;
883 EMACS_INT limit
, limit_byte
;
887 int direction
= ((count
> 0) ? 1 : -1);
889 register unsigned char *cursor
;
893 register unsigned char *ceiling_addr
;
895 int old_immediate_quit
= immediate_quit
;
897 /* The code that follows is like scan_buffer
898 but checks for either newline or carriage return. */
903 start_byte
= CHAR_TO_BYTE (start
);
907 while (start_byte
< limit_byte
)
909 ceiling
= BUFFER_CEILING_OF (start_byte
);
910 ceiling
= min (limit_byte
- 1, ceiling
);
911 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
912 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
915 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
918 if (cursor
!= ceiling_addr
)
922 immediate_quit
= old_immediate_quit
;
923 start_byte
= start_byte
+ cursor
- base
+ 1;
924 start
= BYTE_TO_CHAR (start_byte
);
925 TEMP_SET_PT_BOTH (start
, start_byte
);
929 if (++cursor
== ceiling_addr
)
935 start_byte
+= cursor
- base
;
940 while (start_byte
> limit_byte
)
942 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
943 ceiling
= max (limit_byte
, ceiling
);
944 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
945 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
948 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
951 if (cursor
!= ceiling_addr
)
955 immediate_quit
= old_immediate_quit
;
956 /* Return the position AFTER the match we found. */
957 start_byte
= start_byte
+ cursor
- base
+ 1;
958 start
= BYTE_TO_CHAR (start_byte
);
959 TEMP_SET_PT_BOTH (start
, start_byte
);
966 /* Here we add 1 to compensate for the last decrement
967 of CURSOR, which took it past the valid range. */
968 start_byte
+= cursor
- base
+ 1;
972 TEMP_SET_PT_BOTH (limit
, limit_byte
);
973 immediate_quit
= old_immediate_quit
;
975 return count
* direction
;
979 find_next_newline_no_quit (from
, cnt
)
983 return scan_buffer ('\n', from
, 0, cnt
, (int *) 0, 0);
986 /* Like find_next_newline, but returns position before the newline,
987 not after, and only search up to TO. This isn't just
988 find_next_newline (...)-1, because you might hit TO. */
991 find_before_next_newline (from
, to
, cnt
)
996 int pos
= scan_buffer ('\n', from
, to
, cnt
, &shortage
, 1);
1004 /* Subroutines of Lisp buffer search functions. */
1007 search_command (string
, bound
, noerror
, count
, direction
, RE
, posix
)
1008 Lisp_Object string
, bound
, noerror
, count
;
1019 CHECK_NUMBER (count
);
1023 CHECK_STRING (string
);
1027 lim
= ZV
, lim_byte
= ZV_BYTE
;
1029 lim
= BEGV
, lim_byte
= BEGV_BYTE
;
1033 CHECK_NUMBER_COERCE_MARKER (bound
);
1035 if (n
> 0 ? lim
< PT
: lim
> PT
)
1036 error ("Invalid search bound (wrong side of point)");
1038 lim
= ZV
, lim_byte
= ZV_BYTE
;
1039 else if (lim
< BEGV
)
1040 lim
= BEGV
, lim_byte
= BEGV_BYTE
;
1042 lim_byte
= CHAR_TO_BYTE (lim
);
1045 /* This is so set_image_of_range_1 in regex.c can find the EQV table. */
1046 XCHAR_TABLE (current_buffer
->case_canon_table
)->extras
[2]
1047 = current_buffer
->case_eqv_table
;
1049 np
= search_buffer (string
, PT
, PT_BYTE
, lim
, lim_byte
, n
, RE
,
1050 (!NILP (current_buffer
->case_fold_search
)
1051 ? current_buffer
->case_canon_table
1053 (!NILP (current_buffer
->case_fold_search
)
1054 ? current_buffer
->case_eqv_table
1060 xsignal1 (Qsearch_failed
, string
);
1062 if (!EQ (noerror
, Qt
))
1064 if (lim
< BEGV
|| lim
> ZV
)
1066 SET_PT_BOTH (lim
, lim_byte
);
1068 #if 0 /* This would be clean, but maybe programs depend on
1069 a value of nil here. */
1077 if (np
< BEGV
|| np
> ZV
)
1082 return make_number (np
);
1085 /* Return 1 if REGEXP it matches just one constant string. */
1088 trivial_regexp_p (regexp
)
1091 int len
= SBYTES (regexp
);
1092 unsigned char *s
= SDATA (regexp
);
1097 case '.': case '*': case '+': case '?': case '[': case '^': case '$':
1104 case '|': case '(': case ')': case '`': case '\'': case 'b':
1105 case 'B': case '<': case '>': case 'w': case 'W': case 's':
1106 case 'S': case '=': case '{': case '}': case '_':
1107 case 'c': case 'C': /* for categoryspec and notcategoryspec */
1108 case '1': case '2': case '3': case '4': case '5':
1109 case '6': case '7': case '8': case '9':
1117 /* Search for the n'th occurrence of STRING in the current buffer,
1118 starting at position POS and stopping at position LIM,
1119 treating STRING as a literal string if RE is false or as
1120 a regular expression if RE is true.
1122 If N is positive, searching is forward and LIM must be greater than POS.
1123 If N is negative, searching is backward and LIM must be less than POS.
1125 Returns -x if x occurrences remain to be found (x > 0),
1126 or else the position at the beginning of the Nth occurrence
1127 (if searching backward) or the end (if searching forward).
1129 POSIX is nonzero if we want full backtracking (POSIX style)
1130 for this pattern. 0 means backtrack only enough to get a valid match. */
1132 #define TRANSLATE(out, trt, d) \
1138 temp = Faref (trt, make_number (d)); \
1139 if (INTEGERP (temp)) \
1140 out = XINT (temp); \
1149 /* Only used in search_buffer, to record the end position of the match
1150 when searching regexps and SEARCH_REGS should not be changed
1151 (i.e. Vinhibit_changing_match_data is non-nil). */
1152 static struct re_registers search_regs_1
;
1155 search_buffer (string
, pos
, pos_byte
, lim
, lim_byte
, n
,
1156 RE
, trt
, inverse_trt
, posix
)
1165 Lisp_Object inverse_trt
;
1168 int len
= SCHARS (string
);
1169 int len_byte
= SBYTES (string
);
1172 if (running_asynch_code
)
1173 save_search_regs ();
1175 /* Searching 0 times means don't move. */
1176 /* Null string is found at starting position. */
1177 if (len
== 0 || n
== 0)
1179 set_search_regs (pos_byte
, 0);
1183 if (RE
&& !(trivial_regexp_p (string
) && NILP (Vsearch_spaces_regexp
)))
1185 unsigned char *p1
, *p2
;
1187 struct re_pattern_buffer
*bufp
;
1189 bufp
= compile_pattern (string
,
1190 (NILP (Vinhibit_changing_match_data
)
1191 ? &search_regs
: &search_regs_1
),
1193 !NILP (current_buffer
->enable_multibyte_characters
));
1195 immediate_quit
= 1; /* Quit immediately if user types ^G,
1196 because letting this function finish
1197 can take too long. */
1198 QUIT
; /* Do a pending quit right away,
1199 to avoid paradoxical behavior */
1200 /* Get pointers and sizes of the two strings
1201 that make up the visible portion of the buffer. */
1204 s1
= GPT_BYTE
- BEGV_BYTE
;
1206 s2
= ZV_BYTE
- GPT_BYTE
;
1210 s2
= ZV_BYTE
- BEGV_BYTE
;
1215 s1
= ZV_BYTE
- BEGV_BYTE
;
1218 re_match_object
= Qnil
;
1223 val
= re_search_2 (bufp
, (char *) p1
, s1
, (char *) p2
, s2
,
1224 pos_byte
- BEGV_BYTE
, lim_byte
- pos_byte
,
1225 (NILP (Vinhibit_changing_match_data
)
1226 ? &search_regs
: &search_regs_1
),
1227 /* Don't allow match past current point */
1228 pos_byte
- BEGV_BYTE
);
1231 matcher_overflow ();
1235 if (NILP (Vinhibit_changing_match_data
))
1237 pos_byte
= search_regs
.start
[0] + BEGV_BYTE
;
1238 for (i
= 0; i
< search_regs
.num_regs
; i
++)
1239 if (search_regs
.start
[i
] >= 0)
1241 search_regs
.start
[i
]
1242 = BYTE_TO_CHAR (search_regs
.start
[i
] + BEGV_BYTE
);
1244 = BYTE_TO_CHAR (search_regs
.end
[i
] + BEGV_BYTE
);
1246 XSETBUFFER (last_thing_searched
, current_buffer
);
1247 /* Set pos to the new position. */
1248 pos
= search_regs
.start
[0];
1252 pos_byte
= search_regs_1
.start
[0] + BEGV_BYTE
;
1253 /* Set pos to the new position. */
1254 pos
= BYTE_TO_CHAR (search_regs_1
.start
[0] + BEGV_BYTE
);
1267 val
= re_search_2 (bufp
, (char *) p1
, s1
, (char *) p2
, s2
,
1268 pos_byte
- BEGV_BYTE
, lim_byte
- pos_byte
,
1269 (NILP (Vinhibit_changing_match_data
)
1270 ? &search_regs
: &search_regs_1
),
1271 lim_byte
- BEGV_BYTE
);
1274 matcher_overflow ();
1278 if (NILP (Vinhibit_changing_match_data
))
1280 pos_byte
= search_regs
.end
[0] + BEGV_BYTE
;
1281 for (i
= 0; i
< search_regs
.num_regs
; i
++)
1282 if (search_regs
.start
[i
] >= 0)
1284 search_regs
.start
[i
]
1285 = BYTE_TO_CHAR (search_regs
.start
[i
] + BEGV_BYTE
);
1287 = BYTE_TO_CHAR (search_regs
.end
[i
] + BEGV_BYTE
);
1289 XSETBUFFER (last_thing_searched
, current_buffer
);
1290 pos
= search_regs
.end
[0];
1294 pos_byte
= search_regs_1
.end
[0] + BEGV_BYTE
;
1295 pos
= BYTE_TO_CHAR (search_regs_1
.end
[0] + BEGV_BYTE
);
1308 else /* non-RE case */
1310 unsigned char *raw_pattern
, *pat
;
1311 int raw_pattern_size
;
1312 int raw_pattern_size_byte
;
1313 unsigned char *patbuf
;
1314 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
1315 unsigned char *base_pat
;
1316 /* Set to positive if we find a non-ASCII char that need
1317 translation. Otherwise set to zero later. */
1319 int boyer_moore_ok
= 1;
1321 /* MULTIBYTE says whether the text to be searched is multibyte.
1322 We must convert PATTERN to match that, or we will not really
1323 find things right. */
1325 if (multibyte
== STRING_MULTIBYTE (string
))
1327 raw_pattern
= (unsigned char *) SDATA (string
);
1328 raw_pattern_size
= SCHARS (string
);
1329 raw_pattern_size_byte
= SBYTES (string
);
1333 raw_pattern_size
= SCHARS (string
);
1334 raw_pattern_size_byte
1335 = count_size_as_multibyte (SDATA (string
),
1337 raw_pattern
= (unsigned char *) alloca (raw_pattern_size_byte
+ 1);
1338 copy_text (SDATA (string
), raw_pattern
,
1339 SCHARS (string
), 0, 1);
1343 /* Converting multibyte to single-byte.
1345 ??? Perhaps this conversion should be done in a special way
1346 by subtracting nonascii-insert-offset from each non-ASCII char,
1347 so that only the multibyte chars which really correspond to
1348 the chosen single-byte character set can possibly match. */
1349 raw_pattern_size
= SCHARS (string
);
1350 raw_pattern_size_byte
= SCHARS (string
);
1351 raw_pattern
= (unsigned char *) alloca (raw_pattern_size
+ 1);
1352 copy_text (SDATA (string
), raw_pattern
,
1353 SBYTES (string
), 1, 0);
1356 /* Copy and optionally translate the pattern. */
1357 len
= raw_pattern_size
;
1358 len_byte
= raw_pattern_size_byte
;
1359 patbuf
= (unsigned char *) alloca (len
* MAX_MULTIBYTE_LENGTH
);
1361 base_pat
= raw_pattern
;
1364 /* Fill patbuf by translated characters in STRING while
1365 checking if we can use boyer-moore search. If TRT is
1366 non-nil, we can use boyer-moore search only if TRT can be
1367 represented by the byte array of 256 elements. For that,
1368 all non-ASCII case-equivalents of all case-senstive
1369 characters in STRING must belong to the same charset and
1374 unsigned char str_base
[MAX_MULTIBYTE_LENGTH
], *str
;
1375 int c
, translated
, inverse
;
1376 int in_charlen
, charlen
;
1378 /* If we got here and the RE flag is set, it's because we're
1379 dealing with a regexp known to be trivial, so the backslash
1380 just quotes the next character. */
1381 if (RE
&& *base_pat
== '\\')
1389 c
= STRING_CHAR_AND_LENGTH (base_pat
, len_byte
, in_charlen
);
1394 charlen
= in_charlen
;
1398 /* Translate the character. */
1399 TRANSLATE (translated
, trt
, c
);
1400 charlen
= CHAR_STRING (translated
, str_base
);
1403 /* Check if C has any other case-equivalents. */
1404 TRANSLATE (inverse
, inverse_trt
, c
);
1405 /* If so, check if we can use boyer-moore. */
1406 if (c
!= inverse
&& boyer_moore_ok
)
1408 /* Check if all equivalents belong to the same
1409 group of characters. Note that the check of C
1410 itself is done by the last iteration. */
1411 int this_char_base
= -1;
1413 while (boyer_moore_ok
)
1415 if (ASCII_BYTE_P (inverse
))
1417 if (this_char_base
> 0)
1422 else if (CHAR_BYTE8_P (inverse
))
1423 /* Boyer-moore search can't handle a
1424 translation of an eight-bit
1427 else if (this_char_base
< 0)
1429 this_char_base
= inverse
& ~0x3F;
1431 char_base
= this_char_base
;
1432 else if (this_char_base
!= char_base
)
1435 else if ((inverse
& ~0x3F) != this_char_base
)
1439 TRANSLATE (inverse
, inverse_trt
, inverse
);
1444 /* Store this character into the translated pattern. */
1445 bcopy (str
, pat
, charlen
);
1447 base_pat
+= in_charlen
;
1448 len_byte
-= in_charlen
;
1451 /* If char_base is still negative we didn't find any translated
1452 non-ASCII characters. */
1458 /* Unibyte buffer. */
1464 /* If we got here and the RE flag is set, it's because we're
1465 dealing with a regexp known to be trivial, so the backslash
1466 just quotes the next character. */
1467 if (RE
&& *base_pat
== '\\')
1474 TRANSLATE (translated
, trt
, c
);
1475 *pat
++ = translated
;
1479 len_byte
= pat
- patbuf
;
1480 len
= raw_pattern_size
;
1481 pat
= base_pat
= patbuf
;
1484 return boyer_moore (n
, pat
, len
, len_byte
, trt
, inverse_trt
,
1485 pos
, pos_byte
, lim
, lim_byte
,
1488 return simple_search (n
, pat
, len
, len_byte
, trt
,
1489 pos
, pos_byte
, lim
, lim_byte
);
1493 /* Do a simple string search N times for the string PAT,
1494 whose length is LEN/LEN_BYTE,
1495 from buffer position POS/POS_BYTE until LIM/LIM_BYTE.
1496 TRT is the translation table.
1498 Return the character position where the match is found.
1499 Otherwise, if M matches remained to be found, return -M.
1501 This kind of search works regardless of what is in PAT and
1502 regardless of what is in TRT. It is used in cases where
1503 boyer_moore cannot work. */
1506 simple_search (n
, pat
, len
, len_byte
, trt
, pos
, pos_byte
, lim
, lim_byte
)
1511 EMACS_INT pos
, pos_byte
;
1512 EMACS_INT lim
, lim_byte
;
1514 int multibyte
= ! NILP (current_buffer
->enable_multibyte_characters
);
1515 int forward
= n
> 0;
1516 /* Number of buffer bytes matched. Note that this may be different
1517 from len_byte in a multibyte buffer. */
1520 if (lim
> pos
&& multibyte
)
1525 /* Try matching at position POS. */
1526 EMACS_INT this_pos
= pos
;
1527 EMACS_INT this_pos_byte
= pos_byte
;
1529 int this_len_byte
= len_byte
;
1530 unsigned char *p
= pat
;
1531 if (pos
+ len
> lim
|| pos_byte
+ len_byte
> lim_byte
)
1534 while (this_len
> 0)
1536 int charlen
, buf_charlen
;
1539 pat_ch
= STRING_CHAR_AND_LENGTH (p
, this_len_byte
, charlen
);
1540 buf_ch
= STRING_CHAR_AND_LENGTH (BYTE_POS_ADDR (this_pos_byte
),
1541 ZV_BYTE
- this_pos_byte
,
1543 TRANSLATE (buf_ch
, trt
, buf_ch
);
1545 if (buf_ch
!= pat_ch
)
1548 this_len_byte
-= charlen
;
1552 this_pos_byte
+= buf_charlen
;
1558 match_byte
= this_pos_byte
- pos_byte
;
1560 pos_byte
+= match_byte
;
1564 INC_BOTH (pos
, pos_byte
);
1574 /* Try matching at position POS. */
1575 EMACS_INT this_pos
= pos
;
1577 unsigned char *p
= pat
;
1579 if (pos
+ len
> lim
)
1582 while (this_len
> 0)
1585 int buf_ch
= FETCH_BYTE (this_pos
);
1586 TRANSLATE (buf_ch
, trt
, buf_ch
);
1588 if (buf_ch
!= pat_ch
)
1607 /* Backwards search. */
1608 else if (lim
< pos
&& multibyte
)
1613 /* Try matching at position POS. */
1614 EMACS_INT this_pos
= pos
- len
;
1615 EMACS_INT this_pos_byte
;
1617 int this_len_byte
= len_byte
;
1618 unsigned char *p
= pat
;
1620 if (this_pos
< lim
|| (pos_byte
- len_byte
) < lim_byte
)
1622 this_pos_byte
= CHAR_TO_BYTE (this_pos
);
1623 match_byte
= pos_byte
- this_pos_byte
;
1625 while (this_len
> 0)
1627 int charlen
, buf_charlen
;
1630 pat_ch
= STRING_CHAR_AND_LENGTH (p
, this_len_byte
, charlen
);
1631 buf_ch
= STRING_CHAR_AND_LENGTH (BYTE_POS_ADDR (this_pos_byte
),
1632 ZV_BYTE
- this_pos_byte
,
1634 TRANSLATE (buf_ch
, trt
, buf_ch
);
1636 if (buf_ch
!= pat_ch
)
1639 this_len_byte
-= charlen
;
1642 this_pos_byte
+= buf_charlen
;
1649 pos_byte
-= match_byte
;
1653 DEC_BOTH (pos
, pos_byte
);
1663 /* Try matching at position POS. */
1664 EMACS_INT this_pos
= pos
- len
;
1666 unsigned char *p
= pat
;
1671 while (this_len
> 0)
1674 int buf_ch
= FETCH_BYTE (this_pos
);
1675 TRANSLATE (buf_ch
, trt
, buf_ch
);
1677 if (buf_ch
!= pat_ch
)
1700 set_search_regs ((multibyte
? pos_byte
: pos
) - match_byte
, match_byte
);
1702 set_search_regs (multibyte
? pos_byte
: pos
, match_byte
);
1712 /* Do Boyer-Moore search N times for the string BASE_PAT,
1713 whose length is LEN/LEN_BYTE,
1714 from buffer position POS/POS_BYTE until LIM/LIM_BYTE.
1715 DIRECTION says which direction we search in.
1716 TRT and INVERSE_TRT are translation tables.
1717 Characters in PAT are already translated by TRT.
1719 This kind of search works if all the characters in BASE_PAT that
1720 have nontrivial translation are the same aside from the last byte.
1721 This makes it possible to translate just the last byte of a
1722 character, and do so after just a simple test of the context.
1723 CHAR_BASE is nonzero if there is such a non-ASCII character.
1725 If that criterion is not satisfied, do not call this function. */
1728 boyer_moore (n
, base_pat
, len
, len_byte
, trt
, inverse_trt
,
1729 pos
, pos_byte
, lim
, lim_byte
, char_base
)
1731 unsigned char *base_pat
;
1734 Lisp_Object inverse_trt
;
1735 EMACS_INT pos
, pos_byte
;
1736 EMACS_INT lim
, lim_byte
;
1739 int direction
= ((n
> 0) ? 1 : -1);
1740 register int dirlen
;
1742 int stride_for_teases
= 0;
1744 register unsigned char *cursor
, *p_limit
;
1746 unsigned char *pat
, *pat_end
;
1747 int multibyte
= ! NILP (current_buffer
->enable_multibyte_characters
);
1749 unsigned char simple_translate
[0400];
1750 /* These are set to the preceding bytes of a byte to be translated
1751 if char_base is nonzero. As the maximum byte length of a
1752 multibyte character is 5, we have to check at most four previous
1754 int translate_prev_byte1
= 0;
1755 int translate_prev_byte2
= 0;
1756 int translate_prev_byte3
= 0;
1757 int translate_prev_byte4
= 0;
1759 /* The general approach is that we are going to maintain that we know
1760 the first (closest to the present position, in whatever direction
1761 we're searching) character that could possibly be the last
1762 (furthest from present position) character of a valid match. We
1763 advance the state of our knowledge by looking at that character
1764 and seeing whether it indeed matches the last character of the
1765 pattern. If it does, we take a closer look. If it does not, we
1766 move our pointer (to putative last characters) as far as is
1767 logically possible. This amount of movement, which I call a
1768 stride, will be the length of the pattern if the actual character
1769 appears nowhere in the pattern, otherwise it will be the distance
1770 from the last occurrence of that character to the end of the
1771 pattern. If the amount is zero we have a possible match. */
1773 /* Here we make a "mickey mouse" BM table. The stride of the search
1774 is determined only by the last character of the putative match.
1775 If that character does not match, we will stride the proper
1776 distance to propose a match that superimposes it on the last
1777 instance of a character that matches it (per trt), or misses
1778 it entirely if there is none. */
1780 dirlen
= len_byte
* direction
;
1782 /* Record position after the end of the pattern. */
1783 pat_end
= base_pat
+ len_byte
;
1784 /* BASE_PAT points to a character that we start scanning from.
1785 It is the first character in a forward search,
1786 the last character in a backward search. */
1788 base_pat
= pat_end
- 1;
1790 /* A character that does not appear in the pattern induces a
1791 stride equal to the pattern length. */
1792 for (i
= 0; i
< 0400; i
++)
1795 /* We use this for translation, instead of TRT itself.
1796 We fill this in to handle the characters that actually
1797 occur in the pattern. Others don't matter anyway! */
1798 for (i
= 0; i
< 0400; i
++)
1799 simple_translate
[i
] = i
;
1803 /* Setup translate_prev_byte1/2/3/4 from CHAR_BASE. Only a
1804 byte following them are the target of translation. */
1805 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
1806 int len
= CHAR_STRING (char_base
, str
);
1808 translate_prev_byte1
= str
[len
- 2];
1811 translate_prev_byte2
= str
[len
- 3];
1814 translate_prev_byte3
= str
[len
- 4];
1816 translate_prev_byte4
= str
[len
- 5];
1824 unsigned char *ptr
= base_pat
+ i
;
1828 /* If the byte currently looking at is the last of a
1829 character to check case-equivalents, set CH to that
1830 character. An ASCII character and a non-ASCII character
1831 matching with CHAR_BASE are to be checked. */
1834 if (ASCII_BYTE_P (*ptr
) || ! multibyte
)
1837 && ((pat_end
- ptr
) == 1 || CHAR_HEAD_P (ptr
[1])))
1839 unsigned char *charstart
= ptr
- 1;
1841 while (! (CHAR_HEAD_P (*charstart
)))
1843 ch
= STRING_CHAR (charstart
, ptr
- charstart
+ 1);
1844 if (char_base
!= (ch
& ~0x3F))
1849 j
= (ch
& 0x3F) | 0200;
1854 stride_for_teases
= BM_tab
[j
];
1856 BM_tab
[j
] = dirlen
- i
;
1857 /* A translation table is accompanied by its inverse -- see */
1858 /* comment following downcase_table for details */
1861 int starting_ch
= ch
;
1866 TRANSLATE (ch
, inverse_trt
, ch
);
1868 j
= (ch
& 0x3F) | 0200;
1872 /* For all the characters that map into CH,
1873 set up simple_translate to map the last byte
1875 simple_translate
[j
] = starting_j
;
1876 if (ch
== starting_ch
)
1878 BM_tab
[j
] = dirlen
- i
;
1887 stride_for_teases
= BM_tab
[j
];
1888 BM_tab
[j
] = dirlen
- i
;
1890 /* stride_for_teases tells how much to stride if we get a
1891 match on the far character but are subsequently
1892 disappointed, by recording what the stride would have been
1893 for that character if the last character had been
1896 pos_byte
+= dirlen
- ((direction
> 0) ? direction
: 0);
1897 /* loop invariant - POS_BYTE points at where last char (first
1898 char if reverse) of pattern would align in a possible match. */
1902 unsigned char *tail_end_ptr
;
1904 /* It's been reported that some (broken) compiler thinks that
1905 Boolean expressions in an arithmetic context are unsigned.
1906 Using an explicit ?1:0 prevents this. */
1907 if ((lim_byte
- pos_byte
- ((direction
> 0) ? 1 : 0)) * direction
1909 return (n
* (0 - direction
));
1910 /* First we do the part we can by pointers (maybe nothing) */
1913 limit
= pos_byte
- dirlen
+ direction
;
1916 limit
= BUFFER_CEILING_OF (limit
);
1917 /* LIMIT is now the last (not beyond-last!) value POS_BYTE
1918 can take on without hitting edge of buffer or the gap. */
1919 limit
= min (limit
, pos_byte
+ 20000);
1920 limit
= min (limit
, lim_byte
- 1);
1924 limit
= BUFFER_FLOOR_OF (limit
);
1925 /* LIMIT is now the last (not beyond-last!) value POS_BYTE
1926 can take on without hitting edge of buffer or the gap. */
1927 limit
= max (limit
, pos_byte
- 20000);
1928 limit
= max (limit
, lim_byte
);
1930 tail_end
= BUFFER_CEILING_OF (pos_byte
) + 1;
1931 tail_end_ptr
= BYTE_POS_ADDR (tail_end
);
1933 if ((limit
- pos_byte
) * direction
> 20)
1937 p_limit
= BYTE_POS_ADDR (limit
);
1938 p2
= (cursor
= BYTE_POS_ADDR (pos_byte
));
1939 /* In this loop, pos + cursor - p2 is the surrogate for pos. */
1940 while (1) /* use one cursor setting as long as i can */
1942 if (direction
> 0) /* worth duplicating */
1944 while (cursor
<= p_limit
)
1946 if (BM_tab
[*cursor
] == 0)
1948 cursor
+= BM_tab
[*cursor
];
1953 while (cursor
>= p_limit
)
1955 if (BM_tab
[*cursor
] == 0)
1957 cursor
+= BM_tab
[*cursor
];
1960 /* If you are here, cursor is beyond the end of the
1961 searched region. You fail to match within the
1962 permitted region and would otherwise try a character
1963 beyond that region. */
1967 i
= dirlen
- direction
;
1970 while ((i
-= direction
) + direction
!= 0)
1973 cursor
-= direction
;
1974 /* Translate only the last byte of a character. */
1976 || ((cursor
== tail_end_ptr
1977 || CHAR_HEAD_P (cursor
[1]))
1978 && (CHAR_HEAD_P (cursor
[0])
1979 /* Check if this is the last byte of
1980 a translable character. */
1981 || (translate_prev_byte1
== cursor
[-1]
1982 && (CHAR_HEAD_P (translate_prev_byte1
)
1983 || (translate_prev_byte2
== cursor
[-2]
1984 && (CHAR_HEAD_P (translate_prev_byte2
)
1985 || (translate_prev_byte3
== cursor
[-3]))))))))
1986 ch
= simple_translate
[*cursor
];
1995 while ((i
-= direction
) + direction
!= 0)
1997 cursor
-= direction
;
1998 if (pat
[i
] != *cursor
)
2002 cursor
+= dirlen
- i
- direction
; /* fix cursor */
2003 if (i
+ direction
== 0)
2005 EMACS_INT position
, start
, end
;
2007 cursor
-= direction
;
2009 position
= pos_byte
+ cursor
- p2
+ ((direction
> 0)
2010 ? 1 - len_byte
: 0);
2011 set_search_regs (position
, len_byte
);
2013 if (NILP (Vinhibit_changing_match_data
))
2015 start
= search_regs
.start
[0];
2016 end
= search_regs
.end
[0];
2019 /* If Vinhibit_changing_match_data is non-nil,
2020 search_regs will not be changed. So let's
2021 compute start and end here. */
2023 start
= BYTE_TO_CHAR (position
);
2024 end
= BYTE_TO_CHAR (position
+ len_byte
);
2027 if ((n
-= direction
) != 0)
2028 cursor
+= dirlen
; /* to resume search */
2030 return direction
> 0 ? end
: start
;
2033 cursor
+= stride_for_teases
; /* <sigh> we lose - */
2035 pos_byte
+= cursor
- p2
;
2038 /* Now we'll pick up a clump that has to be done the hard
2039 way because it covers a discontinuity. */
2041 limit
= ((direction
> 0)
2042 ? BUFFER_CEILING_OF (pos_byte
- dirlen
+ 1)
2043 : BUFFER_FLOOR_OF (pos_byte
- dirlen
- 1));
2044 limit
= ((direction
> 0)
2045 ? min (limit
+ len_byte
, lim_byte
- 1)
2046 : max (limit
- len_byte
, lim_byte
));
2047 /* LIMIT is now the last value POS_BYTE can have
2048 and still be valid for a possible match. */
2051 /* This loop can be coded for space rather than
2052 speed because it will usually run only once.
2053 (the reach is at most len + 21, and typically
2054 does not exceed len). */
2055 while ((limit
- pos_byte
) * direction
>= 0)
2057 int ch
= FETCH_BYTE (pos_byte
);
2058 if (BM_tab
[ch
] == 0)
2060 pos_byte
+= BM_tab
[ch
];
2062 break; /* ran off the end */
2065 /* Found what might be a match. */
2066 i
= dirlen
- direction
;
2067 while ((i
-= direction
) + direction
!= 0)
2071 pos_byte
-= direction
;
2072 ptr
= BYTE_POS_ADDR (pos_byte
);
2073 /* Translate only the last byte of a character. */
2075 || ((ptr
== tail_end_ptr
2076 || CHAR_HEAD_P (ptr
[1]))
2077 && (CHAR_HEAD_P (ptr
[0])
2078 /* Check if this is the last byte of a
2079 translable character. */
2080 || (translate_prev_byte1
== ptr
[-1]
2081 && (CHAR_HEAD_P (translate_prev_byte1
)
2082 || (translate_prev_byte2
== ptr
[-2]
2083 && (CHAR_HEAD_P (translate_prev_byte2
)
2084 || translate_prev_byte3
== ptr
[-3])))))))
2085 ch
= simple_translate
[*ptr
];
2091 /* Above loop has moved POS_BYTE part or all the way
2092 back to the first pos (last pos if reverse).
2093 Set it once again at the last (first if reverse) char. */
2094 pos_byte
+= dirlen
- i
- direction
;
2095 if (i
+ direction
== 0)
2097 EMACS_INT position
, start
, end
;
2098 pos_byte
-= direction
;
2100 position
= pos_byte
+ ((direction
> 0) ? 1 - len_byte
: 0);
2101 set_search_regs (position
, len_byte
);
2103 if (NILP (Vinhibit_changing_match_data
))
2105 start
= search_regs
.start
[0];
2106 end
= search_regs
.end
[0];
2109 /* If Vinhibit_changing_match_data is non-nil,
2110 search_regs will not be changed. So let's
2111 compute start and end here. */
2113 start
= BYTE_TO_CHAR (position
);
2114 end
= BYTE_TO_CHAR (position
+ len_byte
);
2117 if ((n
-= direction
) != 0)
2118 pos_byte
+= dirlen
; /* to resume search */
2120 return direction
> 0 ? end
: start
;
2123 pos_byte
+= stride_for_teases
;
2126 /* We have done one clump. Can we continue? */
2127 if ((lim_byte
- pos_byte
) * direction
< 0)
2128 return ((0 - n
) * direction
);
2130 return BYTE_TO_CHAR (pos_byte
);
2133 /* Record beginning BEG_BYTE and end BEG_BYTE + NBYTES
2134 for the overall match just found in the current buffer.
2135 Also clear out the match data for registers 1 and up. */
2138 set_search_regs (beg_byte
, nbytes
)
2139 EMACS_INT beg_byte
, nbytes
;
2143 if (!NILP (Vinhibit_changing_match_data
))
2146 /* Make sure we have registers in which to store
2147 the match position. */
2148 if (search_regs
.num_regs
== 0)
2150 search_regs
.start
= (regoff_t
*) xmalloc (2 * sizeof (regoff_t
));
2151 search_regs
.end
= (regoff_t
*) xmalloc (2 * sizeof (regoff_t
));
2152 search_regs
.num_regs
= 2;
2155 /* Clear out the other registers. */
2156 for (i
= 1; i
< search_regs
.num_regs
; i
++)
2158 search_regs
.start
[i
] = -1;
2159 search_regs
.end
[i
] = -1;
2162 search_regs
.start
[0] = BYTE_TO_CHAR (beg_byte
);
2163 search_regs
.end
[0] = BYTE_TO_CHAR (beg_byte
+ nbytes
);
2164 XSETBUFFER (last_thing_searched
, current_buffer
);
2167 /* Given STRING, a string of words separated by word delimiters,
2168 compute a regexp that matches those exact words separated by
2169 arbitrary punctuation. If LAX is nonzero, the end of the string
2170 need not match a word boundary unless it ends in whitespace. */
2173 wordify (string
, lax
)
2177 register unsigned char *p
, *o
;
2178 register int i
, i_byte
, len
, punct_count
= 0, word_count
= 0;
2181 int adjust
, whitespace_at_end
;
2183 CHECK_STRING (string
);
2185 len
= SCHARS (string
);
2187 for (i
= 0, i_byte
= 0; i
< len
; )
2191 FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c
, string
, i
, i_byte
);
2193 if (SYNTAX (c
) != Sword
)
2196 if (i
> 0 && SYNTAX (prev_c
) == Sword
)
2203 if (SYNTAX (prev_c
) == Sword
)
2206 whitespace_at_end
= 0;
2209 whitespace_at_end
= 1;
2212 return empty_unibyte_string
;
2214 adjust
= - punct_count
+ 5 * (word_count
- 1)
2215 + ((lax
&& !whitespace_at_end
) ? 2 : 4);
2216 if (STRING_MULTIBYTE (string
))
2217 val
= make_uninit_multibyte_string (len
+ adjust
,
2221 val
= make_uninit_string (len
+ adjust
);
2228 for (i
= 0, i_byte
= 0; i
< len
; )
2231 int i_byte_orig
= i_byte
;
2233 FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c
, string
, i
, i_byte
);
2235 if (SYNTAX (c
) == Sword
)
2237 bcopy (SDATA (string
) + i_byte_orig
, o
,
2238 i_byte
- i_byte_orig
);
2239 o
+= i_byte
- i_byte_orig
;
2241 else if (i
> 0 && SYNTAX (prev_c
) == Sword
&& --word_count
)
2253 if (!lax
|| whitespace_at_end
)
2262 DEFUN ("search-backward", Fsearch_backward
, Ssearch_backward
, 1, 4,
2263 "MSearch backward: ",
2264 doc
: /* Search backward from point for STRING.
2265 Set point to the beginning of the occurrence found, and return point.
2266 An optional second argument bounds the search; it is a buffer position.
2267 The match found must not extend before that position.
2268 Optional third argument, if t, means if fail just return nil (no error).
2269 If not nil and not t, position at limit of search and return nil.
2270 Optional fourth argument is repeat count--search for successive occurrences.
2272 Search case-sensitivity is determined by the value of the variable
2273 `case-fold-search', which see.
2275 See also the functions `match-beginning', `match-end' and `replace-match'. */)
2276 (string
, bound
, noerror
, count
)
2277 Lisp_Object string
, bound
, noerror
, count
;
2279 return search_command (string
, bound
, noerror
, count
, -1, 0, 0);
2282 DEFUN ("search-forward", Fsearch_forward
, Ssearch_forward
, 1, 4, "MSearch: ",
2283 doc
: /* Search forward from point for STRING.
2284 Set point to the end of the occurrence found, and return point.
2285 An optional second argument bounds the search; it is a buffer position.
2286 The match found must not extend after that position. A value of nil is
2287 equivalent to (point-max).
2288 Optional third argument, if t, means if fail just return nil (no error).
2289 If not nil and not t, move to limit of search and return nil.
2290 Optional fourth argument is repeat count--search for successive occurrences.
2292 Search case-sensitivity is determined by the value of the variable
2293 `case-fold-search', which see.
2295 See also the functions `match-beginning', `match-end' and `replace-match'. */)
2296 (string
, bound
, noerror
, count
)
2297 Lisp_Object string
, bound
, noerror
, count
;
2299 return search_command (string
, bound
, noerror
, count
, 1, 0, 0);
2302 DEFUN ("word-search-backward", Fword_search_backward
, Sword_search_backward
, 1, 4,
2303 "sWord search backward: ",
2304 doc
: /* Search backward from point for STRING, ignoring differences in punctuation.
2305 Set point to the beginning of the occurrence found, and return point.
2306 An optional second argument bounds the search; it is a buffer position.
2307 The match found must not extend before that position.
2308 Optional third argument, if t, means if fail just return nil (no error).
2309 If not nil and not t, move to limit of search and return nil.
2310 Optional fourth argument is repeat count--search for successive occurrences. */)
2311 (string
, bound
, noerror
, count
)
2312 Lisp_Object string
, bound
, noerror
, count
;
2314 return search_command (wordify (string
, 0), bound
, noerror
, count
, -1, 1, 0);
2317 DEFUN ("word-search-forward", Fword_search_forward
, Sword_search_forward
, 1, 4,
2319 doc
: /* Search forward from point for STRING, ignoring differences in punctuation.
2320 Set point to the end of the occurrence found, and return point.
2321 An optional second argument bounds the search; it is a buffer position.
2322 The match found must not extend after that position.
2323 Optional third argument, if t, means if fail just return nil (no error).
2324 If not nil and not t, move to limit of search and return nil.
2325 Optional fourth argument is repeat count--search for successive occurrences. */)
2326 (string
, bound
, noerror
, count
)
2327 Lisp_Object string
, bound
, noerror
, count
;
2329 return search_command (wordify (string
, 0), bound
, noerror
, count
, 1, 1, 0);
2332 DEFUN ("word-search-backward-lax", Fword_search_backward_lax
, Sword_search_backward_lax
, 1, 4,
2333 "sWord search backward: ",
2334 doc
: /* Search backward from point for STRING, ignoring differences in punctuation.
2335 Set point to the beginning of the occurrence found, and return point.
2337 Unlike `word-search-backward', the end of STRING need not match a word
2338 boundary unless it ends in whitespace.
2340 An optional second argument bounds the search; it is a buffer position.
2341 The match found must not extend before that position.
2342 Optional third argument, if t, means if fail just return nil (no error).
2343 If not nil and not t, move to limit of search and return nil.
2344 Optional fourth argument is repeat count--search for successive occurrences. */)
2345 (string
, bound
, noerror
, count
)
2346 Lisp_Object string
, bound
, noerror
, count
;
2348 return search_command (wordify (string
, 1), bound
, noerror
, count
, -1, 1, 0);
2351 DEFUN ("word-search-forward-lax", Fword_search_forward_lax
, Sword_search_forward_lax
, 1, 4,
2353 doc
: /* Search forward from point for STRING, ignoring differences in punctuation.
2354 Set point to the end of the occurrence found, and return point.
2356 Unlike `word-search-forward', the end of STRING need not match a word
2357 boundary unless it ends in whitespace.
2359 An optional second argument bounds the search; it is a buffer position.
2360 The match found must not extend after that position.
2361 Optional third argument, if t, means if fail just return nil (no error).
2362 If not nil and not t, move to limit of search and return nil.
2363 Optional fourth argument is repeat count--search for successive occurrences. */)
2364 (string
, bound
, noerror
, count
)
2365 Lisp_Object string
, bound
, noerror
, count
;
2367 return search_command (wordify (string
, 1), bound
, noerror
, count
, 1, 1, 0);
2370 DEFUN ("re-search-backward", Fre_search_backward
, Sre_search_backward
, 1, 4,
2371 "sRE search backward: ",
2372 doc
: /* Search backward from point for match for regular expression REGEXP.
2373 Set point to the beginning of the match, and return point.
2374 The match found is the one starting last in the buffer
2375 and yet ending before the origin of the search.
2376 An optional second argument bounds the search; it is a buffer position.
2377 The match found must start at or after that position.
2378 Optional third argument, if t, means if fail just return nil (no error).
2379 If not nil and not t, move to limit of search and return nil.
2380 Optional fourth argument is repeat count--search for successive occurrences.
2381 See also the functions `match-beginning', `match-end', `match-string',
2382 and `replace-match'. */)
2383 (regexp
, bound
, noerror
, count
)
2384 Lisp_Object regexp
, bound
, noerror
, count
;
2386 return search_command (regexp
, bound
, noerror
, count
, -1, 1, 0);
2389 DEFUN ("re-search-forward", Fre_search_forward
, Sre_search_forward
, 1, 4,
2391 doc
: /* Search forward from point for regular expression REGEXP.
2392 Set point to the end of the occurrence found, and return point.
2393 An optional second argument bounds the search; it is a buffer position.
2394 The match found must not extend after that position.
2395 Optional third argument, if t, means if fail just return nil (no error).
2396 If not nil and not t, move to limit of search and return nil.
2397 Optional fourth argument is repeat count--search for successive occurrences.
2398 See also the functions `match-beginning', `match-end', `match-string',
2399 and `replace-match'. */)
2400 (regexp
, bound
, noerror
, count
)
2401 Lisp_Object regexp
, bound
, noerror
, count
;
2403 return search_command (regexp
, bound
, noerror
, count
, 1, 1, 0);
2406 DEFUN ("posix-search-backward", Fposix_search_backward
, Sposix_search_backward
, 1, 4,
2407 "sPosix search backward: ",
2408 doc
: /* Search backward from point for match for regular expression REGEXP.
2409 Find the longest match in accord with Posix regular expression rules.
2410 Set point to the beginning of the match, and return point.
2411 The match found is the one starting last in the buffer
2412 and yet ending before the origin of the search.
2413 An optional second argument bounds the search; it is a buffer position.
2414 The match found must start at or after that position.
2415 Optional third argument, if t, means if fail just return nil (no error).
2416 If not nil and not t, move to limit of search and return nil.
2417 Optional fourth argument is repeat count--search for successive occurrences.
2418 See also the functions `match-beginning', `match-end', `match-string',
2419 and `replace-match'. */)
2420 (regexp
, bound
, noerror
, count
)
2421 Lisp_Object regexp
, bound
, noerror
, count
;
2423 return search_command (regexp
, bound
, noerror
, count
, -1, 1, 1);
2426 DEFUN ("posix-search-forward", Fposix_search_forward
, Sposix_search_forward
, 1, 4,
2428 doc
: /* Search forward from point for regular expression REGEXP.
2429 Find the longest match in accord with Posix regular expression rules.
2430 Set point to the end of the occurrence found, and return point.
2431 An optional second argument bounds the search; it is a buffer position.
2432 The match found must not extend after that position.
2433 Optional third argument, if t, means if fail just return nil (no error).
2434 If not nil and not t, move to limit of search and return nil.
2435 Optional fourth argument is repeat count--search for successive occurrences.
2436 See also the functions `match-beginning', `match-end', `match-string',
2437 and `replace-match'. */)
2438 (regexp
, bound
, noerror
, count
)
2439 Lisp_Object regexp
, bound
, noerror
, count
;
2441 return search_command (regexp
, bound
, noerror
, count
, 1, 1, 1);
2444 DEFUN ("replace-match", Freplace_match
, Sreplace_match
, 1, 5, 0,
2445 doc
: /* Replace text matched by last search with NEWTEXT.
2446 Leave point at the end of the replacement text.
2448 If second arg FIXEDCASE is non-nil, do not alter case of replacement text.
2449 Otherwise maybe capitalize the whole text, or maybe just word initials,
2450 based on the replaced text.
2451 If the replaced text has only capital letters
2452 and has at least one multiletter word, convert NEWTEXT to all caps.
2453 Otherwise if all words are capitalized in the replaced text,
2454 capitalize each word in NEWTEXT.
2456 If third arg LITERAL is non-nil, insert NEWTEXT literally.
2457 Otherwise treat `\\' as special:
2458 `\\&' in NEWTEXT means substitute original matched text.
2459 `\\N' means substitute what matched the Nth `\\(...\\)'.
2460 If Nth parens didn't match, substitute nothing.
2461 `\\\\' means insert one `\\'.
2462 Case conversion does not apply to these substitutions.
2464 FIXEDCASE and LITERAL are optional arguments.
2466 The optional fourth argument STRING can be a string to modify.
2467 This is meaningful when the previous match was done against STRING,
2468 using `string-match'. When used this way, `replace-match'
2469 creates and returns a new string made by copying STRING and replacing
2470 the part of STRING that was matched.
2472 The optional fifth argument SUBEXP specifies a subexpression;
2473 it says to replace just that subexpression with NEWTEXT,
2474 rather than replacing the entire matched text.
2475 This is, in a vague sense, the inverse of using `\\N' in NEWTEXT;
2476 `\\N' copies subexp N into NEWTEXT, but using N as SUBEXP puts
2477 NEWTEXT in place of subexp N.
2478 This is useful only after a regular expression search or match,
2479 since only regular expressions have distinguished subexpressions. */)
2480 (newtext
, fixedcase
, literal
, string
, subexp
)
2481 Lisp_Object newtext
, fixedcase
, literal
, string
, subexp
;
2483 enum { nochange
, all_caps
, cap_initial
} case_action
;
2484 register int pos
, pos_byte
;
2485 int some_multiletter_word
;
2488 int some_nonuppercase_initial
;
2489 register int c
, prevc
;
2491 EMACS_INT opoint
, newpoint
;
2493 CHECK_STRING (newtext
);
2495 if (! NILP (string
))
2496 CHECK_STRING (string
);
2498 case_action
= nochange
; /* We tried an initialization */
2499 /* but some C compilers blew it */
2501 if (search_regs
.num_regs
<= 0)
2502 error ("`replace-match' called before any match found");
2508 CHECK_NUMBER (subexp
);
2509 sub
= XINT (subexp
);
2510 if (sub
< 0 || sub
>= search_regs
.num_regs
)
2511 args_out_of_range (subexp
, make_number (search_regs
.num_regs
));
2516 if (search_regs
.start
[sub
] < BEGV
2517 || search_regs
.start
[sub
] > search_regs
.end
[sub
]
2518 || search_regs
.end
[sub
] > ZV
)
2519 args_out_of_range (make_number (search_regs
.start
[sub
]),
2520 make_number (search_regs
.end
[sub
]));
2524 if (search_regs
.start
[sub
] < 0
2525 || search_regs
.start
[sub
] > search_regs
.end
[sub
]
2526 || search_regs
.end
[sub
] > SCHARS (string
))
2527 args_out_of_range (make_number (search_regs
.start
[sub
]),
2528 make_number (search_regs
.end
[sub
]));
2531 if (NILP (fixedcase
))
2533 /* Decide how to casify by examining the matched text. */
2536 pos
= search_regs
.start
[sub
];
2537 last
= search_regs
.end
[sub
];
2540 pos_byte
= CHAR_TO_BYTE (pos
);
2542 pos_byte
= string_char_to_byte (string
, pos
);
2545 case_action
= all_caps
;
2547 /* some_multiletter_word is set nonzero if any original word
2548 is more than one letter long. */
2549 some_multiletter_word
= 0;
2551 some_nonuppercase_initial
= 0;
2558 c
= FETCH_CHAR_AS_MULTIBYTE (pos_byte
);
2559 INC_BOTH (pos
, pos_byte
);
2562 FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c
, string
, pos
, pos_byte
);
2566 /* Cannot be all caps if any original char is lower case */
2569 if (SYNTAX (prevc
) != Sword
)
2570 some_nonuppercase_initial
= 1;
2572 some_multiletter_word
= 1;
2574 else if (UPPERCASEP (c
))
2577 if (SYNTAX (prevc
) != Sword
)
2580 some_multiletter_word
= 1;
2584 /* If the initial is a caseless word constituent,
2585 treat that like a lowercase initial. */
2586 if (SYNTAX (prevc
) != Sword
)
2587 some_nonuppercase_initial
= 1;
2593 /* Convert to all caps if the old text is all caps
2594 and has at least one multiletter word. */
2595 if (! some_lowercase
&& some_multiletter_word
)
2596 case_action
= all_caps
;
2597 /* Capitalize each word, if the old text has all capitalized words. */
2598 else if (!some_nonuppercase_initial
&& some_multiletter_word
)
2599 case_action
= cap_initial
;
2600 else if (!some_nonuppercase_initial
&& some_uppercase
)
2601 /* Should x -> yz, operating on X, give Yz or YZ?
2602 We'll assume the latter. */
2603 case_action
= all_caps
;
2605 case_action
= nochange
;
2608 /* Do replacement in a string. */
2611 Lisp_Object before
, after
;
2613 before
= Fsubstring (string
, make_number (0),
2614 make_number (search_regs
.start
[sub
]));
2615 after
= Fsubstring (string
, make_number (search_regs
.end
[sub
]), Qnil
);
2617 /* Substitute parts of the match into NEWTEXT
2621 EMACS_INT lastpos
= 0;
2622 EMACS_INT lastpos_byte
= 0;
2623 /* We build up the substituted string in ACCUM. */
2626 int length
= SBYTES (newtext
);
2630 for (pos_byte
= 0, pos
= 0; pos_byte
< length
;)
2634 int delbackslash
= 0;
2636 FETCH_STRING_CHAR_ADVANCE (c
, newtext
, pos
, pos_byte
);
2640 FETCH_STRING_CHAR_ADVANCE (c
, newtext
, pos
, pos_byte
);
2644 substart
= search_regs
.start
[sub
];
2645 subend
= search_regs
.end
[sub
];
2647 else if (c
>= '1' && c
<= '9')
2649 if (search_regs
.start
[c
- '0'] >= 0
2650 && c
<= search_regs
.num_regs
+ '0')
2652 substart
= search_regs
.start
[c
- '0'];
2653 subend
= search_regs
.end
[c
- '0'];
2657 /* If that subexp did not match,
2658 replace \\N with nothing. */
2666 error ("Invalid use of `\\' in replacement text");
2670 if (pos
- 2 != lastpos
)
2671 middle
= substring_both (newtext
, lastpos
,
2673 pos
- 2, pos_byte
- 2);
2676 accum
= concat3 (accum
, middle
,
2678 make_number (substart
),
2679 make_number (subend
)));
2681 lastpos_byte
= pos_byte
;
2683 else if (delbackslash
)
2685 middle
= substring_both (newtext
, lastpos
,
2687 pos
- 1, pos_byte
- 1);
2689 accum
= concat2 (accum
, middle
);
2691 lastpos_byte
= pos_byte
;
2696 middle
= substring_both (newtext
, lastpos
,
2702 newtext
= concat2 (accum
, middle
);
2705 /* Do case substitution in NEWTEXT if desired. */
2706 if (case_action
== all_caps
)
2707 newtext
= Fupcase (newtext
);
2708 else if (case_action
== cap_initial
)
2709 newtext
= Fupcase_initials (newtext
);
2711 return concat3 (before
, newtext
, after
);
2714 /* Record point, then move (quietly) to the start of the match. */
2715 if (PT
>= search_regs
.end
[sub
])
2717 else if (PT
> search_regs
.start
[sub
])
2718 opoint
= search_regs
.end
[sub
] - ZV
;
2722 /* If we want non-literal replacement,
2723 perform substitution on the replacement string. */
2726 int length
= SBYTES (newtext
);
2727 unsigned char *substed
;
2728 int substed_alloc_size
, substed_len
;
2729 int buf_multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
2730 int str_multibyte
= STRING_MULTIBYTE (newtext
);
2731 Lisp_Object rev_tbl
;
2732 int really_changed
= 0;
2736 substed_alloc_size
= length
* 2 + 100;
2737 substed
= (unsigned char *) xmalloc (substed_alloc_size
+ 1);
2740 /* Go thru NEWTEXT, producing the actual text to insert in
2741 SUBSTED while adjusting multibyteness to that of the current
2744 for (pos_byte
= 0, pos
= 0; pos_byte
< length
;)
2746 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
2747 unsigned char *add_stuff
= NULL
;
2753 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c
, newtext
, pos
, pos_byte
);
2755 c
= multibyte_char_to_unibyte (c
, rev_tbl
);
2759 /* Note that we don't have to increment POS. */
2760 c
= SREF (newtext
, pos_byte
++);
2762 c
= unibyte_char_to_multibyte (c
);
2765 /* Either set ADD_STUFF and ADD_LEN to the text to put in SUBSTED,
2766 or set IDX to a match index, which means put that part
2767 of the buffer text into SUBSTED. */
2775 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c
, newtext
,
2777 if (!buf_multibyte
&& !ASCII_CHAR_P (c
))
2778 c
= multibyte_char_to_unibyte (c
, rev_tbl
);
2782 c
= SREF (newtext
, pos_byte
++);
2784 c
= unibyte_char_to_multibyte (c
);
2789 else if (c
>= '1' && c
<= '9' && c
<= search_regs
.num_regs
+ '0')
2791 if (search_regs
.start
[c
- '0'] >= 1)
2795 add_len
= 1, add_stuff
= "\\";
2799 error ("Invalid use of `\\' in replacement text");
2804 add_len
= CHAR_STRING (c
, str
);
2808 /* If we want to copy part of a previous match,
2809 set up ADD_STUFF and ADD_LEN to point to it. */
2812 EMACS_INT begbyte
= CHAR_TO_BYTE (search_regs
.start
[idx
]);
2813 add_len
= CHAR_TO_BYTE (search_regs
.end
[idx
]) - begbyte
;
2814 if (search_regs
.start
[idx
] < GPT
&& GPT
< search_regs
.end
[idx
])
2815 move_gap (search_regs
.start
[idx
]);
2816 add_stuff
= BYTE_POS_ADDR (begbyte
);
2819 /* Now the stuff we want to add to SUBSTED
2820 is invariably ADD_LEN bytes starting at ADD_STUFF. */
2822 /* Make sure SUBSTED is big enough. */
2823 if (substed_len
+ add_len
>= substed_alloc_size
)
2825 substed_alloc_size
= substed_len
+ add_len
+ 500;
2826 substed
= (unsigned char *) xrealloc (substed
,
2827 substed_alloc_size
+ 1);
2830 /* Now add to the end of SUBSTED. */
2833 bcopy (add_stuff
, substed
+ substed_len
, add_len
);
2834 substed_len
+= add_len
;
2842 int nchars
= multibyte_chars_in_text (substed
, substed_len
);
2844 newtext
= make_multibyte_string (substed
, nchars
, substed_len
);
2847 newtext
= make_unibyte_string (substed
, substed_len
);
2852 /* Replace the old text with the new in the cleanest possible way. */
2853 replace_range (search_regs
.start
[sub
], search_regs
.end
[sub
],
2855 newpoint
= search_regs
.start
[sub
] + SCHARS (newtext
);
2857 if (case_action
== all_caps
)
2858 Fupcase_region (make_number (search_regs
.start
[sub
]),
2859 make_number (newpoint
));
2860 else if (case_action
== cap_initial
)
2861 Fupcase_initials_region (make_number (search_regs
.start
[sub
]),
2862 make_number (newpoint
));
2864 /* Adjust search data for this change. */
2866 EMACS_INT oldend
= search_regs
.end
[sub
];
2867 EMACS_INT oldstart
= search_regs
.start
[sub
];
2868 EMACS_INT change
= newpoint
- search_regs
.end
[sub
];
2871 for (i
= 0; i
< search_regs
.num_regs
; i
++)
2873 if (search_regs
.start
[i
] >= oldend
)
2874 search_regs
.start
[i
] += change
;
2875 else if (search_regs
.start
[i
] > oldstart
)
2876 search_regs
.start
[i
] = oldstart
;
2877 if (search_regs
.end
[i
] >= oldend
)
2878 search_regs
.end
[i
] += change
;
2879 else if (search_regs
.end
[i
] > oldstart
)
2880 search_regs
.end
[i
] = oldstart
;
2884 /* Put point back where it was in the text. */
2886 TEMP_SET_PT (opoint
+ ZV
);
2888 TEMP_SET_PT (opoint
);
2890 /* Now move point "officially" to the start of the inserted replacement. */
2891 move_if_not_intangible (newpoint
);
2897 match_limit (num
, beginningp
)
2906 args_out_of_range (num
, make_number (0));
2907 if (search_regs
.num_regs
<= 0)
2908 error ("No match data, because no search succeeded");
2909 if (n
>= search_regs
.num_regs
2910 || search_regs
.start
[n
] < 0)
2912 return (make_number ((beginningp
) ? search_regs
.start
[n
]
2913 : search_regs
.end
[n
]));
2916 DEFUN ("match-beginning", Fmatch_beginning
, Smatch_beginning
, 1, 1, 0,
2917 doc
: /* Return position of start of text matched by last search.
2918 SUBEXP, a number, specifies which parenthesized expression in the last
2920 Value is nil if SUBEXPth pair didn't match, or there were less than
2922 Zero means the entire text matched by the whole regexp or whole string. */)
2926 return match_limit (subexp
, 1);
2929 DEFUN ("match-end", Fmatch_end
, Smatch_end
, 1, 1, 0,
2930 doc
: /* Return position of end of text matched by last search.
2931 SUBEXP, a number, specifies which parenthesized expression in the last
2933 Value is nil if SUBEXPth pair didn't match, or there were less than
2935 Zero means the entire text matched by the whole regexp or whole string. */)
2939 return match_limit (subexp
, 0);
2942 DEFUN ("match-data", Fmatch_data
, Smatch_data
, 0, 3, 0,
2943 doc
: /* Return a list containing all info on what the last search matched.
2944 Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'.
2945 All the elements are markers or nil (nil if the Nth pair didn't match)
2946 if the last match was on a buffer; integers or nil if a string was matched.
2947 Use `set-match-data' to reinstate the data in this list.
2949 If INTEGERS (the optional first argument) is non-nil, always use
2950 integers \(rather than markers) to represent buffer positions. In
2951 this case, and if the last match was in a buffer, the buffer will get
2952 stored as one additional element at the end of the list.
2954 If REUSE is a list, reuse it as part of the value. If REUSE is long
2955 enough to hold all the values, and if INTEGERS is non-nil, no consing
2958 If optional third arg RESEAT is non-nil, any previous markers on the
2959 REUSE list will be modified to point to nowhere.
2961 Return value is undefined if the last search failed. */)
2962 (integers
, reuse
, reseat
)
2963 Lisp_Object integers
, reuse
, reseat
;
2965 Lisp_Object tail
, prev
;
2970 for (tail
= reuse
; CONSP (tail
); tail
= XCDR (tail
))
2971 if (MARKERP (XCAR (tail
)))
2973 unchain_marker (XMARKER (XCAR (tail
)));
2974 XSETCAR (tail
, Qnil
);
2977 if (NILP (last_thing_searched
))
2982 data
= (Lisp_Object
*) alloca ((2 * search_regs
.num_regs
+ 1)
2983 * sizeof (Lisp_Object
));
2986 for (i
= 0; i
< search_regs
.num_regs
; i
++)
2988 int start
= search_regs
.start
[i
];
2991 if (EQ (last_thing_searched
, Qt
)
2992 || ! NILP (integers
))
2994 XSETFASTINT (data
[2 * i
], start
);
2995 XSETFASTINT (data
[2 * i
+ 1], search_regs
.end
[i
]);
2997 else if (BUFFERP (last_thing_searched
))
2999 data
[2 * i
] = Fmake_marker ();
3000 Fset_marker (data
[2 * i
],
3001 make_number (start
),
3002 last_thing_searched
);
3003 data
[2 * i
+ 1] = Fmake_marker ();
3004 Fset_marker (data
[2 * i
+ 1],
3005 make_number (search_regs
.end
[i
]),
3006 last_thing_searched
);
3009 /* last_thing_searched must always be Qt, a buffer, or Qnil. */
3015 data
[2 * i
] = data
[2 * i
+ 1] = Qnil
;
3018 if (BUFFERP (last_thing_searched
) && !NILP (integers
))
3020 data
[len
] = last_thing_searched
;
3024 /* If REUSE is not usable, cons up the values and return them. */
3025 if (! CONSP (reuse
))
3026 return Flist (len
, data
);
3028 /* If REUSE is a list, store as many value elements as will fit
3029 into the elements of REUSE. */
3030 for (i
= 0, tail
= reuse
; CONSP (tail
);
3031 i
++, tail
= XCDR (tail
))
3034 XSETCAR (tail
, data
[i
]);
3036 XSETCAR (tail
, Qnil
);
3040 /* If we couldn't fit all value elements into REUSE,
3041 cons up the rest of them and add them to the end of REUSE. */
3043 XSETCDR (prev
, Flist (len
- i
, data
+ i
));
3048 /* We used to have an internal use variant of `reseat' described as:
3050 If RESEAT is `evaporate', put the markers back on the free list
3051 immediately. No other references to the markers must exist in this
3052 case, so it is used only internally on the unwind stack and
3053 save-match-data from Lisp.
3055 But it was ill-conceived: those supposedly-internal markers get exposed via
3056 the undo-list, so freeing them here is unsafe. */
3058 DEFUN ("set-match-data", Fset_match_data
, Sset_match_data
, 1, 2, 0,
3059 doc
: /* Set internal data on last search match from elements of LIST.
3060 LIST should have been created by calling `match-data' previously.
3062 If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */)
3064 register Lisp_Object list
, reseat
;
3067 register Lisp_Object marker
;
3069 if (running_asynch_code
)
3070 save_search_regs ();
3074 /* Unless we find a marker with a buffer or an explicit buffer
3075 in LIST, assume that this match data came from a string. */
3076 last_thing_searched
= Qt
;
3078 /* Allocate registers if they don't already exist. */
3080 int length
= XFASTINT (Flength (list
)) / 2;
3082 if (length
> search_regs
.num_regs
)
3084 if (search_regs
.num_regs
== 0)
3087 = (regoff_t
*) xmalloc (length
* sizeof (regoff_t
));
3089 = (regoff_t
*) xmalloc (length
* sizeof (regoff_t
));
3094 = (regoff_t
*) xrealloc (search_regs
.start
,
3095 length
* sizeof (regoff_t
));
3097 = (regoff_t
*) xrealloc (search_regs
.end
,
3098 length
* sizeof (regoff_t
));
3101 for (i
= search_regs
.num_regs
; i
< length
; i
++)
3102 search_regs
.start
[i
] = -1;
3104 search_regs
.num_regs
= length
;
3107 for (i
= 0; CONSP (list
); i
++)
3109 marker
= XCAR (list
);
3110 if (BUFFERP (marker
))
3112 last_thing_searched
= marker
;
3119 search_regs
.start
[i
] = -1;
3128 if (MARKERP (marker
))
3130 if (XMARKER (marker
)->buffer
== 0)
3131 XSETFASTINT (marker
, 0);
3133 XSETBUFFER (last_thing_searched
, XMARKER (marker
)->buffer
);
3136 CHECK_NUMBER_COERCE_MARKER (marker
);
3137 from
= XINT (marker
);
3139 if (!NILP (reseat
) && MARKERP (m
))
3141 unchain_marker (XMARKER (m
));
3142 XSETCAR (list
, Qnil
);
3145 if ((list
= XCDR (list
), !CONSP (list
)))
3148 m
= marker
= XCAR (list
);
3150 if (MARKERP (marker
) && XMARKER (marker
)->buffer
== 0)
3151 XSETFASTINT (marker
, 0);
3153 CHECK_NUMBER_COERCE_MARKER (marker
);
3154 search_regs
.start
[i
] = from
;
3155 search_regs
.end
[i
] = XINT (marker
);
3157 if (!NILP (reseat
) && MARKERP (m
))
3159 unchain_marker (XMARKER (m
));
3160 XSETCAR (list
, Qnil
);
3166 for (; i
< search_regs
.num_regs
; i
++)
3167 search_regs
.start
[i
] = -1;
3173 /* If non-zero the match data have been saved in saved_search_regs
3174 during the execution of a sentinel or filter. */
3175 static int search_regs_saved
;
3176 static struct re_registers saved_search_regs
;
3177 static Lisp_Object saved_last_thing_searched
;
3179 /* Called from Flooking_at, Fstring_match, search_buffer, Fstore_match_data
3180 if asynchronous code (filter or sentinel) is running. */
3184 if (!search_regs_saved
)
3186 saved_search_regs
.num_regs
= search_regs
.num_regs
;
3187 saved_search_regs
.start
= search_regs
.start
;
3188 saved_search_regs
.end
= search_regs
.end
;
3189 saved_last_thing_searched
= last_thing_searched
;
3190 last_thing_searched
= Qnil
;
3191 search_regs
.num_regs
= 0;
3192 search_regs
.start
= 0;
3193 search_regs
.end
= 0;
3195 search_regs_saved
= 1;
3199 /* Called upon exit from filters and sentinels. */
3201 restore_search_regs ()
3203 if (search_regs_saved
)
3205 if (search_regs
.num_regs
> 0)
3207 xfree (search_regs
.start
);
3208 xfree (search_regs
.end
);
3210 search_regs
.num_regs
= saved_search_regs
.num_regs
;
3211 search_regs
.start
= saved_search_regs
.start
;
3212 search_regs
.end
= saved_search_regs
.end
;
3213 last_thing_searched
= saved_last_thing_searched
;
3214 saved_last_thing_searched
= Qnil
;
3215 search_regs_saved
= 0;
3220 unwind_set_match_data (list
)
3223 /* It is NOT ALWAYS safe to free (evaporate) the markers immediately. */
3224 return Fset_match_data (list
, Qt
);
3227 /* Called to unwind protect the match data. */
3229 record_unwind_save_match_data ()
3231 record_unwind_protect (unwind_set_match_data
,
3232 Fmatch_data (Qnil
, Qnil
, Qnil
));
3235 /* Quote a string to inactivate reg-expr chars */
3237 DEFUN ("regexp-quote", Fregexp_quote
, Sregexp_quote
, 1, 1, 0,
3238 doc
: /* Return a regexp string which matches exactly STRING and nothing else. */)
3242 register unsigned char *in
, *out
, *end
;
3243 register unsigned char *temp
;
3244 int backslashes_added
= 0;
3246 CHECK_STRING (string
);
3248 temp
= (unsigned char *) alloca (SBYTES (string
) * 2);
3250 /* Now copy the data into the new string, inserting escapes. */
3252 in
= SDATA (string
);
3253 end
= in
+ SBYTES (string
);
3256 for (; in
!= end
; in
++)
3259 || *in
== '*' || *in
== '.' || *in
== '\\'
3260 || *in
== '?' || *in
== '+'
3261 || *in
== '^' || *in
== '$')
3262 *out
++ = '\\', backslashes_added
++;
3266 return make_specified_string (temp
,
3267 SCHARS (string
) + backslashes_added
,
3269 STRING_MULTIBYTE (string
));
3277 for (i
= 0; i
< REGEXP_CACHE_SIZE
; ++i
)
3279 searchbufs
[i
].buf
.allocated
= 100;
3280 searchbufs
[i
].buf
.buffer
= (unsigned char *) xmalloc (100);
3281 searchbufs
[i
].buf
.fastmap
= searchbufs
[i
].fastmap
;
3282 searchbufs
[i
].regexp
= Qnil
;
3283 searchbufs
[i
].whitespace_regexp
= Qnil
;
3284 searchbufs
[i
].syntax_table
= Qnil
;
3285 staticpro (&searchbufs
[i
].regexp
);
3286 staticpro (&searchbufs
[i
].whitespace_regexp
);
3287 staticpro (&searchbufs
[i
].syntax_table
);
3288 searchbufs
[i
].next
= (i
== REGEXP_CACHE_SIZE
-1 ? 0 : &searchbufs
[i
+1]);
3290 searchbuf_head
= &searchbufs
[0];
3292 Qsearch_failed
= intern ("search-failed");
3293 staticpro (&Qsearch_failed
);
3294 Qinvalid_regexp
= intern ("invalid-regexp");
3295 staticpro (&Qinvalid_regexp
);
3297 Fput (Qsearch_failed
, Qerror_conditions
,
3298 Fcons (Qsearch_failed
, Fcons (Qerror
, Qnil
)));
3299 Fput (Qsearch_failed
, Qerror_message
,
3300 build_string ("Search failed"));
3302 Fput (Qinvalid_regexp
, Qerror_conditions
,
3303 Fcons (Qinvalid_regexp
, Fcons (Qerror
, Qnil
)));
3304 Fput (Qinvalid_regexp
, Qerror_message
,
3305 build_string ("Invalid regexp"));
3307 last_thing_searched
= Qnil
;
3308 staticpro (&last_thing_searched
);
3310 saved_last_thing_searched
= Qnil
;
3311 staticpro (&saved_last_thing_searched
);
3313 DEFVAR_LISP ("search-spaces-regexp", &Vsearch_spaces_regexp
,
3314 doc
: /* Regexp to substitute for bunches of spaces in regexp search.
3315 Some commands use this for user-specified regexps.
3316 Spaces that occur inside character classes or repetition operators
3317 or other such regexp constructs are not replaced with this.
3318 A value of nil (which is the normal value) means treat spaces literally. */);
3319 Vsearch_spaces_regexp
= Qnil
;
3321 DEFVAR_LISP ("inhibit-changing-match-data", &Vinhibit_changing_match_data
,
3322 doc
: /* Internal use only.
3323 If non-nil, the primitive searching and matching functions
3324 such as `looking-at', `string-match', `re-search-forward', etc.,
3325 do not set the match data. The proper way to use this variable
3326 is to bind it with `let' around a small expression. */);
3327 Vinhibit_changing_match_data
= Qnil
;
3329 defsubr (&Slooking_at
);
3330 defsubr (&Sposix_looking_at
);
3331 defsubr (&Sstring_match
);
3332 defsubr (&Sposix_string_match
);
3333 defsubr (&Ssearch_forward
);
3334 defsubr (&Ssearch_backward
);
3335 defsubr (&Sword_search_forward
);
3336 defsubr (&Sword_search_backward
);
3337 defsubr (&Sword_search_forward_lax
);
3338 defsubr (&Sword_search_backward_lax
);
3339 defsubr (&Sre_search_forward
);
3340 defsubr (&Sre_search_backward
);
3341 defsubr (&Sposix_search_forward
);
3342 defsubr (&Sposix_search_backward
);
3343 defsubr (&Sreplace_match
);
3344 defsubr (&Smatch_beginning
);
3345 defsubr (&Smatch_end
);
3346 defsubr (&Smatch_data
);
3347 defsubr (&Sset_match_data
);
3348 defsubr (&Sregexp_quote
);
3351 /* arch-tag: a6059d79-0552-4f14-a2cb-d379a4e3c78f
3352 (do not change this comment) */