diff options
| author | Richard M. Stallman | 1994-01-10 22:36:49 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-01-10 22:36:49 +0000 |
| commit | ca325161005f717d0c4aa0ee7ddb345f43e9d12e (patch) | |
| tree | fe0235db75f2d84d6a45a6640422a8b2aef616b3 /src | |
| parent | 67bc89ab85ebe95ec783731c61c2bb4419adad7a (diff) | |
| download | emacs-ca325161005f717d0c4aa0ee7ddb345f43e9d12e.tar.gz emacs-ca325161005f717d0c4aa0ee7ddb345f43e9d12e.zip | |
(set_search_regs): New subroutine.
(search_buffer): Use set_search_regs.
Record beginning and end after matching null string.
Diffstat (limited to 'src')
| -rw-r--r-- | src/search.c | 86 |
1 files changed, 41 insertions, 45 deletions
diff --git a/src/search.c b/src/search.c index b10a8865058..47f52380b9e 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -69,6 +69,8 @@ static Lisp_Object last_thing_searched; | |||
| 69 | 69 | ||
| 70 | Lisp_Object Qinvalid_regexp; | 70 | Lisp_Object Qinvalid_regexp; |
| 71 | 71 | ||
| 72 | static void set_search_regs (); | ||
| 73 | |||
| 72 | static void | 74 | static void |
| 73 | matcher_overflow () | 75 | matcher_overflow () |
| 74 | { | 76 | { |
| @@ -576,7 +578,7 @@ search_command (string, bound, noerror, count, direction, RE) | |||
| 576 | return make_number (np); | 578 | return make_number (np); |
| 577 | } | 579 | } |
| 578 | 580 | ||
| 579 | /* search for the n'th occurrence of STRING in the current buffer, | 581 | /* Search for the n'th occurrence of STRING in the current buffer, |
| 580 | starting at position POS and stopping at position LIM, | 582 | starting at position POS and stopping at position LIM, |
| 581 | treating PAT as a literal string if RE is false or as | 583 | treating PAT as a literal string if RE is false or as |
| 582 | a regular expression if RE is true. | 584 | a regular expression if RE is true. |
| @@ -611,7 +613,10 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt) | |||
| 611 | 613 | ||
| 612 | /* Null string is found at starting position. */ | 614 | /* Null string is found at starting position. */ |
| 613 | if (len == 0) | 615 | if (len == 0) |
| 614 | return pos; | 616 | { |
| 617 | set_search_regs (pos, 0); | ||
| 618 | return pos; | ||
| 619 | } | ||
| 615 | 620 | ||
| 616 | /* Searching 0 times means don't move. */ | 621 | /* Searching 0 times means don't move. */ |
| 617 | if (n == 0) | 622 | if (n == 0) |
| @@ -883,28 +888,10 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt) | |||
| 883 | { | 888 | { |
| 884 | cursor -= direction; | 889 | cursor -= direction; |
| 885 | 890 | ||
| 886 | /* Make sure we have registers in which to store | 891 | set_search_regs (pos + cursor - p2 + ((direction > 0) |
| 887 | the match position. */ | 892 | ? 1 - len : 0), |
| 888 | if (search_regs.num_regs == 0) | 893 | len); |
| 889 | { | 894 | |
| 890 | regoff_t *starts, *ends; | ||
| 891 | |||
| 892 | starts = | ||
| 893 | (regoff_t *) xmalloc (2 * sizeof (regoff_t)); | ||
| 894 | ends = | ||
| 895 | (regoff_t *) xmalloc (2 * sizeof (regoff_t)); | ||
| 896 | BLOCK_INPUT; | ||
| 897 | re_set_registers (&searchbuf, | ||
| 898 | &search_regs, | ||
| 899 | 2, starts, ends); | ||
| 900 | UNBLOCK_INPUT; | ||
| 901 | } | ||
| 902 | |||
| 903 | search_regs.start[0] | ||
| 904 | = pos + cursor - p2 + ((direction > 0) | ||
| 905 | ? 1 - len : 0); | ||
| 906 | search_regs.end[0] = len + search_regs.start[0]; | ||
| 907 | XSET (last_thing_searched, Lisp_Buffer, current_buffer); | ||
| 908 | if ((n -= direction) != 0) | 895 | if ((n -= direction) != 0) |
| 909 | cursor += dirlen; /* to resume search */ | 896 | cursor += dirlen; /* to resume search */ |
| 910 | else | 897 | else |
| @@ -960,27 +947,9 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt) | |||
| 960 | { | 947 | { |
| 961 | pos -= direction; | 948 | pos -= direction; |
| 962 | 949 | ||
| 963 | /* Make sure we have registers in which to store | 950 | set_search_regs (pos + ((direction > 0) ? 1 - len : 0), |
| 964 | the match position. */ | 951 | len); |
| 965 | if (search_regs.num_regs == 0) | 952 | |
| 966 | { | ||
| 967 | regoff_t *starts, *ends; | ||
| 968 | |||
| 969 | starts = | ||
| 970 | (regoff_t *) xmalloc (2 * sizeof (regoff_t)); | ||
| 971 | ends = | ||
| 972 | (regoff_t *) xmalloc (2 * sizeof (regoff_t)); | ||
| 973 | BLOCK_INPUT; | ||
| 974 | re_set_registers (&searchbuf, | ||
| 975 | &search_regs, | ||
| 976 | 2, starts, ends); | ||
| 977 | UNBLOCK_INPUT; | ||
| 978 | } | ||
| 979 | |||
| 980 | search_regs.start[0] | ||
| 981 | = pos + ((direction > 0) ? 1 - len : 0); | ||
| 982 | search_regs.end[0] = len + search_regs.start[0]; | ||
| 983 | XSET (last_thing_searched, Lisp_Buffer, current_buffer); | ||
| 984 | if ((n -= direction) != 0) | 953 | if ((n -= direction) != 0) |
| 985 | pos += dirlen; /* to resume search */ | 954 | pos += dirlen; /* to resume search */ |
| 986 | else | 955 | else |
| @@ -998,6 +967,33 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt) | |||
| 998 | return pos; | 967 | return pos; |
| 999 | } | 968 | } |
| 1000 | } | 969 | } |
| 970 | |||
| 971 | /* Record beginning BEG and end BEG + LEN | ||
| 972 | for a match just found in the current buffer. */ | ||
| 973 | |||
| 974 | static void | ||
| 975 | set_search_regs (beg, len) | ||
| 976 | int beg, len; | ||
| 977 | { | ||
| 978 | /* Make sure we have registers in which to store | ||
| 979 | the match position. */ | ||
| 980 | if (search_regs.num_regs == 0) | ||
| 981 | { | ||
| 982 | regoff_t *starts, *ends; | ||
| 983 | |||
| 984 | starts = (regoff_t *) xmalloc (2 * sizeof (regoff_t)); | ||
| 985 | ends = (regoff_t *) xmalloc (2 * sizeof (regoff_t)); | ||
| 986 | BLOCK_INPUT; | ||
| 987 | re_set_registers (&searchbuf, | ||
| 988 | &search_regs, | ||
| 989 | 2, starts, ends); | ||
| 990 | UNBLOCK_INPUT; | ||
| 991 | } | ||
| 992 | |||
| 993 | search_regs.start[0] = beg; | ||
| 994 | search_regs.end[0] = beg + len; | ||
| 995 | XSET (last_thing_searched, Lisp_Buffer, current_buffer); | ||
| 996 | } | ||
| 1001 | 997 | ||
| 1002 | /* Given a string of words separated by word delimiters, | 998 | /* Given a string of words separated by word delimiters, |
| 1003 | compute a regexp that matches those exact words | 999 | compute a regexp that matches those exact words |