Mercurial > hg > xemacs-beta
comparison src/search.c @ 70:131b0175ea99 r20-0b30
Import from CVS: tag r20-0b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:02:59 +0200 |
parents | 56c54cf7c5b6 |
children | cf808b4c4290 |
comparison
equal
deleted
inserted
replaced
69:804d1389bcd6 | 70:131b0175ea99 |
---|---|
39 | 39 |
40 #include <sys/types.h> | 40 #include <sys/types.h> |
41 #include "regex.h" | 41 #include "regex.h" |
42 | 42 |
43 | 43 |
44 #define REGEXP_CACHE_SIZE 20 | 44 #define REGEXP_CACHE_SIZE 5 |
45 | 45 |
46 /* If the regexp is non-nil, then the buffer contains the compiled form | 46 /* If the regexp is non-nil, then the buffer contains the compiled form |
47 of that regexp, suitable for searching. */ | 47 of that regexp, suitable for searching. */ |
48 struct regexp_cache { | 48 struct regexp_cache { |
49 struct regexp_cache *next; | 49 struct regexp_cache *next; |
76 allocated any registers, and will allocate new registers the next | 76 allocated any registers, and will allocate new registers the next |
77 time you call a searching or matching function. Therefore, we need | 77 time you call a searching or matching function. Therefore, we need |
78 to call re_set_registers after compiling a new pattern or after | 78 to call re_set_registers after compiling a new pattern or after |
79 setting the match registers, so that the regex functions will be | 79 setting the match registers, so that the regex functions will be |
80 able to free or re-allocate it properly. */ | 80 able to free or re-allocate it properly. */ |
81 | |
82 /* Note: things get trickier under Mule because the values returned from | |
83 the regexp routines are in Bytinds but we need them to be in Bufpos's. | |
84 We take the easy way out for the moment and just convert them immediately. | |
85 We could be more clever by not converting them until necessary, but | |
86 that gets real ugly real fast since the buffer might have changed and | |
87 the positions might be out of sync or out of range. | |
88 */ | |
81 static struct re_registers search_regs; | 89 static struct re_registers search_regs; |
82 | 90 |
83 /* The buffer in which the last search was performed, or | 91 /* The buffer in which the last search was performed, or |
84 Qt if the last search was done in a string; | 92 Qt if the last search was done in a string; |
85 Qnil if no searching has been done yet. */ | 93 Qnil if no searching has been done yet. */ |
549 if (shortage) | 557 if (shortage) |
550 *shortage = 0; | 558 *shortage = 0; |
551 | 559 |
552 if (count > 0) | 560 if (count > 0) |
553 { | 561 { |
562 #ifdef MULE | |
563 /* Due to the Mule representation of characters in a buffer, | |
564 we can simply search for characters in the range 0 - 127 | |
565 directly. For other characters, we do it the "hard" way. | |
566 Note that this way works for all characters but the other | |
567 way is faster. */ | |
568 if (target >= 0200) | |
569 { | |
570 while (st < lim && count > 0) | |
571 { | |
572 if (BI_BUF_FETCH_CHAR (buf, st) == target) | |
573 count--; | |
574 INC_BYTIND (buf, st); | |
575 } | |
576 } | |
577 else | |
578 #endif | |
554 { | 579 { |
555 while (st < lim && count > 0) | 580 while (st < lim && count > 0) |
556 { | 581 { |
557 Bytind ceil; | 582 Bytind ceil; |
558 Bufbyte *bufptr; | 583 Bufbyte *bufptr; |
577 QUIT; | 602 QUIT; |
578 return st; | 603 return st; |
579 } | 604 } |
580 else | 605 else |
581 { | 606 { |
607 #ifdef MULE | |
608 if (target >= 0200) | |
609 { | |
610 while (st > lim && count < 0) | |
611 { | |
612 DEC_BYTIND (buf, st); | |
613 if (BI_BUF_FETCH_CHAR (buf, st) == target) | |
614 count++; | |
615 } | |
616 } | |
617 else | |
618 #endif | |
582 { | 619 { |
583 while (st > lim && count < 0) | 620 while (st > lim && count < 0) |
584 { | 621 { |
585 Bytind floor; | 622 Bytind floor; |
586 Bufbyte *bufptr; | 623 Bufbyte *bufptr; |
684 /* We store the first 256 chars in an array here and the rest in | 721 /* We store the first 256 chars in an array here and the rest in |
685 a range table. */ | 722 a range table. */ |
686 unsigned char fastmap[0400]; | 723 unsigned char fastmap[0400]; |
687 int negate = 0; | 724 int negate = 0; |
688 register int i; | 725 register int i; |
689 Lisp_Object syntax_table = buf->syntax_table; | 726 struct Lisp_Char_Table *syntax_table = |
727 XCHAR_TABLE (buf->mirror_syntax_table); | |
690 | 728 |
691 CHECK_STRING (string); | 729 CHECK_STRING (string); |
692 | 730 |
693 if (NILP (lim)) | 731 if (NILP (lim)) |
694 XSETINT (lim, forwardp ? BUF_ZV (buf) : BUF_BEGV (buf)); | 732 XSETINT (lim, forwardp ? BUF_ZV (buf) : BUF_BEGV (buf)); |
1490 wordify (Lisp_Object buffer, Lisp_Object string) | 1528 wordify (Lisp_Object buffer, Lisp_Object string) |
1491 { | 1529 { |
1492 Charcount i, len; | 1530 Charcount i, len; |
1493 EMACS_INT punct_count = 0, word_count = 0; | 1531 EMACS_INT punct_count = 0, word_count = 0; |
1494 struct buffer *buf = decode_buffer (buffer, 0); | 1532 struct buffer *buf = decode_buffer (buffer, 0); |
1495 Lisp_Object syntax_table = buf->syntax_table; | 1533 struct Lisp_Char_Table *syntax_table = |
1534 XCHAR_TABLE (buf->mirror_syntax_table); | |
1496 | 1535 |
1497 CHECK_STRING (string); | 1536 CHECK_STRING (string); |
1498 len = string_char_length (XSTRING (string)); | 1537 len = string_char_length (XSTRING (string)); |
1499 | 1538 |
1500 for (i = 0; i < len; i++) | 1539 for (i = 0; i < len; i++) |
1672 (regexp, bound, no_error, count, buffer)) | 1711 (regexp, bound, no_error, count, buffer)) |
1673 { | 1712 { |
1674 return search_command (regexp, bound, no_error, count, buffer, -1, 1, 1); | 1713 return search_command (regexp, bound, no_error, count, buffer, -1, 1, 1); |
1675 } | 1714 } |
1676 | 1715 |
1677 DEFUN ("posix-search-forward", Fposix_search_forward, 1, 5, | 1716 DEFUN ("posix-search-forward", Fposix_search_forward, 1, 5, "sPosix search: ", /* |
1678 "sPosix search: ", /* | |
1679 Search forward from point for regular expression REGEXP. | 1717 Search forward from point for regular expression REGEXP. |
1680 Find the longest match in accord with Posix regular expression rules. | 1718 Find the longest match in accord with Posix regular expression rules. |
1681 Set point to the end of the occurrence found, and return point. | 1719 Set point to the end of the occurrence found, and return point. |
1682 An optional second argument bounds the search; it is a buffer position. | 1720 An optional second argument bounds the search; it is a buffer position. |
1683 The match found must not extend after that position. | 1721 The match found must not extend after that position. |
1751 int some_uppercase; | 1789 int some_uppercase; |
1752 int some_nonuppercase_initial; | 1790 int some_nonuppercase_initial; |
1753 Emchar c, prevc; | 1791 Emchar c, prevc; |
1754 Charcount inslen; | 1792 Charcount inslen; |
1755 struct buffer *buf; | 1793 struct buffer *buf; |
1756 Lisp_Object syntax_table; | 1794 struct Lisp_Char_Table *syntax_table; |
1757 int mc_count; | 1795 int mc_count; |
1758 Lisp_Object buffer; | 1796 Lisp_Object buffer; |
1759 int_dynarr *ul_action_dynarr = 0; | 1797 int_dynarr *ul_action_dynarr = 0; |
1760 int_dynarr *ul_pos_dynarr = 0; | 1798 int_dynarr *ul_pos_dynarr = 0; |
1761 int speccount; | 1799 int speccount; |
1783 error ("last thing matched was not a buffer"); | 1821 error ("last thing matched was not a buffer"); |
1784 buffer = last_thing_searched; | 1822 buffer = last_thing_searched; |
1785 buf = XBUFFER (buffer); | 1823 buf = XBUFFER (buffer); |
1786 } | 1824 } |
1787 | 1825 |
1788 syntax_table = buf->syntax_table; | 1826 syntax_table = XCHAR_TABLE (buf->mirror_syntax_table); |
1789 | 1827 |
1790 case_action = nochange; /* We tried an initialization */ | 1828 case_action = nochange; /* We tried an initialization */ |
1791 /* but some C compilers blew it */ | 1829 /* but some C compilers blew it */ |
1792 | 1830 |
1793 if (search_regs.num_regs <= 0) | 1831 if (search_regs.num_regs <= 0) |
2413 } | 2451 } |
2414 | 2452 |
2415 return make_string (temp, out - temp); | 2453 return make_string (temp, out - temp); |
2416 } | 2454 } |
2417 | 2455 |
2456 DEFUN ("set-word-regexp", Fset_word_regexp, 1, 1, 0, /* | |
2457 Set the regexp to be used to match a word in regular-expression searching. | |
2458 #### Not yet implemented. Currently does nothing. | |
2459 #### Do not use this yet. Its calling interface is likely to change. | |
2460 */ | |
2461 (regexp)) | |
2462 { | |
2463 return Qnil; | |
2464 } | |
2465 | |
2418 | 2466 |
2419 /************************************************************************/ | 2467 /************************************************************************/ |
2420 /* initialization */ | 2468 /* initialization */ |
2421 /************************************************************************/ | 2469 /************************************************************************/ |
2422 | 2470 |
2447 DEFSUBR (Fmatch_beginning); | 2495 DEFSUBR (Fmatch_beginning); |
2448 DEFSUBR (Fmatch_end); | 2496 DEFSUBR (Fmatch_end); |
2449 DEFSUBR (Fmatch_data); | 2497 DEFSUBR (Fmatch_data); |
2450 DEFSUBR (Fstore_match_data); | 2498 DEFSUBR (Fstore_match_data); |
2451 DEFSUBR (Fregexp_quote); | 2499 DEFSUBR (Fregexp_quote); |
2500 DEFSUBR (Fset_word_regexp); | |
2452 } | 2501 } |
2453 | 2502 |
2454 void | 2503 void |
2455 vars_of_search (void) | 2504 vars_of_search (void) |
2456 { | 2505 { |