Mercurial > hg > xemacs-beta
comparison src/search.c @ 380:8626e4521993 r21-2-5
Import from CVS: tag r21-2-5
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:07:10 +0200 |
parents | cc15677e0335 |
children | aabb7f5b1c81 |
comparison
equal
deleted
inserted
replaced
379:76b7d63099ad | 380:8626e4521993 |
---|---|
27 | 27 |
28 #include <config.h> | 28 #include <config.h> |
29 #include "lisp.h" | 29 #include "lisp.h" |
30 | 30 |
31 #include "buffer.h" | 31 #include "buffer.h" |
32 #include "commands.h" | |
33 #include "insdel.h" | 32 #include "insdel.h" |
34 #include "opaque.h" | 33 #include "opaque.h" |
35 #ifdef REGION_CACHE_NEEDS_WORK | 34 #ifdef REGION_CACHE_NEEDS_WORK |
36 #include "region-cache.h" | 35 #include "region-cache.h" |
37 #endif | 36 #endif |
682 shortage, allow_quit); | 681 shortage, allow_quit); |
683 return bytind_to_bufpos (buf, bi_retval); | 682 return bytind_to_bufpos (buf, bi_retval); |
684 } | 683 } |
685 | 684 |
686 Bytind | 685 Bytind |
687 bi_find_next_newline_no_quit (struct buffer *buf, Bytind from, int cnt) | 686 bi_find_next_newline_no_quit (struct buffer *buf, Bytind from, int count) |
688 { | 687 { |
689 return bi_scan_buffer (buf, '\n', from, 0, cnt, 0, 0); | 688 return bi_scan_buffer (buf, '\n', from, 0, count, 0, 0); |
690 } | 689 } |
691 | 690 |
692 Bufpos | 691 Bufpos |
693 find_next_newline_no_quit (struct buffer *buf, Bufpos from, int cnt) | 692 find_next_newline_no_quit (struct buffer *buf, Bufpos from, int count) |
694 { | 693 { |
695 return scan_buffer (buf, '\n', from, 0, cnt, 0, 0); | 694 return scan_buffer (buf, '\n', from, 0, count, 0, 0); |
696 } | 695 } |
697 | 696 |
698 Bufpos | 697 Bufpos |
699 find_next_newline (struct buffer *buf, Bufpos from, int cnt) | 698 find_next_newline (struct buffer *buf, Bufpos from, int count) |
700 { | 699 { |
701 return scan_buffer (buf, '\n', from, 0, cnt, 0, 1); | 700 return scan_buffer (buf, '\n', from, 0, count, 0, 1); |
702 } | 701 } |
703 | 702 |
704 /* Like find_next_newline, but returns position before the newline, | 703 /* Like find_next_newline, but returns position before the newline, |
705 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 |
706 find_next_newline (...)-1, because you might hit TO. */ | 705 find_next_newline (...)-1, because you might hit TO. */ |
707 Bufpos | 706 Bufpos |
708 find_before_next_newline (struct buffer *buf, Bufpos from, Bufpos to, int cnt) | 707 find_before_next_newline (struct buffer *buf, Bufpos from, Bufpos to, int count) |
709 { | 708 { |
710 EMACS_INT shortage; | 709 EMACS_INT shortage; |
711 Bufpos pos = scan_buffer (buf, '\n', from, to, cnt, &shortage, 1); | 710 Bufpos pos = scan_buffer (buf, '\n', from, to, count, &shortage, 1); |
712 | 711 |
713 if (shortage == 0) | 712 if (shortage == 0) |
714 pos--; | 713 pos--; |
715 | 714 |
716 return pos; | 715 return pos; |
728 unsigned char fastmap[0400]; | 727 unsigned char fastmap[0400]; |
729 int negate = 0; | 728 int negate = 0; |
730 REGISTER int i; | 729 REGISTER int i; |
731 struct Lisp_Char_Table *syntax_table = | 730 struct Lisp_Char_Table *syntax_table = |
732 XCHAR_TABLE (buf->mirror_syntax_table); | 731 XCHAR_TABLE (buf->mirror_syntax_table); |
732 Bufpos limit; | |
733 | |
734 if (NILP (lim)) | |
735 limit = forwardp ? BUF_ZV (buf) : BUF_BEGV (buf); | |
736 else | |
737 { | |
738 CHECK_INT_COERCE_MARKER (lim); | |
739 limit = XINT (lim); | |
740 | |
741 /* In any case, don't allow scan outside bounds of buffer. */ | |
742 if (limit > BUF_ZV (buf)) limit = BUF_ZV (buf); | |
743 if (limit < BUF_BEGV (buf)) limit = BUF_BEGV (buf); | |
744 } | |
733 | 745 |
734 CHECK_STRING (string); | 746 CHECK_STRING (string); |
735 | |
736 if (NILP (lim)) | |
737 XSETINT (lim, forwardp ? BUF_ZV (buf) : BUF_BEGV (buf)); | |
738 else | |
739 CHECK_INT_COERCE_MARKER (lim); | |
740 | |
741 /* In any case, don't allow scan outside bounds of buffer. */ | |
742 if (XINT (lim) > BUF_ZV (buf)) | |
743 lim = make_int (BUF_ZV (buf)); | |
744 if (XINT (lim) < BUF_BEGV (buf)) | |
745 lim = make_int (BUF_BEGV (buf)); | |
746 | |
747 p = XSTRING_DATA (string); | 747 p = XSTRING_DATA (string); |
748 pend = p + XSTRING_LENGTH (string); | 748 pend = p + XSTRING_LENGTH (string); |
749 memset (fastmap, 0, sizeof (fastmap)); | 749 memset (fastmap, 0, sizeof (fastmap)); |
750 | 750 |
751 Fclear_range_table (Vskip_chars_range_table); | 751 Fclear_range_table (Vskip_chars_range_table); |
826 { | 826 { |
827 /* All syntax designators are normal chars so nothing strange | 827 /* All syntax designators are normal chars so nothing strange |
828 to worry about */ | 828 to worry about */ |
829 if (forwardp) | 829 if (forwardp) |
830 { | 830 { |
831 while (BUF_PT (buf) < XINT (lim) | 831 while (BUF_PT (buf) < limit |
832 && fastmap[(unsigned char) | 832 && fastmap[(unsigned char) |
833 syntax_code_spec | 833 syntax_code_spec |
834 [(int) SYNTAX (syntax_table, | 834 [(int) SYNTAX (syntax_table, |
835 BUF_FETCH_CHAR | 835 BUF_FETCH_CHAR |
836 (buf, BUF_PT (buf)))]]) | 836 (buf, BUF_PT (buf)))]]) |
837 BUF_SET_PT (buf, BUF_PT (buf) + 1); | 837 BUF_SET_PT (buf, BUF_PT (buf) + 1); |
838 } | 838 } |
839 else | 839 else |
840 { | 840 { |
841 while (BUF_PT (buf) > XINT (lim) | 841 while (BUF_PT (buf) > limit |
842 && fastmap[(unsigned char) | 842 && fastmap[(unsigned char) |
843 syntax_code_spec | 843 syntax_code_spec |
844 [(int) SYNTAX (syntax_table, | 844 [(int) SYNTAX (syntax_table, |
845 BUF_FETCH_CHAR | 845 BUF_FETCH_CHAR |
846 (buf, BUF_PT (buf) - 1))]]) | 846 (buf, BUF_PT (buf) - 1))]]) |
849 } | 849 } |
850 else | 850 else |
851 { | 851 { |
852 if (forwardp) | 852 if (forwardp) |
853 { | 853 { |
854 while (BUF_PT (buf) < XINT (lim)) | 854 while (BUF_PT (buf) < limit) |
855 { | 855 { |
856 Emchar ch = BUF_FETCH_CHAR (buf, BUF_PT (buf)); | 856 Emchar ch = BUF_FETCH_CHAR (buf, BUF_PT (buf)); |
857 if ((ch < 0400) ? fastmap[ch] : | 857 if ((ch < 0400) ? fastmap[ch] : |
858 (NILP (Fget_range_table (make_int (ch), | 858 (NILP (Fget_range_table (make_int (ch), |
859 Vskip_chars_range_table, | 859 Vskip_chars_range_table, |
864 break; | 864 break; |
865 } | 865 } |
866 } | 866 } |
867 else | 867 else |
868 { | 868 { |
869 while (BUF_PT (buf) > XINT (lim)) | 869 while (BUF_PT (buf) > limit) |
870 { | 870 { |
871 Emchar ch = BUF_FETCH_CHAR (buf, BUF_PT (buf) - 1); | 871 Emchar ch = BUF_FETCH_CHAR (buf, BUF_PT (buf) - 1); |
872 if ((ch < 0400) ? fastmap[ch] : | 872 if ((ch < 0400) ? fastmap[ch] : |
873 (NILP (Fget_range_table (make_int (ch), | 873 (NILP (Fget_range_table (make_int (ch), |
874 Vskip_chars_range_table, | 874 Vskip_chars_range_table, |
1381 else | 1381 else |
1382 while ((EMACS_UINT) cursor >= | 1382 while ((EMACS_UINT) cursor >= |
1383 (EMACS_UINT) p_limit) | 1383 (EMACS_UINT) p_limit) |
1384 cursor += BM_tab[*cursor]; | 1384 cursor += BM_tab[*cursor]; |
1385 } | 1385 } |
1386 /* If you are here, cursor is beyond the end of the searched region. */ | 1386 /* If you are here, cursor is beyond the end of the searched region. */ |
1387 /* This can happen if you match on the far character of the pattern, */ | 1387 /* This can happen if you match on the far character of the pattern, */ |
1388 /* because the "stride" of that character is infinity, a number able */ | 1388 /* because the "stride" of that character is infinity, a number able */ |
1389 /* to throw you well beyond the end of the search. It can also */ | 1389 /* to throw you well beyond the end of the search. It can also */ |
1390 /* happen if you fail to match within the permitted region and would */ | 1390 /* happen if you fail to match within the permitted region and would */ |
1391 /* otherwise try a character beyond that region */ | 1391 /* otherwise try a character beyond that region */ |
1835 syntax_table = XCHAR_TABLE (buf->mirror_syntax_table); | 1835 syntax_table = XCHAR_TABLE (buf->mirror_syntax_table); |
1836 | 1836 |
1837 case_action = nochange; /* We tried an initialization */ | 1837 case_action = nochange; /* We tried an initialization */ |
1838 /* but some C compilers blew it */ | 1838 /* but some C compilers blew it */ |
1839 | 1839 |
1840 if (search_regs.num_regs <= 0) | 1840 if (search_regs.num_regs == 0) |
1841 error ("replace-match called before any match found"); | 1841 error ("replace-match called before any match found"); |
1842 | 1842 |
1843 if (NILP (string)) | 1843 if (NILP (string)) |
1844 { | 1844 { |
1845 if (search_regs.start[0] < BUF_BEGV (buf) | 1845 if (search_regs.start[0] < BUF_BEGV (buf) |
2217 | 2217 |
2218 CHECK_INT (num); | 2218 CHECK_INT (num); |
2219 n = XINT (num); | 2219 n = XINT (num); |
2220 if (n < 0 || n >= search_regs.num_regs) | 2220 if (n < 0 || n >= search_regs.num_regs) |
2221 args_out_of_range (num, make_int (search_regs.num_regs)); | 2221 args_out_of_range (num, make_int (search_regs.num_regs)); |
2222 if (search_regs.num_regs <= 0 || | 2222 if (search_regs.num_regs == 0 || |
2223 search_regs.start[n] < 0) | 2223 search_regs.start[n] < 0) |
2224 return Qnil; | 2224 return Qnil; |
2225 return make_int (beginningp ? search_regs.start[n] : search_regs.end[n]); | 2225 return make_int (beginningp ? search_regs.start[n] : search_regs.end[n]); |
2226 } | 2226 } |
2227 | 2227 |
2308 if (!CONSP (reuse)) | 2308 if (!CONSP (reuse)) |
2309 return Flist (2 * len + 2, data); | 2309 return Flist (2 * len + 2, data); |
2310 | 2310 |
2311 /* If REUSE is a list, store as many value elements as will fit | 2311 /* If REUSE is a list, store as many value elements as will fit |
2312 into the elements of REUSE. */ | 2312 into the elements of REUSE. */ |
2313 for (i = 0, tail = reuse; CONSP (tail); i++, tail = XCDR (tail)) | 2313 for (prev = Qnil, i = 0, tail = reuse; CONSP (tail); i++, tail = XCDR (tail)) |
2314 { | 2314 { |
2315 if (i < 2 * len + 2) | 2315 if (i < 2 * len + 2) |
2316 XCAR (tail) = data[i]; | 2316 XCAR (tail) = data[i]; |
2317 else | 2317 else |
2318 XCAR (tail) = Qnil; | 2318 XCAR (tail) = Qnil; |