annotate src/search.c @ 353:3b3709405255 r21-1-6

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