annotate src/search.c @ 442:abe6d1db359e r21-2-36

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