comparison src/search.c @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents aabb7f5b1c81
children 697ef44129c6
comparison
equal deleted inserted replaced
397:f4aeb21a5bad 398:74fd4e045ea6
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 struct regexp_cache searchbufs[REGEXP_CACHE_SIZE]; 57 static 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 struct regexp_cache *searchbuf_head; 60 static 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
703 /* Like find_next_newline, but returns position before the newline, 747 /* Like find_next_newline, but returns position before the newline,
704 not after, and only search up to TO. This isn't just 748 not after, and only search up to TO. This isn't just
705 find_next_newline (...)-1, because you might hit TO. */ 749 find_next_newline (...)-1, because you might hit TO. */
706 Bufpos 750 Bufpos
707 find_before_next_newline (struct buffer *buf, Bufpos from, Bufpos to, int count) 751 find_before_next_newline (struct buffer *buf, Bufpos from, Bufpos to, int count)
725 /* We store the first 256 chars in an array here and the rest in 769 /* We store the first 256 chars in an array here and the rest in
726 a range table. */ 770 a range table. */
727 unsigned char fastmap[0400]; 771 unsigned char fastmap[0400];
728 int negate = 0; 772 int negate = 0;
729 REGISTER int i; 773 REGISTER int i;
730 struct Lisp_Char_Table *syntax_table = 774 Lisp_Char_Table *syntax_table = XCHAR_TABLE (buf->mirror_syntax_table);
731 XCHAR_TABLE (buf->mirror_syntax_table);
732 Bufpos limit; 775 Bufpos limit;
733 776
734 if (NILP (lim)) 777 if (NILP (lim))
735 limit = forwardp ? BUF_ZV (buf) : BUF_BEGV (buf); 778 limit = forwardp ? BUF_ZV (buf) : BUF_BEGV (buf);
736 else 779 else
1538 wordify (Lisp_Object buffer, Lisp_Object string) 1581 wordify (Lisp_Object buffer, Lisp_Object string)
1539 { 1582 {
1540 Charcount i, len; 1583 Charcount i, len;
1541 EMACS_INT punct_count = 0, word_count = 0; 1584 EMACS_INT punct_count = 0, word_count = 0;
1542 struct buffer *buf = decode_buffer (buffer, 0); 1585 struct buffer *buf = decode_buffer (buffer, 0);
1543 struct Lisp_Char_Table *syntax_table = 1586 Lisp_Char_Table *syntax_table = XCHAR_TABLE (buf->mirror_syntax_table);
1544 XCHAR_TABLE (buf->mirror_syntax_table);
1545 1587
1546 CHECK_STRING (string); 1588 CHECK_STRING (string);
1547 len = XSTRING_CHAR_LENGTH (string); 1589 len = XSTRING_CHAR_LENGTH (string);
1548 1590
1549 for (i = 0; i < len; i++) 1591 for (i = 0; i < len; i++)
1799 int some_uppercase; 1841 int some_uppercase;
1800 int some_nonuppercase_initial; 1842 int some_nonuppercase_initial;
1801 Emchar c, prevc; 1843 Emchar c, prevc;
1802 Charcount inslen; 1844 Charcount inslen;
1803 struct buffer *buf; 1845 struct buffer *buf;
1804 struct Lisp_Char_Table *syntax_table; 1846 Lisp_Char_Table *syntax_table;
1805 int mc_count; 1847 int mc_count;
1806 Lisp_Object buffer; 1848 Lisp_Object buffer;
1807 int_dynarr *ul_action_dynarr = 0; 1849 int_dynarr *ul_action_dynarr = 0;
1808 int_dynarr *ul_pos_dynarr = 0; 1850 int_dynarr *ul_pos_dynarr = 0;
1809 int speccount; 1851 int speccount;
2528 DEFSUBR (Fregexp_quote); 2570 DEFSUBR (Fregexp_quote);
2529 DEFSUBR (Fset_word_regexp); 2571 DEFSUBR (Fset_word_regexp);
2530 } 2572 }
2531 2573
2532 void 2574 void
2533 vars_of_search (void) 2575 reinit_vars_of_search (void)
2534 { 2576 {
2535 REGISTER int i; 2577 int i;
2578
2579 last_thing_searched = Qnil;
2580 staticpro_nodump (&last_thing_searched);
2536 2581
2537 for (i = 0; i < REGEXP_CACHE_SIZE; ++i) 2582 for (i = 0; i < REGEXP_CACHE_SIZE; ++i)
2538 { 2583 {
2539 searchbufs[i].buf.allocated = 100; 2584 searchbufs[i].buf.allocated = 100;
2540 searchbufs[i].buf.buffer = (unsigned char *) xmalloc (100); 2585 searchbufs[i].buf.buffer = (unsigned char *) xmalloc (100);
2541 searchbufs[i].buf.fastmap = searchbufs[i].fastmap; 2586 searchbufs[i].buf.fastmap = searchbufs[i].fastmap;
2542 searchbufs[i].regexp = Qnil; 2587 searchbufs[i].regexp = Qnil;
2543 staticpro (&searchbufs[i].regexp); 2588 staticpro_nodump (&searchbufs[i].regexp);
2544 searchbufs[i].next = (i == REGEXP_CACHE_SIZE-1 ? 0 : &searchbufs[i+1]); 2589 searchbufs[i].next = (i == REGEXP_CACHE_SIZE-1 ? 0 : &searchbufs[i+1]);
2545 } 2590 }
2546 searchbuf_head = &searchbufs[0]; 2591 searchbuf_head = &searchbufs[0];
2547 2592 }
2548 last_thing_searched = Qnil; 2593
2549 staticpro (&last_thing_searched); 2594 void
2595 vars_of_search (void)
2596 {
2597 reinit_vars_of_search ();
2550 2598
2551 DEFVAR_LISP ("forward-word-regexp", &Vforward_word_regexp /* 2599 DEFVAR_LISP ("forward-word-regexp", &Vforward_word_regexp /*
2552 *Regular expression to be used in `forward-word'. 2600 *Regular expression to be used in `forward-word'.
2553 #### Not yet implemented. 2601 #### Not yet implemented.
2554 */ ); 2602 */ );