Mercurial > hg > xemacs-beta
comparison src/search.c @ 1024:ccaf90c5a53a
[xemacs-hg @ 2002-10-02 09:29:37 by stephent]
21.4 -> R21.5 stuff
manual improvements <87k7l1p6su.fsf@tleepslib.sk.tsukuba.ac.jp>
regexp tests <87fzvpp6mf.fsf@tleepslib.sk.tsukuba.ac.jp>
add-to-list doc Ville Skyttä <87bs6dp6io.fsf@tleepslib.sk.tsukuba.ac.jp>
Move filename associations Ville Skyttä <877kh1p6ee.fsf@tleepslib.sk.tsukuba.ac.jp>
lookup-syntax-properties <87admil2e0.fsf_-_@tleepslib.sk.tsukuba.ac.jp>
fix stale submatches <873crpp50v.fsf_-_@tleepslib.sk.tsukuba.ac.jp>
info for developers <87y99hnqc4.fsf@tleepslib.sk.tsukuba.ac.jp>
author | stephent |
---|---|
date | Wed, 02 Oct 2002 09:31:40 +0000 |
parents | f809bc97829a |
children | 8d350b095c21 |
comparison
equal
deleted
inserted
replaced
1023:ce9bdd48654f | 1024:ccaf90c5a53a |
---|---|
109 | 109 |
110 /* range table for use with skip_chars. Only needed for Mule. */ | 110 /* range table for use with skip_chars. Only needed for Mule. */ |
111 Lisp_Object Vskip_chars_range_table; | 111 Lisp_Object Vskip_chars_range_table; |
112 | 112 |
113 static void set_search_regs (struct buffer *buf, Charbpos beg, Charcount len); | 113 static void set_search_regs (struct buffer *buf, Charbpos beg, Charcount len); |
114 static void clear_unused_search_regs (struct re_registers *regp, int no_sub); | |
114 static Charbpos simple_search (struct buffer *buf, Ibyte *base_pat, | 115 static Charbpos simple_search (struct buffer *buf, Ibyte *base_pat, |
115 Bytecount len, Bytebpos pos, Bytebpos lim, | 116 Bytecount len, Bytebpos pos, Bytebpos lim, |
116 EMACS_INT n, Lisp_Object trt); | 117 EMACS_INT n, Lisp_Object trt); |
117 static Charbpos boyer_moore (struct buffer *buf, Ibyte *base_pat, | 118 static Charbpos boyer_moore (struct buffer *buf, Ibyte *base_pat, |
118 Bytecount len, Bytebpos pos, Bytebpos lim, | 119 Bytecount len, Bytebpos pos, Bytebpos lim, |
1220 | 1221 |
1221 /* Null string is found at starting position. */ | 1222 /* Null string is found at starting position. */ |
1222 if (len == 0) | 1223 if (len == 0) |
1223 { | 1224 { |
1224 set_search_regs (buf, charbpos, 0); | 1225 set_search_regs (buf, charbpos, 0); |
1226 clear_unused_search_regs (&search_regs, 0); | |
1225 return charbpos; | 1227 return charbpos; |
1226 } | 1228 } |
1227 | 1229 |
1228 /* Searching 0 times means don't move. */ | 1230 /* Searching 0 times means noop---don't move, don't touch registers. */ |
1229 if (n == 0) | 1231 if (n == 0) |
1230 return charbpos; | 1232 return charbpos; |
1231 | 1233 |
1232 pos = charbpos_to_bytebpos (buf, charbpos); | 1234 pos = charbpos_to_bytebpos (buf, charbpos); |
1233 lim = charbpos_to_bytebpos (buf, buflim); | 1235 lim = charbpos_to_bytebpos (buf, buflim); |
1479 { | 1481 { |
1480 retval = beg = bytebpos_to_charbpos (buf, pos); | 1482 retval = beg = bytebpos_to_charbpos (buf, pos); |
1481 end = bytebpos_to_charbpos (buf, pos + buf_len); | 1483 end = bytebpos_to_charbpos (buf, pos + buf_len); |
1482 } | 1484 } |
1483 set_search_regs (buf, beg, end - beg); | 1485 set_search_regs (buf, beg, end - beg); |
1486 clear_unused_search_regs (&search_regs, 0); | |
1484 | 1487 |
1485 return retval; | 1488 return retval; |
1486 } | 1489 } |
1487 else if (n > 0) | 1490 else if (n > 0) |
1488 return -n; | 1491 return -n; |
1842 ? 1 - len : 0)); | 1845 ? 1 - len : 0)); |
1843 Charbpos bufstart = bytebpos_to_charbpos (buf, bytstart); | 1846 Charbpos bufstart = bytebpos_to_charbpos (buf, bytstart); |
1844 Charbpos bufend = bytebpos_to_charbpos (buf, bytstart + len); | 1847 Charbpos bufend = bytebpos_to_charbpos (buf, bytstart + len); |
1845 | 1848 |
1846 set_search_regs (buf, bufstart, bufend - bufstart); | 1849 set_search_regs (buf, bufstart, bufend - bufstart); |
1850 clear_unused_search_regs (&search_regs, 0); | |
1847 } | 1851 } |
1848 | 1852 |
1849 if ((n -= direction) != 0) | 1853 if ((n -= direction) != 0) |
1850 cursor += dirlen; /* to resume search */ | 1854 cursor += dirlen; /* to resume search */ |
1851 else | 1855 else |
1932 ? 1 - len : 0)); | 1936 ? 1 - len : 0)); |
1933 Charbpos bufstart = bytebpos_to_charbpos (buf, bytstart); | 1937 Charbpos bufstart = bytebpos_to_charbpos (buf, bytstart); |
1934 Charbpos bufend = bytebpos_to_charbpos (buf, bytstart + len); | 1938 Charbpos bufend = bytebpos_to_charbpos (buf, bytstart + len); |
1935 | 1939 |
1936 set_search_regs (buf, bufstart, bufend - bufstart); | 1940 set_search_regs (buf, bufstart, bufend - bufstart); |
1941 clear_unused_search_regs (&search_regs, 0); | |
1937 } | 1942 } |
1938 | 1943 |
1939 if ((n -= direction) != 0) | 1944 if ((n -= direction) != 0) |
1940 pos += dirlen; /* to resume search */ | 1945 pos += dirlen; /* to resume search */ |
1941 else | 1946 else |
1951 return (0 - n) * direction; | 1956 return (0 - n) * direction; |
1952 } | 1957 } |
1953 return bytebpos_to_charbpos (buf, pos); | 1958 return bytebpos_to_charbpos (buf, pos); |
1954 } | 1959 } |
1955 | 1960 |
1956 /* Record beginning BEG and end BEG + LEN | 1961 /* Record the whole-match data (beginning BEG and end BEG + LEN) and the |
1957 for a match just found in the current buffer. */ | 1962 buffer for a match just found. */ |
1958 | 1963 |
1959 static void | 1964 static void |
1960 set_search_regs (struct buffer *buf, Charbpos beg, Charcount len) | 1965 set_search_regs (struct buffer *buf, Charbpos beg, Charcount len) |
1961 { | 1966 { |
1962 /* Make sure we have registers in which to store | 1967 /* Make sure we have registers in which to store |
1969 } | 1974 } |
1970 | 1975 |
1971 search_regs.start[0] = beg; | 1976 search_regs.start[0] = beg; |
1972 search_regs.end[0] = beg + len; | 1977 search_regs.end[0] = beg + len; |
1973 last_thing_searched = wrap_buffer (buf); | 1978 last_thing_searched = wrap_buffer (buf); |
1979 } | |
1980 | |
1981 /* Clear unused search registers so match data will be null. | |
1982 REGP is a pointer to the register structure to clear, usually the global | |
1983 search_regs. | |
1984 NO_SUB is the number of subexpressions to allow for. (Does not count | |
1985 the whole match, ie, for a string search NO_SUB == 0.) | |
1986 It is an error if NO_SUB > REGP.num_regs - 1. */ | |
1987 | |
1988 static void | |
1989 clear_unused_search_regs (struct re_registers *regp, int no_sub) | |
1990 { | |
1991 /* This function has been Mule-ized. */ | |
1992 int i; | |
1993 | |
1994 assert (no_sub >= 0 && no_sub < regp->num_regs); | |
1995 for (i = no_sub + 1; i < regp->num_regs; i++) | |
1996 regp->start[i] = regp->end[i] = -1; | |
1974 } | 1997 } |
1975 | 1998 |
1976 | 1999 |
1977 /* Given a string of words separated by word delimiters, | 2000 /* Given a string of words separated by word delimiters, |
1978 compute a regexp that matches those exact words | 2001 compute a regexp that matches those exact words |