Mercurial > hg > xemacs-beta
comparison src/search.c @ 185:3d6bfa290dbd r20-3b19
Import from CVS: tag r20-3b19
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:55:28 +0200 |
parents | 8eaf7971accc |
children | b405438285a2 |
comparison
equal
deleted
inserted
replaced
184:bcd2674570bf | 185:3d6bfa290dbd |
---|---|
221 We could get a potential speedup by not converting the search registers | 221 We could get a potential speedup by not converting the search registers |
222 until it's really necessary, e.g. when match-data or replace-match is | 222 until it's really necessary, e.g. when match-data or replace-match is |
223 called. However, this complexifies the code a lot (e.g. the buffer | 223 called. However, this complexifies the code a lot (e.g. the buffer |
224 could have changed and the Bytinds stored might be invalid) and is | 224 could have changed and the Bytinds stored might be invalid) and is |
225 probably not a great time-saver. */ | 225 probably not a great time-saver. */ |
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 |
549 /* This function has been Mule-ized. */ | 549 /* This function has been Mule-ized. */ |
550 Bytind lim = en > 0 ? en : | 550 Bytind lim = en > 0 ? en : |
551 ((count > 0) ? BI_BUF_ZV (buf) : BI_BUF_BEGV (buf)); | 551 ((count > 0) ? BI_BUF_ZV (buf) : BI_BUF_BEGV (buf)); |
552 | 552 |
553 /* #### newline cache stuff in this function not yet ported */ | 553 /* #### newline cache stuff in this function not yet ported */ |
554 | 554 |
555 assert (count != 0); | 555 assert (count != 0); |
556 | 556 |
557 if (shortage) | 557 if (shortage) |
558 *shortage = 0; | 558 *shortage = 0; |
559 | 559 |
560 if (count > 0) | 560 if (count > 0) |
561 { | 561 { |
562 #ifdef MULE | 562 #ifdef MULE |
563 /* Due to the Mule representation of characters in a buffer, | 563 /* Due to the Mule representation of characters in a buffer, |
564 we can simply search for characters in the range 0 - 127 | 564 we can simply search for characters in the range 0 - 127 |
579 { | 579 { |
580 while (st < lim && count > 0) | 580 while (st < lim && count > 0) |
581 { | 581 { |
582 Bytind ceil; | 582 Bytind ceil; |
583 Bufbyte *bufptr; | 583 Bufbyte *bufptr; |
584 | 584 |
585 ceil = BI_BUF_CEILING_OF (buf, st); | 585 ceil = BI_BUF_CEILING_OF (buf, st); |
586 ceil = min (lim, ceil); | 586 ceil = min (lim, ceil); |
587 bufptr = (Bufbyte *) memchr (BI_BUF_BYTE_ADDRESS (buf, st), | 587 bufptr = (Bufbyte *) memchr (BI_BUF_BYTE_ADDRESS (buf, st), |
588 (int) target, ceil - st); | 588 (int) target, ceil - st); |
589 if (bufptr) | 589 if (bufptr) |
620 while (st > lim && count < 0) | 620 while (st > lim && count < 0) |
621 { | 621 { |
622 Bytind floor; | 622 Bytind floor; |
623 Bufbyte *bufptr; | 623 Bufbyte *bufptr; |
624 Bufbyte *floorptr; | 624 Bufbyte *floorptr; |
625 | 625 |
626 floor = BI_BUF_FLOOR_OF (buf, st); | 626 floor = BI_BUF_FLOOR_OF (buf, st); |
627 floor = max (lim, floor); | 627 floor = max (lim, floor); |
628 /* No memrchr() ... */ | 628 /* No memrchr() ... */ |
629 bufptr = BI_BUF_BYTE_ADDRESS_BEFORE (buf, st); | 629 bufptr = BI_BUF_BYTE_ADDRESS_BEFORE (buf, st); |
630 floorptr = BI_BUF_BYTE_ADDRESS (buf, floor); | 630 floorptr = BI_BUF_BYTE_ADDRESS (buf, floor); |
705 int shortage; | 705 int shortage; |
706 Bufpos pos = scan_buffer (buf, '\n', from, to, cnt, &shortage, 1); | 706 Bufpos pos = scan_buffer (buf, '\n', from, to, cnt, &shortage, 1); |
707 | 707 |
708 if (shortage == 0) | 708 if (shortage == 0) |
709 pos--; | 709 pos--; |
710 | 710 |
711 return pos; | 711 return pos; |
712 } | 712 } |
713 | 713 |
714 static Lisp_Object | 714 static Lisp_Object |
715 skip_chars (struct buffer *buf, int forwardp, int syntaxp, | 715 skip_chars (struct buffer *buf, int forwardp, int syntaxp, |
742 p = XSTRING_DATA (string); | 742 p = XSTRING_DATA (string); |
743 pend = p + XSTRING_LENGTH (string); | 743 pend = p + XSTRING_LENGTH (string); |
744 memset (fastmap, 0, sizeof (fastmap)); | 744 memset (fastmap, 0, sizeof (fastmap)); |
745 | 745 |
746 Fclear_range_table (Vskip_chars_range_table); | 746 Fclear_range_table (Vskip_chars_range_table); |
747 | 747 |
748 if (p != pend && *p == '^') | 748 if (p != pend && *p == '^') |
749 { | 749 { |
750 negate = 1; | 750 negate = 1; |
751 p++; | 751 p++; |
752 } | 752 } |
776 INC_CHARPTR (p); | 776 INC_CHARPTR (p); |
777 } | 777 } |
778 if (p != pend && *p == '-') | 778 if (p != pend && *p == '-') |
779 { | 779 { |
780 Emchar cend; | 780 Emchar cend; |
781 | 781 |
782 p++; | 782 p++; |
783 if (p == pend) break; | 783 if (p == pend) break; |
784 cend = charptr_emchar (p); | 784 cend = charptr_emchar (p); |
785 while (c <= cend && c < 0400) | 785 while (c <= cend && c < 0400) |
786 { | 786 { |
832 BUF_SET_PT (buf, BUF_PT (buf) + 1); | 832 BUF_SET_PT (buf, BUF_PT (buf) + 1); |
833 } | 833 } |
834 else | 834 else |
835 { | 835 { |
836 while (BUF_PT (buf) > XINT (lim) | 836 while (BUF_PT (buf) > XINT (lim) |
837 && fastmap[(unsigned char) | 837 && fastmap[(unsigned char) |
838 syntax_code_spec | 838 syntax_code_spec |
839 [(int) SYNTAX (syntax_table, | 839 [(int) SYNTAX (syntax_table, |
840 BUF_FETCH_CHAR | 840 BUF_FETCH_CHAR |
841 (buf, BUF_PT (buf) - 1))]]) | 841 (buf, BUF_PT (buf) - 1))]]) |
842 BUF_SET_PT (buf, BUF_PT (buf) - 1); | 842 BUF_SET_PT (buf, BUF_PT (buf) - 1); |
861 } | 861 } |
862 else | 862 else |
863 { | 863 { |
864 while (BUF_PT (buf) > XINT (lim)) | 864 while (BUF_PT (buf) > XINT (lim)) |
865 { | 865 { |
866 Emchar ch = BUF_FETCH_CHAR (buf, BUF_PT (buf) - 1); | 866 Emchar ch = BUF_FETCH_CHAR (buf, BUF_PT (buf) - 1); |
867 if ((ch < 0400) ? fastmap[ch] : | 867 if ((ch < 0400) ? fastmap[ch] : |
868 (NILP (Fget_range_table (make_int (ch), | 868 (NILP (Fget_range_table (make_int (ch), |
869 Vskip_chars_range_table, | 869 Vskip_chars_range_table, |
870 Qnil)) | 870 Qnil)) |
871 == negate)) | 871 == negate)) |
882 | 882 |
883 DEFUN ("skip-chars-forward", Fskip_chars_forward, 1, 3, 0, /* | 883 DEFUN ("skip-chars-forward", Fskip_chars_forward, 1, 3, 0, /* |
884 Move point forward, stopping before a char not in STRING, or at pos LIM. | 884 Move point forward, stopping before a char not in STRING, or at pos LIM. |
885 STRING is like the inside of a `[...]' in a regular expression | 885 STRING is like the inside of a `[...]' in a regular expression |
886 except that `]' is never special and `\\' quotes `^', `-' or `\\'. | 886 except that `]' is never special and `\\' quotes `^', `-' or `\\'. |
887 Thus, with arg \"a-zA-Z\", this skips letters stopping before first nonletter. | 887 Thus, with arg "a-zA-Z", this skips letters stopping before first nonletter. |
888 With arg \"^a-zA-Z\", skips nonletters stopping before first letter. | 888 With arg "^a-zA-Z", skips nonletters stopping before first letter. |
889 Returns the distance traveled, either zero or positive. | 889 Returns the distance traveled, either zero or positive. |
890 | 890 |
891 Optional argument BUFFER defaults to the current buffer. | 891 Optional argument BUFFER defaults to the current buffer. |
892 */ | 892 */ |
893 (string, lim, buffer)) | 893 (string, lim, buffer)) |
1072 EMACS_INT infinity; | 1072 EMACS_INT infinity; |
1073 Bytind limit; | 1073 Bytind limit; |
1074 EMACS_INT k; | 1074 EMACS_INT k; |
1075 Bytecount stride_for_teases = 0; | 1075 Bytecount stride_for_teases = 0; |
1076 register Bufbyte *pat = 0; | 1076 register Bufbyte *pat = 0; |
1077 register Bufbyte *cursor, *p_limit, *ptr2; | 1077 register Bufbyte *cursor, *p_limit, *ptr2; |
1078 register EMACS_INT i, j; | 1078 register EMACS_INT i, j; |
1079 Bytind p1, p2; | 1079 Bytind p1, p2; |
1080 Bytecount s1, s2; | 1080 Bytecount s1, s2; |
1081 Bytind pos, lim; | 1081 Bytind pos, lim; |
1082 | 1082 |
1108 | 1108 |
1109 p1 = BI_BUF_BEGV (buf); | 1109 p1 = BI_BUF_BEGV (buf); |
1110 p2 = BI_BUF_CEILING_OF (buf, p1); | 1110 p2 = BI_BUF_CEILING_OF (buf, p1); |
1111 s1 = p2 - p1; | 1111 s1 = p2 - p1; |
1112 s2 = BI_BUF_ZV (buf) - p2; | 1112 s2 = BI_BUF_ZV (buf) - p2; |
1113 | 1113 |
1114 while (n < 0) | 1114 while (n < 0) |
1115 { | 1115 { |
1116 Bytecount val; | 1116 Bytecount val; |
1117 QUIT; | 1117 QUIT; |
1118 regex_emacs_buffer = buf; | 1118 regex_emacs_buffer = buf; |
1219 { | 1219 { |
1220 #ifdef C_ALLOCA | 1220 #ifdef C_ALLOCA |
1221 EMACS_INT BM_tab_space[0400]; | 1221 EMACS_INT BM_tab_space[0400]; |
1222 BM_tab = &BM_tab_space[0]; | 1222 BM_tab = &BM_tab_space[0]; |
1223 #else | 1223 #else |
1224 BM_tab = (EMACS_INT *) alloca (0400 * sizeof (EMACS_INT)); | 1224 BM_tab = alloca_array (EMACS_INT, 256); |
1225 #endif | 1225 #endif |
1226 { | 1226 { |
1227 Bufbyte *patbuf = (Bufbyte *) alloca (len); | 1227 Bufbyte *patbuf = alloca_array (Bufbyte, len); |
1228 pat = patbuf; | 1228 pat = patbuf; |
1229 while (--len >= 0) | 1229 while (--len >= 0) |
1230 { | 1230 { |
1231 /* If we got here and the RE flag is set, it's because we're | 1231 /* If we got here and the RE flag is set, it's because we're |
1232 dealing with a regexp known to be trivial, so the backslash | 1232 dealing with a regexp known to be trivial, so the backslash |
1257 /* As a coding trick, an enormous stride is coded into the table for */ | 1257 /* As a coding trick, an enormous stride is coded into the table for */ |
1258 /* characters that match the last character. This allows use of only */ | 1258 /* characters that match the last character. This allows use of only */ |
1259 /* a single test, a test for having gone past the end of the */ | 1259 /* a single test, a test for having gone past the end of the */ |
1260 /* permissible match region, to test for both possible matches (when */ | 1260 /* permissible match region, to test for both possible matches (when */ |
1261 /* the stride goes past the end immediately) and failure to */ | 1261 /* the stride goes past the end immediately) and failure to */ |
1262 /* match (where you get nudged past the end one stride at a time). */ | 1262 /* match (where you get nudged past the end one stride at a time). */ |
1263 | 1263 |
1264 /* Here we make a "mickey mouse" BM table. The stride of the search */ | 1264 /* Here we make a "mickey mouse" BM table. The stride of the search */ |
1265 /* is determined only by the last character of the putative match. */ | 1265 /* is determined only by the last character of the putative match. */ |
1266 /* If that character does not match, we will stride the proper */ | 1266 /* If that character does not match, we will stride the proper */ |
1267 /* distance to propose a match that superimposes it on the last */ | 1267 /* distance to propose a match that superimposes it on the last */ |
1268 /* instance of a character that matches it (per trt), or misses */ | 1268 /* instance of a character that matches it (per trt), or misses */ |
1269 /* it entirely if there is none. */ | 1269 /* it entirely if there is none. */ |
1270 | 1270 |
1271 dirlen = len * direction; | 1271 dirlen = len * direction; |
1272 infinity = dirlen - (lim + pos + len + len) * direction; | 1272 infinity = dirlen - (lim + pos + len + len) * direction; |
1273 if (direction < 0) | 1273 if (direction < 0) |
1274 pat = (base_pat += len - 1); | 1274 pat = (base_pat += len - 1); |
1294 k = (j = trt[j]); | 1294 k = (j = trt[j]); |
1295 if (i == infinity) | 1295 if (i == infinity) |
1296 stride_for_teases = BM_tab[j]; | 1296 stride_for_teases = BM_tab[j]; |
1297 BM_tab[j] = dirlen - i; | 1297 BM_tab[j] = dirlen - i; |
1298 /* A translation table is accompanied by its inverse -- see */ | 1298 /* A translation table is accompanied by its inverse -- see */ |
1299 /* comment following downcase_table for details */ | 1299 /* comment following downcase_table for details */ |
1300 | 1300 |
1301 while ((j = inverse_trt[j]) != k) | 1301 while ((j = inverse_trt[j]) != k) |
1302 BM_tab[j] = dirlen - i; | 1302 BM_tab[j] = dirlen - i; |
1303 } | 1303 } |
1304 else | 1304 else |
1407 Bytind bytstart = (pos + cursor - ptr2 + | 1407 Bytind bytstart = (pos + cursor - ptr2 + |
1408 ((direction > 0) | 1408 ((direction > 0) |
1409 ? 1 - len : 0)); | 1409 ? 1 - len : 0)); |
1410 Bufpos bufstart = bytind_to_bufpos (buf, bytstart); | 1410 Bufpos bufstart = bytind_to_bufpos (buf, bytstart); |
1411 Bufpos bufend = bytind_to_bufpos (buf, bytstart + len); | 1411 Bufpos bufend = bytind_to_bufpos (buf, bytstart + len); |
1412 | 1412 |
1413 set_search_regs (buf, bufstart, bufend - bufstart); | 1413 set_search_regs (buf, bufstart, bufend - bufstart); |
1414 } | 1414 } |
1415 | 1415 |
1416 if ((n -= direction) != 0) | 1416 if ((n -= direction) != 0) |
1417 cursor += dirlen; /* to resume search */ | 1417 cursor += dirlen; /* to resume search */ |
1441 while (1) | 1441 while (1) |
1442 { | 1442 { |
1443 /* This loop can be coded for space rather than */ | 1443 /* This loop can be coded for space rather than */ |
1444 /* speed because it will usually run only once. */ | 1444 /* speed because it will usually run only once. */ |
1445 /* (the reach is at most len + 21, and typically */ | 1445 /* (the reach is at most len + 21, and typically */ |
1446 /* does not exceed len) */ | 1446 /* does not exceed len) */ |
1447 while ((limit - pos) * direction >= 0) | 1447 while ((limit - pos) * direction >= 0) |
1448 /* *not* BI_BUF_FETCH_CHAR. We are working here | 1448 /* *not* BI_BUF_FETCH_CHAR. We are working here |
1449 with bytes, not characters. */ | 1449 with bytes, not characters. */ |
1450 pos += BM_tab[*BI_BUF_BYTE_ADDRESS (buf, pos)]; | 1450 pos += BM_tab[*BI_BUF_BYTE_ADDRESS (buf, pos)]; |
1451 /* now run the same tests to distinguish going off the */ | 1451 /* now run the same tests to distinguish going off the */ |
1477 Bytind bytstart = (pos + | 1477 Bytind bytstart = (pos + |
1478 ((direction > 0) | 1478 ((direction > 0) |
1479 ? 1 - len : 0)); | 1479 ? 1 - len : 0)); |
1480 Bufpos bufstart = bytind_to_bufpos (buf, bytstart); | 1480 Bufpos bufstart = bytind_to_bufpos (buf, bytstart); |
1481 Bufpos bufend = bytind_to_bufpos (buf, bytstart + len); | 1481 Bufpos bufend = bytind_to_bufpos (buf, bytstart + len); |
1482 | 1482 |
1483 set_search_regs (buf, bufstart, bufend - bufstart); | 1483 set_search_regs (buf, bufstart, bufend - bufstart); |
1484 } | 1484 } |
1485 | 1485 |
1486 if ((n -= direction) != 0) | 1486 if ((n -= direction) != 0) |
1487 pos += dirlen; /* to resume search */ | 1487 pos += dirlen; /* to resume search */ |
1510 /* This function has been Mule-ized. */ | 1510 /* This function has been Mule-ized. */ |
1511 /* Make sure we have registers in which to store | 1511 /* Make sure we have registers in which to store |
1512 the match position. */ | 1512 the match position. */ |
1513 if (search_regs.num_regs == 0) | 1513 if (search_regs.num_regs == 0) |
1514 { | 1514 { |
1515 /* #### XEmacs: the ones were twos before, which is surely broken. */ | 1515 search_regs.start = xnew (regoff_t); |
1516 search_regs.start = (regoff_t *) xmalloc (1 * sizeof (regoff_t)); | 1516 search_regs.end = xnew (regoff_t); |
1517 search_regs.end = (regoff_t *) xmalloc (1 * sizeof (regoff_t)); | |
1518 search_regs.num_regs = 1; | 1517 search_regs.num_regs = 1; |
1519 } | 1518 } |
1520 | 1519 |
1521 search_regs.start[0] = beg; | 1520 search_regs.start[0] = beg; |
1522 search_regs.end[0] = beg + len; | 1521 search_regs.end[0] = beg + len; |
1564 *o++ = 'b'; | 1563 *o++ = 'b'; |
1565 | 1564 |
1566 for (i = 0; i < len; i++) | 1565 for (i = 0; i < len; i++) |
1567 { | 1566 { |
1568 Emchar ch = string_char (XSTRING (string), i); | 1567 Emchar ch = string_char (XSTRING (string), i); |
1569 | 1568 |
1570 if (WORD_SYNTAX_P (syntax_table, ch)) | 1569 if (WORD_SYNTAX_P (syntax_table, ch)) |
1571 o += set_charptr_emchar (o, ch); | 1570 o += set_charptr_emchar (o, ch); |
1572 else if (i > 0 | 1571 else if (i > 0 |
1573 && WORD_SYNTAX_P (syntax_table, | 1572 && WORD_SYNTAX_P (syntax_table, |
1574 string_char (XSTRING (string), i - 1)) | 1573 string_char (XSTRING (string), i - 1)) |
1826 buffer = last_thing_searched; | 1825 buffer = last_thing_searched; |
1827 buf = XBUFFER (buffer); | 1826 buf = XBUFFER (buffer); |
1828 } | 1827 } |
1829 | 1828 |
1830 syntax_table = XCHAR_TABLE (buf->mirror_syntax_table); | 1829 syntax_table = XCHAR_TABLE (buf->mirror_syntax_table); |
1831 | 1830 |
1832 case_action = nochange; /* We tried an initialization */ | 1831 case_action = nochange; /* We tried an initialization */ |
1833 /* but some C compilers blew it */ | 1832 /* but some C compilers blew it */ |
1834 | 1833 |
1835 if (search_regs.num_regs <= 0) | 1834 if (search_regs.num_regs <= 0) |
1836 error ("replace-match called before any match found"); | 1835 error ("replace-match called before any match found"); |
2042 { | 2041 { |
2043 int i = 0; | 2042 int i = 0; |
2044 int cur_action = 'E'; | 2043 int cur_action = 'E'; |
2045 Charcount stlen = string_char_length (XSTRING (newtext)); | 2044 Charcount stlen = string_char_length (XSTRING (newtext)); |
2046 Charcount strpos; | 2045 Charcount strpos; |
2047 | 2046 |
2048 for (strpos = 0; strpos < stlen; strpos++) | 2047 for (strpos = 0; strpos < stlen; strpos++) |
2049 { | 2048 { |
2050 Emchar curchar = string_char (XSTRING (newtext), strpos); | 2049 Emchar curchar = string_char (XSTRING (newtext), strpos); |
2051 Emchar newchar = -1; | 2050 Emchar newchar = -1; |
2052 if (i < Dynarr_length (ul_pos_dynarr) && | 2051 if (i < Dynarr_length (ul_pos_dynarr) && |
2084 search_regs.end[0]); | 2083 search_regs.end[0]); |
2085 | 2084 |
2086 /* begin_multiple_change() records an unwind-protect, so we need to | 2085 /* begin_multiple_change() records an unwind-protect, so we need to |
2087 record this value now. */ | 2086 record this value now. */ |
2088 speccount = specpdl_depth (); | 2087 speccount = specpdl_depth (); |
2089 | 2088 |
2090 /* We insert the replacement text before the old text, and then | 2089 /* We insert the replacement text before the old text, and then |
2091 delete the original text. This means that markers at the | 2090 delete the original text. This means that markers at the |
2092 beginning or end of the original will float to the corresponding | 2091 beginning or end of the original will float to the corresponding |
2093 position in the replacement. */ | 2092 position in the replacement. */ |
2094 BUF_SET_PT (buf, search_regs.start[0]); | 2093 BUF_SET_PT (buf, search_regs.start[0]); |
2107 c = string_char (XSTRING (newtext), strpos); | 2106 c = string_char (XSTRING (newtext), strpos); |
2108 if (c == '\\') | 2107 if (c == '\\') |
2109 { | 2108 { |
2110 c = string_char (XSTRING (newtext), ++strpos); | 2109 c = string_char (XSTRING (newtext), ++strpos); |
2111 if (c == '&') | 2110 if (c == '&') |
2112 Finsert_buffer_substring | 2111 Finsert_buffer_substring |
2113 (buffer, | 2112 (buffer, |
2114 make_int (search_regs.start[0] + offset), | 2113 make_int (search_regs.start[0] + offset), |
2115 make_int (search_regs.end[0] + offset)); | 2114 make_int (search_regs.end[0] + offset)); |
2116 else if (c >= '1' && c <= '9' && | 2115 else if (c >= '1' && c <= '9' && |
2117 c <= search_regs.num_regs + '0') | 2116 c <= search_regs.num_regs + '0') |
2239 Zero means the entire text matched by the whole regexp or whole string. | 2238 Zero means the entire text matched by the whole regexp or whole string. |
2240 */ | 2239 */ |
2241 (num)) | 2240 (num)) |
2242 { | 2241 { |
2243 return match_limit (num, 0); | 2242 return match_limit (num, 0); |
2244 } | 2243 } |
2245 | 2244 |
2246 DEFUN ("match-data", Fmatch_data, 0, 0, 0, /* | 2245 DEFUN ("match-data", Fmatch_data, 0, 0, 0, /* |
2247 Return a list containing all info on what the last regexp search matched. | 2246 Return a list containing all info on what the last regexp search matched. |
2248 Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'. | 2247 Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'. |
2249 All the elements are markers or nil (nil if the Nth pair didn't match) | 2248 All the elements are markers or nil (nil if the Nth pair didn't match) |
2258 Charcount len; | 2257 Charcount len; |
2259 | 2258 |
2260 if (NILP (last_thing_searched)) | 2259 if (NILP (last_thing_searched)) |
2261 error ("match-data called before any match found"); | 2260 error ("match-data called before any match found"); |
2262 | 2261 |
2263 data = (Lisp_Object *) alloca ((2 * search_regs.num_regs) | 2262 data = alloca_array (Lisp_Object, 2 * search_regs.num_regs); |
2264 * sizeof (Lisp_Object)); | |
2265 | 2263 |
2266 len = -1; | 2264 len = -1; |
2267 for (i = 0; i < search_regs.num_regs; i++) | 2265 for (i = 0; i < search_regs.num_regs; i++) |
2268 { | 2266 { |
2269 Bufpos start = search_regs.start[i]; | 2267 Bufpos start = search_regs.start[i]; |
2280 Fset_marker (data[2 * i], | 2278 Fset_marker (data[2 * i], |
2281 make_int (start), | 2279 make_int (start), |
2282 last_thing_searched); | 2280 last_thing_searched); |
2283 data[2 * i + 1] = Fmake_marker (); | 2281 data[2 * i + 1] = Fmake_marker (); |
2284 Fset_marker (data[2 * i + 1], | 2282 Fset_marker (data[2 * i + 1], |
2285 make_int (search_regs.end[i]), | 2283 make_int (search_regs.end[i]), |
2286 last_thing_searched); | 2284 last_thing_searched); |
2287 } | 2285 } |
2288 else | 2286 else |
2289 /* last_thing_searched must always be Qt, a buffer, or Qnil. */ | 2287 /* last_thing_searched must always be Qt, a buffer, or Qnil. */ |
2290 abort (); | 2288 abort (); |
2312 save_search_regs (); | 2310 save_search_regs (); |
2313 | 2311 |
2314 if (!CONSP (list) && !NILP (list)) | 2312 if (!CONSP (list) && !NILP (list)) |
2315 list = wrong_type_argument (Qconsp, list); | 2313 list = wrong_type_argument (Qconsp, list); |
2316 | 2314 |
2317 /* Unless we find a marker with a buffer in LIST, assume that this | 2315 /* Unless we find a marker with a buffer in LIST, assume that this |
2318 match data came from a string. */ | 2316 match data came from a string. */ |
2319 last_thing_searched = Qt; | 2317 last_thing_searched = Qt; |
2320 | 2318 |
2321 /* Allocate registers if they don't already exist. */ | 2319 /* Allocate registers if they don't already exist. */ |
2322 { | 2320 { |
2324 | 2322 |
2325 if (length > search_regs.num_regs) | 2323 if (length > search_regs.num_regs) |
2326 { | 2324 { |
2327 if (search_regs.num_regs == 0) | 2325 if (search_regs.num_regs == 0) |
2328 { | 2326 { |
2329 search_regs.start | 2327 search_regs.start = xnew_array (regoff_t, length); |
2330 = (regoff_t *) xmalloc (length * sizeof (regoff_t)); | 2328 search_regs.end = xnew_array (regoff_t, length); |
2331 search_regs.end | |
2332 = (regoff_t *) xmalloc (length * sizeof (regoff_t)); | |
2333 } | 2329 } |
2334 else | 2330 else |
2335 { | 2331 { |
2336 search_regs.start | 2332 XREALLOC_ARRAY (search_regs.start, regoff_t, length); |
2337 = (regoff_t *) xrealloc (search_regs.start, | 2333 XREALLOC_ARRAY (search_regs.end, regoff_t, length); |
2338 length * sizeof (regoff_t)); | |
2339 search_regs.end | |
2340 = (regoff_t *) xrealloc (search_regs.end, | |
2341 length * sizeof (regoff_t)); | |
2342 } | 2334 } |
2343 | 2335 |
2344 search_regs.num_regs = length; | 2336 search_regs.num_regs = length; |
2345 } | 2337 } |
2346 } | 2338 } |
2375 search_regs.end[i] = XINT (marker); | 2367 search_regs.end[i] = XINT (marker); |
2376 } | 2368 } |
2377 list = Fcdr (list); | 2369 list = Fcdr (list); |
2378 } | 2370 } |
2379 | 2371 |
2380 return Qnil; | 2372 return Qnil; |
2381 } | 2373 } |
2382 | 2374 |
2383 /* If non-zero the match data have been saved in saved_search_regs | 2375 /* If non-zero the match data have been saved in saved_search_regs |
2384 during the execution of a sentinel or filter. */ | 2376 during the execution of a sentinel or filter. */ |
2385 static int search_regs_saved; | 2377 static int search_regs_saved; |
2439 | 2431 |
2440 /* Now copy the data into the new string, inserting escapes. */ | 2432 /* Now copy the data into the new string, inserting escapes. */ |
2441 | 2433 |
2442 in = XSTRING_DATA (str); | 2434 in = XSTRING_DATA (str); |
2443 end = in + XSTRING_LENGTH (str); | 2435 end = in + XSTRING_LENGTH (str); |
2444 out = temp; | 2436 out = temp; |
2445 | 2437 |
2446 for (; in != end; in++) | 2438 for (; in != end; in++) |
2447 { | 2439 { |
2448 if (*in == '[' || *in == ']' | 2440 if (*in == '[' || *in == ']' |
2449 || *in == '*' || *in == '.' || *in == '\\' | 2441 || *in == '*' || *in == '.' || *in == '\\' |