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