annotate src/search.c @ 90054:f2ebccfa87d4

Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-74 Merge from emacs--cvs-trunk--0 Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-709 Update from CVS: src/indent.c (Fvertical_motion): Fix last change. * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-710 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-715 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-716 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-74 Update from CVS
author Miles Bader <miles@gnu.org>
date Wed, 08 Dec 2004 05:02:30 +0000
parents e24e2e78deda 47729f2cb184
children cd540ce7f0fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* String search routines for GNU Emacs.
56294
aaa6a4ecea38 (match_limit, Fmatch_data, Fset_match_data): YAILOM.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 56276
diff changeset
2 Copyright (C) 1985, 86,87,93,94,97,98, 1999, 2004
aaa6a4ecea38 (match_limit, Fmatch_data, Fset_match_data): YAILOM.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 56276
diff changeset
3 Free Software Foundation, Inc.
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5 This file is part of GNU Emacs.
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 GNU Emacs is free software; you can redistribute it and/or modify
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
12244
ac7375e60931 Update GPL to version 2.
Karl Heuer <kwzh@gnu.org>
parents: 12148
diff changeset
9 the Free Software Foundation; either version 2, or (at your option)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 any later version.
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 GNU Emacs is distributed in the hope that it will be useful,
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 GNU General Public License for more details.
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 along with GNU Emacs; see the file COPYING. If not, write to
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14086
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14086
diff changeset
20 Boston, MA 02111-1307, USA. */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 4635
diff changeset
23 #include <config.h>
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 #include "lisp.h"
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 #include "syntax.h"
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
26 #include "category.h"
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 #include "buffer.h"
88388
e9a23b7c1feb Include "character.h" instead of "charset.h".
Kenichi Handa <handa@m17n.org>
parents: 41389
diff changeset
28 #include "character.h"
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
29 #include "region-cache.h"
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 #include "commands.h"
2439
b6c62e4abf59 Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents: 2393
diff changeset
31 #include "blockinput.h"
20347
d8e5f3c1618b Include "intervals.h" for prototypes.
Andreas Schwab <schwab@suse.de>
parents: 19541
diff changeset
32 #include "intervals.h"
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
33
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 #include <sys/types.h>
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 #include "regex.h"
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36
16275
a4bcfdc9bb66 (REGEXP_CACHE_SIZE): Increase to 20.
Richard M. Stallman <rms@gnu.org>
parents: 16152
diff changeset
37 #define REGEXP_CACHE_SIZE 20
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
39 /* If the regexp is non-nil, then the buffer contains the compiled form
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
40 of that regexp, suitable for searching. */
16275
a4bcfdc9bb66 (REGEXP_CACHE_SIZE): Increase to 20.
Richard M. Stallman <rms@gnu.org>
parents: 16152
diff changeset
41 struct regexp_cache
a4bcfdc9bb66 (REGEXP_CACHE_SIZE): Increase to 20.
Richard M. Stallman <rms@gnu.org>
parents: 16152
diff changeset
42 {
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
43 struct regexp_cache *next;
58330
5be8a633ec57 (struct regexp_cache): New element whitespace_regexp.
Richard M. Stallman <rms@gnu.org>
parents: 58326
diff changeset
44 Lisp_Object regexp, whitespace_regexp;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
45 struct re_pattern_buffer buf;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
46 char fastmap[0400];
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
47 /* Nonzero means regexp was compiled to do full POSIX backtracking. */
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
48 char posix;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
49 };
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
51 /* The instances of that struct. */
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
52 struct regexp_cache searchbufs[REGEXP_CACHE_SIZE];
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
54 /* The head of the linked list; points to the most recently used buffer. */
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
55 struct regexp_cache *searchbuf_head;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
56
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
58 /* Every call to re_match, etc., must pass &search_regs as the regs
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
59 argument unless you can show it is unnecessary (i.e., if re_match
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
60 is certainly going to be called again before region-around-match
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
61 can be called).
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
62
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
63 Since the registers are now dynamically allocated, we need to make
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
64 sure not to refer to the Nth register before checking that it has
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
65 been allocated by checking search_regs.num_regs.
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
67 The regex code keeps track of whether it has allocated the search
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
68 buffer using bits in the re_pattern_buffer. This means that whenever
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
69 you compile a new pattern, it completely forgets whether it has
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
70 allocated any registers, and will allocate new registers the next
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
71 time you call a searching or matching function. Therefore, we need
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
72 to call re_set_registers after compiling a new pattern or after
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
73 setting the match registers, so that the regex functions will be
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
74 able to free or re-allocate it properly. */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 static struct re_registers search_regs;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
77 /* The buffer in which the last search was performed, or
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
78 Qt if the last search was done in a string;
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
79 Qnil if no searching has been done yet. */
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
80 static Lisp_Object last_thing_searched;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81
14036
621a575db6f7 Comment fixes.
Karl Heuer <kwzh@gnu.org>
parents: 13295
diff changeset
82 /* error condition signaled when regexp compile_pattern fails */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 Lisp_Object Qinvalid_regexp;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85
58348
623ffd21f0ff (Vsearch_spaces_regexp):
Richard M. Stallman <rms@gnu.org>
parents: 58330
diff changeset
86 Lisp_Object Vsearch_spaces_regexp;
58326
0cc0d3274d68 (Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 57735
diff changeset
87
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
88 static void set_search_regs ();
10055
cb713218845a (save_search_regs): Add declaration.
Richard M. Stallman <rms@gnu.org>
parents: 10032
diff changeset
89 static void save_search_regs ();
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
90 static int simple_search ();
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
91 static int boyer_moore ();
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
92 static int search_buffer ();
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
93
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 static void
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 matcher_overflow ()
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 error ("Stack overflow in regexp matcher");
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
100 /* Compile a regexp and signal a Lisp error if anything goes wrong.
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
101 PATTERN is the pattern to compile.
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
102 CP is the place to put the result.
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
103 TRANSLATE is a translation table for ignoring case, or nil for none.
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
104 REGP is the structure that says where to store the "register"
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
105 values that will result from matching this pattern.
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
106 If it is 0, we should compile the pattern not to record any
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
107 subexpression bounds.
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
108 POSIX is nonzero if we want full backtracking (POSIX style)
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
109 for this pattern. 0 means backtrack only enough to get a valid match.
89483
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
110 MULTIBYTE is nonzero iff a target of match is a multibyte buffer or
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
111 string. */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
113 static void
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
114 compile_pattern_1 (cp, pattern, translate, regp, posix, multibyte)
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
115 struct regexp_cache *cp;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 Lisp_Object pattern;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
117 Lisp_Object translate;
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
118 struct re_registers *regp;
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
119 int posix;
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
120 int multibyte;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 {
18762
12c0de0113af (compile_pattern_1): Don't declare val with CONST.
Richard M. Stallman <rms@gnu.org>
parents: 18193
diff changeset
122 char *val;
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
123 reg_syntax_t old;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
125 cp->regexp = Qnil;
21531
5811a3129878 (compile_pattern, compile_pattern_1): Fix mixing of
Andreas Schwab <schwab@suse.de>
parents: 21514
diff changeset
126 cp->buf.translate = (! NILP (translate) ? translate : make_number (0));
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
127 cp->posix = posix;
89062
be059fb97bac (compile_pattern_1): Don't adjust the multibyteness of
Kenichi Handa <handa@m17n.org>
parents: 89028
diff changeset
128 cp->buf.multibyte = STRING_MULTIBYTE (pattern);
be059fb97bac (compile_pattern_1): Don't adjust the multibyteness of
Kenichi Handa <handa@m17n.org>
parents: 89028
diff changeset
129 cp->buf.target_multibyte = multibyte;
2439
b6c62e4abf59 Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents: 2393
diff changeset
130 BLOCK_INPUT;
27692
bb0e45f6ca86 * regex.h (RE_SYNTAX_EMACS): Add RE_CHAR_CLASSES and RE_INTERVALS
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27592
diff changeset
131 old = re_set_syntax (RE_SYNTAX_EMACS
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
132 | (posix ? 0 : RE_NO_POSIX_BACKTRACKING));
89483
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
133 val = (char *) re_compile_pattern ((char *) SDATA (pattern),
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
134 SBYTES (pattern), &cp->buf);
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
135 re_set_syntax (old);
2439
b6c62e4abf59 Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents: 2393
diff changeset
136 UNBLOCK_INPUT;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 if (val)
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
138 Fsignal (Qinvalid_regexp, Fcons (build_string (val), Qnil));
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
139
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
140 cp->regexp = Fcopy_sequence (pattern);
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
141 }
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
142
22221
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
143 /* Shrink each compiled regexp buffer in the cache
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
144 to the size actually used right now.
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
145 This is called from garbage collection. */
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
146
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
147 void
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
148 shrink_regexp_cache ()
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
149 {
34966
23a62cf7d0eb (shrink_regexp_cache): Remove unused variable `cpp'.
Eli Zaretskii <eliz@gnu.org>
parents: 33052
diff changeset
150 struct regexp_cache *cp;
22221
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
151
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
152 for (cp = searchbuf_head; cp != 0; cp = cp->next)
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
153 {
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
154 cp->buf.allocated = cp->buf.used;
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
155 cp->buf.buffer
51544
a0c2b39160e9 (shrink_regexp_cache): Use xrealloc.
Dave Love <fx@gnu.org>
parents: 49761
diff changeset
156 = (unsigned char *) xrealloc (cp->buf.buffer, cp->buf.used);
22221
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
157 }
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
158 }
239a4b800303 (shrink_regexp_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22082
diff changeset
159
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
160 /* Compile a regexp if necessary, but first check to see if there's one in
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
161 the cache.
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
162 PATTERN is the pattern to compile.
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
163 TRANSLATE is a translation table for ignoring case, or nil for none.
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
164 REGP is the structure that says where to store the "register"
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
165 values that will result from matching this pattern.
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
166 If it is 0, we should compile the pattern not to record any
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
167 subexpression bounds.
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
168 POSIX is nonzero if we want full backtracking (POSIX style)
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
169 for this pattern. 0 means backtrack only enough to get a valid match. */
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
170
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
171 struct re_pattern_buffer *
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
172 compile_pattern (pattern, regp, translate, posix, multibyte)
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
173 Lisp_Object pattern;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
174 struct re_registers *regp;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
175 Lisp_Object translate;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
176 int posix, multibyte;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
177 {
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
178 struct regexp_cache *cp, **cpp;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
179
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
180 for (cpp = &searchbuf_head; ; cpp = &cp->next)
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
181 {
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
182 cp = *cpp;
27592
5cd59d1800ad * search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents: 26985
diff changeset
183 /* Entries are initialized to nil, and may be set to nil by
5cd59d1800ad * search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents: 26985
diff changeset
184 compile_pattern_1 if the pattern isn't valid. Don't apply
46444
c7158c721fef comment update
Ken Raeburn <raeburn@raeburn.org>
parents: 46432
diff changeset
185 string accessors in those cases. However, compile_pattern_1
c7158c721fef comment update
Ken Raeburn <raeburn@raeburn.org>
parents: 46432
diff changeset
186 is only applied to the cache entry we pick here to reuse. So
c7158c721fef comment update
Ken Raeburn <raeburn@raeburn.org>
parents: 46432
diff changeset
187 nil should never appear before a non-nil entry. */
28507
b6f06a755c7d make_number/XINT/XUINT conversions; EQ/== fixes; ==Qnil -> NILP
Ken Raeburn <raeburn@raeburn.org>
parents: 28387
diff changeset
188 if (NILP (cp->regexp))
27592
5cd59d1800ad * search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents: 26985
diff changeset
189 goto compile_it;
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
190 if (SCHARS (cp->regexp) == SCHARS (pattern)
31486
a3dc5f987e8f (compile_pattern): Check the multibyteness of cached
Kenichi Handa <handa@m17n.org>
parents: 29335
diff changeset
191 && STRING_MULTIBYTE (cp->regexp) == STRING_MULTIBYTE (pattern)
16275
a4bcfdc9bb66 (REGEXP_CACHE_SIZE): Increase to 20.
Richard M. Stallman <rms@gnu.org>
parents: 16152
diff changeset
192 && !NILP (Fstring_equal (cp->regexp, pattern))
21531
5811a3129878 (compile_pattern, compile_pattern_1): Fix mixing of
Andreas Schwab <schwab@suse.de>
parents: 21514
diff changeset
193 && EQ (cp->buf.translate, (! NILP (translate) ? translate : make_number (0)))
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
194 && cp->posix == posix
89454
9bd823b992df (compile_pattern): Check the member target_multibyte,
Kenichi Handa <handa@m17n.org>
parents: 89213
diff changeset
195 && cp->buf.target_multibyte == multibyte)
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
196 break;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
197
27592
5cd59d1800ad * search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents: 26985
diff changeset
198 /* If we're at the end of the cache, compile into the nil cell
5cd59d1800ad * search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents: 26985
diff changeset
199 we found, or the last (least recently used) cell with a
5cd59d1800ad * search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents: 26985
diff changeset
200 string value. */
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
201 if (cp->next == 0)
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
202 {
27592
5cd59d1800ad * search.c (compile_pattern): If a cache entry has a nil regexp, fill in that
Ken Raeburn <raeburn@raeburn.org>
parents: 26985
diff changeset
203 compile_it:
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
204 compile_pattern_1 (cp, pattern, translate, regp, posix, multibyte);
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
205 break;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
206 }
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
207 }
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
208
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
209 /* When we get here, cp (aka *cpp) contains the compiled pattern,
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
210 either because we found it in the cache or because we just compiled it.
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
211 Move it to the front of the queue to mark it as most recently used. */
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
212 *cpp = cp->next;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
213 cp->next = searchbuf_head;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
214 searchbuf_head = cp;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
215
10141
afe81fd385eb (compile_pattern): Call re_set_registers here.
Richard M. Stallman <rms@gnu.org>
parents: 10128
diff changeset
216 /* Advise the searching functions about the space we have allocated
afe81fd385eb (compile_pattern): Call re_set_registers here.
Richard M. Stallman <rms@gnu.org>
parents: 10128
diff changeset
217 for register data. */
afe81fd385eb (compile_pattern): Call re_set_registers here.
Richard M. Stallman <rms@gnu.org>
parents: 10128
diff changeset
218 if (regp)
afe81fd385eb (compile_pattern): Call re_set_registers here.
Richard M. Stallman <rms@gnu.org>
parents: 10128
diff changeset
219 re_set_registers (&cp->buf, regp, regp->num_regs, regp->start, regp->end);
afe81fd385eb (compile_pattern): Call re_set_registers here.
Richard M. Stallman <rms@gnu.org>
parents: 10128
diff changeset
220
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
221 return &cp->buf;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 /* Error condition used for failing searches */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 Lisp_Object Qsearch_failed;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 Lisp_Object
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 signal_failure (arg)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 Lisp_Object arg;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 Fsignal (Qsearch_failed, Fcons (arg, Qnil));
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 return Qnil;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
235 static Lisp_Object
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
236 looking_at_1 (string, posix)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 Lisp_Object string;
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
238 int posix;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 Lisp_Object val;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 unsigned char *p1, *p2;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 int s1, s2;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 register int i;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
244 struct re_pattern_buffer *bufp;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
246 if (running_asynch_code)
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
247 save_search_regs ();
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
248
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
249 CHECK_STRING (string);
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
250 bufp = compile_pattern (string, &search_regs,
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
251 (!NILP (current_buffer->case_fold_search)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
252 ? DOWNCASE_TABLE : Qnil),
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
253 posix,
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
254 !NILP (current_buffer->enable_multibyte_characters));
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 immediate_quit = 1;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 QUIT; /* Do a pending quit right away, to avoid paradoxical behavior */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 /* Get pointers and sizes of the two strings
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 that make up the visible portion of the buffer. */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 p1 = BEGV_ADDR;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
263 s1 = GPT_BYTE - BEGV_BYTE;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 p2 = GAP_END_ADDR;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
265 s2 = ZV_BYTE - GPT_BYTE;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 if (s1 < 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 p2 = p1;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
269 s2 = ZV_BYTE - BEGV_BYTE;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 s1 = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 if (s2 < 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 {
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
274 s1 = ZV_BYTE - BEGV_BYTE;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 s2 = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 }
17463
bb9ae80d22e2 (looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents: 17284
diff changeset
277
bb9ae80d22e2 (looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents: 17284
diff changeset
278 re_match_object = Qnil;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
279
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
280 i = re_match_2 (bufp, (char *) p1, s1, (char *) p2, s2,
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
281 PT_BYTE - BEGV_BYTE, &search_regs,
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
282 ZV_BYTE - BEGV_BYTE);
26985
1121a5da20a5 (looking_at_1): Reset immediate_quit before modifying
Gerd Moellmann <gerd@gnu.org>
parents: 26982
diff changeset
283 immediate_quit = 0;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
284
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 if (i == -2)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 matcher_overflow ();
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 val = (0 <= i ? Qt : Qnil);
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
289 if (i >= 0)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
290 for (i = 0; i < search_regs.num_regs; i++)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
291 if (search_regs.start[i] >= 0)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
292 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
293 search_regs.start[i]
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
294 = BYTE_TO_CHAR (search_regs.start[i] + BEGV_BYTE);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
295 search_regs.end[i]
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
296 = BYTE_TO_CHAR (search_regs.end[i] + BEGV_BYTE);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
297 }
9278
f2138d548313 (Flooking_at, skip_chars, search_buffer, set_search_regs, Fstore_match_data):
Karl Heuer <kwzh@gnu.org>
parents: 9113
diff changeset
298 XSETBUFFER (last_thing_searched, current_buffer);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 return val;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
302 DEFUN ("looking-at", Flooking_at, Slooking_at, 1, 1, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
303 doc: /* Return t if text after point matches regular expression REGEXP.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
304 This function modifies the match data that `match-beginning',
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
305 `match-end' and `match-data' access; save and restore the match
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
306 data if you want to preserve them. */)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
307 (regexp)
11213
d0811ba886f8 (Flooking_at, Fposix_looking_at): Change arg name.
Richard M. Stallman <rms@gnu.org>
parents: 10250
diff changeset
308 Lisp_Object regexp;
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
309 {
11213
d0811ba886f8 (Flooking_at, Fposix_looking_at): Change arg name.
Richard M. Stallman <rms@gnu.org>
parents: 10250
diff changeset
310 return looking_at_1 (regexp, 0);
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
311 }
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
312
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
313 DEFUN ("posix-looking-at", Fposix_looking_at, Sposix_looking_at, 1, 1, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
314 doc: /* Return t if text after point matches regular expression REGEXP.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
315 Find the longest match, in accord with Posix regular expression rules.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
316 This function modifies the match data that `match-beginning',
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
317 `match-end' and `match-data' access; save and restore the match
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
318 data if you want to preserve them. */)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
319 (regexp)
11213
d0811ba886f8 (Flooking_at, Fposix_looking_at): Change arg name.
Richard M. Stallman <rms@gnu.org>
parents: 10250
diff changeset
320 Lisp_Object regexp;
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
321 {
11213
d0811ba886f8 (Flooking_at, Fposix_looking_at): Change arg name.
Richard M. Stallman <rms@gnu.org>
parents: 10250
diff changeset
322 return looking_at_1 (regexp, 1);
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
323 }
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
324
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
325 static Lisp_Object
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
326 string_match_1 (regexp, string, start, posix)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 Lisp_Object regexp, string, start;
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
328 int posix;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 int val;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
331 struct re_pattern_buffer *bufp;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
332 int pos, pos_byte;
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
333 int i;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
335 if (running_asynch_code)
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
336 save_search_regs ();
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
337
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
338 CHECK_STRING (regexp);
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
339 CHECK_STRING (string);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 if (NILP (start))
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
342 pos = 0, pos_byte = 0;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 else
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 {
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
345 int len = SCHARS (string);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
347 CHECK_NUMBER (start);
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
348 pos = XINT (start);
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
349 if (pos < 0 && -pos <= len)
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
350 pos = len + pos;
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
351 else if (0 > pos || pos > len)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 args_out_of_range (string, start);
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
353 pos_byte = string_char_to_byte (string, pos);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
356 bufp = compile_pattern (regexp, &search_regs,
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
357 (!NILP (current_buffer->case_fold_search)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
358 ? DOWNCASE_TABLE : Qnil),
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
359 posix,
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
360 STRING_MULTIBYTE (string));
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 immediate_quit = 1;
17463
bb9ae80d22e2 (looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents: 17284
diff changeset
362 re_match_object = string;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
363
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
364 val = re_search (bufp, (char *) SDATA (string),
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
365 SBYTES (string), pos_byte,
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
366 SBYTES (string) - pos_byte,
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 &search_regs);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 immediate_quit = 0;
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
369 last_thing_searched = Qt;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 if (val == -2)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 matcher_overflow ();
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 if (val < 0) return Qnil;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
373
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
374 for (i = 0; i < search_regs.num_regs; i++)
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
375 if (search_regs.start[i] >= 0)
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
376 {
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
377 search_regs.start[i]
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
378 = string_byte_to_char (string, search_regs.start[i]);
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
379 search_regs.end[i]
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
380 = string_byte_to_char (string, search_regs.end[i]);
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
381 }
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
382
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
383 return make_number (string_byte_to_char (string, val));
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 }
842
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
385
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
386 DEFUN ("string-match", Fstring_match, Sstring_match, 2, 3, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
387 doc: /* Return index of start of first match for REGEXP in STRING, or nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
388 Case is ignored if `case-fold-search' is non-nil in the current buffer.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
389 If third arg START is non-nil, start search at that index in STRING.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
390 For index of first char beyond the match, do (match-end 0).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
391 `match-end' and `match-beginning' also give indices of substrings
48528
467b0e57d985 (Fstring_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 47692
diff changeset
392 matched by parenthesis constructs in the pattern.
467b0e57d985 (Fstring_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 47692
diff changeset
393
467b0e57d985 (Fstring_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 47692
diff changeset
394 You can use the function `match-string' to extract the substrings
467b0e57d985 (Fstring_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 47692
diff changeset
395 matched by the parenthesis constructions in REGEXP. */)
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
396 (regexp, string, start)
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
397 Lisp_Object regexp, string, start;
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
398 {
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
399 return string_match_1 (regexp, string, start, 0);
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
400 }
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
401
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
402 DEFUN ("posix-string-match", Fposix_string_match, Sposix_string_match, 2, 3, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
403 doc: /* Return index of start of first match for REGEXP in STRING, or nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
404 Find the longest match, in accord with Posix regular expression rules.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
405 Case is ignored if `case-fold-search' is non-nil in the current buffer.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
406 If third arg START is non-nil, start search at that index in STRING.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
407 For index of first char beyond the match, do (match-end 0).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
408 `match-end' and `match-beginning' also give indices of substrings
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
409 matched by parenthesis constructs in the pattern. */)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
410 (regexp, string, start)
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
411 Lisp_Object regexp, string, start;
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
412 {
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
413 return string_match_1 (regexp, string, start, 1);
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
414 }
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
415
842
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
416 /* Match REGEXP against STRING, searching all of STRING,
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
417 and return the index of the match, or negative on failure.
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
418 This does not clobber the match data. */
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
419
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
420 int
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
421 fast_string_match (regexp, string)
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
422 Lisp_Object regexp, string;
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
423 {
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
424 int val;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
425 struct re_pattern_buffer *bufp;
842
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
426
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
427 bufp = compile_pattern (regexp, 0, Qnil,
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
428 0, STRING_MULTIBYTE (string));
842
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
429 immediate_quit = 1;
17463
bb9ae80d22e2 (looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents: 17284
diff changeset
430 re_match_object = string;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
431
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
432 val = re_search (bufp, (char *) SDATA (string),
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
433 SBYTES (string), 0,
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
434 SBYTES (string), 0);
842
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
435 immediate_quit = 0;
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
436 return val;
5ce0a9ac1ea7 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 808
diff changeset
437 }
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
438
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
439 /* Match REGEXP against STRING, searching all of STRING ignoring case,
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
440 and return the index of the match, or negative on failure.
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
441 This does not clobber the match data.
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
442 We assume that STRING contains single-byte characters. */
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
443
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
444 extern Lisp_Object Vascii_downcase_table;
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
445
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
446 int
18193
4e4c8edb56da (fast_c_string_match_ignore_case):
Richard M. Stallman <rms@gnu.org>
parents: 18124
diff changeset
447 fast_c_string_match_ignore_case (regexp, string)
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
448 Lisp_Object regexp;
46474
e01b3a5fd791 (fast_c_string_match_ignore_case): String pointer args
Ken Raeburn <raeburn@raeburn.org>
parents: 46444
diff changeset
449 const char *string;
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
450 {
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
451 int val;
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
452 struct re_pattern_buffer *bufp;
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
453 int len = strlen (string);
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
454
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
455 regexp = string_make_unibyte (regexp);
18193
4e4c8edb56da (fast_c_string_match_ignore_case):
Richard M. Stallman <rms@gnu.org>
parents: 18124
diff changeset
456 re_match_object = Qt;
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
457 bufp = compile_pattern (regexp, 0,
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
458 Vascii_downcase_table, 0,
20671
be91d6130341 (compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents: 20588
diff changeset
459 0);
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
460 immediate_quit = 1;
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
461 val = re_search (bufp, string, len, 0, len, 0);
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
462 immediate_quit = 0;
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
463 return val;
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
464 }
57572
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
465
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
466 /* Like fast_string_match but ignore case. */
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
467
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
468 int
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
469 fast_string_match_ignore_case (regexp, string)
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
470 Lisp_Object regexp, string;
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
471 {
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
472 int val;
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
473 struct re_pattern_buffer *bufp;
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
474
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
475 bufp = compile_pattern (regexp, 0, Vascii_downcase_table,
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
476 0, STRING_MULTIBYTE (string));
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
477 immediate_quit = 1;
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
478 re_match_object = string;
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
479
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
480 val = re_search (bufp, (char *) SDATA (string),
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
481 SBYTES (string), 0,
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
482 SBYTES (string), 0);
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
483 immediate_quit = 0;
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
484 return val;
d226830a814e (fast_string_match_ignore_case): New function.
Kenichi Handa <handa@m17n.org>
parents: 56429
diff changeset
485 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
487 /* The newline cache: remembering which sections of text have no newlines. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
488
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
489 /* If the user has requested newline caching, make sure it's on.
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
490 Otherwise, make sure it's off.
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
491 This is our cheezy way of associating an action with the change of
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
492 state of a buffer-local variable. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
493 static void
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
494 newline_cache_on_off (buf)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
495 struct buffer *buf;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
496 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
497 if (NILP (buf->cache_long_line_scans))
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
498 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
499 /* It should be off. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
500 if (buf->newline_cache)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
501 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
502 free_region_cache (buf->newline_cache);
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
503 buf->newline_cache = 0;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
504 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
505 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
506 else
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
507 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
508 /* It should be on. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
509 if (buf->newline_cache == 0)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
510 buf->newline_cache = new_region_cache ();
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
511 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
512 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
513
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
514
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
515 /* Search for COUNT instances of the character TARGET between START and END.
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
516
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
517 If COUNT is positive, search forwards; END must be >= START.
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
518 If COUNT is negative, search backwards for the -COUNTth instance;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
519 END must be <= START.
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
520 If COUNT is zero, do anything you please; run rogue, for all I care.
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
521
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
522 If END is zero, use BEGV or ZV instead, as appropriate for the
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
523 direction indicated by COUNT.
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 639
diff changeset
524
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 639
diff changeset
525 If we find COUNT instances, set *SHORTAGE to zero, and return the
57735
82bd283dbbf8 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 57572
diff changeset
526 position past the COUNTth match. Note that for reverse motion
1413
527af9fa8676 Comment fix.
Richard M. Stallman <rms@gnu.org>
parents: 842
diff changeset
527 this is not the same as the usual convention for Emacs motion commands.
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 639
diff changeset
528
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
529 If we don't find COUNT instances before reaching END, set *SHORTAGE
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
530 to the number of TARGETs left unfound, and return END.
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 639
diff changeset
531
5756
a54c236b43c6 (scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents: 5556
diff changeset
532 If ALLOW_QUIT is non-zero, set immediate_quit. That's good to do
a54c236b43c6 (scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents: 5556
diff changeset
533 except when inside redisplay. */
a54c236b43c6 (scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents: 5556
diff changeset
534
21514
fa9ff387d260 Fix -Wimplicit warnings.
Andreas Schwab <schwab@suse.de>
parents: 21457
diff changeset
535 int
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
536 scan_buffer (target, start, end, count, shortage, allow_quit)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
537 register int target;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
538 int start, end;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
539 int count;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
540 int *shortage;
5756
a54c236b43c6 (scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents: 5556
diff changeset
541 int allow_quit;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
542 {
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
543 struct region_cache *newline_cache;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
544 int direction;
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 639
diff changeset
545
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
546 if (count > 0)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
547 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
548 direction = 1;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
549 if (! end) end = ZV;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
550 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
551 else
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
552 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
553 direction = -1;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
554 if (! end) end = BEGV;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
555 }
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 639
diff changeset
556
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
557 newline_cache_on_off (current_buffer);
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
558 newline_cache = current_buffer->newline_cache;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
559
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
560 if (shortage != 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
561 *shortage = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
562
5756
a54c236b43c6 (scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents: 5556
diff changeset
563 immediate_quit = allow_quit;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
564
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 639
diff changeset
565 if (count > 0)
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
566 while (start != end)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
567 {
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
568 /* Our innermost scanning loop is very simple; it doesn't know
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
569 about gaps, buffer ends, or the newline cache. ceiling is
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
570 the position of the last character before the next such
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
571 obstacle --- the last character the dumb search loop should
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
572 examine. */
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
573 int ceiling_byte = CHAR_TO_BYTE (end) - 1;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
574 int start_byte = CHAR_TO_BYTE (start);
21457
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
575 int tem;
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
576
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
577 /* If we're looking for a newline, consult the newline cache
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
578 to see where we can avoid some scanning. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
579 if (target == '\n' && newline_cache)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
580 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
581 int next_change;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
582 immediate_quit = 0;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
583 while (region_cache_forward
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
584 (current_buffer, newline_cache, start_byte, &next_change))
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
585 start_byte = next_change;
9452
76f75b9091f1 (scan_buffer): After temporarily turning immediate_quit off, turn it
Jim Blandy <jimb@redhat.com>
parents: 9410
diff changeset
586 immediate_quit = allow_quit;
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
587
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
588 /* START should never be after END. */
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
589 if (start_byte > ceiling_byte)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
590 start_byte = ceiling_byte;
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
591
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
592 /* Now the text after start is an unknown region, and
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
593 next_change is the position of the next known region. */
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
594 ceiling_byte = min (next_change - 1, ceiling_byte);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
595 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
596
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
597 /* The dumb loop can only scan text stored in contiguous
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
598 bytes. BUFFER_CEILING_OF returns the last character
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
599 position that is contiguous, so the ceiling is the
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
600 position after that. */
21457
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
601 tem = BUFFER_CEILING_OF (start_byte);
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
602 ceiling_byte = min (tem, ceiling_byte);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
603
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
604 {
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
605 /* The termination address of the dumb loop. */
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
606 register unsigned char *ceiling_addr
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
607 = BYTE_POS_ADDR (ceiling_byte) + 1;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
608 register unsigned char *cursor
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
609 = BYTE_POS_ADDR (start_byte);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
610 unsigned char *base = cursor;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
611
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
612 while (cursor < ceiling_addr)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
613 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
614 unsigned char *scan_start = cursor;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
615
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
616 /* The dumb loop. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
617 while (*cursor != target && ++cursor < ceiling_addr)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
618 ;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
619
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
620 /* If we're looking for newlines, cache the fact that
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
621 the region from start to cursor is free of them. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
622 if (target == '\n' && newline_cache)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
623 know_region_cache (current_buffer, newline_cache,
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
624 start_byte + scan_start - base,
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
625 start_byte + cursor - base);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
626
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
627 /* Did we find the target character? */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
628 if (cursor < ceiling_addr)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
629 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
630 if (--count == 0)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
631 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
632 immediate_quit = 0;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
633 return BYTE_TO_CHAR (start_byte + cursor - base + 1);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
634 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
635 cursor++;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
636 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
637 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
638
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
639 start = BYTE_TO_CHAR (start_byte + cursor - base);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
640 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
641 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
642 else
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
643 while (start > end)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
644 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
645 /* The last character to check before the next obstacle. */
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
646 int ceiling_byte = CHAR_TO_BYTE (end);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
647 int start_byte = CHAR_TO_BYTE (start);
21457
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
648 int tem;
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
649
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
650 /* Consult the newline cache, if appropriate. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
651 if (target == '\n' && newline_cache)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
652 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
653 int next_change;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
654 immediate_quit = 0;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
655 while (region_cache_backward
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
656 (current_buffer, newline_cache, start_byte, &next_change))
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
657 start_byte = next_change;
9452
76f75b9091f1 (scan_buffer): After temporarily turning immediate_quit off, turn it
Jim Blandy <jimb@redhat.com>
parents: 9410
diff changeset
658 immediate_quit = allow_quit;
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
659
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
660 /* Start should never be at or before end. */
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
661 if (start_byte <= ceiling_byte)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
662 start_byte = ceiling_byte + 1;
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
663
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
664 /* Now the text before start is an unknown region, and
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
665 next_change is the position of the next known region. */
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
666 ceiling_byte = max (next_change, ceiling_byte);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
667 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
668
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
669 /* Stop scanning before the gap. */
21457
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
670 tem = BUFFER_FLOOR_OF (start_byte - 1);
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
671 ceiling_byte = max (tem, ceiling_byte);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
672
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
673 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
674 /* The termination address of the dumb loop. */
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
675 register unsigned char *ceiling_addr = BYTE_POS_ADDR (ceiling_byte);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
676 register unsigned char *cursor = BYTE_POS_ADDR (start_byte - 1);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
677 unsigned char *base = cursor;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
678
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
679 while (cursor >= ceiling_addr)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
680 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
681 unsigned char *scan_start = cursor;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
682
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
683 while (*cursor != target && --cursor >= ceiling_addr)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
684 ;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
685
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
686 /* If we're looking for newlines, cache the fact that
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
687 the region from after the cursor to start is free of them. */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
688 if (target == '\n' && newline_cache)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
689 know_region_cache (current_buffer, newline_cache,
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
690 start_byte + cursor - base,
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
691 start_byte + scan_start - base);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
692
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
693 /* Did we find the target character? */
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
694 if (cursor >= ceiling_addr)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
695 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
696 if (++count >= 0)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
697 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
698 immediate_quit = 0;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
699 return BYTE_TO_CHAR (start_byte + cursor - base);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
700 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
701 cursor--;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
702 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
703 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
704
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
705 start = BYTE_TO_CHAR (start_byte + cursor - base);
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
706 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
707 }
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
708
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
709 immediate_quit = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
710 if (shortage != 0)
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 639
diff changeset
711 *shortage = count * direction;
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
712 return start;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
713 }
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
714
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
715 /* Search for COUNT instances of a line boundary, which means either a
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
716 newline or (if selective display enabled) a carriage return.
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
717 Start at START. If COUNT is negative, search backwards.
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
718
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
719 We report the resulting position by calling TEMP_SET_PT_BOTH.
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
720
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
721 If we find COUNT instances. we position after (always after,
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
722 even if scanning backwards) the COUNTth match, and return 0.
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
723
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
724 If we don't find COUNT instances before reaching the end of the
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
725 buffer (or the beginning, if scanning backwards), we return
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
726 the number of line boundaries left unfound, and position at
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
727 the limit we bumped up against.
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
728
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
729 If ALLOW_QUIT is non-zero, set immediate_quit. That's good to do
20547
07053199a368 (scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents: 20545
diff changeset
730 except in special cases. */
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
731
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
732 int
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
733 scan_newline (start, start_byte, limit, limit_byte, count, allow_quit)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
734 int start, start_byte;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
735 int limit, limit_byte;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
736 register int count;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
737 int allow_quit;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
738 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
739 int direction = ((count > 0) ? 1 : -1);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
740
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
741 register unsigned char *cursor;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
742 unsigned char *base;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
743
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
744 register int ceiling;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
745 register unsigned char *ceiling_addr;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
746
20547
07053199a368 (scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents: 20545
diff changeset
747 int old_immediate_quit = immediate_quit;
07053199a368 (scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents: 20545
diff changeset
748
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
749 /* The code that follows is like scan_buffer
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
750 but checks for either newline or carriage return. */
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
751
20547
07053199a368 (scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents: 20545
diff changeset
752 if (allow_quit)
07053199a368 (scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents: 20545
diff changeset
753 immediate_quit++;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
754
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
755 start_byte = CHAR_TO_BYTE (start);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
756
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
757 if (count > 0)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
758 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
759 while (start_byte < limit_byte)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
760 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
761 ceiling = BUFFER_CEILING_OF (start_byte);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
762 ceiling = min (limit_byte - 1, ceiling);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
763 ceiling_addr = BYTE_POS_ADDR (ceiling) + 1;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
764 base = (cursor = BYTE_POS_ADDR (start_byte));
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
765 while (1)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
766 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
767 while (*cursor != '\n' && ++cursor != ceiling_addr)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
768 ;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
769
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
770 if (cursor != ceiling_addr)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
771 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
772 if (--count == 0)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
773 {
20547
07053199a368 (scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents: 20545
diff changeset
774 immediate_quit = old_immediate_quit;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
775 start_byte = start_byte + cursor - base + 1;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
776 start = BYTE_TO_CHAR (start_byte);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
777 TEMP_SET_PT_BOTH (start, start_byte);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
778 return 0;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
779 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
780 else
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
781 if (++cursor == ceiling_addr)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
782 break;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
783 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
784 else
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
785 break;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
786 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
787 start_byte += cursor - base;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
788 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
789 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
790 else
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
791 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
792 while (start_byte > limit_byte)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
793 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
794 ceiling = BUFFER_FLOOR_OF (start_byte - 1);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
795 ceiling = max (limit_byte, ceiling);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
796 ceiling_addr = BYTE_POS_ADDR (ceiling) - 1;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
797 base = (cursor = BYTE_POS_ADDR (start_byte - 1) + 1);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
798 while (1)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
799 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
800 while (--cursor != ceiling_addr && *cursor != '\n')
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
801 ;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
802
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
803 if (cursor != ceiling_addr)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
804 {
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
805 if (++count == 0)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
806 {
20547
07053199a368 (scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents: 20545
diff changeset
807 immediate_quit = old_immediate_quit;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
808 /* Return the position AFTER the match we found. */
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
809 start_byte = start_byte + cursor - base + 1;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
810 start = BYTE_TO_CHAR (start_byte);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
811 TEMP_SET_PT_BOTH (start, start_byte);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
812 return 0;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
813 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
814 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
815 else
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
816 break;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
817 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
818 /* Here we add 1 to compensate for the last decrement
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
819 of CURSOR, which took it past the valid range. */
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
820 start_byte += cursor - base + 1;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
821 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
822 }
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
823
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
824 TEMP_SET_PT_BOTH (limit, limit_byte);
20547
07053199a368 (scan_newline): Always restore prev value of immediate_quit.
Richard M. Stallman <rms@gnu.org>
parents: 20545
diff changeset
825 immediate_quit = old_immediate_quit;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
826
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
827 return count * direction;
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
828 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
829
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
830 int
7891
7d8e0f338e4a (find_next_newline_no_quit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7856
diff changeset
831 find_next_newline_no_quit (from, cnt)
7d8e0f338e4a (find_next_newline_no_quit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7856
diff changeset
832 register int from, cnt;
7d8e0f338e4a (find_next_newline_no_quit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7856
diff changeset
833 {
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
834 return scan_buffer ('\n', from, 0, cnt, (int *) 0, 0);
7891
7d8e0f338e4a (find_next_newline_no_quit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7856
diff changeset
835 }
7d8e0f338e4a (find_next_newline_no_quit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7856
diff changeset
836
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
837 /* Like find_next_newline, but returns position before the newline,
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
838 not after, and only search up to TO. This isn't just
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
839 find_next_newline (...)-1, because you might hit TO. */
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
840
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
841 int
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
842 find_before_next_newline (from, to, cnt)
9452
76f75b9091f1 (scan_buffer): After temporarily turning immediate_quit off, turn it
Jim Blandy <jimb@redhat.com>
parents: 9410
diff changeset
843 int from, to, cnt;
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
844 {
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
845 int shortage;
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
846 int pos = scan_buffer ('\n', from, to, cnt, &shortage, 1);
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
847
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
848 if (shortage == 0)
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
849 pos--;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
850
9410
8598c3d6f2f0 * search.c: #include "region-cache.h".
Jim Blandy <jimb@redhat.com>
parents: 9319
diff changeset
851 return pos;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
852 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
853
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
854 /* Subroutines of Lisp buffer search functions. */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
855
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
856 static Lisp_Object
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
857 search_command (string, bound, noerror, count, direction, RE, posix)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
858 Lisp_Object string, bound, noerror, count;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
859 int direction;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
860 int RE;
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
861 int posix;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
862 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
863 register int np;
20824
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
864 int lim, lim_byte;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
865 int n = direction;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
866
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
867 if (!NILP (count))
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
868 {
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
869 CHECK_NUMBER (count);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
870 n *= XINT (count);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
871 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
872
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
873 CHECK_STRING (string);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
874 if (NILP (bound))
20824
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
875 {
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
876 if (n > 0)
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
877 lim = ZV, lim_byte = ZV_BYTE;
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
878 else
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
879 lim = BEGV, lim_byte = BEGV_BYTE;
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
880 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
881 else
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
882 {
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
883 CHECK_NUMBER_COERCE_MARKER (bound);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
884 lim = XINT (bound);
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15667
diff changeset
885 if (n > 0 ? lim < PT : lim > PT)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
886 error ("Invalid search bound (wrong side of point)");
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
887 if (lim > ZV)
20824
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
888 lim = ZV, lim_byte = ZV_BYTE;
20924
eda7e44ef9d9 (search_command): Check LIM in valid range
Karl Heuer <kwzh@gnu.org>
parents: 20898
diff changeset
889 else if (lim < BEGV)
20824
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
890 lim = BEGV, lim_byte = BEGV_BYTE;
20924
eda7e44ef9d9 (search_command): Check LIM in valid range
Karl Heuer <kwzh@gnu.org>
parents: 20898
diff changeset
891 else
eda7e44ef9d9 (search_command): Check LIM in valid range
Karl Heuer <kwzh@gnu.org>
parents: 20898
diff changeset
892 lim_byte = CHAR_TO_BYTE (lim);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
893 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
894
20824
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
895 np = search_buffer (string, PT, PT_BYTE, lim, lim_byte, n, RE,
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
896 (!NILP (current_buffer->case_fold_search)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
897 ? current_buffer->case_canon_table
20875
4fac9830041a (search_command): Fix call to search_buffer.
Richard M. Stallman <rms@gnu.org>
parents: 20869
diff changeset
898 : Qnil),
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
899 (!NILP (current_buffer->case_fold_search)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
900 ? current_buffer->case_eqv_table
20875
4fac9830041a (search_command): Fix call to search_buffer.
Richard M. Stallman <rms@gnu.org>
parents: 20869
diff changeset
901 : Qnil),
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
902 posix);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
903 if (np <= 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
904 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
905 if (NILP (noerror))
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
906 return signal_failure (string);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
907 if (!EQ (noerror, Qt))
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
908 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
909 if (lim < BEGV || lim > ZV)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
910 abort ();
20824
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
911 SET_PT_BOTH (lim, lim_byte);
1878
1c26d0049d4f (search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents: 1877
diff changeset
912 return Qnil;
1c26d0049d4f (search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents: 1877
diff changeset
913 #if 0 /* This would be clean, but maybe programs depend on
1c26d0049d4f (search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents: 1877
diff changeset
914 a value of nil here. */
1877
7786f61ec635 (search_command): When moving to LIM on failure, return LIM.
Richard M. Stallman <rms@gnu.org>
parents: 1684
diff changeset
915 np = lim;
1878
1c26d0049d4f (search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents: 1877
diff changeset
916 #endif
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
917 }
1877
7786f61ec635 (search_command): When moving to LIM on failure, return LIM.
Richard M. Stallman <rms@gnu.org>
parents: 1684
diff changeset
918 else
7786f61ec635 (search_command): When moving to LIM on failure, return LIM.
Richard M. Stallman <rms@gnu.org>
parents: 1684
diff changeset
919 return Qnil;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
920 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
921
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
922 if (np < BEGV || np > ZV)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
923 abort ();
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
924
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
925 SET_PT (np);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
926
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
927 return make_number (np);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
928 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
929
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
930 /* Return 1 if REGEXP it matches just one constant string. */
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
931
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
932 static int
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
933 trivial_regexp_p (regexp)
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
934 Lisp_Object regexp;
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
935 {
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
936 int len = SBYTES (regexp);
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
937 unsigned char *s = SDATA (regexp);
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
938 while (--len >= 0)
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
939 {
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
940 switch (*s++)
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
941 {
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
942 case '.': case '*': case '+': case '?': case '[': case '^': case '$':
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
943 return 0;
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
944 case '\\':
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
945 if (--len < 0)
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
946 return 0;
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
947 switch (*s++)
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
948 {
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
949 case '|': case '(': case ')': case '`': case '\'': case 'b':
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
950 case 'B': case '<': case '>': case 'w': case 'W': case 's':
55689
f4a937a898f4 (trivial_regexp_p): \_ is no longer a trivial regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53719
diff changeset
951 case 'S': case '=': case '{': case '}': case '_':
17053
df904355f033 Include category.h and charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16880
diff changeset
952 case 'c': case 'C': /* for categoryspec and notcategoryspec */
12069
505dc29a68cf (trivial_regexp_p): = is special after \.
Karl Heuer <kwzh@gnu.org>
parents: 11678
diff changeset
953 case '1': case '2': case '3': case '4': case '5':
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
954 case '6': case '7': case '8': case '9':
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
955 return 0;
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
956 }
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
957 }
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
958 }
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
959 return 1;
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
960 }
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
961
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
962 /* Search for the n'th occurrence of STRING in the current buffer,
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
963 starting at position POS and stopping at position LIM,
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
964 treating STRING as a literal string if RE is false or as
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
965 a regular expression if RE is true.
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
966
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
967 If N is positive, searching is forward and LIM must be greater than POS.
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
968 If N is negative, searching is backward and LIM must be less than POS.
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
969
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
970 Returns -x if x occurrences remain to be found (x > 0),
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
971 or else the position at the beginning of the Nth occurrence
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
972 (if searching backward) or the end (if searching forward).
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
973
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
974 POSIX is nonzero if we want full backtracking (POSIX style)
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
975 for this pattern. 0 means backtrack only enough to get a valid match. */
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
976
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
977 #define TRANSLATE(out, trt, d) \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
978 do \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
979 { \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
980 if (! NILP (trt)) \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
981 { \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
982 Lisp_Object temp; \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
983 temp = Faref (trt, make_number (d)); \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
984 if (INTEGERP (temp)) \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
985 out = XINT (temp); \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
986 else \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
987 out = d; \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
988 } \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
989 else \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
990 out = d; \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
991 } \
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
992 while (0)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
993
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
994 static int
20824
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
995 search_buffer (string, pos, pos_byte, lim, lim_byte, n,
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
996 RE, trt, inverse_trt, posix)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
997 Lisp_Object string;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
998 int pos;
20824
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
999 int pos_byte;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1000 int lim;
20824
97df0c6e753d (search_buffer): New args pos_byte and lim_byte.
Richard M. Stallman <rms@gnu.org>
parents: 20792
diff changeset
1001 int lim_byte;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1002 int n;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1003 int RE;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1004 Lisp_Object trt;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1005 Lisp_Object inverse_trt;
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
1006 int posix;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1007 {
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1008 int len = SCHARS (string);
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1009 int len_byte = SBYTES (string);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1010 register int i;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1011
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
1012 if (running_asynch_code)
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
1013 save_search_regs ();
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
1014
22082
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
1015 /* Searching 0 times means don't move. */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1016 /* Null string is found at starting position. */
22082
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
1017 if (len == 0 || n == 0)
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1018 {
35831
dc8b618615ea (search_buffer): Call set_search_regs with a byte
Gerd Moellmann <gerd@gnu.org>
parents: 34966
diff changeset
1019 set_search_regs (pos_byte, 0);
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1020 return pos;
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1021 }
4299
7a2e1d7362c5 (search_buffer): If n is 0, just return POS.
Richard M. Stallman <rms@gnu.org>
parents: 3615
diff changeset
1022
58348
623ffd21f0ff (Vsearch_spaces_regexp):
Richard M. Stallman <rms@gnu.org>
parents: 58330
diff changeset
1023 if (RE && !(trivial_regexp_p (string) && NILP (Vsearch_spaces_regexp)))
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1024 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1025 unsigned char *p1, *p2;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1026 int s1, s2;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
1027 struct re_pattern_buffer *bufp;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
1028
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1029 bufp = compile_pattern (string, &search_regs, trt, posix,
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1030 !NILP (current_buffer->enable_multibyte_characters));
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1031
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1032 immediate_quit = 1; /* Quit immediately if user types ^G,
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1033 because letting this function finish
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1034 can take too long. */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1035 QUIT; /* Do a pending quit right away,
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1036 to avoid paradoxical behavior */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1037 /* Get pointers and sizes of the two strings
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1038 that make up the visible portion of the buffer. */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1039
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1040 p1 = BEGV_ADDR;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1041 s1 = GPT_BYTE - BEGV_BYTE;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1042 p2 = GAP_END_ADDR;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1043 s2 = ZV_BYTE - GPT_BYTE;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1044 if (s1 < 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1045 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1046 p2 = p1;
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1047 s2 = ZV_BYTE - BEGV_BYTE;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1048 s1 = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1049 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1050 if (s2 < 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1051 {
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1052 s1 = ZV_BYTE - BEGV_BYTE;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1053 s2 = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1054 }
17463
bb9ae80d22e2 (looking_at_1): Set re_match_object.
Richard M. Stallman <rms@gnu.org>
parents: 17284
diff changeset
1055 re_match_object = Qnil;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
1056
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1057 while (n < 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1058 {
2475
052bbdf1b817 (search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents: 2439
diff changeset
1059 int val;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
1060 val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2,
20792
f0aa5cc14e8a (fast_string_match): Give re_search byte size of
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
1061 pos_byte - BEGV_BYTE, lim_byte - pos_byte,
f0aa5cc14e8a (fast_string_match): Give re_search byte size of
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
1062 &search_regs,
2475
052bbdf1b817 (search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents: 2439
diff changeset
1063 /* Don't allow match past current point */
20792
f0aa5cc14e8a (fast_string_match): Give re_search byte size of
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
1064 pos_byte - BEGV_BYTE);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1065 if (val == -2)
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1066 {
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1067 matcher_overflow ();
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1068 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1069 if (val >= 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1070 {
20927
765fdbf766e4 (search_buffer): Update POS_BYTE for regexp search.
Kenichi Handa <handa@m17n.org>
parents: 20924
diff changeset
1071 pos_byte = search_regs.start[0] + BEGV_BYTE;
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
1072 for (i = 0; i < search_regs.num_regs; i++)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1073 if (search_regs.start[i] >= 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1074 {
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1075 search_regs.start[i]
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1076 = BYTE_TO_CHAR (search_regs.start[i] + BEGV_BYTE);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1077 search_regs.end[i]
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1078 = BYTE_TO_CHAR (search_regs.end[i] + BEGV_BYTE);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1079 }
9278
f2138d548313 (Flooking_at, skip_chars, search_buffer, set_search_regs, Fstore_match_data):
Karl Heuer <kwzh@gnu.org>
parents: 9113
diff changeset
1080 XSETBUFFER (last_thing_searched, current_buffer);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1081 /* Set pos to the new position. */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1082 pos = search_regs.start[0];
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1083 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1084 else
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1085 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1086 immediate_quit = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1087 return (n);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1088 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1089 n++;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1090 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1091 while (n > 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1092 {
2475
052bbdf1b817 (search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents: 2439
diff changeset
1093 int val;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
1094 val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2,
20792
f0aa5cc14e8a (fast_string_match): Give re_search byte size of
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
1095 pos_byte - BEGV_BYTE, lim_byte - pos_byte,
f0aa5cc14e8a (fast_string_match): Give re_search byte size of
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
1096 &search_regs,
f0aa5cc14e8a (fast_string_match): Give re_search byte size of
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
1097 lim_byte - BEGV_BYTE);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1098 if (val == -2)
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1099 {
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1100 matcher_overflow ();
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1101 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1102 if (val >= 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1103 {
20927
765fdbf766e4 (search_buffer): Update POS_BYTE for regexp search.
Kenichi Handa <handa@m17n.org>
parents: 20924
diff changeset
1104 pos_byte = search_regs.end[0] + BEGV_BYTE;
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
1105 for (i = 0; i < search_regs.num_regs; i++)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1106 if (search_regs.start[i] >= 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1107 {
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1108 search_regs.start[i]
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1109 = BYTE_TO_CHAR (search_regs.start[i] + BEGV_BYTE);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1110 search_regs.end[i]
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1111 = BYTE_TO_CHAR (search_regs.end[i] + BEGV_BYTE);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1112 }
9278
f2138d548313 (Flooking_at, skip_chars, search_buffer, set_search_regs, Fstore_match_data):
Karl Heuer <kwzh@gnu.org>
parents: 9113
diff changeset
1113 XSETBUFFER (last_thing_searched, current_buffer);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1114 pos = search_regs.end[0];
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1115 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1116 else
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1117 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1118 immediate_quit = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1119 return (0 - n);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1120 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1121 n--;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1122 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1123 immediate_quit = 0;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1124 return (pos);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1125 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1126 else /* non-RE case */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1127 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1128 unsigned char *raw_pattern, *pat;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1129 int raw_pattern_size;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1130 int raw_pattern_size_byte;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1131 unsigned char *patbuf;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1132 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1133 unsigned char *base_pat = SDATA (string);
89483
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
1134 /* High bits of char; 0 for ASCII characters, (CHAR & ~0x3F)
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
1135 otherwise. Characters of the same high bits have the same
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
1136 sequence of bytes but last. To do the BM search, all
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
1137 characters in STRING must have the same high bits (including
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
1138 their case translations). */
89130
e18339404909 (search_buffer): Fix case-fold-search of multibyte
Kenichi Handa <handa@m17n.org>
parents: 89062
diff changeset
1139 int char_high_bits = -1;
23876
8d2f38338c81 (search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents: 23790
diff changeset
1140 int boyer_moore_ok = 1;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1141
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1142 /* MULTIBYTE says whether the text to be searched is multibyte.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1143 We must convert PATTERN to match that, or we will not really
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1144 find things right. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1145
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1146 if (multibyte == STRING_MULTIBYTE (string))
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1147 {
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1148 raw_pattern = (unsigned char *) SDATA (string);
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1149 raw_pattern_size = SCHARS (string);
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1150 raw_pattern_size_byte = SBYTES (string);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1151 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1152 else if (multibyte)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1153 {
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1154 raw_pattern_size = SCHARS (string);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1155 raw_pattern_size_byte
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1156 = count_size_as_multibyte (SDATA (string),
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1157 raw_pattern_size);
21915
8f1159b417c2 (search_buffer): Fix casts when assigning raw_pattern.
Richard M. Stallman <rms@gnu.org>
parents: 21887
diff changeset
1158 raw_pattern = (unsigned char *) alloca (raw_pattern_size_byte + 1);
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1159 copy_text (SDATA (string), raw_pattern,
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1160 SCHARS (string), 0, 1);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1161 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1162 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1163 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1164 /* Converting multibyte to single-byte.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1165
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1166 ??? Perhaps this conversion should be done in a special way
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1167 by subtracting nonascii-insert-offset from each non-ASCII char,
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1168 so that only the multibyte chars which really correspond to
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1169 the chosen single-byte character set can possibly match. */
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1170 raw_pattern_size = SCHARS (string);
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1171 raw_pattern_size_byte = SCHARS (string);
21915
8f1159b417c2 (search_buffer): Fix casts when assigning raw_pattern.
Richard M. Stallman <rms@gnu.org>
parents: 21887
diff changeset
1172 raw_pattern = (unsigned char *) alloca (raw_pattern_size + 1);
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1173 copy_text (SDATA (string), raw_pattern,
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1174 SBYTES (string), 1, 0);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1175 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1176
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1177 /* Copy and optionally translate the pattern. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1178 len = raw_pattern_size;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1179 len_byte = raw_pattern_size_byte;
89130
e18339404909 (search_buffer): Fix case-fold-search of multibyte
Kenichi Handa <handa@m17n.org>
parents: 89062
diff changeset
1180 patbuf = (unsigned char *) alloca (len * MAX_MULTIBYTE_LENGTH);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1181 pat = patbuf;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1182 base_pat = raw_pattern;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1183 if (multibyte)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1184 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1185 while (--len >= 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1186 {
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1187 int c, translated, inverse;
89130
e18339404909 (search_buffer): Fix case-fold-search of multibyte
Kenichi Handa <handa@m17n.org>
parents: 89062
diff changeset
1188 int in_charlen;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1189
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1190 /* If we got here and the RE flag is set, it's because we're
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1191 dealing with a regexp known to be trivial, so the backslash
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1192 just quotes the next character. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1193 if (RE && *base_pat == '\\')
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1194 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1195 len--;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1196 len_byte--;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1197 base_pat++;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1198 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1199
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1200 c = STRING_CHAR_AND_LENGTH (base_pat, len_byte, in_charlen);
23876
8d2f38338c81 (search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents: 23790
diff changeset
1201
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1202 /* Translate the character, if requested. */
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1203 TRANSLATE (translated, trt, c);
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1204 TRANSLATE (inverse, inverse_trt, c);
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1205
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1206 /* Did this char actually get translated?
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1207 Would any other char get translated into it? */
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1208 if (translated != c || inverse != c)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1209 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1210 /* Keep track of which character set row
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1211 contains the characters that need translation. */
89483
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
1212 int this_high_bit = ASCII_CHAR_P (c) ? 0 : (c & ~0x3F);
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
1213 int c1 = inverse != c ? inverse : translated;
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
1214 int trt_high_bit = ASCII_CHAR_P (c1) ? 0 : (c1 & ~0x3F);
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
1215
89130
e18339404909 (search_buffer): Fix case-fold-search of multibyte
Kenichi Handa <handa@m17n.org>
parents: 89062
diff changeset
1216 if (this_high_bit != trt_high_bit)
45263
eeec3bb72a1b (search_buffer): Give up boyer moore search if inverse
Kenichi Handa <handa@m17n.org>
parents: 45217
diff changeset
1217 boyer_moore_ok = 0;
89130
e18339404909 (search_buffer): Fix case-fold-search of multibyte
Kenichi Handa <handa@m17n.org>
parents: 89062
diff changeset
1218 else if (char_high_bits == -1)
e18339404909 (search_buffer): Fix case-fold-search of multibyte
Kenichi Handa <handa@m17n.org>
parents: 89062
diff changeset
1219 char_high_bits = this_high_bit;
e18339404909 (search_buffer): Fix case-fold-search of multibyte
Kenichi Handa <handa@m17n.org>
parents: 89062
diff changeset
1220 else if (char_high_bits != this_high_bit)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1221 /* If two different rows appear, needing translation,
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1222 then we cannot use boyer_moore search. */
23876
8d2f38338c81 (search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents: 23790
diff changeset
1223 boyer_moore_ok = 0;
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1224 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1225
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1226 /* Store this character into the translated pattern. */
89130
e18339404909 (search_buffer): Fix case-fold-search of multibyte
Kenichi Handa <handa@m17n.org>
parents: 89062
diff changeset
1227 CHAR_STRING_ADVANCE (translated, pat);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1228 base_pat += in_charlen;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1229 len_byte -= in_charlen;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1230 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1231 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1232 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1233 {
23876
8d2f38338c81 (search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents: 23790
diff changeset
1234 /* Unibyte buffer. */
89130
e18339404909 (search_buffer): Fix case-fold-search of multibyte
Kenichi Handa <handa@m17n.org>
parents: 89062
diff changeset
1235 char_high_bits = 0;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1236 while (--len >= 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1237 {
23876
8d2f38338c81 (search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents: 23790
diff changeset
1238 int c, translated;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1239
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1240 /* If we got here and the RE flag is set, it's because we're
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1241 dealing with a regexp known to be trivial, so the backslash
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1242 just quotes the next character. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1243 if (RE && *base_pat == '\\')
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1244 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1245 len--;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1246 base_pat++;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1247 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1248 c = *base_pat++;
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1249 TRANSLATE (translated, trt, c);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1250 *pat++ = translated;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1251 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1252 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1253
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1254 len_byte = pat - patbuf;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1255 len = raw_pattern_size;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1256 pat = base_pat = patbuf;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1257
23876
8d2f38338c81 (search_buffer): Don't use Boyer-Moore
Kenichi Handa <handa@m17n.org>
parents: 23790
diff changeset
1258 if (boyer_moore_ok)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1259 return boyer_moore (n, pat, len, len_byte, trt, inverse_trt,
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1260 pos, pos_byte, lim, lim_byte,
89130
e18339404909 (search_buffer): Fix case-fold-search of multibyte
Kenichi Handa <handa@m17n.org>
parents: 89062
diff changeset
1261 char_high_bits);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1262 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1263 return simple_search (n, pat, len, len_byte, trt,
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1264 pos, pos_byte, lim, lim_byte);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1265 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1266 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1267
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1268 /* Do a simple string search N times for the string PAT,
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1269 whose length is LEN/LEN_BYTE,
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1270 from buffer position POS/POS_BYTE until LIM/LIM_BYTE.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1271 TRT is the translation table.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1272
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1273 Return the character position where the match is found.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1274 Otherwise, if M matches remained to be found, return -M.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1275
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1276 This kind of search works regardless of what is in PAT and
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1277 regardless of what is in TRT. It is used in cases where
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1278 boyer_moore cannot work. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1279
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1280 static int
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1281 simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1282 int n;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1283 unsigned char *pat;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1284 int len, len_byte;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1285 Lisp_Object trt;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1286 int pos, pos_byte;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1287 int lim, lim_byte;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1288 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1289 int multibyte = ! NILP (current_buffer->enable_multibyte_characters);
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1290 int forward = n > 0;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1291
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1292 if (lim > pos && multibyte)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1293 while (n > 0)
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1294 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1295 while (1)
20671
be91d6130341 (compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents: 20588
diff changeset
1296 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1297 /* Try matching at position POS. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1298 int this_pos = pos;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1299 int this_pos_byte = pos_byte;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1300 int this_len = len;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1301 int this_len_byte = len_byte;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1302 unsigned char *p = pat;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1303 if (pos + len > lim)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1304 goto stop;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1305
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1306 while (this_len > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1307 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1308 int charlen, buf_charlen;
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1309 int pat_ch, buf_ch;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1310
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1311 pat_ch = STRING_CHAR_AND_LENGTH (p, this_len_byte, charlen);
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1312 buf_ch = STRING_CHAR_AND_LENGTH (BYTE_POS_ADDR (this_pos_byte),
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1313 ZV_BYTE - this_pos_byte,
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1314 buf_charlen);
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1315 TRANSLATE (buf_ch, trt, buf_ch);
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1316
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1317 if (buf_ch != pat_ch)
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1318 break;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1319
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1320 this_len_byte -= charlen;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1321 this_len--;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1322 p += charlen;
20671
be91d6130341 (compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents: 20588
diff changeset
1323
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1324 this_pos_byte += buf_charlen;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1325 this_pos++;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1326 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1327
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1328 if (this_len == 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1329 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1330 pos += len;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1331 pos_byte += len_byte;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1332 break;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1333 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1334
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1335 INC_BOTH (pos, pos_byte);
20671
be91d6130341 (compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents: 20588
diff changeset
1336 }
be91d6130341 (compile_pattern_1): If representation of STRING
Karl Heuer <kwzh@gnu.org>
parents: 20588
diff changeset
1337
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1338 n--;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1339 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1340 else if (lim > pos)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1341 while (n > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1342 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1343 while (1)
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1344 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1345 /* Try matching at position POS. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1346 int this_pos = pos;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1347 int this_len = len;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1348 unsigned char *p = pat;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1349
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1350 if (pos + len > lim)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1351 goto stop;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1352
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1353 while (this_len > 0)
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1354 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1355 int pat_ch = *p++;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1356 int buf_ch = FETCH_BYTE (this_pos);
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1357 TRANSLATE (buf_ch, trt, buf_ch);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1358
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1359 if (buf_ch != pat_ch)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1360 break;
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1361
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1362 this_len--;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1363 this_pos++;
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1364 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1365
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1366 if (this_len == 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1367 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1368 pos += len;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1369 break;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1370 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1371
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1372 pos++;
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1373 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1374
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1375 n--;
8950
68ad2f08d735 (trivial_regexp_p): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8584
diff changeset
1376 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1377 /* Backwards search. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1378 else if (lim < pos && multibyte)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1379 while (n < 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1380 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1381 while (1)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1382 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1383 /* Try matching at position POS. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1384 int this_pos = pos - len;
89850
885b083d5599 (simple_search): Fix settingthis_pos_byte in backward search.
Kenichi Handa <handa@m17n.org>
parents: 89483
diff changeset
1385 int this_pos_byte;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1386 int this_len = len;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1387 int this_len_byte = len_byte;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1388 unsigned char *p = pat;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1389
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1390 if (pos - len < lim)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1391 goto stop;
89850
885b083d5599 (simple_search): Fix settingthis_pos_byte in backward search.
Kenichi Handa <handa@m17n.org>
parents: 89483
diff changeset
1392 this_pos_byte = CHAR_TO_BYTE (this_pos);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1393
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1394 while (this_len > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1395 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1396 int charlen, buf_charlen;
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1397 int pat_ch, buf_ch;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1398
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1399 pat_ch = STRING_CHAR_AND_LENGTH (p, this_len_byte, charlen);
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1400 buf_ch = STRING_CHAR_AND_LENGTH (BYTE_POS_ADDR (this_pos_byte),
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1401 ZV_BYTE - this_pos_byte,
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1402 buf_charlen);
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1403 TRANSLATE (buf_ch, trt, buf_ch);
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1404
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1405 if (buf_ch != pat_ch)
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1406 break;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1407
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1408 this_len_byte -= charlen;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1409 this_len--;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1410 p += charlen;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1411 this_pos_byte += buf_charlen;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1412 this_pos++;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1413 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1414
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1415 if (this_len == 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1416 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1417 pos -= len;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1418 pos_byte -= len_byte;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1419 break;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1420 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1421
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1422 DEC_BOTH (pos, pos_byte);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1423 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1424
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1425 n++;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1426 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1427 else if (lim < pos)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1428 while (n < 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1429 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1430 while (1)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1431 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1432 /* Try matching at position POS. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1433 int this_pos = pos - len;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1434 int this_len = len;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1435 unsigned char *p = pat;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1436
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1437 if (pos - len < lim)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1438 goto stop;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1439
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1440 while (this_len > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1441 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1442 int pat_ch = *p++;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1443 int buf_ch = FETCH_BYTE (this_pos);
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1444 TRANSLATE (buf_ch, trt, buf_ch);
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1445
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1446 if (buf_ch != pat_ch)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1447 break;
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1448 this_len--;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1449 this_pos++;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1450 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1451
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1452 if (this_len == 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1453 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1454 pos -= len;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1455 break;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1456 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1457
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1458 pos--;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1459 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1460
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1461 n++;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1462 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1463
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1464 stop:
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1465 if (n == 0)
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1466 {
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1467 if (forward)
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1468 set_search_regs ((multibyte ? pos_byte : pos) - len_byte, len_byte);
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1469 else
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1470 set_search_regs (multibyte ? pos_byte : pos, len_byte);
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1471
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1472 return pos;
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1473 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1474 else if (n > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1475 return -n;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1476 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1477 return n;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1478 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1479
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1480 /* Do Boyer-Moore search N times for the string PAT,
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1481 whose length is LEN/LEN_BYTE,
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1482 from buffer position POS/POS_BYTE until LIM/LIM_BYTE.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1483 DIRECTION says which direction we search in.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1484 TRT and INVERSE_TRT are translation tables.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1485
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1486 This kind of search works if all the characters in PAT that have
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1487 nontrivial translation are the same aside from the last byte. This
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1488 makes it possible to translate just the last byte of a character,
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1489 and do so after just a simple test of the context.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1490
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1491 If that criterion is not satisfied, do not call this function. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1492
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1493 static int
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1494 boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
89130
e18339404909 (search_buffer): Fix case-fold-search of multibyte
Kenichi Handa <handa@m17n.org>
parents: 89062
diff changeset
1495 pos, pos_byte, lim, lim_byte, char_high_bits)
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1496 int n;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1497 unsigned char *base_pat;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1498 int len, len_byte;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1499 Lisp_Object trt;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1500 Lisp_Object inverse_trt;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1501 int pos, pos_byte;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1502 int lim, lim_byte;
89130
e18339404909 (search_buffer): Fix case-fold-search of multibyte
Kenichi Handa <handa@m17n.org>
parents: 89062
diff changeset
1503 int char_high_bits;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1504 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1505 int direction = ((n > 0) ? 1 : -1);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1506 register int dirlen;
34966
23a62cf7d0eb (shrink_regexp_cache): Remove unused variable `cpp'.
Eli Zaretskii <eliz@gnu.org>
parents: 33052
diff changeset
1507 int infinity, limit, stride_for_teases = 0;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1508 register int *BM_tab;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1509 int *BM_tab_base;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
1510 register unsigned char *cursor, *p_limit;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1511 register int i, j;
21945
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1512 unsigned char *pat, *pat_end;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1513 int multibyte = ! NILP (current_buffer->enable_multibyte_characters);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1514
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1515 unsigned char simple_translate[0400];
31829
43566b0aec59 Avoid some more compiler warnings.
Gerd Moellmann <gerd@gnu.org>
parents: 31486
diff changeset
1516 int translate_prev_byte = 0;
43566b0aec59 Avoid some more compiler warnings.
Gerd Moellmann <gerd@gnu.org>
parents: 31486
diff changeset
1517 int translate_anteprev_byte = 0;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1518
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1519 #ifdef C_ALLOCA
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1520 int BM_tab_space[0400];
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1521 BM_tab = &BM_tab_space[0];
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1522 #else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1523 BM_tab = (int *) alloca (0400 * sizeof (int));
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1524 #endif
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1525 /* The general approach is that we are going to maintain that we know */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1526 /* the first (closest to the present position, in whatever direction */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1527 /* we're searching) character that could possibly be the last */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1528 /* (furthest from present position) character of a valid match. We */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1529 /* advance the state of our knowledge by looking at that character */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1530 /* and seeing whether it indeed matches the last character of the */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1531 /* pattern. If it does, we take a closer look. If it does not, we */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1532 /* move our pointer (to putative last characters) as far as is */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1533 /* logically possible. This amount of movement, which I call a */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1534 /* stride, will be the length of the pattern if the actual character */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1535 /* appears nowhere in the pattern, otherwise it will be the distance */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1536 /* from the last occurrence of that character to the end of the */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1537 /* pattern. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1538 /* As a coding trick, an enormous stride is coded into the table for */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1539 /* characters that match the last character. This allows use of only */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1540 /* a single test, a test for having gone past the end of the */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1541 /* permissible match region, to test for both possible matches (when */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1542 /* the stride goes past the end immediately) and failure to */
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
1543 /* match (where you get nudged past the end one stride at a time). */
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1544
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1545 /* Here we make a "mickey mouse" BM table. The stride of the search */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1546 /* is determined only by the last character of the putative match. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1547 /* If that character does not match, we will stride the proper */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1548 /* distance to propose a match that superimposes it on the last */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1549 /* instance of a character that matches it (per trt), or misses */
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
1550 /* it entirely if there is none. */
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1551
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1552 dirlen = len_byte * direction;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1553 infinity = dirlen - (lim_byte + pos_byte + len_byte + len_byte) * direction;
21945
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1554
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1555 /* Record position after the end of the pattern. */
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1556 pat_end = base_pat + len_byte;
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1557 /* BASE_PAT points to a character that we start scanning from.
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1558 It is the first character in a forward search,
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1559 the last character in a backward search. */
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1560 if (direction < 0)
21945
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1561 base_pat = pat_end - 1;
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1562
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1563 BM_tab_base = BM_tab;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1564 BM_tab += 0400;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1565 j = dirlen; /* to get it in a register */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1566 /* A character that does not appear in the pattern induces a */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1567 /* stride equal to the pattern length. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1568 while (BM_tab_base != BM_tab)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1569 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1570 *--BM_tab = j;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1571 *--BM_tab = j;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1572 *--BM_tab = j;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1573 *--BM_tab = j;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1574 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1575
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1576 /* We use this for translation, instead of TRT itself.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1577 We fill this in to handle the characters that actually
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1578 occur in the pattern. Others don't matter anyway! */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1579 bzero (simple_translate, sizeof simple_translate);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1580 for (i = 0; i < 0400; i++)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1581 simple_translate[i] = i;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1582
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1583 i = 0;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1584 while (i != infinity)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1585 {
21945
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1586 unsigned char *ptr = base_pat + i;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1587 i += direction;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1588 if (i == dirlen)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1589 i = infinity;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1590 if (! NILP (trt))
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1591 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1592 int ch;
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1593 int untranslated;
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1594 int this_translated = 1;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1595
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1596 if (multibyte
21945
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1597 /* Is *PTR the last byte of a character? */
bda081af77e7 (boyer_moore): Check more reliably for ptr[1] being
Richard M. Stallman <rms@gnu.org>
parents: 21915
diff changeset
1598 && (pat_end - ptr == 1 || CHAR_HEAD_P (ptr[1])))
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1599 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1600 unsigned char *charstart = ptr;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1601 while (! CHAR_HEAD_P (*charstart))
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1602 charstart--;
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1603 untranslated = STRING_CHAR (charstart, ptr - charstart + 1);
89483
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
1604 if (char_high_bits
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
1605 == (ASCII_CHAR_P (untranslated) ? 0 : untranslated & ~0x3F))
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1606 {
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1607 TRANSLATE (ch, trt, untranslated);
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1608 if (! CHAR_HEAD_P (*ptr))
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1609 {
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1610 translate_prev_byte = ptr[-1];
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1611 if (! CHAR_HEAD_P (translate_prev_byte))
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1612 translate_anteprev_byte = ptr[-2];
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1613 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1614 }
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1615 else
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1616 {
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1617 this_translated = 0;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1618 ch = *ptr;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1619 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1620 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1621 else if (!multibyte)
20898
f69969e35e78 (simple_search): Call set_search_regs.
Richard M. Stallman <rms@gnu.org>
parents: 20875
diff changeset
1622 TRANSLATE (ch, trt, *ptr);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1623 else
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1624 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1625 ch = *ptr;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1626 this_translated = 0;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1627 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1628
88463
656d99c0c155 (boyer_moore): Fix handling of mulitbyte character translation.
Kenichi Handa <handa@m17n.org>
parents: 88388
diff changeset
1629 if (this_translated
656d99c0c155 (boyer_moore): Fix handling of mulitbyte character translation.
Kenichi Handa <handa@m17n.org>
parents: 88388
diff changeset
1630 && ch >= 0200)
656d99c0c155 (boyer_moore): Fix handling of mulitbyte character translation.
Kenichi Handa <handa@m17n.org>
parents: 88388
diff changeset
1631 j = (ch & 0x3F) | 0200;
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1632 else
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1633 j = (unsigned char) ch;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1634
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1635 if (i == infinity)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1636 stride_for_teases = BM_tab[j];
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1637
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1638 BM_tab[j] = dirlen - i;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1639 /* A translation table is accompanied by its inverse -- see */
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
1640 /* comment following downcase_table for details */
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1641 if (this_translated)
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1642 {
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1643 int starting_ch = ch;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1644 int starting_j = j;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1645 while (1)
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1646 {
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1647 TRANSLATE (ch, inverse_trt, ch);
88463
656d99c0c155 (boyer_moore): Fix handling of mulitbyte character translation.
Kenichi Handa <handa@m17n.org>
parents: 88388
diff changeset
1648 if (ch > 0200)
656d99c0c155 (boyer_moore): Fix handling of mulitbyte character translation.
Kenichi Handa <handa@m17n.org>
parents: 88388
diff changeset
1649 j = (ch & 0x3F) | 0200;
21117
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1650 else
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1651 j = (unsigned char) ch;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1652
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1653 /* For all the characters that map into CH,
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1654 set up simple_translate to map the last byte
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1655 into STARTING_J. */
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1656 simple_translate[j] = starting_j;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1657 if (ch == starting_ch)
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1658 break;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1659 BM_tab[j] = dirlen - i;
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1660 }
a88d2c555a06 (simple_search): Don't count a character until it matches!
Richard M. Stallman <rms@gnu.org>
parents: 20965
diff changeset
1661 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1662 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1663 else
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1664 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1665 j = *ptr;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1666
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1667 if (i == infinity)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1668 stride_for_teases = BM_tab[j];
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1669 BM_tab[j] = dirlen - i;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1670 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1671 /* stride_for_teases tells how much to stride if we get a */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1672 /* match on the far character but are subsequently */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1673 /* disappointed, by recording what the stride would have been */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1674 /* for that character if the last character had been */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1675 /* different. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1676 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1677 infinity = dirlen - infinity;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1678 pos_byte += dirlen - ((direction > 0) ? direction : 0);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1679 /* loop invariant - POS_BYTE points at where last char (first
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1680 char if reverse) of pattern would align in a possible match. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1681 while (n != 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1682 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1683 int tail_end;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1684 unsigned char *tail_end_ptr;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1685
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1686 /* It's been reported that some (broken) compiler thinks that
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1687 Boolean expressions in an arithmetic context are unsigned.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1688 Using an explicit ?1:0 prevents this. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1689 if ((lim_byte - pos_byte - ((direction > 0) ? 1 : 0)) * direction
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1690 < 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1691 return (n * (0 - direction));
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1692 /* First we do the part we can by pointers (maybe nothing) */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1693 QUIT;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1694 pat = base_pat;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1695 limit = pos_byte - dirlen + direction;
21457
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1696 if (direction > 0)
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1697 {
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1698 limit = BUFFER_CEILING_OF (limit);
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1699 /* LIMIT is now the last (not beyond-last!) value POS_BYTE
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1700 can take on without hitting edge of buffer or the gap. */
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1701 limit = min (limit, pos_byte + 20000);
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1702 limit = min (limit, lim_byte - 1);
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1703 }
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1704 else
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1705 {
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1706 limit = BUFFER_FLOOR_OF (limit);
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1707 /* LIMIT is now the last (not beyond-last!) value POS_BYTE
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1708 can take on without hitting edge of buffer or the gap. */
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1709 limit = max (limit, pos_byte - 20000);
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1710 limit = max (limit, lim_byte);
8c6ea32aadfa (min, max): Make these macros, not functions.
Karl Heuer <kwzh@gnu.org>
parents: 21248
diff changeset
1711 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1712 tail_end = BUFFER_CEILING_OF (pos_byte) + 1;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1713 tail_end_ptr = BYTE_POS_ADDR (tail_end);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1714
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1715 if ((limit - pos_byte) * direction > 20)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1716 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1717 unsigned char *p2;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1718
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1719 p_limit = BYTE_POS_ADDR (limit);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1720 p2 = (cursor = BYTE_POS_ADDR (pos_byte));
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1721 /* In this loop, pos + cursor - p2 is the surrogate for pos */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1722 while (1) /* use one cursor setting as long as i can */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1723 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1724 if (direction > 0) /* worth duplicating */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1725 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1726 /* Use signed comparison if appropriate
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1727 to make cursor+infinity sure to be > p_limit.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1728 Assuming that the buffer lies in a range of addresses
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1729 that are all "positive" (as ints) or all "negative",
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1730 either kind of comparison will work as long
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1731 as we don't step by infinity. So pick the kind
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1732 that works when we do step by infinity. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1733 if ((EMACS_INT) (p_limit + infinity) > (EMACS_INT) p_limit)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1734 while ((EMACS_INT) cursor <= (EMACS_INT) p_limit)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1735 cursor += BM_tab[*cursor];
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1736 else
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1737 while ((EMACS_UINT) cursor <= (EMACS_UINT) p_limit)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1738 cursor += BM_tab[*cursor];
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1739 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1740 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1741 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1742 if ((EMACS_INT) (p_limit + infinity) < (EMACS_INT) p_limit)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1743 while ((EMACS_INT) cursor >= (EMACS_INT) p_limit)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1744 cursor += BM_tab[*cursor];
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1745 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1746 while ((EMACS_UINT) cursor >= (EMACS_UINT) p_limit)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1747 cursor += BM_tab[*cursor];
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1748 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1749 /* If you are here, cursor is beyond the end of the searched region. */
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1750 /* This can happen if you match on the far character of the pattern, */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1751 /* because the "stride" of that character is infinity, a number able */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1752 /* to throw you well beyond the end of the search. It can also */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1753 /* happen if you fail to match within the permitted region and would */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1754 /* otherwise try a character beyond that region */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1755 if ((cursor - p_limit) * direction <= len_byte)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1756 break; /* a small overrun is genuine */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1757 cursor -= infinity; /* large overrun = hit */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1758 i = dirlen - direction;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1759 if (! NILP (trt))
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1760 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1761 while ((i -= direction) + direction != 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1762 {
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1763 int ch;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1764 cursor -= direction;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1765 /* Translate only the last byte of a character. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1766 if (! multibyte
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1767 || ((cursor == tail_end_ptr
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1768 || CHAR_HEAD_P (cursor[1]))
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1769 && (CHAR_HEAD_P (cursor[0])
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1770 || (translate_prev_byte == cursor[-1]
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1771 && (CHAR_HEAD_P (translate_prev_byte)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1772 || translate_anteprev_byte == cursor[-2])))))
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1773 ch = simple_translate[*cursor];
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1774 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1775 ch = *cursor;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1776 if (pat[i] != ch)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1777 break;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1778 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1779 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1780 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1781 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1782 while ((i -= direction) + direction != 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1783 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1784 cursor -= direction;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1785 if (pat[i] != *cursor)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1786 break;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1787 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1788 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1789 cursor += dirlen - i - direction; /* fix cursor */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1790 if (i + direction == 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1791 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1792 int position;
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
1793
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1794 cursor -= direction;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1795
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1796 position = pos_byte + cursor - p2 + ((direction > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1797 ? 1 - len_byte : 0);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1798 set_search_regs (position, len_byte);
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
1799
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1800 if ((n -= direction) != 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1801 cursor += dirlen; /* to resume search */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1802 else
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1803 return ((direction > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1804 ? search_regs.end[0] : search_regs.start[0]);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1805 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1806 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1807 cursor += stride_for_teases; /* <sigh> we lose - */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1808 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1809 pos_byte += cursor - p2;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1810 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1811 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1812 /* Now we'll pick up a clump that has to be done the hard */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1813 /* way because it covers a discontinuity */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1814 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1815 limit = ((direction > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1816 ? BUFFER_CEILING_OF (pos_byte - dirlen + 1)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1817 : BUFFER_FLOOR_OF (pos_byte - dirlen - 1));
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1818 limit = ((direction > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1819 ? min (limit + len_byte, lim_byte - 1)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1820 : max (limit - len_byte, lim_byte));
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1821 /* LIMIT is now the last value POS_BYTE can have
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1822 and still be valid for a possible match. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1823 while (1)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1824 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1825 /* This loop can be coded for space rather than */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1826 /* speed because it will usually run only once. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1827 /* (the reach is at most len + 21, and typically */
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
1828 /* does not exceed len) */
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1829 while ((limit - pos_byte) * direction >= 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1830 pos_byte += BM_tab[FETCH_BYTE (pos_byte)];
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1831 /* now run the same tests to distinguish going off the */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1832 /* end, a match or a phony match. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1833 if ((pos_byte - limit) * direction <= len_byte)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1834 break; /* ran off the end */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1835 /* Found what might be a match.
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1836 Set POS_BYTE back to last (first if reverse) pos. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1837 pos_byte -= infinity;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1838 i = dirlen - direction;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1839 while ((i -= direction) + direction != 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1840 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1841 int ch;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1842 unsigned char *ptr;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1843 pos_byte -= direction;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1844 ptr = BYTE_POS_ADDR (pos_byte);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1845 /* Translate only the last byte of a character. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1846 if (! multibyte
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1847 || ((ptr == tail_end_ptr
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1848 || CHAR_HEAD_P (ptr[1]))
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1849 && (CHAR_HEAD_P (ptr[0])
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1850 || (translate_prev_byte == ptr[-1]
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1851 && (CHAR_HEAD_P (translate_prev_byte)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1852 || translate_anteprev_byte == ptr[-2])))))
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1853 ch = simple_translate[*ptr];
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1854 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1855 ch = *ptr;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1856 if (pat[i] != ch)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1857 break;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1858 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1859 /* Above loop has moved POS_BYTE part or all the way
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1860 back to the first pos (last pos if reverse).
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1861 Set it once again at the last (first if reverse) char. */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1862 pos_byte += dirlen - i- direction;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1863 if (i + direction == 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1864 {
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1865 int position;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1866 pos_byte -= direction;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1867
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1868 position = pos_byte + ((direction > 0) ? 1 - len_byte : 0);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1870 set_search_regs (position, len_byte);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1871
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1872 if ((n -= direction) != 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1873 pos_byte += dirlen; /* to resume search */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1874 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1875 return ((direction > 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1876 ? search_regs.end[0] : search_regs.start[0]);
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1877 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1878 else
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1879 pos_byte += stride_for_teases;
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1880 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1881 }
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1882 /* We have done one clump. Can we continue? */
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1883 if ((lim_byte - pos_byte) * direction < 0)
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1884 return ((0 - n) * direction);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1885 }
20869
c9f608f889b4 (boyer_moore, simple_search): New subroutines.
Richard M. Stallman <rms@gnu.org>
parents: 20824
diff changeset
1886 return BYTE_TO_CHAR (pos_byte);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1887 }
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1888
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1889 /* Record beginning BEG_BYTE and end BEG_BYTE + NBYTES
22082
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
1890 for the overall match just found in the current buffer.
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
1891 Also clear out the match data for registers 1 and up. */
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1892
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1893 static void
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1894 set_search_regs (beg_byte, nbytes)
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1895 int beg_byte, nbytes;
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1896 {
22082
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
1897 int i;
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
1898
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1899 /* Make sure we have registers in which to store
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1900 the match position. */
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1901 if (search_regs.num_regs == 0)
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1902 {
10250
422c3b96efda (set_search_regs): Really set search_regs.start and .end.
Richard M. Stallman <rms@gnu.org>
parents: 10141
diff changeset
1903 search_regs.start = (regoff_t *) xmalloc (2 * sizeof (regoff_t));
422c3b96efda (set_search_regs): Really set search_regs.start and .end.
Richard M. Stallman <rms@gnu.org>
parents: 10141
diff changeset
1904 search_regs.end = (regoff_t *) xmalloc (2 * sizeof (regoff_t));
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
1905 search_regs.num_regs = 2;
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1906 }
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1907
22082
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
1908 /* Clear out the other registers. */
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
1909 for (i = 1; i < search_regs.num_regs; i++)
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
1910 {
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
1911 search_regs.start[i] = -1;
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
1912 search_regs.end[i] = -1;
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
1913 }
84bcdbc46d71 (search_buffer): Set search regs for all success with an empty string.
Richard M. Stallman <rms@gnu.org>
parents: 21988
diff changeset
1914
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1915 search_regs.start[0] = BYTE_TO_CHAR (beg_byte);
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
1916 search_regs.end[0] = BYTE_TO_CHAR (beg_byte + nbytes);
9278
f2138d548313 (Flooking_at, skip_chars, search_buffer, set_search_regs, Fstore_match_data):
Karl Heuer <kwzh@gnu.org>
parents: 9113
diff changeset
1917 XSETBUFFER (last_thing_searched, current_buffer);
5556
14161cfec24a (set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents: 4954
diff changeset
1918 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1919
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1920 /* Given a string of words separated by word delimiters,
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1921 compute a regexp that matches those exact words
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1922 separated by arbitrary punctuation. */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1923
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1924 static Lisp_Object
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1925 wordify (string)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1926 Lisp_Object string;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1927 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1928 register unsigned char *p, *o;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1929 register int i, i_byte, len, punct_count = 0, word_count = 0;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1930 Lisp_Object val;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1931 int prev_c = 0;
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1932 int adjust;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1933
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
1934 CHECK_STRING (string);
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1935 p = SDATA (string);
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1936 len = SCHARS (string);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1937
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1938 for (i = 0, i_byte = 0; i < len; )
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1939 {
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1940 int c;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
1941
89062
be059fb97bac (compile_pattern_1): Don't adjust the multibyteness of
Kenichi Handa <handa@m17n.org>
parents: 89028
diff changeset
1942 FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1943
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1944 if (SYNTAX (c) != Sword)
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1945 {
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1946 punct_count++;
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1947 if (i > 0 && SYNTAX (prev_c) == Sword)
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1948 word_count++;
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1949 }
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1950
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1951 prev_c = c;
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1952 }
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1953
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1954 if (SYNTAX (prev_c) == Sword)
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1955 word_count++;
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1956 if (!word_count)
39805
e9374c065e86 (wordify): Use empty_string.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39682
diff changeset
1957 return empty_string;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1958
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
1959 adjust = - punct_count + 5 * (word_count - 1) + 4;
22640
929ad308aba6 (wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents: 22533
diff changeset
1960 if (STRING_MULTIBYTE (string))
929ad308aba6 (wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents: 22533
diff changeset
1961 val = make_uninit_multibyte_string (len + adjust,
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1962 SBYTES (string)
22640
929ad308aba6 (wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents: 22533
diff changeset
1963 + adjust);
929ad308aba6 (wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents: 22533
diff changeset
1964 else
929ad308aba6 (wordify): Fix i_byte even in unibyte case for copy loop.
Richard M. Stallman <rms@gnu.org>
parents: 22533
diff changeset
1965 val = make_uninit_string (len + adjust);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1966
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
1967 o = SDATA (val);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1968 *o++ = '\\';
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1969 *o++ = 'b';
21887
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1970 prev_c = 0;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1971
21887
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1972 for (i = 0, i_byte = 0; i < len; )
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1973 {
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1974 int c;
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1975 int i_byte_orig = i_byte;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
1976
89062
be059fb97bac (compile_pattern_1): Don't adjust the multibyteness of
Kenichi Handa <handa@m17n.org>
parents: 89028
diff changeset
1977 FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte);
21887
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1978
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1979 if (SYNTAX (c) == Sword)
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1980 {
46432
a4697b0a338e * search.c (wordify): Use SDATA.
Ken Raeburn <raeburn@raeburn.org>
parents: 46370
diff changeset
1981 bcopy (SDATA (string) + i_byte_orig, o,
21887
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1982 i_byte - i_byte_orig);
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1983 o += i_byte - i_byte_orig;
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1984 }
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1985 else if (i > 0 && SYNTAX (prev_c) == Sword && --word_count)
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1986 {
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1987 *o++ = '\\';
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1988 *o++ = 'W';
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1989 *o++ = '\\';
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1990 *o++ = 'W';
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1991 *o++ = '*';
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1992 }
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1993
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1994 prev_c = c;
1c9f20274f76 (wordify): Do the second loop by chars, not by bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21531
diff changeset
1995 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1996
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1997 *o++ = '\\';
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1998 *o++ = 'b';
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1999
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2000 return val;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2001 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2002
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2003 DEFUN ("search-backward", Fsearch_backward, Ssearch_backward, 1, 4,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2004 "MSearch backward: ",
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2005 doc: /* Search backward from point for STRING.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2006 Set point to the beginning of the occurrence found, and return point.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2007 An optional second argument bounds the search; it is a buffer position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2008 The match found must not extend before that position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2009 Optional third argument, if t, means if fail just return nil (no error).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2010 If not nil and not t, position at limit of search and return nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2011 Optional fourth argument is repeat count--search for successive occurrences.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2012
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2013 Search case-sensitivity is determined by the value of the variable
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2014 `case-fold-search', which see.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2015
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2016 See also the functions `match-beginning', `match-end' and `replace-match'. */)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2017 (string, bound, noerror, count)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2018 Lisp_Object string, bound, noerror, count;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2019 {
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2020 return search_command (string, bound, noerror, count, -1, 0, 0);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2021 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2022
19541
e7876a076881 (Fsearch_backward): Inherit the current input method on
Kenichi Handa <handa@m17n.org>
parents: 18762
diff changeset
2023 DEFUN ("search-forward", Fsearch_forward, Ssearch_forward, 1, 4, "MSearch: ",
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2024 doc: /* Search forward from point for STRING.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2025 Set point to the end of the occurrence found, and return point.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2026 An optional second argument bounds the search; it is a buffer position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2027 The match found must not extend after that position. nil is equivalent
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2028 to (point-max).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2029 Optional third argument, if t, means if fail just return nil (no error).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2030 If not nil and not t, move to limit of search and return nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2031 Optional fourth argument is repeat count--search for successive occurrences.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2032
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2033 Search case-sensitivity is determined by the value of the variable
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2034 `case-fold-search', which see.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2035
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2036 See also the functions `match-beginning', `match-end' and `replace-match'. */)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2037 (string, bound, noerror, count)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2038 Lisp_Object string, bound, noerror, count;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2039 {
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2040 return search_command (string, bound, noerror, count, 1, 0, 0);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2041 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2042
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2043 DEFUN ("word-search-backward", Fword_search_backward, Sword_search_backward, 1, 4,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2044 "sWord search backward: ",
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2045 doc: /* Search backward from point for STRING, ignoring differences in punctuation.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2046 Set point to the beginning of the occurrence found, and return point.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2047 An optional second argument bounds the search; it is a buffer position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2048 The match found must not extend before that position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2049 Optional third argument, if t, means if fail just return nil (no error).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2050 If not nil and not t, move to limit of search and return nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2051 Optional fourth argument is repeat count--search for successive occurrences. */)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2052 (string, bound, noerror, count)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2053 Lisp_Object string, bound, noerror, count;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2054 {
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2055 return search_command (wordify (string), bound, noerror, count, -1, 1, 0);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2056 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2057
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2058 DEFUN ("word-search-forward", Fword_search_forward, Sword_search_forward, 1, 4,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2059 "sWord search: ",
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2060 doc: /* Search forward from point for STRING, ignoring differences in punctuation.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2061 Set point to the end of the occurrence found, and return point.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2062 An optional second argument bounds the search; it is a buffer position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2063 The match found must not extend after that position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2064 Optional third argument, if t, means if fail just return nil (no error).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2065 If not nil and not t, move to limit of search and return nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2066 Optional fourth argument is repeat count--search for successive occurrences. */)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2067 (string, bound, noerror, count)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2068 Lisp_Object string, bound, noerror, count;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2069 {
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2070 return search_command (wordify (string), bound, noerror, count, 1, 1, 0);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2071 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2072
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2073 DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2074 "sRE search backward: ",
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2075 doc: /* Search backward from point for match for regular expression REGEXP.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2076 Set point to the beginning of the match, and return point.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2077 The match found is the one starting last in the buffer
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2078 and yet ending before the origin of the search.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2079 An optional second argument bounds the search; it is a buffer position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2080 The match found must start at or after that position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2081 Optional third argument, if t, means if fail just return nil (no error).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2082 If not nil and not t, move to limit of search and return nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2083 Optional fourth argument is repeat count--search for successive occurrences.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2084 See also the functions `match-beginning', `match-end', `match-string',
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2085 and `replace-match'. */)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2086 (regexp, bound, noerror, count)
6297
b44907fd0ff0 (Fre_search_forward, Fre_search_backward): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 6196
diff changeset
2087 Lisp_Object regexp, bound, noerror, count;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2088 {
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2089 return search_command (regexp, bound, noerror, count, -1, 1, 0);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2090 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2091
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2092 DEFUN ("re-search-forward", Fre_search_forward, Sre_search_forward, 1, 4,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2093 "sRE search: ",
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2094 doc: /* Search forward from point for regular expression REGEXP.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2095 Set point to the end of the occurrence found, and return point.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2096 An optional second argument bounds the search; it is a buffer position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2097 The match found must not extend after that position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2098 Optional third argument, if t, means if fail just return nil (no error).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2099 If not nil and not t, move to limit of search and return nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2100 Optional fourth argument is repeat count--search for successive occurrences.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2101 See also the functions `match-beginning', `match-end', `match-string',
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2102 and `replace-match'. */)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2103 (regexp, bound, noerror, count)
6297
b44907fd0ff0 (Fre_search_forward, Fre_search_backward): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 6196
diff changeset
2104 Lisp_Object regexp, bound, noerror, count;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2105 {
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2106 return search_command (regexp, bound, noerror, count, 1, 1, 0);
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2107 }
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2108
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2109 DEFUN ("posix-search-backward", Fposix_search_backward, Sposix_search_backward, 1, 4,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2110 "sPosix search backward: ",
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2111 doc: /* Search backward from point for match for regular expression REGEXP.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2112 Find the longest match in accord with Posix regular expression rules.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2113 Set point to the beginning of the match, and return point.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2114 The match found is the one starting last in the buffer
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2115 and yet ending before the origin of the search.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2116 An optional second argument bounds the search; it is a buffer position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2117 The match found must start at or after that position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2118 Optional third argument, if t, means if fail just return nil (no error).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2119 If not nil and not t, move to limit of search and return nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2120 Optional fourth argument is repeat count--search for successive occurrences.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2121 See also the functions `match-beginning', `match-end', `match-string',
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2122 and `replace-match'. */)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2123 (regexp, bound, noerror, count)
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2124 Lisp_Object regexp, bound, noerror, count;
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2125 {
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2126 return search_command (regexp, bound, noerror, count, -1, 1, 1);
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2127 }
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2128
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2129 DEFUN ("posix-search-forward", Fposix_search_forward, Sposix_search_forward, 1, 4,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2130 "sPosix search: ",
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2131 doc: /* Search forward from point for regular expression REGEXP.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2132 Find the longest match in accord with Posix regular expression rules.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2133 Set point to the end of the occurrence found, and return point.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2134 An optional second argument bounds the search; it is a buffer position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2135 The match found must not extend after that position.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2136 Optional third argument, if t, means if fail just return nil (no error).
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2137 If not nil and not t, move to limit of search and return nil.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2138 Optional fourth argument is repeat count--search for successive occurrences.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2139 See also the functions `match-beginning', `match-end', `match-string',
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2140 and `replace-match'. */)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2141 (regexp, bound, noerror, count)
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2142 Lisp_Object regexp, bound, noerror, count;
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2143 {
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2144 return search_command (regexp, bound, noerror, count, 1, 1, 1);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2145 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2146
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2147 DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 5, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2148 doc: /* Replace text matched by last search with NEWTEXT.
45217
4383b69f181b (Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 41389
diff changeset
2149 Leave point at the end of the replacement text.
4383b69f181b (Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 41389
diff changeset
2150
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2151 If second arg FIXEDCASE is non-nil, do not alter case of replacement text.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2152 Otherwise maybe capitalize the whole text, or maybe just word initials,
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2153 based on the replaced text.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2154 If the replaced text has only capital letters
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2155 and has at least one multiletter word, convert NEWTEXT to all caps.
45217
4383b69f181b (Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 41389
diff changeset
2156 Otherwise if all words are capitalized in the replaced text,
4383b69f181b (Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 41389
diff changeset
2157 capitalize each word in NEWTEXT.
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2158
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2159 If third arg LITERAL is non-nil, insert NEWTEXT literally.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2160 Otherwise treat `\\' as special:
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2161 `\\&' in NEWTEXT means substitute original matched text.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2162 `\\N' means substitute what matched the Nth `\\(...\\)'.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2163 If Nth parens didn't match, substitute nothing.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2164 `\\\\' means insert one `\\'.
45217
4383b69f181b (Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 41389
diff changeset
2165 Case conversion does not apply to these substitutions.
4383b69f181b (Freplace_match): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 41389
diff changeset
2166
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2167 FIXEDCASE and LITERAL are optional arguments.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2168
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2169 The optional fourth argument STRING can be a string to modify.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2170 This is meaningful when the previous match was done against STRING,
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2171 using `string-match'. When used this way, `replace-match'
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2172 creates and returns a new string made by copying STRING and replacing
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2173 the part of STRING that was matched.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2174
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2175 The optional fifth argument SUBEXP specifies a subexpression;
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2176 it says to replace just that subexpression with NEWTEXT,
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2177 rather than replacing the entire matched text.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2178 This is, in a vague sense, the inverse of using `\\N' in NEWTEXT;
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2179 `\\N' copies subexp N into NEWTEXT, but using N as SUBEXP puts
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2180 NEWTEXT in place of subexp N.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2181 This is useful only after a regular expression search or match,
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2182 since only regular expressions have distinguished subexpressions. */)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2183 (newtext, fixedcase, literal, string, subexp)
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2184 Lisp_Object newtext, fixedcase, literal, string, subexp;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2185 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2186 enum { nochange, all_caps, cap_initial } case_action;
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2187 register int pos, pos_byte;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2188 int some_multiletter_word;
2393
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2189 int some_lowercase;
7674
947d24fefd9e (Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents: 7673
diff changeset
2190 int some_uppercase;
8526
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2191 int some_nonuppercase_initial;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2192 register int c, prevc;
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2193 int sub;
18081
300068b4fcef (Freplace_match): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 18077
diff changeset
2194 int opoint, newpoint;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2195
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
2196 CHECK_STRING (newtext);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2197
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2198 if (! NILP (string))
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
2199 CHECK_STRING (string);
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2200
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2201 case_action = nochange; /* We tried an initialization */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2202 /* but some C compilers blew it */
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2203
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2204 if (search_regs.num_regs <= 0)
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2205 error ("replace-match called before any match found");
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2206
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2207 if (NILP (subexp))
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2208 sub = 0;
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2209 else
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2210 {
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
2211 CHECK_NUMBER (subexp);
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2212 sub = XINT (subexp);
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2213 if (sub < 0 || sub >= search_regs.num_regs)
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2214 args_out_of_range (subexp, make_number (search_regs.num_regs));
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2215 }
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2216
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2217 if (NILP (string))
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2218 {
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2219 if (search_regs.start[sub] < BEGV
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2220 || search_regs.start[sub] > search_regs.end[sub]
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2221 || search_regs.end[sub] > ZV)
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2222 args_out_of_range (make_number (search_regs.start[sub]),
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2223 make_number (search_regs.end[sub]));
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2224 }
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2225 else
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2226 {
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2227 if (search_regs.start[sub] < 0
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2228 || search_regs.start[sub] > search_regs.end[sub]
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
2229 || search_regs.end[sub] > SCHARS (string))
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2230 args_out_of_range (make_number (search_regs.start[sub]),
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2231 make_number (search_regs.end[sub]));
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2232 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2233
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2234 if (NILP (fixedcase))
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2235 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2236 /* Decide how to casify by examining the matched text. */
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2237 int last;
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2238
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2239 pos = search_regs.start[sub];
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2240 last = search_regs.end[sub];
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2241
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
2242 if (NILP (string))
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2243 pos_byte = CHAR_TO_BYTE (pos);
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
2244 else
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2245 pos_byte = string_char_to_byte (string, pos);
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
2246
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2247 prevc = '\n';
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2248 case_action = all_caps;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2249
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2250 /* some_multiletter_word is set nonzero if any original word
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2251 is more than one letter long. */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2252 some_multiletter_word = 0;
2393
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2253 some_lowercase = 0;
8526
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2254 some_nonuppercase_initial = 0;
7674
947d24fefd9e (Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents: 7673
diff changeset
2255 some_uppercase = 0;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2256
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2257 while (pos < last)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2258 {
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2259 if (NILP (string))
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2260 {
89062
be059fb97bac (compile_pattern_1): Don't adjust the multibyteness of
Kenichi Handa <handa@m17n.org>
parents: 89028
diff changeset
2261 c = FETCH_CHAR_AS_MULTIBYTE (pos_byte);
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2262 INC_BOTH (pos, pos_byte);
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2263 }
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2264 else
89062
be059fb97bac (compile_pattern_1): Don't adjust the multibyteness of
Kenichi Handa <handa@m17n.org>
parents: 89028
diff changeset
2265 FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, pos, pos_byte);
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2266
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2267 if (LOWERCASEP (c))
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2268 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2269 /* Cannot be all caps if any original char is lower case */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2270
2393
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2271 some_lowercase = 1;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2272 if (SYNTAX (prevc) != Sword)
8526
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2273 some_nonuppercase_initial = 1;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2274 else
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2275 some_multiletter_word = 1;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2276 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2277 else if (!NOCASEP (c))
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2278 {
7674
947d24fefd9e (Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents: 7673
diff changeset
2279 some_uppercase = 1;
2393
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2280 if (SYNTAX (prevc) != Sword)
6679
490b7e2db978 (Freplace_match): Don't capitalize unless all matched words are capitalized.
Karl Heuer <kwzh@gnu.org>
parents: 6543
diff changeset
2281 ;
2393
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2282 else
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2283 some_multiletter_word = 1;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2284 }
8526
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2285 else
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2286 {
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2287 /* If the initial is a caseless word constituent,
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2288 treat that like a lowercase initial. */
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2289 if (SYNTAX (prevc) != Sword)
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2290 some_nonuppercase_initial = 1;
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2291 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2292
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2293 prevc = c;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2294 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2295
2393
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2296 /* Convert to all caps if the old text is all caps
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2297 and has at least one multiletter word. */
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2298 if (! some_lowercase && some_multiletter_word)
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2299 case_action = all_caps;
6679
490b7e2db978 (Freplace_match): Don't capitalize unless all matched words are capitalized.
Karl Heuer <kwzh@gnu.org>
parents: 6543
diff changeset
2300 /* Capitalize each word, if the old text has all capitalized words. */
8526
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2301 else if (!some_nonuppercase_initial && some_multiletter_word)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2302 case_action = cap_initial;
8526
2b7b23059f1b (Freplace_match): Treat caseless initial like a lowercase initial.
Richard M. Stallman <rms@gnu.org>
parents: 7891
diff changeset
2303 else if (!some_nonuppercase_initial && some_uppercase)
7674
947d24fefd9e (Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents: 7673
diff changeset
2304 /* Should x -> yz, operating on X, give Yz or YZ?
947d24fefd9e (Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents: 7673
diff changeset
2305 We'll assume the latter. */
947d24fefd9e (Freplace_match): Improve capitalization heuristics.
Karl Heuer <kwzh@gnu.org>
parents: 7673
diff changeset
2306 case_action = all_caps;
2393
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2307 else
a35d2c5cbb3b (Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents: 1926
diff changeset
2308 case_action = nochange;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2309 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2310
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2311 /* Do replacement in a string. */
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2312 if (!NILP (string))
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2313 {
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2314 Lisp_Object before, after;
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2315
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2316 before = Fsubstring (string, make_number (0),
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2317 make_number (search_regs.start[sub]));
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2318 after = Fsubstring (string, make_number (search_regs.end[sub]), Qnil);
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2319
17225
739e41eed8b6 (Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents: 17102
diff changeset
2320 /* Substitute parts of the match into NEWTEXT
739e41eed8b6 (Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents: 17102
diff changeset
2321 if desired. */
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2322 if (NILP (literal))
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2323 {
21988
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2324 int lastpos = 0;
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2325 int lastpos_byte = 0;
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2326 /* We build up the substituted string in ACCUM. */
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2327 Lisp_Object accum;
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2328 Lisp_Object middle;
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
2329 int length = SBYTES (newtext);
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2330
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2331 accum = Qnil;
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2332
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2333 for (pos_byte = 0, pos = 0; pos_byte < length;)
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2334 {
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2335 int substart = -1;
31829
43566b0aec59 Avoid some more compiler warnings.
Gerd Moellmann <gerd@gnu.org>
parents: 31486
diff changeset
2336 int subend = 0;
12148
a1c38b9b0f73 (Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents: 12147
diff changeset
2337 int delbackslash = 0;
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2338
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2339 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte);
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2340
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2341 if (c == '\\')
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2342 {
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2343 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte);
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
2344
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2345 if (c == '&')
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2346 {
12807
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2347 substart = search_regs.start[sub];
34d269b30df1 (Freplace_match): New arg SUBEXP.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
2348 subend = search_regs.end[sub];
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2349 }
53719
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2350 else if (c >= '1' && c <= '9')
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2351 {
53719
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2352 if (search_regs.start[c - '0'] >= 0
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2353 && c <= search_regs.num_regs + '0')
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2354 {
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2355 substart = search_regs.start[c - '0'];
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2356 subend = search_regs.end[c - '0'];
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2357 }
53719
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2358 else
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2359 {
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2360 /* If that subexp did not match,
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2361 replace \\N with nothing. */
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2362 substart = 0;
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2363 subend = 0;
824b5057fbca (Freplace_match): Handle nonexistent back-references properly.
Richard M. Stallman <rms@gnu.org>
parents: 53587
diff changeset
2364 }
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2365 }
12148
a1c38b9b0f73 (Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents: 12147
diff changeset
2366 else if (c == '\\')
a1c38b9b0f73 (Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents: 12147
diff changeset
2367 delbackslash = 1;
17225
739e41eed8b6 (Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents: 17102
diff changeset
2368 else
739e41eed8b6 (Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents: 17102
diff changeset
2369 error ("Invalid use of `\\' in replacement text");
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2370 }
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2371 if (substart >= 0)
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2372 {
21988
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2373 if (pos - 2 != lastpos)
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2374 middle = substring_both (newtext, lastpos,
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2375 lastpos_byte,
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2376 pos - 2, pos_byte - 2);
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2377 else
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2378 middle = Qnil;
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2379 accum = concat3 (accum, middle,
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2380 Fsubstring (string,
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2381 make_number (substart),
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2382 make_number (subend)));
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2383 lastpos = pos;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2384 lastpos_byte = pos_byte;
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2385 }
12148
a1c38b9b0f73 (Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents: 12147
diff changeset
2386 else if (delbackslash)
a1c38b9b0f73 (Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents: 12147
diff changeset
2387 {
21988
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2388 middle = substring_both (newtext, lastpos,
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2389 lastpos_byte,
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2390 pos - 1, pos_byte - 1);
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2391
12148
a1c38b9b0f73 (Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents: 12147
diff changeset
2392 accum = concat2 (accum, middle);
a1c38b9b0f73 (Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents: 12147
diff changeset
2393 lastpos = pos;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2394 lastpos_byte = pos_byte;
12148
a1c38b9b0f73 (Freplace_match): Do the right thing with backslash.
Karl Heuer <kwzh@gnu.org>
parents: 12147
diff changeset
2395 }
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2396 }
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2397
21988
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2398 if (pos != lastpos)
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2399 middle = substring_both (newtext, lastpos,
8cf3bbc89c3c (Freplace_match): Fix the loop for copying text
Richard M. Stallman <rms@gnu.org>
parents: 21945
diff changeset
2400 lastpos_byte,
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2401 pos, pos_byte);
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2402 else
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2403 middle = Qnil;
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2404
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2405 newtext = concat2 (accum, middle);
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2406 }
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2407
17225
739e41eed8b6 (Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents: 17102
diff changeset
2408 /* Do case substitution in NEWTEXT if desired. */
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2409 if (case_action == all_caps)
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2410 newtext = Fupcase (newtext);
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2411 else if (case_action == cap_initial)
12092
b932b2ed40f5 (Freplace_match): Calls to upcase_initials and upcase_initials_region changed
Karl Heuer <kwzh@gnu.org>
parents: 12069
diff changeset
2412 newtext = Fupcase_initials (newtext);
9029
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2413
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2414 return concat3 (before, newtext, after);
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2415 }
f0d89b62dd27 (Freplace_match): New 4th arg OBJECT can specify string to replace in.
Richard M. Stallman <rms@gnu.org>
parents: 8950
diff changeset
2416
39487
b21317213c81 (trivial_regexp_p): Catch \{N,M\} as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 35831
diff changeset
2417 /* Record point, then move (quietly) to the start of the match. */
23790
c1dbb92db43e (Freplace_match): Set OPOINT clearly for the case
Richard M. Stallman <rms@gnu.org>
parents: 22640
diff changeset
2418 if (PT >= search_regs.end[sub])
18077
27a0ced43e7e (Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents: 17463
diff changeset
2419 opoint = PT - ZV;
23790
c1dbb92db43e (Freplace_match): Set OPOINT clearly for the case
Richard M. Stallman <rms@gnu.org>
parents: 22640
diff changeset
2420 else if (PT > search_regs.start[sub])
c1dbb92db43e (Freplace_match): Set OPOINT clearly for the case
Richard M. Stallman <rms@gnu.org>
parents: 22640
diff changeset
2421 opoint = search_regs.end[sub] - ZV;
18077
27a0ced43e7e (Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents: 17463
diff changeset
2422 else
27a0ced43e7e (Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents: 17463
diff changeset
2423 opoint = PT;
27a0ced43e7e (Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents: 17463
diff changeset
2424
40922
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2425 /* If we want non-literal replacement,
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2426 perform substitution on the replacement string. */
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2427 if (NILP (literal))
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2428 {
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
2429 int length = SBYTES (newtext);
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2430 unsigned char *substed;
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2431 int substed_alloc_size, substed_len;
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2432 int buf_multibyte = !NILP (current_buffer->enable_multibyte_characters);
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2433 int str_multibyte = STRING_MULTIBYTE (newtext);
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2434 Lisp_Object rev_tbl;
40922
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2435 int really_changed = 0;
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2436
89483
2f877ed80fa6 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 88123 89454
diff changeset
2437 rev_tbl = Qnil;
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2438
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2439 substed_alloc_size = length * 2 + 100;
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2440 substed = (unsigned char *) xmalloc (substed_alloc_size + 1);
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2441 substed_len = 0;
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2442
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2443 /* Go thru NEWTEXT, producing the actual text to insert in
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2444 SUBSTED while adjusting multibyteness to that of the current
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2445 buffer. */
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2446
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2447 for (pos_byte = 0, pos = 0; pos_byte < length;)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2448 {
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2449 unsigned char str[MAX_MULTIBYTE_LENGTH];
28886
3f60536745bd (Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents: 28507
diff changeset
2450 unsigned char *add_stuff = NULL;
3f60536745bd (Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents: 28507
diff changeset
2451 int add_len = 0;
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2452 int idx = -1;
2655
594a33ffed85 * search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents: 2475
diff changeset
2453
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2454 if (str_multibyte)
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2455 {
29018
2f43c508a9b5 (wordify): Use FETCH_STRING_CHAR_ADVANCE
Kenichi Handa <handa@m17n.org>
parents: 28886
diff changeset
2456 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, newtext, pos, pos_byte);
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2457 if (!buf_multibyte)
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2458 c = multibyte_char_to_unibyte (c, rev_tbl);
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2459 }
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2460 else
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2461 {
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2462 /* Note that we don't have to increment POS. */
46432
a4697b0a338e * search.c (wordify): Use SDATA.
Ken Raeburn <raeburn@raeburn.org>
parents: 46370
diff changeset
2463 c = SREF (newtext, pos_byte++);
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2464 if (buf_multibyte)
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2465 c = unibyte_char_to_multibyte (c);
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2466 }
22533
6eae236a4f01 (Freplace_match): Work by chars, not by bytes,
Karl Heuer <kwzh@gnu.org>
parents: 22221
diff changeset
2467
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2468 /* Either set ADD_STUFF and ADD_LEN to the text to put in SUBSTED,
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2469 or set IDX to a match index, which means put that part
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2470 of the buffer text into SUBSTED. */
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2471
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2472 if (c == '\\')
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2473 {
40922
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2474 really_changed = 1;
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2475
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2476 if (str_multibyte)
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2477 {
29018
2f43c508a9b5 (wordify): Use FETCH_STRING_CHAR_ADVANCE
Kenichi Handa <handa@m17n.org>
parents: 28886
diff changeset
2478 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, newtext,
2f43c508a9b5 (wordify): Use FETCH_STRING_CHAR_ADVANCE
Kenichi Handa <handa@m17n.org>
parents: 28886
diff changeset
2479 pos, pos_byte);
89213
b0d3fa30523c (Freplace_match): Check C by ASCII_CHAR_P, not by
Kenichi Handa <handa@m17n.org>
parents: 89130
diff changeset
2480 if (!buf_multibyte && !ASCII_CHAR_P (c))
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2481 c = multibyte_char_to_unibyte (c, rev_tbl);
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2482 }
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2483 else
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2484 {
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
2485 c = SREF (newtext, pos_byte++);
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2486 if (buf_multibyte)
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2487 c = unibyte_char_to_multibyte (c);
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2488 }
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2489
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2490 if (c == '&')
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2491 idx = sub;
7856
9687141f6264 (Freplace_match): Be sure not to treat non-digit like digit.
Richard M. Stallman <rms@gnu.org>
parents: 7674
diff changeset
2492 else if (c >= '1' && c <= '9' && c <= search_regs.num_regs + '0')
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2493 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2494 if (search_regs.start[c - '0'] >= 1)
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2495 idx = c - '0';
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2496 }
17225
739e41eed8b6 (Freplace_match): Give error if
Richard M. Stallman <rms@gnu.org>
parents: 17102
diff changeset
2497 else if (c == '\\')
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2498 add_len = 1, add_stuff = "\\";
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2499 else
28387
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2500 {
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2501 xfree (substed);
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2502 error ("Invalid use of `\\' in replacement text");
9a8814cc543c (Freplace_match): Adjust multibyteness of the current
Kenichi Handa <handa@m17n.org>
parents: 27884
diff changeset
2503 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2504 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2505 else
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2506 {
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2507 add_len = CHAR_STRING (c, str);
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2508 add_stuff = str;
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2509 }
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2510
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2511 /* If we want to copy part of a previous match,
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2512 set up ADD_STUFF and ADD_LEN to point to it. */
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2513 if (idx >= 0)
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2514 {
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2515 int begbyte = CHAR_TO_BYTE (search_regs.start[idx]);
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2516 add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte;
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2517 if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx])
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2518 move_gap (search_regs.start[idx]);
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2519 add_stuff = BYTE_POS_ADDR (begbyte);
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2520 }
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2521
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2522 /* Now the stuff we want to add to SUBSTED
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2523 is invariably ADD_LEN bytes starting at ADD_STUFF. */
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2524
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2525 /* Make sure SUBSTED is big enough. */
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2526 if (substed_len + add_len >= substed_alloc_size)
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2527 {
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2528 substed_alloc_size = substed_len + add_len + 500;
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2529 substed = (unsigned char *) xrealloc (substed,
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2530 substed_alloc_size + 1);
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2531 }
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2532
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2533 /* Now add to the end of SUBSTED. */
28886
3f60536745bd (Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents: 28507
diff changeset
2534 if (add_stuff)
3f60536745bd (Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents: 28507
diff changeset
2535 {
3f60536745bd (Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents: 28507
diff changeset
2536 bcopy (add_stuff, substed + substed_len, add_len);
3f60536745bd (Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents: 28507
diff changeset
2537 substed_len += add_len;
3f60536745bd (Freplace_match): Handle case of `\N' in the
Gerd Moellmann <gerd@gnu.org>
parents: 28507
diff changeset
2538 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2539 }
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2540
40922
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2541 if (really_changed)
53587
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2542 {
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2543 if (buf_multibyte)
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2544 {
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2545 int nchars = multibyte_chars_in_text (substed, substed_len);
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2546
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2547 newtext = make_multibyte_string (substed, nchars, substed_len);
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2548 }
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2549 else
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2550 newtext = make_unibyte_string (substed, substed_len);
6feb1f3f7a9b (Freplace_match): Use make_multibyte_string or
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
2551 }
26982
3527c131b069 (Freplace_match): For nonliteral replacement,
Richard M. Stallman <rms@gnu.org>
parents: 26869
diff changeset
2552 xfree (substed);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2553 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2554
40922
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2555 /* Replace the old text with the new in the cleanest possible way. */
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2556 replace_range (search_regs.start[sub], search_regs.end[sub],
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2557 newtext, 1, 0, 1);
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
2558 newpoint = search_regs.start[sub] + SCHARS (newtext);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2559
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2560 if (case_action == all_caps)
40922
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2561 Fupcase_region (make_number (search_regs.start[sub]),
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2562 make_number (newpoint));
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2563 else if (case_action == cap_initial)
40922
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2564 Fupcase_initials_region (make_number (search_regs.start[sub]),
9147103247c9 (Freplace_match): Use replace_range to insert and delete.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
2565 make_number (newpoint));
18081
300068b4fcef (Freplace_match): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 18077
diff changeset
2566
47686
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2567 /* Adjust search data for this change. */
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2568 {
47692
ff9770dda600 Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 47686
diff changeset
2569 int oldend = search_regs.end[sub];
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2570 int oldstart = search_regs.start[sub];
47686
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2571 int change = newpoint - search_regs.end[sub];
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2572 int i;
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2573
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2574 for (i = 0; i < search_regs.num_regs; i++)
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2575 {
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2576 if (search_regs.start[i] >= oldend)
47686
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2577 search_regs.start[i] += change;
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2578 else if (search_regs.start[i] > oldstart)
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2579 search_regs.start[i] = oldstart;
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2580 if (search_regs.end[i] >= oldend)
47686
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2581 search_regs.end[i] += change;
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2582 else if (search_regs.end[i] > oldstart)
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2583 search_regs.end[i] = oldstart;
47686
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2584 }
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2585 }
fc66469fe069 (Freplace_match): Adjust match data for the substitution
Richard M. Stallman <rms@gnu.org>
parents: 46474
diff changeset
2586
18077
27a0ced43e7e (Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents: 17463
diff changeset
2587 /* Put point back where it was in the text. */
18124
6f2c80d2425a (Freplace_match): If opoint is 0, that's relative to ZV.
Richard M. Stallman <rms@gnu.org>
parents: 18112
diff changeset
2588 if (opoint <= 0)
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
2589 TEMP_SET_PT (opoint + ZV);
18077
27a0ced43e7e (Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents: 17463
diff changeset
2590 else
20545
c20c92ff4055 (looking_at_1): Use bytepos to call re_search_2.
Richard M. Stallman <rms@gnu.org>
parents: 20347
diff changeset
2591 TEMP_SET_PT (opoint);
18077
27a0ced43e7e (Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents: 17463
diff changeset
2592
27a0ced43e7e (Freplace_match): Use move_if_not_intangible
Richard M. Stallman <rms@gnu.org>
parents: 17463
diff changeset
2593 /* Now move point "officially" to the start of the inserted replacement. */
18081
300068b4fcef (Freplace_match): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 18077
diff changeset
2594 move_if_not_intangible (newpoint);
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
2595
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2596 return Qnil;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2597 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2598
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2599 static Lisp_Object
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2600 match_limit (num, beginningp)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2601 Lisp_Object num;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2602 int beginningp;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2603 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2604 register int n;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2605
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
2606 CHECK_NUMBER (num);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2607 n = XINT (num);
56175
b53351ef3125 (match_limit): Cleaner err msg when no match data available.
Richard M. Stallman <rms@gnu.org>
parents: 56022
diff changeset
2608 if (n < 0)
56294
aaa6a4ecea38 (match_limit, Fmatch_data, Fset_match_data): YAILOM.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 56276
diff changeset
2609 args_out_of_range (num, make_number (0));
56175
b53351ef3125 (match_limit): Cleaner err msg when no match data available.
Richard M. Stallman <rms@gnu.org>
parents: 56022
diff changeset
2610 if (search_regs.num_regs <= 0)
b53351ef3125 (match_limit): Cleaner err msg when no match data available.
Richard M. Stallman <rms@gnu.org>
parents: 56022
diff changeset
2611 error ("No match data, because no search succeeded");
56022
e63446aad5a3 (match_limit): Don't flag an error if match-data
David Kastrup <dak@gnu.org>
parents: 55689
diff changeset
2612 if (n >= search_regs.num_regs
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2613 || search_regs.start[n] < 0)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2614 return Qnil;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2615 return (make_number ((beginningp) ? search_regs.start[n]
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2616 : search_regs.end[n]));
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2617 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2618
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2619 DEFUN ("match-beginning", Fmatch_beginning, Smatch_beginning, 1, 1, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2620 doc: /* Return position of start of text matched by last search.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2621 SUBEXP, a number, specifies which parenthesized expression in the last
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2622 regexp.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2623 Value is nil if SUBEXPth pair didn't match, or there were less than
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2624 SUBEXP pairs.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2625 Zero means the entire text matched by the whole regexp or whole string. */)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2626 (subexp)
14086
a410808fda15 (Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
2627 Lisp_Object subexp;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2628 {
14086
a410808fda15 (Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
2629 return match_limit (subexp, 1);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2630 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2631
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2632 DEFUN ("match-end", Fmatch_end, Smatch_end, 1, 1, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2633 doc: /* Return position of end of text matched by last search.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2634 SUBEXP, a number, specifies which parenthesized expression in the last
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2635 regexp.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2636 Value is nil if SUBEXPth pair didn't match, or there were less than
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2637 SUBEXP pairs.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2638 Zero means the entire text matched by the whole regexp or whole string. */)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2639 (subexp)
14086
a410808fda15 (Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
2640 Lisp_Object subexp;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2641 {
14086
a410808fda15 (Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
2642 return match_limit (subexp, 0);
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
2643 }
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2644
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2645 DEFUN ("match-data", Fmatch_data, Smatch_data, 0, 2, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2646 doc: /* Return a list containing all info on what the last search matched.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2647 Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2648 All the elements are markers or nil (nil if the Nth pair didn't match)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2649 if the last match was on a buffer; integers or nil if a string was matched.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2650 Use `store-match-data' to reinstate the data in this list.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2651
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2652 If INTEGERS (the optional first argument) is non-nil, always use
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2653 integers \(rather than markers) to represent buffer positions. In
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2654 this case, and if the last match was in a buffer, the buffer will get
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2655 stored as one additional element at the end of the list.
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2656
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2657 If REUSE is a list, reuse it as part of the value. If REUSE is long enough
49761
3d562e7ebf97 (Fmatch_data): Doc fix. Explicitly state that
Kim F. Storm <storm@cua.dk>
parents: 49600
diff changeset
2658 to hold all the values, and if INTEGERS is non-nil, no consing is done.
3d562e7ebf97 (Fmatch_data): Doc fix. Explicitly state that
Kim F. Storm <storm@cua.dk>
parents: 49600
diff changeset
2659
3d562e7ebf97 (Fmatch_data): Doc fix. Explicitly state that
Kim F. Storm <storm@cua.dk>
parents: 49600
diff changeset
2660 Return value is undefined if the last search failed. */)
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2661 (integers, reuse)
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2662 Lisp_Object integers, reuse;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2663 {
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2664 Lisp_Object tail, prev;
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2665 Lisp_Object *data;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2666 int i, len;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2667
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2668 if (NILP (last_thing_searched))
15667
9531c03134b6 (Fmatch_data): If no matching done yet, return Qnil.
Karl Heuer <kwzh@gnu.org>
parents: 14186
diff changeset
2669 return Qnil;
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2670
31829
43566b0aec59 Avoid some more compiler warnings.
Gerd Moellmann <gerd@gnu.org>
parents: 31486
diff changeset
2671 prev = Qnil;
43566b0aec59 Avoid some more compiler warnings.
Gerd Moellmann <gerd@gnu.org>
parents: 31486
diff changeset
2672
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2673 data = (Lisp_Object *) alloca ((2 * search_regs.num_regs + 1)
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2674 * sizeof (Lisp_Object));
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2675
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2676 len = 0;
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2677 for (i = 0; i < search_regs.num_regs; i++)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2678 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2679 int start = search_regs.start[i];
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2680 if (start >= 0)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2681 {
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2682 if (EQ (last_thing_searched, Qt)
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2683 || ! NILP (integers))
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2684 {
9319
7969182b6cc6 (skip_chars, Fmatch_data, Fstore_match_data): Don't use XFASTINT as an lvalue.
Karl Heuer <kwzh@gnu.org>
parents: 9278
diff changeset
2685 XSETFASTINT (data[2 * i], start);
7969182b6cc6 (skip_chars, Fmatch_data, Fstore_match_data): Don't use XFASTINT as an lvalue.
Karl Heuer <kwzh@gnu.org>
parents: 9278
diff changeset
2686 XSETFASTINT (data[2 * i + 1], search_regs.end[i]);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2687 }
9113
766b6288e0f2 (Fmatch_data, Fstore_match_data): Use type test macros.
Karl Heuer <kwzh@gnu.org>
parents: 9029
diff changeset
2688 else if (BUFFERP (last_thing_searched))
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2689 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2690 data[2 * i] = Fmake_marker ();
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2691 Fset_marker (data[2 * i],
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2692 make_number (start),
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2693 last_thing_searched);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2694 data[2 * i + 1] = Fmake_marker ();
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2695 Fset_marker (data[2 * i + 1],
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
2696 make_number (search_regs.end[i]),
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2697 last_thing_searched);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2698 }
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2699 else
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2700 /* last_thing_searched must always be Qt, a buffer, or Qnil. */
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2701 abort ();
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2702
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2703 len = 2*(i+1);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2704 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2705 else
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2706 data[2 * i] = data [2 * i + 1] = Qnil;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2707 }
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2708
56294
aaa6a4ecea38 (match_limit, Fmatch_data, Fset_match_data): YAILOM.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 56276
diff changeset
2709 if (BUFFERP (last_thing_searched) && !NILP (integers))
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2710 {
56294
aaa6a4ecea38 (match_limit, Fmatch_data, Fset_match_data): YAILOM.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 56276
diff changeset
2711 data[len] = last_thing_searched;
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2712 len++;
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2713 }
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2714
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2715 /* If REUSE is not usable, cons up the values and return them. */
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2716 if (! CONSP (reuse))
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2717 return Flist (len, data);
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2718
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2719 /* If REUSE is a list, store as many value elements as will fit
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2720 into the elements of REUSE. */
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2721 for (i = 0, tail = reuse; CONSP (tail);
25663
a5eaace0fa01 Use XCAR and XCDR instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25441
diff changeset
2722 i++, tail = XCDR (tail))
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2723 {
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2724 if (i < len)
39973
579177964efa Avoid (most) uses of XCAR/XCDR as lvalues, for flexibility in experimenting
Ken Raeburn <raeburn@raeburn.org>
parents: 39805
diff changeset
2725 XSETCAR (tail, data[i]);
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2726 else
39973
579177964efa Avoid (most) uses of XCAR/XCDR as lvalues, for flexibility in experimenting
Ken Raeburn <raeburn@raeburn.org>
parents: 39805
diff changeset
2727 XSETCAR (tail, Qnil);
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2728 prev = tail;
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2729 }
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2730
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2731 /* If we couldn't fit all value elements into REUSE,
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2732 cons up the rest of them and add them to the end of REUSE. */
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2733 if (i < len)
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2734 XSETCDR (prev, Flist (len - i, data + i));
16724
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2735
4b1fb372a4fe (Fmatch_data): New args INTEGERS and REUSE.
Richard M. Stallman <rms@gnu.org>
parents: 16275
diff changeset
2736 return reuse;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2737 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2738
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2739
21171
60f6085df198 (Fset_match_data): Renamed from Fstore_match_data.
Richard M. Stallman <rms@gnu.org>
parents: 21117
diff changeset
2740 DEFUN ("set-match-data", Fset_match_data, Sset_match_data, 1, 1, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2741 doc: /* Set internal data on last search match from elements of LIST.
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2742 LIST should have been created by calling `match-data' previously. */)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2743 (list)
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2744 register Lisp_Object list;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2745 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2746 register int i;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2747 register Lisp_Object marker;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2748
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2749 if (running_asynch_code)
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2750 save_search_regs ();
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2751
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2752 if (!CONSP (list) && !NILP (list))
1926
952f2a18f83d * callint.c (Fcall_interactively): Pass the correct number of
Jim Blandy <jimb@redhat.com>
parents: 1896
diff changeset
2753 list = wrong_type_argument (Qconsp, list);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2754
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2755 /* Unless we find a marker with a buffer or an explicit buffer
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2756 in LIST, assume that this match data came from a string. */
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2757 last_thing_searched = Qt;
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2758
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2759 /* Allocate registers if they don't already exist. */
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2760 {
1523
bd61aaa7828b * search.c (Fstore_match_data): Don't assume Flength returns an
Jim Blandy <jimb@redhat.com>
parents: 1413
diff changeset
2761 int length = XFASTINT (Flength (list)) / 2;
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2762
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2763 if (length > search_regs.num_regs)
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2764 {
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2765 if (search_regs.num_regs == 0)
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2766 {
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2767 search_regs.start
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2768 = (regoff_t *) xmalloc (length * sizeof (regoff_t));
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2769 search_regs.end
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2770 = (regoff_t *) xmalloc (length * sizeof (regoff_t));
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2771 }
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2772 else
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2773 {
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2774 search_regs.start
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2775 = (regoff_t *) xrealloc (search_regs.start,
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2776 length * sizeof (regoff_t));
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2777 search_regs.end
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2778 = (regoff_t *) xrealloc (search_regs.end,
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2779 length * sizeof (regoff_t));
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
2780 }
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2781
33052
9ec478daa468 (Fset_match_data): Be sure to make search_regs always sane.
Kenichi Handa <handa@m17n.org>
parents: 32387
diff changeset
2782 for (i = search_regs.num_regs; i < length; i++)
9ec478daa468 (Fset_match_data): Be sure to make search_regs always sane.
Kenichi Handa <handa@m17n.org>
parents: 32387
diff changeset
2783 search_regs.start[i] = -1;
9ec478daa468 (Fset_match_data): Be sure to make search_regs always sane.
Kenichi Handa <handa@m17n.org>
parents: 32387
diff changeset
2784
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
2785 search_regs.num_regs = length;
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2786 }
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2787
56276
b04610e283ce (Fset_match_data): Allow buffer before end of list
David Kastrup <dak@gnu.org>
parents: 56224
diff changeset
2788 for (i = 0;; i++)
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2789 {
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2790 marker = Fcar (list);
56294
aaa6a4ecea38 (match_limit, Fmatch_data, Fset_match_data): YAILOM.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 56276
diff changeset
2791 if (BUFFERP (marker))
56276
b04610e283ce (Fset_match_data): Allow buffer before end of list
David Kastrup <dak@gnu.org>
parents: 56224
diff changeset
2792 {
56294
aaa6a4ecea38 (match_limit, Fmatch_data, Fset_match_data): YAILOM.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 56276
diff changeset
2793 last_thing_searched = marker;
56276
b04610e283ce (Fset_match_data): Allow buffer before end of list
David Kastrup <dak@gnu.org>
parents: 56224
diff changeset
2794 break;
b04610e283ce (Fset_match_data): Allow buffer before end of list
David Kastrup <dak@gnu.org>
parents: 56224
diff changeset
2795 }
b04610e283ce (Fset_match_data): Allow buffer before end of list
David Kastrup <dak@gnu.org>
parents: 56224
diff changeset
2796 if (i >= length)
b04610e283ce (Fset_match_data): Allow buffer before end of list
David Kastrup <dak@gnu.org>
parents: 56224
diff changeset
2797 break;
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2798 if (NILP (marker))
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2799 {
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2800 search_regs.start[i] = -1;
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2801 list = Fcdr (list);
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2802 }
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2803 else
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2804 {
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2805 int from;
58567
47729f2cb184 (syms_of_search) <search-spaces-regexp>: Move 'doc:'
Kim F. Storm <storm@cua.dk>
parents: 58348
diff changeset
2806
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2807 if (MARKERP (marker))
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2808 {
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2809 if (XMARKER (marker)->buffer == 0)
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2810 XSETFASTINT (marker, 0);
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2811 else
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2812 XSETBUFFER (last_thing_searched, XMARKER (marker)->buffer);
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2813 }
58567
47729f2cb184 (syms_of_search) <search-spaces-regexp>: Move 'doc:'
Kim F. Storm <storm@cua.dk>
parents: 58348
diff changeset
2814
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2815 CHECK_NUMBER_COERCE_MARKER (marker);
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2816 from = XINT (marker);
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2817 list = Fcdr (list);
58567
47729f2cb184 (syms_of_search) <search-spaces-regexp>: Move 'doc:'
Kim F. Storm <storm@cua.dk>
parents: 58348
diff changeset
2818
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2819 marker = Fcar (list);
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2820 if (MARKERP (marker) && XMARKER (marker)->buffer == 0)
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2821 XSETFASTINT (marker, 0);
58567
47729f2cb184 (syms_of_search) <search-spaces-regexp>: Move 'doc:'
Kim F. Storm <storm@cua.dk>
parents: 58348
diff changeset
2822
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2823 CHECK_NUMBER_COERCE_MARKER (marker);
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2824 search_regs.start[i] = from;
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2825 search_regs.end[i] = XINT (marker);
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2826 }
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2827 list = Fcdr (list);
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2828 }
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2829
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2830 for (; i < search_regs.num_regs; i++)
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2831 search_regs.start[i] = -1;
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2832 }
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 605
diff changeset
2833
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
2834 return Qnil;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2835 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2836
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2837 /* If non-zero the match data have been saved in saved_search_regs
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2838 during the execution of a sentinel or filter. */
10128
59ccd063e016 (search_regs_saved): Delete initializer.
Richard M. Stallman <rms@gnu.org>
parents: 10055
diff changeset
2839 static int search_regs_saved;
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2840 static struct re_registers saved_search_regs;
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2841 static Lisp_Object saved_last_thing_searched;
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2842
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2843 /* Called from Flooking_at, Fstring_match, search_buffer, Fstore_match_data
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2844 if asynchronous code (filter or sentinel) is running. */
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2845 static void
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2846 save_search_regs ()
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2847 {
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2848 if (!search_regs_saved)
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2849 {
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2850 saved_search_regs.num_regs = search_regs.num_regs;
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2851 saved_search_regs.start = search_regs.start;
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2852 saved_search_regs.end = search_regs.end;
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2853 saved_last_thing_searched = last_thing_searched;
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2854 last_thing_searched = Qnil;
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2855 search_regs.num_regs = 0;
10250
422c3b96efda (set_search_regs): Really set search_regs.start and .end.
Richard M. Stallman <rms@gnu.org>
parents: 10141
diff changeset
2856 search_regs.start = 0;
422c3b96efda (set_search_regs): Really set search_regs.start and .end.
Richard M. Stallman <rms@gnu.org>
parents: 10141
diff changeset
2857 search_regs.end = 0;
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2858
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2859 search_regs_saved = 1;
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2860 }
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2861 }
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2862
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2863 /* Called upon exit from filters and sentinels. */
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2864 void
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2865 restore_match_data ()
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2866 {
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2867 if (search_regs_saved)
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2868 {
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2869 if (search_regs.num_regs > 0)
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2870 {
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2871 xfree (search_regs.start);
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2872 xfree (search_regs.end);
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2873 }
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2874 search_regs.num_regs = saved_search_regs.num_regs;
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2875 search_regs.start = saved_search_regs.start;
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2876 search_regs.end = saved_search_regs.end;
56224
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2877 last_thing_searched = saved_last_thing_searched;
17e2d4a894aa (Freplace_match): Adjust the match-data more
David Kastrup <dak@gnu.org>
parents: 56175
diff changeset
2878 saved_last_thing_searched = Qnil;
10032
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2879 search_regs_saved = 0;
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2880 }
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2881 }
f689803caa92 Added code for automatically saving and restoring the match data
Francesco Potortì <pot@gnu.org>
parents: 10020
diff changeset
2882
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2883 /* Quote a string to inactivate reg-expr chars */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2884
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2885 DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0,
40123
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2886 doc: /* Return a regexp string which matches exactly STRING and nothing else. */)
e528f2adeed4 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 39973
diff changeset
2887 (string)
14086
a410808fda15 (Fmatch_end, Fregexp_quote): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
2888 Lisp_Object string;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2889 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2890 register unsigned char *in, *out, *end;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2891 register unsigned char *temp;
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2892 int backslashes_added = 0;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2893
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40269
diff changeset
2894 CHECK_STRING (string);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2895
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
2896 temp = (unsigned char *) alloca (SBYTES (string) * 2);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2897
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2898 /* Now copy the data into the new string, inserting escapes. */
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2899
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
2900 in = SDATA (string);
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
2901 end = in + SBYTES (string);
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
2902 out = temp;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2903
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2904 for (; in != end; in++)
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2905 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2906 if (*in == '[' || *in == ']'
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2907 || *in == '*' || *in == '.' || *in == '\\'
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2908 || *in == '?' || *in == '+'
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2909 || *in == '^' || *in == '$')
20588
138c95482e6b (search_buffer): Handle bytes vs chars in non-RE case.
Richard M. Stallman <rms@gnu.org>
parents: 20547
diff changeset
2910 *out++ = '\\', backslashes_added++;
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2911 *out++ = *in;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2912 }
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2913
21248
aba5e1c3328b (Fregexp_quote): Use make_specified_string.
Richard M. Stallman <rms@gnu.org>
parents: 21244
diff changeset
2914 return make_specified_string (temp,
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45263
diff changeset
2915 SCHARS (string) + backslashes_added,
21248
aba5e1c3328b (Fregexp_quote): Use make_specified_string.
Richard M. Stallman <rms@gnu.org>
parents: 21244
diff changeset
2916 out - temp,
aba5e1c3328b (Fregexp_quote): Use make_specified_string.
Richard M. Stallman <rms@gnu.org>
parents: 21244
diff changeset
2917 STRING_MULTIBYTE (string));
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2918 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48528
diff changeset
2919
21514
fa9ff387d260 Fix -Wimplicit warnings.
Andreas Schwab <schwab@suse.de>
parents: 21457
diff changeset
2920 void
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2921 syms_of_search ()
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2922 {
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2923 register int i;
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2924
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
2925 for (i = 0; i < REGEXP_CACHE_SIZE; ++i)
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
2926 {
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
2927 searchbufs[i].buf.allocated = 100;
51544
a0c2b39160e9 (shrink_regexp_cache): Use xrealloc.
Dave Love <fx@gnu.org>
parents: 49761
diff changeset
2928 searchbufs[i].buf.buffer = (unsigned char *) xmalloc (100);
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
2929 searchbufs[i].buf.fastmap = searchbufs[i].fastmap;
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
2930 searchbufs[i].regexp = Qnil;
58330
5be8a633ec57 (struct regexp_cache): New element whitespace_regexp.
Richard M. Stallman <rms@gnu.org>
parents: 58326
diff changeset
2931 searchbufs[i].whitespace_regexp = Qnil;
9605
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
2932 staticpro (&searchbufs[i].regexp);
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
2933 searchbufs[i].next = (i == REGEXP_CACHE_SIZE-1 ? 0 : &searchbufs[i+1]);
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
2934 }
cf97e75d8e02 (searchbufs): New variable, replaces searchbuf and last_regexp and
Karl Heuer <kwzh@gnu.org>
parents: 9452
diff changeset
2935 searchbuf_head = &searchbufs[0];
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2936
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2937 Qsearch_failed = intern ("search-failed");
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2938 staticpro (&Qsearch_failed);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2939 Qinvalid_regexp = intern ("invalid-regexp");
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2940 staticpro (&Qinvalid_regexp);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2941
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2942 Fput (Qsearch_failed, Qerror_conditions,
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2943 Fcons (Qsearch_failed, Fcons (Qerror, Qnil)));
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2944 Fput (Qsearch_failed, Qerror_message,
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2945 build_string ("Search failed"));
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2946
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2947 Fput (Qinvalid_regexp, Qerror_conditions,
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2948 Fcons (Qinvalid_regexp, Fcons (Qerror, Qnil)));
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2949 Fput (Qinvalid_regexp, Qerror_message,
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2950 build_string ("Invalid regexp"));
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2951
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2952 last_thing_searched = Qnil;
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2953 staticpro (&last_thing_searched);
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 708
diff changeset
2954
56429
65eb0cb0f21f (syms_of_search): staticpro
David Kastrup <dak@gnu.org>
parents: 56294
diff changeset
2955 saved_last_thing_searched = Qnil;
65eb0cb0f21f (syms_of_search): staticpro
David Kastrup <dak@gnu.org>
parents: 56294
diff changeset
2956 staticpro (&saved_last_thing_searched);
65eb0cb0f21f (syms_of_search): staticpro
David Kastrup <dak@gnu.org>
parents: 56294
diff changeset
2957
58348
623ffd21f0ff (Vsearch_spaces_regexp):
Richard M. Stallman <rms@gnu.org>
parents: 58330
diff changeset
2958 DEFVAR_LISP ("search-spaces-regexp", &Vsearch_spaces_regexp,
58567
47729f2cb184 (syms_of_search) <search-spaces-regexp>: Move 'doc:'
Kim F. Storm <storm@cua.dk>
parents: 58348
diff changeset
2959 doc: /* Regexp to substitute for bunches of spaces in regexp search.
58326
0cc0d3274d68 (Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 57735
diff changeset
2960 Some commands use this for user-specified regexps.
0cc0d3274d68 (Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 57735
diff changeset
2961 Spaces that occur inside character classes or repetition operators
0cc0d3274d68 (Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 57735
diff changeset
2962 or other such regexp constructs are not replaced with this.
0cc0d3274d68 (Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 57735
diff changeset
2963 A value of nil (which is the normal value) means treat spaces literally. */);
58348
623ffd21f0ff (Vsearch_spaces_regexp):
Richard M. Stallman <rms@gnu.org>
parents: 58330
diff changeset
2964 Vsearch_spaces_regexp = Qnil;
58326
0cc0d3274d68 (Vsearch_whitespace_regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 57735
diff changeset
2965
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2966 defsubr (&Slooking_at);
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2967 defsubr (&Sposix_looking_at);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2968 defsubr (&Sstring_match);
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2969 defsubr (&Sposix_string_match);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2970 defsubr (&Ssearch_forward);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2971 defsubr (&Ssearch_backward);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2972 defsubr (&Sword_search_forward);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2973 defsubr (&Sword_search_backward);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2974 defsubr (&Sre_search_forward);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2975 defsubr (&Sre_search_backward);
10020
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2976 defsubr (&Sposix_search_forward);
c41ce96785a8 (struct regexp_cache): New field `posix'.
Richard M. Stallman <rms@gnu.org>
parents: 9605
diff changeset
2977 defsubr (&Sposix_search_backward);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2978 defsubr (&Sreplace_match);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2979 defsubr (&Smatch_beginning);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2980 defsubr (&Smatch_end);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2981 defsubr (&Smatch_data);
21171
60f6085df198 (Fset_match_data): Renamed from Fstore_match_data.
Richard M. Stallman <rms@gnu.org>
parents: 21117
diff changeset
2982 defsubr (&Sset_match_data);
603
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2983 defsubr (&Sregexp_quote);
470f556a9453 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2984 }
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 51544
diff changeset
2985
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 51544
diff changeset
2986 /* arch-tag: a6059d79-0552-4f14-a2cb-d379a4e3c78f
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 51544
diff changeset
2987 (do not change this comment) */