comparison src/search.c @ 58330:5be8a633ec57

(struct regexp_cache): New element whitespace_regexp. (syms_of_search): Initialize whitespace_regexp elements. (compile_pattern): Compare whitespace_regexp elements. (compile_pattern_1): Set whitespace_regexp elements.
author Richard M. Stallman <rms@gnu.org>
date Fri, 19 Nov 2004 20:02:32 +0000
parents 0cc0d3274d68
children 623ffd21f0ff
comparison
equal deleted inserted replaced
58329:30f22485a11e 58330:5be8a633ec57
39 /* If the regexp is non-nil, then the buffer contains the compiled form 39 /* If the regexp is non-nil, then the buffer contains the compiled form
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; 44 Lisp_Object regexp, whitespace_regexp;
45 struct re_pattern_buffer buf; 45 struct re_pattern_buffer buf;
46 char fastmap[0400]; 46 char fastmap[0400];
47 /* Nonzero means regexp was compiled to do full POSIX backtracking. */ 47 /* Nonzero means regexp was compiled to do full POSIX backtracking. */
48 char posix; 48 char posix;
49 }; 49 };
107 subexpression bounds. 107 subexpression bounds.
108 POSIX is nonzero if we want full backtracking (POSIX style) 108 POSIX is nonzero if we want full backtracking (POSIX style)
109 for this pattern. 0 means backtrack only enough to get a valid match. 109 for this pattern. 0 means backtrack only enough to get a valid match.
110 MULTIBYTE is nonzero if we want to handle multibyte characters in 110 MULTIBYTE is nonzero if we want to handle multibyte characters in
111 PATTERN. 0 means all multibyte characters are recognized just as 111 PATTERN. 0 means all multibyte characters are recognized just as
112 sequences of binary data. */ 112 sequences of binary data.
113
114 The behavior also depends on Vsearch_whitespace_regexp. */
113 115
114 static void 116 static void
115 compile_pattern_1 (cp, pattern, translate, regp, posix, multibyte) 117 compile_pattern_1 (cp, pattern, translate, regp, posix, multibyte)
116 struct regexp_cache *cp; 118 struct regexp_cache *cp;
117 Lisp_Object pattern; 119 Lisp_Object pattern;
158 160
159 cp->regexp = Qnil; 161 cp->regexp = Qnil;
160 cp->buf.translate = (! NILP (translate) ? translate : make_number (0)); 162 cp->buf.translate = (! NILP (translate) ? translate : make_number (0));
161 cp->posix = posix; 163 cp->posix = posix;
162 cp->buf.multibyte = multibyte; 164 cp->buf.multibyte = multibyte;
165 cp->whitespace_regexp = Vsearch_whitespace_regexp;
163 BLOCK_INPUT; 166 BLOCK_INPUT;
164 old = re_set_syntax (RE_SYNTAX_EMACS 167 old = re_set_syntax (RE_SYNTAX_EMACS
165 | (posix ? 0 : RE_NO_POSIX_BACKTRACKING)); 168 | (posix ? 0 : RE_NO_POSIX_BACKTRACKING));
166 169
167 re_set_whitespace_regexp (NILP (Vsearch_whitespace_regexp) ? NULL 170 re_set_whitespace_regexp (NILP (Vsearch_whitespace_regexp) ? NULL
230 if (SCHARS (cp->regexp) == SCHARS (pattern) 233 if (SCHARS (cp->regexp) == SCHARS (pattern)
231 && STRING_MULTIBYTE (cp->regexp) == STRING_MULTIBYTE (pattern) 234 && STRING_MULTIBYTE (cp->regexp) == STRING_MULTIBYTE (pattern)
232 && !NILP (Fstring_equal (cp->regexp, pattern)) 235 && !NILP (Fstring_equal (cp->regexp, pattern))
233 && EQ (cp->buf.translate, (! NILP (translate) ? translate : make_number (0))) 236 && EQ (cp->buf.translate, (! NILP (translate) ? translate : make_number (0)))
234 && cp->posix == posix 237 && cp->posix == posix
235 && cp->buf.multibyte == multibyte) 238 && cp->buf.multibyte == multibyte
239 && !NILP (Fequal (cp->whitespace_regexp, Vsearch_whitespace_regexp)))
236 break; 240 break;
237 241
238 /* If we're at the end of the cache, compile into the nil cell 242 /* If we're at the end of the cache, compile into the nil cell
239 we found, or the last (least recently used) cell with a 243 we found, or the last (least recently used) cell with a
240 string value. */ 244 string value. */
2979 { 2983 {
2980 searchbufs[i].buf.allocated = 100; 2984 searchbufs[i].buf.allocated = 100;
2981 searchbufs[i].buf.buffer = (unsigned char *) xmalloc (100); 2985 searchbufs[i].buf.buffer = (unsigned char *) xmalloc (100);
2982 searchbufs[i].buf.fastmap = searchbufs[i].fastmap; 2986 searchbufs[i].buf.fastmap = searchbufs[i].fastmap;
2983 searchbufs[i].regexp = Qnil; 2987 searchbufs[i].regexp = Qnil;
2988 searchbufs[i].whitespace_regexp = Qnil;
2984 staticpro (&searchbufs[i].regexp); 2989 staticpro (&searchbufs[i].regexp);
2985 searchbufs[i].next = (i == REGEXP_CACHE_SIZE-1 ? 0 : &searchbufs[i+1]); 2990 searchbufs[i].next = (i == REGEXP_CACHE_SIZE-1 ? 0 : &searchbufs[i+1]);
2986 } 2991 }
2987 searchbuf_head = &searchbufs[0]; 2992 searchbuf_head = &searchbufs[0];
2988 2993