comparison src/search.c @ 272:c5d627a313b1 r21-0b34

Import from CVS: tag r21-0b34
author cvs
date Mon, 13 Aug 2007 10:28:48 +0200
parents 677f6a0ee643
children c42ec1d1cded
comparison
equal deleted inserted replaced
271:c7b7086b0a39 272:c5d627a313b1
226 226
227 static void 227 static void
228 fixup_search_regs_for_buffer (struct buffer *buf) 228 fixup_search_regs_for_buffer (struct buffer *buf)
229 { 229 {
230 int i; 230 int i;
231 231 int num_regs = search_regs.num_regs;
232 for (i = 0; i < search_regs.num_regs; i++) 232
233 for (i = 0; i < num_regs; i++)
233 { 234 {
234 if (search_regs.start[i] >= 0) 235 if (search_regs.start[i] >= 0)
235 search_regs.start[i] = bytind_to_bufpos (buf, search_regs.start[i]); 236 search_regs.start[i] = bytind_to_bufpos (buf, search_regs.start[i]);
236 if (search_regs.end[i] >= 0) 237 if (search_regs.end[i] >= 0)
237 search_regs.end[i] = bytind_to_bufpos (buf, search_regs.end[i]); 238 search_regs.end[i] = bytind_to_bufpos (buf, search_regs.end[i]);
241 /* Similar but for strings. */ 242 /* Similar but for strings. */
242 static void 243 static void
243 fixup_search_regs_for_string (Lisp_Object string) 244 fixup_search_regs_for_string (Lisp_Object string)
244 { 245 {
245 int i; 246 int i;
247 int num_regs = search_regs.num_regs;
246 248
247 /* #### bytecount_to_charcount() is not that efficient. This function 249 /* #### bytecount_to_charcount() is not that efficient. This function
248 could be faster if it did its own conversion (using INC_CHARPTR() 250 could be faster if it did its own conversion (using INC_CHARPTR()
249 and such), because the register ends are likely to be somewhat ordered. 251 and such), because the register ends are likely to be somewhat ordered.
250 (Even if not, you could sort them.) 252 (Even if not, you could sort them.)
251 253
252 Think about this if this function is a time hog, which it's probably 254 Think about this if this function is a time hog, which it's probably
253 not. */ 255 not. */
254 for (i = 0; i < search_regs.num_regs; i++) 256 for (i = 0; i < num_regs; i++)
255 { 257 {
256 if (search_regs.start[i] > 0) 258 if (search_regs.start[i] > 0)
257 { 259 {
258 search_regs.start[i] = 260 search_regs.start[i] =
259 bytecount_to_charcount (XSTRING_DATA (string), 261 bytecount_to_charcount (XSTRING_DATA (string),
309 matcher_overflow (); 311 matcher_overflow ();
310 312
311 val = (0 <= i ? Qt : Qnil); 313 val = (0 <= i ? Qt : Qnil);
312 if (NILP (val)) 314 if (NILP (val))
313 return Qnil; 315 return Qnil;
314 for (i = 0; i < search_regs.num_regs; i++) 316 {
315 if (search_regs.start[i] >= 0) 317 int num_regs = search_regs.num_regs;
316 { 318 for (i = 0; i < num_regs; i++)
317 search_regs.start[i] += BI_BUF_BEGV (buf); 319 if (search_regs.start[i] >= 0)
318 search_regs.end[i] += BI_BUF_BEGV (buf); 320 {
319 } 321 search_regs.start[i] += BI_BUF_BEGV (buf);
322 search_regs.end[i] += BI_BUF_BEGV (buf);
323 }
324 }
320 XSETBUFFER (last_thing_searched, buf); 325 XSETBUFFER (last_thing_searched, buf);
321 fixup_search_regs_for_buffer (buf); 326 fixup_search_regs_for_buffer (buf);
322 return val; 327 return val;
323 } 328 }
324 329
366 371
367 if (NILP (start)) 372 if (NILP (start))
368 s = 0; 373 s = 0;
369 else 374 else
370 { 375 {
371 Charcount len = string_char_length (XSTRING (string)); 376 Charcount len = XSTRING_CHAR_LENGTH (string);
372 377
373 CHECK_INT (start); 378 CHECK_INT (start);
374 s = XINT (start); 379 s = XINT (start);
375 if (s < 0 && -s <= len) 380 if (s < 0 && -s <= len)
376 s = len + s; 381 s = len + s;
739 if (XINT (lim) < BUF_BEGV (buf)) 744 if (XINT (lim) < BUF_BEGV (buf))
740 lim = make_int (BUF_BEGV (buf)); 745 lim = make_int (BUF_BEGV (buf));
741 746
742 p = XSTRING_DATA (string); 747 p = XSTRING_DATA (string);
743 pend = p + XSTRING_LENGTH (string); 748 pend = p + XSTRING_LENGTH (string);
744 memset (fastmap, 0, sizeof (fastmap)); 749 xzero (fastmap);
745 750
746 Fclear_range_table (Vskip_chars_range_table); 751 Fclear_range_table (Vskip_chars_range_table);
747 752
748 if (p != pend && *p == '^') 753 if (p != pend && *p == '^')
749 { 754 {
809 /* If ^ was the first character, complement the fastmap. 814 /* If ^ was the first character, complement the fastmap.
810 We don't complement the range table, however; we just use negate 815 We don't complement the range table, however; we just use negate
811 in the comparisons below. */ 816 in the comparisons below. */
812 817
813 if (negate) 818 if (negate)
814 for (i = 0; i < sizeof fastmap; i++) 819 for (i = 0; i < (int) (sizeof fastmap); i++)
815 fastmap[i] ^= 1; 820 fastmap[i] ^= 1;
816 821
817 { 822 {
818 Bufpos start_point = BUF_PT (buf); 823 Bufpos start_point = BUF_PT (buf);
819 824
1126 { 1131 {
1127 matcher_overflow (); 1132 matcher_overflow ();
1128 } 1133 }
1129 if (val >= 0) 1134 if (val >= 0)
1130 { 1135 {
1136 int num_regs = search_regs.num_regs;
1131 j = BI_BUF_BEGV (buf); 1137 j = BI_BUF_BEGV (buf);
1132 for (i = 0; i < search_regs.num_regs; i++) 1138 for (i = 0; i < num_regs; i++)
1133 if (search_regs.start[i] >= 0) 1139 if (search_regs.start[i] >= 0)
1134 { 1140 {
1135 search_regs.start[i] += j; 1141 search_regs.start[i] += j;
1136 search_regs.end[i] += j; 1142 search_regs.end[i] += j;
1137 } 1143 }
1162 { 1168 {
1163 matcher_overflow (); 1169 matcher_overflow ();
1164 } 1170 }
1165 if (val >= 0) 1171 if (val >= 0)
1166 { 1172 {
1173 int num_regs = search_regs.num_regs;
1167 j = BI_BUF_BEGV (buf); 1174 j = BI_BUF_BEGV (buf);
1168 for (i = 0; i < search_regs.num_regs; i++) 1175 for (i = 0; i < num_regs; i++)
1169 if (search_regs.start[i] >= 0) 1176 if (search_regs.start[i] >= 0)
1170 { 1177 {
1171 search_regs.start[i] += j; 1178 search_regs.start[i] += j;
1172 search_regs.end[i] += j; 1179 search_regs.end[i] += j;
1173 } 1180 }
1358 (EMACS_INT) p_limit) 1365 (EMACS_INT) p_limit)
1359 while ((EMACS_INT) cursor <= 1366 while ((EMACS_INT) cursor <=
1360 (EMACS_INT) p_limit) 1367 (EMACS_INT) p_limit)
1361 cursor += BM_tab[*cursor]; 1368 cursor += BM_tab[*cursor];
1362 else 1369 else
1363 while ((unsigned EMACS_INT) cursor <= 1370 while ((EMACS_UINT) cursor <=
1364 (unsigned EMACS_INT) p_limit) 1371 (EMACS_UINT) p_limit)
1365 cursor += BM_tab[*cursor]; 1372 cursor += BM_tab[*cursor];
1366 } 1373 }
1367 else 1374 else
1368 { 1375 {
1369 if ((EMACS_INT) (p_limit + infinity) < 1376 if ((EMACS_INT) (p_limit + infinity) <
1370 (EMACS_INT) p_limit) 1377 (EMACS_INT) p_limit)
1371 while ((EMACS_INT) cursor >= 1378 while ((EMACS_INT) cursor >=
1372 (EMACS_INT) p_limit) 1379 (EMACS_INT) p_limit)
1373 cursor += BM_tab[*cursor]; 1380 cursor += BM_tab[*cursor];
1374 else 1381 else
1375 while ((unsigned EMACS_INT) cursor >= 1382 while ((EMACS_UINT) cursor >=
1376 (unsigned EMACS_INT) p_limit) 1383 (EMACS_UINT) p_limit)
1377 cursor += BM_tab[*cursor]; 1384 cursor += BM_tab[*cursor];
1378 } 1385 }
1379 /* 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. */
1380 /* 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, */
1381 /* because the "stride" of that character is infinity, a number able */ 1388 /* because the "stride" of that character is infinity, a number able */
1535 struct buffer *buf = decode_buffer (buffer, 0); 1542 struct buffer *buf = decode_buffer (buffer, 0);
1536 struct Lisp_Char_Table *syntax_table = 1543 struct Lisp_Char_Table *syntax_table =
1537 XCHAR_TABLE (buf->mirror_syntax_table); 1544 XCHAR_TABLE (buf->mirror_syntax_table);
1538 1545
1539 CHECK_STRING (string); 1546 CHECK_STRING (string);
1540 len = string_char_length (XSTRING (string)); 1547 len = XSTRING_CHAR_LENGTH (string);
1541 1548
1542 for (i = 0; i < len; i++) 1549 for (i = 0; i < len; i++)
1543 if (!WORD_SYNTAX_P (syntax_table, string_char (XSTRING (string), i))) 1550 if (!WORD_SYNTAX_P (syntax_table, string_char (XSTRING (string), i)))
1544 { 1551 {
1545 punct_count++; 1552 punct_count++;
1843 } 1850 }
1844 else 1851 else
1845 { 1852 {
1846 if (search_regs.start[0] < 0 1853 if (search_regs.start[0] < 0
1847 || search_regs.start[0] > search_regs.end[0] 1854 || search_regs.start[0] > search_regs.end[0]
1848 || search_regs.end[0] > string_char_length (XSTRING (string))) 1855 || search_regs.end[0] > XSTRING_CHAR_LENGTH (string))
1849 args_out_of_range (make_int (search_regs.start[0]), 1856 args_out_of_range (make_int (search_regs.start[0]),
1850 make_int (search_regs.end[0])); 1857 make_int (search_regs.end[0]));
1851 } 1858 }
1852 1859
1853 if (NILP (fixedcase)) 1860 if (NILP (fixedcase))
1926 after = Fsubstring (string, make_int (search_regs.end[0]), Qnil); 1933 after = Fsubstring (string, make_int (search_regs.end[0]), Qnil);
1927 1934
1928 /* Do case substitution into NEWTEXT if desired. */ 1935 /* Do case substitution into NEWTEXT if desired. */
1929 if (NILP (literal)) 1936 if (NILP (literal))
1930 { 1937 {
1931 Charcount stlen = string_char_length (XSTRING (newtext)); 1938 Charcount stlen = XSTRING_CHAR_LENGTH (newtext);
1932 Charcount strpos; 1939 Charcount strpos;
1933 /* XEmacs change: rewrote this loop somewhat to make it 1940 /* XEmacs change: rewrote this loop somewhat to make it
1934 cleaner. Also added \U, \E, etc. */ 1941 cleaner. Also added \U, \E, etc. */
1935 Charcount literal_start = 0; 1942 Charcount literal_start = 0;
1936 /* We build up the substituted string in ACCUM. */ 1943 /* We build up the substituted string in ACCUM. */
1992 make_opaque_ptr (ul_action_dynarr))); 1999 make_opaque_ptr (ul_action_dynarr)));
1993 } 2000 }
1994 literal_end = strpos - 1; 2001 literal_end = strpos - 1;
1995 Dynarr_add (ul_pos_dynarr, 2002 Dynarr_add (ul_pos_dynarr,
1996 (!NILP (accum) 2003 (!NILP (accum)
1997 ? string_char_length (XSTRING (accum)) 2004 ? XSTRING_CHAR_LENGTH (accum)
1998 : 0) + (literal_end - literal_start)); 2005 : 0) + (literal_end - literal_start));
1999 Dynarr_add (ul_action_dynarr, c); 2006 Dynarr_add (ul_action_dynarr, c);
2000 } 2007 }
2001 else if (c == '\\') 2008 else if (c == '\\')
2002 /* So we get just one backslash. */ 2009 /* So we get just one backslash. */
2037 /* Now finally, we need to process the \U's, \E's, etc. */ 2044 /* Now finally, we need to process the \U's, \E's, etc. */
2038 if (ul_pos_dynarr) 2045 if (ul_pos_dynarr)
2039 { 2046 {
2040 int i = 0; 2047 int i = 0;
2041 int cur_action = 'E'; 2048 int cur_action = 'E';
2042 Charcount stlen = string_char_length (XSTRING (newtext)); 2049 Charcount stlen = XSTRING_CHAR_LENGTH (newtext);
2043 Charcount strpos; 2050 Charcount strpos;
2044 2051
2045 for (strpos = 0; strpos < stlen; strpos++) 2052 for (strpos = 0; strpos < stlen; strpos++)
2046 { 2053 {
2047 Emchar curchar = string_char (XSTRING (newtext), strpos); 2054 Emchar curchar = string_char (XSTRING (newtext), strpos);
2091 BUF_SET_PT (buf, search_regs.start[0]); 2098 BUF_SET_PT (buf, search_regs.start[0]);
2092 if (!NILP (literal)) 2099 if (!NILP (literal))
2093 Finsert (1, &newtext); 2100 Finsert (1, &newtext);
2094 else 2101 else
2095 { 2102 {
2096 Charcount stlen = string_char_length (XSTRING (newtext)); 2103 Charcount stlen = XSTRING_CHAR_LENGTH (newtext);
2097 Charcount strpos; 2104 Charcount strpos;
2098 struct gcpro gcpro1; 2105 struct gcpro gcpro1;
2099 GCPRO1 (newtext); 2106 GCPRO1 (newtext);
2100 for (strpos = 0; strpos < stlen; strpos++) 2107 for (strpos = 0; strpos < stlen; strpos++)
2101 { 2108 {
2302 (list)) 2309 (list))
2303 { 2310 {
2304 /* This function has been Mule-ized. */ 2311 /* This function has been Mule-ized. */
2305 REGISTER int i; 2312 REGISTER int i;
2306 REGISTER Lisp_Object marker; 2313 REGISTER Lisp_Object marker;
2314 int num_regs;
2315 int length;
2307 2316
2308 if (running_asynch_code) 2317 if (running_asynch_code)
2309 save_search_regs (); 2318 save_search_regs ();
2310 2319
2311 if (!CONSP (list) && !NILP (list)) 2320 CONCHECK_LIST (list);
2312 list = wrong_type_argument (Qconsp, list);
2313 2321
2314 /* Unless we find a marker with a buffer in LIST, assume that this 2322 /* Unless we find a marker with a buffer in LIST, assume that this
2315 match data came from a string. */ 2323 match data came from a string. */
2316 last_thing_searched = Qt; 2324 last_thing_searched = Qt;
2317 2325
2318 /* Allocate registers if they don't already exist. */ 2326 /* Allocate registers if they don't already exist. */
2319 { 2327 length = XINT (Flength (list)) / 2;
2320 int length = XINT (Flength (list)) / 2; 2328 num_regs = search_regs.num_regs;
2321 2329
2322 if (length > search_regs.num_regs) 2330 if (length > num_regs)
2323 { 2331 {
2324 if (search_regs.num_regs == 0) 2332 if (search_regs.num_regs == 0)
2325 { 2333 {
2326 search_regs.start = xnew_array (regoff_t, length); 2334 search_regs.start = xnew_array (regoff_t, length);
2327 search_regs.end = xnew_array (regoff_t, length); 2335 search_regs.end = xnew_array (regoff_t, length);
2328 } 2336 }
2329 else 2337 else
2330 { 2338 {
2331 XREALLOC_ARRAY (search_regs.start, regoff_t, length); 2339 XREALLOC_ARRAY (search_regs.start, regoff_t, length);
2332 XREALLOC_ARRAY (search_regs.end, regoff_t, length); 2340 XREALLOC_ARRAY (search_regs.end, regoff_t, length);
2333 } 2341 }
2334 2342
2335 search_regs.num_regs = length; 2343 search_regs.num_regs = length;
2336 } 2344 }
2337 } 2345
2338 2346 for (i = 0; i < num_regs; i++)
2339 for (i = 0; i < search_regs.num_regs; i++)
2340 { 2347 {
2341 marker = Fcar (list); 2348 marker = Fcar (list);
2342 if (NILP (marker)) 2349 if (NILP (marker))
2343 { 2350 {
2344 search_regs.start[i] = -1; 2351 search_regs.start[i] = -1;