Mercurial > hg > xemacs-beta
comparison src/search.c @ 442:abe6d1db359e r21-2-36
Import from CVS: tag r21-2-36
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:35:02 +0200 |
parents | 8de8e3f6228a |
children | 576fb035e263 |
comparison
equal
deleted
inserted
replaced
441:72a7cfa4a488 | 442:abe6d1db359e |
---|---|
129 static int | 129 static int |
130 compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, | 130 compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, |
131 char *translate, struct re_registers *regp, int posix, | 131 char *translate, struct re_registers *regp, int posix, |
132 Error_behavior errb) | 132 Error_behavior errb) |
133 { | 133 { |
134 CONST char *val; | 134 const char *val; |
135 reg_syntax_t old; | 135 reg_syntax_t old; |
136 | 136 |
137 cp->regexp = Qnil; | 137 cp->regexp = Qnil; |
138 cp->buf.translate = translate; | 138 cp->buf.translate = translate; |
139 cp->posix = posix; | 139 cp->posix = posix; |
140 old = re_set_syntax (RE_SYNTAX_EMACS | 140 old = re_set_syntax (RE_SYNTAX_EMACS |
141 | (posix ? 0 : RE_NO_POSIX_BACKTRACKING)); | 141 | (posix ? 0 : RE_NO_POSIX_BACKTRACKING)); |
142 val = (CONST char *) | 142 val = (const char *) |
143 re_compile_pattern ((char *) XSTRING_DATA (pattern), | 143 re_compile_pattern ((char *) XSTRING_DATA (pattern), |
144 XSTRING_LENGTH (pattern), &cp->buf); | 144 XSTRING_LENGTH (pattern), &cp->buf); |
145 re_set_syntax (old); | 145 re_set_syntax (old); |
146 if (val) | 146 if (val) |
147 { | 147 { |
299 p2 = BI_BUF_CEILING_OF (buf, p1); | 299 p2 = BI_BUF_CEILING_OF (buf, p1); |
300 s1 = p2 - p1; | 300 s1 = p2 - p1; |
301 s2 = BI_BUF_ZV (buf) - p2; | 301 s2 = BI_BUF_ZV (buf) - p2; |
302 | 302 |
303 regex_emacs_buffer = buf; | 303 regex_emacs_buffer = buf; |
304 regex_emacs_buffer_p = 1; | |
304 i = re_match_2 (bufp, (char *) BI_BUF_BYTE_ADDRESS (buf, p1), | 305 i = re_match_2 (bufp, (char *) BI_BUF_BYTE_ADDRESS (buf, p1), |
305 s1, (char *) BI_BUF_BYTE_ADDRESS (buf, p2), s2, | 306 s1, (char *) BI_BUF_BYTE_ADDRESS (buf, p2), s2, |
306 BI_BUF_PT (buf) - BI_BUF_BEGV (buf), &search_regs, | 307 BI_BUF_PT (buf) - BI_BUF_BEGV (buf), &search_regs, |
307 BI_BUF_ZV (buf) - BI_BUF_BEGV (buf)); | 308 BI_BUF_ZV (buf) - BI_BUF_BEGV (buf)); |
308 | 309 |
389 : 0), 0, ERROR_ME); | 390 : 0), 0, ERROR_ME); |
390 QUIT; | 391 QUIT; |
391 { | 392 { |
392 Bytecount bis = charcount_to_bytecount (XSTRING_DATA (string), s); | 393 Bytecount bis = charcount_to_bytecount (XSTRING_DATA (string), s); |
393 regex_emacs_buffer = buf; | 394 regex_emacs_buffer = buf; |
395 regex_emacs_buffer_p = 0; | |
394 val = re_search (bufp, (char *) XSTRING_DATA (string), | 396 val = re_search (bufp, (char *) XSTRING_DATA (string), |
395 XSTRING_LENGTH (string), bis, | 397 XSTRING_LENGTH (string), bis, |
396 XSTRING_LENGTH (string) - bis, | 398 XSTRING_LENGTH (string) - bis, |
397 &search_regs); | 399 &search_regs); |
398 } | 400 } |
440 /* Match REGEXP against STRING, searching all of STRING, | 442 /* Match REGEXP against STRING, searching all of STRING, |
441 and return the index of the match, or negative on failure. | 443 and return the index of the match, or negative on failure. |
442 This does not clobber the match data. */ | 444 This does not clobber the match data. */ |
443 | 445 |
444 Bytecount | 446 Bytecount |
445 fast_string_match (Lisp_Object regexp, CONST Bufbyte *nonreloc, | 447 fast_string_match (Lisp_Object regexp, const Bufbyte *nonreloc, |
446 Lisp_Object reloc, Bytecount offset, | 448 Lisp_Object reloc, Bytecount offset, |
447 Bytecount length, int case_fold_search, | 449 Bytecount length, int case_fold_search, |
448 Error_behavior errb, int no_quit) | 450 Error_behavior errb, int no_quit) |
449 { | 451 { |
450 /* This function has been Mule-ized, except for the trt table handling. */ | 452 /* This function has been Mule-ized, except for the trt table handling. */ |
482 } | 484 } |
483 } | 485 } |
484 | 486 |
485 /* #### evil current-buffer dependency */ | 487 /* #### evil current-buffer dependency */ |
486 regex_emacs_buffer = current_buffer; | 488 regex_emacs_buffer = current_buffer; |
489 regex_emacs_buffer_p = 0; | |
487 val = re_search (bufp, (char *) newnonreloc + offset, length, 0, | 490 val = re_search (bufp, (char *) newnonreloc + offset, length, 0, |
488 length, 0); | 491 length, 0); |
489 | 492 |
490 no_quit_in_re_search = 0; | 493 no_quit_in_re_search = 0; |
491 return val; | 494 return val; |
1162 while (n < 0) | 1165 while (n < 0) |
1163 { | 1166 { |
1164 Bytecount val; | 1167 Bytecount val; |
1165 QUIT; | 1168 QUIT; |
1166 regex_emacs_buffer = buf; | 1169 regex_emacs_buffer = buf; |
1170 regex_emacs_buffer_p = 1; | |
1167 val = re_search_2 (bufp, | 1171 val = re_search_2 (bufp, |
1168 (char *) BI_BUF_BYTE_ADDRESS (buf, p1), s1, | 1172 (char *) BI_BUF_BYTE_ADDRESS (buf, p1), s1, |
1169 (char *) BI_BUF_BYTE_ADDRESS (buf, p2), s2, | 1173 (char *) BI_BUF_BYTE_ADDRESS (buf, p2), s2, |
1170 pos - BI_BUF_BEGV (buf), lim - pos, &search_regs, | 1174 pos - BI_BUF_BEGV (buf), lim - pos, &search_regs, |
1171 pos - BI_BUF_BEGV (buf)); | 1175 pos - BI_BUF_BEGV (buf)); |
1200 while (n > 0) | 1204 while (n > 0) |
1201 { | 1205 { |
1202 Bytecount val; | 1206 Bytecount val; |
1203 QUIT; | 1207 QUIT; |
1204 regex_emacs_buffer = buf; | 1208 regex_emacs_buffer = buf; |
1209 regex_emacs_buffer_p = 1; | |
1205 val = re_search_2 (bufp, | 1210 val = re_search_2 (bufp, |
1206 (char *) BI_BUF_BYTE_ADDRESS (buf, p1), s1, | 1211 (char *) BI_BUF_BYTE_ADDRESS (buf, p1), s1, |
1207 (char *) BI_BUF_BYTE_ADDRESS (buf, p2), s2, | 1212 (char *) BI_BUF_BYTE_ADDRESS (buf, p2), s2, |
1208 pos - BI_BUF_BEGV (buf), lim - pos, &search_regs, | 1213 pos - BI_BUF_BEGV (buf), lim - pos, &search_regs, |
1209 lim - BI_BUF_BEGV (buf)); | 1214 lim - BI_BUF_BEGV (buf)); |
1240 /* #### Someone really really really needs to comment the workings | 1245 /* #### Someone really really really needs to comment the workings |
1241 of this junk somewhat better. | 1246 of this junk somewhat better. |
1242 | 1247 |
1243 BTW "BM" stands for Boyer-Moore, which is one of the standard | 1248 BTW "BM" stands for Boyer-Moore, which is one of the standard |
1244 string-searching algorithms. It's the best string-searching | 1249 string-searching algorithms. It's the best string-searching |
1245 algorithm out there provided | 1250 algorithm out there, provided that: |
1246 | 1251 |
1247 a) You're not fazed by algorithm complexity. (Rabin-Karp, which | 1252 a) You're not fazed by algorithm complexity. (Rabin-Karp, which |
1248 uses hashing, is much much easier to code but not as fast.) | 1253 uses hashing, is much much easier to code but not as fast.) |
1249 b) You can freely move backwards in the string that you're | 1254 b) You can freely move backwards in the string that you're |
1250 searching through. | 1255 searching through. |
1572 XSETBUFFER (last_thing_searched, buf); | 1577 XSETBUFFER (last_thing_searched, buf); |
1573 } | 1578 } |
1574 | 1579 |
1575 | 1580 |
1576 /* Given a string of words separated by word delimiters, | 1581 /* Given a string of words separated by word delimiters, |
1577 compute a regexp that matches those exact words | 1582 compute a regexp that matches those exact words |
1578 separated by arbitrary punctuation. */ | 1583 separated by arbitrary punctuation. */ |
1579 | 1584 |
1580 static Lisp_Object | 1585 static Lisp_Object |
1581 wordify (Lisp_Object buffer, Lisp_Object string) | 1586 wordify (Lisp_Object buffer, Lisp_Object string) |
1582 { | 1587 { |
1583 Charcount i, len; | 1588 Charcount i, len; |
2541 | 2546 |
2542 void | 2547 void |
2543 syms_of_search (void) | 2548 syms_of_search (void) |
2544 { | 2549 { |
2545 | 2550 |
2546 deferror (&Qsearch_failed, "search-failed", "Search failed", Qerror); | 2551 DEFERROR_STANDARD (Qsearch_failed, Qinvalid_operation); |
2547 deferror (&Qinvalid_regexp, "invalid-regexp", "Invalid regexp", Qerror); | 2552 DEFERROR_STANDARD (Qinvalid_regexp, Qsyntax_error); |
2548 | 2553 |
2549 DEFSUBR (Flooking_at); | 2554 DEFSUBR (Flooking_at); |
2550 DEFSUBR (Fposix_looking_at); | 2555 DEFSUBR (Fposix_looking_at); |
2551 DEFSUBR (Fstring_match); | 2556 DEFSUBR (Fstring_match); |
2552 DEFSUBR (Fposix_string_match); | 2557 DEFSUBR (Fposix_string_match); |