Mercurial > hg > xemacs-beta
comparison src/search.c @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | 74fd4e045ea6 |
children | 95016f13131a |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
52 /* Nonzero means regexp was compiled to do full POSIX backtracking. */ | 52 /* Nonzero means regexp was compiled to do full POSIX backtracking. */ |
53 char posix; | 53 char posix; |
54 }; | 54 }; |
55 | 55 |
56 /* The instances of that struct. */ | 56 /* The instances of that struct. */ |
57 static struct regexp_cache searchbufs[REGEXP_CACHE_SIZE]; | 57 struct regexp_cache searchbufs[REGEXP_CACHE_SIZE]; |
58 | 58 |
59 /* The head of the linked list; points to the most recently used buffer. */ | 59 /* The head of the linked list; points to the most recently used buffer. */ |
60 static struct regexp_cache *searchbuf_head; | 60 struct regexp_cache *searchbuf_head; |
61 | 61 |
62 | 62 |
63 /* Every call to re_match, etc., must pass &search_regs as the regs | 63 /* Every call to re_match, etc., must pass &search_regs as the regs |
64 argument unless you can show it is unnecessary (i.e., if re_match | 64 argument unless you can show it is unnecessary (i.e., if re_match |
65 is certainly going to be called again before region-around-match | 65 is certainly going to be called again before region-around-match |
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 { |
440 /* Match REGEXP against STRING, searching all of STRING, | 440 /* Match REGEXP against STRING, searching all of STRING, |
441 and return the index of the match, or negative on failure. | 441 and return the index of the match, or negative on failure. |
442 This does not clobber the match data. */ | 442 This does not clobber the match data. */ |
443 | 443 |
444 Bytecount | 444 Bytecount |
445 fast_string_match (Lisp_Object regexp, const Bufbyte *nonreloc, | 445 fast_string_match (Lisp_Object regexp, CONST Bufbyte *nonreloc, |
446 Lisp_Object reloc, Bytecount offset, | 446 Lisp_Object reloc, Bytecount offset, |
447 Bytecount length, int case_fold_search, | 447 Bytecount length, int case_fold_search, |
448 Error_behavior errb, int no_quit) | 448 Error_behavior errb, int no_quit) |
449 { | 449 { |
450 /* This function has been Mule-ized, except for the trt table handling. */ | 450 /* This function has been Mule-ized, except for the trt table handling. */ |
698 find_next_newline (struct buffer *buf, Bufpos from, int count) | 698 find_next_newline (struct buffer *buf, Bufpos from, int count) |
699 { | 699 { |
700 return scan_buffer (buf, '\n', from, 0, count, 0, 1); | 700 return scan_buffer (buf, '\n', from, 0, count, 0, 1); |
701 } | 701 } |
702 | 702 |
703 Bytind | |
704 bi_find_next_emchar_in_string (Lisp_String* str, Emchar target, Bytind st, | |
705 EMACS_INT count) | |
706 { | |
707 /* This function has been Mule-ized. */ | |
708 Bytind lim = string_length (str) -1; | |
709 Bufbyte* s = string_data (str); | |
710 | |
711 assert (count >= 0); | |
712 | |
713 #ifdef MULE | |
714 /* Due to the Mule representation of characters in a buffer, | |
715 we can simply search for characters in the range 0 - 127 | |
716 directly. For other characters, we do it the "hard" way. | |
717 Note that this way works for all characters but the other | |
718 way is faster. */ | |
719 if (target >= 0200) | |
720 { | |
721 while (st < lim && count > 0) | |
722 { | |
723 if (string_char (str, st) == target) | |
724 count--; | |
725 INC_CHARBYTIND (s, st); | |
726 } | |
727 } | |
728 else | |
729 #endif | |
730 { | |
731 while (st < lim && count > 0) | |
732 { | |
733 Bufbyte *bufptr = (Bufbyte *) memchr (charptr_n_addr (s, st), | |
734 (int) target, lim - st); | |
735 if (bufptr) | |
736 { | |
737 count--; | |
738 st = (Bytind)(bufptr - s) + 1; | |
739 } | |
740 else | |
741 st = lim; | |
742 } | |
743 } | |
744 return st; | |
745 } | |
746 | |
747 /* Like find_next_newline, but returns position before the newline, | 703 /* Like find_next_newline, but returns position before the newline, |
748 not after, and only search up to TO. This isn't just | 704 not after, and only search up to TO. This isn't just |
749 find_next_newline (...)-1, because you might hit TO. */ | 705 find_next_newline (...)-1, because you might hit TO. */ |
750 Bufpos | 706 Bufpos |
751 find_before_next_newline (struct buffer *buf, Bufpos from, Bufpos to, int count) | 707 find_before_next_newline (struct buffer *buf, Bufpos from, Bufpos to, int count) |
769 /* We store the first 256 chars in an array here and the rest in | 725 /* We store the first 256 chars in an array here and the rest in |
770 a range table. */ | 726 a range table. */ |
771 unsigned char fastmap[0400]; | 727 unsigned char fastmap[0400]; |
772 int negate = 0; | 728 int negate = 0; |
773 REGISTER int i; | 729 REGISTER int i; |
774 Lisp_Char_Table *syntax_table = XCHAR_TABLE (buf->mirror_syntax_table); | 730 struct Lisp_Char_Table *syntax_table = |
731 XCHAR_TABLE (buf->mirror_syntax_table); | |
775 Bufpos limit; | 732 Bufpos limit; |
776 | 733 |
777 if (NILP (lim)) | 734 if (NILP (lim)) |
778 limit = forwardp ? BUF_ZV (buf) : BUF_BEGV (buf); | 735 limit = forwardp ? BUF_ZV (buf) : BUF_BEGV (buf); |
779 else | 736 else |
1581 wordify (Lisp_Object buffer, Lisp_Object string) | 1538 wordify (Lisp_Object buffer, Lisp_Object string) |
1582 { | 1539 { |
1583 Charcount i, len; | 1540 Charcount i, len; |
1584 EMACS_INT punct_count = 0, word_count = 0; | 1541 EMACS_INT punct_count = 0, word_count = 0; |
1585 struct buffer *buf = decode_buffer (buffer, 0); | 1542 struct buffer *buf = decode_buffer (buffer, 0); |
1586 Lisp_Char_Table *syntax_table = XCHAR_TABLE (buf->mirror_syntax_table); | 1543 struct Lisp_Char_Table *syntax_table = |
1544 XCHAR_TABLE (buf->mirror_syntax_table); | |
1587 | 1545 |
1588 CHECK_STRING (string); | 1546 CHECK_STRING (string); |
1589 len = XSTRING_CHAR_LENGTH (string); | 1547 len = XSTRING_CHAR_LENGTH (string); |
1590 | 1548 |
1591 for (i = 0; i < len; i++) | 1549 for (i = 0; i < len; i++) |
1841 int some_uppercase; | 1799 int some_uppercase; |
1842 int some_nonuppercase_initial; | 1800 int some_nonuppercase_initial; |
1843 Emchar c, prevc; | 1801 Emchar c, prevc; |
1844 Charcount inslen; | 1802 Charcount inslen; |
1845 struct buffer *buf; | 1803 struct buffer *buf; |
1846 Lisp_Char_Table *syntax_table; | 1804 struct Lisp_Char_Table *syntax_table; |
1847 int mc_count; | 1805 int mc_count; |
1848 Lisp_Object buffer; | 1806 Lisp_Object buffer; |
1849 int_dynarr *ul_action_dynarr = 0; | 1807 int_dynarr *ul_action_dynarr = 0; |
1850 int_dynarr *ul_pos_dynarr = 0; | 1808 int_dynarr *ul_pos_dynarr = 0; |
1851 int speccount; | 1809 int speccount; |
2570 DEFSUBR (Fregexp_quote); | 2528 DEFSUBR (Fregexp_quote); |
2571 DEFSUBR (Fset_word_regexp); | 2529 DEFSUBR (Fset_word_regexp); |
2572 } | 2530 } |
2573 | 2531 |
2574 void | 2532 void |
2575 reinit_vars_of_search (void) | 2533 vars_of_search (void) |
2576 { | 2534 { |
2577 int i; | 2535 REGISTER int i; |
2578 | |
2579 last_thing_searched = Qnil; | |
2580 staticpro_nodump (&last_thing_searched); | |
2581 | 2536 |
2582 for (i = 0; i < REGEXP_CACHE_SIZE; ++i) | 2537 for (i = 0; i < REGEXP_CACHE_SIZE; ++i) |
2583 { | 2538 { |
2584 searchbufs[i].buf.allocated = 100; | 2539 searchbufs[i].buf.allocated = 100; |
2585 searchbufs[i].buf.buffer = (unsigned char *) xmalloc (100); | 2540 searchbufs[i].buf.buffer = (unsigned char *) xmalloc (100); |
2586 searchbufs[i].buf.fastmap = searchbufs[i].fastmap; | 2541 searchbufs[i].buf.fastmap = searchbufs[i].fastmap; |
2587 searchbufs[i].regexp = Qnil; | 2542 searchbufs[i].regexp = Qnil; |
2588 staticpro_nodump (&searchbufs[i].regexp); | 2543 staticpro (&searchbufs[i].regexp); |
2589 searchbufs[i].next = (i == REGEXP_CACHE_SIZE-1 ? 0 : &searchbufs[i+1]); | 2544 searchbufs[i].next = (i == REGEXP_CACHE_SIZE-1 ? 0 : &searchbufs[i+1]); |
2590 } | 2545 } |
2591 searchbuf_head = &searchbufs[0]; | 2546 searchbuf_head = &searchbufs[0]; |
2592 } | 2547 |
2593 | 2548 last_thing_searched = Qnil; |
2594 void | 2549 staticpro (&last_thing_searched); |
2595 vars_of_search (void) | |
2596 { | |
2597 reinit_vars_of_search (); | |
2598 | 2550 |
2599 DEFVAR_LISP ("forward-word-regexp", &Vforward_word_regexp /* | 2551 DEFVAR_LISP ("forward-word-regexp", &Vforward_word_regexp /* |
2600 *Regular expression to be used in `forward-word'. | 2552 *Regular expression to be used in `forward-word'. |
2601 #### Not yet implemented. | 2553 #### Not yet implemented. |
2602 */ ); | 2554 */ ); |