428
|
1 /* String search routines for XEmacs.
|
|
2 Copyright (C) 1985, 1986, 1987, 1992-1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
793
|
4 Copyright (C) 2001, 2002 Ben Wing.
|
428
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: FSF 19.29, except for region-cache stuff. */
|
|
24
|
|
25 /* Hacked on for Mule by Ben Wing, December 1994 and August 1995. */
|
|
26
|
826
|
27 /* This file has been Mule-ized. */
|
428
|
28
|
|
29 #include <config.h>
|
|
30 #include "lisp.h"
|
|
31
|
|
32 #include "buffer.h"
|
|
33 #include "insdel.h"
|
|
34 #include "opaque.h"
|
|
35 #ifdef REGION_CACHE_NEEDS_WORK
|
|
36 #include "region-cache.h"
|
|
37 #endif
|
|
38 #include "syntax.h"
|
|
39
|
|
40 #include <sys/types.h>
|
|
41 #include "regex.h"
|
446
|
42 #include "casetab.h"
|
|
43 #include "chartab.h"
|
|
44
|
|
45 #define TRANSLATE(table, pos) \
|
867
|
46 (!NILP (table) ? TRT_TABLE_OF (table, (Ichar) pos) : pos)
|
428
|
47
|
|
48 #define REGEXP_CACHE_SIZE 20
|
|
49
|
|
50 /* If the regexp is non-nil, then the buffer contains the compiled form
|
|
51 of that regexp, suitable for searching. */
|
446
|
52 struct regexp_cache
|
|
53 {
|
428
|
54 struct regexp_cache *next;
|
|
55 Lisp_Object regexp;
|
|
56 struct re_pattern_buffer buf;
|
|
57 char fastmap[0400];
|
|
58 /* Nonzero means regexp was compiled to do full POSIX backtracking. */
|
|
59 char posix;
|
|
60 };
|
|
61
|
|
62 /* The instances of that struct. */
|
|
63 static struct regexp_cache searchbufs[REGEXP_CACHE_SIZE];
|
|
64
|
|
65 /* The head of the linked list; points to the most recently used buffer. */
|
|
66 static struct regexp_cache *searchbuf_head;
|
|
67
|
|
68
|
|
69 /* Every call to re_match, etc., must pass &search_regs as the regs
|
|
70 argument unless you can show it is unnecessary (i.e., if re_match
|
|
71 is certainly going to be called again before region-around-match
|
|
72 can be called).
|
|
73
|
|
74 Since the registers are now dynamically allocated, we need to make
|
|
75 sure not to refer to the Nth register before checking that it has
|
|
76 been allocated by checking search_regs.num_regs.
|
|
77
|
|
78 The regex code keeps track of whether it has allocated the search
|
|
79 buffer using bits in the re_pattern_buffer. This means that whenever
|
|
80 you compile a new pattern, it completely forgets whether it has
|
|
81 allocated any registers, and will allocate new registers the next
|
|
82 time you call a searching or matching function. Therefore, we need
|
|
83 to call re_set_registers after compiling a new pattern or after
|
|
84 setting the match registers, so that the regex functions will be
|
|
85 able to free or re-allocate it properly. */
|
|
86
|
|
87 /* Note: things get trickier under Mule because the values returned from
|
826
|
88 the regexp routines are in Bytebpos's but we need them to be in Charbpos's.
|
428
|
89 We take the easy way out for the moment and just convert them immediately.
|
|
90 We could be more clever by not converting them until necessary, but
|
|
91 that gets real ugly real fast since the buffer might have changed and
|
|
92 the positions might be out of sync or out of range.
|
|
93 */
|
|
94 static struct re_registers search_regs;
|
|
95
|
1425
|
96 /* Every function that _may_ set the match data _must_ clear the search
|
|
97 registers on entry. An unsuccessful search should leave the search
|
|
98 registers cleared. Applications that are no-ops by definition (eg,
|
|
99 searches with a repetition count of 0) _must not_ clear the search
|
|
100 registers.
|
|
101
|
|
102 XEmacs 21.5 up to beta 11 may have permitted the following idiom to
|
|
103 "win" in the sense that the match data was set to the last successful
|
|
104 match's match data, and not cleared as the current implemenation does:
|
|
105
|
|
106 (while (search_forward "string"))
|
|
107 (use-match-data-of-last-successful-search)
|
|
108
|
|
109 This no longer can work. You must use save-match-data to preserve the
|
|
110 match data:
|
|
111
|
|
112 (let (md)
|
|
113 (while (when (search-forward "string") (setq md (match-data))))
|
|
114 (set-match-data md))
|
|
115 (use-match-data-of-last-successful-search)
|
|
116 */
|
|
117 static void set_search_regs (struct buffer *buf, Charbpos beg, Charcount len);
|
|
118 static void clear_search_regs (struct re_registers *regp);
|
|
119
|
428
|
120 /* The buffer in which the last search was performed, or
|
|
121 Qt if the last search was done in a string;
|
|
122 Qnil if no searching has been done yet. */
|
|
123 static Lisp_Object last_thing_searched;
|
|
124
|
|
125 /* error condition signalled when regexp compile_pattern fails */
|
|
126
|
|
127 Lisp_Object Qinvalid_regexp;
|
|
128
|
|
129 /* Regular expressions used in forward/backward-word */
|
|
130 Lisp_Object Vforward_word_regexp, Vbackward_word_regexp;
|
|
131
|
507
|
132 Fixnum warn_about_possibly_incompatible_back_references;
|
502
|
133
|
428
|
134 /* range table for use with skip_chars. Only needed for Mule. */
|
|
135 Lisp_Object Vskip_chars_range_table;
|
|
136
|
867
|
137 static Charbpos simple_search (struct buffer *buf, Ibyte *base_pat,
|
826
|
138 Bytecount len, Bytebpos pos, Bytebpos lim,
|
|
139 EMACS_INT n, Lisp_Object trt);
|
867
|
140 static Charbpos boyer_moore (struct buffer *buf, Ibyte *base_pat,
|
826
|
141 Bytecount len, Bytebpos pos, Bytebpos lim,
|
|
142 EMACS_INT n, Lisp_Object trt,
|
|
143 Lisp_Object inverse_trt, int charset_base);
|
665
|
144 static Charbpos search_buffer (struct buffer *buf, Lisp_Object str,
|
826
|
145 Charbpos charbpos, Charbpos buflim, EMACS_INT n,
|
|
146 int RE, Lisp_Object trt,
|
|
147 Lisp_Object inverse_trt, int posix);
|
771
|
148
|
428
|
149 static void
|
|
150 matcher_overflow (void)
|
|
151 {
|
563
|
152 stack_overflow ("Stack overflow in regexp matcher", Qunbound);
|
428
|
153 }
|
|
154
|
|
155 /* Compile a regexp and signal a Lisp error if anything goes wrong.
|
|
156 PATTERN is the pattern to compile.
|
|
157 CP is the place to put the result.
|
826
|
158 TRANSLATE is a translation table for ignoring case, or Qnil for none.
|
428
|
159 REGP is the structure that says where to store the "register"
|
|
160 values that will result from matching this pattern.
|
|
161 If it is 0, we should compile the pattern not to record any
|
|
162 subexpression bounds.
|
|
163 POSIX is nonzero if we want full backtracking (POSIX style)
|
|
164 for this pattern. 0 means backtrack only enough to get a valid match. */
|
|
165
|
|
166 static int
|
|
167 compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern,
|
826
|
168 struct re_registers *regp, Lisp_Object translate,
|
|
169 int posix, Error_Behavior errb)
|
428
|
170 {
|
442
|
171 const char *val;
|
428
|
172 reg_syntax_t old;
|
|
173
|
|
174 cp->regexp = Qnil;
|
|
175 cp->buf.translate = translate;
|
|
176 cp->posix = posix;
|
|
177 old = re_set_syntax (RE_SYNTAX_EMACS
|
|
178 | (posix ? 0 : RE_NO_POSIX_BACKTRACKING));
|
442
|
179 val = (const char *)
|
428
|
180 re_compile_pattern ((char *) XSTRING_DATA (pattern),
|
|
181 XSTRING_LENGTH (pattern), &cp->buf);
|
|
182 re_set_syntax (old);
|
|
183 if (val)
|
|
184 {
|
563
|
185 maybe_signal_error (Qinvalid_regexp, 0, build_string (val),
|
428
|
186 Qsearch, errb);
|
|
187 return 0;
|
|
188 }
|
|
189
|
|
190 cp->regexp = Fcopy_sequence (pattern);
|
|
191 return 1;
|
|
192 }
|
|
193
|
|
194 /* Compile a regexp if necessary, but first check to see if there's one in
|
|
195 the cache.
|
|
196 PATTERN is the pattern to compile.
|
826
|
197 TRANSLATE is a translation table for ignoring case, or Qnil for none.
|
428
|
198 REGP is the structure that says where to store the "register"
|
|
199 values that will result from matching this pattern.
|
|
200 If it is 0, we should compile the pattern not to record any
|
|
201 subexpression bounds.
|
|
202 POSIX is nonzero if we want full backtracking (POSIX style)
|
|
203 for this pattern. 0 means backtrack only enough to get a valid match. */
|
|
204
|
|
205 struct re_pattern_buffer *
|
|
206 compile_pattern (Lisp_Object pattern, struct re_registers *regp,
|
826
|
207 Lisp_Object translate, Lisp_Object searchobj,
|
|
208 struct buffer *searchbuf, int posix, Error_Behavior errb)
|
428
|
209 {
|
|
210 struct regexp_cache *cp, **cpp;
|
|
211
|
|
212 for (cpp = &searchbuf_head; ; cpp = &cp->next)
|
|
213 {
|
|
214 cp = *cpp;
|
826
|
215 /* &&#### once we fix up the fastmap code in regex.c for 8-bit-fixed,
|
|
216 we need to record and compare the buffer and format, since the
|
|
217 fastmap will reflect the state of the buffer -- and things get
|
|
218 more complicated if the buffer has changed formats or (esp.) has
|
|
219 kept the format but changed its interpretation! may need to have
|
|
220 the code that changes the interpretation go through and invalidate
|
|
221 cache entries for that buffer. */
|
428
|
222 if (!NILP (Fstring_equal (cp->regexp, pattern))
|
446
|
223 && EQ (cp->buf.translate, translate)
|
428
|
224 && cp->posix == posix)
|
|
225 break;
|
|
226
|
|
227 /* If we're at the end of the cache, compile into the last cell. */
|
|
228 if (cp->next == 0)
|
|
229 {
|
826
|
230 if (!compile_pattern_1 (cp, pattern, regp, translate,
|
|
231 posix, errb))
|
428
|
232 return 0;
|
|
233 break;
|
|
234 }
|
|
235 }
|
|
236
|
|
237 /* When we get here, cp (aka *cpp) contains the compiled pattern,
|
|
238 either because we found it in the cache or because we just compiled it.
|
|
239 Move it to the front of the queue to mark it as most recently used. */
|
|
240 *cpp = cp->next;
|
|
241 cp->next = searchbuf_head;
|
|
242 searchbuf_head = cp;
|
|
243
|
|
244 /* Advise the searching functions about the space we have allocated
|
|
245 for register data. */
|
|
246 if (regp)
|
|
247 re_set_registers (&cp->buf, regp, regp->num_regs, regp->start, regp->end);
|
|
248
|
|
249 return &cp->buf;
|
|
250 }
|
|
251
|
|
252 /* Error condition used for failing searches */
|
|
253 Lisp_Object Qsearch_failed;
|
|
254
|
|
255 static Lisp_Object
|
|
256 signal_failure (Lisp_Object arg)
|
|
257 {
|
446
|
258 for (;;)
|
|
259 Fsignal (Qsearch_failed, list1 (arg));
|
|
260 return Qnil; /* Not reached. */
|
428
|
261 }
|
|
262
|
826
|
263 /* Convert the search registers from Bytebpos's to Charbpos's. Needs to be
|
428
|
264 done after each regexp match that uses the search regs.
|
|
265
|
|
266 We could get a potential speedup by not converting the search registers
|
|
267 until it's really necessary, e.g. when match-data or replace-match is
|
|
268 called. However, this complexifies the code a lot (e.g. the buffer
|
826
|
269 could have changed and the Bytebpos's stored might be invalid) and is
|
428
|
270 probably not a great time-saver. */
|
|
271
|
|
272 static void
|
|
273 fixup_search_regs_for_buffer (struct buffer *buf)
|
|
274 {
|
|
275 int i;
|
|
276 int num_regs = search_regs.num_regs;
|
|
277
|
|
278 for (i = 0; i < num_regs; i++)
|
|
279 {
|
|
280 if (search_regs.start[i] >= 0)
|
826
|
281 search_regs.start[i] = bytebpos_to_charbpos (buf,
|
|
282 search_regs.start[i]);
|
428
|
283 if (search_regs.end[i] >= 0)
|
665
|
284 search_regs.end[i] = bytebpos_to_charbpos (buf, search_regs.end[i]);
|
428
|
285 }
|
|
286 }
|
|
287
|
|
288 /* Similar but for strings. */
|
|
289 static void
|
|
290 fixup_search_regs_for_string (Lisp_Object string)
|
|
291 {
|
|
292 int i;
|
|
293 int num_regs = search_regs.num_regs;
|
|
294
|
|
295 /* #### bytecount_to_charcount() is not that efficient. This function
|
867
|
296 could be faster if it did its own conversion (using INC_IBYTEPTR()
|
428
|
297 and such), because the register ends are likely to be somewhat ordered.
|
|
298 (Even if not, you could sort them.)
|
|
299
|
|
300 Think about this if this function is a time hog, which it's probably
|
|
301 not. */
|
|
302 for (i = 0; i < num_regs; i++)
|
|
303 {
|
|
304 if (search_regs.start[i] > 0)
|
|
305 {
|
|
306 search_regs.start[i] =
|
793
|
307 string_index_byte_to_char (string, search_regs.start[i]);
|
428
|
308 }
|
|
309 if (search_regs.end[i] > 0)
|
|
310 {
|
|
311 search_regs.end[i] =
|
793
|
312 string_index_byte_to_char (string, search_regs.end[i]);
|
428
|
313 }
|
|
314 }
|
|
315 }
|
|
316
|
|
317
|
|
318 static Lisp_Object
|
|
319 looking_at_1 (Lisp_Object string, struct buffer *buf, int posix)
|
|
320 {
|
|
321 Lisp_Object val;
|
665
|
322 Bytebpos p1, p2;
|
428
|
323 Bytecount s1, s2;
|
|
324 REGISTER int i;
|
|
325 struct re_pattern_buffer *bufp;
|
826
|
326 struct syntax_cache scache_struct;
|
|
327 struct syntax_cache *scache = &scache_struct;
|
|
328
|
1425
|
329 /* clear search registers *now*. no mercy, not even for errors */
|
|
330 clear_search_regs (&search_regs);
|
|
331
|
428
|
332 CHECK_STRING (string);
|
|
333 bufp = compile_pattern (string, &search_regs,
|
|
334 (!NILP (buf->case_fold_search)
|
446
|
335 ? XCASE_TABLE_DOWNCASE (buf->case_table) : Qnil),
|
826
|
336 wrap_buffer (buf), buf, posix, ERROR_ME);
|
428
|
337
|
|
338 QUIT;
|
|
339
|
|
340 /* Get pointers and sizes of the two strings
|
|
341 that make up the visible portion of the buffer. */
|
|
342
|
826
|
343 p1 = BYTE_BUF_BEGV (buf);
|
|
344 p2 = BYTE_BUF_CEILING_OF (buf, p1);
|
428
|
345 s1 = p2 - p1;
|
826
|
346 s2 = BYTE_BUF_ZV (buf) - p2;
|
|
347
|
|
348 /* By making the regex object, regex buffer, and syntax cache arguments
|
|
349 to re_{search,match}{,_2}, we've removed the need to do nasty things
|
|
350 to deal with regex reentrancy. (See stack trace in signal.c for proof
|
|
351 that this can happen.)
|
|
352
|
|
353 #### there is still a potential problem with the regex cache --
|
|
354 the compiled regex could be overwritten. we'd need 20-fold
|
|
355 reentrancy, though. Fix this. */
|
|
356
|
|
357 i = re_match_2 (bufp, (char *) BYTE_BUF_BYTE_ADDRESS (buf, p1),
|
|
358 s1, (char *) BYTE_BUF_BYTE_ADDRESS (buf, p2), s2,
|
|
359 BYTE_BUF_PT (buf) - BYTE_BUF_BEGV (buf), &search_regs,
|
|
360 BYTE_BUF_ZV (buf) - BYTE_BUF_BEGV (buf), wrap_buffer (buf),
|
|
361 buf, scache);
|
428
|
362
|
|
363 if (i == -2)
|
|
364 matcher_overflow ();
|
|
365
|
|
366 val = (0 <= i ? Qt : Qnil);
|
|
367 if (NILP (val))
|
826
|
368 return Qnil;
|
428
|
369 {
|
|
370 int num_regs = search_regs.num_regs;
|
|
371 for (i = 0; i < num_regs; i++)
|
|
372 if (search_regs.start[i] >= 0)
|
|
373 {
|
826
|
374 search_regs.start[i] += BYTE_BUF_BEGV (buf);
|
|
375 search_regs.end[i] += BYTE_BUF_BEGV (buf);
|
428
|
376 }
|
|
377 }
|
793
|
378 last_thing_searched = wrap_buffer (buf);
|
428
|
379 fixup_search_regs_for_buffer (buf);
|
826
|
380 return val;
|
428
|
381 }
|
|
382
|
|
383 DEFUN ("looking-at", Flooking_at, 1, 2, 0, /*
|
|
384 Return t if text after point matches regular expression REGEXP.
|
|
385 This function modifies the match data that `match-beginning',
|
|
386 `match-end' and `match-data' access; save and restore the match
|
|
387 data if you want to preserve them.
|
|
388
|
|
389 Optional argument BUFFER defaults to the current buffer.
|
|
390 */
|
|
391 (regexp, buffer))
|
|
392 {
|
|
393 return looking_at_1 (regexp, decode_buffer (buffer, 0), 0);
|
|
394 }
|
|
395
|
|
396 DEFUN ("posix-looking-at", Fposix_looking_at, 1, 2, 0, /*
|
|
397 Return t if text after point matches regular expression REGEXP.
|
|
398 Find the longest match, in accord with Posix regular expression rules.
|
|
399 This function modifies the match data that `match-beginning',
|
|
400 `match-end' and `match-data' access; save and restore the match
|
|
401 data if you want to preserve them.
|
|
402
|
|
403 Optional argument BUFFER defaults to the current buffer.
|
|
404 */
|
|
405 (regexp, buffer))
|
|
406 {
|
826
|
407 return looking_at_1 (regexp, decode_buffer (buffer, 0), 1);
|
428
|
408 }
|
|
409
|
|
410 static Lisp_Object
|
|
411 string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start,
|
|
412 struct buffer *buf, int posix)
|
|
413 {
|
|
414 Bytecount val;
|
|
415 Charcount s;
|
|
416 struct re_pattern_buffer *bufp;
|
|
417
|
853
|
418 /* Some FSF junk with running_asynch_code, to preserve the match
|
|
419 data. Not necessary because we don't call process filters
|
|
420 asynchronously (i.e. from within QUIT). */
|
428
|
421
|
1425
|
422 /* clear search registers *now*. no mercy, not even for errors */
|
|
423 clear_search_regs (&search_regs);
|
|
424
|
428
|
425 CHECK_STRING (regexp);
|
|
426 CHECK_STRING (string);
|
|
427
|
|
428 if (NILP (start))
|
|
429 s = 0;
|
|
430 else
|
|
431 {
|
826
|
432 Charcount len = string_char_length (string);
|
428
|
433
|
|
434 CHECK_INT (start);
|
|
435 s = XINT (start);
|
|
436 if (s < 0 && -s <= len)
|
|
437 s = len + s;
|
|
438 else if (0 > s || s > len)
|
|
439 args_out_of_range (string, start);
|
|
440 }
|
|
441
|
|
442
|
|
443 bufp = compile_pattern (regexp, &search_regs,
|
|
444 (!NILP (buf->case_fold_search)
|
446
|
445 ? XCASE_TABLE_DOWNCASE (buf->case_table) : Qnil),
|
826
|
446 string, buf, 0, ERROR_ME);
|
428
|
447 QUIT;
|
|
448 {
|
793
|
449 Bytecount bis = string_index_char_to_byte (string, s);
|
826
|
450 struct syntax_cache scache_struct;
|
|
451 struct syntax_cache *scache = &scache_struct;
|
|
452
|
|
453 /* By making the regex object, regex buffer, and syntax cache arguments
|
|
454 to re_{search,match}{,_2}, we've removed the need to do nasty things
|
|
455 to deal with regex reentrancy. (See stack trace in signal.c for proof
|
|
456 that this can happen.)
|
|
457
|
|
458 #### there is still a potential problem with the regex cache --
|
|
459 the compiled regex could be overwritten. we'd need 20-fold
|
|
460 reentrancy, though. Fix this. */
|
|
461
|
428
|
462 val = re_search (bufp, (char *) XSTRING_DATA (string),
|
|
463 XSTRING_LENGTH (string), bis,
|
|
464 XSTRING_LENGTH (string) - bis,
|
826
|
465 &search_regs, string, buf, scache);
|
428
|
466 }
|
|
467 if (val == -2)
|
|
468 matcher_overflow ();
|
826
|
469 if (val < 0) return Qnil;
|
428
|
470 last_thing_searched = Qt;
|
|
471 fixup_search_regs_for_string (string);
|
826
|
472 return make_int (string_index_byte_to_char (string, val));
|
428
|
473 }
|
|
474
|
|
475 DEFUN ("string-match", Fstring_match, 2, 4, 0, /*
|
|
476 Return index of start of first match for REGEXP in STRING, or nil.
|
|
477 If third arg START is non-nil, start search at that index in STRING.
|
|
478 For index of first char beyond the match, do (match-end 0).
|
|
479 `match-end' and `match-beginning' also give indices of substrings
|
|
480 matched by parenthesis constructs in the pattern.
|
|
481
|
826
|
482 Optional arg BUFFER controls how case folding and syntax and category
|
|
483 lookup is done (according to the value of `case-fold-search' in that buffer
|
|
484 and that buffer's case tables, syntax tables, and category table). If nil
|
|
485 or unspecified, it defaults *NOT* to the current buffer but instead:
|
|
486
|
|
487 -- the value of `case-fold-search' in the current buffer is still respected
|
|
488 because of idioms like
|
|
489
|
|
490 (let ((case-fold-search nil))
|
|
491 (string-match "^foo.*bar" string))
|
|
492
|
|
493 but the case, syntax, and category tables come from the standard tables,
|
|
494 which are accessed through functions `default-{case,syntax,category}-table' and serve as the parents of the
|
|
495 tables in particular buffer
|
|
496
|
428
|
497 */
|
|
498 (regexp, string, start, buffer))
|
|
499 {
|
826
|
500 /* &&#### implement new interp for buffer arg; check code to see if it
|
|
501 makes more sense than prev */
|
428
|
502 return string_match_1 (regexp, string, start, decode_buffer (buffer, 0), 0);
|
|
503 }
|
|
504
|
|
505 DEFUN ("posix-string-match", Fposix_string_match, 2, 4, 0, /*
|
|
506 Return index of start of first match for REGEXP in STRING, or nil.
|
|
507 Find the longest match, in accord with Posix regular expression rules.
|
|
508 If third arg START is non-nil, start search at that index in STRING.
|
|
509 For index of first char beyond the match, do (match-end 0).
|
|
510 `match-end' and `match-beginning' also give indices of substrings
|
|
511 matched by parenthesis constructs in the pattern.
|
|
512
|
|
513 Optional arg BUFFER controls how case folding is done (according to
|
|
514 the value of `case-fold-search' in that buffer and that buffer's case
|
|
515 tables) and defaults to the current buffer.
|
|
516 */
|
|
517 (regexp, string, start, buffer))
|
|
518 {
|
|
519 return string_match_1 (regexp, string, start, decode_buffer (buffer, 0), 1);
|
|
520 }
|
|
521
|
|
522 /* Match REGEXP against STRING, searching all of STRING,
|
|
523 and return the index of the match, or negative on failure.
|
|
524 This does not clobber the match data. */
|
|
525
|
|
526 Bytecount
|
1347
|
527 fast_string_match (Lisp_Object regexp, const Ibyte *nonreloc,
|
428
|
528 Lisp_Object reloc, Bytecount offset,
|
|
529 Bytecount length, int case_fold_search,
|
578
|
530 Error_Behavior errb, int no_quit)
|
428
|
531 {
|
|
532 Bytecount val;
|
867
|
533 Ibyte *newnonreloc = (Ibyte *) nonreloc;
|
428
|
534 struct re_pattern_buffer *bufp;
|
826
|
535 struct syntax_cache scache_struct;
|
|
536 struct syntax_cache *scache = &scache_struct;
|
428
|
537
|
|
538 bufp = compile_pattern (regexp, 0,
|
|
539 (case_fold_search
|
771
|
540 ? XCASE_TABLE_DOWNCASE (Vstandard_case_table)
|
446
|
541 : Qnil),
|
826
|
542 reloc, 0, 0, errb);
|
428
|
543 if (!bufp)
|
|
544 return -1; /* will only do this when errb != ERROR_ME */
|
|
545 if (!no_quit)
|
|
546 QUIT;
|
|
547 else
|
|
548 no_quit_in_re_search = 1;
|
|
549
|
|
550 fixup_internal_substring (nonreloc, reloc, offset, &length);
|
|
551
|
771
|
552 /* Don't need to protect against GC inside of re_search() due to QUIT;
|
|
553 QUIT is GC-inhibited. */
|
428
|
554 if (!NILP (reloc))
|
771
|
555 newnonreloc = XSTRING_DATA (reloc);
|
|
556
|
826
|
557 /* By making the regex object, regex buffer, and syntax cache arguments
|
|
558 to re_{search,match}{,_2}, we've removed the need to do nasty things
|
|
559 to deal with regex reentrancy. (See stack trace in signal.c for proof
|
|
560 that this can happen.)
|
|
561
|
|
562 #### there is still a potential problem with the regex cache --
|
|
563 the compiled regex could be overwritten. we'd need 20-fold
|
|
564 reentrancy, though. Fix this. */
|
|
565
|
428
|
566 val = re_search (bufp, (char *) newnonreloc + offset, length, 0,
|
826
|
567 length, 0, reloc, 0, scache);
|
428
|
568
|
|
569 no_quit_in_re_search = 0;
|
|
570 return val;
|
|
571 }
|
|
572
|
|
573 Bytecount
|
|
574 fast_lisp_string_match (Lisp_Object regex, Lisp_Object string)
|
|
575 {
|
|
576 return fast_string_match (regex, 0, string, 0, -1, 0, ERROR_ME, 0);
|
|
577 }
|
|
578
|
|
579
|
|
580 #ifdef REGION_CACHE_NEEDS_WORK
|
|
581 /* The newline cache: remembering which sections of text have no newlines. */
|
|
582
|
|
583 /* If the user has requested newline caching, make sure it's on.
|
|
584 Otherwise, make sure it's off.
|
|
585 This is our cheezy way of associating an action with the change of
|
|
586 state of a buffer-local variable. */
|
|
587 static void
|
|
588 newline_cache_on_off (struct buffer *buf)
|
|
589 {
|
|
590 if (NILP (buf->cache_long_line_scans))
|
|
591 {
|
|
592 /* It should be off. */
|
|
593 if (buf->newline_cache)
|
|
594 {
|
|
595 free_region_cache (buf->newline_cache);
|
|
596 buf->newline_cache = 0;
|
|
597 }
|
|
598 }
|
|
599 else
|
|
600 {
|
|
601 /* It should be on. */
|
|
602 if (buf->newline_cache == 0)
|
|
603 buf->newline_cache = new_region_cache ();
|
|
604 }
|
|
605 }
|
|
606 #endif
|
|
607
|
|
608 /* Search in BUF for COUNT instances of the character TARGET between
|
|
609 START and END.
|
|
610
|
|
611 If COUNT is positive, search forwards; END must be >= START.
|
|
612 If COUNT is negative, search backwards for the -COUNTth instance;
|
|
613 END must be <= START.
|
|
614 If COUNT is zero, do anything you please; run rogue, for all I care.
|
|
615
|
|
616 If END is zero, use BEGV or ZV instead, as appropriate for the
|
|
617 direction indicated by COUNT.
|
|
618
|
|
619 If we find COUNT instances, set *SHORTAGE to zero, and return the
|
|
620 position after the COUNTth match. Note that for reverse motion
|
|
621 this is not the same as the usual convention for Emacs motion commands.
|
|
622
|
|
623 If we don't find COUNT instances before reaching END, set *SHORTAGE
|
|
624 to the number of TARGETs left unfound, and return END.
|
|
625
|
|
626 If ALLOW_QUIT is non-zero, call QUIT periodically. */
|
|
627
|
665
|
628 static Bytebpos
|
867
|
629 byte_scan_buffer (struct buffer *buf, Ichar target, Bytebpos st, Bytebpos en,
|
872
|
630 EMACS_INT count, EMACS_INT *shortage, int allow_quit)
|
428
|
631 {
|
665
|
632 Bytebpos lim = en > 0 ? en :
|
826
|
633 ((count > 0) ? BYTE_BUF_ZV (buf) : BYTE_BUF_BEGV (buf));
|
428
|
634
|
|
635 /* #### newline cache stuff in this function not yet ported */
|
|
636 assert (count != 0);
|
|
637
|
|
638 if (shortage)
|
|
639 *shortage = 0;
|
|
640
|
|
641 if (count > 0)
|
|
642 {
|
|
643 #ifdef MULE
|
826
|
644 Internal_Format fmt = buf->text->format;
|
|
645 /* Check for char that's unrepresentable in the buffer -- it
|
|
646 certainly can't be there. */
|
867
|
647 if (!ichar_fits_in_format (target, fmt, wrap_buffer (buf)))
|
428
|
648 {
|
826
|
649 *shortage = count;
|
|
650 return lim;
|
|
651 }
|
|
652 /* Due to the Mule representation of characters in a buffer, we can
|
|
653 simply search for characters in the range 0 - 127 directly; for
|
|
654 8-bit-fixed, we can do this for all characters. In other cases,
|
|
655 we do it the "hard" way. Note that this way works for all
|
|
656 characters and all formats, but the other way is faster. */
|
|
657 else if (! (fmt == FORMAT_8_BIT_FIXED ||
|
867
|
658 (fmt == FORMAT_DEFAULT && ichar_ascii_p (target))))
|
826
|
659 {
|
867
|
660 Raw_Ichar raw = ichar_to_raw (target, fmt, wrap_buffer (buf));
|
428
|
661 while (st < lim && count > 0)
|
|
662 {
|
826
|
663 if (BYTE_BUF_FETCH_CHAR_RAW (buf, st) == raw)
|
428
|
664 count--;
|
665
|
665 INC_BYTEBPOS (buf, st);
|
428
|
666 }
|
|
667 }
|
|
668 else
|
|
669 #endif
|
|
670 {
|
867
|
671 Raw_Ichar raw = ichar_to_raw (target, fmt, wrap_buffer (buf));
|
428
|
672 while (st < lim && count > 0)
|
|
673 {
|
665
|
674 Bytebpos ceil;
|
867
|
675 Ibyte *bufptr;
|
428
|
676
|
826
|
677 ceil = BYTE_BUF_CEILING_OF (buf, st);
|
428
|
678 ceil = min (lim, ceil);
|
867
|
679 bufptr = (Ibyte *) memchr (BYTE_BUF_BYTE_ADDRESS (buf, st),
|
826
|
680 raw, ceil - st);
|
428
|
681 if (bufptr)
|
|
682 {
|
|
683 count--;
|
826
|
684 st = BYTE_BUF_PTR_BYTE_POS (buf, bufptr) + 1;
|
428
|
685 }
|
|
686 else
|
|
687 st = ceil;
|
|
688 }
|
|
689 }
|
|
690
|
|
691 if (shortage)
|
|
692 *shortage = count;
|
|
693 if (allow_quit)
|
|
694 QUIT;
|
|
695 return st;
|
|
696 }
|
|
697 else
|
|
698 {
|
|
699 #ifdef MULE
|
826
|
700 Internal_Format fmt = buf->text->format;
|
|
701 /* Check for char that's unrepresentable in the buffer -- it
|
|
702 certainly can't be there. */
|
867
|
703 if (!ichar_fits_in_format (target, fmt, wrap_buffer (buf)))
|
428
|
704 {
|
826
|
705 *shortage = -count;
|
|
706 return lim;
|
|
707 }
|
|
708 else if (! (fmt == FORMAT_8_BIT_FIXED ||
|
867
|
709 (fmt == FORMAT_DEFAULT && ichar_ascii_p (target))))
|
826
|
710 {
|
867
|
711 Raw_Ichar raw = ichar_to_raw (target, fmt, wrap_buffer (buf));
|
428
|
712 while (st > lim && count < 0)
|
|
713 {
|
665
|
714 DEC_BYTEBPOS (buf, st);
|
826
|
715 if (BYTE_BUF_FETCH_CHAR_RAW (buf, st) == raw)
|
428
|
716 count++;
|
|
717 }
|
|
718 }
|
|
719 else
|
|
720 #endif
|
|
721 {
|
867
|
722 Raw_Ichar raw = ichar_to_raw (target, fmt, wrap_buffer (buf));
|
428
|
723 while (st > lim && count < 0)
|
|
724 {
|
665
|
725 Bytebpos floor;
|
867
|
726 Ibyte *bufptr;
|
|
727 Ibyte *floorptr;
|
428
|
728
|
826
|
729 floor = BYTE_BUF_FLOOR_OF (buf, st);
|
428
|
730 floor = max (lim, floor);
|
|
731 /* No memrchr() ... */
|
826
|
732 bufptr = BYTE_BUF_BYTE_ADDRESS_BEFORE (buf, st);
|
|
733 floorptr = BYTE_BUF_BYTE_ADDRESS (buf, floor);
|
428
|
734 while (bufptr >= floorptr)
|
|
735 {
|
|
736 st--;
|
|
737 /* At this point, both ST and BUFPTR refer to the same
|
|
738 character. When the loop terminates, ST will
|
|
739 always point to the last character we tried. */
|
867
|
740 if (*bufptr == (Ibyte) raw)
|
428
|
741 {
|
|
742 count++;
|
|
743 break;
|
|
744 }
|
|
745 bufptr--;
|
|
746 }
|
|
747 }
|
|
748 }
|
|
749
|
|
750 if (shortage)
|
|
751 *shortage = -count;
|
|
752 if (allow_quit)
|
|
753 QUIT;
|
|
754 if (count)
|
|
755 return st;
|
|
756 else
|
|
757 {
|
|
758 /* We found the character we were looking for; we have to return
|
|
759 the position *after* it due to the strange way that the return
|
|
760 value is defined. */
|
665
|
761 INC_BYTEBPOS (buf, st);
|
428
|
762 return st;
|
|
763 }
|
|
764 }
|
|
765 }
|
|
766
|
665
|
767 Charbpos
|
867
|
768 scan_buffer (struct buffer *buf, Ichar target, Charbpos start, Charbpos end,
|
428
|
769 EMACS_INT count, EMACS_INT *shortage, int allow_quit)
|
|
770 {
|
826
|
771 Bytebpos byte_retval;
|
|
772 Bytebpos byte_start, byte_end;
|
|
773
|
|
774 byte_start = charbpos_to_bytebpos (buf, start);
|
428
|
775 if (end)
|
826
|
776 byte_end = charbpos_to_bytebpos (buf, end);
|
428
|
777 else
|
826
|
778 byte_end = 0;
|
|
779 byte_retval = byte_scan_buffer (buf, target, byte_start, byte_end, count,
|
428
|
780 shortage, allow_quit);
|
826
|
781 return bytebpos_to_charbpos (buf, byte_retval);
|
428
|
782 }
|
|
783
|
665
|
784 Bytebpos
|
826
|
785 byte_find_next_newline_no_quit (struct buffer *buf, Bytebpos from, int count)
|
428
|
786 {
|
826
|
787 return byte_scan_buffer (buf, '\n', from, 0, count, 0, 0);
|
428
|
788 }
|
|
789
|
665
|
790 Charbpos
|
|
791 find_next_newline_no_quit (struct buffer *buf, Charbpos from, int count)
|
428
|
792 {
|
|
793 return scan_buffer (buf, '\n', from, 0, count, 0, 0);
|
|
794 }
|
|
795
|
665
|
796 Charbpos
|
|
797 find_next_newline (struct buffer *buf, Charbpos from, int count)
|
428
|
798 {
|
|
799 return scan_buffer (buf, '\n', from, 0, count, 0, 1);
|
|
800 }
|
|
801
|
826
|
802 Bytecount
|
867
|
803 byte_find_next_ichar_in_string (Lisp_Object str, Ichar target, Bytecount st,
|
428
|
804 EMACS_INT count)
|
|
805 {
|
793
|
806 Bytebpos lim = XSTRING_LENGTH (str) -1;
|
867
|
807 Ibyte *s = XSTRING_DATA (str);
|
428
|
808
|
|
809 assert (count >= 0);
|
|
810
|
|
811 #ifdef MULE
|
|
812 /* Due to the Mule representation of characters in a buffer,
|
|
813 we can simply search for characters in the range 0 - 127
|
|
814 directly. For other characters, we do it the "hard" way.
|
|
815 Note that this way works for all characters but the other
|
|
816 way is faster. */
|
|
817 if (target >= 0200)
|
|
818 {
|
|
819 while (st < lim && count > 0)
|
|
820 {
|
867
|
821 if (string_ichar (str, st) == target)
|
428
|
822 count--;
|
826
|
823 INC_BYTECOUNT (s, st);
|
428
|
824 }
|
|
825 }
|
|
826 else
|
|
827 #endif
|
|
828 {
|
|
829 while (st < lim && count > 0)
|
|
830 {
|
867
|
831 Ibyte *bufptr = (Ibyte *) memchr (itext_n_addr (s, st),
|
428
|
832 (int) target, lim - st);
|
|
833 if (bufptr)
|
|
834 {
|
|
835 count--;
|
826
|
836 st = (Bytebpos) (bufptr - s) + 1;
|
428
|
837 }
|
|
838 else
|
|
839 st = lim;
|
|
840 }
|
|
841 }
|
|
842 return st;
|
|
843 }
|
|
844
|
|
845 /* Like find_next_newline, but returns position before the newline,
|
|
846 not after, and only search up to TO. This isn't just
|
|
847 find_next_newline (...)-1, because you might hit TO. */
|
665
|
848 Charbpos
|
826
|
849 find_before_next_newline (struct buffer *buf, Charbpos from, Charbpos to,
|
|
850 int count)
|
428
|
851 {
|
|
852 EMACS_INT shortage;
|
665
|
853 Charbpos pos = scan_buffer (buf, '\n', from, to, count, &shortage, 1);
|
428
|
854
|
|
855 if (shortage == 0)
|
|
856 pos--;
|
|
857
|
|
858 return pos;
|
|
859 }
|
|
860
|
872
|
861 /* This function synched with FSF 21.1 */
|
428
|
862 static Lisp_Object
|
|
863 skip_chars (struct buffer *buf, int forwardp, int syntaxp,
|
|
864 Lisp_Object string, Lisp_Object lim)
|
|
865 {
|
867
|
866 REGISTER Ibyte *p, *pend;
|
|
867 REGISTER Ichar c;
|
428
|
868 /* We store the first 256 chars in an array here and the rest in
|
|
869 a range table. */
|
|
870 unsigned char fastmap[0400];
|
|
871 int negate = 0;
|
|
872 REGISTER int i;
|
665
|
873 Charbpos limit;
|
826
|
874 struct syntax_cache *scache;
|
|
875
|
428
|
876 if (NILP (lim))
|
|
877 limit = forwardp ? BUF_ZV (buf) : BUF_BEGV (buf);
|
|
878 else
|
|
879 {
|
|
880 CHECK_INT_COERCE_MARKER (lim);
|
|
881 limit = XINT (lim);
|
|
882
|
|
883 /* In any case, don't allow scan outside bounds of buffer. */
|
|
884 if (limit > BUF_ZV (buf)) limit = BUF_ZV (buf);
|
|
885 if (limit < BUF_BEGV (buf)) limit = BUF_BEGV (buf);
|
|
886 }
|
|
887
|
|
888 CHECK_STRING (string);
|
|
889 p = XSTRING_DATA (string);
|
|
890 pend = p + XSTRING_LENGTH (string);
|
|
891 memset (fastmap, 0, sizeof (fastmap));
|
|
892
|
|
893 Fclear_range_table (Vskip_chars_range_table);
|
|
894
|
|
895 if (p != pend && *p == '^')
|
|
896 {
|
|
897 negate = 1;
|
|
898 p++;
|
|
899 }
|
|
900
|
|
901 /* Find the characters specified and set their elements of fastmap.
|
|
902 If syntaxp, each character counts as itself.
|
|
903 Otherwise, handle backslashes and ranges specially */
|
|
904
|
|
905 while (p != pend)
|
|
906 {
|
867
|
907 c = itext_ichar (p);
|
|
908 INC_IBYTEPTR (p);
|
428
|
909 if (syntaxp)
|
|
910 {
|
|
911 if (c < 0400 && syntax_spec_code[c] < (unsigned char) Smax)
|
|
912 fastmap[c] = 1;
|
|
913 else
|
831
|
914 invalid_argument ("Invalid syntax designator", make_char (c));
|
428
|
915 }
|
|
916 else
|
|
917 {
|
|
918 if (c == '\\')
|
|
919 {
|
|
920 if (p == pend) break;
|
867
|
921 c = itext_ichar (p);
|
|
922 INC_IBYTEPTR (p);
|
428
|
923 }
|
|
924 if (p != pend && *p == '-')
|
|
925 {
|
867
|
926 Ichar cend;
|
428
|
927
|
872
|
928 /* Skip over the dash. */
|
428
|
929 p++;
|
|
930 if (p == pend) break;
|
867
|
931 cend = itext_ichar (p);
|
428
|
932 while (c <= cend && c < 0400)
|
|
933 {
|
|
934 fastmap[c] = 1;
|
|
935 c++;
|
|
936 }
|
|
937 if (c <= cend)
|
|
938 Fput_range_table (make_int (c), make_int (cend), Qt,
|
|
939 Vskip_chars_range_table);
|
867
|
940 INC_IBYTEPTR (p);
|
428
|
941 }
|
|
942 else
|
|
943 {
|
|
944 if (c < 0400)
|
|
945 fastmap[c] = 1;
|
|
946 else
|
|
947 Fput_range_table (make_int (c), make_int (c), Qt,
|
|
948 Vskip_chars_range_table);
|
|
949 }
|
|
950 }
|
|
951 }
|
|
952
|
872
|
953 /* #### Not in FSF 21.1 */
|
428
|
954 if (syntaxp && fastmap['-'] != 0)
|
|
955 fastmap[' '] = 1;
|
|
956
|
|
957 /* If ^ was the first character, complement the fastmap.
|
|
958 We don't complement the range table, however; we just use negate
|
|
959 in the comparisons below. */
|
|
960
|
|
961 if (negate)
|
647
|
962 for (i = 0; i < (int) (sizeof (fastmap)); i++)
|
428
|
963 fastmap[i] ^= 1;
|
|
964
|
|
965 {
|
665
|
966 Charbpos start_point = BUF_PT (buf);
|
872
|
967 Charbpos pos = start_point;
|
|
968 Charbpos pos_byte = BYTE_BUF_PT (buf);
|
428
|
969
|
|
970 if (syntaxp)
|
|
971 {
|
872
|
972 scache = setup_buffer_syntax_cache (buf, pos, forwardp ? 1 : -1);
|
428
|
973 /* All syntax designators are normal chars so nothing strange
|
|
974 to worry about */
|
|
975 if (forwardp)
|
|
976 {
|
872
|
977 if (pos < limit)
|
|
978 while (fastmap[(unsigned char)
|
|
979 syntax_code_spec
|
|
980 [(int) SYNTAX_FROM_CACHE
|
|
981 (scache, BYTE_BUF_FETCH_CHAR (buf, pos_byte))]])
|
|
982 {
|
|
983 pos++;
|
|
984 INC_BYTEBPOS (buf, pos_byte);
|
879
|
985 if (pos >= limit)
|
872
|
986 break;
|
|
987 UPDATE_SYNTAX_CACHE_FORWARD (scache, pos);
|
|
988 }
|
428
|
989 }
|
|
990 else
|
|
991 {
|
872
|
992 while (pos > limit)
|
460
|
993 {
|
872
|
994 Charbpos savepos = pos_byte;
|
|
995 pos--;
|
|
996 DEC_BYTEBPOS (buf, pos_byte);
|
|
997 UPDATE_SYNTAX_CACHE_BACKWARD (scache, pos);
|
|
998 if (!fastmap[(unsigned char)
|
|
999 syntax_code_spec
|
|
1000 [(int) SYNTAX_FROM_CACHE
|
|
1001 (scache, BYTE_BUF_FETCH_CHAR (buf, pos_byte))]])
|
|
1002 {
|
|
1003 pos++;
|
|
1004 pos_byte = savepos;
|
|
1005 break;
|
|
1006 }
|
460
|
1007 }
|
428
|
1008 }
|
|
1009 }
|
|
1010 else
|
|
1011 {
|
|
1012 if (forwardp)
|
|
1013 {
|
872
|
1014 while (pos < limit)
|
428
|
1015 {
|
872
|
1016 Ichar ch = BYTE_BUF_FETCH_CHAR (buf, pos_byte);
|
428
|
1017 if ((ch < 0400) ? fastmap[ch] :
|
|
1018 (NILP (Fget_range_table (make_int (ch),
|
|
1019 Vskip_chars_range_table,
|
|
1020 Qnil))
|
|
1021 == negate))
|
872
|
1022 {
|
|
1023 pos++;
|
|
1024 INC_BYTEBPOS (buf, pos_byte);
|
|
1025 }
|
428
|
1026 else
|
|
1027 break;
|
|
1028 }
|
|
1029 }
|
|
1030 else
|
|
1031 {
|
872
|
1032 while (pos > limit)
|
428
|
1033 {
|
872
|
1034 Charbpos prev_pos_byte = pos_byte;
|
|
1035 Ichar ch;
|
|
1036
|
|
1037 DEC_BYTEBPOS (buf, prev_pos_byte);
|
|
1038 ch = BYTE_BUF_FETCH_CHAR (buf, prev_pos_byte);
|
428
|
1039 if ((ch < 0400) ? fastmap[ch] :
|
|
1040 (NILP (Fget_range_table (make_int (ch),
|
|
1041 Vskip_chars_range_table,
|
|
1042 Qnil))
|
|
1043 == negate))
|
872
|
1044 {
|
|
1045 pos--;
|
|
1046 pos_byte = prev_pos_byte;
|
|
1047 }
|
428
|
1048 else
|
|
1049 break;
|
|
1050 }
|
|
1051 }
|
|
1052 }
|
|
1053 QUIT;
|
872
|
1054 BOTH_BUF_SET_PT (buf, pos, pos_byte);
|
428
|
1055 return make_int (BUF_PT (buf) - start_point);
|
|
1056 }
|
|
1057 }
|
|
1058
|
|
1059 DEFUN ("skip-chars-forward", Fskip_chars_forward, 1, 3, 0, /*
|
444
|
1060 Move point forward, stopping before a char not in STRING, or at pos LIMIT.
|
428
|
1061 STRING is like the inside of a `[...]' in a regular expression
|
|
1062 except that `]' is never special and `\\' quotes `^', `-' or `\\'.
|
|
1063 Thus, with arg "a-zA-Z", this skips letters stopping before first nonletter.
|
|
1064 With arg "^a-zA-Z", skips nonletters stopping before first letter.
|
|
1065 Returns the distance traveled, either zero or positive.
|
|
1066
|
|
1067 Optional argument BUFFER defaults to the current buffer.
|
|
1068 */
|
444
|
1069 (string, limit, buffer))
|
428
|
1070 {
|
444
|
1071 return skip_chars (decode_buffer (buffer, 0), 1, 0, string, limit);
|
428
|
1072 }
|
|
1073
|
|
1074 DEFUN ("skip-chars-backward", Fskip_chars_backward, 1, 3, 0, /*
|
444
|
1075 Move point backward, stopping after a char not in STRING, or at pos LIMIT.
|
428
|
1076 See `skip-chars-forward' for details.
|
|
1077 Returns the distance traveled, either zero or negative.
|
|
1078
|
|
1079 Optional argument BUFFER defaults to the current buffer.
|
|
1080 */
|
444
|
1081 (string, limit, buffer))
|
428
|
1082 {
|
444
|
1083 return skip_chars (decode_buffer (buffer, 0), 0, 0, string, limit);
|
428
|
1084 }
|
|
1085
|
|
1086
|
|
1087 DEFUN ("skip-syntax-forward", Fskip_syntax_forward, 1, 3, 0, /*
|
|
1088 Move point forward across chars in specified syntax classes.
|
|
1089 SYNTAX is a string of syntax code characters.
|
444
|
1090 Stop before a char whose syntax is not in SYNTAX, or at position LIMIT.
|
428
|
1091 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
|
|
1092 This function returns the distance traveled, either zero or positive.
|
|
1093
|
|
1094 Optional argument BUFFER defaults to the current buffer.
|
|
1095 */
|
444
|
1096 (syntax, limit, buffer))
|
428
|
1097 {
|
444
|
1098 return skip_chars (decode_buffer (buffer, 0), 1, 1, syntax, limit);
|
428
|
1099 }
|
|
1100
|
|
1101 DEFUN ("skip-syntax-backward", Fskip_syntax_backward, 1, 3, 0, /*
|
|
1102 Move point backward across chars in specified syntax classes.
|
|
1103 SYNTAX is a string of syntax code characters.
|
444
|
1104 Stop on reaching a char whose syntax is not in SYNTAX, or at position LIMIT.
|
428
|
1105 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
|
|
1106 This function returns the distance traveled, either zero or negative.
|
|
1107
|
|
1108 Optional argument BUFFER defaults to the current buffer.
|
|
1109 */
|
444
|
1110 (syntax, limit, buffer))
|
428
|
1111 {
|
444
|
1112 return skip_chars (decode_buffer (buffer, 0), 0, 1, syntax, limit);
|
428
|
1113 }
|
|
1114
|
|
1115
|
|
1116 /* Subroutines of Lisp buffer search functions. */
|
|
1117
|
|
1118 static Lisp_Object
|
444
|
1119 search_command (Lisp_Object string, Lisp_Object limit, Lisp_Object noerror,
|
428
|
1120 Lisp_Object count, Lisp_Object buffer, int direction,
|
|
1121 int RE, int posix)
|
|
1122 {
|
665
|
1123 REGISTER Charbpos np;
|
|
1124 Charbpos lim;
|
428
|
1125 EMACS_INT n = direction;
|
|
1126 struct buffer *buf;
|
|
1127
|
|
1128 if (!NILP (count))
|
|
1129 {
|
|
1130 CHECK_INT (count);
|
|
1131 n *= XINT (count);
|
|
1132 }
|
|
1133
|
|
1134 buf = decode_buffer (buffer, 0);
|
|
1135 CHECK_STRING (string);
|
444
|
1136 if (NILP (limit))
|
428
|
1137 lim = n > 0 ? BUF_ZV (buf) : BUF_BEGV (buf);
|
|
1138 else
|
|
1139 {
|
444
|
1140 CHECK_INT_COERCE_MARKER (limit);
|
|
1141 lim = XINT (limit);
|
428
|
1142 if (n > 0 ? lim < BUF_PT (buf) : lim > BUF_PT (buf))
|
563
|
1143 invalid_argument ("Invalid search limit (wrong side of point)",
|
|
1144 Qunbound);
|
428
|
1145 if (lim > BUF_ZV (buf))
|
|
1146 lim = BUF_ZV (buf);
|
|
1147 if (lim < BUF_BEGV (buf))
|
|
1148 lim = BUF_BEGV (buf);
|
|
1149 }
|
|
1150
|
|
1151 np = search_buffer (buf, string, BUF_PT (buf), lim, n, RE,
|
|
1152 (!NILP (buf->case_fold_search)
|
446
|
1153 ? XCASE_TABLE_CANON (buf->case_table)
|
|
1154 : Qnil),
|
428
|
1155 (!NILP (buf->case_fold_search)
|
446
|
1156 ? XCASE_TABLE_EQV (buf->case_table)
|
|
1157 : Qnil), posix);
|
428
|
1158
|
|
1159 if (np <= 0)
|
|
1160 {
|
444
|
1161 if (NILP (noerror))
|
428
|
1162 return signal_failure (string);
|
444
|
1163 if (!EQ (noerror, Qt))
|
428
|
1164 {
|
|
1165 if (lim < BUF_BEGV (buf) || lim > BUF_ZV (buf))
|
|
1166 abort ();
|
|
1167 BUF_SET_PT (buf, lim);
|
|
1168 return Qnil;
|
|
1169 #if 0 /* This would be clean, but maybe programs depend on
|
|
1170 a value of nil here. */
|
|
1171 np = lim;
|
|
1172 #endif
|
|
1173 }
|
|
1174 else
|
|
1175 return Qnil;
|
|
1176 }
|
|
1177
|
|
1178 if (np < BUF_BEGV (buf) || np > BUF_ZV (buf))
|
|
1179 abort ();
|
|
1180
|
|
1181 BUF_SET_PT (buf, np);
|
|
1182
|
|
1183 return make_int (np);
|
|
1184 }
|
|
1185
|
|
1186 static int
|
|
1187 trivial_regexp_p (Lisp_Object regexp)
|
|
1188 {
|
|
1189 Bytecount len = XSTRING_LENGTH (regexp);
|
867
|
1190 Ibyte *s = XSTRING_DATA (regexp);
|
428
|
1191 while (--len >= 0)
|
|
1192 {
|
|
1193 switch (*s++)
|
|
1194 {
|
|
1195 case '.': case '*': case '+': case '?': case '[': case '^': case '$':
|
|
1196 return 0;
|
|
1197 case '\\':
|
|
1198 if (--len < 0)
|
|
1199 return 0;
|
|
1200 switch (*s++)
|
|
1201 {
|
|
1202 case '|': case '(': case ')': case '`': case '\'': case 'b':
|
|
1203 case 'B': case '<': case '>': case 'w': case 'W': case 's':
|
|
1204 case 'S': case '=':
|
|
1205 #ifdef MULE
|
|
1206 /* 97/2/25 jhod Added for category matches */
|
|
1207 case 'c': case 'C':
|
|
1208 #endif /* MULE */
|
|
1209 case '1': case '2': case '3': case '4': case '5':
|
|
1210 case '6': case '7': case '8': case '9':
|
|
1211 return 0;
|
|
1212 }
|
|
1213 }
|
|
1214 }
|
|
1215 return 1;
|
|
1216 }
|
|
1217
|
|
1218 /* Search for the n'th occurrence of STRING in BUF,
|
665
|
1219 starting at position CHARBPOS and stopping at position BUFLIM,
|
428
|
1220 treating PAT as a literal string if RE is false or as
|
|
1221 a regular expression if RE is true.
|
|
1222
|
|
1223 If N is positive, searching is forward and BUFLIM must be greater
|
665
|
1224 than CHARBPOS.
|
428
|
1225 If N is negative, searching is backward and BUFLIM must be less
|
665
|
1226 than CHARBPOS.
|
428
|
1227
|
|
1228 Returns -x if only N-x occurrences found (x > 0),
|
|
1229 or else the position at the beginning of the Nth occurrence
|
|
1230 (if searching backward) or the end (if searching forward).
|
|
1231
|
|
1232 POSIX is nonzero if we want full backtracking (POSIX style)
|
|
1233 for this pattern. 0 means backtrack only enough to get a valid match. */
|
665
|
1234 static Charbpos
|
|
1235 search_buffer (struct buffer *buf, Lisp_Object string, Charbpos charbpos,
|
|
1236 Charbpos buflim, EMACS_INT n, int RE, Lisp_Object trt,
|
446
|
1237 Lisp_Object inverse_trt, int posix)
|
428
|
1238 {
|
|
1239 Bytecount len = XSTRING_LENGTH (string);
|
867
|
1240 Ibyte *base_pat = XSTRING_DATA (string);
|
428
|
1241 REGISTER EMACS_INT i, j;
|
665
|
1242 Bytebpos p1, p2;
|
428
|
1243 Bytecount s1, s2;
|
665
|
1244 Bytebpos pos, lim;
|
428
|
1245
|
853
|
1246 /* Some FSF junk with running_asynch_code, to preserve the match
|
|
1247 data. Not necessary because we don't call process filters
|
|
1248 asynchronously (i.e. from within QUIT). */
|
428
|
1249
|
1425
|
1250 /* Searching 0 times means noop---don't move, don't touch registers. */
|
|
1251 if (n == 0)
|
|
1252 return charbpos;
|
|
1253
|
|
1254 /* clear the search regs now */
|
|
1255 clear_search_regs (&search_regs);
|
|
1256
|
428
|
1257 /* Null string is found at starting position. */
|
|
1258 if (len == 0)
|
|
1259 {
|
665
|
1260 set_search_regs (buf, charbpos, 0);
|
|
1261 return charbpos;
|
428
|
1262 }
|
|
1263
|
665
|
1264 pos = charbpos_to_bytebpos (buf, charbpos);
|
|
1265 lim = charbpos_to_bytebpos (buf, buflim);
|
428
|
1266 if (RE && !trivial_regexp_p (string))
|
|
1267 {
|
|
1268 struct re_pattern_buffer *bufp;
|
826
|
1269
|
|
1270 bufp = compile_pattern (string, &search_regs, trt,
|
|
1271 wrap_buffer (buf), buf, posix, ERROR_ME);
|
428
|
1272
|
|
1273 /* Get pointers and sizes of the two strings
|
|
1274 that make up the visible portion of the buffer. */
|
|
1275
|
826
|
1276 p1 = BYTE_BUF_BEGV (buf);
|
|
1277 p2 = BYTE_BUF_CEILING_OF (buf, p1);
|
428
|
1278 s1 = p2 - p1;
|
826
|
1279 s2 = BYTE_BUF_ZV (buf) - p2;
|
|
1280
|
|
1281 while (n != 0)
|
428
|
1282 {
|
|
1283 Bytecount val;
|
826
|
1284 struct syntax_cache scache_struct;
|
|
1285 struct syntax_cache *scache = &scache_struct;
|
|
1286
|
428
|
1287 QUIT;
|
826
|
1288 /* By making the regex object, regex buffer, and syntax cache
|
|
1289 arguments to re_{search,match}{,_2}, we've removed the need to
|
|
1290 do nasty things to deal with regex reentrancy. (See stack
|
|
1291 trace in signal.c for proof that this can happen.)
|
|
1292
|
|
1293 #### there is still a potential problem with the regex cache --
|
|
1294 the compiled regex could be overwritten. we'd need 20-fold
|
|
1295 reentrancy, though. Fix this. */
|
|
1296
|
428
|
1297 val = re_search_2 (bufp,
|
826
|
1298 (char *) BYTE_BUF_BYTE_ADDRESS (buf, p1), s1,
|
|
1299 (char *) BYTE_BUF_BYTE_ADDRESS (buf, p2), s2,
|
|
1300 pos - BYTE_BUF_BEGV (buf), lim - pos, &search_regs,
|
|
1301 n > 0 ? lim - BYTE_BUF_BEGV (buf) :
|
|
1302 pos - BYTE_BUF_BEGV (buf), wrap_buffer (buf),
|
|
1303 buf, scache);
|
428
|
1304
|
|
1305 if (val == -2)
|
|
1306 {
|
|
1307 matcher_overflow ();
|
|
1308 }
|
|
1309 if (val >= 0)
|
|
1310 {
|
|
1311 int num_regs = search_regs.num_regs;
|
826
|
1312 j = BYTE_BUF_BEGV (buf);
|
428
|
1313 for (i = 0; i < num_regs; i++)
|
|
1314 if (search_regs.start[i] >= 0)
|
|
1315 {
|
|
1316 search_regs.start[i] += j;
|
|
1317 search_regs.end[i] += j;
|
|
1318 }
|
793
|
1319 last_thing_searched = wrap_buffer (buf);
|
428
|
1320 /* Set pos to the new position. */
|
826
|
1321 pos = n > 0 ? search_regs.end[0] : search_regs.start[0];
|
428
|
1322 fixup_search_regs_for_buffer (buf);
|
665
|
1323 /* And charbpos too. */
|
826
|
1324 charbpos = n > 0 ? search_regs.end[0] : search_regs.start[0];
|
428
|
1325 }
|
|
1326 else
|
826
|
1327 return (n > 0 ? 0 - n : n);
|
|
1328 if (n > 0) n--; else n++;
|
428
|
1329 }
|
665
|
1330 return charbpos;
|
428
|
1331 }
|
|
1332 else /* non-RE case */
|
|
1333 {
|
446
|
1334 int charset_base = -1;
|
|
1335 int boyer_moore_ok = 1;
|
867
|
1336 Ibyte *pat = 0;
|
|
1337 Ibyte *patbuf = alloca_array (Ibyte, len * MAX_ICHAR_LEN);
|
446
|
1338 pat = patbuf;
|
|
1339 #ifdef MULE
|
826
|
1340 /* &&#### needs some 8-bit work here */
|
446
|
1341 while (len > 0)
|
|
1342 {
|
867
|
1343 Ibyte tmp_str[MAX_ICHAR_LEN];
|
|
1344 Ichar c, translated, inverse;
|
446
|
1345 Bytecount orig_bytelen, new_bytelen, inv_bytelen;
|
|
1346
|
|
1347 /* If we got here and the RE flag is set, it's because
|
|
1348 we're dealing with a regexp known to be trivial, so the
|
|
1349 backslash just quotes the next character. */
|
|
1350 if (RE && *base_pat == '\\')
|
|
1351 {
|
|
1352 len--;
|
|
1353 base_pat++;
|
|
1354 }
|
867
|
1355 c = itext_ichar (base_pat);
|
446
|
1356 translated = TRANSLATE (trt, c);
|
|
1357 inverse = TRANSLATE (inverse_trt, c);
|
|
1358
|
867
|
1359 orig_bytelen = itext_ichar_len (base_pat);
|
|
1360 inv_bytelen = set_itext_ichar (tmp_str, inverse);
|
|
1361 new_bytelen = set_itext_ichar (tmp_str, translated);
|
446
|
1362
|
|
1363 if (new_bytelen != orig_bytelen || inv_bytelen != orig_bytelen)
|
|
1364 boyer_moore_ok = 0;
|
|
1365 if (translated != c || inverse != c)
|
|
1366 {
|
|
1367 /* Keep track of which character set row
|
|
1368 contains the characters that need translation. */
|
867
|
1369 int charset_base_code = c & ~ICHAR_FIELD3_MASK;
|
446
|
1370 if (charset_base == -1)
|
|
1371 charset_base = charset_base_code;
|
|
1372 else if (charset_base != charset_base_code)
|
|
1373 /* If two different rows appear, needing translation,
|
|
1374 then we cannot use boyer_moore search. */
|
|
1375 boyer_moore_ok = 0;
|
|
1376 }
|
|
1377 memcpy (pat, tmp_str, new_bytelen);
|
|
1378 pat += new_bytelen;
|
|
1379 base_pat += orig_bytelen;
|
|
1380 len -= orig_bytelen;
|
|
1381 }
|
|
1382 #else /* not MULE */
|
|
1383 while (--len >= 0)
|
|
1384 {
|
|
1385 /* If we got here and the RE flag is set, it's because
|
|
1386 we're dealing with a regexp known to be trivial, so the
|
|
1387 backslash just quotes the next character. */
|
|
1388 if (RE && *base_pat == '\\')
|
|
1389 {
|
|
1390 len--;
|
|
1391 base_pat++;
|
|
1392 }
|
|
1393 *pat++ = TRANSLATE (trt, *base_pat++);
|
|
1394 }
|
|
1395 #endif /* MULE */
|
|
1396 len = pat - patbuf;
|
|
1397 pat = base_pat = patbuf;
|
|
1398 if (boyer_moore_ok)
|
|
1399 return boyer_moore (buf, base_pat, len, pos, lim, n,
|
|
1400 trt, inverse_trt, charset_base);
|
|
1401 else
|
|
1402 return simple_search (buf, base_pat, len, pos, lim, n, trt);
|
|
1403 }
|
|
1404 }
|
|
1405
|
826
|
1406 /* Do a simple string search N times for the string PAT, whose length is
|
|
1407 LEN/LEN_BYTE, from buffer position POS until LIM. TRT is the
|
|
1408 translation table.
|
446
|
1409
|
|
1410 Return the character position where the match is found.
|
|
1411 Otherwise, if M matches remained to be found, return -M.
|
|
1412
|
|
1413 This kind of search works regardless of what is in PAT and
|
|
1414 regardless of what is in TRT. It is used in cases where
|
|
1415 boyer_moore cannot work. */
|
|
1416
|
665
|
1417 static Charbpos
|
867
|
1418 simple_search (struct buffer *buf, Ibyte *base_pat, Bytecount len,
|
826
|
1419 Bytebpos pos, Bytebpos lim, EMACS_INT n, Lisp_Object trt)
|
446
|
1420 {
|
|
1421 int forward = n > 0;
|
|
1422 Bytecount buf_len = 0; /* Shut up compiler. */
|
|
1423
|
826
|
1424 if (lim > pos)
|
446
|
1425 while (n > 0)
|
428
|
1426 {
|
446
|
1427 while (1)
|
428
|
1428 {
|
826
|
1429 Bytecount this_len = len;
|
|
1430 Bytebpos this_pos = pos;
|
867
|
1431 Ibyte *p = base_pat;
|
826
|
1432 if (pos >= lim)
|
446
|
1433 goto stop;
|
|
1434
|
|
1435 while (this_len > 0)
|
|
1436 {
|
867
|
1437 Ichar pat_ch, buf_ch;
|
446
|
1438 Bytecount pat_len;
|
|
1439
|
867
|
1440 pat_ch = itext_ichar (p);
|
826
|
1441 buf_ch = BYTE_BUF_FETCH_CHAR (buf, this_pos);
|
446
|
1442
|
|
1443 buf_ch = TRANSLATE (trt, buf_ch);
|
|
1444
|
|
1445 if (buf_ch != pat_ch)
|
|
1446 break;
|
|
1447
|
867
|
1448 pat_len = itext_ichar_len (p);
|
446
|
1449 p += pat_len;
|
|
1450 this_len -= pat_len;
|
826
|
1451 INC_BYTEBPOS (buf, this_pos);
|
446
|
1452 }
|
|
1453 if (this_len == 0)
|
428
|
1454 {
|
826
|
1455 buf_len = this_pos - pos;
|
|
1456 pos = this_pos;
|
446
|
1457 break;
|
428
|
1458 }
|
826
|
1459 INC_BYTEBPOS (buf, pos);
|
428
|
1460 }
|
446
|
1461 n--;
|
|
1462 }
|
|
1463 else
|
|
1464 while (n < 0)
|
|
1465 {
|
|
1466 while (1)
|
|
1467 {
|
826
|
1468 Bytecount this_len = len;
|
|
1469 Bytebpos this_pos = pos;
|
867
|
1470 Ibyte *p;
|
826
|
1471 if (pos <= lim)
|
446
|
1472 goto stop;
|
826
|
1473 p = base_pat + len;
|
446
|
1474
|
|
1475 while (this_len > 0)
|
|
1476 {
|
867
|
1477 Ichar pat_ch, buf_ch;
|
|
1478
|
|
1479 DEC_IBYTEPTR (p);
|
826
|
1480 DEC_BYTEBPOS (buf, this_pos);
|
867
|
1481 pat_ch = itext_ichar (p);
|
826
|
1482 buf_ch = BYTE_BUF_FETCH_CHAR (buf, this_pos);
|
446
|
1483
|
|
1484 buf_ch = TRANSLATE (trt, buf_ch);
|
|
1485
|
|
1486 if (buf_ch != pat_ch)
|
|
1487 break;
|
|
1488
|
867
|
1489 this_len -= itext_ichar_len (p);
|
446
|
1490 }
|
|
1491 if (this_len == 0)
|
|
1492 {
|
826
|
1493 buf_len = pos - this_pos;
|
|
1494 pos = this_pos;
|
446
|
1495 break;
|
|
1496 }
|
826
|
1497 DEC_BYTEBPOS (buf, pos);
|
446
|
1498 }
|
|
1499 n++;
|
428
|
1500 }
|
446
|
1501 stop:
|
|
1502 if (n == 0)
|
|
1503 {
|
665
|
1504 Charbpos beg, end, retval;
|
446
|
1505 if (forward)
|
|
1506 {
|
826
|
1507 beg = bytebpos_to_charbpos (buf, pos - buf_len);
|
|
1508 retval = end = bytebpos_to_charbpos (buf, pos);
|
446
|
1509 }
|
|
1510 else
|
428
|
1511 {
|
826
|
1512 retval = beg = bytebpos_to_charbpos (buf, pos);
|
|
1513 end = bytebpos_to_charbpos (buf, pos + buf_len);
|
428
|
1514 }
|
446
|
1515 set_search_regs (buf, beg, end - beg);
|
|
1516
|
|
1517 return retval;
|
|
1518 }
|
|
1519 else if (n > 0)
|
|
1520 return -n;
|
|
1521 else
|
|
1522 return n;
|
|
1523 }
|
|
1524
|
|
1525 /* Do Boyer-Moore search N times for the string PAT,
|
|
1526 whose length is LEN/LEN_BYTE,
|
|
1527 from buffer position POS/POS_BYTE until LIM/LIM_BYTE.
|
|
1528 DIRECTION says which direction we search in.
|
|
1529 TRT and INVERSE_TRT are translation tables.
|
|
1530
|
|
1531 This kind of search works if all the characters in PAT that have
|
|
1532 nontrivial translation are the same aside from the last byte. This
|
|
1533 makes it possible to translate just the last byte of a character,
|
|
1534 and do so after just a simple test of the context.
|
|
1535
|
|
1536 If that criterion is not satisfied, do not call this function. */
|
|
1537
|
665
|
1538 static Charbpos
|
867
|
1539 boyer_moore (struct buffer *buf, Ibyte *base_pat, Bytecount len,
|
665
|
1540 Bytebpos pos, Bytebpos lim, EMACS_INT n, Lisp_Object trt,
|
446
|
1541 Lisp_Object inverse_trt, int charset_base)
|
|
1542 {
|
826
|
1543 /* &&#### needs some 8-bit work here */
|
446
|
1544 /* #### Someone really really really needs to comment the workings
|
|
1545 of this junk somewhat better.
|
|
1546
|
|
1547 BTW "BM" stands for Boyer-Moore, which is one of the standard
|
|
1548 string-searching algorithms. It's the best string-searching
|
|
1549 algorithm out there, provided that:
|
|
1550
|
|
1551 a) You're not fazed by algorithm complexity. (Rabin-Karp, which
|
|
1552 uses hashing, is much much easier to code but not as fast.)
|
|
1553 b) You can freely move backwards in the string that you're
|
|
1554 searching through.
|
|
1555
|
|
1556 As the comment below tries to explain (but garbles in typical
|
|
1557 programmer-ese), the idea is that you don't have to do a
|
|
1558 string match at every successive position in the text. For
|
|
1559 example, let's say the pattern is "a very long string". We
|
|
1560 compare the last character in the string (`g') with the
|
|
1561 corresponding character in the text. If it mismatches, and
|
|
1562 it is, say, `z', then we can skip forward by the entire
|
|
1563 length of the pattern because `z' does not occur anywhere
|
|
1564 in the pattern. If the mismatching character does occur
|
|
1565 in the pattern, we can usually still skip forward by more
|
|
1566 than one: e.g. if it is `l', then we can skip forward
|
|
1567 by the length of the substring "ong string" -- i.e. the
|
|
1568 largest end section of the pattern that does not contain
|
|
1569 the mismatched character. So what we do is compute, for
|
|
1570 each possible character, the distance we can skip forward
|
|
1571 (the "stride") and use it in the string matching. This
|
|
1572 is what the BM_tab holds. */
|
|
1573 REGISTER EMACS_INT *BM_tab;
|
|
1574 EMACS_INT *BM_tab_base;
|
|
1575 REGISTER Bytecount dirlen;
|
|
1576 EMACS_INT infinity;
|
665
|
1577 Bytebpos limit;
|
446
|
1578 Bytecount stride_for_teases = 0;
|
|
1579 REGISTER EMACS_INT i, j;
|
867
|
1580 Ibyte *pat, *pat_end;
|
|
1581 REGISTER Ibyte *cursor, *p_limit, *ptr2;
|
|
1582 Ibyte simple_translate[0400];
|
446
|
1583 REGISTER int direction = ((n > 0) ? 1 : -1);
|
|
1584 #ifdef MULE
|
867
|
1585 Ibyte translate_prev_byte = 0;
|
|
1586 Ibyte translate_anteprev_byte = 0;
|
446
|
1587 #endif
|
|
1588 #ifdef C_ALLOCA
|
|
1589 EMACS_INT BM_tab_space[0400];
|
|
1590 BM_tab = &BM_tab_space[0];
|
|
1591 #else
|
|
1592 BM_tab = alloca_array (EMACS_INT, 256);
|
|
1593 #endif
|
|
1594
|
|
1595 /* The general approach is that we are going to maintain that we
|
|
1596 know the first (closest to the present position, in whatever
|
|
1597 direction we're searching) character that could possibly be
|
|
1598 the last (furthest from present position) character of a
|
|
1599 valid match. We advance the state of our knowledge by
|
|
1600 looking at that character and seeing whether it indeed
|
|
1601 matches the last character of the pattern. If it does, we
|
|
1602 take a closer look. If it does not, we move our pointer (to
|
|
1603 putative last characters) as far as is logically possible.
|
|
1604 This amount of movement, which I call a stride, will be the
|
|
1605 length of the pattern if the actual character appears nowhere
|
|
1606 in the pattern, otherwise it will be the distance from the
|
|
1607 last occurrence of that character to the end of the pattern.
|
|
1608 As a coding trick, an enormous stride is coded into the table
|
|
1609 for characters that match the last character. This allows
|
|
1610 use of only a single test, a test for having gone past the
|
|
1611 end of the permissible match region, to test for both
|
|
1612 possible matches (when the stride goes past the end
|
|
1613 immediately) and failure to match (where you get nudged past
|
|
1614 the end one stride at a time).
|
|
1615
|
|
1616 Here we make a "mickey mouse" BM table. The stride of the
|
|
1617 search is determined only by the last character of the
|
|
1618 putative match. If that character does not match, we will
|
|
1619 stride the proper distance to propose a match that
|
|
1620 superimposes it on the last instance of a character that
|
|
1621 matches it (per trt), or misses it entirely if there is
|
|
1622 none. */
|
|
1623
|
|
1624 dirlen = len * direction;
|
|
1625 infinity = dirlen - (lim + pos + len + len) * direction;
|
|
1626 /* Record position after the end of the pattern. */
|
|
1627 pat_end = base_pat + len;
|
|
1628 if (direction < 0)
|
|
1629 base_pat = pat_end - 1;
|
|
1630 BM_tab_base = BM_tab;
|
|
1631 BM_tab += 0400;
|
|
1632 j = dirlen; /* to get it in a register */
|
|
1633 /* A character that does not appear in the pattern induces a
|
|
1634 stride equal to the pattern length. */
|
|
1635 while (BM_tab_base != BM_tab)
|
|
1636 {
|
|
1637 *--BM_tab = j;
|
|
1638 *--BM_tab = j;
|
|
1639 *--BM_tab = j;
|
|
1640 *--BM_tab = j;
|
|
1641 }
|
|
1642 /* We use this for translation, instead of TRT itself. We
|
|
1643 fill this in to handle the characters that actually occur
|
|
1644 in the pattern. Others don't matter anyway! */
|
|
1645 xzero (simple_translate);
|
|
1646 for (i = 0; i < 0400; i++)
|
867
|
1647 simple_translate[i] = (Ibyte) i;
|
446
|
1648 i = 0;
|
1425
|
1649
|
|
1650 /* clear search regs now */
|
|
1651 clear_search_regs (&search_regs);
|
|
1652
|
446
|
1653 while (i != infinity)
|
|
1654 {
|
867
|
1655 Ibyte *ptr = base_pat + i;
|
446
|
1656 i += direction;
|
|
1657 if (i == dirlen)
|
|
1658 i = infinity;
|
|
1659 if (!NILP (trt))
|
428
|
1660 {
|
446
|
1661 #ifdef MULE
|
867
|
1662 Ichar ch, untranslated;
|
446
|
1663 int this_translated = 1;
|
|
1664
|
|
1665 /* Is *PTR the last byte of a character? */
|
867
|
1666 if (pat_end - ptr == 1 || ibyte_first_byte_p (ptr[1]))
|
428
|
1667 {
|
867
|
1668 Ibyte *charstart = ptr;
|
|
1669 while (!ibyte_first_byte_p (*charstart))
|
446
|
1670 charstart--;
|
867
|
1671 untranslated = itext_ichar (charstart);
|
|
1672 if (charset_base == (untranslated & ~ICHAR_FIELD3_MASK))
|
446
|
1673 {
|
|
1674 ch = TRANSLATE (trt, untranslated);
|
867
|
1675 if (!ibyte_first_byte_p (*ptr))
|
446
|
1676 {
|
|
1677 translate_prev_byte = ptr[-1];
|
867
|
1678 if (!ibyte_first_byte_p (translate_prev_byte))
|
446
|
1679 translate_anteprev_byte = ptr[-2];
|
|
1680 }
|
|
1681 }
|
|
1682 else
|
|
1683 {
|
|
1684 this_translated = 0;
|
|
1685 ch = *ptr;
|
|
1686 }
|
428
|
1687 }
|
|
1688 else
|
|
1689 {
|
446
|
1690 ch = *ptr;
|
|
1691 this_translated = 0;
|
|
1692 }
|
|
1693 if (ch > 0400)
|
|
1694 j = ((unsigned char) ch | 0200);
|
|
1695 else
|
|
1696 j = (unsigned char) ch;
|
|
1697
|
|
1698 if (i == infinity)
|
|
1699 stride_for_teases = BM_tab[j];
|
|
1700 BM_tab[j] = dirlen - i;
|
|
1701 /* A translation table is accompanied by its inverse --
|
826
|
1702 see comment in casetab.c. */
|
446
|
1703 if (this_translated)
|
|
1704 {
|
867
|
1705 Ichar starting_ch = ch;
|
446
|
1706 EMACS_INT starting_j = j;
|
|
1707 while (1)
|
|
1708 {
|
|
1709 ch = TRANSLATE (inverse_trt, ch);
|
|
1710 if (ch > 0400)
|
|
1711 j = ((unsigned char) ch | 0200);
|
|
1712 else
|
|
1713 j = (unsigned char) ch;
|
|
1714
|
|
1715 /* For all the characters that map into CH,
|
|
1716 set up simple_translate to map the last byte
|
|
1717 into STARTING_J. */
|
867
|
1718 simple_translate[j] = (Ibyte) starting_j;
|
446
|
1719 if (ch == starting_ch)
|
|
1720 break;
|
|
1721 BM_tab[j] = dirlen - i;
|
|
1722 }
|
|
1723 }
|
|
1724 #else
|
|
1725 EMACS_INT k;
|
|
1726 j = *ptr;
|
|
1727 k = (j = TRANSLATE (trt, j));
|
|
1728 if (i == infinity)
|
|
1729 stride_for_teases = BM_tab[j];
|
|
1730 BM_tab[j] = dirlen - i;
|
|
1731 /* A translation table is accompanied by its inverse --
|
826
|
1732 see comment in casetab.c. */
|
446
|
1733 while ((j = TRANSLATE (inverse_trt, j)) != k)
|
|
1734 {
|
867
|
1735 simple_translate[j] = (Ibyte) k;
|
428
|
1736 BM_tab[j] = dirlen - i;
|
|
1737 }
|
446
|
1738 #endif
|
|
1739 }
|
|
1740 else
|
|
1741 {
|
|
1742 j = *ptr;
|
|
1743
|
|
1744 if (i == infinity)
|
|
1745 stride_for_teases = BM_tab[j];
|
|
1746 BM_tab[j] = dirlen - i;
|
428
|
1747 }
|
446
|
1748 /* stride_for_teases tells how much to stride if we get a
|
|
1749 match on the far character but are subsequently
|
|
1750 disappointed, by recording what the stride would have been
|
|
1751 for that character if the last character had been
|
|
1752 different. */
|
|
1753 }
|
|
1754 infinity = dirlen - infinity;
|
|
1755 pos += dirlen - ((direction > 0) ? direction : 0);
|
|
1756 /* loop invariant - pos points at where last char (first char if
|
|
1757 reverse) of pattern would align in a possible match. */
|
|
1758 while (n != 0)
|
|
1759 {
|
665
|
1760 Bytebpos tail_end;
|
867
|
1761 Ibyte *tail_end_ptr;
|
446
|
1762 /* It's been reported that some (broken) compiler thinks
|
|
1763 that Boolean expressions in an arithmetic context are
|
|
1764 unsigned. Using an explicit ?1:0 prevents this. */
|
|
1765 if ((lim - pos - ((direction > 0) ? 1 : 0)) * direction < 0)
|
|
1766 return n * (0 - direction);
|
|
1767 /* First we do the part we can by pointers (maybe
|
|
1768 nothing) */
|
|
1769 QUIT;
|
|
1770 pat = base_pat;
|
|
1771 limit = pos - dirlen + direction;
|
|
1772 /* XEmacs change: definitions of CEILING_OF and FLOOR_OF
|
|
1773 have changed. See buffer.h. */
|
|
1774 limit = ((direction > 0)
|
826
|
1775 ? BYTE_BUF_CEILING_OF (buf, limit) - 1
|
|
1776 : BYTE_BUF_FLOOR_OF (buf, limit + 1));
|
446
|
1777 /* LIMIT is now the last (not beyond-last!) value POS can
|
|
1778 take on without hitting edge of buffer or the gap. */
|
|
1779 limit = ((direction > 0)
|
|
1780 ? min (lim - 1, min (limit, pos + 20000))
|
|
1781 : max (lim, max (limit, pos - 20000)));
|
826
|
1782 tail_end = BYTE_BUF_CEILING_OF (buf, pos);
|
|
1783 tail_end_ptr = BYTE_BUF_BYTE_ADDRESS (buf, tail_end);
|
446
|
1784
|
|
1785 if ((limit - pos) * direction > 20)
|
428
|
1786 {
|
826
|
1787 /* We have to be careful because the code can generate addresses
|
|
1788 that don't point to the beginning of characters. */
|
|
1789 p_limit = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, limit);
|
|
1790 ptr2 = (cursor = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, pos));
|
446
|
1791 /* In this loop, pos + cursor - ptr2 is the surrogate
|
|
1792 for pos */
|
|
1793 while (1) /* use one cursor setting as long as i can */
|
|
1794 {
|
|
1795 if (direction > 0) /* worth duplicating */
|
|
1796 {
|
|
1797 /* Use signed comparison if appropriate to make
|
|
1798 cursor+infinity sure to be > p_limit.
|
|
1799 Assuming that the buffer lies in a range of
|
|
1800 addresses that are all "positive" (as ints)
|
|
1801 or all "negative", either kind of comparison
|
|
1802 will work as long as we don't step by
|
|
1803 infinity. So pick the kind that works when
|
|
1804 we do step by infinity. */
|
|
1805 if ((EMACS_INT) (p_limit + infinity) >
|
|
1806 (EMACS_INT) p_limit)
|
|
1807 while ((EMACS_INT) cursor <=
|
|
1808 (EMACS_INT) p_limit)
|
|
1809 cursor += BM_tab[*cursor];
|
|
1810 else
|
|
1811 while ((EMACS_UINT) cursor <=
|
|
1812 (EMACS_UINT) p_limit)
|
|
1813 cursor += BM_tab[*cursor];
|
|
1814 }
|
|
1815 else
|
|
1816 {
|
|
1817 if ((EMACS_INT) (p_limit + infinity) <
|
|
1818 (EMACS_INT) p_limit)
|
|
1819 while ((EMACS_INT) cursor >=
|
|
1820 (EMACS_INT) p_limit)
|
|
1821 cursor += BM_tab[*cursor];
|
|
1822 else
|
|
1823 while ((EMACS_UINT) cursor >=
|
|
1824 (EMACS_UINT) p_limit)
|
|
1825 cursor += BM_tab[*cursor];
|
|
1826 }
|
|
1827 /* If you are here, cursor is beyond the end of the
|
|
1828 searched region. This can happen if you match on
|
|
1829 the far character of the pattern, because the
|
|
1830 "stride" of that character is infinity, a number
|
|
1831 able to throw you well beyond the end of the
|
|
1832 search. It can also happen if you fail to match
|
|
1833 within the permitted region and would otherwise
|
|
1834 try a character beyond that region */
|
|
1835 if ((cursor - p_limit) * direction <= len)
|
|
1836 break; /* a small overrun is genuine */
|
|
1837 cursor -= infinity; /* large overrun = hit */
|
|
1838 i = dirlen - direction;
|
|
1839 if (!NILP (trt))
|
|
1840 {
|
|
1841 while ((i -= direction) + direction != 0)
|
|
1842 {
|
|
1843 #ifdef MULE
|
867
|
1844 Ichar ch;
|
446
|
1845 cursor -= direction;
|
|
1846 /* Translate only the last byte of a character. */
|
|
1847 if ((cursor == tail_end_ptr
|
867
|
1848 || ibyte_first_byte_p (cursor[1]))
|
|
1849 && (ibyte_first_byte_p (cursor[0])
|
446
|
1850 || (translate_prev_byte == cursor[-1]
|
867
|
1851 && (ibyte_first_byte_p (translate_prev_byte)
|
446
|
1852 || translate_anteprev_byte == cursor[-2]))))
|
|
1853 ch = simple_translate[*cursor];
|
|
1854 else
|
|
1855 ch = *cursor;
|
|
1856 if (pat[i] != ch)
|
|
1857 break;
|
|
1858 #else
|
|
1859 if (pat[i] != TRANSLATE (trt, *(cursor -= direction)))
|
|
1860 break;
|
|
1861 #endif
|
|
1862 }
|
|
1863 }
|
|
1864 else
|
|
1865 {
|
|
1866 while ((i -= direction) + direction != 0)
|
|
1867 if (pat[i] != *(cursor -= direction))
|
|
1868 break;
|
|
1869 }
|
|
1870 cursor += dirlen - i - direction; /* fix cursor */
|
|
1871 if (i + direction == 0)
|
|
1872 {
|
|
1873 cursor -= direction;
|
|
1874
|
|
1875 {
|
665
|
1876 Bytebpos bytstart = (pos + cursor - ptr2 +
|
446
|
1877 ((direction > 0)
|
|
1878 ? 1 - len : 0));
|
665
|
1879 Charbpos bufstart = bytebpos_to_charbpos (buf, bytstart);
|
|
1880 Charbpos bufend = bytebpos_to_charbpos (buf, bytstart + len);
|
446
|
1881
|
|
1882 set_search_regs (buf, bufstart, bufend - bufstart);
|
|
1883 }
|
|
1884
|
|
1885 if ((n -= direction) != 0)
|
|
1886 cursor += dirlen; /* to resume search */
|
|
1887 else
|
|
1888 return ((direction > 0)
|
|
1889 ? search_regs.end[0] : search_regs.start[0]);
|
|
1890 }
|
|
1891 else
|
|
1892 cursor += stride_for_teases; /* <sigh> we lose - */
|
|
1893 }
|
|
1894 pos += cursor - ptr2;
|
|
1895 }
|
|
1896 else
|
|
1897 /* Now we'll pick up a clump that has to be done the hard
|
|
1898 way because it covers a discontinuity */
|
|
1899 {
|
428
|
1900 /* XEmacs change: definitions of CEILING_OF and FLOOR_OF
|
|
1901 have changed. See buffer.h. */
|
|
1902 limit = ((direction > 0)
|
826
|
1903 ? BYTE_BUF_CEILING_OF (buf, pos - dirlen + 1) - 1
|
|
1904 : BYTE_BUF_FLOOR_OF (buf, pos - dirlen));
|
428
|
1905 limit = ((direction > 0)
|
446
|
1906 ? min (limit + len, lim - 1)
|
|
1907 : max (limit - len, lim));
|
|
1908 /* LIMIT is now the last value POS can have
|
|
1909 and still be valid for a possible match. */
|
|
1910 while (1)
|
428
|
1911 {
|
446
|
1912 /* This loop can be coded for space rather than
|
|
1913 speed because it will usually run only once.
|
|
1914 (the reach is at most len + 21, and typically
|
|
1915 does not exceed len) */
|
|
1916 while ((limit - pos) * direction >= 0)
|
826
|
1917 /* *not* BYTE_BUF_FETCH_CHAR. We are working here
|
446
|
1918 with bytes, not characters. */
|
826
|
1919 pos += BM_tab[*BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, pos)];
|
446
|
1920 /* now run the same tests to distinguish going off
|
|
1921 the end, a match or a phony match. */
|
|
1922 if ((pos - limit) * direction <= len)
|
|
1923 break; /* ran off the end */
|
|
1924 /* Found what might be a match.
|
|
1925 Set POS back to last (first if reverse) char pos. */
|
|
1926 pos -= infinity;
|
|
1927 i = dirlen - direction;
|
|
1928 while ((i -= direction) + direction != 0)
|
428
|
1929 {
|
446
|
1930 #ifdef MULE
|
867
|
1931 Ichar ch;
|
|
1932 Ibyte *ptr;
|
446
|
1933 #endif
|
|
1934 pos -= direction;
|
|
1935 #ifdef MULE
|
826
|
1936 ptr = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, pos);
|
446
|
1937 if ((ptr == tail_end_ptr
|
867
|
1938 || ibyte_first_byte_p (ptr[1]))
|
|
1939 && (ibyte_first_byte_p (ptr[0])
|
446
|
1940 || (translate_prev_byte == ptr[-1]
|
867
|
1941 && (ibyte_first_byte_p (translate_prev_byte)
|
446
|
1942 || translate_anteprev_byte == ptr[-2]))))
|
|
1943 ch = simple_translate[*ptr];
|
428
|
1944 else
|
446
|
1945 ch = *ptr;
|
|
1946 if (pat[i] != ch)
|
|
1947 break;
|
|
1948
|
|
1949 #else
|
826
|
1950 if (pat[i] !=
|
|
1951 TRANSLATE (trt,
|
|
1952 *BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, pos)))
|
446
|
1953 break;
|
|
1954 #endif
|
428
|
1955 }
|
446
|
1956 /* Above loop has moved POS part or all the way back
|
|
1957 to the first char pos (last char pos if reverse).
|
|
1958 Set it once again at the last (first if reverse)
|
|
1959 char. */
|
|
1960 pos += dirlen - i- direction;
|
|
1961 if (i + direction == 0)
|
428
|
1962 {
|
446
|
1963 pos -= direction;
|
|
1964
|
|
1965 {
|
665
|
1966 Bytebpos bytstart = (pos +
|
446
|
1967 ((direction > 0)
|
|
1968 ? 1 - len : 0));
|
665
|
1969 Charbpos bufstart = bytebpos_to_charbpos (buf, bytstart);
|
|
1970 Charbpos bufend = bytebpos_to_charbpos (buf, bytstart + len);
|
446
|
1971
|
|
1972 set_search_regs (buf, bufstart, bufend - bufstart);
|
|
1973 }
|
|
1974
|
|
1975 if ((n -= direction) != 0)
|
|
1976 pos += dirlen; /* to resume search */
|
428
|
1977 else
|
446
|
1978 return ((direction > 0)
|
|
1979 ? search_regs.end[0] : search_regs.start[0]);
|
428
|
1980 }
|
446
|
1981 else
|
|
1982 pos += stride_for_teases;
|
|
1983 }
|
428
|
1984 }
|
446
|
1985 /* We have done one clump. Can we continue? */
|
|
1986 if ((lim - pos) * direction < 0)
|
|
1987 return (0 - n) * direction;
|
428
|
1988 }
|
665
|
1989 return bytebpos_to_charbpos (buf, pos);
|
428
|
1990 }
|
|
1991
|
1024
|
1992 /* Record the whole-match data (beginning BEG and end BEG + LEN) and the
|
|
1993 buffer for a match just found. */
|
428
|
1994
|
|
1995 static void
|
665
|
1996 set_search_regs (struct buffer *buf, Charbpos beg, Charcount len)
|
428
|
1997 {
|
|
1998 /* Make sure we have registers in which to store
|
|
1999 the match position. */
|
|
2000 if (search_regs.num_regs == 0)
|
|
2001 {
|
|
2002 search_regs.start = xnew (regoff_t);
|
|
2003 search_regs.end = xnew (regoff_t);
|
|
2004 search_regs.num_regs = 1;
|
|
2005 }
|
|
2006
|
|
2007 search_regs.start[0] = beg;
|
|
2008 search_regs.end[0] = beg + len;
|
793
|
2009 last_thing_searched = wrap_buffer (buf);
|
428
|
2010 }
|
|
2011
|
1425
|
2012 /* Clear search registers so match data will be null.
|
1024
|
2013 REGP is a pointer to the register structure to clear, usually the global
|
1425
|
2014 search_regs. */
|
1024
|
2015
|
|
2016 static void
|
1425
|
2017 clear_search_regs (struct re_registers *regp)
|
1024
|
2018 {
|
|
2019 /* This function has been Mule-ized. */
|
|
2020 int i;
|
|
2021
|
1425
|
2022 for (i = 0; i < regp->num_regs; i++)
|
1024
|
2023 regp->start[i] = regp->end[i] = -1;
|
|
2024 }
|
|
2025
|
428
|
2026
|
|
2027 /* Given a string of words separated by word delimiters,
|
442
|
2028 compute a regexp that matches those exact words
|
|
2029 separated by arbitrary punctuation. */
|
428
|
2030
|
|
2031 static Lisp_Object
|
|
2032 wordify (Lisp_Object buffer, Lisp_Object string)
|
|
2033 {
|
|
2034 Charcount i, len;
|
|
2035 EMACS_INT punct_count = 0, word_count = 0;
|
|
2036 struct buffer *buf = decode_buffer (buffer, 0);
|
826
|
2037 Lisp_Object syntax_table = buf->mirror_syntax_table;
|
428
|
2038
|
|
2039 CHECK_STRING (string);
|
826
|
2040 len = string_char_length (string);
|
428
|
2041
|
|
2042 for (i = 0; i < len; i++)
|
867
|
2043 if (!WORD_SYNTAX_P (syntax_table, string_ichar (string, i)))
|
428
|
2044 {
|
|
2045 punct_count++;
|
|
2046 if (i > 0 && WORD_SYNTAX_P (syntax_table,
|
867
|
2047 string_ichar (string, i - 1)))
|
428
|
2048 word_count++;
|
|
2049 }
|
867
|
2050 if (WORD_SYNTAX_P (syntax_table, string_ichar (string, len - 1)))
|
428
|
2051 word_count++;
|
|
2052 if (!word_count) return build_string ("");
|
|
2053
|
|
2054 {
|
|
2055 /* The following value is an upper bound on the amount of storage we
|
|
2056 need. In non-Mule, it is exact. */
|
867
|
2057 Ibyte *storage =
|
|
2058 (Ibyte *) ALLOCA (XSTRING_LENGTH (string) - punct_count +
|
428
|
2059 5 * (word_count - 1) + 4);
|
867
|
2060 Ibyte *o = storage;
|
428
|
2061
|
|
2062 *o++ = '\\';
|
|
2063 *o++ = 'b';
|
|
2064
|
|
2065 for (i = 0; i < len; i++)
|
|
2066 {
|
867
|
2067 Ichar ch = string_ichar (string, i);
|
428
|
2068
|
|
2069 if (WORD_SYNTAX_P (syntax_table, ch))
|
867
|
2070 o += set_itext_ichar (o, ch);
|
428
|
2071 else if (i > 0
|
|
2072 && WORD_SYNTAX_P (syntax_table,
|
867
|
2073 string_ichar (string, i - 1))
|
428
|
2074 && --word_count)
|
|
2075 {
|
|
2076 *o++ = '\\';
|
|
2077 *o++ = 'W';
|
|
2078 *o++ = '\\';
|
|
2079 *o++ = 'W';
|
|
2080 *o++ = '*';
|
|
2081 }
|
|
2082 }
|
|
2083
|
|
2084 *o++ = '\\';
|
|
2085 *o++ = 'b';
|
|
2086
|
|
2087 return make_string (storage, o - storage);
|
|
2088 }
|
|
2089 }
|
|
2090
|
|
2091 DEFUN ("search-backward", Fsearch_backward, 1, 5, "sSearch backward: ", /*
|
|
2092 Search backward from point for STRING.
|
|
2093 Set point to the beginning of the occurrence found, and return point.
|
444
|
2094
|
|
2095 Optional second argument LIMIT bounds the search; it is a buffer
|
|
2096 position. The match found must not extend before that position.
|
|
2097 The value nil is equivalent to (point-min).
|
|
2098
|
|
2099 Optional third argument NOERROR, if t, means just return nil (no
|
|
2100 error) if the search fails. If neither nil nor t, set point to LIMIT
|
|
2101 and return nil.
|
|
2102
|
|
2103 Optional fourth argument COUNT is a repeat count--search for
|
|
2104 successive occurrences.
|
|
2105
|
428
|
2106 Optional fifth argument BUFFER specifies the buffer to search in and
|
444
|
2107 defaults to the current buffer.
|
|
2108
|
428
|
2109 See also the functions `match-beginning', `match-end' and `replace-match'.
|
|
2110 */
|
444
|
2111 (string, limit, noerror, count, buffer))
|
428
|
2112 {
|
444
|
2113 return search_command (string, limit, noerror, count, buffer, -1, 0, 0);
|
428
|
2114 }
|
|
2115
|
|
2116 DEFUN ("search-forward", Fsearch_forward, 1, 5, "sSearch: ", /*
|
|
2117 Search forward from point for STRING.
|
|
2118 Set point to the end of the occurrence found, and return point.
|
444
|
2119
|
|
2120 Optional second argument LIMIT bounds the search; it is a buffer
|
|
2121 position. The match found must not extend after that position. The
|
|
2122 value nil is equivalent to (point-max).
|
|
2123
|
|
2124 Optional third argument NOERROR, if t, means just return nil (no
|
|
2125 error) if the search fails. If neither nil nor t, set point to LIMIT
|
|
2126 and return nil.
|
|
2127
|
|
2128 Optional fourth argument COUNT is a repeat count--search for
|
|
2129 successive occurrences.
|
|
2130
|
428
|
2131 Optional fifth argument BUFFER specifies the buffer to search in and
|
444
|
2132 defaults to the current buffer.
|
|
2133
|
428
|
2134 See also the functions `match-beginning', `match-end' and `replace-match'.
|
|
2135 */
|
444
|
2136 (string, limit, noerror, count, buffer))
|
428
|
2137 {
|
444
|
2138 return search_command (string, limit, noerror, count, buffer, 1, 0, 0);
|
428
|
2139 }
|
|
2140
|
|
2141 DEFUN ("word-search-backward", Fword_search_backward, 1, 5,
|
|
2142 "sWord search backward: ", /*
|
|
2143 Search backward from point for STRING, ignoring differences in punctuation.
|
|
2144 Set point to the beginning of the occurrence found, and return point.
|
444
|
2145
|
|
2146 Optional second argument LIMIT bounds the search; it is a buffer
|
|
2147 position. The match found must not extend before that position.
|
|
2148 The value nil is equivalent to (point-min).
|
|
2149
|
|
2150 Optional third argument NOERROR, if t, means just return nil (no
|
|
2151 error) if the search fails. If neither nil nor t, set point to LIMIT
|
|
2152 and return nil.
|
|
2153
|
|
2154 Optional fourth argument COUNT is a repeat count--search for
|
|
2155 successive occurrences.
|
|
2156
|
428
|
2157 Optional fifth argument BUFFER specifies the buffer to search in and
|
444
|
2158 defaults to the current buffer.
|
|
2159
|
|
2160 See also the functions `match-beginning', `match-end' and `replace-match'.
|
428
|
2161 */
|
444
|
2162 (string, limit, noerror, count, buffer))
|
428
|
2163 {
|
444
|
2164 return search_command (wordify (buffer, string), limit, noerror, count,
|
428
|
2165 buffer, -1, 1, 0);
|
|
2166 }
|
|
2167
|
|
2168 DEFUN ("word-search-forward", Fword_search_forward, 1, 5, "sWord search: ", /*
|
|
2169 Search forward from point for STRING, ignoring differences in punctuation.
|
|
2170 Set point to the end of the occurrence found, and return point.
|
444
|
2171
|
|
2172 Optional second argument LIMIT bounds the search; it is a buffer
|
|
2173 position. The match found must not extend after that position. The
|
|
2174 value nil is equivalent to (point-max).
|
|
2175
|
|
2176 Optional third argument NOERROR, if t, means just return nil (no
|
|
2177 error) if the search fails. If neither nil nor t, set point to LIMIT
|
|
2178 and return nil.
|
|
2179
|
|
2180 Optional fourth argument COUNT is a repeat count--search for
|
|
2181 successive occurrences.
|
|
2182
|
428
|
2183 Optional fifth argument BUFFER specifies the buffer to search in and
|
444
|
2184 defaults to the current buffer.
|
|
2185
|
|
2186 See also the functions `match-beginning', `match-end' and `replace-match'.
|
428
|
2187 */
|
444
|
2188 (string, limit, noerror, count, buffer))
|
428
|
2189 {
|
444
|
2190 return search_command (wordify (buffer, string), limit, noerror, count,
|
428
|
2191 buffer, 1, 1, 0);
|
|
2192 }
|
|
2193
|
|
2194 DEFUN ("re-search-backward", Fre_search_backward, 1, 5,
|
|
2195 "sRE search backward: ", /*
|
|
2196 Search backward from point for match for regular expression REGEXP.
|
|
2197 Set point to the beginning of the match, and return point.
|
|
2198 The match found is the one starting last in the buffer
|
|
2199 and yet ending before the origin of the search.
|
444
|
2200
|
|
2201 Optional second argument LIMIT bounds the search; it is a buffer
|
|
2202 position. The match found must not extend before that position.
|
|
2203 The value nil is equivalent to (point-min).
|
|
2204
|
|
2205 Optional third argument NOERROR, if t, means just return nil (no
|
|
2206 error) if the search fails. If neither nil nor t, set point to LIMIT
|
|
2207 and return nil.
|
|
2208
|
|
2209 Optional fourth argument COUNT is a repeat count--search for
|
|
2210 successive occurrences.
|
|
2211
|
428
|
2212 Optional fifth argument BUFFER specifies the buffer to search in and
|
444
|
2213 defaults to the current buffer.
|
|
2214
|
428
|
2215 See also the functions `match-beginning', `match-end' and `replace-match'.
|
|
2216 */
|
444
|
2217 (regexp, limit, noerror, count, buffer))
|
428
|
2218 {
|
444
|
2219 return search_command (regexp, limit, noerror, count, buffer, -1, 1, 0);
|
428
|
2220 }
|
|
2221
|
|
2222 DEFUN ("re-search-forward", Fre_search_forward, 1, 5, "sRE search: ", /*
|
|
2223 Search forward from point for regular expression REGEXP.
|
|
2224 Set point to the end of the occurrence found, and return point.
|
444
|
2225
|
|
2226 Optional second argument LIMIT bounds the search; it is a buffer
|
|
2227 position. The match found must not extend after that position. The
|
|
2228 value nil is equivalent to (point-max).
|
|
2229
|
|
2230 Optional third argument NOERROR, if t, means just return nil (no
|
|
2231 error) if the search fails. If neither nil nor t, set point to LIMIT
|
|
2232 and return nil.
|
|
2233
|
|
2234 Optional fourth argument COUNT is a repeat count--search for
|
|
2235 successive occurrences.
|
|
2236
|
428
|
2237 Optional fifth argument BUFFER specifies the buffer to search in and
|
444
|
2238 defaults to the current buffer.
|
|
2239
|
428
|
2240 See also the functions `match-beginning', `match-end' and `replace-match'.
|
|
2241 */
|
444
|
2242 (regexp, limit, noerror, count, buffer))
|
428
|
2243 {
|
444
|
2244 return search_command (regexp, limit, noerror, count, buffer, 1, 1, 0);
|
428
|
2245 }
|
|
2246
|
|
2247 DEFUN ("posix-search-backward", Fposix_search_backward, 1, 5,
|
|
2248 "sPosix search backward: ", /*
|
|
2249 Search backward from point for match for regular expression REGEXP.
|
|
2250 Find the longest match in accord with Posix regular expression rules.
|
|
2251 Set point to the beginning of the match, and return point.
|
|
2252 The match found is the one starting last in the buffer
|
|
2253 and yet ending before the origin of the search.
|
444
|
2254
|
|
2255 Optional second argument LIMIT bounds the search; it is a buffer
|
|
2256 position. The match found must not extend before that position.
|
|
2257 The value nil is equivalent to (point-min).
|
|
2258
|
|
2259 Optional third argument NOERROR, if t, means just return nil (no
|
|
2260 error) if the search fails. If neither nil nor t, set point to LIMIT
|
|
2261 and return nil.
|
|
2262
|
|
2263 Optional fourth argument COUNT is a repeat count--search for
|
|
2264 successive occurrences.
|
|
2265
|
428
|
2266 Optional fifth argument BUFFER specifies the buffer to search in and
|
444
|
2267 defaults to the current buffer.
|
|
2268
|
428
|
2269 See also the functions `match-beginning', `match-end' and `replace-match'.
|
|
2270 */
|
444
|
2271 (regexp, limit, noerror, count, buffer))
|
428
|
2272 {
|
444
|
2273 return search_command (regexp, limit, noerror, count, buffer, -1, 1, 1);
|
428
|
2274 }
|
|
2275
|
|
2276 DEFUN ("posix-search-forward", Fposix_search_forward, 1, 5, "sPosix search: ", /*
|
|
2277 Search forward from point for regular expression REGEXP.
|
|
2278 Find the longest match in accord with Posix regular expression rules.
|
|
2279 Set point to the end of the occurrence found, and return point.
|
444
|
2280
|
|
2281 Optional second argument LIMIT bounds the search; it is a buffer
|
|
2282 position. The match found must not extend after that position. The
|
|
2283 value nil is equivalent to (point-max).
|
|
2284
|
|
2285 Optional third argument NOERROR, if t, means just return nil (no
|
|
2286 error) if the search fails. If neither nil nor t, set point to LIMIT
|
|
2287 and return nil.
|
|
2288
|
|
2289 Optional fourth argument COUNT is a repeat count--search for
|
|
2290 successive occurrences.
|
|
2291
|
428
|
2292 Optional fifth argument BUFFER specifies the buffer to search in and
|
444
|
2293 defaults to the current buffer.
|
|
2294
|
428
|
2295 See also the functions `match-beginning', `match-end' and `replace-match'.
|
|
2296 */
|
444
|
2297 (regexp, limit, noerror, count, buffer))
|
428
|
2298 {
|
444
|
2299 return search_command (regexp, limit, noerror, count, buffer, 1, 1, 1);
|
428
|
2300 }
|
|
2301
|
|
2302
|
|
2303 static Lisp_Object
|
|
2304 free_created_dynarrs (Lisp_Object cons)
|
|
2305 {
|
|
2306 Dynarr_free (get_opaque_ptr (XCAR (cons)));
|
|
2307 Dynarr_free (get_opaque_ptr (XCDR (cons)));
|
|
2308 free_opaque_ptr (XCAR (cons));
|
|
2309 free_opaque_ptr (XCDR (cons));
|
853
|
2310 free_cons (cons);
|
428
|
2311 return Qnil;
|
|
2312 }
|
|
2313
|
|
2314 DEFUN ("replace-match", Freplace_match, 1, 5, 0, /*
|
444
|
2315 Replace text matched by last search with REPLACEMENT.
|
428
|
2316 If second arg FIXEDCASE is non-nil, do not alter case of replacement text.
|
|
2317 Otherwise maybe capitalize the whole text, or maybe just word initials,
|
|
2318 based on the replaced text.
|
|
2319 If the replaced text has only capital letters
|
444
|
2320 and has at least one multiletter word, convert REPLACEMENT to all caps.
|
428
|
2321 If the replaced text has at least one word starting with a capital letter,
|
444
|
2322 then capitalize each word in REPLACEMENT.
|
428
|
2323
|
444
|
2324 If third arg LITERAL is non-nil, insert REPLACEMENT literally.
|
428
|
2325 Otherwise treat `\\' as special:
|
444
|
2326 `\\&' in REPLACEMENT means substitute original matched text.
|
428
|
2327 `\\N' means substitute what matched the Nth `\\(...\\)'.
|
|
2328 If Nth parens didn't match, substitute nothing.
|
|
2329 `\\\\' means insert one `\\'.
|
|
2330 `\\u' means upcase the next character.
|
|
2331 `\\l' means downcase the next character.
|
|
2332 `\\U' means begin upcasing all following characters.
|
|
2333 `\\L' means begin downcasing all following characters.
|
|
2334 `\\E' means terminate the effect of any `\\U' or `\\L'.
|
|
2335 Case changes made with `\\u', `\\l', `\\U', and `\\L' override
|
|
2336 all other case changes that may be made in the replaced text.
|
|
2337 FIXEDCASE and LITERAL are optional arguments.
|
|
2338 Leaves point at end of replacement text.
|
|
2339
|
|
2340 The optional fourth argument STRING can be a string to modify.
|
|
2341 In that case, this function creates and returns a new string
|
|
2342 which is made by replacing the part of STRING that was matched.
|
|
2343 When fourth argument is a string, fifth argument STRBUFFER specifies
|
|
2344 the buffer to be used for syntax-table and case-table lookup and
|
444
|
2345 defaults to the current buffer. When fourth argument is not a string,
|
428
|
2346 the buffer that the match occurred in has automatically been remembered
|
444
|
2347 and you do not need to specify it.
|
469
|
2348
|
|
2349 When fourth argument is nil, STRBUFFER specifies a subexpression of
|
|
2350 the match. It says to replace just that subexpression instead of the
|
|
2351 whole match. This is useful only after a regular expression search or
|
|
2352 match since only regular expressions have distinguished subexpressions.
|
1425
|
2353
|
|
2354 If no match (including searches) has been conducted, the last match
|
|
2355 operation failed, or the requested subexpression was not matched, an
|
|
2356 `args-out-of-range' error will be signaled. (If no match has ever been
|
|
2357 conducted in this instance of XEmacs, an `invalid-operation' error will
|
|
2358 be signaled. This is very rare.)
|
428
|
2359 */
|
444
|
2360 (replacement, fixedcase, literal, string, strbuffer))
|
428
|
2361 {
|
|
2362 /* This function can GC */
|
|
2363 enum { nochange, all_caps, cap_initial } case_action;
|
665
|
2364 Charbpos pos, last;
|
428
|
2365 int some_multiletter_word;
|
|
2366 int some_lowercase;
|
|
2367 int some_uppercase;
|
|
2368 int some_nonuppercase_initial;
|
867
|
2369 Ichar c, prevc;
|
428
|
2370 Charcount inslen;
|
|
2371 struct buffer *buf;
|
826
|
2372 Lisp_Object syntax_table;
|
428
|
2373 int mc_count;
|
|
2374 Lisp_Object buffer;
|
|
2375 int_dynarr *ul_action_dynarr = 0;
|
|
2376 int_dynarr *ul_pos_dynarr = 0;
|
502
|
2377 int sub = 0;
|
428
|
2378 int speccount;
|
|
2379
|
444
|
2380 CHECK_STRING (replacement);
|
428
|
2381
|
|
2382 if (! NILP (string))
|
|
2383 {
|
|
2384 CHECK_STRING (string);
|
|
2385 if (!EQ (last_thing_searched, Qt))
|
563
|
2386 invalid_argument ("last thing matched was not a string", Qunbound);
|
428
|
2387 /* If the match data
|
|
2388 were abstracted into a special "match data" type instead
|
|
2389 of the typical half-assed "let the implementation be
|
|
2390 visible" form it's in, we could extend it to include
|
|
2391 the last string matched and the buffer used for that
|
|
2392 matching. But of course we can't change it as it is. */
|
|
2393 buf = decode_buffer (strbuffer, 0);
|
793
|
2394 buffer = wrap_buffer (buf);
|
428
|
2395 }
|
|
2396 else
|
|
2397 {
|
707
|
2398 if (!NILP (strbuffer))
|
469
|
2399 {
|
|
2400 CHECK_INT (strbuffer);
|
|
2401 sub = XINT (strbuffer);
|
|
2402 if (sub < 0 || sub >= (int) search_regs.num_regs)
|
|
2403 args_out_of_range (strbuffer, make_int (search_regs.num_regs));
|
|
2404 }
|
428
|
2405 if (!BUFFERP (last_thing_searched))
|
563
|
2406 invalid_argument ("last thing matched was not a buffer", Qunbound);
|
428
|
2407 buffer = last_thing_searched;
|
|
2408 buf = XBUFFER (buffer);
|
|
2409 }
|
|
2410
|
826
|
2411 syntax_table = buf->mirror_syntax_table;
|
428
|
2412
|
|
2413 case_action = nochange; /* We tried an initialization */
|
|
2414 /* but some C compilers blew it */
|
|
2415
|
|
2416 if (search_regs.num_regs == 0)
|
826
|
2417 signal_error (Qinvalid_operation,
|
|
2418 "replace-match called before any match found", Qunbound);
|
428
|
2419
|
|
2420 if (NILP (string))
|
|
2421 {
|
469
|
2422 if (search_regs.start[sub] < BUF_BEGV (buf)
|
|
2423 || search_regs.start[sub] > search_regs.end[sub]
|
|
2424 || search_regs.end[sub] > BUF_ZV (buf))
|
|
2425 args_out_of_range (make_int (search_regs.start[sub]),
|
|
2426 make_int (search_regs.end[sub]));
|
428
|
2427 }
|
|
2428 else
|
|
2429 {
|
|
2430 if (search_regs.start[0] < 0
|
|
2431 || search_regs.start[0] > search_regs.end[0]
|
826
|
2432 || search_regs.end[0] > string_char_length (string))
|
428
|
2433 args_out_of_range (make_int (search_regs.start[0]),
|
|
2434 make_int (search_regs.end[0]));
|
|
2435 }
|
|
2436
|
|
2437 if (NILP (fixedcase))
|
|
2438 {
|
|
2439 /* Decide how to casify by examining the matched text. */
|
|
2440
|
707
|
2441 last = search_regs.end[sub];
|
428
|
2442 prevc = '\n';
|
|
2443 case_action = all_caps;
|
|
2444
|
|
2445 /* some_multiletter_word is set nonzero if any original word
|
|
2446 is more than one letter long. */
|
|
2447 some_multiletter_word = 0;
|
|
2448 some_lowercase = 0;
|
|
2449 some_nonuppercase_initial = 0;
|
|
2450 some_uppercase = 0;
|
|
2451
|
707
|
2452 for (pos = search_regs.start[sub]; pos < last; pos++)
|
428
|
2453 {
|
|
2454 if (NILP (string))
|
|
2455 c = BUF_FETCH_CHAR (buf, pos);
|
|
2456 else
|
867
|
2457 c = string_ichar (string, pos);
|
428
|
2458
|
|
2459 if (LOWERCASEP (buf, c))
|
|
2460 {
|
|
2461 /* Cannot be all caps if any original char is lower case */
|
|
2462
|
|
2463 some_lowercase = 1;
|
|
2464 if (!WORD_SYNTAX_P (syntax_table, prevc))
|
|
2465 some_nonuppercase_initial = 1;
|
|
2466 else
|
|
2467 some_multiletter_word = 1;
|
|
2468 }
|
|
2469 else if (!NOCASEP (buf, c))
|
|
2470 {
|
|
2471 some_uppercase = 1;
|
|
2472 if (!WORD_SYNTAX_P (syntax_table, prevc))
|
|
2473 ;
|
|
2474 else
|
|
2475 some_multiletter_word = 1;
|
|
2476 }
|
|
2477 else
|
|
2478 {
|
|
2479 /* If the initial is a caseless word constituent,
|
|
2480 treat that like a lowercase initial. */
|
|
2481 if (!WORD_SYNTAX_P (syntax_table, prevc))
|
|
2482 some_nonuppercase_initial = 1;
|
|
2483 }
|
|
2484
|
|
2485 prevc = c;
|
|
2486 }
|
|
2487
|
|
2488 /* Convert to all caps if the old text is all caps
|
|
2489 and has at least one multiletter word. */
|
|
2490 if (! some_lowercase && some_multiletter_word)
|
|
2491 case_action = all_caps;
|
|
2492 /* Capitalize each word, if the old text has all capitalized words. */
|
|
2493 else if (!some_nonuppercase_initial && some_multiletter_word)
|
|
2494 case_action = cap_initial;
|
|
2495 else if (!some_nonuppercase_initial && some_uppercase)
|
|
2496 /* Should x -> yz, operating on X, give Yz or YZ?
|
|
2497 We'll assume the latter. */
|
|
2498 case_action = all_caps;
|
|
2499 else
|
|
2500 case_action = nochange;
|
|
2501 }
|
|
2502
|
|
2503 /* Do replacement in a string. */
|
|
2504 if (!NILP (string))
|
|
2505 {
|
|
2506 Lisp_Object before, after;
|
|
2507
|
|
2508 speccount = specpdl_depth ();
|
|
2509 before = Fsubstring (string, Qzero, make_int (search_regs.start[0]));
|
|
2510 after = Fsubstring (string, make_int (search_regs.end[0]), Qnil);
|
|
2511
|
444
|
2512 /* Do case substitution into REPLACEMENT if desired. */
|
428
|
2513 if (NILP (literal))
|
|
2514 {
|
826
|
2515 Charcount stlen = string_char_length (replacement);
|
428
|
2516 Charcount strpos;
|
|
2517 /* XEmacs change: rewrote this loop somewhat to make it
|
|
2518 cleaner. Also added \U, \E, etc. */
|
|
2519 Charcount literal_start = 0;
|
|
2520 /* We build up the substituted string in ACCUM. */
|
|
2521 Lisp_Object accum;
|
|
2522
|
|
2523 accum = Qnil;
|
|
2524
|
|
2525 /* OK, the basic idea here is that we scan through the
|
|
2526 replacement string until we find a backslash, which
|
|
2527 represents a substring of the original string to be
|
|
2528 substituted. We then append onto ACCUM the literal
|
|
2529 text before the backslash (LASTPOS marks the
|
|
2530 beginning of this) followed by the substring of the
|
|
2531 original string that needs to be inserted. */
|
|
2532 for (strpos = 0; strpos < stlen; strpos++)
|
|
2533 {
|
|
2534 /* If LITERAL_END is set, we've encountered a backslash
|
|
2535 (the end of literal text to be inserted). */
|
|
2536 Charcount literal_end = -1;
|
|
2537 /* If SUBSTART is set, we need to also insert the
|
|
2538 text from SUBSTART to SUBEND in the original string. */
|
|
2539 Charcount substart = -1;
|
|
2540 Charcount subend = -1;
|
|
2541
|
867
|
2542 c = string_ichar (replacement, strpos);
|
428
|
2543 if (c == '\\' && strpos < stlen - 1)
|
|
2544 {
|
867
|
2545 c = string_ichar (replacement, ++strpos);
|
428
|
2546 if (c == '&')
|
|
2547 {
|
|
2548 literal_end = strpos - 1;
|
|
2549 substart = search_regs.start[0];
|
|
2550 subend = search_regs.end[0];
|
|
2551 }
|
|
2552 else if (c >= '1' && c <= '9' &&
|
|
2553 c <= search_regs.num_regs + '0')
|
|
2554 {
|
|
2555 if (search_regs.start[c - '0'] >= 0)
|
|
2556 {
|
|
2557 literal_end = strpos - 1;
|
|
2558 substart = search_regs.start[c - '0'];
|
|
2559 subend = search_regs.end[c - '0'];
|
|
2560 }
|
|
2561 }
|
|
2562 else if (c == 'U' || c == 'u' || c == 'L' || c == 'l' ||
|
|
2563 c == 'E')
|
|
2564 {
|
|
2565 /* Keep track of all case changes requested, but don't
|
|
2566 make them now. Do them later so we override
|
|
2567 everything else. */
|
|
2568 if (!ul_pos_dynarr)
|
|
2569 {
|
|
2570 ul_pos_dynarr = Dynarr_new (int);
|
|
2571 ul_action_dynarr = Dynarr_new (int);
|
|
2572 record_unwind_protect
|
|
2573 (free_created_dynarrs,
|
|
2574 noseeum_cons
|
|
2575 (make_opaque_ptr (ul_pos_dynarr),
|
|
2576 make_opaque_ptr (ul_action_dynarr)));
|
|
2577 }
|
|
2578 literal_end = strpos - 1;
|
|
2579 Dynarr_add (ul_pos_dynarr,
|
|
2580 (!NILP (accum)
|
826
|
2581 ? string_char_length (accum)
|
428
|
2582 : 0) + (literal_end - literal_start));
|
|
2583 Dynarr_add (ul_action_dynarr, c);
|
|
2584 }
|
|
2585 else if (c == '\\')
|
|
2586 /* So we get just one backslash. */
|
|
2587 literal_end = strpos;
|
|
2588 }
|
|
2589 if (literal_end >= 0)
|
|
2590 {
|
|
2591 Lisp_Object literal_text = Qnil;
|
|
2592 Lisp_Object substring = Qnil;
|
|
2593 if (literal_end != literal_start)
|
444
|
2594 literal_text = Fsubstring (replacement,
|
428
|
2595 make_int (literal_start),
|
|
2596 make_int (literal_end));
|
|
2597 if (substart >= 0 && subend != substart)
|
|
2598 substring = Fsubstring (string,
|
|
2599 make_int (substart),
|
|
2600 make_int (subend));
|
|
2601 if (!NILP (literal_text) || !NILP (substring))
|
|
2602 accum = concat3 (accum, literal_text, substring);
|
|
2603 literal_start = strpos + 1;
|
|
2604 }
|
|
2605 }
|
|
2606
|
|
2607 if (strpos != literal_start)
|
|
2608 /* some literal text at end to be inserted */
|
444
|
2609 replacement = concat2 (accum, Fsubstring (replacement,
|
|
2610 make_int (literal_start),
|
|
2611 make_int (strpos)));
|
428
|
2612 else
|
444
|
2613 replacement = accum;
|
428
|
2614 }
|
|
2615
|
444
|
2616 /* replacement can be nil. */
|
|
2617 if (NILP (replacement))
|
|
2618 replacement = build_string ("");
|
|
2619
|
428
|
2620 if (case_action == all_caps)
|
444
|
2621 replacement = Fupcase (replacement, buffer);
|
428
|
2622 else if (case_action == cap_initial)
|
444
|
2623 replacement = Fupcase_initials (replacement, buffer);
|
428
|
2624
|
|
2625 /* Now finally, we need to process the \U's, \E's, etc. */
|
|
2626 if (ul_pos_dynarr)
|
|
2627 {
|
|
2628 int i = 0;
|
|
2629 int cur_action = 'E';
|
826
|
2630 Charcount stlen = string_char_length (replacement);
|
428
|
2631 Charcount strpos;
|
|
2632
|
|
2633 for (strpos = 0; strpos < stlen; strpos++)
|
|
2634 {
|
867
|
2635 Ichar curchar = string_ichar (replacement, strpos);
|
|
2636 Ichar newchar = -1;
|
428
|
2637 if (i < Dynarr_length (ul_pos_dynarr) &&
|
|
2638 strpos == Dynarr_at (ul_pos_dynarr, i))
|
|
2639 {
|
|
2640 int new_action = Dynarr_at (ul_action_dynarr, i);
|
|
2641 i++;
|
|
2642 if (new_action == 'u')
|
|
2643 newchar = UPCASE (buf, curchar);
|
|
2644 else if (new_action == 'l')
|
|
2645 newchar = DOWNCASE (buf, curchar);
|
|
2646 else
|
|
2647 cur_action = new_action;
|
|
2648 }
|
|
2649 if (newchar == -1)
|
|
2650 {
|
|
2651 if (cur_action == 'U')
|
|
2652 newchar = UPCASE (buf, curchar);
|
|
2653 else if (cur_action == 'L')
|
|
2654 newchar = DOWNCASE (buf, curchar);
|
|
2655 else
|
|
2656 newchar = curchar;
|
|
2657 }
|
|
2658 if (newchar != curchar)
|
793
|
2659 set_string_char (replacement, strpos, newchar);
|
428
|
2660 }
|
|
2661 }
|
|
2662
|
|
2663 /* frees the Dynarrs if necessary. */
|
771
|
2664 unbind_to (speccount);
|
444
|
2665 return concat3 (before, replacement, after);
|
428
|
2666 }
|
|
2667
|
707
|
2668 mc_count = begin_multiple_change (buf, search_regs.start[sub],
|
|
2669 search_regs.end[sub]);
|
428
|
2670
|
|
2671 /* begin_multiple_change() records an unwind-protect, so we need to
|
|
2672 record this value now. */
|
|
2673 speccount = specpdl_depth ();
|
|
2674
|
|
2675 /* We insert the replacement text before the old text, and then
|
|
2676 delete the original text. This means that markers at the
|
|
2677 beginning or end of the original will float to the corresponding
|
|
2678 position in the replacement. */
|
707
|
2679 BUF_SET_PT (buf, search_regs.start[sub]);
|
428
|
2680 if (!NILP (literal))
|
444
|
2681 Finsert (1, &replacement);
|
428
|
2682 else
|
|
2683 {
|
826
|
2684 Charcount stlen = string_char_length (replacement);
|
428
|
2685 Charcount strpos;
|
|
2686 struct gcpro gcpro1;
|
444
|
2687 GCPRO1 (replacement);
|
428
|
2688 for (strpos = 0; strpos < stlen; strpos++)
|
|
2689 {
|
707
|
2690 /* on the first iteration assert(offset==0),
|
|
2691 exactly complementing BUF_SET_PT() above.
|
|
2692 During the loop, it keeps track of the amount inserted.
|
|
2693 */
|
|
2694 Charcount offset = BUF_PT (buf) - search_regs.start[sub];
|
428
|
2695
|
867
|
2696 c = string_ichar (replacement, strpos);
|
428
|
2697 if (c == '\\' && strpos < stlen - 1)
|
|
2698 {
|
707
|
2699 /* XXX FIXME: replacing just a substring non-literally
|
|
2700 using backslash refs to the match looks dangerous. But
|
|
2701 <15366.18513.698042.156573@ns.caldera.de> from Torsten Duwe
|
|
2702 <duwe@caldera.de> claims Finsert_buffer_substring already
|
|
2703 handles this correctly.
|
|
2704 */
|
867
|
2705 c = string_ichar (replacement, ++strpos);
|
428
|
2706 if (c == '&')
|
|
2707 Finsert_buffer_substring
|
|
2708 (buffer,
|
|
2709 make_int (search_regs.start[0] + offset),
|
|
2710 make_int (search_regs.end[0] + offset));
|
|
2711 else if (c >= '1' && c <= '9' &&
|
|
2712 c <= search_regs.num_regs + '0')
|
|
2713 {
|
|
2714 if (search_regs.start[c - '0'] >= 1)
|
|
2715 Finsert_buffer_substring
|
|
2716 (buffer,
|
|
2717 make_int (search_regs.start[c - '0'] + offset),
|
|
2718 make_int (search_regs.end[c - '0'] + offset));
|
|
2719 }
|
|
2720 else if (c == 'U' || c == 'u' || c == 'L' || c == 'l' ||
|
|
2721 c == 'E')
|
|
2722 {
|
|
2723 /* Keep track of all case changes requested, but don't
|
|
2724 make them now. Do them later so we override
|
|
2725 everything else. */
|
|
2726 if (!ul_pos_dynarr)
|
|
2727 {
|
|
2728 ul_pos_dynarr = Dynarr_new (int);
|
|
2729 ul_action_dynarr = Dynarr_new (int);
|
|
2730 record_unwind_protect
|
|
2731 (free_created_dynarrs,
|
|
2732 Fcons (make_opaque_ptr (ul_pos_dynarr),
|
|
2733 make_opaque_ptr (ul_action_dynarr)));
|
|
2734 }
|
|
2735 Dynarr_add (ul_pos_dynarr, BUF_PT (buf));
|
|
2736 Dynarr_add (ul_action_dynarr, c);
|
|
2737 }
|
|
2738 else
|
|
2739 buffer_insert_emacs_char (buf, c);
|
|
2740 }
|
|
2741 else
|
|
2742 buffer_insert_emacs_char (buf, c);
|
|
2743 }
|
|
2744 UNGCPRO;
|
|
2745 }
|
|
2746
|
707
|
2747 inslen = BUF_PT (buf) - (search_regs.start[sub]);
|
|
2748 buffer_delete_range (buf, search_regs.start[sub] + inslen,
|
|
2749 search_regs.end[sub] + inslen, 0);
|
428
|
2750
|
|
2751 if (case_action == all_caps)
|
|
2752 Fupcase_region (make_int (BUF_PT (buf) - inslen),
|
|
2753 make_int (BUF_PT (buf)), buffer);
|
|
2754 else if (case_action == cap_initial)
|
|
2755 Fupcase_initials_region (make_int (BUF_PT (buf) - inslen),
|
|
2756 make_int (BUF_PT (buf)), buffer);
|
|
2757
|
|
2758 /* Now go through and make all the case changes that were requested
|
|
2759 in the replacement string. */
|
|
2760 if (ul_pos_dynarr)
|
|
2761 {
|
665
|
2762 Charbpos eend = BUF_PT (buf);
|
428
|
2763 int i = 0;
|
|
2764 int cur_action = 'E';
|
|
2765
|
|
2766 for (pos = BUF_PT (buf) - inslen; pos < eend; pos++)
|
|
2767 {
|
867
|
2768 Ichar curchar = BUF_FETCH_CHAR (buf, pos);
|
|
2769 Ichar newchar = -1;
|
428
|
2770 if (i < Dynarr_length (ul_pos_dynarr) &&
|
|
2771 pos == Dynarr_at (ul_pos_dynarr, i))
|
|
2772 {
|
|
2773 int new_action = Dynarr_at (ul_action_dynarr, i);
|
|
2774 i++;
|
|
2775 if (new_action == 'u')
|
|
2776 newchar = UPCASE (buf, curchar);
|
|
2777 else if (new_action == 'l')
|
|
2778 newchar = DOWNCASE (buf, curchar);
|
|
2779 else
|
|
2780 cur_action = new_action;
|
|
2781 }
|
|
2782 if (newchar == -1)
|
|
2783 {
|
|
2784 if (cur_action == 'U')
|
|
2785 newchar = UPCASE (buf, curchar);
|
|
2786 else if (cur_action == 'L')
|
|
2787 newchar = DOWNCASE (buf, curchar);
|
|
2788 else
|
|
2789 newchar = curchar;
|
|
2790 }
|
|
2791 if (newchar != curchar)
|
|
2792 buffer_replace_char (buf, pos, newchar, 0, 0);
|
|
2793 }
|
|
2794 }
|
|
2795
|
|
2796 /* frees the Dynarrs if necessary. */
|
771
|
2797 unbind_to (speccount);
|
428
|
2798 end_multiple_change (buf, mc_count);
|
|
2799
|
|
2800 return Qnil;
|
|
2801 }
|
|
2802
|
|
2803 static Lisp_Object
|
|
2804 match_limit (Lisp_Object num, int beginningp)
|
|
2805 {
|
|
2806 int n;
|
|
2807
|
|
2808 CHECK_INT (num);
|
|
2809 n = XINT (num);
|
|
2810 if (n < 0 || n >= search_regs.num_regs)
|
|
2811 args_out_of_range (num, make_int (search_regs.num_regs));
|
|
2812 if (search_regs.num_regs == 0 ||
|
|
2813 search_regs.start[n] < 0)
|
|
2814 return Qnil;
|
|
2815 return make_int (beginningp ? search_regs.start[n] : search_regs.end[n]);
|
|
2816 }
|
|
2817
|
|
2818 DEFUN ("match-beginning", Fmatch_beginning, 1, 1, 0, /*
|
|
2819 Return position of start of text matched by last regexp search.
|
|
2820 NUM, specifies which parenthesized expression in the last regexp.
|
|
2821 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
|
|
2822 Zero means the entire text matched by the whole regexp or whole string.
|
|
2823 */
|
|
2824 (num))
|
|
2825 {
|
|
2826 return match_limit (num, 1);
|
|
2827 }
|
|
2828
|
|
2829 DEFUN ("match-end", Fmatch_end, 1, 1, 0, /*
|
|
2830 Return position of end of text matched by last regexp search.
|
|
2831 NUM specifies which parenthesized expression in the last regexp.
|
|
2832 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
|
|
2833 Zero means the entire text matched by the whole regexp or whole string.
|
|
2834 */
|
|
2835 (num))
|
|
2836 {
|
|
2837 return match_limit (num, 0);
|
|
2838 }
|
|
2839
|
|
2840 DEFUN ("match-data", Fmatch_data, 0, 2, 0, /*
|
|
2841 Return a list containing all info on what the last regexp search matched.
|
|
2842 Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'.
|
|
2843 All the elements are markers or nil (nil if the Nth pair didn't match)
|
|
2844 if the last match was on a buffer; integers or nil if a string was matched.
|
|
2845 Use `store-match-data' to reinstate the data in this list.
|
|
2846
|
|
2847 If INTEGERS (the optional first argument) is non-nil, always use integers
|
|
2848 \(rather than markers) to represent buffer positions.
|
|
2849 If REUSE is a list, reuse it as part of the value. If REUSE is long enough
|
|
2850 to hold all the values, and if INTEGERS is non-nil, no consing is done.
|
|
2851 */
|
|
2852 (integers, reuse))
|
|
2853 {
|
|
2854 Lisp_Object tail, prev;
|
|
2855 Lisp_Object *data;
|
|
2856 int i;
|
|
2857 Charcount len;
|
|
2858
|
|
2859 if (NILP (last_thing_searched))
|
563
|
2860 /*error ("match-data called before any match found", Qunbound);*/
|
428
|
2861 return Qnil;
|
|
2862
|
|
2863 data = alloca_array (Lisp_Object, 2 * search_regs.num_regs);
|
|
2864
|
|
2865 len = -1;
|
|
2866 for (i = 0; i < search_regs.num_regs; i++)
|
|
2867 {
|
665
|
2868 Charbpos start = search_regs.start[i];
|
428
|
2869 if (start >= 0)
|
|
2870 {
|
|
2871 if (EQ (last_thing_searched, Qt)
|
|
2872 || !NILP (integers))
|
|
2873 {
|
|
2874 data[2 * i] = make_int (start);
|
|
2875 data[2 * i + 1] = make_int (search_regs.end[i]);
|
|
2876 }
|
|
2877 else if (BUFFERP (last_thing_searched))
|
|
2878 {
|
|
2879 data[2 * i] = Fmake_marker ();
|
|
2880 Fset_marker (data[2 * i],
|
|
2881 make_int (start),
|
|
2882 last_thing_searched);
|
|
2883 data[2 * i + 1] = Fmake_marker ();
|
|
2884 Fset_marker (data[2 * i + 1],
|
|
2885 make_int (search_regs.end[i]),
|
|
2886 last_thing_searched);
|
|
2887 }
|
|
2888 else
|
|
2889 /* last_thing_searched must always be Qt, a buffer, or Qnil. */
|
|
2890 abort ();
|
|
2891
|
|
2892 len = i;
|
|
2893 }
|
|
2894 else
|
|
2895 data[2 * i] = data [2 * i + 1] = Qnil;
|
|
2896 }
|
|
2897 if (!CONSP (reuse))
|
|
2898 return Flist (2 * len + 2, data);
|
|
2899
|
|
2900 /* If REUSE is a list, store as many value elements as will fit
|
|
2901 into the elements of REUSE. */
|
|
2902 for (prev = Qnil, i = 0, tail = reuse; CONSP (tail); i++, tail = XCDR (tail))
|
|
2903 {
|
|
2904 if (i < 2 * len + 2)
|
|
2905 XCAR (tail) = data[i];
|
|
2906 else
|
|
2907 XCAR (tail) = Qnil;
|
|
2908 prev = tail;
|
|
2909 }
|
|
2910
|
|
2911 /* If we couldn't fit all value elements into REUSE,
|
|
2912 cons up the rest of them and add them to the end of REUSE. */
|
|
2913 if (i < 2 * len + 2)
|
|
2914 XCDR (prev) = Flist (2 * len + 2 - i, data + i);
|
|
2915
|
|
2916 return reuse;
|
|
2917 }
|
|
2918
|
|
2919
|
|
2920 DEFUN ("store-match-data", Fstore_match_data, 1, 1, 0, /*
|
|
2921 Set internal data on last search match from elements of LIST.
|
|
2922 LIST should have been created by calling `match-data' previously.
|
|
2923 */
|
|
2924 (list))
|
|
2925 {
|
|
2926 REGISTER int i;
|
|
2927 REGISTER Lisp_Object marker;
|
|
2928 int num_regs;
|
|
2929 int length;
|
|
2930
|
853
|
2931 /* Some FSF junk with running_asynch_code, to preserve the match
|
|
2932 data. Not necessary because we don't call process filters
|
|
2933 asynchronously (i.e. from within QUIT). */
|
428
|
2934
|
|
2935 CONCHECK_LIST (list);
|
|
2936
|
|
2937 /* Unless we find a marker with a buffer in LIST, assume that this
|
|
2938 match data came from a string. */
|
|
2939 last_thing_searched = Qt;
|
|
2940
|
|
2941 /* Allocate registers if they don't already exist. */
|
|
2942 length = XINT (Flength (list)) / 2;
|
|
2943 num_regs = search_regs.num_regs;
|
|
2944
|
|
2945 if (length > num_regs)
|
|
2946 {
|
|
2947 if (search_regs.num_regs == 0)
|
|
2948 {
|
|
2949 search_regs.start = xnew_array (regoff_t, length);
|
|
2950 search_regs.end = xnew_array (regoff_t, length);
|
|
2951 }
|
|
2952 else
|
|
2953 {
|
|
2954 XREALLOC_ARRAY (search_regs.start, regoff_t, length);
|
|
2955 XREALLOC_ARRAY (search_regs.end, regoff_t, length);
|
|
2956 }
|
|
2957
|
|
2958 search_regs.num_regs = length;
|
|
2959 }
|
|
2960
|
|
2961 for (i = 0; i < num_regs; i++)
|
|
2962 {
|
|
2963 marker = Fcar (list);
|
|
2964 if (NILP (marker))
|
|
2965 {
|
|
2966 search_regs.start[i] = -1;
|
|
2967 list = Fcdr (list);
|
|
2968 }
|
|
2969 else
|
|
2970 {
|
|
2971 if (MARKERP (marker))
|
|
2972 {
|
|
2973 if (XMARKER (marker)->buffer == 0)
|
|
2974 marker = Qzero;
|
|
2975 else
|
793
|
2976 last_thing_searched = wrap_buffer (XMARKER (marker)->buffer);
|
428
|
2977 }
|
|
2978
|
|
2979 CHECK_INT_COERCE_MARKER (marker);
|
|
2980 search_regs.start[i] = XINT (marker);
|
|
2981 list = Fcdr (list);
|
|
2982
|
|
2983 marker = Fcar (list);
|
|
2984 if (MARKERP (marker) && XMARKER (marker)->buffer == 0)
|
|
2985 marker = Qzero;
|
|
2986
|
|
2987 CHECK_INT_COERCE_MARKER (marker);
|
|
2988 search_regs.end[i] = XINT (marker);
|
|
2989 }
|
|
2990 list = Fcdr (list);
|
|
2991 }
|
|
2992
|
|
2993 return Qnil;
|
|
2994 }
|
|
2995
|
|
2996 /* Quote a string to inactivate reg-expr chars */
|
|
2997
|
|
2998 DEFUN ("regexp-quote", Fregexp_quote, 1, 1, 0, /*
|
|
2999 Return a regexp string which matches exactly STRING and nothing else.
|
|
3000 */
|
444
|
3001 (string))
|
428
|
3002 {
|
867
|
3003 REGISTER Ibyte *in, *out, *end;
|
|
3004 REGISTER Ibyte *temp;
|
428
|
3005
|
444
|
3006 CHECK_STRING (string);
|
428
|
3007
|
867
|
3008 temp = (Ibyte *) ALLOCA (XSTRING_LENGTH (string) * 2);
|
428
|
3009
|
|
3010 /* Now copy the data into the new string, inserting escapes. */
|
|
3011
|
444
|
3012 in = XSTRING_DATA (string);
|
|
3013 end = in + XSTRING_LENGTH (string);
|
428
|
3014 out = temp;
|
|
3015
|
|
3016 while (in < end)
|
|
3017 {
|
867
|
3018 Ichar c = itext_ichar (in);
|
428
|
3019
|
|
3020 if (c == '[' || c == ']'
|
|
3021 || c == '*' || c == '.' || c == '\\'
|
|
3022 || c == '?' || c == '+'
|
|
3023 || c == '^' || c == '$')
|
|
3024 *out++ = '\\';
|
867
|
3025 out += set_itext_ichar (out, c);
|
|
3026 INC_IBYTEPTR (in);
|
428
|
3027 }
|
|
3028
|
|
3029 return make_string (temp, out - temp);
|
|
3030 }
|
|
3031
|
|
3032 DEFUN ("set-word-regexp", Fset_word_regexp, 1, 1, 0, /*
|
|
3033 Set the regexp to be used to match a word in regular-expression searching.
|
|
3034 #### Not yet implemented. Currently does nothing.
|
|
3035 #### Do not use this yet. Its calling interface is likely to change.
|
|
3036 */
|
|
3037 (regexp))
|
|
3038 {
|
|
3039 return Qnil;
|
|
3040 }
|
|
3041
|
|
3042
|
|
3043 /************************************************************************/
|
|
3044 /* initialization */
|
|
3045 /************************************************************************/
|
|
3046
|
|
3047 void
|
|
3048 syms_of_search (void)
|
|
3049 {
|
|
3050
|
442
|
3051 DEFERROR_STANDARD (Qsearch_failed, Qinvalid_operation);
|
|
3052 DEFERROR_STANDARD (Qinvalid_regexp, Qsyntax_error);
|
563
|
3053 Fput (Qinvalid_regexp, Qerror_lacks_explanatory_string, Qt);
|
428
|
3054
|
|
3055 DEFSUBR (Flooking_at);
|
|
3056 DEFSUBR (Fposix_looking_at);
|
|
3057 DEFSUBR (Fstring_match);
|
|
3058 DEFSUBR (Fposix_string_match);
|
|
3059 DEFSUBR (Fskip_chars_forward);
|
|
3060 DEFSUBR (Fskip_chars_backward);
|
|
3061 DEFSUBR (Fskip_syntax_forward);
|
|
3062 DEFSUBR (Fskip_syntax_backward);
|
|
3063 DEFSUBR (Fsearch_forward);
|
|
3064 DEFSUBR (Fsearch_backward);
|
|
3065 DEFSUBR (Fword_search_forward);
|
|
3066 DEFSUBR (Fword_search_backward);
|
|
3067 DEFSUBR (Fre_search_forward);
|
|
3068 DEFSUBR (Fre_search_backward);
|
|
3069 DEFSUBR (Fposix_search_forward);
|
|
3070 DEFSUBR (Fposix_search_backward);
|
|
3071 DEFSUBR (Freplace_match);
|
|
3072 DEFSUBR (Fmatch_beginning);
|
|
3073 DEFSUBR (Fmatch_end);
|
|
3074 DEFSUBR (Fmatch_data);
|
|
3075 DEFSUBR (Fstore_match_data);
|
|
3076 DEFSUBR (Fregexp_quote);
|
|
3077 DEFSUBR (Fset_word_regexp);
|
|
3078 }
|
|
3079
|
|
3080 void
|
|
3081 reinit_vars_of_search (void)
|
|
3082 {
|
|
3083 int i;
|
|
3084
|
|
3085 last_thing_searched = Qnil;
|
|
3086 staticpro_nodump (&last_thing_searched);
|
|
3087
|
|
3088 for (i = 0; i < REGEXP_CACHE_SIZE; ++i)
|
|
3089 {
|
|
3090 searchbufs[i].buf.allocated = 100;
|
|
3091 searchbufs[i].buf.buffer = (unsigned char *) xmalloc (100);
|
|
3092 searchbufs[i].buf.fastmap = searchbufs[i].fastmap;
|
|
3093 searchbufs[i].regexp = Qnil;
|
|
3094 staticpro_nodump (&searchbufs[i].regexp);
|
|
3095 searchbufs[i].next = (i == REGEXP_CACHE_SIZE-1 ? 0 : &searchbufs[i+1]);
|
|
3096 }
|
|
3097 searchbuf_head = &searchbufs[0];
|
|
3098 }
|
|
3099
|
|
3100 void
|
|
3101 vars_of_search (void)
|
|
3102 {
|
|
3103 reinit_vars_of_search ();
|
|
3104
|
|
3105 DEFVAR_LISP ("forward-word-regexp", &Vforward_word_regexp /*
|
|
3106 *Regular expression to be used in `forward-word'.
|
|
3107 #### Not yet implemented.
|
|
3108 */ );
|
|
3109 Vforward_word_regexp = Qnil;
|
|
3110
|
|
3111 DEFVAR_LISP ("backward-word-regexp", &Vbackward_word_regexp /*
|
|
3112 *Regular expression to be used in `backward-word'.
|
|
3113 #### Not yet implemented.
|
|
3114 */ );
|
|
3115 Vbackward_word_regexp = Qnil;
|
502
|
3116
|
|
3117 DEFVAR_INT ("warn-about-possibly-incompatible-back-references",
|
|
3118 &warn_about_possibly_incompatible_back_references /*
|
|
3119 If true, issue warnings when new-semantics back references occur.
|
|
3120 This is to catch places where old code might inadvertently have changed
|
|
3121 semantics. This will occur in old code only where more than nine groups
|
|
3122 occur and a back reference to one of them is directly followed by a digit.
|
|
3123 */ );
|
|
3124 warn_about_possibly_incompatible_back_references = 1;
|
814
|
3125
|
428
|
3126 Vskip_chars_range_table = Fmake_range_table ();
|
|
3127 staticpro (&Vskip_chars_range_table);
|
|
3128 }
|