Mercurial > emacs
comparison src/search.c @ 10032:f689803caa92
Added code for automatically saving and restoring the match data
when a filter or sentinel tries to modify it.
author | Francesco Potortì <pot@gnu.org> |
---|---|
date | Mon, 21 Nov 1994 12:50:27 +0000 |
parents | c41ce96785a8 |
children | cb713218845a |
comparison
equal
deleted
inserted
replaced
10031:324e027f01bc | 10032:f689803caa92 |
---|---|
204 unsigned char *p1, *p2; | 204 unsigned char *p1, *p2; |
205 int s1, s2; | 205 int s1, s2; |
206 register int i; | 206 register int i; |
207 struct re_pattern_buffer *bufp; | 207 struct re_pattern_buffer *bufp; |
208 | 208 |
209 if (running_asynch_code) | |
210 save_search_regs (); | |
211 | |
209 CHECK_STRING (string, 0); | 212 CHECK_STRING (string, 0); |
210 bufp = compile_pattern (string, &search_regs, | 213 bufp = compile_pattern (string, &search_regs, |
211 (!NILP (current_buffer->case_fold_search) | 214 (!NILP (current_buffer->case_fold_search) |
212 ? DOWNCASE_TABLE : 0), | 215 ? DOWNCASE_TABLE : 0), |
213 posix); | 216 posix); |
281 int posix; | 284 int posix; |
282 { | 285 { |
283 int val; | 286 int val; |
284 int s; | 287 int s; |
285 struct re_pattern_buffer *bufp; | 288 struct re_pattern_buffer *bufp; |
289 | |
290 if (running_asynch_code) | |
291 save_search_regs (); | |
286 | 292 |
287 CHECK_STRING (regexp, 0); | 293 CHECK_STRING (regexp, 0); |
288 CHECK_STRING (string, 1); | 294 CHECK_STRING (string, 1); |
289 | 295 |
290 if (NILP (start)) | 296 if (NILP (start)) |
925 int infinity, limit, k, stride_for_teases; | 931 int infinity, limit, k, stride_for_teases; |
926 register unsigned char *pat, *cursor, *p_limit; | 932 register unsigned char *pat, *cursor, *p_limit; |
927 register int i, j; | 933 register int i, j; |
928 unsigned char *p1, *p2; | 934 unsigned char *p1, *p2; |
929 int s1, s2; | 935 int s1, s2; |
936 | |
937 if (running_asynch_code) | |
938 save_search_regs (); | |
930 | 939 |
931 /* Null string is found at starting position. */ | 940 /* Null string is found at starting position. */ |
932 if (len == 0) | 941 if (len == 0) |
933 { | 942 { |
934 set_search_regs (pos, 0); | 943 set_search_regs (pos, 0); |
1843 register Lisp_Object list; | 1852 register Lisp_Object list; |
1844 { | 1853 { |
1845 register int i; | 1854 register int i; |
1846 register Lisp_Object marker; | 1855 register Lisp_Object marker; |
1847 | 1856 |
1857 if (running_asynch_code) | |
1858 save_search_regs (); | |
1859 | |
1848 if (!CONSP (list) && !NILP (list)) | 1860 if (!CONSP (list) && !NILP (list)) |
1849 list = wrong_type_argument (Qconsp, list); | 1861 list = wrong_type_argument (Qconsp, list); |
1850 | 1862 |
1851 /* Unless we find a marker with a buffer in LIST, assume that this | 1863 /* Unless we find a marker with a buffer in LIST, assume that this |
1852 match data came from a string. */ | 1864 match data came from a string. */ |
1910 } | 1922 } |
1911 list = Fcdr (list); | 1923 list = Fcdr (list); |
1912 } | 1924 } |
1913 | 1925 |
1914 return Qnil; | 1926 return Qnil; |
1927 } | |
1928 | |
1929 /* If non-zero the match data have been saved in saved_search_regs | |
1930 during the execution of a sentinel or filter. */ | |
1931 static int search_regs_saved = 0; | |
1932 static struct re_registers saved_search_regs; | |
1933 | |
1934 /* Called from Flooking_at, Fstring_match, search_buffer, Fstore_match_data | |
1935 if asynchronous code (filter or sentinel) is running. */ | |
1936 static void | |
1937 save_search_regs () | |
1938 { | |
1939 if (!search_regs_saved) | |
1940 { | |
1941 saved_search_regs.num_regs = search_regs.num_regs; | |
1942 saved_search_regs.start = search_regs.start; | |
1943 saved_search_regs.end = search_regs.end; | |
1944 search_regs.num_regs = 0; | |
1945 | |
1946 search_regs_saved = 1; | |
1947 } | |
1948 } | |
1949 | |
1950 /* Called upon exit from filters and sentinels. */ | |
1951 void | |
1952 restore_match_data () | |
1953 { | |
1954 if (search_regs_saved) | |
1955 { | |
1956 if (search_regs.num_regs > 0) | |
1957 { | |
1958 xfree (search_regs.start); | |
1959 xfree (search_regs.end); | |
1960 } | |
1961 search_regs.num_regs = saved_search_regs.num_regs; | |
1962 search_regs.start = saved_search_regs.start; | |
1963 search_regs.end = saved_search_regs.end; | |
1964 | |
1965 search_regs_saved = 0; | |
1966 } | |
1915 } | 1967 } |
1916 | 1968 |
1917 /* Quote a string to inactivate reg-expr chars */ | 1969 /* Quote a string to inactivate reg-expr chars */ |
1918 | 1970 |
1919 DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0, | 1971 DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0, |