Mercurial > emacs
annotate src/search.c @ 95304:300e5a5c5a17
Merge from gnus--devo--0
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-1178
author | Miles Bader <miles@gnu.org> |
---|---|
date | Mon, 26 May 2008 06:57:27 +0000 |
parents | 8971ddf55736 |
children | 99656f6b55ce |
rev | line source |
---|---|
603 | 1 /* String search routines for GNU Emacs. |
75227
e90d04cd455a
Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents:
74917
diff
changeset
|
2 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1997, 1998, 1999, 2001, 2002, |
79759 | 3 2003, 2004, 2005, 2006, 2007, 2008 |
4 Free Software Foundation, Inc. | |
603 | 5 |
6 This file is part of GNU Emacs. | |
7 | |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93758
diff
changeset
|
8 GNU Emacs is free software: you can redistribute it and/or modify |
603 | 9 it under the terms of the GNU General Public License as published by |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93758
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93758
diff
changeset
|
11 (at your option) any later version. |
603 | 12 |
13 GNU Emacs is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93758
diff
changeset
|
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
603 | 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" |
88388
e9a23b7c1feb
Include "character.h" instead of "charset.h".
Kenichi Handa <handa@m17n.org>
parents:
41389
diff
changeset
|
27 #include "character.h" |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
28 #include "charset.h" |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
29 #include "region-cache.h" |
603 | 30 #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
|
31 #include "blockinput.h" |
20347
d8e5f3c1618b
Include "intervals.h" for prototypes.
Andreas Schwab <schwab@suse.de>
parents:
19541
diff
changeset
|
32 #include "intervals.h" |
621 | 33 |
603 | 34 #include <sys/types.h> |
35 #include "regex.h" | |
36 | |
16275
a4bcfdc9bb66
(REGEXP_CACHE_SIZE): Increase to 20.
Richard M. Stallman <rms@gnu.org>
parents:
16152
diff
changeset
|
37 #define REGEXP_CACHE_SIZE 20 |
603 | 38 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
39 /* 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
|
40 of that regexp, suitable for searching. */ |
16275
a4bcfdc9bb66
(REGEXP_CACHE_SIZE): Increase to 20.
Richard M. Stallman <rms@gnu.org>
parents:
16152
diff
changeset
|
41 struct regexp_cache |
a4bcfdc9bb66
(REGEXP_CACHE_SIZE): Increase to 20.
Richard M. Stallman <rms@gnu.org>
parents:
16152
diff
changeset
|
42 { |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
43 struct regexp_cache *next; |
58330
5be8a633ec57
(struct regexp_cache): New element whitespace_regexp.
Richard M. Stallman <rms@gnu.org>
parents:
58326
diff
changeset
|
44 Lisp_Object regexp, whitespace_regexp; |
73002
b3a72607819d
* search.c (struct regexp_cache): New entry syntax_table.
Chong Yidong <cyd@stupidchicken.com>
parents:
72945
diff
changeset
|
45 /* Syntax table for which the regexp applies. We need this because |
73230
20801e603746
(compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
73096
diff
changeset
|
46 of character classes. If this is t, then the compiled pattern is valid |
20801e603746
(compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
73096
diff
changeset
|
47 for any syntax-table. */ |
73002
b3a72607819d
* search.c (struct regexp_cache): New entry syntax_table.
Chong Yidong <cyd@stupidchicken.com>
parents:
72945
diff
changeset
|
48 Lisp_Object syntax_table; |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
49 struct re_pattern_buffer buf; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
50 char fastmap[0400]; |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
51 /* 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
|
52 char posix; |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
53 }; |
603 | 54 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
55 /* The instances of that struct. */ |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
56 struct regexp_cache searchbufs[REGEXP_CACHE_SIZE]; |
603 | 57 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
58 /* 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
|
59 struct regexp_cache *searchbuf_head; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
60 |
603 | 61 |
621 | 62 /* Every call to re_match, etc., must pass &search_regs as the regs |
63 argument unless you can show it is unnecessary (i.e., if re_match | |
64 is certainly going to be called again before region-around-match | |
65 can be called). | |
66 | |
67 Since the registers are now dynamically allocated, we need to make | |
68 sure not to refer to the Nth register before checking that it has | |
708 | 69 been allocated by checking search_regs.num_regs. |
603 | 70 |
708 | 71 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
|
72 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
|
73 you compile a new pattern, it completely forgets whether it has |
708 | 74 allocated any registers, and will allocate new registers the next |
75 time you call a searching or matching function. Therefore, we need | |
76 to call re_set_registers after compiling a new pattern or after | |
77 setting the match registers, so that the regex functions will be | |
78 able to free or re-allocate it properly. */ | |
603 | 79 static struct re_registers search_regs; |
80 | |
727 | 81 /* The buffer in which the last search was performed, or |
82 Qt if the last search was done in a string; | |
83 Qnil if no searching has been done yet. */ | |
84 static Lisp_Object last_thing_searched; | |
603 | 85 |
14036 | 86 /* error condition signaled when regexp compile_pattern fails */ |
603 | 87 |
88 Lisp_Object Qinvalid_regexp; | |
89 | |
71987
6dd00de34fff
(compile_pattern_1): Use xsignal1.
Kim F. Storm <storm@cua.dk>
parents:
71841
diff
changeset
|
90 /* Error condition used for failing searches */ |
6dd00de34fff
(compile_pattern_1): Use xsignal1.
Kim F. Storm <storm@cua.dk>
parents:
71841
diff
changeset
|
91 Lisp_Object Qsearch_failed; |
6dd00de34fff
(compile_pattern_1): Use xsignal1.
Kim F. Storm <storm@cua.dk>
parents:
71841
diff
changeset
|
92 |
58348
623ffd21f0ff
(Vsearch_spaces_regexp):
Richard M. Stallman <rms@gnu.org>
parents:
58330
diff
changeset
|
93 Lisp_Object Vsearch_spaces_regexp; |
58326
0cc0d3274d68
(Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
57735
diff
changeset
|
94 |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
95 /* If non-nil, the match data will not be changed during call to |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
96 searching or matching functions. This variable is for internal use |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
97 only. */ |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
98 Lisp_Object Vinhibit_changing_match_data; |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
99 |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
100 static void set_search_regs (); |
10055
cb713218845a
(save_search_regs): Add declaration.
Richard M. Stallman <rms@gnu.org>
parents:
10032
diff
changeset
|
101 static void save_search_regs (); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
102 static int simple_search (); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
103 static int boyer_moore (); |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
104 static int search_buffer (); |
71063
7510757f449b
* search.c (matcher_overflow): Mark as NO_RETURN.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
69882
diff
changeset
|
105 static void matcher_overflow () NO_RETURN; |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
106 |
603 | 107 static void |
108 matcher_overflow () | |
109 { | |
110 error ("Stack overflow in regexp matcher"); | |
111 } | |
112 | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
113 /* 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
|
114 PATTERN is the pattern to compile. |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 subexpression bounds. |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
121 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
|
122 for this pattern. 0 means backtrack only enough to get a valid match. |
58330
5be8a633ec57
(struct regexp_cache): New element whitespace_regexp.
Richard M. Stallman <rms@gnu.org>
parents:
58326
diff
changeset
|
123 |
58348
623ffd21f0ff
(Vsearch_spaces_regexp):
Richard M. Stallman <rms@gnu.org>
parents:
58330
diff
changeset
|
124 The behavior also depends on Vsearch_spaces_regexp. */ |
603 | 125 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
126 static void |
90760 | 127 compile_pattern_1 (cp, pattern, translate, regp, posix) |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
128 struct regexp_cache *cp; |
603 | 129 Lisp_Object pattern; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
130 Lisp_Object translate; |
708 | 131 struct re_registers *regp; |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
132 int posix; |
603 | 133 { |
18762
12c0de0113af
(compile_pattern_1): Don't declare val with CONST.
Richard M. Stallman <rms@gnu.org>
parents:
18193
diff
changeset
|
134 char *val; |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
135 reg_syntax_t old; |
603 | 136 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
137 cp->regexp = Qnil; |
21531
5811a3129878
(compile_pattern, compile_pattern_1): Fix mixing of
Andreas Schwab <schwab@suse.de>
parents:
21514
diff
changeset
|
138 cp->buf.translate = (! NILP (translate) ? translate : make_number (0)); |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
139 cp->posix = posix; |
89062
be059fb97bac
(compile_pattern_1): Don't adjust the multibyteness of
Kenichi Handa <handa@m17n.org>
parents:
89028
diff
changeset
|
140 cp->buf.multibyte = STRING_MULTIBYTE (pattern); |
90760 | 141 cp->buf.charset_unibyte = charset_unibyte; |
93758
abcbb8375c30
(compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents:
91762
diff
changeset
|
142 if (STRINGP (Vsearch_spaces_regexp)) |
abcbb8375c30
(compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents:
91762
diff
changeset
|
143 cp->whitespace_regexp = Vsearch_spaces_regexp; |
abcbb8375c30
(compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents:
91762
diff
changeset
|
144 else |
abcbb8375c30
(compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents:
91762
diff
changeset
|
145 cp->whitespace_regexp = Qnil; |
abcbb8375c30
(compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents:
91762
diff
changeset
|
146 |
73096
2f768f0aab61
(compile_pattern_1): Don't BLOCK_INPUT.
Richard M. Stallman <rms@gnu.org>
parents:
73002
diff
changeset
|
147 /* rms: I think BLOCK_INPUT is not needed here any more, |
2f768f0aab61
(compile_pattern_1): Don't BLOCK_INPUT.
Richard M. Stallman <rms@gnu.org>
parents:
73002
diff
changeset
|
148 because regex.c defines malloc to call xmalloc. |
2f768f0aab61
(compile_pattern_1): Don't BLOCK_INPUT.
Richard M. Stallman <rms@gnu.org>
parents:
73002
diff
changeset
|
149 Using BLOCK_INPUT here means the debugger won't run if an error occurs. |
2f768f0aab61
(compile_pattern_1): Don't BLOCK_INPUT.
Richard M. Stallman <rms@gnu.org>
parents:
73002
diff
changeset
|
150 So let's turn it off. */ |
2f768f0aab61
(compile_pattern_1): Don't BLOCK_INPUT.
Richard M. Stallman <rms@gnu.org>
parents:
73002
diff
changeset
|
151 /* BLOCK_INPUT; */ |
27692
bb0e45f6ca86
* regex.h (RE_SYNTAX_EMACS): Add RE_CHAR_CLASSES and RE_INTERVALS
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27592
diff
changeset
|
152 old = re_set_syntax (RE_SYNTAX_EMACS |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
153 | (posix ? 0 : RE_NO_POSIX_BACKTRACKING)); |
93758
abcbb8375c30
(compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents:
91762
diff
changeset
|
154 |
abcbb8375c30
(compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents:
91762
diff
changeset
|
155 if (STRINGP (Vsearch_spaces_regexp)) |
abcbb8375c30
(compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents:
91762
diff
changeset
|
156 re_set_whitespace_regexp (SDATA (Vsearch_spaces_regexp)); |
abcbb8375c30
(compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents:
91762
diff
changeset
|
157 else |
abcbb8375c30
(compile_pattern_1): Treat non-nil and non-string of
Chong Yidong <cyd@stupidchicken.com>
parents:
91762
diff
changeset
|
158 re_set_whitespace_regexp (NULL); |
58326
0cc0d3274d68
(Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
57735
diff
changeset
|
159 |
89483 | 160 val = (char *) re_compile_pattern ((char *) SDATA (pattern), |
161 SBYTES (pattern), &cp->buf); | |
58326
0cc0d3274d68
(Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
57735
diff
changeset
|
162 |
73230
20801e603746
(compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
73096
diff
changeset
|
163 /* If the compiled pattern hard codes some of the contents of the |
20801e603746
(compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
73096
diff
changeset
|
164 syntax-table, it can only be reused with *this* syntax table. */ |
20801e603746
(compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
73096
diff
changeset
|
165 cp->syntax_table = cp->buf.used_syntax ? current_buffer->syntax_table : Qt; |
20801e603746
(compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
73096
diff
changeset
|
166 |
58326
0cc0d3274d68
(Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
57735
diff
changeset
|
167 re_set_whitespace_regexp (NULL); |
0cc0d3274d68
(Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
57735
diff
changeset
|
168 |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
169 re_set_syntax (old); |
73096
2f768f0aab61
(compile_pattern_1): Don't BLOCK_INPUT.
Richard M. Stallman <rms@gnu.org>
parents:
73002
diff
changeset
|
170 /* UNBLOCK_INPUT; */ |
603 | 171 if (val) |
71987
6dd00de34fff
(compile_pattern_1): Use xsignal1.
Kim F. Storm <storm@cua.dk>
parents:
71841
diff
changeset
|
172 xsignal1 (Qinvalid_regexp, build_string (val)); |
708 | 173 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
174 cp->regexp = Fcopy_sequence (pattern); |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
175 } |
708 | 176 |
22221
239a4b800303
(shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22082
diff
changeset
|
177 /* Shrink each compiled regexp buffer in the cache |
239a4b800303
(shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22082
diff
changeset
|
178 to the size actually used right now. |
239a4b800303
(shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22082
diff
changeset
|
179 This is called from garbage collection. */ |
239a4b800303
(shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22082
diff
changeset
|
180 |
239a4b800303
(shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22082
diff
changeset
|
181 void |
239a4b800303
(shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22082
diff
changeset
|
182 shrink_regexp_cache () |
239a4b800303
(shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22082
diff
changeset
|
183 { |
34966
23a62cf7d0eb
(shrink_regexp_cache): Remove unused variable `cpp'.
Eli Zaretskii <eliz@gnu.org>
parents:
33052
diff
changeset
|
184 struct regexp_cache *cp; |
22221
239a4b800303
(shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22082
diff
changeset
|
185 |
239a4b800303
(shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22082
diff
changeset
|
186 for (cp = searchbuf_head; cp != 0; cp = cp->next) |
239a4b800303
(shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22082
diff
changeset
|
187 { |
239a4b800303
(shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22082
diff
changeset
|
188 cp->buf.allocated = cp->buf.used; |
239a4b800303
(shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22082
diff
changeset
|
189 cp->buf.buffer |
51544
a0c2b39160e9
(shrink_regexp_cache): Use xrealloc.
Dave Love <fx@gnu.org>
parents:
49761
diff
changeset
|
190 = (unsigned char *) xrealloc (cp->buf.buffer, cp->buf.used); |
22221
239a4b800303
(shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22082
diff
changeset
|
191 } |
239a4b800303
(shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22082
diff
changeset
|
192 } |
239a4b800303
(shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22082
diff
changeset
|
193 |
73232
5f8a28d018b2
(compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
73230
diff
changeset
|
194 /* Clear the regexp cache w.r.t. a particular syntax table, |
5f8a28d018b2
(compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
73230
diff
changeset
|
195 because it was changed. |
72945
d4ecc69b8d2e
* search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents:
72725
diff
changeset
|
196 There is no danger of memory leak here because re_compile_pattern |
d4ecc69b8d2e
* search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents:
72725
diff
changeset
|
197 automagically manages the memory in each re_pattern_buffer struct, |
d4ecc69b8d2e
* search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents:
72725
diff
changeset
|
198 based on its `allocated' and `buffer' values. */ |
d4ecc69b8d2e
* search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents:
72725
diff
changeset
|
199 void |
d4ecc69b8d2e
* search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents:
72725
diff
changeset
|
200 clear_regexp_cache () |
d4ecc69b8d2e
* search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents:
72725
diff
changeset
|
201 { |
d4ecc69b8d2e
* search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents:
72725
diff
changeset
|
202 int i; |
d4ecc69b8d2e
* search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents:
72725
diff
changeset
|
203 |
d4ecc69b8d2e
* search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents:
72725
diff
changeset
|
204 for (i = 0; i < REGEXP_CACHE_SIZE; ++i) |
73232
5f8a28d018b2
(compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
73230
diff
changeset
|
205 /* It's tempting to compare with the syntax-table we've actually changd, |
5f8a28d018b2
(compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
73230
diff
changeset
|
206 but it's not sufficient because char-table inheritance mewans that |
5f8a28d018b2
(compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
73230
diff
changeset
|
207 modifying one syntax-table can change others at the same time. */ |
5f8a28d018b2
(compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
73230
diff
changeset
|
208 if (!EQ (searchbufs[i].syntax_table, Qt)) |
5f8a28d018b2
(compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
73230
diff
changeset
|
209 searchbufs[i].regexp = Qnil; |
72945
d4ecc69b8d2e
* search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents:
72725
diff
changeset
|
210 } |
d4ecc69b8d2e
* search.c (clear_regexp_cache): New function.
Chong Yidong <cyd@stupidchicken.com>
parents:
72725
diff
changeset
|
211 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
212 /* 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
|
213 the cache. |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
214 PATTERN is the pattern to compile. |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
215 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
|
216 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
|
217 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
|
218 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
|
219 subexpression bounds. |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
220 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
|
221 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
|
222 |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
223 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
|
224 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
|
225 Lisp_Object pattern; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
226 struct re_registers *regp; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
227 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
|
228 int posix, multibyte; |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
229 { |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
230 struct regexp_cache *cp, **cpp; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
231 |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
232 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
|
233 { |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
234 cp = *cpp; |
27592
5cd59d1800ad
* search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents:
26985
diff
changeset
|
235 /* Entries are initialized to nil, and may be set to nil by |
5cd59d1800ad
* search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents:
26985
diff
changeset
|
236 compile_pattern_1 if the pattern isn't valid. Don't apply |
46444 | 237 string accessors in those cases. However, compile_pattern_1 |
238 is only applied to the cache entry we pick here to reuse. So | |
239 nil should never appear before a non-nil entry. */ | |
28507
b6f06a755c7d
make_number/XINT/XUINT conversions; EQ/== fixes; ==Qnil -> NILP
Ken Raeburn <raeburn@raeburn.org>
parents:
28387
diff
changeset
|
240 if (NILP (cp->regexp)) |
27592
5cd59d1800ad
* search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents:
26985
diff
changeset
|
241 goto compile_it; |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
242 if (SCHARS (cp->regexp) == SCHARS (pattern) |
31486
a3dc5f987e8f
(compile_pattern): Check the multibyteness of cached
Kenichi Handa <handa@m17n.org>
parents:
29335
diff
changeset
|
243 && STRING_MULTIBYTE (cp->regexp) == STRING_MULTIBYTE (pattern) |
16275
a4bcfdc9bb66
(REGEXP_CACHE_SIZE): Increase to 20.
Richard M. Stallman <rms@gnu.org>
parents:
16152
diff
changeset
|
244 && !NILP (Fstring_equal (cp->regexp, pattern)) |
21531
5811a3129878
(compile_pattern, compile_pattern_1): Fix mixing of
Andreas Schwab <schwab@suse.de>
parents:
21514
diff
changeset
|
245 && EQ (cp->buf.translate, (! NILP (translate) ? translate : make_number (0))) |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
246 && cp->posix == posix |
73230
20801e603746
(compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
73096
diff
changeset
|
247 && (EQ (cp->syntax_table, Qt) |
20801e603746
(compile_pattern): Only check `cp->syntax_table' if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
73096
diff
changeset
|
248 || EQ (cp->syntax_table, current_buffer->syntax_table)) |
90760 | 249 && !NILP (Fequal (cp->whitespace_regexp, Vsearch_spaces_regexp)) |
250 && cp->buf.charset_unibyte == charset_unibyte) | |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
251 break; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
252 |
27592
5cd59d1800ad
* search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents:
26985
diff
changeset
|
253 /* If we're at the end of the cache, compile into the nil cell |
5cd59d1800ad
* search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents:
26985
diff
changeset
|
254 we found, or the last (least recently used) cell with a |
5cd59d1800ad
* search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents:
26985
diff
changeset
|
255 string value. */ |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
256 if (cp->next == 0) |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
257 { |
27592
5cd59d1800ad
* search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents:
26985
diff
changeset
|
258 compile_it: |
90760 | 259 compile_pattern_1 (cp, pattern, translate, regp, posix); |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
260 break; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
261 } |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
262 } |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
263 |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
264 /* 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
|
265 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
|
266 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
|
267 *cpp = cp->next; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
268 cp->next = searchbuf_head; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
269 searchbuf_head = cp; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
270 |
10141
afe81fd385eb
(compile_pattern): Call re_set_registers here.
Richard M. Stallman <rms@gnu.org>
parents:
10128
diff
changeset
|
271 /* 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
|
272 for register data. */ |
afe81fd385eb
(compile_pattern): Call re_set_registers here.
Richard M. Stallman <rms@gnu.org>
parents:
10128
diff
changeset
|
273 if (regp) |
afe81fd385eb
(compile_pattern): Call re_set_registers here.
Richard M. Stallman <rms@gnu.org>
parents:
10128
diff
changeset
|
274 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
|
275 |
90760 | 276 /* The compiled pattern can be used both for mulitbyte and unibyte |
277 target. But, we have to tell which the pattern is used for. */ | |
278 cp->buf.target_multibyte = multibyte; | |
279 | |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
280 return &cp->buf; |
603 | 281 } |
282 | |
283 | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
284 static Lisp_Object |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
285 looking_at_1 (string, posix) |
603 | 286 Lisp_Object string; |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
287 int posix; |
603 | 288 { |
289 Lisp_Object val; | |
290 unsigned char *p1, *p2; | |
291 int s1, s2; | |
292 register int i; | |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
293 struct re_pattern_buffer *bufp; |
603 | 294 |
10032
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
295 if (running_asynch_code) |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
296 save_search_regs (); |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
297 |
72725
ef0421dfce16
(looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents:
71987
diff
changeset
|
298 /* This is so set_image_of_range_1 in regex.c can find the EQV table. */ |
ef0421dfce16
(looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents:
71987
diff
changeset
|
299 XCHAR_TABLE (current_buffer->case_canon_table)->extras[2] |
ef0421dfce16
(looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents:
71987
diff
changeset
|
300 = current_buffer->case_eqv_table; |
ef0421dfce16
(looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents:
71987
diff
changeset
|
301 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40269
diff
changeset
|
302 CHECK_STRING (string); |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
303 bufp = compile_pattern (string, |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
304 (NILP (Vinhibit_changing_match_data) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
305 ? &search_regs : NULL), |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
306 (!NILP (current_buffer->case_fold_search) |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
307 ? current_buffer->case_canon_table : Qnil), |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
308 posix, |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
309 !NILP (current_buffer->enable_multibyte_characters)); |
603 | 310 |
311 immediate_quit = 1; | |
312 QUIT; /* Do a pending quit right away, to avoid paradoxical behavior */ | |
313 | |
314 /* Get pointers and sizes of the two strings | |
315 that make up the visible portion of the buffer. */ | |
316 | |
317 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
|
318 s1 = GPT_BYTE - BEGV_BYTE; |
603 | 319 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
|
320 s2 = ZV_BYTE - GPT_BYTE; |
603 | 321 if (s1 < 0) |
322 { | |
323 p2 = p1; | |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
324 s2 = ZV_BYTE - BEGV_BYTE; |
603 | 325 s1 = 0; |
326 } | |
327 if (s2 < 0) | |
328 { | |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
329 s1 = ZV_BYTE - BEGV_BYTE; |
603 | 330 s2 = 0; |
331 } | |
17463
bb9ae80d22e2
(looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents:
17284
diff
changeset
|
332 |
bb9ae80d22e2
(looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents:
17284
diff
changeset
|
333 re_match_object = Qnil; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
334 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
335 i = re_match_2 (bufp, (char *) p1, s1, (char *) p2, s2, |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
336 PT_BYTE - BEGV_BYTE, |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
337 (NILP (Vinhibit_changing_match_data) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
338 ? &search_regs : NULL), |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
339 ZV_BYTE - BEGV_BYTE); |
26985
1121a5da20a5
(looking_at_1): Reset immediate_quit before modifying
Gerd Moellmann <gerd@gnu.org>
parents:
26982
diff
changeset
|
340 immediate_quit = 0; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
341 |
603 | 342 if (i == -2) |
343 matcher_overflow (); | |
344 | |
345 val = (0 <= i ? Qt : Qnil); | |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
346 if (NILP (Vinhibit_changing_match_data) && i >= 0) |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
347 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
|
348 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
|
349 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
350 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
|
351 = 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
|
352 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
|
353 = 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
|
354 } |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
355 |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
356 /* Set last_thing_searched only when match data is changed. */ |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
357 if (NILP (Vinhibit_changing_match_data)) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
358 XSETBUFFER (last_thing_searched, current_buffer); |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
359 |
603 | 360 return val; |
361 } | |
362 | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
363 DEFUN ("looking-at", Flooking_at, Slooking_at, 1, 1, 0, |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
364 doc: /* Return t if text after point matches regular expression REGEXP. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
365 This function modifies the match data that `match-beginning', |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
366 `match-end' and `match-data' access; save and restore the match |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
367 data if you want to preserve them. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
368 (regexp) |
11213
d0811ba886f8
(Flooking_at, Fposix_looking_at): Change arg name.
Richard M. Stallman <rms@gnu.org>
parents:
10250
diff
changeset
|
369 Lisp_Object regexp; |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
370 { |
11213
d0811ba886f8
(Flooking_at, Fposix_looking_at): Change arg name.
Richard M. Stallman <rms@gnu.org>
parents:
10250
diff
changeset
|
371 return looking_at_1 (regexp, 0); |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
372 } |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
373 |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
374 DEFUN ("posix-looking-at", Fposix_looking_at, Sposix_looking_at, 1, 1, 0, |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
375 doc: /* Return t if text after point matches regular expression REGEXP. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
376 Find the longest match, in accord with Posix regular expression rules. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
377 This function modifies the match data that `match-beginning', |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
378 `match-end' and `match-data' access; save and restore the match |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
379 data if you want to preserve them. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
380 (regexp) |
11213
d0811ba886f8
(Flooking_at, Fposix_looking_at): Change arg name.
Richard M. Stallman <rms@gnu.org>
parents:
10250
diff
changeset
|
381 Lisp_Object regexp; |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
382 { |
11213
d0811ba886f8
(Flooking_at, Fposix_looking_at): Change arg name.
Richard M. Stallman <rms@gnu.org>
parents:
10250
diff
changeset
|
383 return looking_at_1 (regexp, 1); |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
384 } |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
385 |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
386 static Lisp_Object |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
387 string_match_1 (regexp, string, start, posix) |
603 | 388 Lisp_Object regexp, string, start; |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
389 int posix; |
603 | 390 { |
391 int val; | |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
392 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
|
393 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
|
394 int i; |
603 | 395 |
10032
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
396 if (running_asynch_code) |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
397 save_search_regs (); |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
398 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40269
diff
changeset
|
399 CHECK_STRING (regexp); |
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40269
diff
changeset
|
400 CHECK_STRING (string); |
603 | 401 |
402 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
|
403 pos = 0, pos_byte = 0; |
603 | 404 else |
405 { | |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
406 int len = SCHARS (string); |
603 | 407 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40269
diff
changeset
|
408 CHECK_NUMBER (start); |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
409 pos = XINT (start); |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
410 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
|
411 pos = len + pos; |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
412 else if (0 > pos || pos > len) |
603 | 413 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
|
414 pos_byte = string_char_to_byte (string, pos); |
603 | 415 } |
416 | |
72725
ef0421dfce16
(looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents:
71987
diff
changeset
|
417 /* This is so set_image_of_range_1 in regex.c can find the EQV table. */ |
ef0421dfce16
(looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents:
71987
diff
changeset
|
418 XCHAR_TABLE (current_buffer->case_canon_table)->extras[2] |
ef0421dfce16
(looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents:
71987
diff
changeset
|
419 = current_buffer->case_eqv_table; |
ef0421dfce16
(looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents:
71987
diff
changeset
|
420 |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
421 bufp = compile_pattern (regexp, |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
422 (NILP (Vinhibit_changing_match_data) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
423 ? &search_regs : NULL), |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
424 (!NILP (current_buffer->case_fold_search) |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
425 ? current_buffer->case_canon_table : Qnil), |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
426 posix, |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
427 STRING_MULTIBYTE (string)); |
603 | 428 immediate_quit = 1; |
17463
bb9ae80d22e2
(looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents:
17284
diff
changeset
|
429 re_match_object = string; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
430 |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
431 val = re_search (bufp, (char *) SDATA (string), |
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
432 SBYTES (string), pos_byte, |
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
433 SBYTES (string) - pos_byte, |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
434 (NILP (Vinhibit_changing_match_data) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
435 ? &search_regs : NULL)); |
603 | 436 immediate_quit = 0; |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
437 |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
438 /* Set last_thing_searched only when match data is changed. */ |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
439 if (NILP (Vinhibit_changing_match_data)) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
440 last_thing_searched = Qt; |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
441 |
603 | 442 if (val == -2) |
443 matcher_overflow (); | |
444 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
|
445 |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
446 if (NILP (Vinhibit_changing_match_data)) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
447 for (i = 0; i < search_regs.num_regs; i++) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
448 if (search_regs.start[i] >= 0) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
449 { |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
450 search_regs.start[i] |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
451 = string_byte_to_char (string, search_regs.start[i]); |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
452 search_regs.end[i] |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
453 = string_byte_to_char (string, search_regs.end[i]); |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
454 } |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
455 |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
456 return make_number (string_byte_to_char (string, val)); |
603 | 457 } |
842 | 458 |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
459 DEFUN ("string-match", Fstring_match, Sstring_match, 2, 3, 0, |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
460 doc: /* Return index of start of first match for REGEXP in STRING, or nil. |
66200 | 461 Matching ignores case if `case-fold-search' is non-nil. |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
462 If third arg START is non-nil, start search at that index in STRING. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
463 For index of first char beyond the match, do (match-end 0). |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
464 `match-end' and `match-beginning' also give indices of substrings |
48528
467b0e57d985
(Fstring_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47692
diff
changeset
|
465 matched by parenthesis constructs in the pattern. |
467b0e57d985
(Fstring_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47692
diff
changeset
|
466 |
467b0e57d985
(Fstring_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47692
diff
changeset
|
467 You can use the function `match-string' to extract the substrings |
467b0e57d985
(Fstring_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47692
diff
changeset
|
468 matched by the parenthesis constructions in REGEXP. */) |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
469 (regexp, string, start) |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
470 Lisp_Object regexp, string, start; |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
471 { |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
472 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
|
473 } |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
474 |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
475 DEFUN ("posix-string-match", Fposix_string_match, Sposix_string_match, 2, 3, 0, |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
476 doc: /* Return index of start of first match for REGEXP in STRING, or nil. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
477 Find the longest match, in accord with Posix regular expression rules. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
478 Case is ignored if `case-fold-search' is non-nil in the current buffer. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
479 If third arg START is non-nil, start search at that index in STRING. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
480 For index of first char beyond the match, do (match-end 0). |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
481 `match-end' and `match-beginning' also give indices of substrings |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
482 matched by parenthesis constructs in the pattern. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
483 (regexp, string, start) |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
484 Lisp_Object regexp, string, start; |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
485 { |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
486 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
|
487 } |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
488 |
842 | 489 /* Match REGEXP against STRING, searching all of STRING, |
490 and return the index of the match, or negative on failure. | |
491 This does not clobber the match data. */ | |
492 | |
493 int | |
494 fast_string_match (regexp, string) | |
495 Lisp_Object regexp, string; | |
496 { | |
497 int val; | |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
498 struct re_pattern_buffer *bufp; |
842 | 499 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
500 bufp = compile_pattern (regexp, 0, Qnil, |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
501 0, STRING_MULTIBYTE (string)); |
842 | 502 immediate_quit = 1; |
17463
bb9ae80d22e2
(looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents:
17284
diff
changeset
|
503 re_match_object = string; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
504 |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
505 val = re_search (bufp, (char *) SDATA (string), |
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
506 SBYTES (string), 0, |
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
507 SBYTES (string), 0); |
842 | 508 immediate_quit = 0; |
509 return val; | |
510 } | |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
511 |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
512 /* 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
|
513 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
|
514 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
|
515 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
|
516 |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
517 extern Lisp_Object Vascii_downcase_table; |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
518 |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
519 int |
18193
4e4c8edb56da
(fast_c_string_match_ignore_case):
Richard M. Stallman <rms@gnu.org>
parents:
18124
diff
changeset
|
520 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
|
521 Lisp_Object regexp; |
46474
e01b3a5fd791
(fast_c_string_match_ignore_case): String pointer args
Ken Raeburn <raeburn@raeburn.org>
parents:
46444
diff
changeset
|
522 const char *string; |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
523 { |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
524 int val; |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
525 struct re_pattern_buffer *bufp; |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
526 int len = strlen (string); |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
527 |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
528 regexp = string_make_unibyte (regexp); |
18193
4e4c8edb56da
(fast_c_string_match_ignore_case):
Richard M. Stallman <rms@gnu.org>
parents:
18124
diff
changeset
|
529 re_match_object = Qt; |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
530 bufp = compile_pattern (regexp, 0, |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
531 Vascii_canon_table, 0, |
20671
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
532 0); |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
533 immediate_quit = 1; |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
534 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
|
535 immediate_quit = 0; |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
536 return val; |
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
537 } |
57572
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
538 |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
539 /* Like fast_string_match but ignore case. */ |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
540 |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
541 int |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
542 fast_string_match_ignore_case (regexp, string) |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
543 Lisp_Object regexp, string; |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
544 { |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
545 int val; |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
546 struct re_pattern_buffer *bufp; |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
547 |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
548 bufp = compile_pattern (regexp, 0, Vascii_canon_table, |
57572
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
549 0, STRING_MULTIBYTE (string)); |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
550 immediate_quit = 1; |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
551 re_match_object = string; |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
552 |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
553 val = re_search (bufp, (char *) SDATA (string), |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
554 SBYTES (string), 0, |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
555 SBYTES (string), 0); |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
556 immediate_quit = 0; |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
557 return val; |
d226830a814e
(fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents:
56429
diff
changeset
|
558 } |
603 | 559 |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
560 /* 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
|
561 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
562 /* 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
|
563 Otherwise, make sure it's off. |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
564 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
|
565 state of a buffer-local variable. */ |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
566 static void |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
567 newline_cache_on_off (buf) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
568 struct buffer *buf; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
569 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
570 if (NILP (buf->cache_long_line_scans)) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
571 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
572 /* It should be off. */ |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
573 if (buf->newline_cache) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
574 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
575 free_region_cache (buf->newline_cache); |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
576 buf->newline_cache = 0; |
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 else |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
580 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
581 /* It should be on. */ |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
582 if (buf->newline_cache == 0) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
583 buf->newline_cache = new_region_cache (); |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
584 } |
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 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
588 /* 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
|
589 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
590 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
|
591 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
|
592 END must be <= START. |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
593 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
|
594 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
595 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
|
596 direction indicated by COUNT. |
648 | 597 |
598 If we find COUNT instances, set *SHORTAGE to zero, and return the | |
57735 | 599 position past the COUNTth match. Note that for reverse motion |
1413 | 600 this is not the same as the usual convention for Emacs motion commands. |
648 | 601 |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
602 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
|
603 to the number of TARGETs left unfound, and return END. |
648 | 604 |
5756
a54c236b43c6
(scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents:
5556
diff
changeset
|
605 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
|
606 except when inside redisplay. */ |
a54c236b43c6
(scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents:
5556
diff
changeset
|
607 |
21514 | 608 int |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
609 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
|
610 register int target; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
611 int start, end; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
612 int count; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
613 int *shortage; |
5756
a54c236b43c6
(scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents:
5556
diff
changeset
|
614 int allow_quit; |
603 | 615 { |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
616 struct region_cache *newline_cache; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
617 int direction; |
648 | 618 |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
619 if (count > 0) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
620 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
621 direction = 1; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
622 if (! end) end = ZV; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
623 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
624 else |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
625 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
626 direction = -1; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
627 if (! end) end = BEGV; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
628 } |
648 | 629 |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
630 newline_cache_on_off (current_buffer); |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
631 newline_cache = current_buffer->newline_cache; |
603 | 632 |
633 if (shortage != 0) | |
634 *shortage = 0; | |
635 | |
5756
a54c236b43c6
(scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents:
5556
diff
changeset
|
636 immediate_quit = allow_quit; |
603 | 637 |
648 | 638 if (count > 0) |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
639 while (start != end) |
603 | 640 { |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
641 /* 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
|
642 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
|
643 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
|
644 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
|
645 examine. */ |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
646 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
|
647 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
|
648 int tem; |
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 /* 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
|
651 to see where we can avoid some scanning. */ |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
652 if (target == '\n' && newline_cache) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
653 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
654 int next_change; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
655 immediate_quit = 0; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
656 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
|
657 (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
|
658 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
|
659 immediate_quit = allow_quit; |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
660 |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
661 /* 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
|
662 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
|
663 start_byte = ceiling_byte; |
9410
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 /* 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
|
666 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
|
667 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
|
668 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
669 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
670 /* 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
|
671 bytes. BUFFER_CEILING_OF returns the last character |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
672 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
|
673 position after that. */ |
21457
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
674 tem = BUFFER_CEILING_OF (start_byte); |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
675 ceiling_byte = min (tem, ceiling_byte); |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
676 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
677 { |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
678 /* 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
|
679 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
|
680 = 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
|
681 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
|
682 = BYTE_POS_ADDR (start_byte); |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
683 unsigned char *base = cursor; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
684 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
685 while (cursor < ceiling_addr) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
686 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
687 unsigned char *scan_start = cursor; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
688 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
689 /* The dumb loop. */ |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
690 while (*cursor != target && ++cursor < ceiling_addr) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
691 ; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
692 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
693 /* 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
|
694 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
|
695 if (target == '\n' && newline_cache) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
696 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
|
697 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
|
698 start_byte + cursor - base); |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
699 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
700 /* Did we find the target character? */ |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
701 if (cursor < ceiling_addr) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
702 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
703 if (--count == 0) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
704 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
705 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
|
706 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
|
707 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
708 cursor++; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
709 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
710 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
711 |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
712 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
|
713 } |
603 | 714 } |
715 else | |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
716 while (start > end) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
717 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
718 /* 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
|
719 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
|
720 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
|
721 int tem; |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
722 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
723 /* Consult the newline cache, if appropriate. */ |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
724 if (target == '\n' && newline_cache) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
725 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
726 int next_change; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
727 immediate_quit = 0; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
728 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
|
729 (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
|
730 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
|
731 immediate_quit = allow_quit; |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
732 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
733 /* 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
|
734 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
|
735 start_byte = ceiling_byte + 1; |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
736 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
737 /* 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
|
738 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
|
739 ceiling_byte = max (next_change, ceiling_byte); |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
740 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
741 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
742 /* Stop scanning before the gap. */ |
21457
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
743 tem = BUFFER_FLOOR_OF (start_byte - 1); |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
744 ceiling_byte = max (tem, ceiling_byte); |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
745 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
746 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
747 /* 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
|
748 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
|
749 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
|
750 unsigned char *base = cursor; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
751 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
752 while (cursor >= ceiling_addr) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
753 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
754 unsigned char *scan_start = cursor; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
755 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
756 while (*cursor != target && --cursor >= ceiling_addr) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
757 ; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
758 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
759 /* 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
|
760 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
|
761 if (target == '\n' && newline_cache) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
762 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
|
763 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
|
764 start_byte + scan_start - base); |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
765 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
766 /* Did we find the target character? */ |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
767 if (cursor >= ceiling_addr) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
768 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
769 if (++count >= 0) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
770 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
771 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
|
772 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
|
773 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
774 cursor--; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
775 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
776 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
777 |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
778 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
|
779 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
780 } |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
781 |
603 | 782 immediate_quit = 0; |
783 if (shortage != 0) | |
648 | 784 *shortage = count * direction; |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
785 return start; |
603 | 786 } |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
787 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
788 /* 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
|
789 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
|
790 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
|
791 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
792 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
|
793 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
794 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
|
795 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
|
796 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
797 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
|
798 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
|
799 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
|
800 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
|
801 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
802 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
|
803 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
|
804 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
805 int |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
806 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
|
807 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
|
808 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
|
809 register int count; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
810 int allow_quit; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
811 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
812 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
|
813 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
814 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
|
815 unsigned char *base; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
816 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
817 register int ceiling; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
818 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
|
819 |
20547
07053199a368
(scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents:
20545
diff
changeset
|
820 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
|
821 |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
822 /* 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
|
823 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
|
824 |
20547
07053199a368
(scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents:
20545
diff
changeset
|
825 if (allow_quit) |
07053199a368
(scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents:
20545
diff
changeset
|
826 immediate_quit++; |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
827 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
828 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
|
829 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
830 if (count > 0) |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
831 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
832 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
|
833 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
834 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
|
835 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
|
836 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
|
837 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
|
838 while (1) |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
839 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
840 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
|
841 ; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
842 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
843 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
|
844 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
845 if (--count == 0) |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
846 { |
20547
07053199a368
(scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents:
20545
diff
changeset
|
847 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
|
848 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
|
849 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
|
850 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
|
851 return 0; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
852 } |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
853 else |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
854 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
|
855 break; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
856 } |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
857 else |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
858 break; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
859 } |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
860 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
|
861 } |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
862 } |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
863 else |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
864 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
865 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
|
866 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
867 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
|
868 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
|
869 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
|
870 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
|
871 while (1) |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
872 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
873 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
|
874 ; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
875 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
876 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
|
877 { |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
878 if (++count == 0) |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
879 { |
20547
07053199a368
(scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents:
20545
diff
changeset
|
880 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
|
881 /* 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
|
882 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
|
883 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
|
884 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
|
885 return 0; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
886 } |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
887 } |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
888 else |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
889 break; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
890 } |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
891 /* 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
|
892 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
|
893 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
|
894 } |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
895 } |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
896 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
897 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
|
898 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
|
899 |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
900 return count * direction; |
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
901 } |
603 | 902 |
903 int | |
7891
7d8e0f338e4a
(find_next_newline_no_quit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
7856
diff
changeset
|
904 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
|
905 register int from, cnt; |
7d8e0f338e4a
(find_next_newline_no_quit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
7856
diff
changeset
|
906 { |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
907 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
|
908 } |
7d8e0f338e4a
(find_next_newline_no_quit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
7856
diff
changeset
|
909 |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
910 /* 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
|
911 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
|
912 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
|
913 |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
914 int |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
915 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
|
916 int from, to, cnt; |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
917 { |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
918 int shortage; |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
919 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
|
920 |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
921 if (shortage == 0) |
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
922 pos--; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
923 |
9410
8598c3d6f2f0
* search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents:
9319
diff
changeset
|
924 return pos; |
603 | 925 } |
926 | |
927 /* Subroutines of Lisp buffer search functions. */ | |
928 | |
929 static Lisp_Object | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
930 search_command (string, bound, noerror, count, direction, RE, posix) |
603 | 931 Lisp_Object string, bound, noerror, count; |
932 int direction; | |
933 int RE; | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
934 int posix; |
603 | 935 { |
936 register int np; | |
20824
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
937 int lim, lim_byte; |
603 | 938 int n = direction; |
939 | |
940 if (!NILP (count)) | |
941 { | |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40269
diff
changeset
|
942 CHECK_NUMBER (count); |
603 | 943 n *= XINT (count); |
944 } | |
945 | |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40269
diff
changeset
|
946 CHECK_STRING (string); |
603 | 947 if (NILP (bound)) |
20824
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
948 { |
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
949 if (n > 0) |
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
950 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
|
951 else |
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
952 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
|
953 } |
603 | 954 else |
955 { | |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40269
diff
changeset
|
956 CHECK_NUMBER_COERCE_MARKER (bound); |
603 | 957 lim = XINT (bound); |
16039
855c8d8ba0f0
Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents:
15667
diff
changeset
|
958 if (n > 0 ? lim < PT : lim > PT) |
603 | 959 error ("Invalid search bound (wrong side of point)"); |
960 if (lim > ZV) | |
20824
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
961 lim = ZV, lim_byte = ZV_BYTE; |
20924
eda7e44ef9d9
(search_command): Check LIM in valid range
Karl Heuer <kwzh@gnu.org>
parents:
20898
diff
changeset
|
962 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
|
963 lim = BEGV, lim_byte = BEGV_BYTE; |
20924
eda7e44ef9d9
(search_command): Check LIM in valid range
Karl Heuer <kwzh@gnu.org>
parents:
20898
diff
changeset
|
964 else |
eda7e44ef9d9
(search_command): Check LIM in valid range
Karl Heuer <kwzh@gnu.org>
parents:
20898
diff
changeset
|
965 lim_byte = CHAR_TO_BYTE (lim); |
603 | 966 } |
967 | |
72725
ef0421dfce16
(looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents:
71987
diff
changeset
|
968 /* This is so set_image_of_range_1 in regex.c can find the EQV table. */ |
ef0421dfce16
(looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents:
71987
diff
changeset
|
969 XCHAR_TABLE (current_buffer->case_canon_table)->extras[2] |
ef0421dfce16
(looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents:
71987
diff
changeset
|
970 = current_buffer->case_eqv_table; |
ef0421dfce16
(looking_at_1, string_match_1, search_command):
Richard M. Stallman <rms@gnu.org>
parents:
71987
diff
changeset
|
971 |
20824
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
972 np = search_buffer (string, PT, PT_BYTE, lim, lim_byte, n, RE, |
603 | 973 (!NILP (current_buffer->case_fold_search) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
974 ? current_buffer->case_canon_table |
20875
4fac9830041a
(search_command): Fix call to search_buffer.
Richard M. Stallman <rms@gnu.org>
parents:
20869
diff
changeset
|
975 : Qnil), |
603 | 976 (!NILP (current_buffer->case_fold_search) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
977 ? current_buffer->case_eqv_table |
20875
4fac9830041a
(search_command): Fix call to search_buffer.
Richard M. Stallman <rms@gnu.org>
parents:
20869
diff
changeset
|
978 : Qnil), |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
979 posix); |
603 | 980 if (np <= 0) |
981 { | |
982 if (NILP (noerror)) | |
71987
6dd00de34fff
(compile_pattern_1): Use xsignal1.
Kim F. Storm <storm@cua.dk>
parents:
71841
diff
changeset
|
983 xsignal1 (Qsearch_failed, string); |
6dd00de34fff
(compile_pattern_1): Use xsignal1.
Kim F. Storm <storm@cua.dk>
parents:
71841
diff
changeset
|
984 |
603 | 985 if (!EQ (noerror, Qt)) |
986 { | |
987 if (lim < BEGV || lim > ZV) | |
988 abort (); | |
20824
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
989 SET_PT_BOTH (lim, lim_byte); |
1878
1c26d0049d4f
(search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents:
1877
diff
changeset
|
990 return Qnil; |
1c26d0049d4f
(search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents:
1877
diff
changeset
|
991 #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
|
992 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
|
993 np = lim; |
1878
1c26d0049d4f
(search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents:
1877
diff
changeset
|
994 #endif |
603 | 995 } |
1877
7786f61ec635
(search_command): When moving to LIM on failure, return LIM.
Richard M. Stallman <rms@gnu.org>
parents:
1684
diff
changeset
|
996 else |
7786f61ec635
(search_command): When moving to LIM on failure, return LIM.
Richard M. Stallman <rms@gnu.org>
parents:
1684
diff
changeset
|
997 return Qnil; |
603 | 998 } |
999 | |
1000 if (np < BEGV || np > ZV) | |
1001 abort (); | |
1002 | |
1003 SET_PT (np); | |
1004 | |
1005 return make_number (np); | |
1006 } | |
1007 | |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
1008 /* 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
|
1009 |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1010 static int |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1011 trivial_regexp_p (regexp) |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1012 Lisp_Object regexp; |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1013 { |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
1014 int len = SBYTES (regexp); |
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
1015 unsigned char *s = SDATA (regexp); |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1016 while (--len >= 0) |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1017 { |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1018 switch (*s++) |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1019 { |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1020 case '.': case '*': case '+': case '?': case '[': case '^': case '$': |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1021 return 0; |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1022 case '\\': |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1023 if (--len < 0) |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1024 return 0; |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1025 switch (*s++) |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1026 { |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1027 case '|': case '(': case ')': case '`': case '\'': case 'b': |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1028 case 'B': case '<': case '>': case 'w': case 'W': case 's': |
55689
f4a937a898f4
(trivial_regexp_p): \_ is no longer a trivial regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53719
diff
changeset
|
1029 case 'S': case '=': case '{': case '}': case '_': |
17053
df904355f033
Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents:
16880
diff
changeset
|
1030 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
|
1031 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
|
1032 case '6': case '7': case '8': case '9': |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1033 return 0; |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1034 } |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1035 } |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1036 } |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1037 return 1; |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1038 } |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1039 |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
1040 /* Search for the n'th occurrence of STRING in the current buffer, |
603 | 1041 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
|
1042 treating STRING as a literal string if RE is false or as |
603 | 1043 a regular expression if RE is true. |
1044 | |
1045 If N is positive, searching is forward and LIM must be greater than POS. | |
1046 If N is negative, searching is backward and LIM must be less than POS. | |
1047 | |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1048 Returns -x if x occurrences remain to be found (x > 0), |
603 | 1049 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
|
1050 (if searching backward) or the end (if searching forward). |
603 | 1051 |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
1052 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
|
1053 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
|
1054 |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1055 #define TRANSLATE(out, trt, d) \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1056 do \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1057 { \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1058 if (! NILP (trt)) \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1059 { \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1060 Lisp_Object temp; \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1061 temp = Faref (trt, make_number (d)); \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1062 if (INTEGERP (temp)) \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1063 out = XINT (temp); \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1064 else \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1065 out = d; \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1066 } \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1067 else \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1068 out = d; \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1069 } \ |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1070 while (0) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1071 |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1072 /* Only used in search_buffer, to record the end position of the match |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1073 when searching regexps and SEARCH_REGS should not be changed |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1074 (i.e. Vinhibit_changing_match_data is non-nil). */ |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1075 static struct re_registers search_regs_1; |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1076 |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
1077 static int |
20824
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
1078 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
|
1079 RE, trt, inverse_trt, posix) |
603 | 1080 Lisp_Object string; |
1081 int pos; | |
20824
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
1082 int pos_byte; |
603 | 1083 int lim; |
20824
97df0c6e753d
(search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents:
20792
diff
changeset
|
1084 int lim_byte; |
603 | 1085 int n; |
1086 int RE; | |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1087 Lisp_Object trt; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1088 Lisp_Object inverse_trt; |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
1089 int posix; |
603 | 1090 { |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
1091 int len = SCHARS (string); |
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
1092 int len_byte = SBYTES (string); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1093 register int i; |
603 | 1094 |
10032
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
1095 if (running_asynch_code) |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
1096 save_search_regs (); |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
1097 |
22082
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
1098 /* Searching 0 times means don't move. */ |
603 | 1099 /* Null string is found at starting position. */ |
22082
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
1100 if (len == 0 || n == 0) |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
1101 { |
35831
dc8b618615ea
(search_buffer): Call set_search_regs with a byte
Gerd Moellmann <gerd@gnu.org>
parents:
34966
diff
changeset
|
1102 set_search_regs (pos_byte, 0); |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
1103 return pos; |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
1104 } |
4299
7a2e1d7362c5
(search_buffer): If n is 0, just return POS.
Richard M. Stallman <rms@gnu.org>
parents:
3615
diff
changeset
|
1105 |
58348
623ffd21f0ff
(Vsearch_spaces_regexp):
Richard M. Stallman <rms@gnu.org>
parents:
58330
diff
changeset
|
1106 if (RE && !(trivial_regexp_p (string) && NILP (Vsearch_spaces_regexp))) |
603 | 1107 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1108 unsigned char *p1, *p2; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1109 int s1, s2; |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
1110 struct re_pattern_buffer *bufp; |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
1111 |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1112 bufp = compile_pattern (string, |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1113 (NILP (Vinhibit_changing_match_data) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1114 ? &search_regs : &search_regs_1), |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1115 trt, posix, |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1116 !NILP (current_buffer->enable_multibyte_characters)); |
603 | 1117 |
1118 immediate_quit = 1; /* Quit immediately if user types ^G, | |
1119 because letting this function finish | |
1120 can take too long. */ | |
1121 QUIT; /* Do a pending quit right away, | |
1122 to avoid paradoxical behavior */ | |
1123 /* Get pointers and sizes of the two strings | |
1124 that make up the visible portion of the buffer. */ | |
1125 | |
1126 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
|
1127 s1 = GPT_BYTE - BEGV_BYTE; |
603 | 1128 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
|
1129 s2 = ZV_BYTE - GPT_BYTE; |
603 | 1130 if (s1 < 0) |
1131 { | |
1132 p2 = p1; | |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
1133 s2 = ZV_BYTE - BEGV_BYTE; |
603 | 1134 s1 = 0; |
1135 } | |
1136 if (s2 < 0) | |
1137 { | |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
1138 s1 = ZV_BYTE - BEGV_BYTE; |
603 | 1139 s2 = 0; |
1140 } | |
17463
bb9ae80d22e2
(looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents:
17284
diff
changeset
|
1141 re_match_object = Qnil; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
1142 |
603 | 1143 while (n < 0) |
1144 { | |
2475
052bbdf1b817
(search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1145 int val; |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
1146 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
|
1147 pos_byte - BEGV_BYTE, lim_byte - pos_byte, |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1148 (NILP (Vinhibit_changing_match_data) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1149 ? &search_regs : &search_regs_1), |
2475
052bbdf1b817
(search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1150 /* 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
|
1151 pos_byte - BEGV_BYTE); |
603 | 1152 if (val == -2) |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1153 { |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1154 matcher_overflow (); |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1155 } |
603 | 1156 if (val >= 0) |
1157 { | |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1158 if (NILP (Vinhibit_changing_match_data)) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1159 { |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1160 pos_byte = search_regs.start[0] + BEGV_BYTE; |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1161 for (i = 0; i < search_regs.num_regs; i++) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1162 if (search_regs.start[i] >= 0) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1163 { |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1164 search_regs.start[i] |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1165 = BYTE_TO_CHAR (search_regs.start[i] + BEGV_BYTE); |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1166 search_regs.end[i] |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1167 = BYTE_TO_CHAR (search_regs.end[i] + BEGV_BYTE); |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1168 } |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1169 XSETBUFFER (last_thing_searched, current_buffer); |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1170 /* Set pos to the new position. */ |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1171 pos = search_regs.start[0]; |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1172 } |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1173 else |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1174 { |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1175 pos_byte = search_regs_1.start[0] + BEGV_BYTE; |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1176 /* Set pos to the new position. */ |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1177 pos = BYTE_TO_CHAR (search_regs_1.start[0] + BEGV_BYTE); |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1178 } |
603 | 1179 } |
1180 else | |
1181 { | |
1182 immediate_quit = 0; | |
1183 return (n); | |
1184 } | |
1185 n++; | |
1186 } | |
1187 while (n > 0) | |
1188 { | |
2475
052bbdf1b817
(search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1189 int val; |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
1190 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
|
1191 pos_byte - BEGV_BYTE, lim_byte - pos_byte, |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1192 (NILP (Vinhibit_changing_match_data) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1193 ? &search_regs : &search_regs_1), |
20792
f0aa5cc14e8a
(fast_string_match): Give re_search byte size of
Kenichi Handa <handa@m17n.org>
parents:
20706
diff
changeset
|
1194 lim_byte - BEGV_BYTE); |
603 | 1195 if (val == -2) |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1196 { |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1197 matcher_overflow (); |
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1198 } |
603 | 1199 if (val >= 0) |
1200 { | |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1201 if (NILP (Vinhibit_changing_match_data)) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1202 { |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1203 pos_byte = search_regs.end[0] + BEGV_BYTE; |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1204 for (i = 0; i < search_regs.num_regs; i++) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1205 if (search_regs.start[i] >= 0) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1206 { |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1207 search_regs.start[i] |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1208 = BYTE_TO_CHAR (search_regs.start[i] + BEGV_BYTE); |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1209 search_regs.end[i] |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1210 = BYTE_TO_CHAR (search_regs.end[i] + BEGV_BYTE); |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1211 } |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1212 XSETBUFFER (last_thing_searched, current_buffer); |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1213 pos = search_regs.end[0]; |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1214 } |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1215 else |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1216 { |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1217 pos_byte = search_regs_1.end[0] + BEGV_BYTE; |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1218 pos = BYTE_TO_CHAR (search_regs_1.end[0] + BEGV_BYTE); |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1219 } |
603 | 1220 } |
1221 else | |
1222 { | |
1223 immediate_quit = 0; | |
1224 return (0 - n); | |
1225 } | |
1226 n--; | |
1227 } | |
1228 immediate_quit = 0; | |
1229 return (pos); | |
1230 } | |
1231 else /* non-RE case */ | |
1232 { | |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1233 unsigned char *raw_pattern, *pat; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1234 int raw_pattern_size; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1235 int raw_pattern_size_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1236 unsigned char *patbuf; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1237 int multibyte = !NILP (current_buffer->enable_multibyte_characters); |
66751
e1496b6cebc3
(search_buffer): No need to initialize base_pat.
Kim F. Storm <storm@cua.dk>
parents:
66259
diff
changeset
|
1238 unsigned char *base_pat; |
66078
2fe97fc2ee41
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
64770
diff
changeset
|
1239 /* Set to positive if we find a non-ASCII char that need |
2fe97fc2ee41
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
64770
diff
changeset
|
1240 translation. Otherwise set to zero later. */ |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1241 int char_base = -1; |
23876
8d2f38338c81
(search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents:
23790
diff
changeset
|
1242 int boyer_moore_ok = 1; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1243 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1244 /* 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
|
1245 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
|
1246 find things right. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1247 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1248 if (multibyte == STRING_MULTIBYTE (string)) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1249 { |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
1250 raw_pattern = (unsigned char *) SDATA (string); |
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
1251 raw_pattern_size = SCHARS (string); |
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
1252 raw_pattern_size_byte = SBYTES (string); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1253 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1254 else if (multibyte) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1255 { |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
1256 raw_pattern_size = SCHARS (string); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1257 raw_pattern_size_byte |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
1258 = count_size_as_multibyte (SDATA (string), |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1259 raw_pattern_size); |
21915
8f1159b417c2
(search_buffer): Fix casts when assigning raw_pattern.
Richard M. Stallman <rms@gnu.org>
parents:
21887
diff
changeset
|
1260 raw_pattern = (unsigned char *) alloca (raw_pattern_size_byte + 1); |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
1261 copy_text (SDATA (string), raw_pattern, |
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
1262 SCHARS (string), 0, 1); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1263 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1264 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1265 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1266 /* Converting multibyte to single-byte. |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1267 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1268 ??? 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
|
1269 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
|
1270 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
|
1271 the chosen single-byte character set can possibly match. */ |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
1272 raw_pattern_size = SCHARS (string); |
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
1273 raw_pattern_size_byte = SCHARS (string); |
21915
8f1159b417c2
(search_buffer): Fix casts when assigning raw_pattern.
Richard M. Stallman <rms@gnu.org>
parents:
21887
diff
changeset
|
1274 raw_pattern = (unsigned char *) alloca (raw_pattern_size + 1); |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
1275 copy_text (SDATA (string), raw_pattern, |
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
1276 SBYTES (string), 1, 0); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1277 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1278 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1279 /* Copy and optionally translate the pattern. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1280 len = raw_pattern_size; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1281 len_byte = raw_pattern_size_byte; |
89130
e18339404909
(search_buffer): Fix case-fold-search of multibyte
Kenichi Handa <handa@m17n.org>
parents:
89062
diff
changeset
|
1282 patbuf = (unsigned char *) alloca (len * MAX_MULTIBYTE_LENGTH); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1283 pat = patbuf; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1284 base_pat = raw_pattern; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1285 if (multibyte) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1286 { |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1287 /* Fill patbuf by translated characters in STRING while |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1288 checking if we can use boyer-moore search. If TRT is |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1289 non-nil, we can use boyer-moore search only if TRT can be |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1290 represented by the byte array of 256 elements. For that, |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1291 all non-ASCII case-equivalents of all case-senstive |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1292 characters in STRING must belong to the same charset and |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1293 row. */ |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1294 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1295 while (--len >= 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1296 { |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1297 unsigned char str_base[MAX_MULTIBYTE_LENGTH], *str; |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1298 int c, translated, inverse; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1299 int in_charlen, charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1300 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1301 /* 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
|
1302 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
|
1303 just quotes the next character. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1304 if (RE && *base_pat == '\\') |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1305 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1306 len--; |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1307 raw_pattern_size--; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1308 len_byte--; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1309 base_pat++; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1310 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1311 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1312 c = STRING_CHAR_AND_LENGTH (base_pat, len_byte, in_charlen); |
23876
8d2f38338c81
(search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents:
23790
diff
changeset
|
1313 |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1314 if (NILP (trt)) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1315 { |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1316 str = base_pat; |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1317 charlen = in_charlen; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1318 } |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1319 else |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1320 { |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1321 /* Translate the character. */ |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1322 TRANSLATE (translated, trt, c); |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1323 charlen = CHAR_STRING (translated, str_base); |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1324 str = str_base; |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1325 |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1326 /* Check if C has any other case-equivalents. */ |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1327 TRANSLATE (inverse, inverse_trt, c); |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1328 /* If so, check if we can use boyer-moore. */ |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1329 if (c != inverse && boyer_moore_ok) |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1330 { |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1331 /* Check if all equivalents belong to the same |
90137
e465b832ab21
(search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents:
90136
diff
changeset
|
1332 group of characters. Note that the check of C |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1333 itself is done by the last iteration. */ |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1334 int this_char_base = -1; |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1335 |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1336 while (boyer_moore_ok) |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1337 { |
66078
2fe97fc2ee41
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
64770
diff
changeset
|
1338 if (ASCII_BYTE_P (inverse)) |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1339 { |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1340 if (this_char_base > 0) |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1341 boyer_moore_ok = 0; |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1342 else |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1343 { |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1344 this_char_base = 0; |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1345 if (char_base < 0) |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1346 char_base = this_char_base; |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1347 } |
66078
2fe97fc2ee41
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
64770
diff
changeset
|
1348 } |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1349 else if (CHAR_BYTE8_P (inverse)) |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1350 /* Boyer-moore search can't handle a |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1351 translation of an eight-bit |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1352 character. */ |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1353 boyer_moore_ok = 0; |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1354 else if (this_char_base < 0) |
66078
2fe97fc2ee41
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
64770
diff
changeset
|
1355 { |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1356 this_char_base = inverse & ~0x3F; |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1357 if (char_base < 0) |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1358 char_base = this_char_base; |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1359 else if (char_base > 0 |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1360 && this_char_base != char_base) |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1361 boyer_moore_ok = 0; |
66078
2fe97fc2ee41
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
64770
diff
changeset
|
1362 } |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1363 else if ((inverse & ~0x3F) != this_char_base) |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1364 boyer_moore_ok = 0; |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1365 if (c == inverse) |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1366 break; |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1367 TRANSLATE (inverse, inverse_trt, inverse); |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1368 } |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1369 } |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1370 } |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1371 if (char_base < 0) |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1372 char_base = 0; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1373 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1374 /* Store this character into the translated pattern. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1375 bcopy (str, pat, charlen); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1376 pat += charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1377 base_pat += in_charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1378 len_byte -= in_charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1379 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1380 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1381 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1382 { |
23876
8d2f38338c81
(search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents:
23790
diff
changeset
|
1383 /* Unibyte buffer. */ |
90137
e465b832ab21
(search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents:
90136
diff
changeset
|
1384 char_base = 0; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1385 while (--len >= 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1386 { |
23876
8d2f38338c81
(search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents:
23790
diff
changeset
|
1387 int c, translated; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1388 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1389 /* 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
|
1390 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
|
1391 just quotes the next character. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1392 if (RE && *base_pat == '\\') |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1393 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1394 len--; |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1395 raw_pattern_size--; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1396 base_pat++; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1397 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1398 c = *base_pat++; |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1399 TRANSLATE (translated, trt, c); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1400 *pat++ = translated; |
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 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1403 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1404 len_byte = pat - patbuf; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1405 len = raw_pattern_size; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1406 pat = base_pat = patbuf; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1407 |
23876
8d2f38338c81
(search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents:
23790
diff
changeset
|
1408 if (boyer_moore_ok) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1409 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
|
1410 pos, pos_byte, lim, lim_byte, |
90137
e465b832ab21
(search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents:
90136
diff
changeset
|
1411 char_base); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1412 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1413 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
|
1414 pos, pos_byte, lim, lim_byte); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1415 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1416 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1417 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1418 /* 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
|
1419 whose length is LEN/LEN_BYTE, |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1420 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
|
1421 TRT is the translation table. |
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 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
|
1424 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
|
1425 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1426 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
|
1427 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
|
1428 boyer_moore cannot work. */ |
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 static int |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1431 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
|
1432 int n; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1433 unsigned char *pat; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1434 int len, len_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1435 Lisp_Object trt; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1436 int pos, pos_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1437 int lim, lim_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1438 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1439 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
|
1440 int forward = n > 0; |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1441 /* Number of buffer bytes matched. Note that this may be different |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1442 from len_byte in a multibyte buffer. */ |
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1443 int match_byte; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1444 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1445 if (lim > pos && multibyte) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1446 while (n > 0) |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1447 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1448 while (1) |
20671
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
1449 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1450 /* Try matching at position POS. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1451 int this_pos = pos; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1452 int this_pos_byte = pos_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1453 int this_len = len; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1454 int this_len_byte = len_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1455 unsigned char *p = pat; |
90671
140d663891af
(simple_search): Fix sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90667
diff
changeset
|
1456 if (pos + len > lim || pos_byte + len_byte > lim_byte) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1457 goto stop; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1458 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1459 while (this_len > 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1460 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1461 int 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
|
1462 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
|
1463 |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1464 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
|
1465 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
|
1466 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
|
1467 buf_charlen); |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1468 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
|
1469 |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1470 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
|
1471 break; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1472 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1473 this_len_byte -= charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1474 this_len--; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1475 p += charlen; |
20671
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
1476 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1477 this_pos_byte += buf_charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1478 this_pos++; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1479 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1480 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1481 if (this_len == 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1482 { |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1483 match_byte = this_pos_byte - pos_byte; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1484 pos += len; |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1485 pos_byte += match_byte; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1486 break; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1487 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1488 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1489 INC_BOTH (pos, pos_byte); |
20671
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
1490 } |
be91d6130341
(compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents:
20588
diff
changeset
|
1491 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1492 n--; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1493 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1494 else if (lim > pos) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1495 while (n > 0) |
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 while (1) |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1498 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1499 /* Try matching at position POS. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1500 int this_pos = pos; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1501 int this_len = len; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1502 unsigned char *p = pat; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1503 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1504 if (pos + len > lim) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1505 goto stop; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1506 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1507 while (this_len > 0) |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1508 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1509 int pat_ch = *p++; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1510 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
|
1511 TRANSLATE (buf_ch, trt, buf_ch); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1512 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1513 if (buf_ch != pat_ch) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1514 break; |
21117
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1515 |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1516 this_len--; |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1517 this_pos++; |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1518 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1519 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1520 if (this_len == 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1521 { |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1522 match_byte = len; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1523 pos += len; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1524 break; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1525 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1526 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1527 pos++; |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1528 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1529 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1530 n--; |
8950
68ad2f08d735
(trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents:
8584
diff
changeset
|
1531 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1532 /* Backwards search. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1533 else if (lim < pos && multibyte) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1534 while (n < 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1535 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1536 while (1) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1537 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1538 /* Try matching at position POS. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1539 int this_pos = pos - len; |
90703
4df8b1be70dc
(simple_search): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
90671
diff
changeset
|
1540 int this_pos_byte; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1541 int this_len = len; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1542 int this_len_byte = len_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1543 unsigned char *p = pat; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1544 |
90703
4df8b1be70dc
(simple_search): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
90671
diff
changeset
|
1545 if (this_pos < lim || (pos_byte - len_byte) < lim_byte) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1546 goto stop; |
90703
4df8b1be70dc
(simple_search): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
90671
diff
changeset
|
1547 this_pos_byte = CHAR_TO_BYTE (this_pos); |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1548 match_byte = pos_byte - this_pos_byte; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1549 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1550 while (this_len > 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1551 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1552 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
|
1553 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
|
1554 |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1555 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
|
1556 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
|
1557 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
|
1558 buf_charlen); |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1559 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
|
1560 |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1561 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
|
1562 break; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1563 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1564 this_len_byte -= charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1565 this_len--; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1566 p += charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1567 this_pos_byte += buf_charlen; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1568 this_pos++; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1569 } |
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 if (this_len == 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1572 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1573 pos -= len; |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1574 pos_byte -= match_byte; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1575 break; |
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 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1578 DEC_BOTH (pos, pos_byte); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1579 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1580 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1581 n++; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1582 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1583 else if (lim < pos) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1584 while (n < 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1585 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1586 while (1) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1587 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1588 /* Try matching at position POS. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1589 int this_pos = pos - len; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1590 int this_len = len; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1591 unsigned char *p = pat; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1592 |
90671
140d663891af
(simple_search): Fix sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90667
diff
changeset
|
1593 if (this_pos < lim) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1594 goto stop; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1595 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1596 while (this_len > 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1597 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1598 int pat_ch = *p++; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1599 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
|
1600 TRANSLATE (buf_ch, trt, buf_ch); |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1601 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1602 if (buf_ch != pat_ch) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1603 break; |
21117
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1604 this_len--; |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1605 this_pos++; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1606 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1607 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1608 if (this_len == 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1609 { |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1610 match_byte = len; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1611 pos -= len; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1612 break; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1613 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1614 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1615 pos--; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1616 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1617 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1618 n++; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1619 } |
603 | 1620 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1621 stop: |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1622 if (n == 0) |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1623 { |
21117
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1624 if (forward) |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1625 set_search_regs ((multibyte ? pos_byte : pos) - match_byte, match_byte); |
21117
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1626 else |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1627 set_search_regs (multibyte ? pos_byte : pos, match_byte); |
20898
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1628 |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1629 return pos; |
f69969e35e78
(simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents:
20875
diff
changeset
|
1630 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1631 else if (n > 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1632 return -n; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1633 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1634 return n; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1635 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1636 |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1637 /* Do Boyer-Moore search N times for the string BASE_PAT, |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1638 whose length is LEN/LEN_BYTE, |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1639 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
|
1640 DIRECTION says which direction we search in. |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1641 TRT and INVERSE_TRT are translation tables. |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1642 Characters in PAT are already translated by TRT. |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1643 |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1644 This kind of search works if all the characters in BASE_PAT that |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1645 have nontrivial translation are the same aside from the last byte. |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1646 This makes it possible to translate just the last byte of a |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1647 character, and do so after just a simple test of the context. |
91005 | 1648 CHAR_BASE is nonzero if there is such a non-ASCII character. |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1649 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1650 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
|
1651 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1652 static int |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1653 boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt, |
90137
e465b832ab21
(search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents:
90136
diff
changeset
|
1654 pos, pos_byte, lim, lim_byte, char_base) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1655 int n; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1656 unsigned char *base_pat; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1657 int len, len_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1658 Lisp_Object trt; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1659 Lisp_Object inverse_trt; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1660 int pos, pos_byte; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1661 int lim, lim_byte; |
90137
e465b832ab21
(search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents:
90136
diff
changeset
|
1662 int char_base; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1663 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1664 int direction = ((n > 0) ? 1 : -1); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1665 register int dirlen; |
34966
23a62cf7d0eb
(shrink_regexp_cache): Remove unused variable `cpp'.
Eli Zaretskii <eliz@gnu.org>
parents:
33052
diff
changeset
|
1666 int infinity, limit, stride_for_teases = 0; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1667 register int *BM_tab; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1668 int *BM_tab_base; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
1669 register unsigned char *cursor, *p_limit; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1670 register int i, j; |
21945
bda081af77e7
(boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents:
21915
diff
changeset
|
1671 unsigned char *pat, *pat_end; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1672 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
|
1673 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1674 unsigned char simple_translate[0400]; |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1675 /* These are set to the preceding bytes of a byte to be translated |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1676 if char_base is nonzero. As the maximum byte length of a |
90137
e465b832ab21
(search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents:
90136
diff
changeset
|
1677 multibyte character is 5, we have to check at most four previous |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1678 bytes. */ |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1679 int translate_prev_byte1 = 0; |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1680 int translate_prev_byte2 = 0; |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1681 int translate_prev_byte3 = 0; |
90137
e465b832ab21
(search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents:
90136
diff
changeset
|
1682 int translate_prev_byte4 = 0; |
603 | 1683 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1684 BM_tab = (int *) alloca (0400 * sizeof (int)); |
84494
e6938db78161
(boyer_moore): Remove #ifdef C_ALLOCA block.
Glenn Morris <rgm@gnu.org>
parents:
82365
diff
changeset
|
1685 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1686 /* 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
|
1687 /* 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
|
1688 /* 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
|
1689 /* (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
|
1690 /* 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
|
1691 /* 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
|
1692 /* 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
|
1693 /* 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
|
1694 /* 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
|
1695 /* 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
|
1696 /* 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
|
1697 /* 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
|
1698 /* pattern. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1699 /* 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
|
1700 /* 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
|
1701 /* 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
|
1702 /* 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
|
1703 /* the stride goes past the end immediately) and failure to */ |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
1704 /* match (where you get nudged past the end one stride at a time). */ |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1705 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1706 /* 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
|
1707 /* 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
|
1708 /* 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
|
1709 /* 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
|
1710 /* instance of a character that matches it (per trt), or misses */ |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
1711 /* it entirely if there is none. */ |
20869
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 dirlen = len_byte * direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1714 infinity = dirlen - (lim_byte + pos_byte + len_byte + len_byte) * direction; |
21945
bda081af77e7
(boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents:
21915
diff
changeset
|
1715 |
bda081af77e7
(boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents:
21915
diff
changeset
|
1716 /* Record position after the end of the pattern. */ |
bda081af77e7
(boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents:
21915
diff
changeset
|
1717 pat_end = base_pat + len_byte; |
bda081af77e7
(boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents:
21915
diff
changeset
|
1718 /* BASE_PAT points to a character that we start scanning from. |
bda081af77e7
(boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents:
21915
diff
changeset
|
1719 It is the first character in a forward search, |
bda081af77e7
(boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents:
21915
diff
changeset
|
1720 the last character in a backward search. */ |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1721 if (direction < 0) |
21945
bda081af77e7
(boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents:
21915
diff
changeset
|
1722 base_pat = pat_end - 1; |
bda081af77e7
(boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents:
21915
diff
changeset
|
1723 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1724 BM_tab_base = BM_tab; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1725 BM_tab += 0400; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1726 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
|
1727 /* 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
|
1728 /* stride equal to the pattern length. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1729 while (BM_tab_base != BM_tab) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1730 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1731 *--BM_tab = j; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1732 *--BM_tab = j; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1733 *--BM_tab = j; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1734 *--BM_tab = j; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1735 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1736 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1737 /* 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
|
1738 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
|
1739 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
|
1740 bzero (simple_translate, sizeof simple_translate); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1741 for (i = 0; i < 0400; i++) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1742 simple_translate[i] = i; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1743 |
90137
e465b832ab21
(search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents:
90136
diff
changeset
|
1744 if (char_base) |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1745 { |
90137
e465b832ab21
(search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents:
90136
diff
changeset
|
1746 /* Setup translate_prev_byte1/2/3/4 from CHAR_BASE. Only a |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1747 byte following them are the target of translation. */ |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1748 unsigned char str[MAX_MULTIBYTE_LENGTH]; |
90137
e465b832ab21
(search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents:
90136
diff
changeset
|
1749 int len = CHAR_STRING (char_base, str); |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1750 |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1751 translate_prev_byte1 = str[len - 2]; |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1752 if (len > 2) |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1753 { |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1754 translate_prev_byte2 = str[len - 3]; |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1755 if (len > 3) |
90137
e465b832ab21
(search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents:
90136
diff
changeset
|
1756 { |
e465b832ab21
(search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents:
90136
diff
changeset
|
1757 translate_prev_byte3 = str[len - 4]; |
e465b832ab21
(search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents:
90136
diff
changeset
|
1758 if (len > 4) |
e465b832ab21
(search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents:
90136
diff
changeset
|
1759 translate_prev_byte4 = str[len - 5]; |
e465b832ab21
(search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents:
90136
diff
changeset
|
1760 } |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1761 } |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1762 } |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1763 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1764 i = 0; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1765 while (i != infinity) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1766 { |
21945
bda081af77e7
(boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents:
21915
diff
changeset
|
1767 unsigned char *ptr = base_pat + i; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1768 i += direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1769 if (i == dirlen) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1770 i = infinity; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1771 if (! NILP (trt)) |
603 | 1772 { |
61682
0015a00ccb5a
(boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
61189
diff
changeset
|
1773 /* If the byte currently looking at is the last of a |
0015a00ccb5a
(boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
61189
diff
changeset
|
1774 character to check case-equivalents, set CH to that |
0015a00ccb5a
(boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
61189
diff
changeset
|
1775 character. An ASCII character and a non-ASCII character |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1776 matching with CHAR_BASE are to be checked. */ |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1777 int ch = -1; |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1778 |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1779 if (ASCII_BYTE_P (*ptr) || ! multibyte) |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1780 ch = *ptr; |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1781 else if (char_base |
66259
d0daa61f9e6f
(boyer_moore): Surround the '||' part of expression in
Kenichi Handa <handa@m17n.org>
parents:
66200
diff
changeset
|
1782 && ((pat_end - ptr) == 1 || CHAR_HEAD_P (ptr[1]))) |
603 | 1783 { |
61682
0015a00ccb5a
(boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
61189
diff
changeset
|
1784 unsigned char *charstart = ptr - 1; |
0015a00ccb5a
(boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
61189
diff
changeset
|
1785 |
0015a00ccb5a
(boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
61189
diff
changeset
|
1786 while (! (CHAR_HEAD_P (*charstart))) |
0015a00ccb5a
(boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
61189
diff
changeset
|
1787 charstart--; |
0015a00ccb5a
(boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
61189
diff
changeset
|
1788 ch = STRING_CHAR (charstart, ptr - charstart + 1); |
90137
e465b832ab21
(search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents:
90136
diff
changeset
|
1789 if (char_base != (ch & ~0x3F)) |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1790 ch = -1; |
603 | 1791 } |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1792 |
91762
5a41bb37f0ee
(boyer_moore): Fix incorrect synching of the trunk and
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
1793 if (ch >= 0200) |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1794 j = (ch & 0x3F) | 0200; |
61682
0015a00ccb5a
(boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
61189
diff
changeset
|
1795 else |
0015a00ccb5a
(boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
61189
diff
changeset
|
1796 j = *ptr; |
0015a00ccb5a
(boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
61189
diff
changeset
|
1797 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1798 if (i == infinity) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1799 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
|
1800 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1801 BM_tab[j] = dirlen - i; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1802 /* A translation table is accompanied by its inverse -- see */ |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
1803 /* comment following downcase_table for details */ |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1804 if (ch >= 0) |
21117
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1805 { |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1806 int starting_ch = ch; |
61682
0015a00ccb5a
(boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
61189
diff
changeset
|
1807 int starting_j = j; |
0015a00ccb5a
(boyer_moore): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
61189
diff
changeset
|
1808 |
21117
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1809 while (1) |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1810 { |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1811 TRANSLATE (ch, inverse_trt, ch); |
91762
5a41bb37f0ee
(boyer_moore): Fix incorrect synching of the trunk and
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
1812 if (ch >= 0200) |
90245
7dd79b4dd8a5
(search_buffer): Give up BM search on case-fold-search
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
1813 j = (ch & 0x3F) | 0200; |
21117
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1814 else |
90137
e465b832ab21
(search_buffer): Fix the change for syncing with CVS
Kenichi Handa <handa@m17n.org>
parents:
90136
diff
changeset
|
1815 j = ch; |
21117
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1816 |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1817 /* 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
|
1818 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
|
1819 into STARTING_J. */ |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1820 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
|
1821 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
|
1822 break; |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1823 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
|
1824 } |
a88d2c555a06
(simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents:
20965
diff
changeset
|
1825 } |
603 | 1826 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1827 else |
603 | 1828 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1829 j = *ptr; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1830 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1831 if (i == infinity) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1832 stride_for_teases = BM_tab[j]; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1833 BM_tab[j] = dirlen - i; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1834 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1835 /* 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
|
1836 /* 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
|
1837 /* 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
|
1838 /* 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
|
1839 /* different. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1840 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1841 infinity = dirlen - infinity; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1842 pos_byte += dirlen - ((direction > 0) ? direction : 0); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1843 /* 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
|
1844 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
|
1845 while (n != 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1846 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1847 int tail_end; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1848 unsigned char *tail_end_ptr; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1849 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1850 /* 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
|
1851 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
|
1852 Using an explicit ?1:0 prevents this. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1853 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
|
1854 < 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1855 return (n * (0 - direction)); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1856 /* 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
|
1857 QUIT; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1858 pat = base_pat; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1859 limit = pos_byte - dirlen + direction; |
21457
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1860 if (direction > 0) |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1861 { |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1862 limit = BUFFER_CEILING_OF (limit); |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1863 /* 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
|
1864 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
|
1865 limit = min (limit, pos_byte + 20000); |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1866 limit = min (limit, lim_byte - 1); |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1867 } |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1868 else |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1869 { |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1870 limit = BUFFER_FLOOR_OF (limit); |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1871 /* 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
|
1872 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
|
1873 limit = max (limit, pos_byte - 20000); |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1874 limit = max (limit, lim_byte); |
8c6ea32aadfa
(min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents:
21248
diff
changeset
|
1875 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1876 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
|
1877 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
|
1878 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1879 if ((limit - pos_byte) * direction > 20) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1880 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1881 unsigned char *p2; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1882 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1883 p_limit = BYTE_POS_ADDR (limit); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1884 p2 = (cursor = BYTE_POS_ADDR (pos_byte)); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1885 /* 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
|
1886 while (1) /* use one cursor setting as long as i can */ |
603 | 1887 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1888 if (direction > 0) /* worth duplicating */ |
603 | 1889 { |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1890 /* Use signed comparison if appropriate |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1891 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
|
1892 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
|
1893 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
|
1894 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
|
1895 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
|
1896 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
|
1897 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
|
1898 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
|
1899 cursor += BM_tab[*cursor]; |
603 | 1900 else |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1901 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
|
1902 cursor += BM_tab[*cursor]; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1903 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1904 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1905 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1906 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
|
1907 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
|
1908 cursor += BM_tab[*cursor]; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1909 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1910 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
|
1911 cursor += BM_tab[*cursor]; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1912 } |
603 | 1913 /* 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
|
1914 /* 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
|
1915 /* 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
|
1916 /* 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
|
1917 /* 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
|
1918 /* otherwise try a character beyond that region */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1919 if ((cursor - p_limit) * direction <= len_byte) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1920 break; /* a small overrun is genuine */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1921 cursor -= infinity; /* large overrun = hit */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1922 i = dirlen - direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1923 if (! NILP (trt)) |
603 | 1924 { |
1925 while ((i -= direction) + direction != 0) | |
1926 { | |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1927 int ch; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1928 cursor -= direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1929 /* 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
|
1930 if (! multibyte |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1931 || ((cursor == tail_end_ptr |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1932 || CHAR_HEAD_P (cursor[1])) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1933 && (CHAR_HEAD_P (cursor[0]) |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1934 /* Check if this is the last byte of |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1935 a translable character. */ |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1936 || (translate_prev_byte1 == cursor[-1] |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1937 && (CHAR_HEAD_P (translate_prev_byte1) |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1938 || (translate_prev_byte2 == cursor[-2] |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1939 && (CHAR_HEAD_P (translate_prev_byte2) |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
1940 || (translate_prev_byte3 == cursor[-3])))))))) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1941 ch = simple_translate[*cursor]; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1942 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1943 ch = *cursor; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1944 if (pat[i] != ch) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1945 break; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1946 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1947 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1948 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1949 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1950 while ((i -= direction) + direction != 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1951 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1952 cursor -= direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1953 if (pat[i] != *cursor) |
603 | 1954 break; |
1955 } | |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1956 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1957 cursor += dirlen - i - direction; /* fix cursor */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1958 if (i + direction == 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1959 { |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1960 int position, start, end; |
708 | 1961 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1962 cursor -= direction; |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
1963 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1964 position = pos_byte + cursor - p2 + ((direction > 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1965 ? 1 - len_byte : 0); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1966 set_search_regs (position, len_byte); |
708 | 1967 |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1968 if (NILP (Vinhibit_changing_match_data)) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1969 { |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1970 start = search_regs.start[0]; |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1971 end = search_regs.end[0]; |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1972 } |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1973 else |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1974 /* If Vinhibit_changing_match_data is non-nil, |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1975 search_regs will not be changed. So let's |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1976 compute start and end here. */ |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1977 { |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1978 start = BYTE_TO_CHAR (position); |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1979 end = BYTE_TO_CHAR (position + len_byte); |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1980 } |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1981 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1982 if ((n -= direction) != 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1983 cursor += dirlen; /* to resume search */ |
603 | 1984 else |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
1985 return direction > 0 ? end : start; |
603 | 1986 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1987 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1988 cursor += stride_for_teases; /* <sigh> we lose - */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1989 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1990 pos_byte += cursor - p2; |
603 | 1991 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1992 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1993 /* 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
|
1994 /* way because it covers a discontinuity */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1995 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1996 limit = ((direction > 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1997 ? BUFFER_CEILING_OF (pos_byte - dirlen + 1) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1998 : BUFFER_FLOOR_OF (pos_byte - dirlen - 1)); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
1999 limit = ((direction > 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2000 ? min (limit + len_byte, lim_byte - 1) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2001 : max (limit - len_byte, lim_byte)); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2002 /* 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
|
2003 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
|
2004 while (1) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2005 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2006 /* 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
|
2007 /* 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
|
2008 /* (the reach is at most len + 21, and typically */ |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
2009 /* does not exceed len) */ |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2010 while ((limit - pos_byte) * direction >= 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2011 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
|
2012 /* 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
|
2013 /* end, a match or a phony match. */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2014 if ((pos_byte - limit) * direction <= len_byte) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2015 break; /* ran off the end */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2016 /* Found what might be a match. |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2017 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
|
2018 pos_byte -= infinity; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2019 i = dirlen - direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2020 while ((i -= direction) + direction != 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2021 { |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2022 int ch; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2023 unsigned char *ptr; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2024 pos_byte -= direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2025 ptr = BYTE_POS_ADDR (pos_byte); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2026 /* 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
|
2027 if (! multibyte |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2028 || ((ptr == tail_end_ptr |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2029 || CHAR_HEAD_P (ptr[1])) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2030 && (CHAR_HEAD_P (ptr[0]) |
61189
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
2031 /* Check if this is the last byte of a |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
2032 translable character. */ |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
2033 || (translate_prev_byte1 == ptr[-1] |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
2034 && (CHAR_HEAD_P (translate_prev_byte1) |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
2035 || (translate_prev_byte2 == ptr[-2] |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
2036 && (CHAR_HEAD_P (translate_prev_byte2) |
91ba6c641a60
(looking_at_1): Use current_buffer->case_canon_table,
Kenichi Handa <handa@m17n.org>
parents:
58567
diff
changeset
|
2037 || translate_prev_byte3 == ptr[-3]))))))) |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2038 ch = simple_translate[*ptr]; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2039 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2040 ch = *ptr; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2041 if (pat[i] != ch) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2042 break; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2043 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2044 /* 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
|
2045 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
|
2046 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
|
2047 pos_byte += dirlen - i- direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2048 if (i + direction == 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2049 { |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2050 int position, start, end; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2051 pos_byte -= direction; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2052 |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2053 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
|
2054 set_search_regs (position, len_byte); |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2055 |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2056 if (NILP (Vinhibit_changing_match_data)) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2057 { |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2058 start = search_regs.start[0]; |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2059 end = search_regs.end[0]; |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2060 } |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2061 else |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2062 /* If Vinhibit_changing_match_data is non-nil, |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2063 search_regs will not be changed. So let's |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2064 compute start and end here. */ |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2065 { |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2066 start = BYTE_TO_CHAR (position); |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2067 end = BYTE_TO_CHAR (position + len_byte); |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2068 } |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2069 |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2070 if ((n -= direction) != 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2071 pos_byte += dirlen; /* to resume search */ |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2072 else |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2073 return direction > 0 ? end : start; |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2074 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2075 else |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2076 pos_byte += stride_for_teases; |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2077 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2078 } |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2079 /* 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
|
2080 if ((lim_byte - pos_byte) * direction < 0) |
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2081 return ((0 - n) * direction); |
603 | 2082 } |
20869
c9f608f889b4
(boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents:
20824
diff
changeset
|
2083 return BYTE_TO_CHAR (pos_byte); |
603 | 2084 } |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
2085 |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
2086 /* Record beginning BEG_BYTE and end BEG_BYTE + NBYTES |
22082
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
2087 for the overall match just found in the current buffer. |
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
2088 Also clear out the match data for registers 1 and up. */ |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
2089 |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
2090 static void |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
2091 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
|
2092 int beg_byte, nbytes; |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
2093 { |
22082
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
2094 int i; |
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
2095 |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2096 if (!NILP (Vinhibit_changing_match_data)) |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2097 return; |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
2098 |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
2099 /* 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
|
2100 the match position. */ |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
2101 if (search_regs.num_regs == 0) |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
2102 { |
10250
422c3b96efda
(set_search_regs): Really set search_regs.start and .end.
Richard M. Stallman <rms@gnu.org>
parents:
10141
diff
changeset
|
2103 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
|
2104 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
|
2105 search_regs.num_regs = 2; |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
2106 } |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
2107 |
22082
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
2108 /* Clear out the other registers. */ |
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
2109 for (i = 1; i < search_regs.num_regs; i++) |
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
2110 { |
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
2111 search_regs.start[i] = -1; |
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
2112 search_regs.end[i] = -1; |
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
2113 } |
84bcdbc46d71
(search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
21988
diff
changeset
|
2114 |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
2115 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
|
2116 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
|
2117 XSETBUFFER (last_thing_searched, current_buffer); |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
2118 } |
603 | 2119 |
2120 /* Given a string of words separated by word delimiters, | |
2121 compute a regexp that matches those exact words | |
2122 separated by arbitrary punctuation. */ | |
2123 | |
2124 static Lisp_Object | |
2125 wordify (string) | |
2126 Lisp_Object string; | |
2127 { | |
2128 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
|
2129 register int i, i_byte, len, punct_count = 0, word_count = 0; |
603 | 2130 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
|
2131 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
|
2132 int adjust; |
603 | 2133 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40269
diff
changeset
|
2134 CHECK_STRING (string); |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
2135 p = SDATA (string); |
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
2136 len = SCHARS (string); |
603 | 2137 |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2138 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
|
2139 { |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2140 int c; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
2141 |
89062
be059fb97bac
(compile_pattern_1): Don't adjust the multibyteness of
Kenichi Handa <handa@m17n.org>
parents:
89028
diff
changeset
|
2142 FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte); |
603 | 2143 |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2144 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
|
2145 { |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2146 punct_count++; |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2147 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
|
2148 word_count++; |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2149 } |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2150 |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2151 prev_c = c; |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2152 } |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2153 |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2154 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
|
2155 word_count++; |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2156 if (!word_count) |
81279
326992131788
(wordify): Use empty_unibyte_string.
Juanma Barranquero <lekktu@gmail.com>
parents:
75227
diff
changeset
|
2157 return empty_unibyte_string; |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2158 |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2159 adjust = - punct_count + 5 * (word_count - 1) + 4; |
22640
929ad308aba6
(wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents:
22533
diff
changeset
|
2160 if (STRING_MULTIBYTE (string)) |
929ad308aba6
(wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents:
22533
diff
changeset
|
2161 val = make_uninit_multibyte_string (len + adjust, |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
2162 SBYTES (string) |
22640
929ad308aba6
(wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents:
22533
diff
changeset
|
2163 + adjust); |
929ad308aba6
(wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents:
22533
diff
changeset
|
2164 else |
929ad308aba6
(wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents:
22533
diff
changeset
|
2165 val = make_uninit_string (len + adjust); |
603 | 2166 |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
2167 o = SDATA (val); |
603 | 2168 *o++ = '\\'; |
2169 *o++ = 'b'; | |
21887
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2170 prev_c = 0; |
603 | 2171 |
21887
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2172 for (i = 0, i_byte = 0; i < len; ) |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2173 { |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2174 int c; |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2175 int i_byte_orig = i_byte; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
2176 |
89062
be059fb97bac
(compile_pattern_1): Don't adjust the multibyteness of
Kenichi Handa <handa@m17n.org>
parents:
89028
diff
changeset
|
2177 FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte); |
21887
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2178 |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2179 if (SYNTAX (c) == Sword) |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2180 { |
46432
a4697b0a338e
* search.c (wordify): Use SDATA.
Ken Raeburn <raeburn@raeburn.org>
parents:
46370
diff
changeset
|
2181 bcopy (SDATA (string) + i_byte_orig, o, |
21887
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2182 i_byte - i_byte_orig); |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2183 o += i_byte - i_byte_orig; |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2184 } |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2185 else if (i > 0 && SYNTAX (prev_c) == Sword && --word_count) |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2186 { |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2187 *o++ = '\\'; |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2188 *o++ = 'W'; |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2189 *o++ = '\\'; |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2190 *o++ = 'W'; |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2191 *o++ = '*'; |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2192 } |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2193 |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2194 prev_c = c; |
1c9f20274f76
(wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents:
21531
diff
changeset
|
2195 } |
603 | 2196 |
2197 *o++ = '\\'; | |
2198 *o++ = 'b'; | |
2199 | |
2200 return val; | |
2201 } | |
2202 | |
2203 DEFUN ("search-backward", Fsearch_backward, Ssearch_backward, 1, 4, | |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2204 "MSearch backward: ", |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2205 doc: /* Search backward from point for STRING. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2206 Set point to the beginning of the occurrence found, and return point. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2207 An optional second argument bounds the search; it is a buffer position. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2208 The match found must not extend before that position. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2209 Optional third argument, if t, means if fail just return nil (no error). |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2210 If not nil and not t, position at limit of search and return nil. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2211 Optional fourth argument is repeat count--search for successive occurrences. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2212 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2213 Search case-sensitivity is determined by the value of the variable |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2214 `case-fold-search', which see. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2215 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2216 See also the functions `match-beginning', `match-end' and `replace-match'. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2217 (string, bound, noerror, count) |
603 | 2218 Lisp_Object string, bound, noerror, count; |
2219 { | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2220 return search_command (string, bound, noerror, count, -1, 0, 0); |
603 | 2221 } |
2222 | |
19541
e7876a076881
(Fsearch_backward): Inherit the current input method on
Kenichi Handa <handa@m17n.org>
parents:
18762
diff
changeset
|
2223 DEFUN ("search-forward", Fsearch_forward, Ssearch_forward, 1, 4, "MSearch: ", |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2224 doc: /* Search forward from point for STRING. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2225 Set point to the end of the occurrence found, and return point. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2226 An optional second argument bounds the search; it is a buffer position. |
74917
898edc583814
(Fsearch_forward): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
74756
diff
changeset
|
2227 The match found must not extend after that position. A value of nil is |
74756
c751765838ca
(Fsearch_forward): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
74033
diff
changeset
|
2228 equivalent to (point-max). |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2229 Optional third argument, if t, means if fail just return nil (no error). |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2230 If not nil and not t, move to limit of search and return nil. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2231 Optional fourth argument is repeat count--search for successive occurrences. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2232 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2233 Search case-sensitivity is determined by the value of the variable |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2234 `case-fold-search', which see. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2235 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2236 See also the functions `match-beginning', `match-end' and `replace-match'. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2237 (string, bound, noerror, count) |
603 | 2238 Lisp_Object string, bound, noerror, count; |
2239 { | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2240 return search_command (string, bound, noerror, count, 1, 0, 0); |
603 | 2241 } |
2242 | |
2243 DEFUN ("word-search-backward", Fword_search_backward, Sword_search_backward, 1, 4, | |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2244 "sWord search backward: ", |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2245 doc: /* Search backward from point for STRING, ignoring differences in punctuation. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2246 Set point to the beginning of the occurrence found, and return point. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2247 An optional second argument bounds the search; it is a buffer position. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2248 The match found must not extend before that position. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2249 Optional third argument, if t, means if fail just return nil (no error). |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2250 If not nil and not t, move to limit of search and return nil. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2251 Optional fourth argument is repeat count--search for successive occurrences. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2252 (string, bound, noerror, count) |
603 | 2253 Lisp_Object string, bound, noerror, count; |
2254 { | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2255 return search_command (wordify (string), bound, noerror, count, -1, 1, 0); |
603 | 2256 } |
2257 | |
2258 DEFUN ("word-search-forward", Fword_search_forward, Sword_search_forward, 1, 4, | |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2259 "sWord search: ", |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2260 doc: /* Search forward from point for STRING, ignoring differences in punctuation. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2261 Set point to the end of the occurrence found, and return point. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2262 An optional second argument bounds the search; it is a buffer position. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2263 The match found must not extend after that position. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2264 Optional third argument, if t, means if fail just return nil (no error). |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2265 If not nil and not t, move to limit of search and return nil. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2266 Optional fourth argument is repeat count--search for successive occurrences. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2267 (string, bound, noerror, count) |
603 | 2268 Lisp_Object string, bound, noerror, count; |
2269 { | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2270 return search_command (wordify (string), bound, noerror, count, 1, 1, 0); |
603 | 2271 } |
2272 | |
2273 DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4, | |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2274 "sRE search backward: ", |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2275 doc: /* Search backward from point for match for regular expression REGEXP. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2276 Set point to the beginning of the match, and return point. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2277 The match found is the one starting last in the buffer |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2278 and yet ending before the origin of the search. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2279 An optional second argument bounds the search; it is a buffer position. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2280 The match found must start at or after that position. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2281 Optional third argument, if t, means if fail just return nil (no error). |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2282 If not nil and not t, move to limit of search and return nil. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2283 Optional fourth argument is repeat count--search for successive occurrences. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2284 See also the functions `match-beginning', `match-end', `match-string', |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2285 and `replace-match'. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2286 (regexp, bound, noerror, count) |
6297
b44907fd0ff0
(Fre_search_forward, Fre_search_backward): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
6196
diff
changeset
|
2287 Lisp_Object regexp, bound, noerror, count; |
603 | 2288 { |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2289 return search_command (regexp, bound, noerror, count, -1, 1, 0); |
603 | 2290 } |
2291 | |
2292 DEFUN ("re-search-forward", Fre_search_forward, Sre_search_forward, 1, 4, | |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2293 "sRE search: ", |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2294 doc: /* Search forward from point for regular expression REGEXP. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2295 Set point to the end of the occurrence found, and return point. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2296 An optional second argument bounds the search; it is a buffer position. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2297 The match found must not extend after that position. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2298 Optional third argument, if t, means if fail just return nil (no error). |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2299 If not nil and not t, move to limit of search and return nil. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2300 Optional fourth argument is repeat count--search for successive occurrences. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2301 See also the functions `match-beginning', `match-end', `match-string', |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2302 and `replace-match'. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2303 (regexp, bound, noerror, count) |
6297
b44907fd0ff0
(Fre_search_forward, Fre_search_backward): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
6196
diff
changeset
|
2304 Lisp_Object regexp, bound, noerror, count; |
603 | 2305 { |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2306 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
|
2307 } |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2308 |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2309 DEFUN ("posix-search-backward", Fposix_search_backward, Sposix_search_backward, 1, 4, |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2310 "sPosix search backward: ", |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2311 doc: /* Search backward from point for match for regular expression REGEXP. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2312 Find the longest match in accord with Posix regular expression rules. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2313 Set point to the beginning of the match, and return point. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2314 The match found is the one starting last in the buffer |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2315 and yet ending before the origin of the search. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2316 An optional second argument bounds the search; it is a buffer position. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2317 The match found must start at or after that position. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2318 Optional third argument, if t, means if fail just return nil (no error). |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2319 If not nil and not t, move to limit of search and return nil. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2320 Optional fourth argument is repeat count--search for successive occurrences. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2321 See also the functions `match-beginning', `match-end', `match-string', |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2322 and `replace-match'. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2323 (regexp, bound, noerror, count) |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2324 Lisp_Object regexp, bound, noerror, count; |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2325 { |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2326 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
|
2327 } |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2328 |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2329 DEFUN ("posix-search-forward", Fposix_search_forward, Sposix_search_forward, 1, 4, |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2330 "sPosix search: ", |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2331 doc: /* Search forward from point for regular expression REGEXP. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2332 Find the longest match in accord with Posix regular expression rules. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2333 Set point to the end of the occurrence found, and return point. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2334 An optional second argument bounds the search; it is a buffer position. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2335 The match found must not extend after that position. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2336 Optional third argument, if t, means if fail just return nil (no error). |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2337 If not nil and not t, move to limit of search and return nil. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2338 Optional fourth argument is repeat count--search for successive occurrences. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2339 See also the functions `match-beginning', `match-end', `match-string', |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2340 and `replace-match'. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2341 (regexp, bound, noerror, count) |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2342 Lisp_Object regexp, bound, noerror, count; |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2343 { |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
2344 return search_command (regexp, bound, noerror, count, 1, 1, 1); |
603 | 2345 } |
2346 | |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2347 DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 5, 0, |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2348 doc: /* Replace text matched by last search with NEWTEXT. |
45217
4383b69f181b
(Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
41389
diff
changeset
|
2349 Leave point at the end of the replacement text. |
4383b69f181b
(Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
41389
diff
changeset
|
2350 |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2351 If second arg FIXEDCASE is non-nil, do not alter case of replacement text. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2352 Otherwise maybe capitalize the whole text, or maybe just word initials, |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2353 based on the replaced text. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2354 If the replaced text has only capital letters |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2355 and has at least one multiletter word, convert NEWTEXT to all caps. |
45217
4383b69f181b
(Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
41389
diff
changeset
|
2356 Otherwise if all words are capitalized in the replaced text, |
4383b69f181b
(Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
41389
diff
changeset
|
2357 capitalize each word in NEWTEXT. |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2358 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2359 If third arg LITERAL is non-nil, insert NEWTEXT literally. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2360 Otherwise treat `\\' as special: |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2361 `\\&' in NEWTEXT means substitute original matched text. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2362 `\\N' means substitute what matched the Nth `\\(...\\)'. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2363 If Nth parens didn't match, substitute nothing. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2364 `\\\\' means insert one `\\'. |
45217
4383b69f181b
(Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
41389
diff
changeset
|
2365 Case conversion does not apply to these substitutions. |
4383b69f181b
(Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
41389
diff
changeset
|
2366 |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2367 FIXEDCASE and LITERAL are optional arguments. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2368 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2369 The optional fourth argument STRING can be a string to modify. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2370 This is meaningful when the previous match was done against STRING, |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2371 using `string-match'. When used this way, `replace-match' |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2372 creates and returns a new string made by copying STRING and replacing |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2373 the part of STRING that was matched. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2374 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2375 The optional fifth argument SUBEXP specifies a subexpression; |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2376 it says to replace just that subexpression with NEWTEXT, |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2377 rather than replacing the entire matched text. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2378 This is, in a vague sense, the inverse of using `\\N' in NEWTEXT; |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2379 `\\N' copies subexp N into NEWTEXT, but using N as SUBEXP puts |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2380 NEWTEXT in place of subexp N. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2381 This is useful only after a regular expression search or match, |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2382 since only regular expressions have distinguished subexpressions. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2383 (newtext, fixedcase, literal, string, subexp) |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2384 Lisp_Object newtext, fixedcase, literal, string, subexp; |
603 | 2385 { |
2386 enum { nochange, all_caps, cap_initial } case_action; | |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2387 register int pos, pos_byte; |
603 | 2388 int some_multiletter_word; |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
2389 int some_lowercase; |
7674
947d24fefd9e
(Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents:
7673
diff
changeset
|
2390 int some_uppercase; |
8526
2b7b23059f1b
(Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents:
7891
diff
changeset
|
2391 int some_nonuppercase_initial; |
603 | 2392 register int c, prevc; |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2393 int sub; |
18081
300068b4fcef
(Freplace_match): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
18077
diff
changeset
|
2394 int opoint, newpoint; |
603 | 2395 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40269
diff
changeset
|
2396 CHECK_STRING (newtext); |
603 | 2397 |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2398 if (! NILP (string)) |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40269
diff
changeset
|
2399 CHECK_STRING (string); |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2400 |
603 | 2401 case_action = nochange; /* We tried an initialization */ |
2402 /* but some C compilers blew it */ | |
621 | 2403 |
2404 if (search_regs.num_regs <= 0) | |
63702
6d4accecc80c
(Freplace_match): Follow error conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
63666
diff
changeset
|
2405 error ("`replace-match' called before any match found"); |
621 | 2406 |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2407 if (NILP (subexp)) |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2408 sub = 0; |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2409 else |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2410 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40269
diff
changeset
|
2411 CHECK_NUMBER (subexp); |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2412 sub = XINT (subexp); |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2413 if (sub < 0 || sub >= search_regs.num_regs) |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2414 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
|
2415 } |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2416 |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2417 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
|
2418 { |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2419 if (search_regs.start[sub] < BEGV |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2420 || search_regs.start[sub] > search_regs.end[sub] |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2421 || search_regs.end[sub] > ZV) |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2422 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
|
2423 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
|
2424 } |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2425 else |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2426 { |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2427 if (search_regs.start[sub] < 0 |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2428 || search_regs.start[sub] > search_regs.end[sub] |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
2429 || search_regs.end[sub] > SCHARS (string)) |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2430 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
|
2431 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
|
2432 } |
603 | 2433 |
2434 if (NILP (fixedcase)) | |
2435 { | |
2436 /* Decide how to casify by examining the matched text. */ | |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2437 int last; |
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2438 |
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2439 pos = search_regs.start[sub]; |
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2440 last = search_regs.end[sub]; |
603 | 2441 |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
2442 if (NILP (string)) |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2443 pos_byte = CHAR_TO_BYTE (pos); |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
2444 else |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2445 pos_byte = string_char_to_byte (string, pos); |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
2446 |
603 | 2447 prevc = '\n'; |
2448 case_action = all_caps; | |
2449 | |
2450 /* some_multiletter_word is set nonzero if any original word | |
2451 is more than one letter long. */ | |
2452 some_multiletter_word = 0; | |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
2453 some_lowercase = 0; |
8526
2b7b23059f1b
(Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents:
7891
diff
changeset
|
2454 some_nonuppercase_initial = 0; |
7674
947d24fefd9e
(Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents:
7673
diff
changeset
|
2455 some_uppercase = 0; |
603 | 2456 |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2457 while (pos < last) |
603 | 2458 { |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2459 if (NILP (string)) |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2460 { |
89062
be059fb97bac
(compile_pattern_1): Don't adjust the multibyteness of
Kenichi Handa <handa@m17n.org>
parents:
89028
diff
changeset
|
2461 c = FETCH_CHAR_AS_MULTIBYTE (pos_byte); |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2462 INC_BOTH (pos, pos_byte); |
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2463 } |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2464 else |
89062
be059fb97bac
(compile_pattern_1): Don't adjust the multibyteness of
Kenichi Handa <handa@m17n.org>
parents:
89028
diff
changeset
|
2465 FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, pos, pos_byte); |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2466 |
603 | 2467 if (LOWERCASEP (c)) |
2468 { | |
2469 /* Cannot be all caps if any original char is lower case */ | |
2470 | |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
2471 some_lowercase = 1; |
603 | 2472 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
|
2473 some_nonuppercase_initial = 1; |
603 | 2474 else |
2475 some_multiletter_word = 1; | |
2476 } | |
68200
5fc4d9faaa2f
(Freplace_match): Use UPPERCASEP instead of !NOCASEP.
Andreas Schwab <schwab@suse.de>
parents:
66751
diff
changeset
|
2477 else if (UPPERCASEP (c)) |
603 | 2478 { |
7674
947d24fefd9e
(Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents:
7673
diff
changeset
|
2479 some_uppercase = 1; |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
2480 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
|
2481 ; |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
2482 else |
603 | 2483 some_multiletter_word = 1; |
2484 } | |
8526
2b7b23059f1b
(Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents:
7891
diff
changeset
|
2485 else |
2b7b23059f1b
(Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents:
7891
diff
changeset
|
2486 { |
2b7b23059f1b
(Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents:
7891
diff
changeset
|
2487 /* 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
|
2488 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
|
2489 if (SYNTAX (prevc) != Sword) |
2b7b23059f1b
(Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents:
7891
diff
changeset
|
2490 some_nonuppercase_initial = 1; |
2b7b23059f1b
(Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents:
7891
diff
changeset
|
2491 } |
603 | 2492 |
2493 prevc = c; | |
2494 } | |
2495 | |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
2496 /* 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
|
2497 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
|
2498 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
|
2499 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
|
2500 /* 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
|
2501 else if (!some_nonuppercase_initial && some_multiletter_word) |
603 | 2502 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
|
2503 else if (!some_nonuppercase_initial && some_uppercase) |
7674
947d24fefd9e
(Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents:
7673
diff
changeset
|
2504 /* 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
|
2505 We'll assume the latter. */ |
947d24fefd9e
(Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents:
7673
diff
changeset
|
2506 case_action = all_caps; |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
2507 else |
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
2508 case_action = nochange; |
603 | 2509 } |
2510 | |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2511 /* 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
|
2512 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
|
2513 { |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2514 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
|
2515 |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2516 before = Fsubstring (string, make_number (0), |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2517 make_number (search_regs.start[sub])); |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2518 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
|
2519 |
17225
739e41eed8b6
(Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents:
17102
diff
changeset
|
2520 /* Substitute parts of the match into NEWTEXT |
739e41eed8b6
(Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents:
17102
diff
changeset
|
2521 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
|
2522 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
|
2523 { |
21988
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2524 int lastpos = 0; |
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2525 int lastpos_byte = 0; |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2526 /* 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
|
2527 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
|
2528 Lisp_Object middle; |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
2529 int length = SBYTES (newtext); |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2530 |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2531 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
|
2532 |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2533 for (pos_byte = 0, pos = 0; pos_byte < length;) |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2534 { |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2535 int substart = -1; |
31829
43566b0aec59
Avoid some more compiler warnings.
Gerd Moellmann <gerd@gnu.org>
parents:
31486
diff
changeset
|
2536 int subend = 0; |
12148
a1c38b9b0f73
(Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents:
12147
diff
changeset
|
2537 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
|
2538 |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2539 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
|
2540 |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2541 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
|
2542 { |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2543 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
2544 |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2545 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
|
2546 { |
12807
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2547 substart = search_regs.start[sub]; |
34d269b30df1
(Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
2548 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
|
2549 } |
53719
824b5057fbca
(Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents:
53587
diff
changeset
|
2550 else if (c >= '1' && c <= '9') |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2551 { |
53719
824b5057fbca
(Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents:
53587
diff
changeset
|
2552 if (search_regs.start[c - '0'] >= 0 |
824b5057fbca
(Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents:
53587
diff
changeset
|
2553 && c <= search_regs.num_regs + '0') |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2554 { |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2555 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
|
2556 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
|
2557 } |
53719
824b5057fbca
(Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents:
53587
diff
changeset
|
2558 else |
824b5057fbca
(Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents:
53587
diff
changeset
|
2559 { |
824b5057fbca
(Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents:
53587
diff
changeset
|
2560 /* If that subexp did not match, |
824b5057fbca
(Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents:
53587
diff
changeset
|
2561 replace \\N with nothing. */ |
824b5057fbca
(Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents:
53587
diff
changeset
|
2562 substart = 0; |
824b5057fbca
(Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents:
53587
diff
changeset
|
2563 subend = 0; |
824b5057fbca
(Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents:
53587
diff
changeset
|
2564 } |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2565 } |
12148
a1c38b9b0f73
(Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents:
12147
diff
changeset
|
2566 else if (c == '\\') |
a1c38b9b0f73
(Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents:
12147
diff
changeset
|
2567 delbackslash = 1; |
17225
739e41eed8b6
(Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents:
17102
diff
changeset
|
2568 else |
739e41eed8b6
(Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents:
17102
diff
changeset
|
2569 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
|
2570 } |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2571 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
|
2572 { |
21988
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2573 if (pos - 2 != lastpos) |
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2574 middle = substring_both (newtext, lastpos, |
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2575 lastpos_byte, |
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2576 pos - 2, pos_byte - 2); |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2577 else |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2578 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
|
2579 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
|
2580 Fsubstring (string, |
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2581 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
|
2582 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
|
2583 lastpos = pos; |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2584 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
|
2585 } |
12148
a1c38b9b0f73
(Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents:
12147
diff
changeset
|
2586 else if (delbackslash) |
a1c38b9b0f73
(Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents:
12147
diff
changeset
|
2587 { |
21988
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2588 middle = substring_both (newtext, lastpos, |
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2589 lastpos_byte, |
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2590 pos - 1, pos_byte - 1); |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2591 |
12148
a1c38b9b0f73
(Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents:
12147
diff
changeset
|
2592 accum = concat2 (accum, middle); |
a1c38b9b0f73
(Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents:
12147
diff
changeset
|
2593 lastpos = pos; |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2594 lastpos_byte = pos_byte; |
12148
a1c38b9b0f73
(Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents:
12147
diff
changeset
|
2595 } |
9029
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2596 } |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2597 |
21988
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2598 if (pos != lastpos) |
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2599 middle = substring_both (newtext, lastpos, |
8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents:
21945
diff
changeset
|
2600 lastpos_byte, |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
2601 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
|
2602 else |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2603 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
|
2604 |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2605 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
|
2606 } |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2607 |
17225
739e41eed8b6
(Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents:
17102
diff
changeset
|
2608 /* 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
|
2609 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
|
2610 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
|
2611 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
|
2612 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
|
2613 |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2614 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
|
2615 } |
f0d89b62dd27
(Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents:
8950
diff
changeset
|
2616 |
39487
b21317213c81
(trivial_regexp_p): Catch \{N,M\} as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35831
diff
changeset
|
2617 /* Record point, then move (quietly) to the start of the match. */ |
23790
c1dbb92db43e
(Freplace_match): Set OPOINT clearly for the case
Richard M. Stallman <rms@gnu.org>
parents:
22640
diff
changeset
|
2618 if (PT >= search_regs.end[sub]) |
18077
27a0ced43e7e
(Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents:
17463
diff
changeset
|
2619 opoint = PT - ZV; |
23790
c1dbb92db43e
(Freplace_match): Set OPOINT clearly for the case
Richard M. Stallman <rms@gnu.org>
parents:
22640
diff
changeset
|
2620 else if (PT > search_regs.start[sub]) |
c1dbb92db43e
(Freplace_match): Set OPOINT clearly for the case
Richard M. Stallman <rms@gnu.org>
parents:
22640
diff
changeset
|
2621 opoint = search_regs.end[sub] - ZV; |
18077
27a0ced43e7e
(Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents:
17463
diff
changeset
|
2622 else |
27a0ced43e7e
(Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents:
17463
diff
changeset
|
2623 opoint = PT; |
27a0ced43e7e
(Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents:
17463
diff
changeset
|
2624 |
40922
9147103247c9
(Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents:
40656
diff
changeset
|
2625 /* If we want non-literal replacement, |
9147103247c9
(Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents:
40656
diff
changeset
|
2626 perform substitution on the replacement string. */ |
9147103247c9
(Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents:
40656
diff
changeset
|
2627 if (NILP (literal)) |
603 | 2628 { |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
2629 int length = SBYTES (newtext); |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2630 unsigned char *substed; |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2631 int substed_alloc_size, substed_len; |
28387
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2632 int buf_multibyte = !NILP (current_buffer->enable_multibyte_characters); |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2633 int str_multibyte = STRING_MULTIBYTE (newtext); |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2634 Lisp_Object rev_tbl; |
40922
9147103247c9
(Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents:
40656
diff
changeset
|
2635 int really_changed = 0; |
28387
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2636 |
89483 | 2637 rev_tbl = Qnil; |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2638 |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2639 substed_alloc_size = length * 2 + 100; |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2640 substed = (unsigned char *) xmalloc (substed_alloc_size + 1); |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2641 substed_len = 0; |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2642 |
28387
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2643 /* Go thru NEWTEXT, producing the actual text to insert in |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2644 SUBSTED while adjusting multibyteness to that of the current |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2645 buffer. */ |
603 | 2646 |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2647 for (pos_byte = 0, pos = 0; pos_byte < length;) |
603 | 2648 { |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2649 unsigned char str[MAX_MULTIBYTE_LENGTH]; |
28886
3f60536745bd
(Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents:
28507
diff
changeset
|
2650 unsigned char *add_stuff = NULL; |
3f60536745bd
(Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents:
28507
diff
changeset
|
2651 int add_len = 0; |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2652 int idx = -1; |
2655
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
2653 |
28387
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2654 if (str_multibyte) |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2655 { |
29018
2f43c508a9b5
(wordify): Use FETCH_STRING_CHAR_ADVANCE
Kenichi Handa <handa@m17n.org>
parents:
28886
diff
changeset
|
2656 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, newtext, pos, pos_byte); |
28387
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2657 if (!buf_multibyte) |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2658 c = multibyte_char_to_unibyte (c, rev_tbl); |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2659 } |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2660 else |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2661 { |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2662 /* Note that we don't have to increment POS. */ |
46432
a4697b0a338e
* search.c (wordify): Use SDATA.
Ken Raeburn <raeburn@raeburn.org>
parents:
46370
diff
changeset
|
2663 c = SREF (newtext, pos_byte++); |
28387
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2664 if (buf_multibyte) |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2665 c = unibyte_char_to_multibyte (c); |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2666 } |
22533
6eae236a4f01
(Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents:
22221
diff
changeset
|
2667 |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2668 /* Either set ADD_STUFF and ADD_LEN to the text to put in SUBSTED, |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2669 or set IDX to a match index, which means put that part |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2670 of the buffer text into SUBSTED. */ |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2671 |
603 | 2672 if (c == '\\') |
2673 { | |
40922
9147103247c9
(Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents:
40656
diff
changeset
|
2674 really_changed = 1; |
9147103247c9
(Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents:
40656
diff
changeset
|
2675 |
28387
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2676 if (str_multibyte) |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2677 { |
29018
2f43c508a9b5
(wordify): Use FETCH_STRING_CHAR_ADVANCE
Kenichi Handa <handa@m17n.org>
parents:
28886
diff
changeset
|
2678 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, newtext, |
2f43c508a9b5
(wordify): Use FETCH_STRING_CHAR_ADVANCE
Kenichi Handa <handa@m17n.org>
parents:
28886
diff
changeset
|
2679 pos, pos_byte); |
89213
b0d3fa30523c
(Freplace_match): Check C by ASCII_CHAR_P, not by
Kenichi Handa <handa@m17n.org>
parents:
89130
diff
changeset
|
2680 if (!buf_multibyte && !ASCII_CHAR_P (c)) |
28387
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2681 c = multibyte_char_to_unibyte (c, rev_tbl); |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2682 } |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2683 else |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2684 { |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
2685 c = SREF (newtext, pos_byte++); |
28387
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2686 if (buf_multibyte) |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2687 c = unibyte_char_to_multibyte (c); |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2688 } |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2689 |
603 | 2690 if (c == '&') |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2691 idx = sub; |
7856
9687141f6264
(Freplace_match): Be sure not to treat non-digit like digit.
Richard M. Stallman <rms@gnu.org>
parents:
7674
diff
changeset
|
2692 else if (c >= '1' && c <= '9' && c <= search_regs.num_regs + '0') |
603 | 2693 { |
2694 if (search_regs.start[c - '0'] >= 1) | |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2695 idx = c - '0'; |
603 | 2696 } |
17225
739e41eed8b6
(Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents:
17102
diff
changeset
|
2697 else if (c == '\\') |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2698 add_len = 1, add_stuff = "\\"; |
603 | 2699 else |
28387
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2700 { |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2701 xfree (substed); |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2702 error ("Invalid use of `\\' in replacement text"); |
9a8814cc543c
(Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents:
27884
diff
changeset
|
2703 } |
603 | 2704 } |
2705 else | |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2706 { |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2707 add_len = CHAR_STRING (c, str); |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2708 add_stuff = str; |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2709 } |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2710 |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2711 /* If we want to copy part of a previous match, |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2712 set up ADD_STUFF and ADD_LEN to point to it. */ |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2713 if (idx >= 0) |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2714 { |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2715 int begbyte = CHAR_TO_BYTE (search_regs.start[idx]); |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2716 add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte; |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2717 if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx]) |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2718 move_gap (search_regs.start[idx]); |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2719 add_stuff = BYTE_POS_ADDR (begbyte); |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2720 } |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2721 |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2722 /* Now the stuff we want to add to SUBSTED |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2723 is invariably ADD_LEN bytes starting at ADD_STUFF. */ |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2724 |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2725 /* Make sure SUBSTED is big enough. */ |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2726 if (substed_len + add_len >= substed_alloc_size) |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2727 { |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2728 substed_alloc_size = substed_len + add_len + 500; |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2729 substed = (unsigned char *) xrealloc (substed, |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2730 substed_alloc_size + 1); |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2731 } |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2732 |
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2733 /* Now add to the end of SUBSTED. */ |
28886
3f60536745bd
(Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents:
28507
diff
changeset
|
2734 if (add_stuff) |
3f60536745bd
(Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents:
28507
diff
changeset
|
2735 { |
3f60536745bd
(Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents:
28507
diff
changeset
|
2736 bcopy (add_stuff, substed + substed_len, add_len); |
3f60536745bd
(Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents:
28507
diff
changeset
|
2737 substed_len += add_len; |
3f60536745bd
(Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents:
28507
diff
changeset
|
2738 } |
603 | 2739 } |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2740 |
40922
9147103247c9
(Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents:
40656
diff
changeset
|
2741 if (really_changed) |
53587
6feb1f3f7a9b
(Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
2742 { |
6feb1f3f7a9b
(Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
2743 if (buf_multibyte) |
6feb1f3f7a9b
(Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
2744 { |
6feb1f3f7a9b
(Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
2745 int nchars = multibyte_chars_in_text (substed, substed_len); |
6feb1f3f7a9b
(Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
2746 |
6feb1f3f7a9b
(Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
2747 newtext = make_multibyte_string (substed, nchars, substed_len); |
6feb1f3f7a9b
(Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
2748 } |
6feb1f3f7a9b
(Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
2749 else |
6feb1f3f7a9b
(Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
2750 newtext = make_unibyte_string (substed, substed_len); |
6feb1f3f7a9b
(Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
2751 } |
26982
3527c131b069
(Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents:
26869
diff
changeset
|
2752 xfree (substed); |
603 | 2753 } |
2754 | |
40922
9147103247c9
(Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents:
40656
diff
changeset
|
2755 /* Replace the old text with the new in the cleanest possible way. */ |
9147103247c9
(Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents:
40656
diff
changeset
|
2756 replace_range (search_regs.start[sub], search_regs.end[sub], |
9147103247c9
(Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents:
40656
diff
changeset
|
2757 newtext, 1, 0, 1); |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
2758 newpoint = search_regs.start[sub] + SCHARS (newtext); |
603 | 2759 |
2760 if (case_action == all_caps) | |
40922
9147103247c9
(Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents:
40656
diff
changeset
|
2761 Fupcase_region (make_number (search_regs.start[sub]), |
9147103247c9
(Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents:
40656
diff
changeset
|
2762 make_number (newpoint)); |
603 | 2763 else if (case_action == cap_initial) |
40922
9147103247c9
(Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents:
40656
diff
changeset
|
2764 Fupcase_initials_region (make_number (search_regs.start[sub]), |
9147103247c9
(Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents:
40656
diff
changeset
|
2765 make_number (newpoint)); |
18081
300068b4fcef
(Freplace_match): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
18077
diff
changeset
|
2766 |
47686
fc66469fe069
(Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents:
46474
diff
changeset
|
2767 /* Adjust search data for this change. */ |
fc66469fe069
(Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents:
46474
diff
changeset
|
2768 { |
47692 | 2769 int oldend = search_regs.end[sub]; |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2770 int oldstart = search_regs.start[sub]; |
47686
fc66469fe069
(Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents:
46474
diff
changeset
|
2771 int change = newpoint - search_regs.end[sub]; |
fc66469fe069
(Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents:
46474
diff
changeset
|
2772 int i; |
fc66469fe069
(Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents:
46474
diff
changeset
|
2773 |
fc66469fe069
(Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents:
46474
diff
changeset
|
2774 for (i = 0; i < search_regs.num_regs; i++) |
fc66469fe069
(Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents:
46474
diff
changeset
|
2775 { |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2776 if (search_regs.start[i] >= oldend) |
47686
fc66469fe069
(Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents:
46474
diff
changeset
|
2777 search_regs.start[i] += change; |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2778 else if (search_regs.start[i] > oldstart) |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2779 search_regs.start[i] = oldstart; |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2780 if (search_regs.end[i] >= oldend) |
47686
fc66469fe069
(Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents:
46474
diff
changeset
|
2781 search_regs.end[i] += change; |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2782 else if (search_regs.end[i] > oldstart) |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2783 search_regs.end[i] = oldstart; |
47686
fc66469fe069
(Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents:
46474
diff
changeset
|
2784 } |
fc66469fe069
(Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents:
46474
diff
changeset
|
2785 } |
fc66469fe069
(Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents:
46474
diff
changeset
|
2786 |
18077
27a0ced43e7e
(Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents:
17463
diff
changeset
|
2787 /* 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
|
2788 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
|
2789 TEMP_SET_PT (opoint + ZV); |
18077
27a0ced43e7e
(Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents:
17463
diff
changeset
|
2790 else |
20545
c20c92ff4055
(looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents:
20347
diff
changeset
|
2791 TEMP_SET_PT (opoint); |
18077
27a0ced43e7e
(Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents:
17463
diff
changeset
|
2792 |
27a0ced43e7e
(Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents:
17463
diff
changeset
|
2793 /* 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
|
2794 move_if_not_intangible (newpoint); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
2795 |
603 | 2796 return Qnil; |
2797 } | |
2798 | |
2799 static Lisp_Object | |
2800 match_limit (num, beginningp) | |
2801 Lisp_Object num; | |
2802 int beginningp; | |
2803 { | |
2804 register int n; | |
2805 | |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40269
diff
changeset
|
2806 CHECK_NUMBER (num); |
603 | 2807 n = XINT (num); |
56175
b53351ef3125
(match_limit): Cleaner err msg when no match data available.
Richard M. Stallman <rms@gnu.org>
parents:
56022
diff
changeset
|
2808 if (n < 0) |
56294
aaa6a4ecea38
(match_limit, Fmatch_data, Fset_match_data): YAILOM.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
56276
diff
changeset
|
2809 args_out_of_range (num, make_number (0)); |
56175
b53351ef3125
(match_limit): Cleaner err msg when no match data available.
Richard M. Stallman <rms@gnu.org>
parents:
56022
diff
changeset
|
2810 if (search_regs.num_regs <= 0) |
b53351ef3125
(match_limit): Cleaner err msg when no match data available.
Richard M. Stallman <rms@gnu.org>
parents:
56022
diff
changeset
|
2811 error ("No match data, because no search succeeded"); |
56022
e63446aad5a3
(match_limit): Don't flag an error if match-data
David Kastrup <dak@gnu.org>
parents:
55689
diff
changeset
|
2812 if (n >= search_regs.num_regs |
621 | 2813 || search_regs.start[n] < 0) |
603 | 2814 return Qnil; |
2815 return (make_number ((beginningp) ? search_regs.start[n] | |
2816 : search_regs.end[n])); | |
2817 } | |
2818 | |
2819 DEFUN ("match-beginning", Fmatch_beginning, Smatch_beginning, 1, 1, 0, | |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2820 doc: /* Return position of start of text matched by last search. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2821 SUBEXP, a number, specifies which parenthesized expression in the last |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2822 regexp. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2823 Value is nil if SUBEXPth pair didn't match, or there were less than |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2824 SUBEXP pairs. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2825 Zero means the entire text matched by the whole regexp or whole string. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2826 (subexp) |
14086
a410808fda15
(Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
2827 Lisp_Object subexp; |
603 | 2828 { |
14086
a410808fda15
(Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
2829 return match_limit (subexp, 1); |
603 | 2830 } |
2831 | |
2832 DEFUN ("match-end", Fmatch_end, Smatch_end, 1, 1, 0, | |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2833 doc: /* Return position of end of text matched by last search. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2834 SUBEXP, a number, specifies which parenthesized expression in the last |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2835 regexp. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2836 Value is nil if SUBEXPth pair didn't match, or there were less than |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2837 SUBEXP pairs. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2838 Zero means the entire text matched by the whole regexp or whole string. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2839 (subexp) |
14086
a410808fda15
(Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
2840 Lisp_Object subexp; |
603 | 2841 { |
14086
a410808fda15
(Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
2842 return match_limit (subexp, 0); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
2843 } |
603 | 2844 |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2845 DEFUN ("match-data", Fmatch_data, Smatch_data, 0, 3, 0, |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2846 doc: /* Return a list containing all info on what the last search matched. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2847 Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2848 All the elements are markers or nil (nil if the Nth pair didn't match) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2849 if the last match was on a buffer; integers or nil if a string was matched. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2850 Use `store-match-data' to reinstate the data in this list. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2851 |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2852 If INTEGERS (the optional first argument) is non-nil, always use |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2853 integers \(rather than markers) to represent buffer positions. In |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2854 this case, and if the last match was in a buffer, the buffer will get |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2855 stored as one additional element at the end of the list. |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2856 |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2857 If REUSE is a list, reuse it as part of the value. If REUSE is long |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2858 enough to hold all the values, and if INTEGERS is non-nil, no consing |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2859 is done. |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2860 |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2861 If optional third arg RESEAT is non-nil, any previous markers on the |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2862 REUSE list will be modified to point to nowhere. |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2863 |
49761
3d562e7ebf97
(Fmatch_data): Doc fix. Explicitly state that
Kim F. Storm <storm@cua.dk>
parents:
49600
diff
changeset
|
2864 Return value is undefined if the last search failed. */) |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2865 (integers, reuse, reseat) |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2866 Lisp_Object integers, reuse, reseat; |
603 | 2867 { |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2868 Lisp_Object tail, prev; |
621 | 2869 Lisp_Object *data; |
603 | 2870 int i, len; |
2871 | |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2872 if (!NILP (reseat)) |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2873 for (tail = reuse; CONSP (tail); tail = XCDR (tail)) |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2874 if (MARKERP (XCAR (tail))) |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2875 { |
63666
e0dd6fa42c85
(Fmatch_data): Remove evaporate option.
Kim F. Storm <storm@cua.dk>
parents:
63152
diff
changeset
|
2876 unchain_marker (XMARKER (XCAR (tail))); |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2877 XSETCAR (tail, Qnil); |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2878 } |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2879 |
727 | 2880 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
|
2881 return Qnil; |
727 | 2882 |
31829
43566b0aec59
Avoid some more compiler warnings.
Gerd Moellmann <gerd@gnu.org>
parents:
31486
diff
changeset
|
2883 prev = Qnil; |
43566b0aec59
Avoid some more compiler warnings.
Gerd Moellmann <gerd@gnu.org>
parents:
31486
diff
changeset
|
2884 |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2885 data = (Lisp_Object *) alloca ((2 * search_regs.num_regs + 1) |
621 | 2886 * sizeof (Lisp_Object)); |
2887 | |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2888 len = 0; |
621 | 2889 for (i = 0; i < search_regs.num_regs; i++) |
603 | 2890 { |
2891 int start = search_regs.start[i]; | |
2892 if (start >= 0) | |
2893 { | |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2894 if (EQ (last_thing_searched, Qt) |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2895 || ! NILP (integers)) |
603 | 2896 { |
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
|
2897 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
|
2898 XSETFASTINT (data[2 * i + 1], search_regs.end[i]); |
603 | 2899 } |
9113
766b6288e0f2
(Fmatch_data, Fstore_match_data): Use type test macros.
Karl Heuer <kwzh@gnu.org>
parents:
9029
diff
changeset
|
2900 else if (BUFFERP (last_thing_searched)) |
603 | 2901 { |
2902 data[2 * i] = Fmake_marker (); | |
727 | 2903 Fset_marker (data[2 * i], |
2904 make_number (start), | |
2905 last_thing_searched); | |
603 | 2906 data[2 * i + 1] = Fmake_marker (); |
2907 Fset_marker (data[2 * i + 1], | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
2908 make_number (search_regs.end[i]), |
727 | 2909 last_thing_searched); |
603 | 2910 } |
727 | 2911 else |
2912 /* last_thing_searched must always be Qt, a buffer, or Qnil. */ | |
2913 abort (); | |
2914 | |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2915 len = 2 * i + 2; |
603 | 2916 } |
2917 else | |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2918 data[2 * i] = data[2 * i + 1] = Qnil; |
603 | 2919 } |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2920 |
56294
aaa6a4ecea38
(match_limit, Fmatch_data, Fset_match_data): YAILOM.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
56276
diff
changeset
|
2921 if (BUFFERP (last_thing_searched) && !NILP (integers)) |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2922 { |
56294
aaa6a4ecea38
(match_limit, Fmatch_data, Fset_match_data): YAILOM.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
56276
diff
changeset
|
2923 data[len] = last_thing_searched; |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2924 len++; |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2925 } |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2926 |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2927 /* 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
|
2928 if (! CONSP (reuse)) |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2929 return Flist (len, data); |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2930 |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2931 /* 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
|
2932 into the elements of REUSE. */ |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2933 for (i = 0, tail = reuse; CONSP (tail); |
25663
a5eaace0fa01
Use XCAR and XCDR instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25441
diff
changeset
|
2934 i++, tail = XCDR (tail)) |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2935 { |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2936 if (i < len) |
39973
579177964efa
Avoid (most) uses of XCAR/XCDR as lvalues, for flexibility in experimenting
Ken Raeburn <raeburn@raeburn.org>
parents:
39805
diff
changeset
|
2937 XSETCAR (tail, data[i]); |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2938 else |
39973
579177964efa
Avoid (most) uses of XCAR/XCDR as lvalues, for flexibility in experimenting
Ken Raeburn <raeburn@raeburn.org>
parents:
39805
diff
changeset
|
2939 XSETCAR (tail, Qnil); |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2940 prev = tail; |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2941 } |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2942 |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2943 /* 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
|
2944 cons up the rest of them and add them to the end of REUSE. */ |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2945 if (i < len) |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2946 XSETCDR (prev, Flist (len - i, data + i)); |
16724
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2947 |
4b1fb372a4fe
(Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents:
16275
diff
changeset
|
2948 return reuse; |
603 | 2949 } |
2950 | |
79443
fc388b33b46d
(Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78501
diff
changeset
|
2951 /* We used to have an internal use variant of `reseat' described as: |
fc388b33b46d
(Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78501
diff
changeset
|
2952 |
fc388b33b46d
(Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78501
diff
changeset
|
2953 If RESEAT is `evaporate', put the markers back on the free list |
fc388b33b46d
(Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78501
diff
changeset
|
2954 immediately. No other references to the markers must exist in this |
fc388b33b46d
(Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78501
diff
changeset
|
2955 case, so it is used only internally on the unwind stack and |
fc388b33b46d
(Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78501
diff
changeset
|
2956 save-match-data from Lisp. |
fc388b33b46d
(Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78501
diff
changeset
|
2957 |
fc388b33b46d
(Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78501
diff
changeset
|
2958 But it was ill-conceived: those supposedly-internal markers get exposed via |
fc388b33b46d
(Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78501
diff
changeset
|
2959 the undo-list, so freeing them here is unsafe. */ |
603 | 2960 |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2961 DEFUN ("set-match-data", Fset_match_data, Sset_match_data, 1, 2, 0, |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
2962 doc: /* Set internal data on last search match from elements of LIST. |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2963 LIST should have been created by calling `match-data' previously. |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2964 |
63666
e0dd6fa42c85
(Fmatch_data): Remove evaporate option.
Kim F. Storm <storm@cua.dk>
parents:
63152
diff
changeset
|
2965 If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */) |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2966 (list, reseat) |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
2967 register Lisp_Object list, reseat; |
603 | 2968 { |
2969 register int i; | |
2970 register Lisp_Object marker; | |
2971 | |
10032
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2972 if (running_asynch_code) |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2973 save_search_regs (); |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
2974 |
71841
0b34cf45daa8
(Fset_match_data): Use CHECK_LIST.
Kim F. Storm <storm@cua.dk>
parents:
71063
diff
changeset
|
2975 CHECK_LIST (list); |
603 | 2976 |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2977 /* Unless we find a marker with a buffer or an explicit buffer |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
2978 in LIST, assume that this match data came from a string. */ |
727 | 2979 last_thing_searched = Qt; |
2980 | |
621 | 2981 /* Allocate registers if they don't already exist. */ |
2982 { | |
1523
bd61aaa7828b
* search.c (Fstore_match_data): Don't assume Flength returns an
Jim Blandy <jimb@redhat.com>
parents:
1413
diff
changeset
|
2983 int length = XFASTINT (Flength (list)) / 2; |
621 | 2984 |
2985 if (length > search_regs.num_regs) | |
2986 { | |
708 | 2987 if (search_regs.num_regs == 0) |
2988 { | |
2989 search_regs.start | |
2990 = (regoff_t *) xmalloc (length * sizeof (regoff_t)); | |
2991 search_regs.end | |
2992 = (regoff_t *) xmalloc (length * sizeof (regoff_t)); | |
2993 } | |
621 | 2994 else |
708 | 2995 { |
2996 search_regs.start | |
2997 = (regoff_t *) xrealloc (search_regs.start, | |
2998 length * sizeof (regoff_t)); | |
2999 search_regs.end | |
3000 = (regoff_t *) xrealloc (search_regs.end, | |
3001 length * sizeof (regoff_t)); | |
3002 } | |
621 | 3003 |
33052
9ec478daa468
(Fset_match_data): Be sure to make search_regs always sane.
Kenichi Handa <handa@m17n.org>
parents:
32387
diff
changeset
|
3004 for (i = search_regs.num_regs; i < length; i++) |
9ec478daa468
(Fset_match_data): Be sure to make search_regs always sane.
Kenichi Handa <handa@m17n.org>
parents:
32387
diff
changeset
|
3005 search_regs.start[i] = -1; |
9ec478daa468
(Fset_match_data): Be sure to make search_regs always sane.
Kenichi Handa <handa@m17n.org>
parents:
32387
diff
changeset
|
3006 |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
3007 search_regs.num_regs = length; |
621 | 3008 } |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3009 |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3010 for (i = 0; CONSP (list); i++) |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3011 { |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3012 marker = XCAR (list); |
56294
aaa6a4ecea38
(match_limit, Fmatch_data, Fset_match_data): YAILOM.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
56276
diff
changeset
|
3013 if (BUFFERP (marker)) |
56276
b04610e283ce
(Fset_match_data): Allow buffer before end of list
David Kastrup <dak@gnu.org>
parents:
56224
diff
changeset
|
3014 { |
56294
aaa6a4ecea38
(match_limit, Fmatch_data, Fset_match_data): YAILOM.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
56276
diff
changeset
|
3015 last_thing_searched = marker; |
56276
b04610e283ce
(Fset_match_data): Allow buffer before end of list
David Kastrup <dak@gnu.org>
parents:
56224
diff
changeset
|
3016 break; |
b04610e283ce
(Fset_match_data): Allow buffer before end of list
David Kastrup <dak@gnu.org>
parents:
56224
diff
changeset
|
3017 } |
b04610e283ce
(Fset_match_data): Allow buffer before end of list
David Kastrup <dak@gnu.org>
parents:
56224
diff
changeset
|
3018 if (i >= length) |
b04610e283ce
(Fset_match_data): Allow buffer before end of list
David Kastrup <dak@gnu.org>
parents:
56224
diff
changeset
|
3019 break; |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3020 if (NILP (marker)) |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3021 { |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3022 search_regs.start[i] = -1; |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3023 list = XCDR (list); |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3024 } |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3025 else |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3026 { |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3027 int from; |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3028 Lisp_Object m; |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3029 |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3030 m = marker; |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3031 if (MARKERP (marker)) |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3032 { |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3033 if (XMARKER (marker)->buffer == 0) |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3034 XSETFASTINT (marker, 0); |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3035 else |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3036 XSETBUFFER (last_thing_searched, XMARKER (marker)->buffer); |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3037 } |
58567
47729f2cb184
(syms_of_search) <search-spaces-regexp>: Move 'doc:'
Kim F. Storm <storm@cua.dk>
parents:
58348
diff
changeset
|
3038 |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3039 CHECK_NUMBER_COERCE_MARKER (marker); |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3040 from = XINT (marker); |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3041 |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3042 if (!NILP (reseat) && MARKERP (m)) |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3043 { |
79443
fc388b33b46d
(Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78501
diff
changeset
|
3044 unchain_marker (XMARKER (m)); |
63152
3f80de0be046
(Fset_match_data): Fix last change.
Kim F. Storm <storm@cua.dk>
parents:
63145
diff
changeset
|
3045 XSETCAR (list, Qnil); |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3046 } |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3047 |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3048 if ((list = XCDR (list), !CONSP (list))) |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3049 break; |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3050 |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3051 m = marker = XCAR (list); |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3052 |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3053 if (MARKERP (marker) && XMARKER (marker)->buffer == 0) |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3054 XSETFASTINT (marker, 0); |
58567
47729f2cb184
(syms_of_search) <search-spaces-regexp>: Move 'doc:'
Kim F. Storm <storm@cua.dk>
parents:
58348
diff
changeset
|
3055 |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3056 CHECK_NUMBER_COERCE_MARKER (marker); |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3057 search_regs.start[i] = from; |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3058 search_regs.end[i] = XINT (marker); |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3059 |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3060 if (!NILP (reseat) && MARKERP (m)) |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3061 { |
79443
fc388b33b46d
(Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78501
diff
changeset
|
3062 unchain_marker (XMARKER (m)); |
63152
3f80de0be046
(Fset_match_data): Fix last change.
Kim F. Storm <storm@cua.dk>
parents:
63145
diff
changeset
|
3063 XSETCAR (list, Qnil); |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3064 } |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3065 } |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3066 list = XCDR (list); |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3067 } |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3068 |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3069 for (; i < search_regs.num_regs; i++) |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3070 search_regs.start[i] = -1; |
621 | 3071 } |
3072 | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
3073 return Qnil; |
603 | 3074 } |
3075 | |
10032
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3076 /* 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
|
3077 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
|
3078 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
|
3079 static struct re_registers saved_search_regs; |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3080 static Lisp_Object saved_last_thing_searched; |
10032
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3081 |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3082 /* 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
|
3083 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
|
3084 static void |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3085 save_search_regs () |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3086 { |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3087 if (!search_regs_saved) |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3088 { |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3089 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
|
3090 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
|
3091 saved_search_regs.end = search_regs.end; |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3092 saved_last_thing_searched = last_thing_searched; |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3093 last_thing_searched = Qnil; |
10032
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3094 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
|
3095 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
|
3096 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
|
3097 |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3098 search_regs_saved = 1; |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3099 } |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3100 } |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3101 |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3102 /* 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
|
3103 void |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3104 restore_search_regs () |
10032
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3105 { |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3106 if (search_regs_saved) |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3107 { |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3108 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
|
3109 { |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3110 xfree (search_regs.start); |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3111 xfree (search_regs.end); |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3112 } |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3113 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
|
3114 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
|
3115 search_regs.end = saved_search_regs.end; |
56224
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3116 last_thing_searched = saved_last_thing_searched; |
17e2d4a894aa
(Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents:
56175
diff
changeset
|
3117 saved_last_thing_searched = Qnil; |
10032
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3118 search_regs_saved = 0; |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3119 } |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3120 } |
f689803caa92
Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents:
10020
diff
changeset
|
3121 |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3122 static Lisp_Object |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3123 unwind_set_match_data (list) |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3124 Lisp_Object list; |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3125 { |
79443
fc388b33b46d
(Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78501
diff
changeset
|
3126 /* It is NOT ALWAYS safe to free (evaporate) the markers immediately. */ |
fc388b33b46d
(Fset_match_data): Remove the `evaporate' feature.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78501
diff
changeset
|
3127 return Fset_match_data (list, Qt); |
63145
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3128 } |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3129 |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3130 /* Called to unwind protect the match data. */ |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3131 void |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3132 record_unwind_save_match_data () |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3133 { |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3134 record_unwind_protect (unwind_set_match_data, |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3135 Fmatch_data (Qnil, Qnil, Qnil)); |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3136 } |
73d9b884e8c8
(Fmatch_data): Add optional RESEAT arg. Unchain markers
Kim F. Storm <storm@cua.dk>
parents:
61682
diff
changeset
|
3137 |
603 | 3138 /* Quote a string to inactivate reg-expr chars */ |
3139 | |
3140 DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0, | |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
3141 doc: /* Return a regexp string which matches exactly STRING and nothing else. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39973
diff
changeset
|
3142 (string) |
14086
a410808fda15
(Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
3143 Lisp_Object string; |
603 | 3144 { |
3145 register unsigned char *in, *out, *end; | |
3146 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
|
3147 int backslashes_added = 0; |
603 | 3148 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40269
diff
changeset
|
3149 CHECK_STRING (string); |
603 | 3150 |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
3151 temp = (unsigned char *) alloca (SBYTES (string) * 2); |
603 | 3152 |
3153 /* Now copy the data into the new string, inserting escapes. */ | |
3154 | |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
3155 in = SDATA (string); |
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
3156 end = in + SBYTES (string); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
3157 out = temp; |
603 | 3158 |
3159 for (; in != end; in++) | |
3160 { | |
69238
de924a86ee65
(Fregexp_quote): Do not precede a literal `]' with two backslashes to
Luc Teirlinck <teirllm@auburn.edu>
parents:
68651
diff
changeset
|
3161 if (*in == '[' |
603 | 3162 || *in == '*' || *in == '.' || *in == '\\' |
3163 || *in == '?' || *in == '+' | |
3164 || *in == '^' || *in == '$') | |
20588
138c95482e6b
(search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents:
20547
diff
changeset
|
3165 *out++ = '\\', backslashes_added++; |
603 | 3166 *out++ = *in; |
3167 } | |
3168 | |
21248
aba5e1c3328b
(Fregexp_quote): Use make_specified_string.
Richard M. Stallman <rms@gnu.org>
parents:
21244
diff
changeset
|
3169 return make_specified_string (temp, |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45263
diff
changeset
|
3170 SCHARS (string) + backslashes_added, |
21248
aba5e1c3328b
(Fregexp_quote): Use make_specified_string.
Richard M. Stallman <rms@gnu.org>
parents:
21244
diff
changeset
|
3171 out - temp, |
aba5e1c3328b
(Fregexp_quote): Use make_specified_string.
Richard M. Stallman <rms@gnu.org>
parents:
21244
diff
changeset
|
3172 STRING_MULTIBYTE (string)); |
603 | 3173 } |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48528
diff
changeset
|
3174 |
21514 | 3175 void |
603 | 3176 syms_of_search () |
3177 { | |
3178 register int i; | |
3179 | |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
3180 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
|
3181 { |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
3182 searchbufs[i].buf.allocated = 100; |
51544
a0c2b39160e9
(shrink_regexp_cache): Use xrealloc.
Dave Love <fx@gnu.org>
parents:
49761
diff
changeset
|
3183 searchbufs[i].buf.buffer = (unsigned char *) xmalloc (100); |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
3184 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
|
3185 searchbufs[i].regexp = Qnil; |
58330
5be8a633ec57
(struct regexp_cache): New element whitespace_regexp.
Richard M. Stallman <rms@gnu.org>
parents:
58326
diff
changeset
|
3186 searchbufs[i].whitespace_regexp = Qnil; |
73002
b3a72607819d
* search.c (struct regexp_cache): New entry syntax_table.
Chong Yidong <cyd@stupidchicken.com>
parents:
72945
diff
changeset
|
3187 searchbufs[i].syntax_table = Qnil; |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
3188 staticpro (&searchbufs[i].regexp); |
64318
a64663d06985
(syms_of_search): Staticpro searchbuf.whitespace_regexp.
Kim F. Storm <storm@cua.dk>
parents:
64084
diff
changeset
|
3189 staticpro (&searchbufs[i].whitespace_regexp); |
73002
b3a72607819d
* search.c (struct regexp_cache): New entry syntax_table.
Chong Yidong <cyd@stupidchicken.com>
parents:
72945
diff
changeset
|
3190 staticpro (&searchbufs[i].syntax_table); |
9605
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
3191 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
|
3192 } |
cf97e75d8e02
(searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents:
9452
diff
changeset
|
3193 searchbuf_head = &searchbufs[0]; |
603 | 3194 |
3195 Qsearch_failed = intern ("search-failed"); | |
3196 staticpro (&Qsearch_failed); | |
3197 Qinvalid_regexp = intern ("invalid-regexp"); | |
3198 staticpro (&Qinvalid_regexp); | |
3199 | |
3200 Fput (Qsearch_failed, Qerror_conditions, | |
3201 Fcons (Qsearch_failed, Fcons (Qerror, Qnil))); | |
3202 Fput (Qsearch_failed, Qerror_message, | |
3203 build_string ("Search failed")); | |
3204 | |
3205 Fput (Qinvalid_regexp, Qerror_conditions, | |
3206 Fcons (Qinvalid_regexp, Fcons (Qerror, Qnil))); | |
3207 Fput (Qinvalid_regexp, Qerror_message, | |
3208 build_string ("Invalid regexp")); | |
3209 | |
727 | 3210 last_thing_searched = Qnil; |
3211 staticpro (&last_thing_searched); | |
3212 | |
56429 | 3213 saved_last_thing_searched = Qnil; |
3214 staticpro (&saved_last_thing_searched); | |
3215 | |
58348
623ffd21f0ff
(Vsearch_spaces_regexp):
Richard M. Stallman <rms@gnu.org>
parents:
58330
diff
changeset
|
3216 DEFVAR_LISP ("search-spaces-regexp", &Vsearch_spaces_regexp, |
58567
47729f2cb184
(syms_of_search) <search-spaces-regexp>: Move 'doc:'
Kim F. Storm <storm@cua.dk>
parents:
58348
diff
changeset
|
3217 doc: /* Regexp to substitute for bunches of spaces in regexp search. |
58326
0cc0d3274d68
(Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
57735
diff
changeset
|
3218 Some commands use this for user-specified regexps. |
0cc0d3274d68
(Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
57735
diff
changeset
|
3219 Spaces that occur inside character classes or repetition operators |
0cc0d3274d68
(Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
57735
diff
changeset
|
3220 or other such regexp constructs are not replaced with this. |
0cc0d3274d68
(Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
57735
diff
changeset
|
3221 A value of nil (which is the normal value) means treat spaces literally. */); |
58348
623ffd21f0ff
(Vsearch_spaces_regexp):
Richard M. Stallman <rms@gnu.org>
parents:
58330
diff
changeset
|
3222 Vsearch_spaces_regexp = Qnil; |
58326
0cc0d3274d68
(Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
57735
diff
changeset
|
3223 |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
3224 DEFVAR_LISP ("inhibit-changing-match-data", &Vinhibit_changing_match_data, |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
3225 doc: /* Internal use only. |
86900
a65aa1e9a34b
(syms_of_search) <inhibit-changing-match-data>: Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
86275
diff
changeset
|
3226 If non-nil, the primitive searching and matching functions |
a65aa1e9a34b
(syms_of_search) <inhibit-changing-match-data>: Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
86275
diff
changeset
|
3227 such as `looking-at', `string-match', `re-search-forward', etc., |
a65aa1e9a34b
(syms_of_search) <inhibit-changing-match-data>: Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
86275
diff
changeset
|
3228 do not set the match data. The proper way to use this variable |
a65aa1e9a34b
(syms_of_search) <inhibit-changing-match-data>: Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
86275
diff
changeset
|
3229 is to bind it with `let' around a small expression. */); |
81780
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
3230 Vinhibit_changing_match_data = Qnil; |
54b5d7bec019
(Vinhibit_changing_match_data, search_regs_1): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
81279
diff
changeset
|
3231 |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
3232 defsubr (&Slooking_at); |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
3233 defsubr (&Sposix_looking_at); |
603 | 3234 defsubr (&Sstring_match); |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
3235 defsubr (&Sposix_string_match); |
603 | 3236 defsubr (&Ssearch_forward); |
3237 defsubr (&Ssearch_backward); | |
3238 defsubr (&Sword_search_forward); | |
3239 defsubr (&Sword_search_backward); | |
3240 defsubr (&Sre_search_forward); | |
3241 defsubr (&Sre_search_backward); | |
10020
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
3242 defsubr (&Sposix_search_forward); |
c41ce96785a8
(struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents:
9605
diff
changeset
|
3243 defsubr (&Sposix_search_backward); |
603 | 3244 defsubr (&Sreplace_match); |
3245 defsubr (&Smatch_beginning); | |
3246 defsubr (&Smatch_end); | |
3247 defsubr (&Smatch_data); | |
21171
60f6085df198
(Fset_match_data): Renamed from Fstore_match_data.
Richard M. Stallman <rms@gnu.org>
parents:
21117
diff
changeset
|
3248 defsubr (&Sset_match_data); |
603 | 3249 defsubr (&Sregexp_quote); |
3250 } | |
52401 | 3251 |
3252 /* arch-tag: a6059d79-0552-4f14-a2cb-d379a4e3c78f | |
3253 (do not change this comment) */ |