comparison src/search.c @ 83542:2d56e13fd23d

Merged from emacs@sv.gnu.org Patches applied: * emacs@sv.gnu.org/emacs--devo--0--patch-413 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-414 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-415 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-416 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-417 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-418 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-419 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-420 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-421 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-422 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-423 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-424 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-425 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-426 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-427 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-428 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-429 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-430 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-431 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-432 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-433 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-434 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-435 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-436 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-437 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-438 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-439 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-440 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-441 lisp/url/url-methods.el: Fix format error when http_proxy is empty string * emacs@sv.gnu.org/emacs--devo--0--patch-442 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-443 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-444 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-445 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-446 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-447 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-448 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-449 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-450 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-451 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-452 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-453 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-454 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-455 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-456 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-457 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-458 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-459 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-460 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-461 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-462 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-463 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-464 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-465 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-466 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-467 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-468 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-469 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-470 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-471 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-472 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-473 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-128 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-129 Merge from emacs--devo--0 * emacs@sv.gnu.org/gnus--rel--5.10--patch-130 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-131 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-132 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-133 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-134 Merge from emacs--devo--0 * emacs@sv.gnu.org/gnus--rel--5.10--patch-135 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-136 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-137 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-138 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-139 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-140 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-141 Merge from emacs--devo--0 * emacs@sv.gnu.org/gnus--rel--5.10--patch-142 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-143 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-144 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-145 Merge from emacs--devo--0 * emacs@sv.gnu.org/gnus--rel--5.10--patch-146 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-147 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-148 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-149 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-582
author Karoly Lorentey <lorentey@elte.hu>
date Sat, 14 Oct 2006 17:36:28 +0000
parents 5f8a28d018b2
children 94626132135d 8dd8c8286063
comparison
equal deleted inserted replaced
83541:694bbb62a75d 83542:2d56e13fd23d
40 of that regexp, suitable for searching. */ 40 of that regexp, suitable for searching. */
41 struct regexp_cache 41 struct regexp_cache
42 { 42 {
43 struct regexp_cache *next; 43 struct regexp_cache *next;
44 Lisp_Object regexp, whitespace_regexp; 44 Lisp_Object regexp, whitespace_regexp;
45 /* Syntax table for which the regexp applies. We need this because
46 of character classes. If this is t, then the compiled pattern is valid
47 for any syntax-table. */
48 Lisp_Object syntax_table;
45 struct re_pattern_buffer buf; 49 struct re_pattern_buffer buf;
46 char fastmap[0400]; 50 char fastmap[0400];
47 /* Nonzero means regexp was compiled to do full POSIX backtracking. */ 51 /* Nonzero means regexp was compiled to do full POSIX backtracking. */
48 char posix; 52 char posix;
49 }; 53 };
165 cp->regexp = Qnil; 169 cp->regexp = Qnil;
166 cp->buf.translate = (! NILP (translate) ? translate : make_number (0)); 170 cp->buf.translate = (! NILP (translate) ? translate : make_number (0));
167 cp->posix = posix; 171 cp->posix = posix;
168 cp->buf.multibyte = multibyte; 172 cp->buf.multibyte = multibyte;
169 cp->whitespace_regexp = Vsearch_spaces_regexp; 173 cp->whitespace_regexp = Vsearch_spaces_regexp;
170 BLOCK_INPUT; 174 /* rms: I think BLOCK_INPUT is not needed here any more,
175 because regex.c defines malloc to call xmalloc.
176 Using BLOCK_INPUT here means the debugger won't run if an error occurs.
177 So let's turn it off. */
178 /* BLOCK_INPUT; */
171 old = re_set_syntax (RE_SYNTAX_EMACS 179 old = re_set_syntax (RE_SYNTAX_EMACS
172 | (posix ? 0 : RE_NO_POSIX_BACKTRACKING)); 180 | (posix ? 0 : RE_NO_POSIX_BACKTRACKING));
173 181
174 re_set_whitespace_regexp (NILP (Vsearch_spaces_regexp) ? NULL 182 re_set_whitespace_regexp (NILP (Vsearch_spaces_regexp) ? NULL
175 : SDATA (Vsearch_spaces_regexp)); 183 : SDATA (Vsearch_spaces_regexp));
176 184
177 val = (char *) re_compile_pattern ((char *)raw_pattern, 185 val = (char *) re_compile_pattern ((char *)raw_pattern,
178 raw_pattern_size, &cp->buf); 186 raw_pattern_size, &cp->buf);
179 187
188 /* If the compiled pattern hard codes some of the contents of the
189 syntax-table, it can only be reused with *this* syntax table. */
190 cp->syntax_table = cp->buf.used_syntax ? current_buffer->syntax_table : Qt;
191
180 re_set_whitespace_regexp (NULL); 192 re_set_whitespace_regexp (NULL);
181 193
182 re_set_syntax (old); 194 re_set_syntax (old);
183 UNBLOCK_INPUT; 195 /* UNBLOCK_INPUT; */
184 if (val) 196 if (val)
185 xsignal1 (Qinvalid_regexp, build_string (val)); 197 xsignal1 (Qinvalid_regexp, build_string (val));
186 198
187 cp->regexp = Fcopy_sequence (pattern); 199 cp->regexp = Fcopy_sequence (pattern);
188 } 200 }
200 { 212 {
201 cp->buf.allocated = cp->buf.used; 213 cp->buf.allocated = cp->buf.used;
202 cp->buf.buffer 214 cp->buf.buffer
203 = (unsigned char *) xrealloc (cp->buf.buffer, cp->buf.used); 215 = (unsigned char *) xrealloc (cp->buf.buffer, cp->buf.used);
204 } 216 }
217 }
218
219 /* Clear the regexp cache w.r.t. a particular syntax table,
220 because it was changed.
221 There is no danger of memory leak here because re_compile_pattern
222 automagically manages the memory in each re_pattern_buffer struct,
223 based on its `allocated' and `buffer' values. */
224 void
225 clear_regexp_cache ()
226 {
227 int i;
228
229 for (i = 0; i < REGEXP_CACHE_SIZE; ++i)
230 /* It's tempting to compare with the syntax-table we've actually changd,
231 but it's not sufficient because char-table inheritance mewans that
232 modifying one syntax-table can change others at the same time. */
233 if (!EQ (searchbufs[i].syntax_table, Qt))
234 searchbufs[i].regexp = Qnil;
205 } 235 }
206 236
207 /* Compile a regexp if necessary, but first check to see if there's one in 237 /* Compile a regexp if necessary, but first check to see if there's one in
208 the cache. 238 the cache.
209 PATTERN is the pattern to compile. 239 PATTERN is the pattern to compile.
238 && STRING_MULTIBYTE (cp->regexp) == STRING_MULTIBYTE (pattern) 268 && STRING_MULTIBYTE (cp->regexp) == STRING_MULTIBYTE (pattern)
239 && !NILP (Fstring_equal (cp->regexp, pattern)) 269 && !NILP (Fstring_equal (cp->regexp, pattern))
240 && EQ (cp->buf.translate, (! NILP (translate) ? translate : make_number (0))) 270 && EQ (cp->buf.translate, (! NILP (translate) ? translate : make_number (0)))
241 && cp->posix == posix 271 && cp->posix == posix
242 && cp->buf.multibyte == multibyte 272 && cp->buf.multibyte == multibyte
273 && (EQ (cp->syntax_table, Qt)
274 || EQ (cp->syntax_table, current_buffer->syntax_table))
243 && !NILP (Fequal (cp->whitespace_regexp, Vsearch_spaces_regexp))) 275 && !NILP (Fequal (cp->whitespace_regexp, Vsearch_spaces_regexp)))
244 break; 276 break;
245 277
246 /* If we're at the end of the cache, compile into the nil cell 278 /* If we're at the end of the cache, compile into the nil cell
247 we found, or the last (least recently used) cell with a 279 we found, or the last (least recently used) cell with a
281 register int i; 313 register int i;
282 struct re_pattern_buffer *bufp; 314 struct re_pattern_buffer *bufp;
283 315
284 if (running_asynch_code) 316 if (running_asynch_code)
285 save_search_regs (); 317 save_search_regs ();
318
319 /* This is so set_image_of_range_1 in regex.c can find the EQV table. */
320 XCHAR_TABLE (current_buffer->case_canon_table)->extras[2]
321 = current_buffer->case_eqv_table;
286 322
287 CHECK_STRING (string); 323 CHECK_STRING (string);
288 bufp = compile_pattern (string, &search_regs, 324 bufp = compile_pattern (string, &search_regs,
289 (!NILP (current_buffer->case_fold_search) 325 (!NILP (current_buffer->case_fold_search)
290 ? current_buffer->case_canon_table : Qnil), 326 ? current_buffer->case_canon_table : Qnil),
388 pos = len + pos; 424 pos = len + pos;
389 else if (0 > pos || pos > len) 425 else if (0 > pos || pos > len)
390 args_out_of_range (string, start); 426 args_out_of_range (string, start);
391 pos_byte = string_char_to_byte (string, pos); 427 pos_byte = string_char_to_byte (string, pos);
392 } 428 }
429
430 /* This is so set_image_of_range_1 in regex.c can find the EQV table. */
431 XCHAR_TABLE (current_buffer->case_canon_table)->extras[2]
432 = current_buffer->case_eqv_table;
393 433
394 bufp = compile_pattern (regexp, &search_regs, 434 bufp = compile_pattern (regexp, &search_regs,
395 (!NILP (current_buffer->case_fold_search) 435 (!NILP (current_buffer->case_fold_search)
396 ? current_buffer->case_canon_table : Qnil), 436 ? current_buffer->case_canon_table : Qnil),
397 posix, 437 posix,
927 else if (lim < BEGV) 967 else if (lim < BEGV)
928 lim = BEGV, lim_byte = BEGV_BYTE; 968 lim = BEGV, lim_byte = BEGV_BYTE;
929 else 969 else
930 lim_byte = CHAR_TO_BYTE (lim); 970 lim_byte = CHAR_TO_BYTE (lim);
931 } 971 }
972
973 /* This is so set_image_of_range_1 in regex.c can find the EQV table. */
974 XCHAR_TABLE (current_buffer->case_canon_table)->extras[2]
975 = current_buffer->case_eqv_table;
932 976
933 np = search_buffer (string, PT, PT_BYTE, lim, lim_byte, n, RE, 977 np = search_buffer (string, PT, PT_BYTE, lim, lim_byte, n, RE,
934 (!NILP (current_buffer->case_fold_search) 978 (!NILP (current_buffer->case_fold_search)
935 ? current_buffer->case_canon_table 979 ? current_buffer->case_canon_table
936 : Qnil), 980 : Qnil),
3084 searchbufs[i].buf.allocated = 100; 3128 searchbufs[i].buf.allocated = 100;
3085 searchbufs[i].buf.buffer = (unsigned char *) xmalloc (100); 3129 searchbufs[i].buf.buffer = (unsigned char *) xmalloc (100);
3086 searchbufs[i].buf.fastmap = searchbufs[i].fastmap; 3130 searchbufs[i].buf.fastmap = searchbufs[i].fastmap;
3087 searchbufs[i].regexp = Qnil; 3131 searchbufs[i].regexp = Qnil;
3088 searchbufs[i].whitespace_regexp = Qnil; 3132 searchbufs[i].whitespace_regexp = Qnil;
3133 searchbufs[i].syntax_table = Qnil;
3089 staticpro (&searchbufs[i].regexp); 3134 staticpro (&searchbufs[i].regexp);
3090 staticpro (&searchbufs[i].whitespace_regexp); 3135 staticpro (&searchbufs[i].whitespace_regexp);
3136 staticpro (&searchbufs[i].syntax_table);
3091 searchbufs[i].next = (i == REGEXP_CACHE_SIZE-1 ? 0 : &searchbufs[i+1]); 3137 searchbufs[i].next = (i == REGEXP_CACHE_SIZE-1 ? 0 : &searchbufs[i+1]);
3092 } 3138 }
3093 searchbuf_head = &searchbufs[0]; 3139 searchbuf_head = &searchbufs[0];
3094 3140
3095 Qsearch_failed = intern ("search-failed"); 3141 Qsearch_failed = intern ("search-failed");