Mercurial > emacs
comparison src/search.c @ 49600:23a1cea22d13
Trailing whitespace deleted.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Tue, 04 Feb 2003 14:56:31 +0000 |
parents | 467b0e57d985 |
children | 3d562e7ebf97 |
comparison
equal
deleted
inserted
replaced
49599:5ade352e8d1c | 49600:23a1cea22d13 |
---|---|
304 s1 = ZV_BYTE - BEGV_BYTE; | 304 s1 = ZV_BYTE - BEGV_BYTE; |
305 s2 = 0; | 305 s2 = 0; |
306 } | 306 } |
307 | 307 |
308 re_match_object = Qnil; | 308 re_match_object = Qnil; |
309 | 309 |
310 i = re_match_2 (bufp, (char *) p1, s1, (char *) p2, s2, | 310 i = re_match_2 (bufp, (char *) p1, s1, (char *) p2, s2, |
311 PT_BYTE - BEGV_BYTE, &search_regs, | 311 PT_BYTE - BEGV_BYTE, &search_regs, |
312 ZV_BYTE - BEGV_BYTE); | 312 ZV_BYTE - BEGV_BYTE); |
313 immediate_quit = 0; | 313 immediate_quit = 0; |
314 | 314 |
315 if (i == -2) | 315 if (i == -2) |
316 matcher_overflow (); | 316 matcher_overflow (); |
317 | 317 |
318 val = (0 <= i ? Qt : Qnil); | 318 val = (0 <= i ? Qt : Qnil); |
319 if (i >= 0) | 319 if (i >= 0) |
388 ? DOWNCASE_TABLE : Qnil), | 388 ? DOWNCASE_TABLE : Qnil), |
389 posix, | 389 posix, |
390 STRING_MULTIBYTE (string)); | 390 STRING_MULTIBYTE (string)); |
391 immediate_quit = 1; | 391 immediate_quit = 1; |
392 re_match_object = string; | 392 re_match_object = string; |
393 | 393 |
394 val = re_search (bufp, (char *) SDATA (string), | 394 val = re_search (bufp, (char *) SDATA (string), |
395 SBYTES (string), pos_byte, | 395 SBYTES (string), pos_byte, |
396 SBYTES (string) - pos_byte, | 396 SBYTES (string) - pos_byte, |
397 &search_regs); | 397 &search_regs); |
398 immediate_quit = 0; | 398 immediate_quit = 0; |
456 | 456 |
457 bufp = compile_pattern (regexp, 0, Qnil, | 457 bufp = compile_pattern (regexp, 0, Qnil, |
458 0, STRING_MULTIBYTE (string)); | 458 0, STRING_MULTIBYTE (string)); |
459 immediate_quit = 1; | 459 immediate_quit = 1; |
460 re_match_object = string; | 460 re_match_object = string; |
461 | 461 |
462 val = re_search (bufp, (char *) SDATA (string), | 462 val = re_search (bufp, (char *) SDATA (string), |
463 SBYTES (string), 0, | 463 SBYTES (string), 0, |
464 SBYTES (string), 0); | 464 SBYTES (string), 0); |
465 immediate_quit = 0; | 465 immediate_quit = 0; |
466 return val; | 466 return val; |
548 int count; | 548 int count; |
549 int *shortage; | 549 int *shortage; |
550 int allow_quit; | 550 int allow_quit; |
551 { | 551 { |
552 struct region_cache *newline_cache; | 552 struct region_cache *newline_cache; |
553 int direction; | 553 int direction; |
554 | 554 |
555 if (count > 0) | 555 if (count > 0) |
556 { | 556 { |
557 direction = 1; | 557 direction = 1; |
558 if (! end) end = ZV; | 558 if (! end) end = ZV; |
609 position after that. */ | 609 position after that. */ |
610 tem = BUFFER_CEILING_OF (start_byte); | 610 tem = BUFFER_CEILING_OF (start_byte); |
611 ceiling_byte = min (tem, ceiling_byte); | 611 ceiling_byte = min (tem, ceiling_byte); |
612 | 612 |
613 { | 613 { |
614 /* The termination address of the dumb loop. */ | 614 /* The termination address of the dumb loop. */ |
615 register unsigned char *ceiling_addr | 615 register unsigned char *ceiling_addr |
616 = BYTE_POS_ADDR (ceiling_byte) + 1; | 616 = BYTE_POS_ADDR (ceiling_byte) + 1; |
617 register unsigned char *cursor | 617 register unsigned char *cursor |
618 = BYTE_POS_ADDR (start_byte); | 618 = BYTE_POS_ADDR (start_byte); |
619 unsigned char *base = cursor; | 619 unsigned char *base = cursor; |
854 int shortage; | 854 int shortage; |
855 int pos = scan_buffer ('\n', from, to, cnt, &shortage, 1); | 855 int pos = scan_buffer ('\n', from, to, cnt, &shortage, 1); |
856 | 856 |
857 if (shortage == 0) | 857 if (shortage == 0) |
858 pos--; | 858 pos--; |
859 | 859 |
860 return pos; | 860 return pos; |
861 } | 861 } |
862 | 862 |
863 /* Subroutines of Lisp buffer search functions. */ | 863 /* Subroutines of Lisp buffer search functions. */ |
864 | 864 |
1060 { | 1060 { |
1061 s1 = ZV_BYTE - BEGV_BYTE; | 1061 s1 = ZV_BYTE - BEGV_BYTE; |
1062 s2 = 0; | 1062 s2 = 0; |
1063 } | 1063 } |
1064 re_match_object = Qnil; | 1064 re_match_object = Qnil; |
1065 | 1065 |
1066 while (n < 0) | 1066 while (n < 0) |
1067 { | 1067 { |
1068 int val; | 1068 int val; |
1069 val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2, | 1069 val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2, |
1070 pos_byte - BEGV_BYTE, lim_byte - pos_byte, | 1070 pos_byte - BEGV_BYTE, lim_byte - pos_byte, |
1526 int direction = ((n > 0) ? 1 : -1); | 1526 int direction = ((n > 0) ? 1 : -1); |
1527 register int dirlen; | 1527 register int dirlen; |
1528 int infinity, limit, stride_for_teases = 0; | 1528 int infinity, limit, stride_for_teases = 0; |
1529 register int *BM_tab; | 1529 register int *BM_tab; |
1530 int *BM_tab_base; | 1530 int *BM_tab_base; |
1531 register unsigned char *cursor, *p_limit; | 1531 register unsigned char *cursor, *p_limit; |
1532 register int i, j; | 1532 register int i, j; |
1533 unsigned char *pat, *pat_end; | 1533 unsigned char *pat, *pat_end; |
1534 int multibyte = ! NILP (current_buffer->enable_multibyte_characters); | 1534 int multibyte = ! NILP (current_buffer->enable_multibyte_characters); |
1535 | 1535 |
1536 unsigned char simple_translate[0400]; | 1536 unsigned char simple_translate[0400]; |
1559 /* As a coding trick, an enormous stride is coded into the table for */ | 1559 /* As a coding trick, an enormous stride is coded into the table for */ |
1560 /* characters that match the last character. This allows use of only */ | 1560 /* characters that match the last character. This allows use of only */ |
1561 /* a single test, a test for having gone past the end of the */ | 1561 /* a single test, a test for having gone past the end of the */ |
1562 /* permissible match region, to test for both possible matches (when */ | 1562 /* permissible match region, to test for both possible matches (when */ |
1563 /* the stride goes past the end immediately) and failure to */ | 1563 /* the stride goes past the end immediately) and failure to */ |
1564 /* match (where you get nudged past the end one stride at a time). */ | 1564 /* match (where you get nudged past the end one stride at a time). */ |
1565 | 1565 |
1566 /* Here we make a "mickey mouse" BM table. The stride of the search */ | 1566 /* Here we make a "mickey mouse" BM table. The stride of the search */ |
1567 /* is determined only by the last character of the putative match. */ | 1567 /* is determined only by the last character of the putative match. */ |
1568 /* If that character does not match, we will stride the proper */ | 1568 /* If that character does not match, we will stride the proper */ |
1569 /* distance to propose a match that superimposes it on the last */ | 1569 /* distance to propose a match that superimposes it on the last */ |
1570 /* instance of a character that matches it (per trt), or misses */ | 1570 /* instance of a character that matches it (per trt), or misses */ |
1571 /* it entirely if there is none. */ | 1571 /* it entirely if there is none. */ |
1572 | 1572 |
1573 dirlen = len_byte * direction; | 1573 dirlen = len_byte * direction; |
1574 infinity = dirlen - (lim_byte + pos_byte + len_byte + len_byte) * direction; | 1574 infinity = dirlen - (lim_byte + pos_byte + len_byte + len_byte) * direction; |
1575 | 1575 |
1576 /* Record position after the end of the pattern. */ | 1576 /* Record position after the end of the pattern. */ |
1654 if (i == infinity) | 1654 if (i == infinity) |
1655 stride_for_teases = BM_tab[j]; | 1655 stride_for_teases = BM_tab[j]; |
1656 | 1656 |
1657 BM_tab[j] = dirlen - i; | 1657 BM_tab[j] = dirlen - i; |
1658 /* A translation table is accompanied by its inverse -- see */ | 1658 /* A translation table is accompanied by its inverse -- see */ |
1659 /* comment following downcase_table for details */ | 1659 /* comment following downcase_table for details */ |
1660 if (this_translated) | 1660 if (this_translated) |
1661 { | 1661 { |
1662 int starting_ch = ch; | 1662 int starting_ch = ch; |
1663 int starting_j = j; | 1663 int starting_j = j; |
1664 while (1) | 1664 while (1) |
1842 while (1) | 1842 while (1) |
1843 { | 1843 { |
1844 /* This loop can be coded for space rather than */ | 1844 /* This loop can be coded for space rather than */ |
1845 /* speed because it will usually run only once. */ | 1845 /* speed because it will usually run only once. */ |
1846 /* (the reach is at most len + 21, and typically */ | 1846 /* (the reach is at most len + 21, and typically */ |
1847 /* does not exceed len) */ | 1847 /* does not exceed len) */ |
1848 while ((limit - pos_byte) * direction >= 0) | 1848 while ((limit - pos_byte) * direction >= 0) |
1849 pos_byte += BM_tab[FETCH_BYTE (pos_byte)]; | 1849 pos_byte += BM_tab[FETCH_BYTE (pos_byte)]; |
1850 /* now run the same tests to distinguish going off the */ | 1850 /* now run the same tests to distinguish going off the */ |
1851 /* end, a match or a phony match. */ | 1851 /* end, a match or a phony match. */ |
1852 if ((pos_byte - limit) * direction <= len_byte) | 1852 if ((pos_byte - limit) * direction <= len_byte) |
1955 len = SCHARS (string); | 1955 len = SCHARS (string); |
1956 | 1956 |
1957 for (i = 0, i_byte = 0; i < len; ) | 1957 for (i = 0, i_byte = 0; i < len; ) |
1958 { | 1958 { |
1959 int c; | 1959 int c; |
1960 | 1960 |
1961 FETCH_STRING_CHAR_ADVANCE (c, string, i, i_byte); | 1961 FETCH_STRING_CHAR_ADVANCE (c, string, i, i_byte); |
1962 | 1962 |
1963 if (SYNTAX (c) != Sword) | 1963 if (SYNTAX (c) != Sword) |
1964 { | 1964 { |
1965 punct_count++; | 1965 punct_count++; |
1990 | 1990 |
1991 for (i = 0, i_byte = 0; i < len; ) | 1991 for (i = 0, i_byte = 0; i < len; ) |
1992 { | 1992 { |
1993 int c; | 1993 int c; |
1994 int i_byte_orig = i_byte; | 1994 int i_byte_orig = i_byte; |
1995 | 1995 |
1996 FETCH_STRING_CHAR_ADVANCE (c, string, i, i_byte); | 1996 FETCH_STRING_CHAR_ADVANCE (c, string, i, i_byte); |
1997 | 1997 |
1998 if (SYNTAX (c) == Sword) | 1998 if (SYNTAX (c) == Sword) |
1999 { | 1999 { |
2000 bcopy (SDATA (string) + i_byte_orig, o, | 2000 bcopy (SDATA (string) + i_byte_orig, o, |
2358 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte); | 2358 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte); |
2359 | 2359 |
2360 if (c == '\\') | 2360 if (c == '\\') |
2361 { | 2361 { |
2362 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte); | 2362 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte); |
2363 | 2363 |
2364 if (c == '&') | 2364 if (c == '&') |
2365 { | 2365 { |
2366 substart = search_regs.start[sub]; | 2366 substart = search_regs.start[sub]; |
2367 subend = search_regs.end[sub]; | 2367 subend = search_regs.end[sub]; |
2368 } | 2368 } |
2591 else | 2591 else |
2592 TEMP_SET_PT (opoint); | 2592 TEMP_SET_PT (opoint); |
2593 | 2593 |
2594 /* Now move point "officially" to the start of the inserted replacement. */ | 2594 /* Now move point "officially" to the start of the inserted replacement. */ |
2595 move_if_not_intangible (newpoint); | 2595 move_if_not_intangible (newpoint); |
2596 | 2596 |
2597 return Qnil; | 2597 return Qnil; |
2598 } | 2598 } |
2599 | 2599 |
2600 static Lisp_Object | 2600 static Lisp_Object |
2601 match_limit (num, beginningp) | 2601 match_limit (num, beginningp) |
2637 Zero means the entire text matched by the whole regexp or whole string. */) | 2637 Zero means the entire text matched by the whole regexp or whole string. */) |
2638 (subexp) | 2638 (subexp) |
2639 Lisp_Object subexp; | 2639 Lisp_Object subexp; |
2640 { | 2640 { |
2641 return match_limit (subexp, 0); | 2641 return match_limit (subexp, 0); |
2642 } | 2642 } |
2643 | 2643 |
2644 DEFUN ("match-data", Fmatch_data, Smatch_data, 0, 2, 0, | 2644 DEFUN ("match-data", Fmatch_data, Smatch_data, 0, 2, 0, |
2645 doc: /* Return a list containing all info on what the last search matched. | 2645 doc: /* Return a list containing all info on what the last search matched. |
2646 Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'. | 2646 Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'. |
2647 All the elements are markers or nil (nil if the Nth pair didn't match) | 2647 All the elements are markers or nil (nil if the Nth pair didn't match) |
2685 Fset_marker (data[2 * i], | 2685 Fset_marker (data[2 * i], |
2686 make_number (start), | 2686 make_number (start), |
2687 last_thing_searched); | 2687 last_thing_searched); |
2688 data[2 * i + 1] = Fmake_marker (); | 2688 data[2 * i + 1] = Fmake_marker (); |
2689 Fset_marker (data[2 * i + 1], | 2689 Fset_marker (data[2 * i + 1], |
2690 make_number (search_regs.end[i]), | 2690 make_number (search_regs.end[i]), |
2691 last_thing_searched); | 2691 last_thing_searched); |
2692 } | 2692 } |
2693 else | 2693 else |
2694 /* last_thing_searched must always be Qt, a buffer, or Qnil. */ | 2694 /* last_thing_searched must always be Qt, a buffer, or Qnil. */ |
2695 abort (); | 2695 abort (); |
2738 save_search_regs (); | 2738 save_search_regs (); |
2739 | 2739 |
2740 if (!CONSP (list) && !NILP (list)) | 2740 if (!CONSP (list) && !NILP (list)) |
2741 list = wrong_type_argument (Qconsp, list); | 2741 list = wrong_type_argument (Qconsp, list); |
2742 | 2742 |
2743 /* Unless we find a marker with a buffer in LIST, assume that this | 2743 /* Unless we find a marker with a buffer in LIST, assume that this |
2744 match data came from a string. */ | 2744 match data came from a string. */ |
2745 last_thing_searched = Qt; | 2745 last_thing_searched = Qt; |
2746 | 2746 |
2747 /* Allocate registers if they don't already exist. */ | 2747 /* Allocate registers if they don't already exist. */ |
2748 { | 2748 { |
2807 search_regs.end[i] = XINT (marker); | 2807 search_regs.end[i] = XINT (marker); |
2808 } | 2808 } |
2809 list = Fcdr (list); | 2809 list = Fcdr (list); |
2810 } | 2810 } |
2811 | 2811 |
2812 return Qnil; | 2812 return Qnil; |
2813 } | 2813 } |
2814 | 2814 |
2815 /* If non-zero the match data have been saved in saved_search_regs | 2815 /* If non-zero the match data have been saved in saved_search_regs |
2816 during the execution of a sentinel or filter. */ | 2816 during the execution of a sentinel or filter. */ |
2817 static int search_regs_saved; | 2817 static int search_regs_saved; |
2871 | 2871 |
2872 /* Now copy the data into the new string, inserting escapes. */ | 2872 /* Now copy the data into the new string, inserting escapes. */ |
2873 | 2873 |
2874 in = SDATA (string); | 2874 in = SDATA (string); |
2875 end = in + SBYTES (string); | 2875 end = in + SBYTES (string); |
2876 out = temp; | 2876 out = temp; |
2877 | 2877 |
2878 for (; in != end; in++) | 2878 for (; in != end; in++) |
2879 { | 2879 { |
2880 if (*in == '[' || *in == ']' | 2880 if (*in == '[' || *in == ']' |
2881 || *in == '*' || *in == '.' || *in == '\\' | 2881 || *in == '*' || *in == '.' || *in == '\\' |
2888 return make_specified_string (temp, | 2888 return make_specified_string (temp, |
2889 SCHARS (string) + backslashes_added, | 2889 SCHARS (string) + backslashes_added, |
2890 out - temp, | 2890 out - temp, |
2891 STRING_MULTIBYTE (string)); | 2891 STRING_MULTIBYTE (string)); |
2892 } | 2892 } |
2893 | 2893 |
2894 void | 2894 void |
2895 syms_of_search () | 2895 syms_of_search () |
2896 { | 2896 { |
2897 register int i; | 2897 register int i; |
2898 | 2898 |