Mercurial > emacs
annotate src/search.c @ 40195:dbb68d0ddad1
(compilation-set-window-height): Select
old window only if it's still live.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Mon, 22 Oct 2001 18:43:26 +0000 |
parents | e528f2adeed4 |
children | 613a0932bd77 |
rev | line source |
---|---|
603 | 1 /* String search routines for GNU Emacs. |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
25663
diff
changeset
|
2 Copyright (C) 1985, 86,87,93,94,97,98, 1999 Free Software Foundation, Inc. |
603 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
12244 | 8 the Free Software Foundation; either version 2, or (at your option) |
603 | 9 any later version. |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14086
diff
changeset
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14086
diff
changeset
|
19 Boston, MA 02111-1307, USA. */ |
603 | 20 |
21 | |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
4635
diff
changeset
|
22 #include <config.h> |
603 | 23 #include "lisp.h" |
24 #include "syntax.h" | |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
25 #include "category.h" |
603 | 26 #include "buffer.h" |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
27 #include "charset.h" |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
28 #include "region-cache.h" |
603 | 29 #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
|
30 #include "blockinput.h" |
20347
d8e5f3c1618b
Include "intervals.h" for prototypes.
Andreas Schwab <schwab@suse.de>
parents:
19541
diff
changeset
|
31 #include "intervals.h" |
621 | 32 |
603 | 33 #include <sys/types.h> |
34 #include "regex.h" | |
35 | |
16275
a4bcfdc9bb66
(REGEXP_CACHE_SIZE): Increase to 20.
Richard M. Stallman <rms@gnu.org>
parents:
16152
diff
changeset
|
36 #define REGEXP_CACHE_SIZE 20 |
603 | 37 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
38 /* 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
|
39 of that regexp, suitable for searching. */ |
16275
a4bcfdc9bb66
(REGEXP_CACHE_SIZE): Increase to 20.
Richard M. Stallman <rms@gnu.org>
parents:
16152
diff
changeset
|
40 struct regexp_cache |
a4bcfdc9bb66
(REGEXP_CACHE_SIZE): Increase to 20.
Richard M. Stallman <rms@gnu.org>
parents:
16152
diff
changeset
|
41 { |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
42 struct regexp_cache *next; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
43 Lisp_Object regexp; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
44 struct re_pattern_buffer buf; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
45 char fastmap[0400]; |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
46 /* 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
|
47 char posix; |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
48 }; |
603 | 49 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
50 /* The instances of that struct. */ |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
51 struct regexp_cache searchbufs[REGEXP_CACHE_SIZE]; |
603 | 52 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
53 /* 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
|
54 struct regexp_cache *searchbuf_head; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
55 |
603 | 56 |
621 | 57 /* Every call to re_match, etc., must pass &search_regs as the regs |
58 argument unless you can show it is unnecessary (i.e., if re_match | |
59 is certainly going to be called again before region-around-match | |
60 can be called). | |
61 | |
62 Since the registers are now dynamically allocated, we need to make | |
63 sure not to refer to the Nth register before checking that it has | |
708 | 64 been allocated by checking search_regs.num_regs. |
603 | 65 |
708 | 66 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
|
67 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
|
68 you compile a new pattern, it completely forgets whether it has |
708 | 69 allocated any registers, and will allocate new registers the next |
70 time you call a searching or matching function. Therefore, we need | |
71 to call re_set_registers after compiling a new pattern or after | |
72 setting the match registers, so that the regex functions will be | |
73 able to free or re-allocate it properly. */ | |
603 | 74 static struct re_registers search_regs; |
75 | |
727 | 76 /* The buffer in which the last search was performed, or |
77 Qt if the last search was done in a string; | |
78 Qnil if no searching has been done yet. */ | |
79 static Lisp_Object last_thing_searched; | |
603 | 80 |
14036 | 81 /* error condition signaled when regexp compile_pattern fails */ |
603 | 82 |
83 Lisp_Object Qinvalid_regexp; | |
84 | |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
85 static void set_search_regs (); |
10055
cb713218845a
(save_search_regs): Add declaration.
Richard M. Stallman <rms@gnu.org>
parents:
10032
diff
changeset
|
86 static void save_search_regs (); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
87 static int simple_search (); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
88 static int boyer_moore (); |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
89 static int search_buffer (); |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
90 |
603 | 91 static void |
92 matcher_overflow () | |
93 { | |
94 error ("Stack overflow in regexp matcher"); | |
95 } | |
96 | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
97 /* 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
|
98 PATTERN is the pattern to compile. |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 subexpression bounds. |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
105 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
|
106 for this pattern. 0 means backtrack only enough to get a valid match. |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
107 MULTIBYTE is nonzero if we want to handle multibyte characters in |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
108 PATTERN. 0 means all multibyte characters are recognized just as |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
109 sequences of binary data. */ |
603 | 110 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
111 static void |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
112 compile_pattern_1 (cp, pattern, translate, regp, posix, multibyte) |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
113 struct regexp_cache *cp; |
603 | 114 Lisp_Object pattern; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
115 Lisp_Object translate; |
708 | 116 struct re_registers *regp; |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
117 int posix; |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
118 int multibyte; |
603 | 119 { |
21915
8f1159b417c2
(search_buffer): Fix casts when assigning raw_pattern.
Richard M. Stallman <rms@gnu.org>
parents:
21887
diff
changeset
|
120 unsigned char *raw_pattern; |
20671
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
121 int raw_pattern_size; |
18762
12c0de0113af
(compile_pattern_1): Don't declare val with CONST.
Richard M. Stallman <rms@gnu.org>
parents:
18193
diff
changeset
|
122 char *val; |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
123 reg_syntax_t old; |
603 | 124 |
20671
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
125 /* MULTIBYTE says whether the text to be searched is multibyte. |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
126 We must convert PATTERN to match that, or we will not really |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
127 find things right. */ |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
128 |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
129 if (multibyte == STRING_MULTIBYTE (pattern)) |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
130 { |
21915
8f1159b417c2
(search_buffer): Fix casts when assigning raw_pattern.
Richard M. Stallman <rms@gnu.org>
parents:
21887
diff
changeset
|
131 raw_pattern = (unsigned char *) XSTRING (pattern)->data; |
21244
50929073a0ba
Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents:
21171
diff
changeset
|
132 raw_pattern_size = STRING_BYTES (XSTRING (pattern)); |
20671
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
133 } |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
134 else if (multibyte) |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
135 { |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
136 raw_pattern_size = count_size_as_multibyte (XSTRING (pattern)->data, |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
137 XSTRING (pattern)->size); |
21915
8f1159b417c2
(search_buffer): Fix casts when assigning raw_pattern.
Richard M. Stallman <rms@gnu.org>
parents:
21887
diff
changeset
|
138 raw_pattern = (unsigned char *) alloca (raw_pattern_size + 1); |
20671
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
139 copy_text (XSTRING (pattern)->data, raw_pattern, |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
140 XSTRING (pattern)->size, 0, 1); |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
141 } |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
142 else |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
143 { |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
144 /* Converting multibyte to single-byte. |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
145 |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
146 ??? Perhaps this conversion should be done in a special way |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
147 by subtracting nonascii-insert-offset from each non-ASCII char, |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
148 so that only the multibyte chars which really correspond to |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
149 the chosen single-byte character set can possibly match. */ |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
150 raw_pattern_size = XSTRING (pattern)->size; |
21915
8f1159b417c2
(search_buffer): Fix casts when assigning raw_pattern.
Richard M. Stallman <rms@gnu.org>
parents:
21887
diff
changeset
|
151 raw_pattern = (unsigned char *) alloca (raw_pattern_size + 1); |
20671
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
152 copy_text (XSTRING (pattern)->data, raw_pattern, |
21244
50929073a0ba
Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents:
21171
diff
changeset
|
153 STRING_BYTES (XSTRING (pattern)), 1, 0); |
20671
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
154 } |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
155 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
156 cp->regexp = Qnil; |
21531
5811a3129878
(compile_pattern, compile_pattern_1): Fix mixing of
Andreas Schwab <schwab@suse.de>
parents:
21514
diff
changeset
|
157 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
|
158 cp->posix = posix; |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
159 cp->buf.multibyte = multibyte; |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2393
diff
changeset
|
160 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
|
161 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
|
162 | (posix ? 0 : RE_NO_POSIX_BACKTRACKING)); |
21915
8f1159b417c2
(search_buffer): Fix casts when assigning raw_pattern.
Richard M. Stallman <rms@gnu.org>
parents:
21887
diff
changeset
|
163 val = (char *) re_compile_pattern ((char *)raw_pattern, |
8f1159b417c2
(search_buffer): Fix casts when assigning raw_pattern.
Richard M. Stallman <rms@gnu.org>
parents:
21887
diff
changeset
|
164 raw_pattern_size, &cp->buf); |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
165 re_set_syntax (old); |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2393
diff
changeset
|
166 UNBLOCK_INPUT; |
603 | 167 if (val) |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
168 Fsignal (Qinvalid_regexp, Fcons (build_string (val), Qnil)); |
708 | 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 | 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 |
239a4b800303
(shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22082
diff
changeset
|
178 shrink_regexp_cache () |
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 |
239a4b800303
(shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22082
diff
changeset
|
186 = (unsigned char *) realloc (cp->buf.buffer, cp->buf.used); |
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 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
190 /* 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
|
191 the cache. |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
192 PATTERN is the pattern to compile. |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
193 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
|
194 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
|
195 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
|
196 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
|
197 subexpression bounds. |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
198 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
|
199 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
|
200 |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
201 struct re_pattern_buffer * |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
202 compile_pattern (pattern, regp, translate, posix, multibyte) |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
203 Lisp_Object pattern; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
204 struct re_registers *regp; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
205 Lisp_Object translate; |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
206 int posix, multibyte; |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
207 { |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
208 struct regexp_cache *cp, **cpp; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
209 |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
210 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
|
211 { |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
212 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
|
213 /* 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
|
214 compile_pattern_1 if the pattern isn't valid. Don't apply |
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
|
215 XSTRING in those cases. However, compile_pattern_1 is only |
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
|
216 applied to the cache entry we pick here to reuse. So nil |
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
|
217 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
|
218 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
|
219 goto compile_it; |
16275
a4bcfdc9bb66
(REGEXP_CACHE_SIZE): Increase to 20.
Richard M. Stallman <rms@gnu.org>
parents:
16152
diff
changeset
|
220 if (XSTRING (cp->regexp)->size == XSTRING (pattern)->size |
31486
a3dc5f987e8f
(compile_pattern): Check the multibyteness of cached
Kenichi Handa <handa@m17n.org>
parents:
29335
diff
changeset
|
221 && 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
|
222 && !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
|
223 && 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
|
224 && cp->posix == posix |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
225 && cp->buf.multibyte == multibyte) |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
226 break; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
227 |
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
|
228 /* 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
|
229 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
|
230 string value. */ |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
231 if (cp->next == 0) |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
232 { |
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 compile_it: |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
234 compile_pattern_1 (cp, pattern, translate, regp, posix, multibyte); |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
235 break; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
236 } |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
237 } |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
238 |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
239 /* 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
|
240 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
|
241 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
|
242 *cpp = cp->next; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
243 cp->next = searchbuf_head; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
244 searchbuf_head = cp; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
245 |
10141
afe81fd385eb
(compile_pattern): Call re_set_registers here.
Richard M. Stallman <rms@gnu.org>
parents:
10128
diff
changeset
|
246 /* 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
|
247 for register data. */ |
afe81fd385eb
(compile_pattern): Call re_set_registers here.
Richard M. Stallman <rms@gnu.org>
parents:
10128
diff
changeset
|
248 if (regp) |
afe81fd385eb
(compile_pattern): Call re_set_registers here.
Richard M. Stallman <rms@gnu.org>
parents:
10128
diff
changeset
|
249 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
|
250 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
251 return &cp->buf; |
603 | 252 } |
253 | |
254 /* Error condition used for failing searches */ | |
255 Lisp_Object Qsearch_failed; | |
256 | |
257 Lisp_Object | |
258 signal_failure (arg) | |
259 Lisp_Object arg; | |
260 { | |
261 Fsignal (Qsearch_failed, Fcons (arg, Qnil)); | |
262 return Qnil; | |
263 } | |
264 | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
265 static Lisp_Object |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
266 looking_at_1 (string, posix) |
603 | 267 Lisp_Object string; |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
268 int posix; |
603 | 269 { |
270 Lisp_Object val; | |
271 unsigned char *p1, *p2; | |
272 int s1, s2; | |
273 register int i; | |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
274 struct re_pattern_buffer *bufp; |
603 | 275 |
10032
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
276 if (running_asynch_code) |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
277 save_search_regs (); |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
278 |
603 | 279 CHECK_STRING (string, 0); |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
280 bufp = compile_pattern (string, &search_regs, |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
281 (!NILP (current_buffer->case_fold_search) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
282 ? DOWNCASE_TABLE : Qnil), |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
283 posix, |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
284 !NILP (current_buffer->enable_multibyte_characters)); |
603 | 285 |
286 immediate_quit = 1; | |
287 QUIT; /* Do a pending quit right away, to avoid paradoxical behavior */ | |
288 | |
289 /* Get pointers and sizes of the two strings | |
290 that make up the visible portion of the buffer. */ | |
291 | |
292 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
|
293 s1 = GPT_BYTE - BEGV_BYTE; |
603 | 294 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
|
295 s2 = ZV_BYTE - GPT_BYTE; |
603 | 296 if (s1 < 0) |
297 { | |
298 p2 = p1; | |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
299 s2 = ZV_BYTE - BEGV_BYTE; |
603 | 300 s1 = 0; |
301 } | |
302 if (s2 < 0) | |
303 { | |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
304 s1 = ZV_BYTE - BEGV_BYTE; |
603 | 305 s2 = 0; |
306 } | |
17463
bb9ae80d22e2
(looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents:
17284
diff
changeset
|
307 |
bb9ae80d22e2
(looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents:
17284
diff
changeset
|
308 re_match_object = Qnil; |
603 | 309 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
310 i = re_match_2 (bufp, (char *) p1, s1, (char *) p2, s2, |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
311 PT_BYTE - BEGV_BYTE, &search_regs, |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
312 ZV_BYTE - BEGV_BYTE); |
26985
1121a5da20a5
(looking_at_1): Reset immediate_quit before modifying
Gerd Moellmann <gerd@gnu.org>
parents:
26982
diff
changeset
|
313 immediate_quit = 0; |
1121a5da20a5
(looking_at_1): Reset immediate_quit before modifying
Gerd Moellmann <gerd@gnu.org>
parents:
26982
diff
changeset
|
314 |
603 | 315 if (i == -2) |
316 matcher_overflow (); | |
317 | |
318 val = (0 <= i ? Qt : Qnil); | |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
319 if (i >= 0) |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
320 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
|
321 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
|
322 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
323 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
|
324 = 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
|
325 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
|
326 = 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
|
327 } |
9278
f2138d548313
(Flooking_at, skip_chars, search_buffer, set_search_regs, Fstore_match_data):
Karl Heuer <kwzh@gnu.org>
parents:
9113
diff
changeset
|
328 XSETBUFFER (last_thing_searched, current_buffer); |
603 | 329 return val; |
330 } | |
331 | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
332 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
|
333 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
|
334 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
|
335 `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
|
336 data if you want to preserve them. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
337 (regexp) |
11213
d0811ba886f8
(Flooking_at, Fposix_looking_at): Change arg name.
Richard M. Stallman <rms@gnu.org>
parents:
10250
diff
changeset
|
338 Lisp_Object regexp; |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
339 { |
11213
d0811ba886f8
(Flooking_at, Fposix_looking_at): Change arg name.
Richard M. Stallman <rms@gnu.org>
parents:
10250
diff
changeset
|
340 return looking_at_1 (regexp, 0); |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
341 } |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
342 |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
343 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
|
344 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
|
345 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
|
346 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
|
347 `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
|
348 data if you want to preserve them. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
349 (regexp) |
11213
d0811ba886f8
(Flooking_at, Fposix_looking_at): Change arg name.
Richard M. Stallman <rms@gnu.org>
parents:
10250
diff
changeset
|
350 Lisp_Object regexp; |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
351 { |
11213
d0811ba886f8
(Flooking_at, Fposix_looking_at): Change arg name.
Richard M. Stallman <rms@gnu.org>
parents:
10250
diff
changeset
|
352 return looking_at_1 (regexp, 1); |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
353 } |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
354 |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
355 static Lisp_Object |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
356 string_match_1 (regexp, string, start, posix) |
603 | 357 Lisp_Object regexp, string, start; |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
358 int posix; |
603 | 359 { |
360 int val; | |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
361 struct re_pattern_buffer *bufp; |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
362 int pos, pos_byte; |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
363 int i; |
603 | 364 |
10032
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
365 if (running_asynch_code) |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
366 save_search_regs (); |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
367 |
603 | 368 CHECK_STRING (regexp, 0); |
369 CHECK_STRING (string, 1); | |
370 | |
371 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
|
372 pos = 0, pos_byte = 0; |
603 | 373 else |
374 { | |
375 int len = XSTRING (string)->size; | |
376 | |
377 CHECK_NUMBER (start, 2); | |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
378 pos = XINT (start); |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
379 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
|
380 pos = len + pos; |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
381 else if (0 > pos || pos > len) |
603 | 382 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
|
383 pos_byte = string_char_to_byte (string, pos); |
603 | 384 } |
385 | |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
386 bufp = compile_pattern (regexp, &search_regs, |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
387 (!NILP (current_buffer->case_fold_search) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
388 ? DOWNCASE_TABLE : Qnil), |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
389 posix, |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
390 STRING_MULTIBYTE (string)); |
603 | 391 immediate_quit = 1; |
17463
bb9ae80d22e2
(looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents:
17284
diff
changeset
|
392 re_match_object = string; |
bb9ae80d22e2
(looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents:
17284
diff
changeset
|
393 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
394 val = re_search (bufp, (char *) XSTRING (string)->data, |
21244
50929073a0ba
Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents:
21171
diff
changeset
|
395 STRING_BYTES (XSTRING (string)), pos_byte, |
50929073a0ba
Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents:
21171
diff
changeset
|
396 STRING_BYTES (XSTRING (string)) - pos_byte, |
603 | 397 &search_regs); |
398 immediate_quit = 0; | |
727 | 399 last_thing_searched = Qt; |
603 | 400 if (val == -2) |
401 matcher_overflow (); | |
402 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
|
403 |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
404 for (i = 0; i < search_regs.num_regs; i++) |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
405 if (search_regs.start[i] >= 0) |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
406 { |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
407 search_regs.start[i] |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
408 = string_byte_to_char (string, search_regs.start[i]); |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
409 search_regs.end[i] |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
410 = string_byte_to_char (string, search_regs.end[i]); |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
411 } |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
412 |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
413 return make_number (string_byte_to_char (string, val)); |
603 | 414 } |
842 | 415 |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
416 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
|
417 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
|
418 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
|
419 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
|
420 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
|
421 `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
|
422 matched by parenthesis constructs in the pattern. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
423 (regexp, string, start) |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
424 Lisp_Object regexp, string, start; |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
425 { |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
426 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
|
427 } |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
428 |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
429 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
|
430 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
|
431 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
|
432 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
|
433 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
|
434 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
|
435 `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
|
436 matched by parenthesis constructs in the pattern. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
437 (regexp, string, start) |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
438 Lisp_Object regexp, string, start; |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
439 { |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
440 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
|
441 } |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
442 |
842 | 443 /* Match REGEXP against STRING, searching all of STRING, |
444 and return the index of the match, or negative on failure. | |
445 This does not clobber the match data. */ | |
446 | |
447 int | |
448 fast_string_match (regexp, string) | |
449 Lisp_Object regexp, string; | |
450 { | |
451 int val; | |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
452 struct re_pattern_buffer *bufp; |
842 | 453 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
454 bufp = compile_pattern (regexp, 0, Qnil, |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
455 0, STRING_MULTIBYTE (string)); |
842 | 456 immediate_quit = 1; |
17463
bb9ae80d22e2
(looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents:
17284
diff
changeset
|
457 re_match_object = string; |
bb9ae80d22e2
(looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents:
17284
diff
changeset
|
458 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
459 val = re_search (bufp, (char *) XSTRING (string)->data, |
21244
50929073a0ba
Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents:
21171
diff
changeset
|
460 STRING_BYTES (XSTRING (string)), 0, |
50929073a0ba
Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents:
21171
diff
changeset
|
461 STRING_BYTES (XSTRING (string)), 0); |
842 | 462 immediate_quit = 0; |
463 return val; | |
464 } | |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
465 |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
466 /* 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
|
467 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
|
468 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
|
469 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
|
470 |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
471 extern Lisp_Object Vascii_downcase_table; |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
472 |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
473 int |
18193
4e4c8edb56da
(fast_c_string_match_ignore_case):
Richard M. Stallman <rms@gnu.org>
parents:
18124
diff
changeset
|
474 fast_c_string_match_ignore_case (regexp, string) |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
475 Lisp_Object regexp; |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
476 char *string; |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
477 { |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
478 int val; |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
479 struct re_pattern_buffer *bufp; |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
480 int len = strlen (string); |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
481 |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
482 regexp = string_make_unibyte (regexp); |
18193
4e4c8edb56da
(fast_c_string_match_ignore_case):
Richard M. Stallman <rms@gnu.org>
parents:
18124
diff
changeset
|
483 re_match_object = Qt; |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
484 bufp = compile_pattern (regexp, 0, |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
485 Vascii_downcase_table, 0, |
20671
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
486 0); |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
487 immediate_quit = 1; |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
488 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
|
489 immediate_quit = 0; |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
490 return val; |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
491 } |
603 | 492 |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
493 /* 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
|
494 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
495 /* 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
|
496 Otherwise, make sure it's off. |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
497 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
|
498 state of a buffer-local variable. */ |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
499 static void |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
500 newline_cache_on_off (buf) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
501 struct buffer *buf; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
502 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
503 if (NILP (buf->cache_long_line_scans)) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
504 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
505 /* It should be off. */ |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
506 if (buf->newline_cache) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
507 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
508 free_region_cache (buf->newline_cache); |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
509 buf->newline_cache = 0; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
510 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
511 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
512 else |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
513 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
514 /* It should be on. */ |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
515 if (buf->newline_cache == 0) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
516 buf->newline_cache = new_region_cache (); |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
517 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
518 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
519 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
520 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
521 /* 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
|
522 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
523 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
|
524 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
|
525 END must be <= START. |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
526 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
|
527 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
528 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
|
529 direction indicated by COUNT. |
648 | 530 |
531 If we find COUNT instances, set *SHORTAGE to zero, and return the | |
1413 | 532 position after the COUNTth match. Note that for reverse motion |
533 this is not the same as the usual convention for Emacs motion commands. | |
648 | 534 |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
535 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
|
536 to the number of TARGETs left unfound, and return END. |
648 | 537 |
5756
a54c236b43c6
(scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents:
5556
diff
changeset
|
538 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
|
539 except when inside redisplay. */ |
a54c236b43c6
(scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents:
5556
diff
changeset
|
540 |
21514 | 541 int |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
542 scan_buffer (target, start, end, count, shortage, allow_quit) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
543 register int target; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
544 int start, end; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
545 int count; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
546 int *shortage; |
5756
a54c236b43c6
(scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents:
5556
diff
changeset
|
547 int allow_quit; |
603 | 548 { |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
549 struct region_cache *newline_cache; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
550 int direction; |
648 | 551 |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
552 if (count > 0) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
553 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
554 direction = 1; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
555 if (! end) end = ZV; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
556 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
557 else |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
558 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
559 direction = -1; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
560 if (! end) end = BEGV; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
561 } |
648 | 562 |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
563 newline_cache_on_off (current_buffer); |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
564 newline_cache = current_buffer->newline_cache; |
603 | 565 |
566 if (shortage != 0) | |
567 *shortage = 0; | |
568 | |
5756
a54c236b43c6
(scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents:
5556
diff
changeset
|
569 immediate_quit = allow_quit; |
603 | 570 |
648 | 571 if (count > 0) |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
572 while (start != end) |
603 | 573 { |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
574 /* 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
|
575 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
|
576 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
|
577 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
|
578 examine. */ |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
579 int ceiling_byte = CHAR_TO_BYTE (end) - 1; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
580 int start_byte = CHAR_TO_BYTE (start); |
21457
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
581 int tem; |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
582 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
583 /* 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
|
584 to see where we can avoid some scanning. */ |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
585 if (target == '\n' && newline_cache) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
586 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
587 int next_change; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
588 immediate_quit = 0; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
589 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
|
590 (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
|
591 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
|
592 immediate_quit = allow_quit; |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
593 |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
594 /* 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
|
595 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
|
596 start_byte = ceiling_byte; |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
597 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
598 /* 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
|
599 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
|
600 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
|
601 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
602 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
603 /* 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
|
604 bytes. BUFFER_CEILING_OF returns the last character |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
605 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
|
606 position after that. */ |
21457
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
607 tem = BUFFER_CEILING_OF (start_byte); |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
608 ceiling_byte = min (tem, ceiling_byte); |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
609 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
610 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
611 /* 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
|
612 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
|
613 = 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
|
614 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
|
615 = BYTE_POS_ADDR (start_byte); |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
616 unsigned char *base = cursor; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
617 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
618 while (cursor < ceiling_addr) |
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 unsigned char *scan_start = cursor; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
621 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
622 /* The dumb loop. */ |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
623 while (*cursor != target && ++cursor < ceiling_addr) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
624 ; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
625 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
626 /* 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
|
627 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
|
628 if (target == '\n' && newline_cache) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
629 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
|
630 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
|
631 start_byte + cursor - base); |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
632 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
633 /* Did we find the target character? */ |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
634 if (cursor < ceiling_addr) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
635 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
636 if (--count == 0) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
637 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
638 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
|
639 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
|
640 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
641 cursor++; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
642 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
643 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
644 |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
645 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
|
646 } |
603 | 647 } |
648 else | |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
649 while (start > end) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
650 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
651 /* The last character to check before the next obstacle. */ |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
652 int ceiling_byte = CHAR_TO_BYTE (end); |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
653 int start_byte = CHAR_TO_BYTE (start); |
21457
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
654 int tem; |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
655 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
656 /* Consult the newline cache, if appropriate. */ |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
657 if (target == '\n' && newline_cache) |
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 int next_change; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
660 immediate_quit = 0; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
661 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
|
662 (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
|
663 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
|
664 immediate_quit = allow_quit; |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
665 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
666 /* 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
|
667 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
|
668 start_byte = ceiling_byte + 1; |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
669 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
670 /* 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
|
671 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
|
672 ceiling_byte = max (next_change, ceiling_byte); |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
673 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
674 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
675 /* Stop scanning before the gap. */ |
21457
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
676 tem = BUFFER_FLOOR_OF (start_byte - 1); |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
677 ceiling_byte = max (tem, ceiling_byte); |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
678 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
679 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
680 /* 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
|
681 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
|
682 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
|
683 unsigned char *base = cursor; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
684 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
685 while (cursor >= ceiling_addr) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
686 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
687 unsigned char *scan_start = cursor; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
688 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
689 while (*cursor != target && --cursor >= ceiling_addr) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
690 ; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
691 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
692 /* 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
|
693 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
|
694 if (target == '\n' && newline_cache) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
695 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
|
696 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
|
697 start_byte + scan_start - base); |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
698 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
699 /* Did we find the target character? */ |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
700 if (cursor >= ceiling_addr) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
701 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
702 if (++count >= 0) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
703 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
704 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
|
705 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
|
706 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
707 cursor--; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
708 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
709 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
710 |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
711 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
|
712 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
713 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
714 |
603 | 715 immediate_quit = 0; |
716 if (shortage != 0) | |
648 | 717 *shortage = count * direction; |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
718 return start; |
603 | 719 } |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
720 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
721 /* 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
|
722 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
|
723 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
|
724 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
725 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
|
726 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
727 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
|
728 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
|
729 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
730 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
|
731 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
|
732 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
|
733 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
|
734 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
735 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
|
736 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
|
737 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
738 int |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
739 scan_newline (start, start_byte, limit, limit_byte, count, allow_quit) |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
740 int start, start_byte; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
741 int limit, limit_byte; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
742 register int count; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
743 int allow_quit; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
744 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
745 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
|
746 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
747 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
|
748 unsigned char *base; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
749 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
750 register int ceiling; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
751 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
|
752 |
20547
07053199a368
(scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents:
20545
diff
changeset
|
753 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
|
754 |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
755 /* If we are not in selective display mode, |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
756 check only for newlines. */ |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
757 int selective_display = (!NILP (current_buffer->selective_display) |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
758 && !INTEGERP (current_buffer->selective_display)); |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
759 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
760 /* 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
|
761 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
|
762 |
20547
07053199a368
(scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents:
20545
diff
changeset
|
763 if (allow_quit) |
07053199a368
(scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents:
20545
diff
changeset
|
764 immediate_quit++; |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
765 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
766 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
|
767 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
768 if (count > 0) |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
769 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
770 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
|
771 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
772 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
|
773 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
|
774 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
|
775 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
|
776 while (1) |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
777 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
778 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
|
779 ; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
780 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
781 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
|
782 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
783 if (--count == 0) |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
784 { |
20547
07053199a368
(scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents:
20545
diff
changeset
|
785 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
|
786 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
|
787 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
|
788 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
|
789 return 0; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
790 } |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
791 else |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
792 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
|
793 break; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
794 } |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
795 else |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
796 break; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
797 } |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
798 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
|
799 } |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
800 } |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
801 else |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
802 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
803 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
|
804 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
805 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
|
806 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
|
807 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
|
808 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
|
809 while (1) |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
810 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
811 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
|
812 ; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
813 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
814 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
|
815 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
816 if (++count == 0) |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
817 { |
20547
07053199a368
(scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents:
20545
diff
changeset
|
818 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
|
819 /* 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
|
820 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
|
821 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
|
822 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
|
823 return 0; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
824 } |
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 else |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
827 break; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
828 } |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
829 /* 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
|
830 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
|
831 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
|
832 } |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
833 } |
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 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
|
836 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
|
837 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
838 return count * direction; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
839 } |
603 | 840 |
841 int | |
7891
7d8e0f338e4a
(find_next_newline_no_quit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
7856
diff
changeset
|
842 find_next_newline_no_quit (from, cnt) |
7d8e0f338e4a
(find_next_newline_no_quit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
7856
diff
changeset
|
843 register int from, cnt; |
7d8e0f338e4a
(find_next_newline_no_quit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
7856
diff
changeset
|
844 { |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
845 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
|
846 } |
7d8e0f338e4a
(find_next_newline_no_quit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
7856
diff
changeset
|
847 |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
848 /* 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
|
849 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
|
850 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
|
851 |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
852 int |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
853 find_before_next_newline (from, to, cnt) |
9452
76f75b9091f1
(scan_buffer): After temporarily turning immediate_quit off, turn it
Jim Blandy <jimb@redhat.com>
parents:
9410
diff
changeset
|
854 int from, to, cnt; |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
855 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
856 int shortage; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
857 int pos = scan_buffer ('\n', from, to, cnt, &shortage, 1); |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
858 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
859 if (shortage == 0) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
860 pos--; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
861 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
862 return pos; |
603 | 863 } |
864 | |
865 /* Subroutines of Lisp buffer search functions. */ | |
866 | |
867 static Lisp_Object | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
868 search_command (string, bound, noerror, count, direction, RE, posix) |
603 | 869 Lisp_Object string, bound, noerror, count; |
870 int direction; | |
871 int RE; | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
872 int posix; |
603 | 873 { |
874 register int np; | |
20824
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
875 int lim, lim_byte; |
603 | 876 int n = direction; |
877 | |
878 if (!NILP (count)) | |
879 { | |
880 CHECK_NUMBER (count, 3); | |
881 n *= XINT (count); | |
882 } | |
883 | |
884 CHECK_STRING (string, 0); | |
885 if (NILP (bound)) | |
20824
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
886 { |
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
887 if (n > 0) |
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
888 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
|
889 else |
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
890 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
|
891 } |
603 | 892 else |
893 { | |
894 CHECK_NUMBER_COERCE_MARKER (bound, 1); | |
895 lim = XINT (bound); | |
16039
855c8d8ba0f0
Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents:
15667
diff
changeset
|
896 if (n > 0 ? lim < PT : lim > PT) |
603 | 897 error ("Invalid search bound (wrong side of point)"); |
898 if (lim > ZV) | |
20824
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
899 lim = ZV, lim_byte = ZV_BYTE; |
20924
eda7e44ef9d9
(search_command): Check LIM in valid range
Karl Heuer <kwzh@gnu.org>
parents:
20898
diff
changeset
|
900 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
|
901 lim = BEGV, lim_byte = BEGV_BYTE; |
20924
eda7e44ef9d9
(search_command): Check LIM in valid range
Karl Heuer <kwzh@gnu.org>
parents:
20898
diff
changeset
|
902 else |
eda7e44ef9d9
(search_command): Check LIM in valid range
Karl Heuer <kwzh@gnu.org>
parents:
20898
diff
changeset
|
903 lim_byte = CHAR_TO_BYTE (lim); |
603 | 904 } |
905 | |
20824
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
906 np = search_buffer (string, PT, PT_BYTE, lim, lim_byte, n, RE, |
603 | 907 (!NILP (current_buffer->case_fold_search) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
908 ? current_buffer->case_canon_table |
20875
4fac9830041a
(search_command): Fix call to search_buffer.
Richard M. Stallman <rms@gnu.org>
parents:
20869
diff
changeset
|
909 : Qnil), |
603 | 910 (!NILP (current_buffer->case_fold_search) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
911 ? current_buffer->case_eqv_table |
20875
4fac9830041a
(search_command): Fix call to search_buffer.
Richard M. Stallman <rms@gnu.org>
parents:
20869
diff
changeset
|
912 : Qnil), |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
913 posix); |
603 | 914 if (np <= 0) |
915 { | |
916 if (NILP (noerror)) | |
917 return signal_failure (string); | |
918 if (!EQ (noerror, Qt)) | |
919 { | |
920 if (lim < BEGV || lim > ZV) | |
921 abort (); | |
20824
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
922 SET_PT_BOTH (lim, lim_byte); |
1878
1c26d0049d4f
(search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents:
1877
diff
changeset
|
923 return Qnil; |
1c26d0049d4f
(search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents:
1877
diff
changeset
|
924 #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
|
925 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
|
926 np = lim; |
1878
1c26d0049d4f
(search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents:
1877
diff
changeset
|
927 #endif |
603 | 928 } |
1877
7786f61ec635
(search_command): When moving to LIM on failure, return LIM.
Richard M. Stallman <rms@gnu.org>
parents:
1684
diff
changeset
|
929 else |
7786f61ec635
(search_command): When moving to LIM on failure, return LIM.
Richard M. Stallman <rms@gnu.org>
parents:
1684
diff
changeset
|
930 return Qnil; |
603 | 931 } |
932 | |
933 if (np < BEGV || np > ZV) | |
934 abort (); | |
935 | |
936 SET_PT (np); | |
937 | |
938 return make_number (np); | |
939 } | |
940 | |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
941 /* 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
|
942 |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
943 static int |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
944 trivial_regexp_p (regexp) |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
945 Lisp_Object regexp; |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
946 { |
21244
50929073a0ba
Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents:
21171
diff
changeset
|
947 int len = STRING_BYTES (XSTRING (regexp)); |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
948 unsigned char *s = XSTRING (regexp)->data; |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
949 while (--len >= 0) |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
950 { |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
951 switch (*s++) |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
952 { |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
953 case '.': case '*': case '+': case '?': case '[': case '^': case '$': |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
954 return 0; |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
955 case '\\': |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
956 if (--len < 0) |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
957 return 0; |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
958 switch (*s++) |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
959 { |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
960 case '|': case '(': case ')': case '`': case '\'': case 'b': |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
961 case 'B': case '<': case '>': case 'w': case 'W': case 's': |
39487
b21317213c81
(trivial_regexp_p): Catch \{N,M\} as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35831
diff
changeset
|
962 case 'S': case '=': case '{': case '}': |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
963 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
|
964 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
|
965 case '6': case '7': case '8': case '9': |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
966 return 0; |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
967 } |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
968 } |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
969 } |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
970 return 1; |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
971 } |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
972 |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
973 /* Search for the n'th occurrence of STRING in the current buffer, |
603 | 974 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
|
975 treating STRING as a literal string if RE is false or as |
603 | 976 a regular expression if RE is true. |
977 | |
978 If N is positive, searching is forward and LIM must be greater than POS. | |
979 If N is negative, searching is backward and LIM must be less than POS. | |
980 | |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
981 Returns -x if x occurrences remain to be found (x > 0), |
603 | 982 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
|
983 (if searching backward) or the end (if searching forward). |
603 | 984 |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
985 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
|
986 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
|
987 |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
988 #define TRANSLATE(out, trt, d) \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
989 do \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
990 { \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
991 if (! NILP (trt)) \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
992 { \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
993 Lisp_Object temp; \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
994 temp = Faref (trt, make_number (d)); \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
995 if (INTEGERP (temp)) \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
996 out = XINT (temp); \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
997 else \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
998 out = d; \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
999 } \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1000 else \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1001 out = d; \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1002 } \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1003 while (0) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1004 |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
1005 static int |
20824
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
1006 search_buffer (string, pos, pos_byte, lim, lim_byte, n, |
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
1007 RE, trt, inverse_trt, posix) |
603 | 1008 Lisp_Object string; |
1009 int pos; | |
20824
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
1010 int pos_byte; |
603 | 1011 int lim; |
20824
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
1012 int lim_byte; |
603 | 1013 int n; |
1014 int RE; | |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1015 Lisp_Object trt; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1016 Lisp_Object inverse_trt; |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
1017 int posix; |
603 | 1018 { |
1019 int len = XSTRING (string)->size; | |
21244
50929073a0ba
Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents:
21171
diff
changeset
|
1020 int len_byte = STRING_BYTES (XSTRING (string)); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1021 register int i; |
603 | 1022 |
10032
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
1023 if (running_asynch_code) |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
1024 save_search_regs (); |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
1025 |
22082
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
1026 /* Searching 0 times means don't move. */ |
603 | 1027 /* 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
|
1028 if (len == 0 || n == 0) |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
1029 { |
35831
dc8b618615ea
(search_buffer): Call set_search_regs with a byte
Gerd Moellmann <gerd@gnu.org>
parents:
34966
diff
changeset
|
1030 set_search_regs (pos_byte, 0); |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
1031 return pos; |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
1032 } |
4299
7a2e1d7362c5
(search_buffer): If n is 0, just return POS.
Richard M. Stallman <rms@gnu.org>
parents:
3615
diff
changeset
|
1033 |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1034 if (RE && !trivial_regexp_p (string)) |
603 | 1035 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1036 unsigned char *p1, *p2; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1037 int s1, s2; |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
1038 struct re_pattern_buffer *bufp; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
1039 |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1040 bufp = compile_pattern (string, &search_regs, trt, posix, |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1041 !NILP (current_buffer->enable_multibyte_characters)); |
603 | 1042 |
1043 immediate_quit = 1; /* Quit immediately if user types ^G, | |
1044 because letting this function finish | |
1045 can take too long. */ | |
1046 QUIT; /* Do a pending quit right away, | |
1047 to avoid paradoxical behavior */ | |
1048 /* Get pointers and sizes of the two strings | |
1049 that make up the visible portion of the buffer. */ | |
1050 | |
1051 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
|
1052 s1 = GPT_BYTE - BEGV_BYTE; |
603 | 1053 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
|
1054 s2 = ZV_BYTE - GPT_BYTE; |
603 | 1055 if (s1 < 0) |
1056 { | |
1057 p2 = p1; | |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
1058 s2 = ZV_BYTE - BEGV_BYTE; |
603 | 1059 s1 = 0; |
1060 } | |
1061 if (s2 < 0) | |
1062 { | |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
1063 s1 = ZV_BYTE - BEGV_BYTE; |
603 | 1064 s2 = 0; |
1065 } | |
17463
bb9ae80d22e2
(looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents:
17284
diff
changeset
|
1066 re_match_object = Qnil; |
bb9ae80d22e2
(looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents:
17284
diff
changeset
|
1067 |
603 | 1068 while (n < 0) |
1069 { | |
2475
052bbdf1b817
(search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1070 int val; |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
1071 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
|
1072 pos_byte - BEGV_BYTE, lim_byte - pos_byte, |
f0aa5cc14e8a
(fast_string_match): Give re_search byte size of
Kenichi Handa <handa@m17n.org>
parents:
20706
diff
changeset
|
1073 &search_regs, |
2475
052bbdf1b817
(search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1074 /* 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
|
1075 pos_byte - BEGV_BYTE); |
603 | 1076 if (val == -2) |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1077 { |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1078 matcher_overflow (); |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1079 } |
603 | 1080 if (val >= 0) |
1081 { | |
20927
765fdbf766e4
(search_buffer): Update POS_BYTE for regexp search.
Kenichi Handa <handa@m17n.org>
parents:
20924
diff
changeset
|
1082 pos_byte = search_regs.start[0] + BEGV_BYTE; |
621 | 1083 for (i = 0; i < search_regs.num_regs; i++) |
603 | 1084 if (search_regs.start[i] >= 0) |
1085 { | |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
1086 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
|
1087 = 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
|
1088 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
|
1089 = BYTE_TO_CHAR (search_regs.end[i] + BEGV_BYTE); |
603 | 1090 } |
9278
f2138d548313
(Flooking_at, skip_chars, search_buffer, set_search_regs, Fstore_match_data):
Karl Heuer <kwzh@gnu.org>
parents:
9113
diff
changeset
|
1091 XSETBUFFER (last_thing_searched, current_buffer); |
603 | 1092 /* Set pos to the new position. */ |
1093 pos = search_regs.start[0]; | |
1094 } | |
1095 else | |
1096 { | |
1097 immediate_quit = 0; | |
1098 return (n); | |
1099 } | |
1100 n++; | |
1101 } | |
1102 while (n > 0) | |
1103 { | |
2475
052bbdf1b817
(search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1104 int val; |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
1105 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
|
1106 pos_byte - BEGV_BYTE, lim_byte - pos_byte, |
f0aa5cc14e8a
(fast_string_match): Give re_search byte size of
Kenichi Handa <handa@m17n.org>
parents:
20706
diff
changeset
|
1107 &search_regs, |
f0aa5cc14e8a
(fast_string_match): Give re_search byte size of
Kenichi Handa <handa@m17n.org>
parents:
20706
diff
changeset
|
1108 lim_byte - BEGV_BYTE); |
603 | 1109 if (val == -2) |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1110 { |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1111 matcher_overflow (); |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1112 } |
603 | 1113 if (val >= 0) |
1114 { | |
20927
765fdbf766e4
(search_buffer): Update POS_BYTE for regexp search.
Kenichi Handa <handa@m17n.org>
parents:
20924
diff
changeset
|
1115 pos_byte = search_regs.end[0] + BEGV_BYTE; |
621 | 1116 for (i = 0; i < search_regs.num_regs; i++) |
603 | 1117 if (search_regs.start[i] >= 0) |
1118 { | |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
1119 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
|
1120 = 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
|
1121 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
|
1122 = BYTE_TO_CHAR (search_regs.end[i] + BEGV_BYTE); |
603 | 1123 } |
9278
f2138d548313
(Flooking_at, skip_chars, search_buffer, set_search_regs, Fstore_match_data):
Karl Heuer <kwzh@gnu.org>
parents:
9113
diff
changeset
|
1124 XSETBUFFER (last_thing_searched, current_buffer); |
603 | 1125 pos = search_regs.end[0]; |
1126 } | |
1127 else | |
1128 { | |
1129 immediate_quit = 0; | |
1130 return (0 - n); | |
1131 } | |
1132 n--; | |
1133 } | |
1134 immediate_quit = 0; | |
1135 return (pos); | |
1136 } | |
1137 else /* non-RE case */ | |
1138 { | |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1139 unsigned char *raw_pattern, *pat; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1140 int raw_pattern_size; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1141 int raw_pattern_size_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1142 unsigned char *patbuf; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1143 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
|
1144 unsigned char *base_pat = XSTRING (string)->data; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1145 int charset_base = -1; |
23876
8d2f38338c81
(search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents:
23790
diff
changeset
|
1146 int boyer_moore_ok = 1; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1147 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1148 /* 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
|
1149 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
|
1150 find things right. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1151 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1152 if (multibyte == STRING_MULTIBYTE (string)) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1153 { |
21915
8f1159b417c2
(search_buffer): Fix casts when assigning raw_pattern.
Richard M. Stallman <rms@gnu.org>
parents:
21887
diff
changeset
|
1154 raw_pattern = (unsigned char *) XSTRING (string)->data; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1155 raw_pattern_size = XSTRING (string)->size; |
21244
50929073a0ba
Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents:
21171
diff
changeset
|
1156 raw_pattern_size_byte = STRING_BYTES (XSTRING (string)); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1157 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1158 else if (multibyte) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1159 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1160 raw_pattern_size = XSTRING (string)->size; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1161 raw_pattern_size_byte |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1162 = count_size_as_multibyte (XSTRING (string)->data, |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1163 raw_pattern_size); |
21915
8f1159b417c2
(search_buffer): Fix casts when assigning raw_pattern.
Richard M. Stallman <rms@gnu.org>
parents:
21887
diff
changeset
|
1164 raw_pattern = (unsigned char *) alloca (raw_pattern_size_byte + 1); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1165 copy_text (XSTRING (string)->data, raw_pattern, |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1166 XSTRING (string)->size, 0, 1); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1167 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1168 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1169 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1170 /* Converting multibyte to single-byte. |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1171 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1172 ??? 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
|
1173 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
|
1174 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
|
1175 the chosen single-byte character set can possibly match. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1176 raw_pattern_size = XSTRING (string)->size; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1177 raw_pattern_size_byte = XSTRING (string)->size; |
21915
8f1159b417c2
(search_buffer): Fix casts when assigning raw_pattern.
Richard M. Stallman <rms@gnu.org>
parents:
21887
diff
changeset
|
1178 raw_pattern = (unsigned char *) alloca (raw_pattern_size + 1); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1179 copy_text (XSTRING (string)->data, raw_pattern, |
21244
50929073a0ba
Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents:
21171
diff
changeset
|
1180 STRING_BYTES (XSTRING (string)), 1, 0); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1181 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1182 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1183 /* Copy and optionally translate the pattern. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1184 len = raw_pattern_size; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1185 len_byte = raw_pattern_size_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1186 patbuf = (unsigned char *) alloca (len_byte); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1187 pat = patbuf; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1188 base_pat = raw_pattern; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1189 if (multibyte) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1190 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1191 while (--len >= 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1192 { |
26869
cb8fbc50812f
(search_buffer): Adjusted for the change of CHAR_STRING.
Kenichi Handa <handa@m17n.org>
parents:
26088
diff
changeset
|
1193 unsigned char str[MAX_MULTIBYTE_LENGTH]; |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1194 int c, translated, inverse; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1195 int in_charlen, charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1196 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1197 /* 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
|
1198 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
|
1199 just quotes the next character. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1200 if (RE && *base_pat == '\\') |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1201 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1202 len--; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1203 len_byte--; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1204 base_pat++; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1205 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1206 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1207 c = STRING_CHAR_AND_LENGTH (base_pat, len_byte, in_charlen); |
23876
8d2f38338c81
(search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents:
23790
diff
changeset
|
1208 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1209 /* Translate the character, if requested. */ |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1210 TRANSLATE (translated, trt, c); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1211 /* If translation changed the byte-length, go back |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1212 to the original character. */ |
26869
cb8fbc50812f
(search_buffer): Adjusted for the change of CHAR_STRING.
Kenichi Handa <handa@m17n.org>
parents:
26088
diff
changeset
|
1213 charlen = CHAR_STRING (translated, str); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1214 if (in_charlen != charlen) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1215 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1216 translated = c; |
26869
cb8fbc50812f
(search_buffer): Adjusted for the change of CHAR_STRING.
Kenichi Handa <handa@m17n.org>
parents:
26088
diff
changeset
|
1217 charlen = CHAR_STRING (c, str); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1218 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1219 |
24014
0997bcfd8827
(search_buffer): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
23876
diff
changeset
|
1220 /* If we are searching for something strange, |
0997bcfd8827
(search_buffer): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
23876
diff
changeset
|
1221 an invalid multibyte code, don't use boyer-moore. */ |
0997bcfd8827
(search_buffer): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
23876
diff
changeset
|
1222 if (! ASCII_BYTE_P (translated) |
0997bcfd8827
(search_buffer): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
23876
diff
changeset
|
1223 && (charlen == 1 /* 8bit code */ |
0997bcfd8827
(search_buffer): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
23876
diff
changeset
|
1224 || charlen != in_charlen /* invalid multibyte code */ |
0997bcfd8827
(search_buffer): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
23876
diff
changeset
|
1225 )) |
0997bcfd8827
(search_buffer): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
23876
diff
changeset
|
1226 boyer_moore_ok = 0; |
0997bcfd8827
(search_buffer): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
23876
diff
changeset
|
1227 |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1228 TRANSLATE (inverse, inverse_trt, c); |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1229 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1230 /* Did this char actually get translated? |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1231 Would any other char get translated into it? */ |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1232 if (translated != c || inverse != c) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1233 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1234 /* Keep track of which character set row |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1235 contains the characters that need translation. */ |
24014
0997bcfd8827
(search_buffer): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
23876
diff
changeset
|
1236 int charset_base_code = c & ~CHAR_FIELD3_MASK; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1237 if (charset_base == -1) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1238 charset_base = charset_base_code; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1239 else if (charset_base != charset_base_code) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1240 /* If two different rows appear, needing translation, |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1241 then we cannot use boyer_moore search. */ |
23876
8d2f38338c81
(search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents:
23790
diff
changeset
|
1242 boyer_moore_ok = 0; |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1243 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1244 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1245 /* Store this character into the translated pattern. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1246 bcopy (str, pat, charlen); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1247 pat += charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1248 base_pat += in_charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1249 len_byte -= in_charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1250 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1251 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1252 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1253 { |
23876
8d2f38338c81
(search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents:
23790
diff
changeset
|
1254 /* Unibyte buffer. */ |
8d2f38338c81
(search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents:
23790
diff
changeset
|
1255 charset_base = 0; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1256 while (--len >= 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1257 { |
23876
8d2f38338c81
(search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents:
23790
diff
changeset
|
1258 int c, translated; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1259 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1260 /* 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
|
1261 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
|
1262 just quotes the next character. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1263 if (RE && *base_pat == '\\') |
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 len--; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1266 base_pat++; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1267 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1268 c = *base_pat++; |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1269 TRANSLATE (translated, trt, c); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1270 *pat++ = translated; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1271 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1272 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1273 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1274 len_byte = pat - patbuf; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1275 len = raw_pattern_size; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1276 pat = base_pat = patbuf; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1277 |
23876
8d2f38338c81
(search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents:
23790
diff
changeset
|
1278 if (boyer_moore_ok) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1279 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
|
1280 pos, pos_byte, lim, lim_byte, |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1281 charset_base); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1282 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1283 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
|
1284 pos, pos_byte, lim, lim_byte); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1285 } |
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 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1288 /* 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
|
1289 whose length is LEN/LEN_BYTE, |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1290 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
|
1291 TRT is the translation table. |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1292 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1293 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
|
1294 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
|
1295 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1296 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
|
1297 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
|
1298 boyer_moore cannot work. */ |
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 static int |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1301 simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1302 int n; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1303 unsigned char *pat; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1304 int len, len_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1305 Lisp_Object trt; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1306 int pos, pos_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1307 int lim, lim_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1308 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1309 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
|
1310 int forward = n > 0; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1311 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1312 if (lim > pos && multibyte) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1313 while (n > 0) |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1314 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1315 while (1) |
20671
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
1316 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1317 /* Try matching at position POS. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1318 int this_pos = pos; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1319 int this_pos_byte = pos_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1320 int this_len = len; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1321 int this_len_byte = len_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1322 unsigned char *p = pat; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1323 if (pos + len > lim) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1324 goto stop; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1325 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1326 while (this_len > 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1327 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1328 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
|
1329 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
|
1330 |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1331 pat_ch = STRING_CHAR_AND_LENGTH (p, this_len_byte, charlen); |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1332 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
|
1333 ZV_BYTE - this_pos_byte, |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1334 buf_charlen); |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1335 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
|
1336 |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1337 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
|
1338 break; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1339 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1340 this_len_byte -= charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1341 this_len--; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1342 p += charlen; |
20671
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
1343 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1344 this_pos_byte += buf_charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1345 this_pos++; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1346 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1347 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1348 if (this_len == 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1349 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1350 pos += len; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1351 pos_byte += len_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1352 break; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1353 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1354 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1355 INC_BOTH (pos, pos_byte); |
20671
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
1356 } |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
1357 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1358 n--; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1359 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1360 else if (lim > pos) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1361 while (n > 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1362 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1363 while (1) |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1364 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1365 /* Try matching at position POS. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1366 int this_pos = pos; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1367 int this_len = len; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1368 unsigned char *p = pat; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1369 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1370 if (pos + len > lim) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1371 goto stop; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1372 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1373 while (this_len > 0) |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1374 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1375 int pat_ch = *p++; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1376 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
|
1377 TRANSLATE (buf_ch, trt, buf_ch); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1378 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1379 if (buf_ch != pat_ch) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1380 break; |
21117
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1381 |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1382 this_len--; |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1383 this_pos++; |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1384 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1385 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1386 if (this_len == 0) |
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 pos += len; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1389 break; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1390 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1391 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1392 pos++; |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1393 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1394 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1395 n--; |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1396 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1397 /* Backwards search. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1398 else if (lim < pos && multibyte) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1399 while (n < 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1400 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1401 while (1) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1402 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1403 /* Try matching at position POS. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1404 int this_pos = pos - len; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1405 int this_pos_byte = pos_byte - len_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1406 int this_len = len; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1407 int this_len_byte = len_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1408 unsigned char *p = pat; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1409 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1410 if (pos - len < lim) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1411 goto stop; |
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 while (this_len > 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1414 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1415 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
|
1416 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
|
1417 |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1418 pat_ch = STRING_CHAR_AND_LENGTH (p, this_len_byte, charlen); |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1419 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
|
1420 ZV_BYTE - this_pos_byte, |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1421 buf_charlen); |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1422 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
|
1423 |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1424 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
|
1425 break; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1426 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1427 this_len_byte -= charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1428 this_len--; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1429 p += charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1430 this_pos_byte += buf_charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1431 this_pos++; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1432 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1433 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1434 if (this_len == 0) |
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 pos -= len; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1437 pos_byte -= len_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1438 break; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1439 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1440 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1441 DEC_BOTH (pos, pos_byte); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1442 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1443 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1444 n++; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1445 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1446 else if (lim < pos) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1447 while (n < 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1448 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1449 while (1) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1450 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1451 /* Try matching at position POS. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1452 int this_pos = pos - len; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1453 int this_len = len; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1454 unsigned char *p = pat; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1455 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1456 if (pos - len < lim) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1457 goto stop; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1458 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1459 while (this_len > 0) |
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 int pat_ch = *p++; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1462 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
|
1463 TRANSLATE (buf_ch, trt, buf_ch); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1464 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1465 if (buf_ch != pat_ch) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1466 break; |
21117
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1467 this_len--; |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1468 this_pos++; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1469 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1470 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1471 if (this_len == 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1472 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1473 pos -= len; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1474 break; |
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 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1477 pos--; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1478 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1479 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1480 n++; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1481 } |
603 | 1482 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1483 stop: |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1484 if (n == 0) |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1485 { |
21117
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1486 if (forward) |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1487 set_search_regs ((multibyte ? pos_byte : pos) - len_byte, len_byte); |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1488 else |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1489 set_search_regs (multibyte ? pos_byte : pos, len_byte); |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1490 |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1491 return pos; |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1492 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1493 else if (n > 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1494 return -n; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1495 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1496 return n; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1497 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1498 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1499 /* Do Boyer-Moore search N times for the string PAT, |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1500 whose length is LEN/LEN_BYTE, |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1501 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
|
1502 DIRECTION says which direction we search in. |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1503 TRT and INVERSE_TRT are translation tables. |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1504 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1505 This kind of search works if all the characters in PAT that have |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1506 nontrivial translation are the same aside from the last byte. This |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1507 makes it possible to translate just the last byte of a character, |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1508 and do so after just a simple test of the context. |
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 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
|
1511 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1512 static int |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1513 boyer_moore (n, base_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
|
1514 pos, pos_byte, lim, lim_byte, charset_base) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1515 int n; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1516 unsigned char *base_pat; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1517 int len, len_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1518 Lisp_Object trt; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1519 Lisp_Object inverse_trt; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1520 int pos, pos_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1521 int lim, lim_byte; |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1522 int charset_base; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1523 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1524 int direction = ((n > 0) ? 1 : -1); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1525 register int dirlen; |
34966
23a62cf7d0eb
(shrink_regexp_cache): Remove unused variable `cpp'.
Eli Zaretskii <eliz@gnu.org>
parents:
33052
diff
changeset
|
1526 int infinity, limit, stride_for_teases = 0; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1527 register int *BM_tab; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1528 int *BM_tab_base; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1529 register unsigned char *cursor, *p_limit; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1530 register int i, j; |
21945
bda081af77e7
(boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents:
21915
diff
changeset
|
1531 unsigned char *pat, *pat_end; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1532 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
|
1533 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1534 unsigned char simple_translate[0400]; |
31829
43566b0aec59
Avoid some more compiler warnings.
Gerd Moellmann <gerd@gnu.org>
parents:
31486
diff
changeset
|
1535 int translate_prev_byte = 0; |
43566b0aec59
Avoid some more compiler warnings.
Gerd Moellmann <gerd@gnu.org>
parents:
31486
diff
changeset
|
1536 int translate_anteprev_byte = 0; |
603 | 1537 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1538 #ifdef C_ALLOCA |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1539 int BM_tab_space[0400]; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1540 BM_tab = &BM_tab_space[0]; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1541 #else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1542 BM_tab = (int *) alloca (0400 * sizeof (int)); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1543 #endif |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1544 /* The general approach is that we are going to maintain that we know */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1545 /* the first (closest to the present position, in whatever direction */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1546 /* we're searching) character that could possibly be the last */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1547 /* (furthest from present position) character of a valid match. We */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1548 /* advance the state of our knowledge by looking at that character */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1549 /* and seeing whether it indeed matches the last character of the */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1550 /* pattern. If it does, we take a closer look. If it does not, we */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1551 /* move our pointer (to putative last characters) as far as is */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1552 /* logically possible. This amount of movement, which I call a */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1553 /* stride, will be the length of the pattern if the actual character */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1554 /* appears nowhere in the pattern, otherwise it will be the distance */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1555 /* from the last occurrence of that character to the end of the */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1556 /* pattern. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1557 /* As a coding trick, an enormous stride is coded into the table for */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1558 /* characters that match the last character. This allows use of only */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1559 /* a single test, a test for having gone past the end of the */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1560 /* permissible match region, to test for both possible matches (when */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1561 /* the stride goes past the end immediately) and failure to */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1562 /* match (where you get nudged past the end one stride at a time). */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1563 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1564 /* Here we make a "mickey mouse" BM table. The stride of the search */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1565 /* is determined only by the last character of the putative match. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1566 /* If that character does not match, we will stride the proper */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1567 /* distance to propose a match that superimposes it on the last */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1568 /* instance of a character that matches it (per trt), or misses */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1569 /* it entirely if there is none. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1570 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1571 dirlen = len_byte * direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1572 infinity = dirlen - (lim_byte + pos_byte + len_byte + len_byte) * direction; |
21945
bda081af77e7
(boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents:
21915
diff
changeset
|
1573 |
bda081af77e7
(boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents:
21915
diff
changeset
|
1574 /* 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
|
1575 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
|
1576 /* 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
|
1577 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
|
1578 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
|
1579 if (direction < 0) |
21945
bda081af77e7
(boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents:
21915
diff
changeset
|
1580 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
|
1581 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1582 BM_tab_base = BM_tab; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1583 BM_tab += 0400; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1584 j = dirlen; /* to get it in a register */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1585 /* A character that does not appear in the pattern induces a */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1586 /* stride equal to the pattern length. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1587 while (BM_tab_base != BM_tab) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1588 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1589 *--BM_tab = j; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1590 *--BM_tab = j; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1591 *--BM_tab = j; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1592 *--BM_tab = j; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1593 } |
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 /* 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
|
1596 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
|
1597 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
|
1598 bzero (simple_translate, sizeof simple_translate); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1599 for (i = 0; i < 0400; i++) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1600 simple_translate[i] = i; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1601 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1602 i = 0; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1603 while (i != infinity) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1604 { |
21945
bda081af77e7
(boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents:
21915
diff
changeset
|
1605 unsigned char *ptr = base_pat + i; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1606 i += direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1607 if (i == dirlen) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1608 i = infinity; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1609 if (! NILP (trt)) |
603 | 1610 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1611 int ch; |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1612 int untranslated; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1613 int this_translated = 1; |
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 (multibyte |
21945
bda081af77e7
(boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents:
21915
diff
changeset
|
1616 /* Is *PTR the last byte of a character? */ |
bda081af77e7
(boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents:
21915
diff
changeset
|
1617 && (pat_end - ptr == 1 || CHAR_HEAD_P (ptr[1]))) |
603 | 1618 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1619 unsigned char *charstart = ptr; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1620 while (! CHAR_HEAD_P (*charstart)) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1621 charstart--; |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1622 untranslated = STRING_CHAR (charstart, ptr - charstart + 1); |
24716
ceeb1f1d1a88
(boyer_moore): Get charset base value of `untranslated'
Kenichi Handa <handa@m17n.org>
parents:
24433
diff
changeset
|
1623 if (charset_base == (untranslated & ~CHAR_FIELD3_MASK)) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1624 { |
21117
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1625 TRANSLATE (ch, trt, untranslated); |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1626 if (! CHAR_HEAD_P (*ptr)) |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1627 { |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1628 translate_prev_byte = ptr[-1]; |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1629 if (! CHAR_HEAD_P (translate_prev_byte)) |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1630 translate_anteprev_byte = ptr[-2]; |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1631 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1632 } |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1633 else |
21117
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1634 { |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1635 this_translated = 0; |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1636 ch = *ptr; |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1637 } |
603 | 1638 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1639 else if (!multibyte) |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1640 TRANSLATE (ch, trt, *ptr); |
603 | 1641 else |
1642 { | |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1643 ch = *ptr; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1644 this_translated = 0; |
603 | 1645 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1646 |
21117
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1647 if (ch > 0400) |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1648 j = ((unsigned char) ch) | 0200; |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1649 else |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1650 j = (unsigned char) ch; |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1651 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1652 if (i == infinity) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1653 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
|
1654 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1655 BM_tab[j] = dirlen - i; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1656 /* A translation table is accompanied by its inverse -- see */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1657 /* comment following downcase_table for details */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1658 if (this_translated) |
21117
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1659 { |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1660 int starting_ch = ch; |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1661 int starting_j = j; |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1662 while (1) |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1663 { |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1664 TRANSLATE (ch, inverse_trt, ch); |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1665 if (ch > 0400) |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1666 j = ((unsigned char) ch) | 0200; |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1667 else |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1668 j = (unsigned char) ch; |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1669 |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1670 /* 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
|
1671 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
|
1672 into STARTING_J. */ |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1673 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
|
1674 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
|
1675 break; |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1676 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
|
1677 } |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1678 } |
603 | 1679 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1680 else |
603 | 1681 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1682 j = *ptr; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1683 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1684 if (i == infinity) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1685 stride_for_teases = BM_tab[j]; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1686 BM_tab[j] = dirlen - i; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1687 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1688 /* stride_for_teases tells how much to stride if we get a */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1689 /* match on the far character but are subsequently */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1690 /* disappointed, by recording what the stride would have been */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1691 /* for that character if the last character had been */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1692 /* different. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1693 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1694 infinity = dirlen - infinity; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1695 pos_byte += dirlen - ((direction > 0) ? direction : 0); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1696 /* 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
|
1697 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
|
1698 while (n != 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1699 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1700 int tail_end; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1701 unsigned char *tail_end_ptr; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1702 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1703 /* 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
|
1704 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
|
1705 Using an explicit ?1:0 prevents this. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1706 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
|
1707 < 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1708 return (n * (0 - direction)); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1709 /* 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
|
1710 QUIT; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1711 pat = base_pat; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1712 limit = pos_byte - dirlen + direction; |
21457
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1713 if (direction > 0) |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1714 { |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1715 limit = BUFFER_CEILING_OF (limit); |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1716 /* 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
|
1717 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
|
1718 limit = min (limit, pos_byte + 20000); |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1719 limit = min (limit, lim_byte - 1); |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1720 } |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1721 else |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1722 { |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1723 limit = BUFFER_FLOOR_OF (limit); |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1724 /* 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
|
1725 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
|
1726 limit = max (limit, pos_byte - 20000); |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1727 limit = max (limit, lim_byte); |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1728 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1729 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
|
1730 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
|
1731 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1732 if ((limit - pos_byte) * direction > 20) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1733 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1734 unsigned char *p2; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1735 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1736 p_limit = BYTE_POS_ADDR (limit); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1737 p2 = (cursor = BYTE_POS_ADDR (pos_byte)); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1738 /* In this loop, pos + cursor - p2 is the surrogate for pos */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1739 while (1) /* use one cursor setting as long as i can */ |
603 | 1740 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1741 if (direction > 0) /* worth duplicating */ |
603 | 1742 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1743 /* Use signed comparison if appropriate |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1744 to make cursor+infinity sure to be > p_limit. |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1745 Assuming that the buffer lies in a range of addresses |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1746 that are all "positive" (as ints) or all "negative", |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1747 either kind of comparison will work as long |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1748 as we don't step by infinity. So pick the kind |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1749 that works when we do step by infinity. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1750 if ((EMACS_INT) (p_limit + infinity) > (EMACS_INT) p_limit) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1751 while ((EMACS_INT) cursor <= (EMACS_INT) p_limit) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1752 cursor += BM_tab[*cursor]; |
603 | 1753 else |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1754 while ((EMACS_UINT) cursor <= (EMACS_UINT) p_limit) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1755 cursor += BM_tab[*cursor]; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1756 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1757 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1758 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1759 if ((EMACS_INT) (p_limit + infinity) < (EMACS_INT) p_limit) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1760 while ((EMACS_INT) cursor >= (EMACS_INT) p_limit) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1761 cursor += BM_tab[*cursor]; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1762 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1763 while ((EMACS_UINT) cursor >= (EMACS_UINT) p_limit) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1764 cursor += BM_tab[*cursor]; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1765 } |
603 | 1766 /* If you are here, cursor is beyond the end of the searched region. */ |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1767 /* This can happen if you match on the far character of the pattern, */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1768 /* because the "stride" of that character is infinity, a number able */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1769 /* to throw you well beyond the end of the search. It can also */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1770 /* happen if you fail to match within the permitted region and would */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1771 /* otherwise try a character beyond that region */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1772 if ((cursor - p_limit) * direction <= len_byte) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1773 break; /* a small overrun is genuine */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1774 cursor -= infinity; /* large overrun = hit */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1775 i = dirlen - direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1776 if (! NILP (trt)) |
603 | 1777 { |
1778 while ((i -= direction) + direction != 0) | |
1779 { | |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1780 int ch; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1781 cursor -= direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1782 /* 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
|
1783 if (! multibyte |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1784 || ((cursor == tail_end_ptr |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1785 || CHAR_HEAD_P (cursor[1])) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1786 && (CHAR_HEAD_P (cursor[0]) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1787 || (translate_prev_byte == cursor[-1] |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1788 && (CHAR_HEAD_P (translate_prev_byte) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1789 || translate_anteprev_byte == cursor[-2]))))) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1790 ch = simple_translate[*cursor]; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1791 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1792 ch = *cursor; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1793 if (pat[i] != ch) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1794 break; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1795 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1796 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1797 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1798 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1799 while ((i -= direction) + direction != 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1800 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1801 cursor -= direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1802 if (pat[i] != *cursor) |
603 | 1803 break; |
1804 } | |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1805 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1806 cursor += dirlen - i - direction; /* fix cursor */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1807 if (i + direction == 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1808 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1809 int position; |
708 | 1810 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1811 cursor -= direction; |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1812 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1813 position = pos_byte + cursor - p2 + ((direction > 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1814 ? 1 - len_byte : 0); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1815 set_search_regs (position, len_byte); |
708 | 1816 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1817 if ((n -= direction) != 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1818 cursor += dirlen; /* to resume search */ |
603 | 1819 else |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1820 return ((direction > 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1821 ? search_regs.end[0] : search_regs.start[0]); |
603 | 1822 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1823 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1824 cursor += stride_for_teases; /* <sigh> we lose - */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1825 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1826 pos_byte += cursor - p2; |
603 | 1827 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1828 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1829 /* Now we'll pick up a clump that has to be done the hard */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1830 /* way because it covers a discontinuity */ |
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 limit = ((direction > 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1833 ? BUFFER_CEILING_OF (pos_byte - dirlen + 1) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1834 : BUFFER_FLOOR_OF (pos_byte - dirlen - 1)); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1835 limit = ((direction > 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1836 ? min (limit + len_byte, lim_byte - 1) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1837 : max (limit - len_byte, lim_byte)); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1838 /* 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
|
1839 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
|
1840 while (1) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1841 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1842 /* This loop can be coded for space rather than */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1843 /* speed because it will usually run only once. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1844 /* (the reach is at most len + 21, and typically */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1845 /* does not exceed len) */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1846 while ((limit - pos_byte) * direction >= 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1847 pos_byte += BM_tab[FETCH_BYTE (pos_byte)]; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1848 /* now run the same tests to distinguish going off the */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1849 /* end, a match or a phony match. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1850 if ((pos_byte - limit) * direction <= len_byte) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1851 break; /* ran off the end */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1852 /* Found what might be a match. |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1853 Set POS_BYTE back to last (first if reverse) pos. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1854 pos_byte -= infinity; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1855 i = dirlen - direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1856 while ((i -= direction) + direction != 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1857 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1858 int ch; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1859 unsigned char *ptr; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1860 pos_byte -= direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1861 ptr = BYTE_POS_ADDR (pos_byte); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1862 /* 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
|
1863 if (! multibyte |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1864 || ((ptr == tail_end_ptr |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1865 || CHAR_HEAD_P (ptr[1])) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1866 && (CHAR_HEAD_P (ptr[0]) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1867 || (translate_prev_byte == ptr[-1] |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1868 && (CHAR_HEAD_P (translate_prev_byte) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1869 || translate_anteprev_byte == ptr[-2]))))) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1870 ch = simple_translate[*ptr]; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1871 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1872 ch = *ptr; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1873 if (pat[i] != ch) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1874 break; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1875 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1876 /* 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
|
1877 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
|
1878 Set it once again at the last (first if reverse) char. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1879 pos_byte += dirlen - i- direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1880 if (i + direction == 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1881 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1882 int position; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1883 pos_byte -= direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1884 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1885 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
|
1886 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1887 set_search_regs (position, len_byte); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1888 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1889 if ((n -= direction) != 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1890 pos_byte += dirlen; /* to resume search */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1891 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1892 return ((direction > 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1893 ? search_regs.end[0] : search_regs.start[0]); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1894 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1895 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1896 pos_byte += stride_for_teases; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1897 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1898 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1899 /* 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
|
1900 if ((lim_byte - pos_byte) * direction < 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1901 return ((0 - n) * direction); |
603 | 1902 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1903 return BYTE_TO_CHAR (pos_byte); |
603 | 1904 } |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
1905 |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
1906 /* 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
|
1907 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
|
1908 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
|
1909 |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
1910 static void |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
1911 set_search_regs (beg_byte, nbytes) |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
1912 int beg_byte, nbytes; |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
1913 { |
22082
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
1914 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
|
1915 |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
1916 /* 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
|
1917 the match position. */ |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
1918 if (search_regs.num_regs == 0) |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
1919 { |
10250
422c3b96efda
(set_search_regs): Really set search_regs.start and .end.
Richard M. Stallman <rms@gnu.org>
parents:
10141
diff
changeset
|
1920 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
|
1921 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
|
1922 search_regs.num_regs = 2; |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
1923 } |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
1924 |
22082
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
1925 /* 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
|
1926 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
|
1927 { |
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
1928 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
|
1929 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
|
1930 } |
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
1931 |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
1932 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
|
1933 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
|
1934 XSETBUFFER (last_thing_searched, current_buffer); |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
1935 } |
603 | 1936 |
1937 /* Given a string of words separated by word delimiters, | |
1938 compute a regexp that matches those exact words | |
1939 separated by arbitrary punctuation. */ | |
1940 | |
1941 static Lisp_Object | |
1942 wordify (string) | |
1943 Lisp_Object string; | |
1944 { | |
1945 register unsigned char *p, *o; | |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1946 register int i, i_byte, len, punct_count = 0, word_count = 0; |
603 | 1947 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
|
1948 int prev_c = 0; |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1949 int adjust; |
603 | 1950 |
1951 CHECK_STRING (string, 0); | |
1952 p = XSTRING (string)->data; | |
1953 len = XSTRING (string)->size; | |
1954 | |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1955 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
|
1956 { |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1957 int c; |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1958 |
29018
2f43c508a9b5
(wordify): Use FETCH_STRING_CHAR_ADVANCE
Kenichi Handa <handa@m17n.org>
parents:
28886
diff
changeset
|
1959 FETCH_STRING_CHAR_ADVANCE (c, string, i, i_byte); |
603 | 1960 |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1961 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
|
1962 { |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1963 punct_count++; |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1964 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
|
1965 word_count++; |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1966 } |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1967 |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1968 prev_c = c; |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1969 } |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1970 |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1971 if (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
|
1972 word_count++; |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1973 if (!word_count) |
39805
e9374c065e86
(wordify): Use empty_string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39682
diff
changeset
|
1974 return empty_string; |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1975 |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1976 adjust = - punct_count + 5 * (word_count - 1) + 4; |
22640
929ad308aba6
(wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents:
22533
diff
changeset
|
1977 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
|
1978 val = make_uninit_multibyte_string (len + adjust, |
929ad308aba6
(wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents:
22533
diff
changeset
|
1979 STRING_BYTES (XSTRING (string)) |
929ad308aba6
(wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents:
22533
diff
changeset
|
1980 + adjust); |
929ad308aba6
(wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents:
22533
diff
changeset
|
1981 else |
929ad308aba6
(wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents:
22533
diff
changeset
|
1982 val = make_uninit_string (len + adjust); |
603 | 1983 |
1984 o = XSTRING (val)->data; | |
1985 *o++ = '\\'; | |
1986 *o++ = 'b'; | |
21887
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
1987 prev_c = 0; |
603 | 1988 |
21887
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
1989 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
|
1990 { |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
1991 int c; |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
1992 int i_byte_orig = i_byte; |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
1993 |
29018
2f43c508a9b5
(wordify): Use FETCH_STRING_CHAR_ADVANCE
Kenichi Handa <handa@m17n.org>
parents:
28886
diff
changeset
|
1994 FETCH_STRING_CHAR_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
|
1995 |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
1996 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
|
1997 { |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
1998 bcopy (&XSTRING (string)->data[i_byte_orig], o, |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
1999 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
|
2000 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
|
2001 } |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2002 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
|
2003 { |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2004 *o++ = '\\'; |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2005 *o++ = 'W'; |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2006 *o++ = '\\'; |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2007 *o++ = 'W'; |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2008 *o++ = '*'; |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2009 } |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2010 |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2011 prev_c = c; |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2012 } |
603 | 2013 |
2014 *o++ = '\\'; | |
2015 *o++ = 'b'; | |
2016 | |
2017 return val; | |
2018 } | |
2019 | |
2020 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
|
2021 "MSearch backward: ", |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2022 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
|
2023 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
|
2024 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
|
2025 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
|
2026 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
|
2027 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
|
2028 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
|
2029 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2030 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
|
2031 `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
|
2032 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2033 See also the functions `match-beginning', `match-end' and `replace-match'. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2034 (string, bound, noerror, count) |
603 | 2035 Lisp_Object string, bound, noerror, count; |
2036 { | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2037 return search_command (string, bound, noerror, count, -1, 0, 0); |
603 | 2038 } |
2039 | |
19541
e7876a076881
(Fsearch_backward): Inherit the current input method on
Kenichi Handa <handa@m17n.org>
parents:
18762
diff
changeset
|
2040 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
|
2041 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
|
2042 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
|
2043 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
|
2044 The match found must not extend after that position. nil is equivalent |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2045 to (point-max). |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2046 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
|
2047 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
|
2048 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
|
2049 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2050 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
|
2051 `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
|
2052 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2053 See also the functions `match-beginning', `match-end' and `replace-match'. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2054 (string, bound, noerror, count) |
603 | 2055 Lisp_Object string, bound, noerror, count; |
2056 { | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2057 return search_command (string, bound, noerror, count, 1, 0, 0); |
603 | 2058 } |
2059 | |
2060 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
|
2061 "sWord search backward: ", |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2062 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
|
2063 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
|
2064 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
|
2065 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
|
2066 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
|
2067 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
|
2068 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
|
2069 (string, bound, noerror, count) |
603 | 2070 Lisp_Object string, bound, noerror, count; |
2071 { | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2072 return search_command (wordify (string), bound, noerror, count, -1, 1, 0); |
603 | 2073 } |
2074 | |
2075 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
|
2076 "sWord search: ", |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2077 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
|
2078 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
|
2079 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
|
2080 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
|
2081 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
|
2082 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
|
2083 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
|
2084 (string, bound, noerror, count) |
603 | 2085 Lisp_Object string, bound, noerror, count; |
2086 { | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2087 return search_command (wordify (string), bound, noerror, count, 1, 1, 0); |
603 | 2088 } |
2089 | |
2090 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
|
2091 "sRE search backward: ", |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2092 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
|
2093 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
|
2094 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
|
2095 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
|
2096 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
|
2097 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
|
2098 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
|
2099 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
|
2100 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
|
2101 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
|
2102 and `replace-match'. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2103 (regexp, bound, noerror, count) |
6297
b44907fd0ff0
(Fre_search_forward, Fre_search_backward): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
6196
diff
changeset
|
2104 Lisp_Object regexp, bound, noerror, count; |
603 | 2105 { |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2106 return search_command (regexp, bound, noerror, count, -1, 1, 0); |
603 | 2107 } |
2108 | |
2109 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
|
2110 "sRE search: ", |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2111 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
|
2112 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
|
2113 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
|
2114 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
|
2115 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
|
2116 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
|
2117 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
|
2118 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
|
2119 and `replace-match'. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2120 (regexp, bound, noerror, count) |
6297
b44907fd0ff0
(Fre_search_forward, Fre_search_backward): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
6196
diff
changeset
|
2121 Lisp_Object regexp, bound, noerror, count; |
603 | 2122 { |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2123 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
|
2124 } |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2125 |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2126 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
|
2127 "sPosix search backward: ", |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2128 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
|
2129 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
|
2130 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
|
2131 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
|
2132 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
|
2133 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
|
2134 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
|
2135 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
|
2136 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
|
2137 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
|
2138 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
|
2139 and `replace-match'. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2140 (regexp, bound, noerror, count) |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2141 Lisp_Object regexp, bound, noerror, count; |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2142 { |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2143 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
|
2144 } |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2145 |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2146 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
|
2147 "sPosix search: ", |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2148 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
|
2149 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
|
2150 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
|
2151 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
|
2152 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
|
2153 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
|
2154 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
|
2155 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
|
2156 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
|
2157 and `replace-match'. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2158 (regexp, bound, noerror, count) |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2159 Lisp_Object regexp, bound, noerror, count; |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2160 { |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2161 return search_command (regexp, bound, noerror, count, 1, 1, 1); |
603 | 2162 } |
2163 | |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2164 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
|
2165 doc: /* Replace text matched by last search with NEWTEXT. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2166 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
|
2167 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
|
2168 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
|
2169 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
|
2170 and has at least one multiletter word, convert NEWTEXT to all caps. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2171 If the replaced text has at least one word starting with a capital letter, |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2172 then capitalize each word in NEWTEXT. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2173 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2174 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
|
2175 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
|
2176 `\\&' 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
|
2177 `\\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
|
2178 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
|
2179 `\\\\' means insert one `\\'. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2180 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
|
2181 Leaves point at end of replacement text. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2182 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2183 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
|
2184 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
|
2185 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
|
2186 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
|
2187 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
|
2188 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2189 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
|
2190 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
|
2191 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
|
2192 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
|
2193 `\\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
|
2194 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
|
2195 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
|
2196 since only regular expressions have distinguished subexpressions. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2197 (newtext, fixedcase, literal, string, subexp) |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2198 Lisp_Object newtext, fixedcase, literal, string, subexp; |
603 | 2199 { |
2200 enum { nochange, all_caps, cap_initial } case_action; | |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2201 register int pos, pos_byte; |
603 | 2202 int some_multiletter_word; |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
2203 int some_lowercase; |
7674
947d24fefd9e
(Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents:
7673
diff
changeset
|
2204 int some_uppercase; |
8526
2b7b23059f1b
(Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents:
7891
diff
changeset
|
2205 int some_nonuppercase_initial; |
603 | 2206 register int c, prevc; |
2207 int inslen; | |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2208 int sub; |
18081
300068b4fcef
(Freplace_match): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
18077
diff
changeset
|
2209 int opoint, newpoint; |
603 | 2210 |
4882
8c09f87f5087
(Freplace_match): Fix argument names to match doc string.
Brian Fox <bfox@gnu.org>
parents:
4832
diff
changeset
|
2211 CHECK_STRING (newtext, 0); |
603 | 2212 |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2213 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
|
2214 CHECK_STRING (string, 4); |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2215 |
603 | 2216 case_action = nochange; /* We tried an initialization */ |
2217 /* but some C compilers blew it */ | |
621 | 2218 |
2219 if (search_regs.num_regs <= 0) | |
2220 error ("replace-match called before any match found"); | |
2221 | |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2222 if (NILP (subexp)) |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2223 sub = 0; |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2224 else |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2225 { |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2226 CHECK_NUMBER (subexp, 3); |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2227 sub = XINT (subexp); |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2228 if (sub < 0 || sub >= search_regs.num_regs) |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2229 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
|
2230 } |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2231 |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2232 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
|
2233 { |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2234 if (search_regs.start[sub] < BEGV |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2235 || search_regs.start[sub] > search_regs.end[sub] |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2236 || search_regs.end[sub] > ZV) |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2237 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
|
2238 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
|
2239 } |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2240 else |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2241 { |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2242 if (search_regs.start[sub] < 0 |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2243 || search_regs.start[sub] > search_regs.end[sub] |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2244 || search_regs.end[sub] > XSTRING (string)->size) |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2245 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
|
2246 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
|
2247 } |
603 | 2248 |
2249 if (NILP (fixedcase)) | |
2250 { | |
2251 /* Decide how to casify by examining the matched text. */ | |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2252 int last; |
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2253 |
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2254 pos = search_regs.start[sub]; |
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2255 last = search_regs.end[sub]; |
603 | 2256 |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
2257 if (NILP (string)) |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2258 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
|
2259 else |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2260 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
|
2261 |
603 | 2262 prevc = '\n'; |
2263 case_action = all_caps; | |
2264 | |
2265 /* some_multiletter_word is set nonzero if any original word | |
2266 is more than one letter long. */ | |
2267 some_multiletter_word = 0; | |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
2268 some_lowercase = 0; |
8526
2b7b23059f1b
(Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents:
7891
diff
changeset
|
2269 some_nonuppercase_initial = 0; |
7674
947d24fefd9e
(Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents:
7673
diff
changeset
|
2270 some_uppercase = 0; |
603 | 2271 |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2272 while (pos < last) |
603 | 2273 { |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2274 if (NILP (string)) |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2275 { |
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2276 c = FETCH_CHAR (pos_byte); |
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2277 INC_BOTH (pos, pos_byte); |
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2278 } |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2279 else |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2280 FETCH_STRING_CHAR_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
|
2281 |
603 | 2282 if (LOWERCASEP (c)) |
2283 { | |
2284 /* Cannot be all caps if any original char is lower case */ | |
2285 | |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
2286 some_lowercase = 1; |
603 | 2287 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
|
2288 some_nonuppercase_initial = 1; |
603 | 2289 else |
2290 some_multiletter_word = 1; | |
2291 } | |
2292 else if (!NOCASEP (c)) | |
2293 { | |
7674
947d24fefd9e
(Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents:
7673
diff
changeset
|
2294 some_uppercase = 1; |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
2295 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
|
2296 ; |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
2297 else |
603 | 2298 some_multiletter_word = 1; |
2299 } | |
8526
2b7b23059f1b
(Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents:
7891
diff
changeset
|
2300 else |
2b7b23059f1b
(Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents:
7891
diff
changeset
|
2301 { |
2b7b23059f1b
(Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents:
7891
diff
changeset
|
2302 /* 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
|
2303 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
|
2304 if (SYNTAX (prevc) != Sword) |
2b7b23059f1b
(Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents:
7891
diff
changeset
|
2305 some_nonuppercase_initial = 1; |
2b7b23059f1b
(Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents:
7891
diff
changeset
|
2306 } |
603 | 2307 |
2308 prevc = c; | |
2309 } | |
2310 | |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
2311 /* 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
|
2312 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
|
2313 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
|
2314 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
|
2315 /* 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
|
2316 else if (!some_nonuppercase_initial && some_multiletter_word) |
603 | 2317 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
|
2318 else if (!some_nonuppercase_initial && some_uppercase) |
7674
947d24fefd9e
(Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents:
7673
diff
changeset
|
2319 /* 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
|
2320 We'll assume the latter. */ |
947d24fefd9e
(Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents:
7673
diff
changeset
|
2321 case_action = all_caps; |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
2322 else |
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
2323 case_action = nochange; |
603 | 2324 } |
2325 | |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2326 /* 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
|
2327 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
|
2328 { |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2329 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
|
2330 |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2331 before = Fsubstring (string, make_number (0), |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2332 make_number (search_regs.start[sub])); |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2333 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
|
2334 |
17225
739e41eed8b6
(Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents:
17102
diff
changeset
|
2335 /* Substitute parts of the match into NEWTEXT |
739e41eed8b6
(Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents:
17102
diff
changeset
|
2336 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
|
2337 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
|
2338 { |
21988
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2339 int lastpos = 0; |
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2340 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
|
2341 /* 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
|
2342 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
|
2343 Lisp_Object middle; |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2344 int length = STRING_BYTES (XSTRING (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
|
2345 |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2346 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
|
2347 |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2348 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
|
2349 { |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2350 int substart = -1; |
31829
43566b0aec59
Avoid some more compiler warnings.
Gerd Moellmann <gerd@gnu.org>
parents:
31486
diff
changeset
|
2351 int subend = 0; |
12148
a1c38b9b0f73
(Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents:
12147
diff
changeset
|
2352 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
|
2353 |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2354 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
|
2355 |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2356 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
|
2357 { |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2358 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte); |
29018
2f43c508a9b5
(wordify): Use FETCH_STRING_CHAR_ADVANCE
Kenichi Handa <handa@m17n.org>
parents:
28886
diff
changeset
|
2359 |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2360 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
|
2361 { |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2362 substart = search_regs.start[sub]; |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2363 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
|
2364 } |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2365 else if (c >= '1' && c <= '9' && c <= search_regs.num_regs + '0') |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2366 { |
12147
9200a0e153d3
(Freplace_match): Fix check for valid reg in string replace.
Karl Heuer <kwzh@gnu.org>
parents:
12092
diff
changeset
|
2367 if (search_regs.start[c - '0'] >= 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
|
2368 { |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2369 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
|
2370 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
|
2371 } |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2372 } |
12148
a1c38b9b0f73
(Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents:
12147
diff
changeset
|
2373 else if (c == '\\') |
a1c38b9b0f73
(Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents:
12147
diff
changeset
|
2374 delbackslash = 1; |
17225
739e41eed8b6
(Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents:
17102
diff
changeset
|
2375 else |
739e41eed8b6
(Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents:
17102
diff
changeset
|
2376 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
|
2377 } |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2378 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
|
2379 { |
21988
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2380 if (pos - 2 != lastpos) |
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2381 middle = substring_both (newtext, lastpos, |
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2382 lastpos_byte, |
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2383 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
|
2384 else |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2385 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
|
2386 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
|
2387 Fsubstring (string, |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2388 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
|
2389 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
|
2390 lastpos = pos; |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2391 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
|
2392 } |
12148
a1c38b9b0f73
(Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents:
12147
diff
changeset
|
2393 else if (delbackslash) |
a1c38b9b0f73
(Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents:
12147
diff
changeset
|
2394 { |
21988
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2395 middle = substring_both (newtext, lastpos, |
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2396 lastpos_byte, |
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2397 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
|
2398 |
12148
a1c38b9b0f73
(Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents:
12147
diff
changeset
|
2399 accum = concat2 (accum, middle); |
a1c38b9b0f73
(Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents:
12147
diff
changeset
|
2400 lastpos = pos; |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2401 lastpos_byte = pos_byte; |
12148
a1c38b9b0f73
(Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents:
12147
diff
changeset
|
2402 } |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2403 } |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2404 |
21988
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2405 if (pos != lastpos) |
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2406 middle = substring_both (newtext, lastpos, |
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2407 lastpos_byte, |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2408 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
|
2409 else |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2410 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
|
2411 |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2412 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
|
2413 } |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2414 |
17225
739e41eed8b6
(Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents:
17102
diff
changeset
|
2415 /* 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
|
2416 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
|
2417 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
|
2418 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
|
2419 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
|
2420 |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2421 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
|
2422 } |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2423 |
39487
b21317213c81
(trivial_regexp_p): Catch \{N,M\} as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35831
diff
changeset
|
2424 /* 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
|
2425 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
|
2426 opoint = PT - ZV; |
23790
c1dbb92db43e
(Freplace_match): Set OPOINT clearly for the case
Richard M. Stallman <rms@gnu.org>
parents:
22640
diff
changeset
|
2427 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
|
2428 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
|
2429 else |
27a0ced43e7e
(Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents:
17463
diff
changeset
|
2430 opoint = PT; |
27a0ced43e7e
(Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents:
17463
diff
changeset
|
2431 |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
2432 TEMP_SET_PT (search_regs.start[sub]); |
18077
27a0ced43e7e
(Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents:
17463
diff
changeset
|
2433 |
2655
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
2434 /* We insert the replacement text before the old text, and then |
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
2435 delete the original text. This means that markers at the |
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
2436 beginning or end of the original will float to the corresponding |
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
2437 position in the replacement. */ |
603 | 2438 if (!NILP (literal)) |
4882
8c09f87f5087
(Freplace_match): Fix argument names to match doc string.
Brian Fox <bfox@gnu.org>
parents:
4832
diff
changeset
|
2439 Finsert_and_inherit (1, &newtext); |
603 | 2440 else |
2441 { | |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2442 int length = STRING_BYTES (XSTRING (newtext)); |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2443 unsigned char *substed; |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2444 int substed_alloc_size, substed_len; |
28387
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2445 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
|
2446 int str_multibyte = STRING_MULTIBYTE (newtext); |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2447 Lisp_Object rev_tbl; |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2448 |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2449 rev_tbl= (!buf_multibyte && CHAR_TABLE_P (Vnonascii_translation_table) |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2450 ? Fchar_table_extra_slot (Vnonascii_translation_table, |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2451 make_number (0)) |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2452 : Qnil); |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2453 |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2454 substed_alloc_size = length * 2 + 100; |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2455 substed = (unsigned char *) xmalloc (substed_alloc_size + 1); |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2456 substed_len = 0; |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2457 |
28387
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2458 /* 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
|
2459 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
|
2460 buffer. */ |
603 | 2461 |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2462 for (pos_byte = 0, pos = 0; pos_byte < length;) |
603 | 2463 { |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2464 unsigned char str[MAX_MULTIBYTE_LENGTH]; |
28886
3f60536745bd
(Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents:
28507
diff
changeset
|
2465 unsigned char *add_stuff = NULL; |
3f60536745bd
(Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents:
28507
diff
changeset
|
2466 int add_len = 0; |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2467 int idx = -1; |
2655
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
2468 |
28387
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2469 if (str_multibyte) |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2470 { |
29018
2f43c508a9b5
(wordify): Use FETCH_STRING_CHAR_ADVANCE
Kenichi Handa <handa@m17n.org>
parents:
28886
diff
changeset
|
2471 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
|
2472 if (!buf_multibyte) |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2473 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
|
2474 } |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2475 else |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2476 { |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2477 /* Note that we don't have to increment POS. */ |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2478 c = XSTRING (newtext)->data[pos_byte++]; |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2479 if (buf_multibyte) |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2480 c = unibyte_char_to_multibyte (c); |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2481 } |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2482 |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2483 /* 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
|
2484 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
|
2485 of the buffer text into SUBSTED. */ |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2486 |
603 | 2487 if (c == '\\') |
2488 { | |
28387
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2489 if (str_multibyte) |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2490 { |
29018
2f43c508a9b5
(wordify): Use FETCH_STRING_CHAR_ADVANCE
Kenichi Handa <handa@m17n.org>
parents:
28886
diff
changeset
|
2491 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, newtext, |
2f43c508a9b5
(wordify): Use FETCH_STRING_CHAR_ADVANCE
Kenichi Handa <handa@m17n.org>
parents:
28886
diff
changeset
|
2492 pos, pos_byte); |
28387
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2493 if (!buf_multibyte && !SINGLE_BYTE_CHAR_P (c)) |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2494 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
|
2495 } |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2496 else |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2497 { |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2498 c = XSTRING (newtext)->data[pos_byte++]; |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2499 if (buf_multibyte) |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2500 c = unibyte_char_to_multibyte (c); |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2501 } |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2502 |
603 | 2503 if (c == '&') |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2504 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
|
2505 else if (c >= '1' && c <= '9' && c <= search_regs.num_regs + '0') |
603 | 2506 { |
2507 if (search_regs.start[c - '0'] >= 1) | |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2508 idx = c - '0'; |
603 | 2509 } |
17225
739e41eed8b6
(Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents:
17102
diff
changeset
|
2510 else if (c == '\\') |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2511 add_len = 1, add_stuff = "\\"; |
603 | 2512 else |
28387
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2513 { |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2514 xfree (substed); |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2515 error ("Invalid use of `\\' in replacement text"); |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2516 } |
603 | 2517 } |
2518 else | |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2519 { |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2520 add_len = CHAR_STRING (c, str); |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2521 add_stuff = str; |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2522 } |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2523 |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2524 /* 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
|
2525 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
|
2526 if (idx >= 0) |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2527 { |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2528 int begbyte = CHAR_TO_BYTE (search_regs.start[idx]); |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2529 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
|
2530 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
|
2531 move_gap (search_regs.start[idx]); |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2532 add_stuff = BYTE_POS_ADDR (begbyte); |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2533 } |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2534 |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2535 /* 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
|
2536 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
|
2537 |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2538 /* Make sure SUBSTED is big enough. */ |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2539 if (substed_len + add_len >= substed_alloc_size) |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2540 { |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2541 substed_alloc_size = substed_len + add_len + 500; |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2542 substed = (unsigned char *) xrealloc (substed, |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2543 substed_alloc_size + 1); |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2544 } |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2545 |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2546 /* 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
|
2547 if (add_stuff) |
3f60536745bd
(Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents:
28507
diff
changeset
|
2548 { |
3f60536745bd
(Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents:
28507
diff
changeset
|
2549 bcopy (add_stuff, substed + substed_len, add_len); |
3f60536745bd
(Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents:
28507
diff
changeset
|
2550 substed_len += add_len; |
3f60536745bd
(Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents:
28507
diff
changeset
|
2551 } |
603 | 2552 } |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2553 |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2554 /* Now insert what we accumulated. */ |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2555 insert_and_inherit (substed, substed_len); |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2556 |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2557 xfree (substed); |
603 | 2558 } |
2559 | |
16039
855c8d8ba0f0
Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents:
15667
diff
changeset
|
2560 inslen = PT - (search_regs.start[sub]); |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2561 del_range (search_regs.start[sub] + inslen, search_regs.end[sub] + inslen); |
603 | 2562 |
2563 if (case_action == all_caps) | |
16039
855c8d8ba0f0
Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents:
15667
diff
changeset
|
2564 Fupcase_region (make_number (PT - inslen), make_number (PT)); |
603 | 2565 else if (case_action == cap_initial) |
16039
855c8d8ba0f0
Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents:
15667
diff
changeset
|
2566 Fupcase_initials_region (make_number (PT - inslen), make_number (PT)); |
18077
27a0ced43e7e
(Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents:
17463
diff
changeset
|
2567 |
18081
300068b4fcef
(Freplace_match): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
18077
diff
changeset
|
2568 newpoint = PT; |
300068b4fcef
(Freplace_match): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
18077
diff
changeset
|
2569 |
18077
27a0ced43e7e
(Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents:
17463
diff
changeset
|
2570 /* 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
|
2571 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
|
2572 TEMP_SET_PT (opoint + ZV); |
18077
27a0ced43e7e
(Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents:
17463
diff
changeset
|
2573 else |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
2574 TEMP_SET_PT (opoint); |
18077
27a0ced43e7e
(Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents:
17463
diff
changeset
|
2575 |
27a0ced43e7e
(Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents:
17463
diff
changeset
|
2576 /* 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
|
2577 move_if_not_intangible (newpoint); |
18077
27a0ced43e7e
(Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents:
17463
diff
changeset
|
2578 |
603 | 2579 return Qnil; |
2580 } | |
2581 | |
2582 static Lisp_Object | |
2583 match_limit (num, beginningp) | |
2584 Lisp_Object num; | |
2585 int beginningp; | |
2586 { | |
2587 register int n; | |
2588 | |
2589 CHECK_NUMBER (num, 0); | |
2590 n = XINT (num); | |
621 | 2591 if (n < 0 || n >= search_regs.num_regs) |
2592 args_out_of_range (num, make_number (search_regs.num_regs)); | |
2593 if (search_regs.num_regs <= 0 | |
2594 || search_regs.start[n] < 0) | |
603 | 2595 return Qnil; |
2596 return (make_number ((beginningp) ? search_regs.start[n] | |
2597 : search_regs.end[n])); | |
2598 } | |
2599 | |
2600 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
|
2601 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
|
2602 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
|
2603 regexp. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2604 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
|
2605 SUBEXP pairs. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2606 Zero means the entire text matched by the whole regexp or whole string. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2607 (subexp) |
14086
a410808fda15
(Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
2608 Lisp_Object subexp; |
603 | 2609 { |
14086
a410808fda15
(Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
2610 return match_limit (subexp, 1); |
603 | 2611 } |
2612 | |
2613 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
|
2614 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
|
2615 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
|
2616 regexp. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2617 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
|
2618 SUBEXP pairs. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2619 Zero means the entire text matched by the whole regexp or whole string. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2620 (subexp) |
14086
a410808fda15
(Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
2621 Lisp_Object subexp; |
603 | 2622 { |
14086
a410808fda15
(Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
2623 return match_limit (subexp, 0); |
603 | 2624 } |
2625 | |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2626 DEFUN ("match-data", Fmatch_data, Smatch_data, 0, 2, 0, |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2627 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
|
2628 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
|
2629 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
|
2630 if the last match was on a buffer; integers or nil if a string was matched. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2631 Use `store-match-data' to reinstate the data in this list. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2632 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2633 If INTEGERS (the optional first argument) is non-nil, always use integers |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2634 \(rather than markers) to represent buffer positions. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2635 If REUSE is a list, reuse it as part of the value. If REUSE is long enough |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2636 to hold all the values, and if INTEGERS is non-nil, no consing is done. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2637 (integers, reuse) |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2638 Lisp_Object integers, reuse; |
603 | 2639 { |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2640 Lisp_Object tail, prev; |
621 | 2641 Lisp_Object *data; |
603 | 2642 int i, len; |
2643 | |
727 | 2644 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
|
2645 return Qnil; |
727 | 2646 |
31829
43566b0aec59
Avoid some more compiler warnings.
Gerd Moellmann <gerd@gnu.org>
parents:
31486
diff
changeset
|
2647 prev = Qnil; |
43566b0aec59
Avoid some more compiler warnings.
Gerd Moellmann <gerd@gnu.org>
parents:
31486
diff
changeset
|
2648 |
621 | 2649 data = (Lisp_Object *) alloca ((2 * search_regs.num_regs) |
2650 * sizeof (Lisp_Object)); | |
2651 | |
603 | 2652 len = -1; |
621 | 2653 for (i = 0; i < search_regs.num_regs; i++) |
603 | 2654 { |
2655 int start = search_regs.start[i]; | |
2656 if (start >= 0) | |
2657 { | |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2658 if (EQ (last_thing_searched, Qt) |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2659 || ! NILP (integers)) |
603 | 2660 { |
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
|
2661 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
|
2662 XSETFASTINT (data[2 * i + 1], search_regs.end[i]); |
603 | 2663 } |
9113
766b6288e0f2
(Fmatch_data, Fstore_match_data): Use type test macros.
Karl Heuer <kwzh@gnu.org>
parents:
9029
diff
changeset
|
2664 else if (BUFFERP (last_thing_searched)) |
603 | 2665 { |
2666 data[2 * i] = Fmake_marker (); | |
727 | 2667 Fset_marker (data[2 * i], |
2668 make_number (start), | |
2669 last_thing_searched); | |
603 | 2670 data[2 * i + 1] = Fmake_marker (); |
2671 Fset_marker (data[2 * i + 1], | |
727 | 2672 make_number (search_regs.end[i]), |
2673 last_thing_searched); | |
603 | 2674 } |
727 | 2675 else |
2676 /* last_thing_searched must always be Qt, a buffer, or Qnil. */ | |
2677 abort (); | |
2678 | |
603 | 2679 len = i; |
2680 } | |
2681 else | |
2682 data[2 * i] = data [2 * i + 1] = Qnil; | |
2683 } | |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2684 |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2685 /* 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
|
2686 if (! CONSP (reuse)) |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2687 return Flist (2 * len + 2, data); |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2688 |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2689 /* 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
|
2690 into the elements of REUSE. */ |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2691 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
|
2692 i++, tail = XCDR (tail)) |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2693 { |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2694 if (i < 2 * len + 2) |
39973
579177964efa
Avoid (most) uses of XCAR/XCDR as lvalues, for flexibility in experimenting
Ken Raeburn <raeburn@raeburn.org>
parents:
39805
diff
changeset
|
2695 XSETCAR (tail, data[i]); |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2696 else |
39973
579177964efa
Avoid (most) uses of XCAR/XCDR as lvalues, for flexibility in experimenting
Ken Raeburn <raeburn@raeburn.org>
parents:
39805
diff
changeset
|
2697 XSETCAR (tail, Qnil); |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2698 prev = tail; |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2699 } |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2700 |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2701 /* 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
|
2702 cons up the rest of them and add them to the end of REUSE. */ |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2703 if (i < 2 * len + 2) |
39973
579177964efa
Avoid (most) uses of XCAR/XCDR as lvalues, for flexibility in experimenting
Ken Raeburn <raeburn@raeburn.org>
parents:
39805
diff
changeset
|
2704 XSETCDR (prev, Flist (2 * len + 2 - i, data + i)); |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2705 |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2706 return reuse; |
603 | 2707 } |
2708 | |
2709 | |
21171
60f6085df198
(Fset_match_data): Renamed from Fstore_match_data.
Richard M. Stallman <rms@gnu.org>
parents:
21117
diff
changeset
|
2710 DEFUN ("set-match-data", Fset_match_data, Sset_match_data, 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
|
2711 doc: /* Set internal data on last search match from elements of LIST. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2712 LIST should have been created by calling `match-data' previously. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2713 (list) |
603 | 2714 register Lisp_Object list; |
2715 { | |
2716 register int i; | |
2717 register Lisp_Object marker; | |
2718 | |
10032
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2719 if (running_asynch_code) |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2720 save_search_regs (); |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2721 |
603 | 2722 if (!CONSP (list) && !NILP (list)) |
1926
952f2a18f83d
* callint.c (Fcall_interactively): Pass the correct number of
Jim Blandy <jimb@redhat.com>
parents:
1896
diff
changeset
|
2723 list = wrong_type_argument (Qconsp, list); |
603 | 2724 |
727 | 2725 /* Unless we find a marker with a buffer in LIST, assume that this |
2726 match data came from a string. */ | |
2727 last_thing_searched = Qt; | |
2728 | |
621 | 2729 /* Allocate registers if they don't already exist. */ |
2730 { | |
1523
bd61aaa7828b
* search.c (Fstore_match_data): Don't assume Flength returns an
Jim Blandy <jimb@redhat.com>
parents:
1413
diff
changeset
|
2731 int length = XFASTINT (Flength (list)) / 2; |
621 | 2732 |
2733 if (length > search_regs.num_regs) | |
2734 { | |
708 | 2735 if (search_regs.num_regs == 0) |
2736 { | |
2737 search_regs.start | |
2738 = (regoff_t *) xmalloc (length * sizeof (regoff_t)); | |
2739 search_regs.end | |
2740 = (regoff_t *) xmalloc (length * sizeof (regoff_t)); | |
2741 } | |
621 | 2742 else |
708 | 2743 { |
2744 search_regs.start | |
2745 = (regoff_t *) xrealloc (search_regs.start, | |
2746 length * sizeof (regoff_t)); | |
2747 search_regs.end | |
2748 = (regoff_t *) xrealloc (search_regs.end, | |
2749 length * sizeof (regoff_t)); | |
2750 } | |
621 | 2751 |
33052
9ec478daa468
(Fset_match_data): Be sure to make search_regs always sane.
Kenichi Handa <handa@m17n.org>
parents:
32387
diff
changeset
|
2752 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
|
2753 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
|
2754 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
2755 search_regs.num_regs = length; |
621 | 2756 } |
2757 } | |
2758 | |
2759 for (i = 0; i < search_regs.num_regs; i++) | |
603 | 2760 { |
2761 marker = Fcar (list); | |
2762 if (NILP (marker)) | |
2763 { | |
2764 search_regs.start[i] = -1; | |
2765 list = Fcdr (list); | |
2766 } | |
2767 else | |
2768 { | |
33052
9ec478daa468
(Fset_match_data): Be sure to make search_regs always sane.
Kenichi Handa <handa@m17n.org>
parents:
32387
diff
changeset
|
2769 int from; |
9ec478daa468
(Fset_match_data): Be sure to make search_regs always sane.
Kenichi Handa <handa@m17n.org>
parents:
32387
diff
changeset
|
2770 |
9113
766b6288e0f2
(Fmatch_data, Fstore_match_data): Use type test macros.
Karl Heuer <kwzh@gnu.org>
parents:
9029
diff
changeset
|
2771 if (MARKERP (marker)) |
727 | 2772 { |
2773 if (XMARKER (marker)->buffer == 0) | |
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
|
2774 XSETFASTINT (marker, 0); |
727 | 2775 else |
9278
f2138d548313
(Flooking_at, skip_chars, search_buffer, set_search_regs, Fstore_match_data):
Karl Heuer <kwzh@gnu.org>
parents:
9113
diff
changeset
|
2776 XSETBUFFER (last_thing_searched, XMARKER (marker)->buffer); |
727 | 2777 } |
603 | 2778 |
2779 CHECK_NUMBER_COERCE_MARKER (marker, 0); | |
33052
9ec478daa468
(Fset_match_data): Be sure to make search_regs always sane.
Kenichi Handa <handa@m17n.org>
parents:
32387
diff
changeset
|
2780 from = XINT (marker); |
603 | 2781 list = Fcdr (list); |
2782 | |
2783 marker = Fcar (list); | |
9113
766b6288e0f2
(Fmatch_data, Fstore_match_data): Use type test macros.
Karl Heuer <kwzh@gnu.org>
parents:
9029
diff
changeset
|
2784 if (MARKERP (marker) && XMARKER (marker)->buffer == 0) |
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
|
2785 XSETFASTINT (marker, 0); |
603 | 2786 |
2787 CHECK_NUMBER_COERCE_MARKER (marker, 0); | |
33052
9ec478daa468
(Fset_match_data): Be sure to make search_regs always sane.
Kenichi Handa <handa@m17n.org>
parents:
32387
diff
changeset
|
2788 search_regs.start[i] = from; |
603 | 2789 search_regs.end[i] = XINT (marker); |
2790 } | |
2791 list = Fcdr (list); | |
2792 } | |
2793 | |
2794 return Qnil; | |
2795 } | |
2796 | |
10032
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2797 /* 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
|
2798 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
|
2799 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
|
2800 static struct re_registers saved_search_regs; |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2801 |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2802 /* 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
|
2803 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
|
2804 static void |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2805 save_search_regs () |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2806 { |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2807 if (!search_regs_saved) |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2808 { |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2809 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
|
2810 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
|
2811 saved_search_regs.end = search_regs.end; |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2812 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
|
2813 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
|
2814 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
|
2815 |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2816 search_regs_saved = 1; |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2817 } |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2818 } |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2819 |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2820 /* 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
|
2821 void |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2822 restore_match_data () |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2823 { |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2824 if (search_regs_saved) |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2825 { |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2826 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
|
2827 { |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2828 xfree (search_regs.start); |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2829 xfree (search_regs.end); |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2830 } |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2831 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
|
2832 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
|
2833 search_regs.end = saved_search_regs.end; |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2834 |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2835 search_regs_saved = 0; |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2836 } |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2837 } |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2838 |
603 | 2839 /* Quote a string to inactivate reg-expr chars */ |
2840 | |
2841 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
|
2842 doc: /* Return a regexp string which matches exactly STRING and nothing else. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2843 (string) |
14086
a410808fda15
(Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
2844 Lisp_Object string; |
603 | 2845 { |
2846 register unsigned char *in, *out, *end; | |
2847 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
|
2848 int backslashes_added = 0; |
603 | 2849 |
14086
a410808fda15
(Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
2850 CHECK_STRING (string, 0); |
603 | 2851 |
21244
50929073a0ba
Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents:
21171
diff
changeset
|
2852 temp = (unsigned char *) alloca (STRING_BYTES (XSTRING (string)) * 2); |
603 | 2853 |
2854 /* Now copy the data into the new string, inserting escapes. */ | |
2855 | |
14086
a410808fda15
(Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
2856 in = XSTRING (string)->data; |
21244
50929073a0ba
Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents:
21171
diff
changeset
|
2857 end = in + STRING_BYTES (XSTRING (string)); |
603 | 2858 out = temp; |
2859 | |
2860 for (; in != end; in++) | |
2861 { | |
2862 if (*in == '[' || *in == ']' | |
2863 || *in == '*' || *in == '.' || *in == '\\' | |
2864 || *in == '?' || *in == '+' | |
2865 || *in == '^' || *in == '$') | |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2866 *out++ = '\\', backslashes_added++; |
603 | 2867 *out++ = *in; |
2868 } | |
2869 | |
21248
aba5e1c3328b
(Fregexp_quote): Use make_specified_string.
Richard M. Stallman <rms@gnu.org>
parents:
21244
diff
changeset
|
2870 return make_specified_string (temp, |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2871 XSTRING (string)->size + backslashes_added, |
21248
aba5e1c3328b
(Fregexp_quote): Use make_specified_string.
Richard M. Stallman <rms@gnu.org>
parents:
21244
diff
changeset
|
2872 out - temp, |
aba5e1c3328b
(Fregexp_quote): Use make_specified_string.
Richard M. Stallman <rms@gnu.org>
parents:
21244
diff
changeset
|
2873 STRING_MULTIBYTE (string)); |
603 | 2874 } |
2875 | |
21514 | 2876 void |
603 | 2877 syms_of_search () |
2878 { | |
2879 register int i; | |
2880 | |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
2881 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
|
2882 { |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
2883 searchbufs[i].buf.allocated = 100; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
2884 searchbufs[i].buf.buffer = (unsigned char *) malloc (100); |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
2885 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
|
2886 searchbufs[i].regexp = Qnil; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
2887 staticpro (&searchbufs[i].regexp); |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
2888 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
|
2889 } |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
2890 searchbuf_head = &searchbufs[0]; |
603 | 2891 |
2892 Qsearch_failed = intern ("search-failed"); | |
2893 staticpro (&Qsearch_failed); | |
2894 Qinvalid_regexp = intern ("invalid-regexp"); | |
2895 staticpro (&Qinvalid_regexp); | |
2896 | |
2897 Fput (Qsearch_failed, Qerror_conditions, | |
2898 Fcons (Qsearch_failed, Fcons (Qerror, Qnil))); | |
2899 Fput (Qsearch_failed, Qerror_message, | |
2900 build_string ("Search failed")); | |
2901 | |
2902 Fput (Qinvalid_regexp, Qerror_conditions, | |
2903 Fcons (Qinvalid_regexp, Fcons (Qerror, Qnil))); | |
2904 Fput (Qinvalid_regexp, Qerror_message, | |
2905 build_string ("Invalid regexp")); | |
2906 | |
727 | 2907 last_thing_searched = Qnil; |
2908 staticpro (&last_thing_searched); | |
2909 | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2910 defsubr (&Slooking_at); |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2911 defsubr (&Sposix_looking_at); |
603 | 2912 defsubr (&Sstring_match); |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2913 defsubr (&Sposix_string_match); |
603 | 2914 defsubr (&Ssearch_forward); |
2915 defsubr (&Ssearch_backward); | |
2916 defsubr (&Sword_search_forward); | |
2917 defsubr (&Sword_search_backward); | |
2918 defsubr (&Sre_search_forward); | |
2919 defsubr (&Sre_search_backward); | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2920 defsubr (&Sposix_search_forward); |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2921 defsubr (&Sposix_search_backward); |
603 | 2922 defsubr (&Sreplace_match); |
2923 defsubr (&Smatch_beginning); | |
2924 defsubr (&Smatch_end); | |
2925 defsubr (&Smatch_data); | |
21171
60f6085df198
(Fset_match_data): Renamed from Fstore_match_data.
Richard M. Stallman <rms@gnu.org>
parents:
21117
diff
changeset
|
2926 defsubr (&Sset_match_data); |
603 | 2927 defsubr (&Sregexp_quote); |
2928 } |