diff options
| author | Roland McGrath | 1995-11-16 02:51:19 +0000 |
|---|---|---|
| committer | Roland McGrath | 1995-11-16 02:51:19 +0000 |
| commit | 5e69f11ee56686fd50a5b81ccaaf46f4bc8d4b1c (patch) | |
| tree | a5243212757a69cf958f8acfbe93772c102ef5ff /src | |
| parent | 51e8c46a3af99bc05dcbaf7267bd1434c42c192e (diff) | |
| download | emacs-5e69f11ee56686fd50a5b81ccaaf46f4bc8d4b1c.tar.gz emacs-5e69f11ee56686fd50a5b81ccaaf46f4bc8d4b1c.zip | |
(gettext_noop): New macro, identity fn.
(re_error_msgid): Mark strings with that, to ease message catalog creation.
Diffstat (limited to 'src')
| -rw-r--r-- | src/regex.c | 599 |
1 files changed, 303 insertions, 296 deletions
diff --git a/src/regex.c b/src/regex.c index 480cbbc1632..b4c124ae889 100644 --- a/src/regex.c +++ b/src/regex.c | |||
| @@ -41,6 +41,12 @@ | |||
| 41 | # define gettext(msgid) (msgid) | 41 | # define gettext(msgid) (msgid) |
| 42 | #endif | 42 | #endif |
| 43 | 43 | ||
| 44 | #ifndef gettext_noop | ||
| 45 | /* This define is so xgettext can find the internationalizable | ||
| 46 | strings. */ | ||
| 47 | #define gettext_noop(String) String | ||
| 48 | #endif | ||
| 49 | |||
| 44 | /* The `emacs' switch turns on certain matching commands | 50 | /* The `emacs' switch turns on certain matching commands |
| 45 | that make sense only in Emacs. */ | 51 | that make sense only in Emacs. */ |
| 46 | #ifdef emacs | 52 | #ifdef emacs |
| @@ -97,7 +103,7 @@ char *realloc (); | |||
| 97 | 103 | ||
| 98 | /* This must be nonzero for the wordchar and notwordchar pattern | 104 | /* This must be nonzero for the wordchar and notwordchar pattern |
| 99 | commands in re_match_2. */ | 105 | commands in re_match_2. */ |
| 100 | #ifndef Sword | 106 | #ifndef Sword |
| 101 | #define Sword 1 | 107 | #define Sword 1 |
| 102 | #endif | 108 | #endif |
| 103 | 109 | ||
| @@ -214,8 +220,8 @@ init_syntax_once () | |||
| 214 | use `alloca' instead of `malloc'. This is because using malloc in | 220 | use `alloca' instead of `malloc'. This is because using malloc in |
| 215 | re_search* or re_match* could cause memory leaks when C-g is used in | 221 | re_search* or re_match* could cause memory leaks when C-g is used in |
| 216 | Emacs; also, malloc is slower and causes storage fragmentation. On | 222 | Emacs; also, malloc is slower and causes storage fragmentation. On |
| 217 | the other hand, malloc is more portable, and easier to debug. | 223 | the other hand, malloc is more portable, and easier to debug. |
| 218 | 224 | ||
| 219 | Because we sometimes use alloca, some routines have to be macros, | 225 | Because we sometimes use alloca, some routines have to be macros, |
| 220 | not functions -- `alloca'-allocated space disappears at the end of the | 226 | not functions -- `alloca'-allocated space disappears at the end of the |
| 221 | function it is called in. */ | 227 | function it is called in. */ |
| @@ -243,7 +249,7 @@ init_syntax_once () | |||
| 243 | char *alloca (); | 249 | char *alloca (); |
| 244 | #endif /* not _AIX */ | 250 | #endif /* not _AIX */ |
| 245 | #endif | 251 | #endif |
| 246 | #endif /* not HAVE_ALLOCA_H */ | 252 | #endif /* not HAVE_ALLOCA_H */ |
| 247 | #endif /* not __GNUC__ */ | 253 | #endif /* not __GNUC__ */ |
| 248 | 254 | ||
| 249 | #endif /* not alloca */ | 255 | #endif /* not alloca */ |
| @@ -385,9 +391,9 @@ typedef enum | |||
| 385 | 391 | ||
| 386 | /* Analogously, for end of buffer/string. */ | 392 | /* Analogously, for end of buffer/string. */ |
| 387 | endbuf, | 393 | endbuf, |
| 388 | 394 | ||
| 389 | /* Followed by two byte relative address to which to jump. */ | 395 | /* Followed by two byte relative address to which to jump. */ |
| 390 | jump, | 396 | jump, |
| 391 | 397 | ||
| 392 | /* Same as jump, but marks the end of an alternative. */ | 398 | /* Same as jump, but marks the end of an alternative. */ |
| 393 | jump_past_alt, | 399 | jump_past_alt, |
| @@ -395,11 +401,11 @@ typedef enum | |||
| 395 | /* Followed by two-byte relative address of place to resume at | 401 | /* Followed by two-byte relative address of place to resume at |
| 396 | in case of failure. */ | 402 | in case of failure. */ |
| 397 | on_failure_jump, | 403 | on_failure_jump, |
| 398 | 404 | ||
| 399 | /* Like on_failure_jump, but pushes a placeholder instead of the | 405 | /* Like on_failure_jump, but pushes a placeholder instead of the |
| 400 | current string position when executed. */ | 406 | current string position when executed. */ |
| 401 | on_failure_keep_string_jump, | 407 | on_failure_keep_string_jump, |
| 402 | 408 | ||
| 403 | /* Throw away latest failure point and then jump to following | 409 | /* Throw away latest failure point and then jump to following |
| 404 | two-byte relative address. */ | 410 | two-byte relative address. */ |
| 405 | pop_failure_jump, | 411 | pop_failure_jump, |
| @@ -495,7 +501,7 @@ extract_number (dest, source) | |||
| 495 | int *dest; | 501 | int *dest; |
| 496 | unsigned char *source; | 502 | unsigned char *source; |
| 497 | { | 503 | { |
| 498 | int temp = SIGN_EXTEND_CHAR (*(source + 1)); | 504 | int temp = SIGN_EXTEND_CHAR (*(source + 1)); |
| 499 | *dest = *source & 0377; | 505 | *dest = *source & 0377; |
| 500 | *dest += temp << 8; | 506 | *dest += temp << 8; |
| 501 | } | 507 | } |
| @@ -521,7 +527,7 @@ static void | |||
| 521 | extract_number_and_incr (destination, source) | 527 | extract_number_and_incr (destination, source) |
| 522 | int *destination; | 528 | int *destination; |
| 523 | unsigned char **source; | 529 | unsigned char **source; |
| 524 | { | 530 | { |
| 525 | extract_number (destination, *source); | 531 | extract_number (destination, *source); |
| 526 | *source += 2; | 532 | *source += 2; |
| 527 | } | 533 | } |
| @@ -568,8 +574,8 @@ print_fastmap (fastmap) | |||
| 568 | char *fastmap; | 574 | char *fastmap; |
| 569 | { | 575 | { |
| 570 | unsigned was_a_range = 0; | 576 | unsigned was_a_range = 0; |
| 571 | unsigned i = 0; | 577 | unsigned i = 0; |
| 572 | 578 | ||
| 573 | while (i < (1 << BYTEWIDTH)) | 579 | while (i < (1 << BYTEWIDTH)) |
| 574 | { | 580 | { |
| 575 | if (fastmap[i++]) | 581 | if (fastmap[i++]) |
| @@ -588,7 +594,7 @@ print_fastmap (fastmap) | |||
| 588 | } | 594 | } |
| 589 | } | 595 | } |
| 590 | } | 596 | } |
| 591 | putchar ('\n'); | 597 | putchar ('\n'); |
| 592 | } | 598 | } |
| 593 | 599 | ||
| 594 | 600 | ||
| @@ -609,7 +615,7 @@ print_partial_compiled_pattern (start, end) | |||
| 609 | printf ("(null)\n"); | 615 | printf ("(null)\n"); |
| 610 | return; | 616 | return; |
| 611 | } | 617 | } |
| 612 | 618 | ||
| 613 | /* Loop over pattern commands. */ | 619 | /* Loop over pattern commands. */ |
| 614 | while (p < pend) | 620 | while (p < pend) |
| 615 | { | 621 | { |
| @@ -658,7 +664,7 @@ print_partial_compiled_pattern (start, end) | |||
| 658 | 664 | ||
| 659 | printf ("/charset [%s", | 665 | printf ("/charset [%s", |
| 660 | (re_opcode_t) *(p - 1) == charset_not ? "^" : ""); | 666 | (re_opcode_t) *(p - 1) == charset_not ? "^" : ""); |
| 661 | 667 | ||
| 662 | assert (p + *p < pend); | 668 | assert (p + *p < pend); |
| 663 | 669 | ||
| 664 | for (c = 0; c < 256; c++) | 670 | for (c = 0; c < 256; c++) |
| @@ -677,7 +683,7 @@ print_partial_compiled_pattern (start, end) | |||
| 677 | putchar (last); | 683 | putchar (last); |
| 678 | in_range = 0; | 684 | in_range = 0; |
| 679 | } | 685 | } |
| 680 | 686 | ||
| 681 | if (! in_range) | 687 | if (! in_range) |
| 682 | putchar (c); | 688 | putchar (c); |
| 683 | 689 | ||
| @@ -719,7 +725,7 @@ print_partial_compiled_pattern (start, end) | |||
| 719 | case push_dummy_failure: | 725 | case push_dummy_failure: |
| 720 | printf ("/push_dummy_failure"); | 726 | printf ("/push_dummy_failure"); |
| 721 | break; | 727 | break; |
| 722 | 728 | ||
| 723 | case maybe_pop_jump: | 729 | case maybe_pop_jump: |
| 724 | extract_number_and_incr (&mcnt, &p); | 730 | extract_number_and_incr (&mcnt, &p); |
| 725 | printf ("/maybe_pop_jump to %d", p + mcnt - start); | 731 | printf ("/maybe_pop_jump to %d", p + mcnt - start); |
| @@ -728,36 +734,36 @@ print_partial_compiled_pattern (start, end) | |||
| 728 | case pop_failure_jump: | 734 | case pop_failure_jump: |
| 729 | extract_number_and_incr (&mcnt, &p); | 735 | extract_number_and_incr (&mcnt, &p); |
| 730 | printf ("/pop_failure_jump to %d", p + mcnt - start); | 736 | printf ("/pop_failure_jump to %d", p + mcnt - start); |
| 731 | break; | 737 | break; |
| 732 | 738 | ||
| 733 | case jump_past_alt: | 739 | case jump_past_alt: |
| 734 | extract_number_and_incr (&mcnt, &p); | 740 | extract_number_and_incr (&mcnt, &p); |
| 735 | printf ("/jump_past_alt to %d", p + mcnt - start); | 741 | printf ("/jump_past_alt to %d", p + mcnt - start); |
| 736 | break; | 742 | break; |
| 737 | 743 | ||
| 738 | case jump: | 744 | case jump: |
| 739 | extract_number_and_incr (&mcnt, &p); | 745 | extract_number_and_incr (&mcnt, &p); |
| 740 | printf ("/jump to %d", p + mcnt - start); | 746 | printf ("/jump to %d", p + mcnt - start); |
| 741 | break; | 747 | break; |
| 742 | 748 | ||
| 743 | case succeed_n: | 749 | case succeed_n: |
| 744 | extract_number_and_incr (&mcnt, &p); | 750 | extract_number_and_incr (&mcnt, &p); |
| 745 | extract_number_and_incr (&mcnt2, &p); | 751 | extract_number_and_incr (&mcnt2, &p); |
| 746 | printf ("/succeed_n to %d, %d times", p + mcnt - start, mcnt2); | 752 | printf ("/succeed_n to %d, %d times", p + mcnt - start, mcnt2); |
| 747 | break; | 753 | break; |
| 748 | 754 | ||
| 749 | case jump_n: | 755 | case jump_n: |
| 750 | extract_number_and_incr (&mcnt, &p); | 756 | extract_number_and_incr (&mcnt, &p); |
| 751 | extract_number_and_incr (&mcnt2, &p); | 757 | extract_number_and_incr (&mcnt2, &p); |
| 752 | printf ("/jump_n to %d, %d times", p + mcnt - start, mcnt2); | 758 | printf ("/jump_n to %d, %d times", p + mcnt - start, mcnt2); |
| 753 | break; | 759 | break; |
| 754 | 760 | ||
| 755 | case set_number_at: | 761 | case set_number_at: |
| 756 | extract_number_and_incr (&mcnt, &p); | 762 | extract_number_and_incr (&mcnt, &p); |
| 757 | extract_number_and_incr (&mcnt2, &p); | 763 | extract_number_and_incr (&mcnt2, &p); |
| 758 | printf ("/set_number_at location %d to %d", p + mcnt - start, mcnt2); | 764 | printf ("/set_number_at location %d to %d", p + mcnt - start, mcnt2); |
| 759 | break; | 765 | break; |
| 760 | 766 | ||
| 761 | case wordbound: | 767 | case wordbound: |
| 762 | printf ("/wordbound"); | 768 | printf ("/wordbound"); |
| 763 | break; | 769 | break; |
| @@ -769,10 +775,10 @@ print_partial_compiled_pattern (start, end) | |||
| 769 | case wordbeg: | 775 | case wordbeg: |
| 770 | printf ("/wordbeg"); | 776 | printf ("/wordbeg"); |
| 771 | break; | 777 | break; |
| 772 | 778 | ||
| 773 | case wordend: | 779 | case wordend: |
| 774 | printf ("/wordend"); | 780 | printf ("/wordend"); |
| 775 | 781 | ||
| 776 | #ifdef emacs | 782 | #ifdef emacs |
| 777 | case before_dot: | 783 | case before_dot: |
| 778 | printf ("/before_dot"); | 784 | printf ("/before_dot"); |
| @@ -791,7 +797,7 @@ print_partial_compiled_pattern (start, end) | |||
| 791 | mcnt = *p++; | 797 | mcnt = *p++; |
| 792 | printf ("/%d", mcnt); | 798 | printf ("/%d", mcnt); |
| 793 | break; | 799 | break; |
| 794 | 800 | ||
| 795 | case notsyntaxspec: | 801 | case notsyntaxspec: |
| 796 | printf ("/notsyntaxspec"); | 802 | printf ("/notsyntaxspec"); |
| 797 | mcnt = *p++; | 803 | mcnt = *p++; |
| @@ -802,7 +808,7 @@ print_partial_compiled_pattern (start, end) | |||
| 802 | case wordchar: | 808 | case wordchar: |
| 803 | printf ("/wordchar"); | 809 | printf ("/wordchar"); |
| 804 | break; | 810 | break; |
| 805 | 811 | ||
| 806 | case notwordchar: | 812 | case notwordchar: |
| 807 | printf ("/notwordchar"); | 813 | printf ("/notwordchar"); |
| 808 | break; | 814 | break; |
| @@ -862,7 +868,7 @@ print_double_string (where, string1, size1, string2, size2) | |||
| 862 | int size2; | 868 | int size2; |
| 863 | { | 869 | { |
| 864 | unsigned this_char; | 870 | unsigned this_char; |
| 865 | 871 | ||
| 866 | if (where == NULL) | 872 | if (where == NULL) |
| 867 | printf ("(null)"); | 873 | printf ("(null)"); |
| 868 | else | 874 | else |
| @@ -872,7 +878,7 @@ print_double_string (where, string1, size1, string2, size2) | |||
| 872 | for (this_char = where - string1; this_char < size1; this_char++) | 878 | for (this_char = where - string1; this_char < size1; this_char++) |
| 873 | putchar (string1[this_char]); | 879 | putchar (string1[this_char]); |
| 874 | 880 | ||
| 875 | where = string2; | 881 | where = string2; |
| 876 | } | 882 | } |
| 877 | 883 | ||
| 878 | for (this_char = where - string2; this_char < size2; this_char++) | 884 | for (this_char = where - string2; this_char < size2; this_char++) |
| @@ -915,7 +921,7 @@ re_set_syntax (syntax) | |||
| 915 | reg_syntax_t syntax; | 921 | reg_syntax_t syntax; |
| 916 | { | 922 | { |
| 917 | reg_syntax_t ret = re_syntax_options; | 923 | reg_syntax_t ret = re_syntax_options; |
| 918 | 924 | ||
| 919 | re_syntax_options = syntax; | 925 | re_syntax_options = syntax; |
| 920 | return ret; | 926 | return ret; |
| 921 | } | 927 | } |
| @@ -926,23 +932,24 @@ re_set_syntax (syntax) | |||
| 926 | but why not be nice? */ | 932 | but why not be nice? */ |
| 927 | 933 | ||
| 928 | static const char *re_error_msgid[] = | 934 | static const char *re_error_msgid[] = |
| 929 | { "Success", /* REG_NOERROR */ | 935 | { |
| 930 | "No match", /* REG_NOMATCH */ | 936 | gettext_noop ("Success"), /* REG_NOERROR */ |
| 931 | "Invalid regular expression", /* REG_BADPAT */ | 937 | gettext_noop ("No match"), /* REG_NOMATCH */ |
| 932 | "Invalid collation character", /* REG_ECOLLATE */ | 938 | gettext_noop ("Invalid regular expression"), /* REG_BADPAT */ |
| 933 | "Invalid character class name", /* REG_ECTYPE */ | 939 | gettext_noop ("Invalid collation character"), /* REG_ECOLLATE */ |
| 934 | "Trailing backslash", /* REG_EESCAPE */ | 940 | gettext_noop ("Invalid character class name"), /* REG_ECTYPE */ |
| 935 | "Invalid back reference", /* REG_ESUBREG */ | 941 | gettext_noop ("Trailing backslash"), /* REG_EESCAPE */ |
| 936 | "Unmatched [ or [^", /* REG_EBRACK */ | 942 | gettext_noop ("Invalid back reference"), /* REG_ESUBREG */ |
| 937 | "Unmatched ( or \\(", /* REG_EPAREN */ | 943 | gettext_noop ("Unmatched [ or [^"), /* REG_EBRACK */ |
| 938 | "Unmatched \\{", /* REG_EBRACE */ | 944 | gettext_noop ("Unmatched ( or \\("), /* REG_EPAREN */ |
| 939 | "Invalid content of \\{\\}", /* REG_BADBR */ | 945 | gettext_noop ("Unmatched \\{"), /* REG_EBRACE */ |
| 940 | "Invalid range end", /* REG_ERANGE */ | 946 | gettext_noop ("Invalid content of \\{\\}"), /* REG_BADBR */ |
| 941 | "Memory exhausted", /* REG_ESPACE */ | 947 | gettext_noop ("Invalid range end"), /* REG_ERANGE */ |
| 942 | "Invalid preceding regular expression", /* REG_BADRPT */ | 948 | gettext_noop ("Memory exhausted"), /* REG_ESPACE */ |
| 943 | "Premature end of regular expression", /* REG_EEND */ | 949 | gettext_noop ("Invalid preceding regular expression"), /* REG_BADRPT */ |
| 944 | "Regular expression too big", /* REG_ESIZE */ | 950 | gettext_noop ("Premature end of regular expression"), /* REG_EEND */ |
| 945 | "Unmatched ) or \\)", /* REG_ERPAREN */ | 951 | gettext_noop ("Regular expression too big"), /* REG_ESIZE */ |
| 952 | gettext_noop ("Unmatched ) or \\)"), /* REG_ERPAREN */ | ||
| 946 | }; | 953 | }; |
| 947 | 954 | ||
| 948 | /* Avoiding alloca during matching, to placate r_alloc. */ | 955 | /* Avoiding alloca during matching, to placate r_alloc. */ |
| @@ -955,7 +962,7 @@ static const char *re_error_msgid[] = | |||
| 955 | ralloc heap) shift the data out from underneath the regexp | 962 | ralloc heap) shift the data out from underneath the regexp |
| 956 | routines. | 963 | routines. |
| 957 | 964 | ||
| 958 | Here's another reason to avoid allocation: Emacs | 965 | Here's another reason to avoid allocation: Emacs |
| 959 | processes input from X in a signal handler; processing X input may | 966 | processes input from X in a signal handler; processing X input may |
| 960 | call malloc; if input arrives while a matching routine is calling | 967 | call malloc; if input arrives while a matching routine is calling |
| 961 | malloc, then we're scrod. But Emacs can't just block input while | 968 | malloc, then we're scrod. But Emacs can't just block input while |
| @@ -986,7 +993,7 @@ static const char *re_error_msgid[] = | |||
| 986 | /* Failure stack declarations and macros; both re_compile_fastmap and | 993 | /* Failure stack declarations and macros; both re_compile_fastmap and |
| 987 | re_match_2 use a failure stack. These have to be macros because of | 994 | re_match_2 use a failure stack. These have to be macros because of |
| 988 | REGEX_ALLOCATE_STACK. */ | 995 | REGEX_ALLOCATE_STACK. */ |
| 989 | 996 | ||
| 990 | 997 | ||
| 991 | /* Number of failure points for which to initially allocate space | 998 | /* Number of failure points for which to initially allocate space |
| 992 | when matching. If this number is exceeded, we allocate more | 999 | when matching. If this number is exceeded, we allocate more |
| @@ -1055,8 +1062,8 @@ typedef struct | |||
| 1055 | /* Double the size of FAIL_STACK, up to approximately `re_max_failures' items. | 1062 | /* Double the size of FAIL_STACK, up to approximately `re_max_failures' items. |
| 1056 | 1063 | ||
| 1057 | Return 1 if succeeds, and 0 if either ran out of memory | 1064 | Return 1 if succeeds, and 0 if either ran out of memory |
| 1058 | allocating space for it or it was already too large. | 1065 | allocating space for it or it was already too large. |
| 1059 | 1066 | ||
| 1060 | REGEX_REALLOCATE_STACK requires `destination' be declared. */ | 1067 | REGEX_REALLOCATE_STACK requires `destination' be declared. */ |
| 1061 | 1068 | ||
| 1062 | #define DOUBLE_FAIL_STACK(fail_stack) \ | 1069 | #define DOUBLE_FAIL_STACK(fail_stack) \ |
| @@ -1073,7 +1080,7 @@ typedef struct | |||
| 1073 | 1))) | 1080 | 1))) |
| 1074 | 1081 | ||
| 1075 | 1082 | ||
| 1076 | /* Push pointer POINTER on FAIL_STACK. | 1083 | /* Push pointer POINTER on FAIL_STACK. |
| 1077 | Return 1 if was able to do so and 0 if ran out of memory allocating | 1084 | Return 1 if was able to do so and 0 if ran out of memory allocating |
| 1078 | space to do so. */ | 1085 | space to do so. */ |
| 1079 | #define PUSH_PATTERN_OP(POINTER, FAIL_STACK) \ | 1086 | #define PUSH_PATTERN_OP(POINTER, FAIL_STACK) \ |
| @@ -1118,12 +1125,12 @@ typedef struct | |||
| 1118 | 1125 | ||
| 1119 | 1126 | ||
| 1120 | /* Push the information about the state we will need | 1127 | /* Push the information about the state we will need |
| 1121 | if we ever fail back to it. | 1128 | if we ever fail back to it. |
| 1122 | 1129 | ||
| 1123 | Requires variables fail_stack, regstart, regend, reg_info, and | 1130 | Requires variables fail_stack, regstart, regend, reg_info, and |
| 1124 | num_regs be declared. DOUBLE_FAIL_STACK requires `destination' be | 1131 | num_regs be declared. DOUBLE_FAIL_STACK requires `destination' be |
| 1125 | declared. | 1132 | declared. |
| 1126 | 1133 | ||
| 1127 | Does `return FAILURE_CODE' if runs out of memory. */ | 1134 | Does `return FAILURE_CODE' if runs out of memory. */ |
| 1128 | 1135 | ||
| 1129 | #define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code) \ | 1136 | #define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code) \ |
| @@ -1234,7 +1241,7 @@ typedef struct | |||
| 1234 | LOW_REG, HIGH_REG -- the highest and lowest active registers. | 1241 | LOW_REG, HIGH_REG -- the highest and lowest active registers. |
| 1235 | REGSTART, REGEND -- arrays of string positions. | 1242 | REGSTART, REGEND -- arrays of string positions. |
| 1236 | REG_INFO -- array of information about each subexpression. | 1243 | REG_INFO -- array of information about each subexpression. |
| 1237 | 1244 | ||
| 1238 | Also assumes the variables `fail_stack' and (if debugging), `bufp', | 1245 | Also assumes the variables `fail_stack' and (if debugging), `bufp', |
| 1239 | `pend', `string1', `size1', `string2', and `size2'. */ | 1246 | `pend', `string1', `size1', `string2', and `size2'. */ |
| 1240 | 1247 | ||
| @@ -1313,8 +1320,8 @@ typedef struct | |||
| 1313 | Other register information, such as the | 1320 | Other register information, such as the |
| 1314 | starting and ending positions (which are addresses), and the list of | 1321 | starting and ending positions (which are addresses), and the list of |
| 1315 | inner groups (which is a bits list) are maintained in separate | 1322 | inner groups (which is a bits list) are maintained in separate |
| 1316 | variables. | 1323 | variables. |
| 1317 | 1324 | ||
| 1318 | We are making a (strictly speaking) nonportable assumption here: that | 1325 | We are making a (strictly speaking) nonportable assumption here: that |
| 1319 | the compiler will pack our bit fields into something that fits into | 1326 | the compiler will pack our bit fields into something that fits into |
| 1320 | the type of `word', i.e., is something that fits into one item on the | 1327 | the type of `word', i.e., is something that fits into one item on the |
| @@ -1374,7 +1381,7 @@ static boolean at_begline_loc_p (), at_endline_loc_p (); | |||
| 1374 | static boolean group_in_compile_stack (); | 1381 | static boolean group_in_compile_stack (); |
| 1375 | static reg_errcode_t compile_range (); | 1382 | static reg_errcode_t compile_range (); |
| 1376 | 1383 | ||
| 1377 | /* Fetch the next character in the uncompiled pattern---translating it | 1384 | /* Fetch the next character in the uncompiled pattern---translating it |
| 1378 | if necessary. Also cast from a signed character in the constant | 1385 | if necessary. Also cast from a signed character in the constant |
| 1379 | string passed to us by the user to an unsigned char that we can use | 1386 | string passed to us by the user to an unsigned char that we can use |
| 1380 | as an array index (in, e.g., `translate'). */ | 1387 | as an array index (in, e.g., `translate'). */ |
| @@ -1519,7 +1526,7 @@ typedef struct | |||
| 1519 | pattern_offset_t begalt_offset; | 1526 | pattern_offset_t begalt_offset; |
| 1520 | pattern_offset_t fixup_alt_jump; | 1527 | pattern_offset_t fixup_alt_jump; |
| 1521 | pattern_offset_t inner_group_offset; | 1528 | pattern_offset_t inner_group_offset; |
| 1522 | pattern_offset_t laststart_offset; | 1529 | pattern_offset_t laststart_offset; |
| 1523 | regnum_t regnum; | 1530 | regnum_t regnum; |
| 1524 | } compile_stack_elt_t; | 1531 | } compile_stack_elt_t; |
| 1525 | 1532 | ||
| @@ -1562,7 +1569,7 @@ typedef struct | |||
| 1562 | PATFETCH (c); \ | 1569 | PATFETCH (c); \ |
| 1563 | } \ | 1570 | } \ |
| 1564 | } \ | 1571 | } \ |
| 1565 | } | 1572 | } |
| 1566 | 1573 | ||
| 1567 | #define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */ | 1574 | #define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */ |
| 1568 | 1575 | ||
| @@ -1593,7 +1600,7 @@ static int regs_allocated_size; | |||
| 1593 | static const char ** regstart, ** regend; | 1600 | static const char ** regstart, ** regend; |
| 1594 | static const char ** old_regstart, ** old_regend; | 1601 | static const char ** old_regstart, ** old_regend; |
| 1595 | static const char **best_regstart, **best_regend; | 1602 | static const char **best_regstart, **best_regend; |
| 1596 | static register_info_type *reg_info; | 1603 | static register_info_type *reg_info; |
| 1597 | static const char **reg_dummy; | 1604 | static const char **reg_dummy; |
| 1598 | static register_info_type *reg_info_dummy; | 1605 | static register_info_type *reg_info_dummy; |
| 1599 | 1606 | ||
| @@ -1636,7 +1643,7 @@ regex_grow_registers (num_regs) | |||
| 1636 | `fastmap_accurate' is zero; | 1643 | `fastmap_accurate' is zero; |
| 1637 | `re_nsub' is the number of subexpressions in PATTERN; | 1644 | `re_nsub' is the number of subexpressions in PATTERN; |
| 1638 | `not_bol' and `not_eol' are zero; | 1645 | `not_bol' and `not_eol' are zero; |
| 1639 | 1646 | ||
| 1640 | The `fastmap' and `newline_anchor' fields are neither | 1647 | The `fastmap' and `newline_anchor' fields are neither |
| 1641 | examined nor set. */ | 1648 | examined nor set. */ |
| 1642 | 1649 | ||
| @@ -1655,20 +1662,20 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 1655 | `char *' (i.e., signed), we declare these variables as unsigned, so | 1662 | `char *' (i.e., signed), we declare these variables as unsigned, so |
| 1656 | they can be reliably used as array indices. */ | 1663 | they can be reliably used as array indices. */ |
| 1657 | register unsigned char c, c1; | 1664 | register unsigned char c, c1; |
| 1658 | 1665 | ||
| 1659 | /* A random temporary spot in PATTERN. */ | 1666 | /* A random temporary spot in PATTERN. */ |
| 1660 | const char *p1; | 1667 | const char *p1; |
| 1661 | 1668 | ||
| 1662 | /* Points to the end of the buffer, where we should append. */ | 1669 | /* Points to the end of the buffer, where we should append. */ |
| 1663 | register unsigned char *b; | 1670 | register unsigned char *b; |
| 1664 | 1671 | ||
| 1665 | /* Keeps track of unclosed groups. */ | 1672 | /* Keeps track of unclosed groups. */ |
| 1666 | compile_stack_type compile_stack; | 1673 | compile_stack_type compile_stack; |
| 1667 | 1674 | ||
| 1668 | /* Points to the current (ending) position in the pattern. */ | 1675 | /* Points to the current (ending) position in the pattern. */ |
| 1669 | const char *p = pattern; | 1676 | const char *p = pattern; |
| 1670 | const char *pend = pattern + size; | 1677 | const char *pend = pattern + size; |
| 1671 | 1678 | ||
| 1672 | /* How to translate the characters in the pattern. */ | 1679 | /* How to translate the characters in the pattern. */ |
| 1673 | RE_TRANSLATE_TYPE translate = bufp->translate; | 1680 | RE_TRANSLATE_TYPE translate = bufp->translate; |
| 1674 | 1681 | ||
| @@ -1689,7 +1696,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 1689 | /* Place in the uncompiled pattern (i.e., the {) to | 1696 | /* Place in the uncompiled pattern (i.e., the {) to |
| 1690 | which to go back if the interval is invalid. */ | 1697 | which to go back if the interval is invalid. */ |
| 1691 | const char *beg_interval; | 1698 | const char *beg_interval; |
| 1692 | 1699 | ||
| 1693 | /* Address of the place where a forward jump should go to the end of | 1700 | /* Address of the place where a forward jump should go to the end of |
| 1694 | the containing expression. Each alternative of an `or' -- except the | 1701 | the containing expression. Each alternative of an `or' -- except the |
| 1695 | last -- ends with a forward jump of this sort. */ | 1702 | last -- ends with a forward jump of this sort. */ |
| @@ -1705,7 +1712,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 1705 | if (debug) | 1712 | if (debug) |
| 1706 | { | 1713 | { |
| 1707 | unsigned debug_count; | 1714 | unsigned debug_count; |
| 1708 | 1715 | ||
| 1709 | for (debug_count = 0; debug_count < size; debug_count++) | 1716 | for (debug_count = 0; debug_count < size; debug_count++) |
| 1710 | putchar (pattern[debug_count]); | 1717 | putchar (pattern[debug_count]); |
| 1711 | putchar ('\n'); | 1718 | putchar ('\n'); |
| @@ -1729,9 +1736,9 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 1729 | printer (for debugging) will think there's no pattern. We reset it | 1736 | printer (for debugging) will think there's no pattern. We reset it |
| 1730 | at the end. */ | 1737 | at the end. */ |
| 1731 | bufp->used = 0; | 1738 | bufp->used = 0; |
| 1732 | 1739 | ||
| 1733 | /* Always count groups, whether or not bufp->no_sub is set. */ | 1740 | /* Always count groups, whether or not bufp->no_sub is set. */ |
| 1734 | bufp->re_nsub = 0; | 1741 | bufp->re_nsub = 0; |
| 1735 | 1742 | ||
| 1736 | #if !defined (emacs) && !defined (SYNTAX_TABLE) | 1743 | #if !defined (emacs) && !defined (SYNTAX_TABLE) |
| 1737 | /* Initialize the syntax table. */ | 1744 | /* Initialize the syntax table. */ |
| @@ -1782,7 +1789,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 1782 | case '$': | 1789 | case '$': |
| 1783 | { | 1790 | { |
| 1784 | if ( /* If at end of pattern, it's an operator. */ | 1791 | if ( /* If at end of pattern, it's an operator. */ |
| 1785 | p == pend | 1792 | p == pend |
| 1786 | /* If context independent, it's an operator. */ | 1793 | /* If context independent, it's an operator. */ |
| 1787 | || syntax & RE_CONTEXT_INDEP_ANCHORS | 1794 | || syntax & RE_CONTEXT_INDEP_ANCHORS |
| 1788 | /* Otherwise, depends on what's next. */ | 1795 | /* Otherwise, depends on what's next. */ |
| @@ -1813,7 +1820,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 1813 | { | 1820 | { |
| 1814 | /* Are we optimizing this jump? */ | 1821 | /* Are we optimizing this jump? */ |
| 1815 | boolean keep_string_p = false; | 1822 | boolean keep_string_p = false; |
| 1816 | 1823 | ||
| 1817 | /* 1 means zero (many) matches is allowed. */ | 1824 | /* 1 means zero (many) matches is allowed. */ |
| 1818 | char zero_times_ok = 0, many_times_ok = 0; | 1825 | char zero_times_ok = 0, many_times_ok = 0; |
| 1819 | 1826 | ||
| @@ -1861,7 +1868,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 1861 | 1868 | ||
| 1862 | /* Star, etc. applied to an empty pattern is equivalent | 1869 | /* Star, etc. applied to an empty pattern is equivalent |
| 1863 | to an empty pattern. */ | 1870 | to an empty pattern. */ |
| 1864 | if (!laststart) | 1871 | if (!laststart) |
| 1865 | break; | 1872 | break; |
| 1866 | 1873 | ||
| 1867 | /* Now we know whether or not zero matches is allowed | 1874 | /* Now we know whether or not zero matches is allowed |
| @@ -1870,7 +1877,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 1870 | { /* More than one repetition is allowed, so put in at the | 1877 | { /* More than one repetition is allowed, so put in at the |
| 1871 | end a backward relative jump from `b' to before the next | 1878 | end a backward relative jump from `b' to before the next |
| 1872 | jump we're going to put in below (which jumps from | 1879 | jump we're going to put in below (which jumps from |
| 1873 | laststart to after this jump). | 1880 | laststart to after this jump). |
| 1874 | 1881 | ||
| 1875 | But if we are at the `*' in the exact sequence `.*\n', | 1882 | But if we are at the `*' in the exact sequence `.*\n', |
| 1876 | insert an unconditional jump backwards to the ., | 1883 | insert an unconditional jump backwards to the ., |
| @@ -1947,7 +1954,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 1947 | 1954 | ||
| 1948 | /* We test `*p == '^' twice, instead of using an if | 1955 | /* We test `*p == '^' twice, instead of using an if |
| 1949 | statement, so we only need one BUF_PUSH. */ | 1956 | statement, so we only need one BUF_PUSH. */ |
| 1950 | BUF_PUSH (*p == '^' ? charset_not : charset); | 1957 | BUF_PUSH (*p == '^' ? charset_not : charset); |
| 1951 | if (*p == '^') | 1958 | if (*p == '^') |
| 1952 | p++; | 1959 | p++; |
| 1953 | 1960 | ||
| @@ -1997,8 +2004,8 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 1997 | was a character: if this is a hyphen not at the | 2004 | was a character: if this is a hyphen not at the |
| 1998 | beginning or the end of a list, then it's the range | 2005 | beginning or the end of a list, then it's the range |
| 1999 | operator. */ | 2006 | operator. */ |
| 2000 | if (c == '-' | 2007 | if (c == '-' |
| 2001 | && !(p - 2 >= pattern && p[-2] == '[') | 2008 | && !(p - 2 >= pattern && p[-2] == '[') |
| 2002 | && !(p - 3 >= pattern && p[-3] == '[' && p[-2] == '^') | 2009 | && !(p - 3 >= pattern && p[-3] == '[' && p[-2] == '^') |
| 2003 | && *p != ']') | 2010 | && *p != ']') |
| 2004 | { | 2011 | { |
| @@ -2013,7 +2020,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2013 | 2020 | ||
| 2014 | /* Move past the `-'. */ | 2021 | /* Move past the `-'. */ |
| 2015 | PATFETCH (c1); | 2022 | PATFETCH (c1); |
| 2016 | 2023 | ||
| 2017 | ret = compile_range (&p, pend, translate, syntax, b); | 2024 | ret = compile_range (&p, pend, translate, syntax, b); |
| 2018 | if (ret != REG_NOERROR) FREE_STACK_RETURN (ret); | 2025 | if (ret != REG_NOERROR) FREE_STACK_RETURN (ret); |
| 2019 | } | 2026 | } |
| @@ -2042,7 +2049,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2042 | str[c1] = '\0'; | 2049 | str[c1] = '\0'; |
| 2043 | 2050 | ||
| 2044 | /* If isn't a word bracketed by `[:' and:`]': | 2051 | /* If isn't a word bracketed by `[:' and:`]': |
| 2045 | undo the ending character, the letters, and leave | 2052 | undo the ending character, the letters, and leave |
| 2046 | the leading `:' and `[' (but set bits for them). */ | 2053 | the leading `:' and `[' (but set bits for them). */ |
| 2047 | if (c == ':' && *p == ']') | 2054 | if (c == ':' && *p == ']') |
| 2048 | { | 2055 | { |
| @@ -2059,13 +2066,13 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2059 | boolean is_space = STREQ (str, "space"); | 2066 | boolean is_space = STREQ (str, "space"); |
| 2060 | boolean is_upper = STREQ (str, "upper"); | 2067 | boolean is_upper = STREQ (str, "upper"); |
| 2061 | boolean is_xdigit = STREQ (str, "xdigit"); | 2068 | boolean is_xdigit = STREQ (str, "xdigit"); |
| 2062 | 2069 | ||
| 2063 | if (!IS_CHAR_CLASS (str)) | 2070 | if (!IS_CHAR_CLASS (str)) |
| 2064 | FREE_STACK_RETURN (REG_ECTYPE); | 2071 | FREE_STACK_RETURN (REG_ECTYPE); |
| 2065 | 2072 | ||
| 2066 | /* Throw away the ] at the end of the character | 2073 | /* Throw away the ] at the end of the character |
| 2067 | class. */ | 2074 | class. */ |
| 2068 | PATFETCH (c); | 2075 | PATFETCH (c); |
| 2069 | 2076 | ||
| 2070 | if (p == pend) FREE_STACK_RETURN (REG_EBRACK); | 2077 | if (p == pend) FREE_STACK_RETURN (REG_EBRACK); |
| 2071 | 2078 | ||
| @@ -2094,7 +2101,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2094 | else | 2101 | else |
| 2095 | { | 2102 | { |
| 2096 | c1++; | 2103 | c1++; |
| 2097 | while (c1--) | 2104 | while (c1--) |
| 2098 | PATUNFETCH; | 2105 | PATUNFETCH; |
| 2099 | SET_LIST_BIT ('['); | 2106 | SET_LIST_BIT ('['); |
| 2100 | SET_LIST_BIT (':'); | 2107 | SET_LIST_BIT (':'); |
| @@ -2110,8 +2117,8 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2110 | 2117 | ||
| 2111 | /* Discard any (non)matching list bytes that are all 0 at the | 2118 | /* Discard any (non)matching list bytes that are all 0 at the |
| 2112 | end of the map. Decrease the map-length byte too. */ | 2119 | end of the map. Decrease the map-length byte too. */ |
| 2113 | while ((int) b[-1] > 0 && b[b[-1] - 1] == 0) | 2120 | while ((int) b[-1] > 0 && b[b[-1] - 1] == 0) |
| 2114 | b[-1]--; | 2121 | b[-1]--; |
| 2115 | b += b[-1]; | 2122 | b += b[-1]; |
| 2116 | } | 2123 | } |
| 2117 | break; | 2124 | break; |
| @@ -2171,7 +2178,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2171 | regnum++; | 2178 | regnum++; |
| 2172 | 2179 | ||
| 2173 | if (COMPILE_STACK_FULL) | 2180 | if (COMPILE_STACK_FULL) |
| 2174 | { | 2181 | { |
| 2175 | RETALLOC (compile_stack.stack, compile_stack.size << 1, | 2182 | RETALLOC (compile_stack.stack, compile_stack.size << 1, |
| 2176 | compile_stack_elt_t); | 2183 | compile_stack_elt_t); |
| 2177 | if (compile_stack.stack == NULL) return REG_ESPACE; | 2184 | if (compile_stack.stack == NULL) return REG_ESPACE; |
| @@ -2184,7 +2191,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2184 | whole pattern moves because of realloc, they will still | 2191 | whole pattern moves because of realloc, they will still |
| 2185 | be valid. */ | 2192 | be valid. */ |
| 2186 | COMPILE_STACK_TOP.begalt_offset = begalt - bufp->buffer; | 2193 | COMPILE_STACK_TOP.begalt_offset = begalt - bufp->buffer; |
| 2187 | COMPILE_STACK_TOP.fixup_alt_jump | 2194 | COMPILE_STACK_TOP.fixup_alt_jump |
| 2188 | = fixup_alt_jump ? fixup_alt_jump - bufp->buffer + 1 : 0; | 2195 | = fixup_alt_jump ? fixup_alt_jump - bufp->buffer + 1 : 0; |
| 2189 | COMPILE_STACK_TOP.laststart_offset = b - bufp->buffer; | 2196 | COMPILE_STACK_TOP.laststart_offset = b - bufp->buffer; |
| 2190 | COMPILE_STACK_TOP.regnum = regnum; | 2197 | COMPILE_STACK_TOP.regnum = regnum; |
| @@ -2198,7 +2205,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2198 | COMPILE_STACK_TOP.inner_group_offset = b - bufp->buffer + 2; | 2205 | COMPILE_STACK_TOP.inner_group_offset = b - bufp->buffer + 2; |
| 2199 | BUF_PUSH_3 (start_memory, regnum, 0); | 2206 | BUF_PUSH_3 (start_memory, regnum, 0); |
| 2200 | } | 2207 | } |
| 2201 | 2208 | ||
| 2202 | compile_stack.avail++; | 2209 | compile_stack.avail++; |
| 2203 | 2210 | ||
| 2204 | fixup_alt_jump = 0; | 2211 | fixup_alt_jump = 0; |
| @@ -2227,7 +2234,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2227 | `pop_failure_jump' to pop. See comments at | 2234 | `pop_failure_jump' to pop. See comments at |
| 2228 | `push_dummy_failure' in `re_match_2'. */ | 2235 | `push_dummy_failure' in `re_match_2'. */ |
| 2229 | BUF_PUSH (push_dummy_failure); | 2236 | BUF_PUSH (push_dummy_failure); |
| 2230 | 2237 | ||
| 2231 | /* We allocated space for this jump when we assigned | 2238 | /* We allocated space for this jump when we assigned |
| 2232 | to `fixup_alt_jump', in the `handle_alt' case below. */ | 2239 | to `fixup_alt_jump', in the `handle_alt' case below. */ |
| 2233 | STORE_JUMP (jump_past_alt, fixup_alt_jump, b - 1); | 2240 | STORE_JUMP (jump_past_alt, fixup_alt_jump, b - 1); |
| @@ -2249,11 +2256,11 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2249 | as in `(ab)c(de)' -- the second group is #2. */ | 2256 | as in `(ab)c(de)' -- the second group is #2. */ |
| 2250 | regnum_t this_group_regnum; | 2257 | regnum_t this_group_regnum; |
| 2251 | 2258 | ||
| 2252 | compile_stack.avail--; | 2259 | compile_stack.avail--; |
| 2253 | begalt = bufp->buffer + COMPILE_STACK_TOP.begalt_offset; | 2260 | begalt = bufp->buffer + COMPILE_STACK_TOP.begalt_offset; |
| 2254 | fixup_alt_jump | 2261 | fixup_alt_jump |
| 2255 | = COMPILE_STACK_TOP.fixup_alt_jump | 2262 | = COMPILE_STACK_TOP.fixup_alt_jump |
| 2256 | ? bufp->buffer + COMPILE_STACK_TOP.fixup_alt_jump - 1 | 2263 | ? bufp->buffer + COMPILE_STACK_TOP.fixup_alt_jump - 1 |
| 2257 | : 0; | 2264 | : 0; |
| 2258 | laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset; | 2265 | laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset; |
| 2259 | this_group_regnum = COMPILE_STACK_TOP.regnum; | 2266 | this_group_regnum = COMPILE_STACK_TOP.regnum; |
| @@ -2268,7 +2275,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2268 | { | 2275 | { |
| 2269 | unsigned char *inner_group_loc | 2276 | unsigned char *inner_group_loc |
| 2270 | = bufp->buffer + COMPILE_STACK_TOP.inner_group_offset; | 2277 | = bufp->buffer + COMPILE_STACK_TOP.inner_group_offset; |
| 2271 | 2278 | ||
| 2272 | *inner_group_loc = regnum - this_group_regnum; | 2279 | *inner_group_loc = regnum - this_group_regnum; |
| 2273 | BUF_PUSH_3 (stop_memory, this_group_regnum, | 2280 | BUF_PUSH_3 (stop_memory, this_group_regnum, |
| 2274 | regnum - this_group_regnum); | 2281 | regnum - this_group_regnum); |
| @@ -2297,10 +2304,10 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2297 | jump (put in below, which in turn will jump to the next | 2304 | jump (put in below, which in turn will jump to the next |
| 2298 | (if any) alternative's such jump, etc.). The last such | 2305 | (if any) alternative's such jump, etc.). The last such |
| 2299 | jump jumps to the correct final destination. A picture: | 2306 | jump jumps to the correct final destination. A picture: |
| 2300 | _____ _____ | 2307 | _____ _____ |
| 2301 | | | | | | 2308 | | | | | |
| 2302 | | v | v | 2309 | | v | v |
| 2303 | a | b | c | 2310 | a | b | c |
| 2304 | 2311 | ||
| 2305 | If we are at `b', then fixup_alt_jump right now points to a | 2312 | If we are at `b', then fixup_alt_jump right now points to a |
| 2306 | three-byte space after `a'. We'll put in the jump, set | 2313 | three-byte space after `a'. We'll put in the jump, set |
| @@ -2322,10 +2329,10 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2322 | break; | 2329 | break; |
| 2323 | 2330 | ||
| 2324 | 2331 | ||
| 2325 | case '{': | 2332 | case '{': |
| 2326 | /* If \{ is a literal. */ | 2333 | /* If \{ is a literal. */ |
| 2327 | if (!(syntax & RE_INTERVALS) | 2334 | if (!(syntax & RE_INTERVALS) |
| 2328 | /* If we're at `\{' and it's not the open-interval | 2335 | /* If we're at `\{' and it's not the open-interval |
| 2329 | operator. */ | 2336 | operator. */ |
| 2330 | || ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES)) | 2337 | || ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES)) |
| 2331 | || (p - 2 == pattern && p == pend)) | 2338 | || (p - 2 == pattern && p == pend)) |
| @@ -2364,11 +2371,11 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2364 | { | 2371 | { |
| 2365 | if (syntax & RE_NO_BK_BRACES) | 2372 | if (syntax & RE_NO_BK_BRACES) |
| 2366 | goto unfetch_interval; | 2373 | goto unfetch_interval; |
| 2367 | else | 2374 | else |
| 2368 | FREE_STACK_RETURN (REG_BADBR); | 2375 | FREE_STACK_RETURN (REG_BADBR); |
| 2369 | } | 2376 | } |
| 2370 | 2377 | ||
| 2371 | if (!(syntax & RE_NO_BK_BRACES)) | 2378 | if (!(syntax & RE_NO_BK_BRACES)) |
| 2372 | { | 2379 | { |
| 2373 | if (c != '\\') FREE_STACK_RETURN (REG_EBRACE); | 2380 | if (c != '\\') FREE_STACK_RETURN (REG_EBRACE); |
| 2374 | 2381 | ||
| @@ -2379,7 +2386,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2379 | { | 2386 | { |
| 2380 | if (syntax & RE_NO_BK_BRACES) | 2387 | if (syntax & RE_NO_BK_BRACES) |
| 2381 | goto unfetch_interval; | 2388 | goto unfetch_interval; |
| 2382 | else | 2389 | else |
| 2383 | FREE_STACK_RETURN (REG_BADBR); | 2390 | FREE_STACK_RETURN (REG_BADBR); |
| 2384 | } | 2391 | } |
| 2385 | 2392 | ||
| @@ -2415,7 +2422,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2415 | jump_n <succeed_n addr> <jump count> | 2422 | jump_n <succeed_n addr> <jump count> |
| 2416 | (The upper bound and `jump_n' are omitted if | 2423 | (The upper bound and `jump_n' are omitted if |
| 2417 | `upper_bound' is 1, though.) */ | 2424 | `upper_bound' is 1, though.) */ |
| 2418 | else | 2425 | else |
| 2419 | { /* If the upper bound is > 1, we need to insert | 2426 | { /* If the upper bound is > 1, we need to insert |
| 2420 | more at the end of the loop. */ | 2427 | more at the end of the loop. */ |
| 2421 | unsigned nbytes = 10 + (upper_bound > 1) * 10; | 2428 | unsigned nbytes = 10 + (upper_bound > 1) * 10; |
| @@ -2432,7 +2439,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2432 | lower_bound); | 2439 | lower_bound); |
| 2433 | b += 5; | 2440 | b += 5; |
| 2434 | 2441 | ||
| 2435 | /* Code to initialize the lower bound. Insert | 2442 | /* Code to initialize the lower bound. Insert |
| 2436 | before the `succeed_n'. The `5' is the last two | 2443 | before the `succeed_n'. The `5' is the last two |
| 2437 | bytes of this `set_number_at', plus 3 bytes of | 2444 | bytes of this `set_number_at', plus 3 bytes of |
| 2438 | the following `succeed_n'. */ | 2445 | the following `succeed_n'. */ |
| @@ -2443,7 +2450,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2443 | { /* More than one repetition is allowed, so | 2450 | { /* More than one repetition is allowed, so |
| 2444 | append a backward jump to the `succeed_n' | 2451 | append a backward jump to the `succeed_n' |
| 2445 | that starts this interval. | 2452 | that starts this interval. |
| 2446 | 2453 | ||
| 2447 | When we've reached this during matching, | 2454 | When we've reached this during matching, |
| 2448 | we'll have matched the interval once, so | 2455 | we'll have matched the interval once, so |
| 2449 | jump back only `upper_bound - 1' times. */ | 2456 | jump back only `upper_bound - 1' times. */ |
| @@ -2461,7 +2468,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2461 | so everything is getting moved up by 5. | 2468 | so everything is getting moved up by 5. |
| 2462 | Conclusion: (b - 2) - (laststart + 3) + 5, | 2469 | Conclusion: (b - 2) - (laststart + 3) + 5, |
| 2463 | i.e., b - laststart. | 2470 | i.e., b - laststart. |
| 2464 | 2471 | ||
| 2465 | We insert this at the beginning of the loop | 2472 | We insert this at the beginning of the loop |
| 2466 | so that if we fail during matching, we'll | 2473 | so that if we fail during matching, we'll |
| 2467 | reinitialize the bounds. */ | 2474 | reinitialize the bounds. */ |
| @@ -2482,7 +2489,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2482 | beg_interval = NULL; | 2489 | beg_interval = NULL; |
| 2483 | 2490 | ||
| 2484 | /* normal_char and normal_backslash need `c'. */ | 2491 | /* normal_char and normal_backslash need `c'. */ |
| 2485 | PATFETCH (c); | 2492 | PATFETCH (c); |
| 2486 | 2493 | ||
| 2487 | if (!(syntax & RE_NO_BK_BRACES)) | 2494 | if (!(syntax & RE_NO_BK_BRACES)) |
| 2488 | { | 2495 | { |
| @@ -2498,7 +2505,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2498 | BUF_PUSH (at_dot); | 2505 | BUF_PUSH (at_dot); |
| 2499 | break; | 2506 | break; |
| 2500 | 2507 | ||
| 2501 | case 's': | 2508 | case 's': |
| 2502 | laststart = b; | 2509 | laststart = b; |
| 2503 | PATFETCH (c); | 2510 | PATFETCH (c); |
| 2504 | BUF_PUSH_2 (syntaxspec, syntax_spec_code[c]); | 2511 | BUF_PUSH_2 (syntaxspec, syntax_spec_code[c]); |
| @@ -2589,11 +2596,11 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2589 | /* Expects the character in `c'. */ | 2596 | /* Expects the character in `c'. */ |
| 2590 | normal_char: | 2597 | normal_char: |
| 2591 | /* If no exactn currently being built. */ | 2598 | /* If no exactn currently being built. */ |
| 2592 | if (!pending_exact | 2599 | if (!pending_exact |
| 2593 | 2600 | ||
| 2594 | /* If last exactn not at current position. */ | 2601 | /* If last exactn not at current position. */ |
| 2595 | || pending_exact + *pending_exact + 1 != b | 2602 | || pending_exact + *pending_exact + 1 != b |
| 2596 | 2603 | ||
| 2597 | /* We have only one byte following the exactn for the count. */ | 2604 | /* We have only one byte following the exactn for the count. */ |
| 2598 | || *pending_exact == (1 << BYTEWIDTH) - 1 | 2605 | || *pending_exact == (1 << BYTEWIDTH) - 1 |
| 2599 | 2606 | ||
| @@ -2608,26 +2615,26 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2608 | : (p[0] == '\\' && p[1] == '{')))) | 2615 | : (p[0] == '\\' && p[1] == '{')))) |
| 2609 | { | 2616 | { |
| 2610 | /* Start building a new exactn. */ | 2617 | /* Start building a new exactn. */ |
| 2611 | 2618 | ||
| 2612 | laststart = b; | 2619 | laststart = b; |
| 2613 | 2620 | ||
| 2614 | BUF_PUSH_2 (exactn, 0); | 2621 | BUF_PUSH_2 (exactn, 0); |
| 2615 | pending_exact = b - 1; | 2622 | pending_exact = b - 1; |
| 2616 | } | 2623 | } |
| 2617 | 2624 | ||
| 2618 | BUF_PUSH (c); | 2625 | BUF_PUSH (c); |
| 2619 | (*pending_exact)++; | 2626 | (*pending_exact)++; |
| 2620 | break; | 2627 | break; |
| 2621 | } /* switch (c) */ | 2628 | } /* switch (c) */ |
| 2622 | } /* while p != pend */ | 2629 | } /* while p != pend */ |
| 2623 | 2630 | ||
| 2624 | 2631 | ||
| 2625 | /* Through the pattern now. */ | 2632 | /* Through the pattern now. */ |
| 2626 | 2633 | ||
| 2627 | if (fixup_alt_jump) | 2634 | if (fixup_alt_jump) |
| 2628 | STORE_JUMP (jump_past_alt, fixup_alt_jump, b); | 2635 | STORE_JUMP (jump_past_alt, fixup_alt_jump, b); |
| 2629 | 2636 | ||
| 2630 | if (!COMPILE_STACK_EMPTY) | 2637 | if (!COMPILE_STACK_EMPTY) |
| 2631 | FREE_STACK_RETURN (REG_EPAREN); | 2638 | FREE_STACK_RETURN (REG_EPAREN); |
| 2632 | 2639 | ||
| 2633 | /* If we don't want backtracking, force success | 2640 | /* If we don't want backtracking, force success |
| @@ -2665,7 +2672,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2665 | #ifdef emacs | 2672 | #ifdef emacs |
| 2666 | if (! fail_stack.stack) | 2673 | if (! fail_stack.stack) |
| 2667 | fail_stack.stack | 2674 | fail_stack.stack |
| 2668 | = (fail_stack_elt_t *) xmalloc (fail_stack.size | 2675 | = (fail_stack_elt_t *) xmalloc (fail_stack.size |
| 2669 | * sizeof (fail_stack_elt_t)); | 2676 | * sizeof (fail_stack_elt_t)); |
| 2670 | else | 2677 | else |
| 2671 | fail_stack.stack | 2678 | fail_stack.stack |
| @@ -2675,7 +2682,7 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2675 | #else /* not emacs */ | 2682 | #else /* not emacs */ |
| 2676 | if (! fail_stack.stack) | 2683 | if (! fail_stack.stack) |
| 2677 | fail_stack.stack | 2684 | fail_stack.stack |
| 2678 | = (fail_stack_elt_t *) malloc (fail_stack.size | 2685 | = (fail_stack_elt_t *) malloc (fail_stack.size |
| 2679 | * sizeof (fail_stack_elt_t)); | 2686 | * sizeof (fail_stack_elt_t)); |
| 2680 | else | 2687 | else |
| 2681 | fail_stack.stack | 2688 | fail_stack.stack |
| @@ -2729,14 +2736,14 @@ insert_op1 (op, loc, arg, end) | |||
| 2729 | re_opcode_t op; | 2736 | re_opcode_t op; |
| 2730 | unsigned char *loc; | 2737 | unsigned char *loc; |
| 2731 | int arg; | 2738 | int arg; |
| 2732 | unsigned char *end; | 2739 | unsigned char *end; |
| 2733 | { | 2740 | { |
| 2734 | register unsigned char *pfrom = end; | 2741 | register unsigned char *pfrom = end; |
| 2735 | register unsigned char *pto = end + 3; | 2742 | register unsigned char *pto = end + 3; |
| 2736 | 2743 | ||
| 2737 | while (pfrom != loc) | 2744 | while (pfrom != loc) |
| 2738 | *--pto = *--pfrom; | 2745 | *--pto = *--pfrom; |
| 2739 | 2746 | ||
| 2740 | store_op1 (op, loc, arg); | 2747 | store_op1 (op, loc, arg); |
| 2741 | } | 2748 | } |
| 2742 | 2749 | ||
| @@ -2748,14 +2755,14 @@ insert_op2 (op, loc, arg1, arg2, end) | |||
| 2748 | re_opcode_t op; | 2755 | re_opcode_t op; |
| 2749 | unsigned char *loc; | 2756 | unsigned char *loc; |
| 2750 | int arg1, arg2; | 2757 | int arg1, arg2; |
| 2751 | unsigned char *end; | 2758 | unsigned char *end; |
| 2752 | { | 2759 | { |
| 2753 | register unsigned char *pfrom = end; | 2760 | register unsigned char *pfrom = end; |
| 2754 | register unsigned char *pto = end + 5; | 2761 | register unsigned char *pto = end + 5; |
| 2755 | 2762 | ||
| 2756 | while (pfrom != loc) | 2763 | while (pfrom != loc) |
| 2757 | *--pto = *--pfrom; | 2764 | *--pto = *--pfrom; |
| 2758 | 2765 | ||
| 2759 | store_op2 (op, loc, arg1, arg2); | 2766 | store_op2 (op, loc, arg1, arg2); |
| 2760 | } | 2767 | } |
| 2761 | 2768 | ||
| @@ -2771,7 +2778,7 @@ at_begline_loc_p (pattern, p, syntax) | |||
| 2771 | { | 2778 | { |
| 2772 | const char *prev = p - 2; | 2779 | const char *prev = p - 2; |
| 2773 | boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\'; | 2780 | boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\'; |
| 2774 | 2781 | ||
| 2775 | return | 2782 | return |
| 2776 | /* After a subexpression? */ | 2783 | /* After a subexpression? */ |
| 2777 | (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash)) | 2784 | (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash)) |
| @@ -2791,7 +2798,7 @@ at_endline_loc_p (p, pend, syntax) | |||
| 2791 | const char *next = p; | 2798 | const char *next = p; |
| 2792 | boolean next_backslash = *next == '\\'; | 2799 | boolean next_backslash = *next == '\\'; |
| 2793 | const char *next_next = p + 1 < pend ? p + 1 : 0; | 2800 | const char *next_next = p + 1 < pend ? p + 1 : 0; |
| 2794 | 2801 | ||
| 2795 | return | 2802 | return |
| 2796 | /* Before a subexpression? */ | 2803 | /* Before a subexpression? */ |
| 2797 | (syntax & RE_NO_BK_PARENS ? *next == ')' | 2804 | (syntax & RE_NO_BK_PARENS ? *next == ')' |
| @@ -2802,7 +2809,7 @@ at_endline_loc_p (p, pend, syntax) | |||
| 2802 | } | 2809 | } |
| 2803 | 2810 | ||
| 2804 | 2811 | ||
| 2805 | /* Returns true if REGNUM is in one of COMPILE_STACK's elements and | 2812 | /* Returns true if REGNUM is in one of COMPILE_STACK's elements and |
| 2806 | false if it's not. */ | 2813 | false if it's not. */ |
| 2807 | 2814 | ||
| 2808 | static boolean | 2815 | static boolean |
| @@ -2812,8 +2819,8 @@ group_in_compile_stack (compile_stack, regnum) | |||
| 2812 | { | 2819 | { |
| 2813 | int this_element; | 2820 | int this_element; |
| 2814 | 2821 | ||
| 2815 | for (this_element = compile_stack.avail - 1; | 2822 | for (this_element = compile_stack.avail - 1; |
| 2816 | this_element >= 0; | 2823 | this_element >= 0; |
| 2817 | this_element--) | 2824 | this_element--) |
| 2818 | if (compile_stack.stack[this_element].regnum == regnum) | 2825 | if (compile_stack.stack[this_element].regnum == regnum) |
| 2819 | return true; | 2826 | return true; |
| @@ -2827,9 +2834,9 @@ group_in_compile_stack (compile_stack, regnum) | |||
| 2827 | starting character is in `P[-2]'. (`P[-1]' is the character `-'.) | 2834 | starting character is in `P[-2]'. (`P[-1]' is the character `-'.) |
| 2828 | Then we set the translation of all bits between the starting and | 2835 | Then we set the translation of all bits between the starting and |
| 2829 | ending characters (inclusive) in the compiled pattern B. | 2836 | ending characters (inclusive) in the compiled pattern B. |
| 2830 | 2837 | ||
| 2831 | Return an error code. | 2838 | Return an error code. |
| 2832 | 2839 | ||
| 2833 | We use these short variable names so we can use the same macros as | 2840 | We use these short variable names so we can use the same macros as |
| 2834 | `regex_compile' itself. */ | 2841 | `regex_compile' itself. */ |
| 2835 | 2842 | ||
| @@ -2844,7 +2851,7 @@ compile_range (p_ptr, pend, translate, syntax, b) | |||
| 2844 | 2851 | ||
| 2845 | const char *p = *p_ptr; | 2852 | const char *p = *p_ptr; |
| 2846 | int range_start, range_end; | 2853 | int range_start, range_end; |
| 2847 | 2854 | ||
| 2848 | if (p == pend) | 2855 | if (p == pend) |
| 2849 | return REG_ERANGE; | 2856 | return REG_ERANGE; |
| 2850 | 2857 | ||
| @@ -2853,7 +2860,7 @@ compile_range (p_ptr, pend, translate, syntax, b) | |||
| 2853 | is set, the range endpoints will be negative if we fetch using a | 2860 | is set, the range endpoints will be negative if we fetch using a |
| 2854 | signed char *. | 2861 | signed char *. |
| 2855 | 2862 | ||
| 2856 | We also want to fetch the endpoints without translating them; the | 2863 | We also want to fetch the endpoints without translating them; the |
| 2857 | appropriate translation is done in the bit-setting loop below. */ | 2864 | appropriate translation is done in the bit-setting loop below. */ |
| 2858 | /* The SVR4 compiler on the 3B2 had trouble with unsigned const char *. */ | 2865 | /* The SVR4 compiler on the 3B2 had trouble with unsigned const char *. */ |
| 2859 | range_start = ((const unsigned char *) p)[-2]; | 2866 | range_start = ((const unsigned char *) p)[-2]; |
| @@ -2875,7 +2882,7 @@ compile_range (p_ptr, pend, translate, syntax, b) | |||
| 2875 | { | 2882 | { |
| 2876 | SET_LIST_BIT (TRANSLATE (this_char)); | 2883 | SET_LIST_BIT (TRANSLATE (this_char)); |
| 2877 | } | 2884 | } |
| 2878 | 2885 | ||
| 2879 | return REG_NOERROR; | 2886 | return REG_NOERROR; |
| 2880 | } | 2887 | } |
| 2881 | 2888 | ||
| @@ -2886,7 +2893,7 @@ compile_range (p_ptr, pend, translate, syntax, b) | |||
| 2886 | 2893 | ||
| 2887 | The caller must supply the address of a (1 << BYTEWIDTH)-byte data | 2894 | The caller must supply the address of a (1 << BYTEWIDTH)-byte data |
| 2888 | area as BUFP->fastmap. | 2895 | area as BUFP->fastmap. |
| 2889 | 2896 | ||
| 2890 | We set the `fastmap', `fastmap_accurate', and `can_be_null' fields in | 2897 | We set the `fastmap', `fastmap_accurate', and `can_be_null' fields in |
| 2891 | the pattern buffer. | 2898 | the pattern buffer. |
| 2892 | 2899 | ||
| @@ -2905,7 +2912,7 @@ re_compile_fastmap (bufp) | |||
| 2905 | #endif | 2912 | #endif |
| 2906 | /* We don't push any register information onto the failure stack. */ | 2913 | /* We don't push any register information onto the failure stack. */ |
| 2907 | unsigned num_regs = 0; | 2914 | unsigned num_regs = 0; |
| 2908 | 2915 | ||
| 2909 | register char *fastmap = bufp->fastmap; | 2916 | register char *fastmap = bufp->fastmap; |
| 2910 | unsigned char *pattern = bufp->buffer; | 2917 | unsigned char *pattern = bufp->buffer; |
| 2911 | unsigned long size = bufp->used; | 2918 | unsigned long size = bufp->used; |
| @@ -2926,12 +2933,12 @@ re_compile_fastmap (bufp) | |||
| 2926 | boolean succeed_n_p = false; | 2933 | boolean succeed_n_p = false; |
| 2927 | 2934 | ||
| 2928 | assert (fastmap != NULL && p != NULL); | 2935 | assert (fastmap != NULL && p != NULL); |
| 2929 | 2936 | ||
| 2930 | INIT_FAIL_STACK (); | 2937 | INIT_FAIL_STACK (); |
| 2931 | bzero (fastmap, 1 << BYTEWIDTH); /* Assume nothing's valid. */ | 2938 | bzero (fastmap, 1 << BYTEWIDTH); /* Assume nothing's valid. */ |
| 2932 | bufp->fastmap_accurate = 1; /* It will be when we're done. */ | 2939 | bufp->fastmap_accurate = 1; /* It will be when we're done. */ |
| 2933 | bufp->can_be_null = 0; | 2940 | bufp->can_be_null = 0; |
| 2934 | 2941 | ||
| 2935 | while (1) | 2942 | while (1) |
| 2936 | { | 2943 | { |
| 2937 | if (p == pend || *p == succeed) | 2944 | if (p == pend || *p == succeed) |
| @@ -2954,7 +2961,7 @@ re_compile_fastmap (bufp) | |||
| 2954 | 2961 | ||
| 2955 | /* We should never be about to go beyond the end of the pattern. */ | 2962 | /* We should never be about to go beyond the end of the pattern. */ |
| 2956 | assert (p < pend); | 2963 | assert (p < pend); |
| 2957 | 2964 | ||
| 2958 | switch (SWITCH_ENUM_CAST ((re_opcode_t) *p++)) | 2965 | switch (SWITCH_ENUM_CAST ((re_opcode_t) *p++)) |
| 2959 | { | 2966 | { |
| 2960 | 2967 | ||
| @@ -3077,10 +3084,10 @@ re_compile_fastmap (bufp) | |||
| 3077 | case jump_past_alt: | 3084 | case jump_past_alt: |
| 3078 | case dummy_failure_jump: | 3085 | case dummy_failure_jump: |
| 3079 | EXTRACT_NUMBER_AND_INCR (j, p); | 3086 | EXTRACT_NUMBER_AND_INCR (j, p); |
| 3080 | p += j; | 3087 | p += j; |
| 3081 | if (j > 0) | 3088 | if (j > 0) |
| 3082 | continue; | 3089 | continue; |
| 3083 | 3090 | ||
| 3084 | /* Jump backward implies we just went through the body of a | 3091 | /* Jump backward implies we just went through the body of a |
| 3085 | loop and matched nothing. Opcode jumped to should be | 3092 | loop and matched nothing. Opcode jumped to should be |
| 3086 | `on_failure_jump' or `succeed_n'. Just treat it like an | 3093 | `on_failure_jump' or `succeed_n'. Just treat it like an |
| @@ -3092,10 +3099,10 @@ re_compile_fastmap (bufp) | |||
| 3092 | 3099 | ||
| 3093 | p++; | 3100 | p++; |
| 3094 | EXTRACT_NUMBER_AND_INCR (j, p); | 3101 | EXTRACT_NUMBER_AND_INCR (j, p); |
| 3095 | p += j; | 3102 | p += j; |
| 3096 | 3103 | ||
| 3097 | /* If what's on the stack is where we are now, pop it. */ | 3104 | /* If what's on the stack is where we are now, pop it. */ |
| 3098 | if (!FAIL_STACK_EMPTY () | 3105 | if (!FAIL_STACK_EMPTY () |
| 3099 | && fail_stack.stack[fail_stack.avail - 1].pointer == p) | 3106 | && fail_stack.stack[fail_stack.avail - 1].pointer == p) |
| 3100 | fail_stack.avail--; | 3107 | fail_stack.avail--; |
| 3101 | 3108 | ||
| @@ -3136,7 +3143,7 @@ re_compile_fastmap (bufp) | |||
| 3136 | 3143 | ||
| 3137 | case succeed_n: | 3144 | case succeed_n: |
| 3138 | /* Get to the number of times to succeed. */ | 3145 | /* Get to the number of times to succeed. */ |
| 3139 | p += 2; | 3146 | p += 2; |
| 3140 | 3147 | ||
| 3141 | /* Increment p past the n for when k != 0. */ | 3148 | /* Increment p past the n for when k != 0. */ |
| 3142 | EXTRACT_NUMBER_AND_INCR (k, p); | 3149 | EXTRACT_NUMBER_AND_INCR (k, p); |
| @@ -3230,7 +3237,7 @@ re_search (bufp, string, size, startpos, range, regs) | |||
| 3230 | int size, startpos, range; | 3237 | int size, startpos, range; |
| 3231 | struct re_registers *regs; | 3238 | struct re_registers *regs; |
| 3232 | { | 3239 | { |
| 3233 | return re_search_2 (bufp, NULL, 0, string, size, startpos, range, | 3240 | return re_search_2 (bufp, NULL, 0, string, size, startpos, range, |
| 3234 | regs, size); | 3241 | regs, size); |
| 3235 | } | 3242 | } |
| 3236 | 3243 | ||
| @@ -3238,17 +3245,17 @@ re_search (bufp, string, size, startpos, range, regs) | |||
| 3238 | /* Using the compiled pattern in BUFP->buffer, first tries to match the | 3245 | /* Using the compiled pattern in BUFP->buffer, first tries to match the |
| 3239 | virtual concatenation of STRING1 and STRING2, starting first at index | 3246 | virtual concatenation of STRING1 and STRING2, starting first at index |
| 3240 | STARTPOS, then at STARTPOS + 1, and so on. | 3247 | STARTPOS, then at STARTPOS + 1, and so on. |
| 3241 | 3248 | ||
| 3242 | STRING1 and STRING2 have length SIZE1 and SIZE2, respectively. | 3249 | STRING1 and STRING2 have length SIZE1 and SIZE2, respectively. |
| 3243 | 3250 | ||
| 3244 | RANGE is how far to scan while trying to match. RANGE = 0 means try | 3251 | RANGE is how far to scan while trying to match. RANGE = 0 means try |
| 3245 | only at STARTPOS; in general, the last start tried is STARTPOS + | 3252 | only at STARTPOS; in general, the last start tried is STARTPOS + |
| 3246 | RANGE. | 3253 | RANGE. |
| 3247 | 3254 | ||
| 3248 | In REGS, return the indices of the virtual concatenation of STRING1 | 3255 | In REGS, return the indices of the virtual concatenation of STRING1 |
| 3249 | and STRING2 that matched the entire BUFP->buffer and its contained | 3256 | and STRING2 that matched the entire BUFP->buffer and its contained |
| 3250 | subexpressions. | 3257 | subexpressions. |
| 3251 | 3258 | ||
| 3252 | Do not consider matching one past the index STOP in the virtual | 3259 | Do not consider matching one past the index STOP in the virtual |
| 3253 | concatenation of STRING1 and STRING2. | 3260 | concatenation of STRING1 and STRING2. |
| 3254 | 3261 | ||
| @@ -3275,10 +3282,10 @@ re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop) | |||
| 3275 | /* Check for out-of-range STARTPOS. */ | 3282 | /* Check for out-of-range STARTPOS. */ |
| 3276 | if (startpos < 0 || startpos > total_size) | 3283 | if (startpos < 0 || startpos > total_size) |
| 3277 | return -1; | 3284 | return -1; |
| 3278 | 3285 | ||
| 3279 | /* Fix up RANGE if it might eventually take us outside | 3286 | /* Fix up RANGE if it might eventually take us outside |
| 3280 | the virtual concatenation of STRING1 and STRING2. | 3287 | the virtual concatenation of STRING1 and STRING2. |
| 3281 | Make sure we won't move STARTPOS below 0 or above TOTAL_SIZE. */ | 3288 | Make sure we won't move STARTPOS below 0 or above TOTAL_SIZE. */ |
| 3282 | if (endpos < 0) | 3289 | if (endpos < 0) |
| 3283 | range = 0 - startpos; | 3290 | range = 0 - startpos; |
| 3284 | else if (endpos > total_size) | 3291 | else if (endpos > total_size) |
| @@ -3309,10 +3316,10 @@ re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop) | |||
| 3309 | if (fastmap && !bufp->fastmap_accurate) | 3316 | if (fastmap && !bufp->fastmap_accurate) |
| 3310 | if (re_compile_fastmap (bufp) == -2) | 3317 | if (re_compile_fastmap (bufp) == -2) |
| 3311 | return -2; | 3318 | return -2; |
| 3312 | 3319 | ||
| 3313 | /* Loop through the string, looking for a place to start matching. */ | 3320 | /* Loop through the string, looking for a place to start matching. */ |
| 3314 | for (;;) | 3321 | for (;;) |
| 3315 | { | 3322 | { |
| 3316 | /* If a fastmap is supplied, skip quickly over characters that | 3323 | /* If a fastmap is supplied, skip quickly over characters that |
| 3317 | cannot be the start of a match. If the pattern can match the | 3324 | cannot be the start of a match. If the pattern can match the |
| 3318 | null string, however, we don't need to skip characters; we want | 3325 | null string, however, we don't need to skip characters; we want |
| @@ -3329,7 +3336,7 @@ re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop) | |||
| 3329 | lim = range - (size1 - startpos); | 3336 | lim = range - (size1 - startpos); |
| 3330 | 3337 | ||
| 3331 | d = (startpos >= size1 ? string2 - size1 : string1) + startpos; | 3338 | d = (startpos >= size1 ? string2 - size1 : string1) + startpos; |
| 3332 | 3339 | ||
| 3333 | /* Written out as an if-else to avoid testing `translate' | 3340 | /* Written out as an if-else to avoid testing `translate' |
| 3334 | inside the loop. */ | 3341 | inside the loop. */ |
| 3335 | if (translate) | 3342 | if (translate) |
| @@ -3346,7 +3353,7 @@ re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop) | |||
| 3346 | else /* Searching backwards. */ | 3353 | else /* Searching backwards. */ |
| 3347 | { | 3354 | { |
| 3348 | register char c = (size1 == 0 || startpos >= size1 | 3355 | register char c = (size1 == 0 || startpos >= size1 |
| 3349 | ? string2[startpos - size1] | 3356 | ? string2[startpos - size1] |
| 3350 | : string1[startpos]); | 3357 | : string1[startpos]); |
| 3351 | 3358 | ||
| 3352 | if (!fastmap[(unsigned char) TRANSLATE (c)]) | 3359 | if (!fastmap[(unsigned char) TRANSLATE (c)]) |
| @@ -3369,21 +3376,21 @@ re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop) | |||
| 3369 | 3376 | ||
| 3370 | if (val >= 0) | 3377 | if (val >= 0) |
| 3371 | return startpos; | 3378 | return startpos; |
| 3372 | 3379 | ||
| 3373 | if (val == -2) | 3380 | if (val == -2) |
| 3374 | return -2; | 3381 | return -2; |
| 3375 | 3382 | ||
| 3376 | advance: | 3383 | advance: |
| 3377 | if (!range) | 3384 | if (!range) |
| 3378 | break; | 3385 | break; |
| 3379 | else if (range > 0) | 3386 | else if (range > 0) |
| 3380 | { | 3387 | { |
| 3381 | range--; | 3388 | range--; |
| 3382 | startpos++; | 3389 | startpos++; |
| 3383 | } | 3390 | } |
| 3384 | else | 3391 | else |
| 3385 | { | 3392 | { |
| 3386 | range++; | 3393 | range++; |
| 3387 | startpos--; | 3394 | startpos--; |
| 3388 | } | 3395 | } |
| 3389 | } | 3396 | } |
| @@ -3425,7 +3432,7 @@ static boolean alt_match_null_string_p (), | |||
| 3425 | /* Test if at very beginning or at very end of the virtual concatenation | 3432 | /* Test if at very beginning or at very end of the virtual concatenation |
| 3426 | of `string1' and `string2'. If only one string, it's `string2'. */ | 3433 | of `string1' and `string2'. If only one string, it's `string2'. */ |
| 3427 | #define AT_STRINGS_BEG(d) ((d) == (size1 ? string1 : string2) || !size2) | 3434 | #define AT_STRINGS_BEG(d) ((d) == (size1 ? string1 : string2) || !size2) |
| 3428 | #define AT_STRINGS_END(d) ((d) == end2) | 3435 | #define AT_STRINGS_END(d) ((d) == end2) |
| 3429 | 3436 | ||
| 3430 | 3437 | ||
| 3431 | /* Test if D points to a character which is word-constituent. We have | 3438 | /* Test if D points to a character which is word-constituent. We have |
| @@ -3498,7 +3505,7 @@ re_match (bufp, string, size, pos, regs) | |||
| 3498 | the (virtual) concatenation of STRING1 and STRING2 (of length SIZE1 | 3505 | the (virtual) concatenation of STRING1 and STRING2 (of length SIZE1 |
| 3499 | and SIZE2, respectively). We start matching at POS, and stop | 3506 | and SIZE2, respectively). We start matching at POS, and stop |
| 3500 | matching at STOP. | 3507 | matching at STOP. |
| 3501 | 3508 | ||
| 3502 | If REGS is non-null and the `no_sub' field of BUFP is nonzero, we | 3509 | If REGS is non-null and the `no_sub' field of BUFP is nonzero, we |
| 3503 | store offsets for the substring each group matched in REGS. See the | 3510 | store offsets for the substring each group matched in REGS. See the |
| 3504 | documentation for exactly how many groups we fill. | 3511 | documentation for exactly how many groups we fill. |
| @@ -3546,7 +3553,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3546 | 3553 | ||
| 3547 | /* Where we are in the data, and the end of the current string. */ | 3554 | /* Where we are in the data, and the end of the current string. */ |
| 3548 | const char *d, *dend; | 3555 | const char *d, *dend; |
| 3549 | 3556 | ||
| 3550 | /* Where we are in the pattern, and the end of the pattern. */ | 3557 | /* Where we are in the pattern, and the end of the pattern. */ |
| 3551 | unsigned char *p = bufp->buffer; | 3558 | unsigned char *p = bufp->buffer; |
| 3552 | register unsigned char *pend = p + bufp->used; | 3559 | register unsigned char *pend = p + bufp->used; |
| @@ -3583,7 +3590,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3583 | return, for use in backreferences. The number here includes | 3590 | return, for use in backreferences. The number here includes |
| 3584 | an element for register zero. */ | 3591 | an element for register zero. */ |
| 3585 | unsigned num_regs = bufp->re_nsub + 1; | 3592 | unsigned num_regs = bufp->re_nsub + 1; |
| 3586 | 3593 | ||
| 3587 | /* The currently active registers. */ | 3594 | /* The currently active registers. */ |
| 3588 | unsigned lowest_active_reg = NO_LOWEST_ACTIVE_REG; | 3595 | unsigned lowest_active_reg = NO_LOWEST_ACTIVE_REG; |
| 3589 | unsigned highest_active_reg = NO_HIGHEST_ACTIVE_REG; | 3596 | unsigned highest_active_reg = NO_HIGHEST_ACTIVE_REG; |
| @@ -3615,18 +3622,18 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3615 | subexpression. These two fields get reset each time through any | 3622 | subexpression. These two fields get reset each time through any |
| 3616 | loop their register is in. */ | 3623 | loop their register is in. */ |
| 3617 | #ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */ | 3624 | #ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */ |
| 3618 | register_info_type *reg_info; | 3625 | register_info_type *reg_info; |
| 3619 | #endif | 3626 | #endif |
| 3620 | 3627 | ||
| 3621 | /* The following record the register info as found in the above | 3628 | /* The following record the register info as found in the above |
| 3622 | variables when we find a match better than any we've seen before. | 3629 | variables when we find a match better than any we've seen before. |
| 3623 | This happens as we backtrack through the failure points, which in | 3630 | This happens as we backtrack through the failure points, which in |
| 3624 | turn happens only if we have not yet matched the entire string. */ | 3631 | turn happens only if we have not yet matched the entire string. */ |
| 3625 | unsigned best_regs_set = false; | 3632 | unsigned best_regs_set = false; |
| 3626 | #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */ | 3633 | #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */ |
| 3627 | const char **best_regstart, **best_regend; | 3634 | const char **best_regstart, **best_regend; |
| 3628 | #endif | 3635 | #endif |
| 3629 | 3636 | ||
| 3630 | /* Logically, this is `best_regend[0]'. But we don't want to have to | 3637 | /* Logically, this is `best_regend[0]'. But we don't want to have to |
| 3631 | allocate space for that if we're not allocating space for anything | 3638 | allocate space for that if we're not allocating space for anything |
| 3632 | else (see below). Also, we never need info about register 0 for | 3639 | else (see below). Also, we never need info about register 0 for |
| @@ -3648,13 +3655,13 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3648 | 3655 | ||
| 3649 | #ifdef DEBUG | 3656 | #ifdef DEBUG |
| 3650 | /* Counts the total number of registers pushed. */ | 3657 | /* Counts the total number of registers pushed. */ |
| 3651 | unsigned num_regs_pushed = 0; | 3658 | unsigned num_regs_pushed = 0; |
| 3652 | #endif | 3659 | #endif |
| 3653 | 3660 | ||
| 3654 | DEBUG_PRINT1 ("\n\nEntering re_match_2.\n"); | 3661 | DEBUG_PRINT1 ("\n\nEntering re_match_2.\n"); |
| 3655 | 3662 | ||
| 3656 | INIT_FAIL_STACK (); | 3663 | INIT_FAIL_STACK (); |
| 3657 | 3664 | ||
| 3658 | #ifdef MATCH_MAY_ALLOCATE | 3665 | #ifdef MATCH_MAY_ALLOCATE |
| 3659 | /* Do not bother to initialize all the register variables if there are | 3666 | /* Do not bother to initialize all the register variables if there are |
| 3660 | no groups in the pattern, as it takes a fair amount of time. If | 3667 | no groups in the pattern, as it takes a fair amount of time. If |
| @@ -3673,8 +3680,8 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3673 | reg_dummy = REGEX_TALLOC (num_regs, const char *); | 3680 | reg_dummy = REGEX_TALLOC (num_regs, const char *); |
| 3674 | reg_info_dummy = REGEX_TALLOC (num_regs, register_info_type); | 3681 | reg_info_dummy = REGEX_TALLOC (num_regs, register_info_type); |
| 3675 | 3682 | ||
| 3676 | if (!(regstart && regend && old_regstart && old_regend && reg_info | 3683 | if (!(regstart && regend && old_regstart && old_regend && reg_info |
| 3677 | && best_regstart && best_regend && reg_dummy && reg_info_dummy)) | 3684 | && best_regstart && best_regend && reg_dummy && reg_info_dummy)) |
| 3678 | { | 3685 | { |
| 3679 | FREE_VARIABLES (); | 3686 | FREE_VARIABLES (); |
| 3680 | return -2; | 3687 | return -2; |
| @@ -3696,21 +3703,21 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3696 | FREE_VARIABLES (); | 3703 | FREE_VARIABLES (); |
| 3697 | return -1; | 3704 | return -1; |
| 3698 | } | 3705 | } |
| 3699 | 3706 | ||
| 3700 | /* Initialize subexpression text positions to -1 to mark ones that no | 3707 | /* Initialize subexpression text positions to -1 to mark ones that no |
| 3701 | start_memory/stop_memory has been seen for. Also initialize the | 3708 | start_memory/stop_memory has been seen for. Also initialize the |
| 3702 | register information struct. */ | 3709 | register information struct. */ |
| 3703 | for (mcnt = 1; mcnt < num_regs; mcnt++) | 3710 | for (mcnt = 1; mcnt < num_regs; mcnt++) |
| 3704 | { | 3711 | { |
| 3705 | regstart[mcnt] = regend[mcnt] | 3712 | regstart[mcnt] = regend[mcnt] |
| 3706 | = old_regstart[mcnt] = old_regend[mcnt] = REG_UNSET_VALUE; | 3713 | = old_regstart[mcnt] = old_regend[mcnt] = REG_UNSET_VALUE; |
| 3707 | 3714 | ||
| 3708 | REG_MATCH_NULL_STRING_P (reg_info[mcnt]) = MATCH_NULL_UNSET_VALUE; | 3715 | REG_MATCH_NULL_STRING_P (reg_info[mcnt]) = MATCH_NULL_UNSET_VALUE; |
| 3709 | IS_ACTIVE (reg_info[mcnt]) = 0; | 3716 | IS_ACTIVE (reg_info[mcnt]) = 0; |
| 3710 | MATCHED_SOMETHING (reg_info[mcnt]) = 0; | 3717 | MATCHED_SOMETHING (reg_info[mcnt]) = 0; |
| 3711 | EVER_MATCHED_SOMETHING (reg_info[mcnt]) = 0; | 3718 | EVER_MATCHED_SOMETHING (reg_info[mcnt]) = 0; |
| 3712 | } | 3719 | } |
| 3713 | 3720 | ||
| 3714 | /* We move `string1' into `string2' if the latter's empty -- but not if | 3721 | /* We move `string1' into `string2' if the latter's empty -- but not if |
| 3715 | `string1' is null. */ | 3722 | `string1' is null. */ |
| 3716 | if (size2 == 0 && string1 != NULL) | 3723 | if (size2 == 0 && string1 != NULL) |
| @@ -3735,7 +3742,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3735 | end_match_2 = string2 + stop - size1; | 3742 | end_match_2 = string2 + stop - size1; |
| 3736 | } | 3743 | } |
| 3737 | 3744 | ||
| 3738 | /* `p' scans through the pattern as `d' scans through the data. | 3745 | /* `p' scans through the pattern as `d' scans through the data. |
| 3739 | `dend' is the end of the input string that `d' points within. `d' | 3746 | `dend' is the end of the input string that `d' points within. `d' |
| 3740 | is advanced into the following input string whenever necessary, but | 3747 | is advanced into the following input string whenever necessary, but |
| 3741 | this happens before fetching; therefore, at the beginning of the | 3748 | this happens before fetching; therefore, at the beginning of the |
| @@ -3757,7 +3764,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3757 | DEBUG_PRINT1 ("The string to match is: `"); | 3764 | DEBUG_PRINT1 ("The string to match is: `"); |
| 3758 | DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2); | 3765 | DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2); |
| 3759 | DEBUG_PRINT1 ("'\n"); | 3766 | DEBUG_PRINT1 ("'\n"); |
| 3760 | 3767 | ||
| 3761 | /* This loops over pattern commands. It exits by returning from the | 3768 | /* This loops over pattern commands. It exits by returning from the |
| 3762 | function if the match is complete, or it drops through if the match | 3769 | function if the match is complete, or it drops through if the match |
| 3763 | fails at this starting point in the input data. */ | 3770 | fails at this starting point in the input data. */ |
| @@ -3768,14 +3775,14 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3768 | if (p == pend) | 3775 | if (p == pend) |
| 3769 | { /* End of pattern means we might have succeeded. */ | 3776 | { /* End of pattern means we might have succeeded. */ |
| 3770 | DEBUG_PRINT1 ("end of pattern ... "); | 3777 | DEBUG_PRINT1 ("end of pattern ... "); |
| 3771 | 3778 | ||
| 3772 | /* If we haven't matched the entire string, and we want the | 3779 | /* If we haven't matched the entire string, and we want the |
| 3773 | longest match, try backtracking. */ | 3780 | longest match, try backtracking. */ |
| 3774 | if (d != end_match_2) | 3781 | if (d != end_match_2) |
| 3775 | { | 3782 | { |
| 3776 | /* 1 if this match ends in the same string (string1 or string2) | 3783 | /* 1 if this match ends in the same string (string1 or string2) |
| 3777 | as the best previous match. */ | 3784 | as the best previous match. */ |
| 3778 | boolean same_str_p = (FIRST_STRING_P (match_end) | 3785 | boolean same_str_p = (FIRST_STRING_P (match_end) |
| 3779 | == MATCHING_IN_FIRST_STRING); | 3786 | == MATCHING_IN_FIRST_STRING); |
| 3780 | /* 1 if this match is the best seen so far. */ | 3787 | /* 1 if this match is the best seen so far. */ |
| 3781 | boolean best_match_p; | 3788 | boolean best_match_p; |
| @@ -3788,7 +3795,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3788 | best_match_p = !MATCHING_IN_FIRST_STRING; | 3795 | best_match_p = !MATCHING_IN_FIRST_STRING; |
| 3789 | 3796 | ||
| 3790 | DEBUG_PRINT1 ("backtracking.\n"); | 3797 | DEBUG_PRINT1 ("backtracking.\n"); |
| 3791 | 3798 | ||
| 3792 | if (!FAIL_STACK_EMPTY ()) | 3799 | if (!FAIL_STACK_EMPTY ()) |
| 3793 | { /* More failure points to try. */ | 3800 | { /* More failure points to try. */ |
| 3794 | 3801 | ||
| @@ -3797,16 +3804,16 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3797 | { | 3804 | { |
| 3798 | best_regs_set = true; | 3805 | best_regs_set = true; |
| 3799 | match_end = d; | 3806 | match_end = d; |
| 3800 | 3807 | ||
| 3801 | DEBUG_PRINT1 ("\nSAVING match as best so far.\n"); | 3808 | DEBUG_PRINT1 ("\nSAVING match as best so far.\n"); |
| 3802 | 3809 | ||
| 3803 | for (mcnt = 1; mcnt < num_regs; mcnt++) | 3810 | for (mcnt = 1; mcnt < num_regs; mcnt++) |
| 3804 | { | 3811 | { |
| 3805 | best_regstart[mcnt] = regstart[mcnt]; | 3812 | best_regstart[mcnt] = regstart[mcnt]; |
| 3806 | best_regend[mcnt] = regend[mcnt]; | 3813 | best_regend[mcnt] = regend[mcnt]; |
| 3807 | } | 3814 | } |
| 3808 | } | 3815 | } |
| 3809 | goto fail; | 3816 | goto fail; |
| 3810 | } | 3817 | } |
| 3811 | 3818 | ||
| 3812 | /* If no failure points, don't restore garbage. And if | 3819 | /* If no failure points, don't restore garbage. And if |
| @@ -3821,7 +3828,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3821 | strings `x-' and `y-z-', if the two strings are | 3828 | strings `x-' and `y-z-', if the two strings are |
| 3822 | not consecutive in memory. */ | 3829 | not consecutive in memory. */ |
| 3823 | DEBUG_PRINT1 ("Restoring best registers.\n"); | 3830 | DEBUG_PRINT1 ("Restoring best registers.\n"); |
| 3824 | 3831 | ||
| 3825 | d = match_end; | 3832 | d = match_end; |
| 3826 | dend = ((d >= string1 && d <= end1) | 3833 | dend = ((d >= string1 && d <= end1) |
| 3827 | ? end_match_1 : end_match_2); | 3834 | ? end_match_1 : end_match_2); |
| @@ -3888,7 +3895,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3888 | ? ((regoff_t) (d - string1)) | 3895 | ? ((regoff_t) (d - string1)) |
| 3889 | : ((regoff_t) (d - string2 + size1))); | 3896 | : ((regoff_t) (d - string2 + size1))); |
| 3890 | } | 3897 | } |
| 3891 | 3898 | ||
| 3892 | /* Go through the first `min (num_regs, regs->num_regs)' | 3899 | /* Go through the first `min (num_regs, regs->num_regs)' |
| 3893 | registers, since that is all we initialized. */ | 3900 | registers, since that is all we initialized. */ |
| 3894 | for (mcnt = 1; mcnt < MIN (num_regs, regs->num_regs); mcnt++) | 3901 | for (mcnt = 1; mcnt < MIN (num_regs, regs->num_regs); mcnt++) |
| @@ -3903,7 +3910,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3903 | = (regoff_t) POINTER_TO_OFFSET (regend[mcnt]); | 3910 | = (regoff_t) POINTER_TO_OFFSET (regend[mcnt]); |
| 3904 | } | 3911 | } |
| 3905 | } | 3912 | } |
| 3906 | 3913 | ||
| 3907 | /* If the regs structure we return has more elements than | 3914 | /* If the regs structure we return has more elements than |
| 3908 | were in the pattern, set the extra elements to -1. If | 3915 | were in the pattern, set the extra elements to -1. If |
| 3909 | we (re)allocated the registers, this is the case, | 3916 | we (re)allocated the registers, this is the case, |
| @@ -3918,8 +3925,8 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3918 | nfailure_points_pushed - nfailure_points_popped); | 3925 | nfailure_points_pushed - nfailure_points_popped); |
| 3919 | DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed); | 3926 | DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed); |
| 3920 | 3927 | ||
| 3921 | mcnt = d - pos - (MATCHING_IN_FIRST_STRING | 3928 | mcnt = d - pos - (MATCHING_IN_FIRST_STRING |
| 3922 | ? string1 | 3929 | ? string1 |
| 3923 | : string2 - size1); | 3930 | : string2 - size1); |
| 3924 | 3931 | ||
| 3925 | DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt); | 3932 | DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt); |
| @@ -4010,7 +4017,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4010 | p += 1 + *p; | 4017 | p += 1 + *p; |
| 4011 | 4018 | ||
| 4012 | if (!not) goto fail; | 4019 | if (!not) goto fail; |
| 4013 | 4020 | ||
| 4014 | SET_REGS_MATCHED (); | 4021 | SET_REGS_MATCHED (); |
| 4015 | d++; | 4022 | d++; |
| 4016 | break; | 4023 | break; |
| @@ -4027,9 +4034,9 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4027 | 4034 | ||
| 4028 | /* Find out if this group can match the empty string. */ | 4035 | /* Find out if this group can match the empty string. */ |
| 4029 | p1 = p; /* To send to group_match_null_string_p. */ | 4036 | p1 = p; /* To send to group_match_null_string_p. */ |
| 4030 | 4037 | ||
| 4031 | if (REG_MATCH_NULL_STRING_P (reg_info[*p]) == MATCH_NULL_UNSET_VALUE) | 4038 | if (REG_MATCH_NULL_STRING_P (reg_info[*p]) == MATCH_NULL_UNSET_VALUE) |
| 4032 | REG_MATCH_NULL_STRING_P (reg_info[*p]) | 4039 | REG_MATCH_NULL_STRING_P (reg_info[*p]) |
| 4033 | = group_match_null_string_p (&p1, pend, reg_info); | 4040 | = group_match_null_string_p (&p1, pend, reg_info); |
| 4034 | 4041 | ||
| 4035 | /* Save the position in the string where we were the last time | 4042 | /* Save the position in the string where we were the last time |
| @@ -4040,7 +4047,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4040 | old_regstart[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p]) | 4047 | old_regstart[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p]) |
| 4041 | ? REG_UNSET (regstart[*p]) ? d : regstart[*p] | 4048 | ? REG_UNSET (regstart[*p]) ? d : regstart[*p] |
| 4042 | : regstart[*p]; | 4049 | : regstart[*p]; |
| 4043 | DEBUG_PRINT2 (" old_regstart: %d\n", | 4050 | DEBUG_PRINT2 (" old_regstart: %d\n", |
| 4044 | POINTER_TO_OFFSET (old_regstart[*p])); | 4051 | POINTER_TO_OFFSET (old_regstart[*p])); |
| 4045 | 4052 | ||
| 4046 | regstart[*p] = d; | 4053 | regstart[*p] = d; |
| @@ -4051,10 +4058,10 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4051 | 4058 | ||
| 4052 | /* Clear this whenever we change the register activity status. */ | 4059 | /* Clear this whenever we change the register activity status. */ |
| 4053 | set_regs_matched_done = 0; | 4060 | set_regs_matched_done = 0; |
| 4054 | 4061 | ||
| 4055 | /* This is the new highest active register. */ | 4062 | /* This is the new highest active register. */ |
| 4056 | highest_active_reg = *p; | 4063 | highest_active_reg = *p; |
| 4057 | 4064 | ||
| 4058 | /* If nothing was active before, this is the new lowest active | 4065 | /* If nothing was active before, this is the new lowest active |
| 4059 | register. */ | 4066 | register. */ |
| 4060 | if (lowest_active_reg == NO_LOWEST_ACTIVE_REG) | 4067 | if (lowest_active_reg == NO_LOWEST_ACTIVE_REG) |
| @@ -4072,7 +4079,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4072 | number, and the number of inner groups. */ | 4079 | number, and the number of inner groups. */ |
| 4073 | case stop_memory: | 4080 | case stop_memory: |
| 4074 | DEBUG_PRINT3 ("EXECUTING stop_memory %d (%d):\n", *p, p[1]); | 4081 | DEBUG_PRINT3 ("EXECUTING stop_memory %d (%d):\n", *p, p[1]); |
| 4075 | 4082 | ||
| 4076 | /* We need to save the string position the last time we were at | 4083 | /* We need to save the string position the last time we were at |
| 4077 | this close-group operator in case the group is operated | 4084 | this close-group operator in case the group is operated |
| 4078 | upon by a repetition operator, e.g., with `((a*)*(b*)*)*' | 4085 | upon by a repetition operator, e.g., with `((a*)*(b*)*)*' |
| @@ -4081,7 +4088,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4081 | old_regend[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p]) | 4088 | old_regend[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p]) |
| 4082 | ? REG_UNSET (regend[*p]) ? d : regend[*p] | 4089 | ? REG_UNSET (regend[*p]) ? d : regend[*p] |
| 4083 | : regend[*p]; | 4090 | : regend[*p]; |
| 4084 | DEBUG_PRINT2 (" old_regend: %d\n", | 4091 | DEBUG_PRINT2 (" old_regend: %d\n", |
| 4085 | POINTER_TO_OFFSET (old_regend[*p])); | 4092 | POINTER_TO_OFFSET (old_regend[*p])); |
| 4086 | 4093 | ||
| 4087 | regend[*p] = d; | 4094 | regend[*p] = d; |
| @@ -4108,7 +4115,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4108 | unsigned char r = *p - 1; | 4115 | unsigned char r = *p - 1; |
| 4109 | while (r > 0 && !IS_ACTIVE (reg_info[r])) | 4116 | while (r > 0 && !IS_ACTIVE (reg_info[r])) |
| 4110 | r--; | 4117 | r--; |
| 4111 | 4118 | ||
| 4112 | /* If we end up at register zero, that means that we saved | 4119 | /* If we end up at register zero, that means that we saved |
| 4113 | the registers as the result of an `on_failure_jump', not | 4120 | the registers as the result of an `on_failure_jump', not |
| 4114 | a `start_memory', and we jumped to past the innermost | 4121 | a `start_memory', and we jumped to past the innermost |
| @@ -4124,7 +4131,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4124 | else | 4131 | else |
| 4125 | highest_active_reg = r; | 4132 | highest_active_reg = r; |
| 4126 | } | 4133 | } |
| 4127 | 4134 | ||
| 4128 | /* If just failed to match something this time around with a | 4135 | /* If just failed to match something this time around with a |
| 4129 | group that's operated on by a repetition operator, try to | 4136 | group that's operated on by a repetition operator, try to |
| 4130 | force exit from the ``loop'', and restore the register | 4137 | force exit from the ``loop'', and restore the register |
| @@ -4132,10 +4139,10 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4132 | last match. */ | 4139 | last match. */ |
| 4133 | if ((!MATCHED_SOMETHING (reg_info[*p]) | 4140 | if ((!MATCHED_SOMETHING (reg_info[*p]) |
| 4134 | || just_past_start_mem == p - 1) | 4141 | || just_past_start_mem == p - 1) |
| 4135 | && (p + 2) < pend) | 4142 | && (p + 2) < pend) |
| 4136 | { | 4143 | { |
| 4137 | boolean is_a_jump_n = false; | 4144 | boolean is_a_jump_n = false; |
| 4138 | 4145 | ||
| 4139 | p1 = p + 2; | 4146 | p1 = p + 2; |
| 4140 | mcnt = 0; | 4147 | mcnt = 0; |
| 4141 | switch ((re_opcode_t) *p1++) | 4148 | switch ((re_opcode_t) *p1++) |
| @@ -4150,12 +4157,12 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4150 | if (is_a_jump_n) | 4157 | if (is_a_jump_n) |
| 4151 | p1 += 2; | 4158 | p1 += 2; |
| 4152 | break; | 4159 | break; |
| 4153 | 4160 | ||
| 4154 | default: | 4161 | default: |
| 4155 | /* do nothing */ ; | 4162 | /* do nothing */ ; |
| 4156 | } | 4163 | } |
| 4157 | p1 += mcnt; | 4164 | p1 += mcnt; |
| 4158 | 4165 | ||
| 4159 | /* If the next operation is a jump backwards in the pattern | 4166 | /* If the next operation is a jump backwards in the pattern |
| 4160 | to an on_failure_jump right before the start_memory | 4167 | to an on_failure_jump right before the start_memory |
| 4161 | corresponding to this stop_memory, exit from the loop | 4168 | corresponding to this stop_memory, exit from the loop |
| @@ -4169,17 +4176,17 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4169 | failed match, e.g., with `(a*)*b' against `ab' for | 4176 | failed match, e.g., with `(a*)*b' against `ab' for |
| 4170 | regstart[1], and, e.g., with `((a*)*(b*)*)*' | 4177 | regstart[1], and, e.g., with `((a*)*(b*)*)*' |
| 4171 | against `aba' for regend[3]. | 4178 | against `aba' for regend[3]. |
| 4172 | 4179 | ||
| 4173 | Also restore the registers for inner groups for, | 4180 | Also restore the registers for inner groups for, |
| 4174 | e.g., `((a*)(b*))*' against `aba' (register 3 would | 4181 | e.g., `((a*)(b*))*' against `aba' (register 3 would |
| 4175 | otherwise get trashed). */ | 4182 | otherwise get trashed). */ |
| 4176 | 4183 | ||
| 4177 | if (EVER_MATCHED_SOMETHING (reg_info[*p])) | 4184 | if (EVER_MATCHED_SOMETHING (reg_info[*p])) |
| 4178 | { | 4185 | { |
| 4179 | unsigned r; | 4186 | unsigned r; |
| 4180 | 4187 | ||
| 4181 | EVER_MATCHED_SOMETHING (reg_info[*p]) = 0; | 4188 | EVER_MATCHED_SOMETHING (reg_info[*p]) = 0; |
| 4182 | 4189 | ||
| 4183 | /* Restore this and inner groups' (if any) registers. */ | 4190 | /* Restore this and inner groups' (if any) registers. */ |
| 4184 | for (r = *p; r < *p + *(p + 1); r++) | 4191 | for (r = *p; r < *p + *(p + 1); r++) |
| 4185 | { | 4192 | { |
| @@ -4188,7 +4195,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4188 | /* xx why this test? */ | 4195 | /* xx why this test? */ |
| 4189 | if (old_regend[r] >= regstart[r]) | 4196 | if (old_regend[r] >= regstart[r]) |
| 4190 | regend[r] = old_regend[r]; | 4197 | regend[r] = old_regend[r]; |
| 4191 | } | 4198 | } |
| 4192 | } | 4199 | } |
| 4193 | p1++; | 4200 | p1++; |
| 4194 | EXTRACT_NUMBER_AND_INCR (mcnt, p1); | 4201 | EXTRACT_NUMBER_AND_INCR (mcnt, p1); |
| @@ -4197,7 +4204,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4197 | goto fail; | 4204 | goto fail; |
| 4198 | } | 4205 | } |
| 4199 | } | 4206 | } |
| 4200 | 4207 | ||
| 4201 | /* Move past the register number and the inner group count. */ | 4208 | /* Move past the register number and the inner group count. */ |
| 4202 | p += 2; | 4209 | p += 2; |
| 4203 | break; | 4210 | break; |
| @@ -4214,16 +4221,16 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4214 | /* Can't back reference a group which we've never matched. */ | 4221 | /* Can't back reference a group which we've never matched. */ |
| 4215 | if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno])) | 4222 | if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno])) |
| 4216 | goto fail; | 4223 | goto fail; |
| 4217 | 4224 | ||
| 4218 | /* Where in input to try to start matching. */ | 4225 | /* Where in input to try to start matching. */ |
| 4219 | d2 = regstart[regno]; | 4226 | d2 = regstart[regno]; |
| 4220 | 4227 | ||
| 4221 | /* Where to stop matching; if both the place to start and | 4228 | /* Where to stop matching; if both the place to start and |
| 4222 | the place to stop matching are in the same string, then | 4229 | the place to stop matching are in the same string, then |
| 4223 | set to the place to stop, otherwise, for now have to use | 4230 | set to the place to stop, otherwise, for now have to use |
| 4224 | the end of the first string. */ | 4231 | the end of the first string. */ |
| 4225 | 4232 | ||
| 4226 | dend2 = ((FIRST_STRING_P (regstart[regno]) | 4233 | dend2 = ((FIRST_STRING_P (regstart[regno]) |
| 4227 | == FIRST_STRING_P (regend[regno])) | 4234 | == FIRST_STRING_P (regend[regno])) |
| 4228 | ? regend[regno] : end_match_1); | 4235 | ? regend[regno] : end_match_1); |
| 4229 | for (;;) | 4236 | for (;;) |
| @@ -4247,16 +4254,16 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4247 | 4254 | ||
| 4248 | /* How many characters left in this segment to match. */ | 4255 | /* How many characters left in this segment to match. */ |
| 4249 | mcnt = dend - d; | 4256 | mcnt = dend - d; |
| 4250 | 4257 | ||
| 4251 | /* Want how many consecutive characters we can match in | 4258 | /* Want how many consecutive characters we can match in |
| 4252 | one shot, so, if necessary, adjust the count. */ | 4259 | one shot, so, if necessary, adjust the count. */ |
| 4253 | if (mcnt > dend2 - d2) | 4260 | if (mcnt > dend2 - d2) |
| 4254 | mcnt = dend2 - d2; | 4261 | mcnt = dend2 - d2; |
| 4255 | 4262 | ||
| 4256 | /* Compare that many; failure if mismatch, else move | 4263 | /* Compare that many; failure if mismatch, else move |
| 4257 | past them. */ | 4264 | past them. */ |
| 4258 | if (translate | 4265 | if (translate |
| 4259 | ? bcmp_translate (d, d2, mcnt, translate) | 4266 | ? bcmp_translate (d, d2, mcnt, translate) |
| 4260 | : bcmp (d, d2, mcnt)) | 4267 | : bcmp (d, d2, mcnt)) |
| 4261 | goto fail; | 4268 | goto fail; |
| 4262 | d += mcnt, d2 += mcnt; | 4269 | d += mcnt, d2 += mcnt; |
| @@ -4273,7 +4280,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4273 | `newline_anchor' is set, after newlines. */ | 4280 | `newline_anchor' is set, after newlines. */ |
| 4274 | case begline: | 4281 | case begline: |
| 4275 | DEBUG_PRINT1 ("EXECUTING begline.\n"); | 4282 | DEBUG_PRINT1 ("EXECUTING begline.\n"); |
| 4276 | 4283 | ||
| 4277 | if (AT_STRINGS_BEG (d)) | 4284 | if (AT_STRINGS_BEG (d)) |
| 4278 | { | 4285 | { |
| 4279 | if (!bufp->not_bol) break; | 4286 | if (!bufp->not_bol) break; |
| @@ -4294,7 +4301,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4294 | { | 4301 | { |
| 4295 | if (!bufp->not_eol) break; | 4302 | if (!bufp->not_eol) break; |
| 4296 | } | 4303 | } |
| 4297 | 4304 | ||
| 4298 | /* We have to ``prefetch'' the next character. */ | 4305 | /* We have to ``prefetch'' the next character. */ |
| 4299 | else if ((d == end1 ? *string2 : *d) == '\n' | 4306 | else if ((d == end1 ? *string2 : *d) == '\n' |
| 4300 | && bufp->newline_anchor) | 4307 | && bufp->newline_anchor) |
| @@ -4328,7 +4335,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4328 | then the . fails against the \n. But the next thing we want | 4335 | then the . fails against the \n. But the next thing we want |
| 4329 | to do is match the \n against the \n; if we restored the | 4336 | to do is match the \n against the \n; if we restored the |
| 4330 | string value, we would be back at the foo. | 4337 | string value, we would be back at the foo. |
| 4331 | 4338 | ||
| 4332 | Because this is used only in specific cases, we don't need to | 4339 | Because this is used only in specific cases, we don't need to |
| 4333 | check all the things that `on_failure_jump' does, to make | 4340 | check all the things that `on_failure_jump' does, to make |
| 4334 | sure the right things get saved on the stack. Hence we don't | 4341 | sure the right things get saved on the stack. Hence we don't |
| @@ -4338,7 +4345,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4338 | case; that seems worse than this. */ | 4345 | case; that seems worse than this. */ |
| 4339 | case on_failure_keep_string_jump: | 4346 | case on_failure_keep_string_jump: |
| 4340 | DEBUG_PRINT1 ("EXECUTING on_failure_keep_string_jump"); | 4347 | DEBUG_PRINT1 ("EXECUTING on_failure_keep_string_jump"); |
| 4341 | 4348 | ||
| 4342 | EXTRACT_NUMBER_AND_INCR (mcnt, p); | 4349 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 4343 | DEBUG_PRINT3 (" %d (to 0x%x):\n", mcnt, p + mcnt); | 4350 | DEBUG_PRINT3 (" %d (to 0x%x):\n", mcnt, p + mcnt); |
| 4344 | 4351 | ||
| @@ -4347,7 +4354,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4347 | 4354 | ||
| 4348 | 4355 | ||
| 4349 | /* Uses of on_failure_jump: | 4356 | /* Uses of on_failure_jump: |
| 4350 | 4357 | ||
| 4351 | Each alternative starts with an on_failure_jump that points | 4358 | Each alternative starts with an on_failure_jump that points |
| 4352 | to the beginning of the next alternative. Each alternative | 4359 | to the beginning of the next alternative. Each alternative |
| 4353 | except the last ends with a jump that in effect jumps past | 4360 | except the last ends with a jump that in effect jumps past |
| @@ -4413,7 +4420,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4413 | would have to backtrack because of (as in, e.g., `a*a') | 4420 | would have to backtrack because of (as in, e.g., `a*a') |
| 4414 | then we can change to pop_failure_jump, because we'll | 4421 | then we can change to pop_failure_jump, because we'll |
| 4415 | never have to backtrack. | 4422 | never have to backtrack. |
| 4416 | 4423 | ||
| 4417 | This is not true in the case of alternatives: in | 4424 | This is not true in the case of alternatives: in |
| 4418 | `(a|ab)*' we do need to backtrack to the `ab' alternative | 4425 | `(a|ab)*' we do need to backtrack to the `ab' alternative |
| 4419 | (e.g., if the string was `ab'). But instead of trying to | 4426 | (e.g., if the string was `ab'). But instead of trying to |
| @@ -4439,7 +4446,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4439 | 4446 | ||
| 4440 | p1 = p + mcnt; | 4447 | p1 = p + mcnt; |
| 4441 | /* p1[0] ... p1[2] are the `on_failure_jump' corresponding | 4448 | /* p1[0] ... p1[2] are the `on_failure_jump' corresponding |
| 4442 | to the `maybe_finalize_jump' of this case. Examine what | 4449 | to the `maybe_finalize_jump' of this case. Examine what |
| 4443 | follows. */ | 4450 | follows. */ |
| 4444 | 4451 | ||
| 4445 | /* If we're at the end of the pattern, we can change. */ | 4452 | /* If we're at the end of the pattern, we can change. */ |
| @@ -4465,12 +4472,12 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4465 | DEBUG_PRINT3 (" %c != %c => pop_failure_jump.\n", | 4472 | DEBUG_PRINT3 (" %c != %c => pop_failure_jump.\n", |
| 4466 | c, p1[5]); | 4473 | c, p1[5]); |
| 4467 | } | 4474 | } |
| 4468 | 4475 | ||
| 4469 | else if ((re_opcode_t) p1[3] == charset | 4476 | else if ((re_opcode_t) p1[3] == charset |
| 4470 | || (re_opcode_t) p1[3] == charset_not) | 4477 | || (re_opcode_t) p1[3] == charset_not) |
| 4471 | { | 4478 | { |
| 4472 | int not = (re_opcode_t) p1[3] == charset_not; | 4479 | int not = (re_opcode_t) p1[3] == charset_not; |
| 4473 | 4480 | ||
| 4474 | if (c < (unsigned char) (p1[4] * BYTEWIDTH) | 4481 | if (c < (unsigned char) (p1[4] * BYTEWIDTH) |
| 4475 | && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) | 4482 | && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) |
| 4476 | not = !not; | 4483 | not = !not; |
| @@ -4500,7 +4507,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4500 | DEBUG_PRINT3 (" %c != %c => pop_failure_jump.\n", | 4507 | DEBUG_PRINT3 (" %c != %c => pop_failure_jump.\n", |
| 4501 | c, p1[5]); | 4508 | c, p1[5]); |
| 4502 | } | 4509 | } |
| 4503 | 4510 | ||
| 4504 | else if ((re_opcode_t) p1[3] == charset_not) | 4511 | else if ((re_opcode_t) p1[3] == charset_not) |
| 4505 | { | 4512 | { |
| 4506 | int idx; | 4513 | int idx; |
| @@ -4571,7 +4578,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4571 | } | 4578 | } |
| 4572 | /* Note fall through. */ | 4579 | /* Note fall through. */ |
| 4573 | 4580 | ||
| 4574 | 4581 | ||
| 4575 | /* Unconditionally jump (without popping any failure points). */ | 4582 | /* Unconditionally jump (without popping any failure points). */ |
| 4576 | case jump: | 4583 | case jump: |
| 4577 | unconditional_jump: | 4584 | unconditional_jump: |
| @@ -4581,7 +4588,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4581 | DEBUG_PRINT2 ("(to 0x%x).\n", p); | 4588 | DEBUG_PRINT2 ("(to 0x%x).\n", p); |
| 4582 | break; | 4589 | break; |
| 4583 | 4590 | ||
| 4584 | 4591 | ||
| 4585 | /* We need this opcode so we can detect where alternatives end | 4592 | /* We need this opcode so we can detect where alternatives end |
| 4586 | in `group_match_null_string_p' et al. */ | 4593 | in `group_match_null_string_p' et al. */ |
| 4587 | case jump_past_alt: | 4594 | case jump_past_alt: |
| @@ -4616,7 +4623,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4616 | 4623 | ||
| 4617 | /* Have to succeed matching what follows at least n times. | 4624 | /* Have to succeed matching what follows at least n times. |
| 4618 | After that, handle like `on_failure_jump'. */ | 4625 | After that, handle like `on_failure_jump'. */ |
| 4619 | case succeed_n: | 4626 | case succeed_n: |
| 4620 | EXTRACT_NUMBER (mcnt, p + 2); | 4627 | EXTRACT_NUMBER (mcnt, p + 2); |
| 4621 | DEBUG_PRINT2 ("EXECUTING succeed_n %d.\n", mcnt); | 4628 | DEBUG_PRINT2 ("EXECUTING succeed_n %d.\n", mcnt); |
| 4622 | 4629 | ||
| @@ -4637,8 +4644,8 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4637 | goto on_failure; | 4644 | goto on_failure; |
| 4638 | } | 4645 | } |
| 4639 | break; | 4646 | break; |
| 4640 | 4647 | ||
| 4641 | case jump_n: | 4648 | case jump_n: |
| 4642 | EXTRACT_NUMBER (mcnt, p + 2); | 4649 | EXTRACT_NUMBER (mcnt, p + 2); |
| 4643 | DEBUG_PRINT2 ("EXECUTING jump_n %d.\n", mcnt); | 4650 | DEBUG_PRINT2 ("EXECUTING jump_n %d.\n", mcnt); |
| 4644 | 4651 | ||
| @@ -4647,13 +4654,13 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4647 | { | 4654 | { |
| 4648 | mcnt--; | 4655 | mcnt--; |
| 4649 | STORE_NUMBER (p + 2, mcnt); | 4656 | STORE_NUMBER (p + 2, mcnt); |
| 4650 | goto unconditional_jump; | 4657 | goto unconditional_jump; |
| 4651 | } | 4658 | } |
| 4652 | /* If don't have to jump any more, skip over the rest of command. */ | 4659 | /* If don't have to jump any more, skip over the rest of command. */ |
| 4653 | else | 4660 | else |
| 4654 | p += 4; | 4661 | p += 4; |
| 4655 | break; | 4662 | break; |
| 4656 | 4663 | ||
| 4657 | case set_number_at: | 4664 | case set_number_at: |
| 4658 | { | 4665 | { |
| 4659 | DEBUG_PRINT1 ("EXECUTING set_number_at.\n"); | 4666 | DEBUG_PRINT1 ("EXECUTING set_number_at.\n"); |
| @@ -4697,13 +4704,13 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4697 | if (PTR_CHAR_POS ((unsigned char *) d) >= point) | 4704 | if (PTR_CHAR_POS ((unsigned char *) d) >= point) |
| 4698 | goto fail; | 4705 | goto fail; |
| 4699 | break; | 4706 | break; |
| 4700 | 4707 | ||
| 4701 | case at_dot: | 4708 | case at_dot: |
| 4702 | DEBUG_PRINT1 ("EXECUTING at_dot.\n"); | 4709 | DEBUG_PRINT1 ("EXECUTING at_dot.\n"); |
| 4703 | if (PTR_CHAR_POS ((unsigned char *) d) != point) | 4710 | if (PTR_CHAR_POS ((unsigned char *) d) != point) |
| 4704 | goto fail; | 4711 | goto fail; |
| 4705 | break; | 4712 | break; |
| 4706 | 4713 | ||
| 4707 | case after_dot: | 4714 | case after_dot: |
| 4708 | DEBUG_PRINT1 ("EXECUTING after_dot.\n"); | 4715 | DEBUG_PRINT1 ("EXECUTING after_dot.\n"); |
| 4709 | if (PTR_CHAR_POS ((unsigned char *) d) <= point) | 4716 | if (PTR_CHAR_POS ((unsigned char *) d) <= point) |
| @@ -4753,7 +4760,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4753 | SET_REGS_MATCHED (); | 4760 | SET_REGS_MATCHED (); |
| 4754 | d++; | 4761 | d++; |
| 4755 | break; | 4762 | break; |
| 4756 | 4763 | ||
| 4757 | case notwordchar: | 4764 | case notwordchar: |
| 4758 | DEBUG_PRINT1 ("EXECUTING non-Emacs notwordchar.\n"); | 4765 | DEBUG_PRINT1 ("EXECUTING non-Emacs notwordchar.\n"); |
| 4759 | PREFETCH (); | 4766 | PREFETCH (); |
| @@ -4763,7 +4770,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4763 | d++; | 4770 | d++; |
| 4764 | break; | 4771 | break; |
| 4765 | #endif /* not emacs */ | 4772 | #endif /* not emacs */ |
| 4766 | 4773 | ||
| 4767 | default: | 4774 | default: |
| 4768 | abort (); | 4775 | abort (); |
| 4769 | } | 4776 | } |
| @@ -4788,7 +4795,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4788 | if (p < pend) | 4795 | if (p < pend) |
| 4789 | { | 4796 | { |
| 4790 | boolean is_a_jump_n = false; | 4797 | boolean is_a_jump_n = false; |
| 4791 | 4798 | ||
| 4792 | /* If failed to a backwards jump that's part of a repetition | 4799 | /* If failed to a backwards jump that's part of a repetition |
| 4793 | loop, need to pop this failure point and use the next one. */ | 4800 | loop, need to pop this failure point and use the next one. */ |
| 4794 | switch ((re_opcode_t) *p) | 4801 | switch ((re_opcode_t) *p) |
| @@ -4800,7 +4807,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4800 | case jump: | 4807 | case jump: |
| 4801 | p1 = p + 1; | 4808 | p1 = p + 1; |
| 4802 | EXTRACT_NUMBER_AND_INCR (mcnt, p1); | 4809 | EXTRACT_NUMBER_AND_INCR (mcnt, p1); |
| 4803 | p1 += mcnt; | 4810 | p1 += mcnt; |
| 4804 | 4811 | ||
| 4805 | if ((is_a_jump_n && (re_opcode_t) *p1 == succeed_n) | 4812 | if ((is_a_jump_n && (re_opcode_t) *p1 == succeed_n) |
| 4806 | || (!is_a_jump_n | 4813 | || (!is_a_jump_n |
| @@ -4831,10 +4838,10 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 4831 | 4838 | ||
| 4832 | 4839 | ||
| 4833 | /* We are passed P pointing to a register number after a start_memory. | 4840 | /* We are passed P pointing to a register number after a start_memory. |
| 4834 | 4841 | ||
| 4835 | Return true if the pattern up to the corresponding stop_memory can | 4842 | Return true if the pattern up to the corresponding stop_memory can |
| 4836 | match the empty string, and false otherwise. | 4843 | match the empty string, and false otherwise. |
| 4837 | 4844 | ||
| 4838 | If we find the matching stop_memory, sets P to point to one past its number. | 4845 | If we find the matching stop_memory, sets P to point to one past its number. |
| 4839 | Otherwise, sets P to an undefined byte less than or equal to END. | 4846 | Otherwise, sets P to an undefined byte less than or equal to END. |
| 4840 | 4847 | ||
| @@ -4848,20 +4855,20 @@ group_match_null_string_p (p, end, reg_info) | |||
| 4848 | int mcnt; | 4855 | int mcnt; |
| 4849 | /* Point to after the args to the start_memory. */ | 4856 | /* Point to after the args to the start_memory. */ |
| 4850 | unsigned char *p1 = *p + 2; | 4857 | unsigned char *p1 = *p + 2; |
| 4851 | 4858 | ||
| 4852 | while (p1 < end) | 4859 | while (p1 < end) |
| 4853 | { | 4860 | { |
| 4854 | /* Skip over opcodes that can match nothing, and return true or | 4861 | /* Skip over opcodes that can match nothing, and return true or |
| 4855 | false, as appropriate, when we get to one that can't, or to the | 4862 | false, as appropriate, when we get to one that can't, or to the |
| 4856 | matching stop_memory. */ | 4863 | matching stop_memory. */ |
| 4857 | 4864 | ||
| 4858 | switch ((re_opcode_t) *p1) | 4865 | switch ((re_opcode_t) *p1) |
| 4859 | { | 4866 | { |
| 4860 | /* Could be either a loop or a series of alternatives. */ | 4867 | /* Could be either a loop or a series of alternatives. */ |
| 4861 | case on_failure_jump: | 4868 | case on_failure_jump: |
| 4862 | p1++; | 4869 | p1++; |
| 4863 | EXTRACT_NUMBER_AND_INCR (mcnt, p1); | 4870 | EXTRACT_NUMBER_AND_INCR (mcnt, p1); |
| 4864 | 4871 | ||
| 4865 | /* If the next operation is not a jump backwards in the | 4872 | /* If the next operation is not a jump backwards in the |
| 4866 | pattern. */ | 4873 | pattern. */ |
| 4867 | 4874 | ||
| @@ -4875,7 +4882,7 @@ group_match_null_string_p (p, end, reg_info) | |||
| 4875 | 4882 | ||
| 4876 | /on_failure_jump/0/6/exactn/1/a/jump_past_alt/0/6 | 4883 | /on_failure_jump/0/6/exactn/1/a/jump_past_alt/0/6 |
| 4877 | /on_failure_jump/0/6/exactn/1/b/jump_past_alt/0/3 | 4884 | /on_failure_jump/0/6/exactn/1/b/jump_past_alt/0/3 |
| 4878 | /exactn/1/c | 4885 | /exactn/1/c |
| 4879 | 4886 | ||
| 4880 | So, we have to first go through the first (n-1) | 4887 | So, we have to first go through the first (n-1) |
| 4881 | alternatives and then deal with the last one separately. */ | 4888 | alternatives and then deal with the last one separately. */ |
| @@ -4891,19 +4898,19 @@ group_match_null_string_p (p, end, reg_info) | |||
| 4891 | is, including the ending `jump_past_alt' and | 4898 | is, including the ending `jump_past_alt' and |
| 4892 | its number. */ | 4899 | its number. */ |
| 4893 | 4900 | ||
| 4894 | if (!alt_match_null_string_p (p1, p1 + mcnt - 3, | 4901 | if (!alt_match_null_string_p (p1, p1 + mcnt - 3, |
| 4895 | reg_info)) | 4902 | reg_info)) |
| 4896 | return false; | 4903 | return false; |
| 4897 | 4904 | ||
| 4898 | /* Move to right after this alternative, including the | 4905 | /* Move to right after this alternative, including the |
| 4899 | jump_past_alt. */ | 4906 | jump_past_alt. */ |
| 4900 | p1 += mcnt; | 4907 | p1 += mcnt; |
| 4901 | 4908 | ||
| 4902 | /* Break if it's the beginning of an n-th alternative | 4909 | /* Break if it's the beginning of an n-th alternative |
| 4903 | that doesn't begin with an on_failure_jump. */ | 4910 | that doesn't begin with an on_failure_jump. */ |
| 4904 | if ((re_opcode_t) *p1 != on_failure_jump) | 4911 | if ((re_opcode_t) *p1 != on_failure_jump) |
| 4905 | break; | 4912 | break; |
| 4906 | 4913 | ||
| 4907 | /* Still have to check that it's not an n-th | 4914 | /* Still have to check that it's not an n-th |
| 4908 | alternative that starts with an on_failure_jump. */ | 4915 | alternative that starts with an on_failure_jump. */ |
| 4909 | p1++; | 4916 | p1++; |
| @@ -4928,14 +4935,14 @@ group_match_null_string_p (p, end, reg_info) | |||
| 4928 | } /* if mcnt > 0 */ | 4935 | } /* if mcnt > 0 */ |
| 4929 | break; | 4936 | break; |
| 4930 | 4937 | ||
| 4931 | 4938 | ||
| 4932 | case stop_memory: | 4939 | case stop_memory: |
| 4933 | assert (p1[1] == **p); | 4940 | assert (p1[1] == **p); |
| 4934 | *p = p1 + 2; | 4941 | *p = p1 + 2; |
| 4935 | return true; | 4942 | return true; |
| 4936 | 4943 | ||
| 4937 | 4944 | ||
| 4938 | default: | 4945 | default: |
| 4939 | if (!common_op_match_null_string_p (&p1, end, reg_info)) | 4946 | if (!common_op_match_null_string_p (&p1, end, reg_info)) |
| 4940 | return false; | 4947 | return false; |
| 4941 | } | 4948 | } |
| @@ -4948,7 +4955,7 @@ group_match_null_string_p (p, end, reg_info) | |||
| 4948 | /* Similar to group_match_null_string_p, but doesn't deal with alternatives: | 4955 | /* Similar to group_match_null_string_p, but doesn't deal with alternatives: |
| 4949 | It expects P to be the first byte of a single alternative and END one | 4956 | It expects P to be the first byte of a single alternative and END one |
| 4950 | byte past the last. The alternative can contain groups. */ | 4957 | byte past the last. The alternative can contain groups. */ |
| 4951 | 4958 | ||
| 4952 | static boolean | 4959 | static boolean |
| 4953 | alt_match_null_string_p (p, end, reg_info) | 4960 | alt_match_null_string_p (p, end, reg_info) |
| 4954 | unsigned char *p, *end; | 4961 | unsigned char *p, *end; |
| @@ -4956,12 +4963,12 @@ alt_match_null_string_p (p, end, reg_info) | |||
| 4956 | { | 4963 | { |
| 4957 | int mcnt; | 4964 | int mcnt; |
| 4958 | unsigned char *p1 = p; | 4965 | unsigned char *p1 = p; |
| 4959 | 4966 | ||
| 4960 | while (p1 < end) | 4967 | while (p1 < end) |
| 4961 | { | 4968 | { |
| 4962 | /* Skip over opcodes that can match nothing, and break when we get | 4969 | /* Skip over opcodes that can match nothing, and break when we get |
| 4963 | to one that can't. */ | 4970 | to one that can't. */ |
| 4964 | 4971 | ||
| 4965 | switch ((re_opcode_t) *p1) | 4972 | switch ((re_opcode_t) *p1) |
| 4966 | { | 4973 | { |
| 4967 | /* It's a loop. */ | 4974 | /* It's a loop. */ |
| @@ -4970,8 +4977,8 @@ alt_match_null_string_p (p, end, reg_info) | |||
| 4970 | EXTRACT_NUMBER_AND_INCR (mcnt, p1); | 4977 | EXTRACT_NUMBER_AND_INCR (mcnt, p1); |
| 4971 | p1 += mcnt; | 4978 | p1 += mcnt; |
| 4972 | break; | 4979 | break; |
| 4973 | 4980 | ||
| 4974 | default: | 4981 | default: |
| 4975 | if (!common_op_match_null_string_p (&p1, end, reg_info)) | 4982 | if (!common_op_match_null_string_p (&p1, end, reg_info)) |
| 4976 | return false; | 4983 | return false; |
| 4977 | } | 4984 | } |
| @@ -4982,8 +4989,8 @@ alt_match_null_string_p (p, end, reg_info) | |||
| 4982 | 4989 | ||
| 4983 | 4990 | ||
| 4984 | /* Deals with the ops common to group_match_null_string_p and | 4991 | /* Deals with the ops common to group_match_null_string_p and |
| 4985 | alt_match_null_string_p. | 4992 | alt_match_null_string_p. |
| 4986 | 4993 | ||
| 4987 | Sets P to one after the op and its arguments, if any. */ | 4994 | Sets P to one after the op and its arguments, if any. */ |
| 4988 | 4995 | ||
| 4989 | static boolean | 4996 | static boolean |
| @@ -5018,7 +5025,7 @@ common_op_match_null_string_p (p, end, reg_info) | |||
| 5018 | reg_no = *p1; | 5025 | reg_no = *p1; |
| 5019 | assert (reg_no > 0 && reg_no <= MAX_REGNUM); | 5026 | assert (reg_no > 0 && reg_no <= MAX_REGNUM); |
| 5020 | ret = group_match_null_string_p (&p1, end, reg_info); | 5027 | ret = group_match_null_string_p (&p1, end, reg_info); |
| 5021 | 5028 | ||
| 5022 | /* Have to set this here in case we're checking a group which | 5029 | /* Have to set this here in case we're checking a group which |
| 5023 | contains a group and a back reference to it. */ | 5030 | contains a group and a back reference to it. */ |
| 5024 | 5031 | ||
| @@ -5028,7 +5035,7 @@ common_op_match_null_string_p (p, end, reg_info) | |||
| 5028 | if (!ret) | 5035 | if (!ret) |
| 5029 | return false; | 5036 | return false; |
| 5030 | break; | 5037 | break; |
| 5031 | 5038 | ||
| 5032 | /* If this is an optimized succeed_n for zero times, make the jump. */ | 5039 | /* If this is an optimized succeed_n for zero times, make the jump. */ |
| 5033 | case jump: | 5040 | case jump: |
| 5034 | EXTRACT_NUMBER_AND_INCR (mcnt, p1); | 5041 | EXTRACT_NUMBER_AND_INCR (mcnt, p1); |
| @@ -5040,7 +5047,7 @@ common_op_match_null_string_p (p, end, reg_info) | |||
| 5040 | 5047 | ||
| 5041 | case succeed_n: | 5048 | case succeed_n: |
| 5042 | /* Get to the number of times to succeed. */ | 5049 | /* Get to the number of times to succeed. */ |
| 5043 | p1 += 2; | 5050 | p1 += 2; |
| 5044 | EXTRACT_NUMBER_AND_INCR (mcnt, p1); | 5051 | EXTRACT_NUMBER_AND_INCR (mcnt, p1); |
| 5045 | 5052 | ||
| 5046 | if (mcnt == 0) | 5053 | if (mcnt == 0) |
| @@ -5053,7 +5060,7 @@ common_op_match_null_string_p (p, end, reg_info) | |||
| 5053 | return false; | 5060 | return false; |
| 5054 | break; | 5061 | break; |
| 5055 | 5062 | ||
| 5056 | case duplicate: | 5063 | case duplicate: |
| 5057 | if (!REG_MATCH_NULL_STRING_P (reg_info[*p1])) | 5064 | if (!REG_MATCH_NULL_STRING_P (reg_info[*p1])) |
| 5058 | return false; | 5065 | return false; |
| 5059 | break; | 5066 | break; |
| @@ -5073,7 +5080,7 @@ common_op_match_null_string_p (p, end, reg_info) | |||
| 5073 | 5080 | ||
| 5074 | /* Return zero if TRANSLATE[S1] and TRANSLATE[S2] are identical for LEN | 5081 | /* Return zero if TRANSLATE[S1] and TRANSLATE[S2] are identical for LEN |
| 5075 | bytes; nonzero otherwise. */ | 5082 | bytes; nonzero otherwise. */ |
| 5076 | 5083 | ||
| 5077 | static int | 5084 | static int |
| 5078 | bcmp_translate (s1, s2, len, translate) | 5085 | bcmp_translate (s1, s2, len, translate) |
| 5079 | unsigned char *s1, *s2; | 5086 | unsigned char *s1, *s2; |
| @@ -5094,10 +5101,10 @@ bcmp_translate (s1, s2, len, translate) | |||
| 5094 | /* re_compile_pattern is the GNU regular expression compiler: it | 5101 | /* re_compile_pattern is the GNU regular expression compiler: it |
| 5095 | compiles PATTERN (of length SIZE) and puts the result in BUFP. | 5102 | compiles PATTERN (of length SIZE) and puts the result in BUFP. |
| 5096 | Returns 0 if the pattern was valid, otherwise an error string. | 5103 | Returns 0 if the pattern was valid, otherwise an error string. |
| 5097 | 5104 | ||
| 5098 | Assumes the `allocated' (and perhaps `buffer') and `translate' fields | 5105 | Assumes the `allocated' (and perhaps `buffer') and `translate' fields |
| 5099 | are set in BUFP on entry. | 5106 | are set in BUFP on entry. |
| 5100 | 5107 | ||
| 5101 | We call regex_compile to do the actual compilation. */ | 5108 | We call regex_compile to do the actual compilation. */ |
| 5102 | 5109 | ||
| 5103 | const char * | 5110 | const char * |
| @@ -5107,25 +5114,25 @@ re_compile_pattern (pattern, length, bufp) | |||
| 5107 | struct re_pattern_buffer *bufp; | 5114 | struct re_pattern_buffer *bufp; |
| 5108 | { | 5115 | { |
| 5109 | reg_errcode_t ret; | 5116 | reg_errcode_t ret; |
| 5110 | 5117 | ||
| 5111 | /* GNU code is written to assume at least RE_NREGS registers will be set | 5118 | /* GNU code is written to assume at least RE_NREGS registers will be set |
| 5112 | (and at least one extra will be -1). */ | 5119 | (and at least one extra will be -1). */ |
| 5113 | bufp->regs_allocated = REGS_UNALLOCATED; | 5120 | bufp->regs_allocated = REGS_UNALLOCATED; |
| 5114 | 5121 | ||
| 5115 | /* And GNU code determines whether or not to get register information | 5122 | /* And GNU code determines whether or not to get register information |
| 5116 | by passing null for the REGS argument to re_match, etc., not by | 5123 | by passing null for the REGS argument to re_match, etc., not by |
| 5117 | setting no_sub. */ | 5124 | setting no_sub. */ |
| 5118 | bufp->no_sub = 0; | 5125 | bufp->no_sub = 0; |
| 5119 | 5126 | ||
| 5120 | /* Match anchors at newline. */ | 5127 | /* Match anchors at newline. */ |
| 5121 | bufp->newline_anchor = 1; | 5128 | bufp->newline_anchor = 1; |
| 5122 | 5129 | ||
| 5123 | ret = regex_compile (pattern, length, re_syntax_options, bufp); | 5130 | ret = regex_compile (pattern, length, re_syntax_options, bufp); |
| 5124 | 5131 | ||
| 5125 | if (!ret) | 5132 | if (!ret) |
| 5126 | return NULL; | 5133 | return NULL; |
| 5127 | return gettext (re_error_msgid[(int) ret]); | 5134 | return gettext (re_error_msgid[(int) ret]); |
| 5128 | } | 5135 | } |
| 5129 | 5136 | ||
| 5130 | /* Entry points compatible with 4.2 BSD regex library. We don't define | 5137 | /* Entry points compatible with 4.2 BSD regex library. We don't define |
| 5131 | them unless specifically requested. */ | 5138 | them unless specifically requested. */ |
| @@ -5140,7 +5147,7 @@ re_comp (s) | |||
| 5140 | const char *s; | 5147 | const char *s; |
| 5141 | { | 5148 | { |
| 5142 | reg_errcode_t ret; | 5149 | reg_errcode_t ret; |
| 5143 | 5150 | ||
| 5144 | if (!s) | 5151 | if (!s) |
| 5145 | { | 5152 | { |
| 5146 | if (!re_comp_buf.buffer) | 5153 | if (!re_comp_buf.buffer) |
| @@ -5167,7 +5174,7 @@ re_comp (s) | |||
| 5167 | re_comp_buf.newline_anchor = 1; | 5174 | re_comp_buf.newline_anchor = 1; |
| 5168 | 5175 | ||
| 5169 | ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf); | 5176 | ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf); |
| 5170 | 5177 | ||
| 5171 | if (!ret) | 5178 | if (!ret) |
| 5172 | return NULL; | 5179 | return NULL; |
| 5173 | 5180 | ||
| @@ -5227,7 +5234,7 @@ re_exec (s) | |||
| 5227 | int | 5234 | int |
| 5228 | regcomp (preg, pattern, cflags) | 5235 | regcomp (preg, pattern, cflags) |
| 5229 | regex_t *preg; | 5236 | regex_t *preg; |
| 5230 | const char *pattern; | 5237 | const char *pattern; |
| 5231 | int cflags; | 5238 | int cflags; |
| 5232 | { | 5239 | { |
| 5233 | reg_errcode_t ret; | 5240 | reg_errcode_t ret; |
| @@ -5239,17 +5246,17 @@ regcomp (preg, pattern, cflags) | |||
| 5239 | preg->buffer = 0; | 5246 | preg->buffer = 0; |
| 5240 | preg->allocated = 0; | 5247 | preg->allocated = 0; |
| 5241 | preg->used = 0; | 5248 | preg->used = 0; |
| 5242 | 5249 | ||
| 5243 | /* Don't bother to use a fastmap when searching. This simplifies the | 5250 | /* Don't bother to use a fastmap when searching. This simplifies the |
| 5244 | REG_NEWLINE case: if we used a fastmap, we'd have to put all the | 5251 | REG_NEWLINE case: if we used a fastmap, we'd have to put all the |
| 5245 | characters after newlines into the fastmap. This way, we just try | 5252 | characters after newlines into the fastmap. This way, we just try |
| 5246 | every character. */ | 5253 | every character. */ |
| 5247 | preg->fastmap = 0; | 5254 | preg->fastmap = 0; |
| 5248 | 5255 | ||
| 5249 | if (cflags & REG_ICASE) | 5256 | if (cflags & REG_ICASE) |
| 5250 | { | 5257 | { |
| 5251 | unsigned i; | 5258 | unsigned i; |
| 5252 | 5259 | ||
| 5253 | preg->translate | 5260 | preg->translate |
| 5254 | = (RE_TRANSLATE_TYPE) malloc (CHAR_SET_SIZE | 5261 | = (RE_TRANSLATE_TYPE) malloc (CHAR_SET_SIZE |
| 5255 | * sizeof (*(RE_TRANSLATE_TYPE)0)); | 5262 | * sizeof (*(RE_TRANSLATE_TYPE)0)); |
| @@ -5276,38 +5283,38 @@ regcomp (preg, pattern, cflags) | |||
| 5276 | 5283 | ||
| 5277 | preg->no_sub = !!(cflags & REG_NOSUB); | 5284 | preg->no_sub = !!(cflags & REG_NOSUB); |
| 5278 | 5285 | ||
| 5279 | /* POSIX says a null character in the pattern terminates it, so we | 5286 | /* POSIX says a null character in the pattern terminates it, so we |
| 5280 | can use strlen here in compiling the pattern. */ | 5287 | can use strlen here in compiling the pattern. */ |
| 5281 | ret = regex_compile (pattern, strlen (pattern), syntax, preg); | 5288 | ret = regex_compile (pattern, strlen (pattern), syntax, preg); |
| 5282 | 5289 | ||
| 5283 | /* POSIX doesn't distinguish between an unmatched open-group and an | 5290 | /* POSIX doesn't distinguish between an unmatched open-group and an |
| 5284 | unmatched close-group: both are REG_EPAREN. */ | 5291 | unmatched close-group: both are REG_EPAREN. */ |
| 5285 | if (ret == REG_ERPAREN) ret = REG_EPAREN; | 5292 | if (ret == REG_ERPAREN) ret = REG_EPAREN; |
| 5286 | 5293 | ||
| 5287 | return (int) ret; | 5294 | return (int) ret; |
| 5288 | } | 5295 | } |
| 5289 | 5296 | ||
| 5290 | 5297 | ||
| 5291 | /* regexec searches for a given pattern, specified by PREG, in the | 5298 | /* regexec searches for a given pattern, specified by PREG, in the |
| 5292 | string STRING. | 5299 | string STRING. |
| 5293 | 5300 | ||
| 5294 | If NMATCH is zero or REG_NOSUB was set in the cflags argument to | 5301 | If NMATCH is zero or REG_NOSUB was set in the cflags argument to |
| 5295 | `regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at | 5302 | `regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at |
| 5296 | least NMATCH elements, and we set them to the offsets of the | 5303 | least NMATCH elements, and we set them to the offsets of the |
| 5297 | corresponding matched substrings. | 5304 | corresponding matched substrings. |
| 5298 | 5305 | ||
| 5299 | EFLAGS specifies `execution flags' which affect matching: if | 5306 | EFLAGS specifies `execution flags' which affect matching: if |
| 5300 | REG_NOTBOL is set, then ^ does not match at the beginning of the | 5307 | REG_NOTBOL is set, then ^ does not match at the beginning of the |
| 5301 | string; if REG_NOTEOL is set, then $ does not match at the end. | 5308 | string; if REG_NOTEOL is set, then $ does not match at the end. |
| 5302 | 5309 | ||
| 5303 | We return 0 if we find a match and REG_NOMATCH if not. */ | 5310 | We return 0 if we find a match and REG_NOMATCH if not. */ |
| 5304 | 5311 | ||
| 5305 | int | 5312 | int |
| 5306 | regexec (preg, string, nmatch, pmatch, eflags) | 5313 | regexec (preg, string, nmatch, pmatch, eflags) |
| 5307 | const regex_t *preg; | 5314 | const regex_t *preg; |
| 5308 | const char *string; | 5315 | const char *string; |
| 5309 | size_t nmatch; | 5316 | size_t nmatch; |
| 5310 | regmatch_t pmatch[]; | 5317 | regmatch_t pmatch[]; |
| 5311 | int eflags; | 5318 | int eflags; |
| 5312 | { | 5319 | { |
| 5313 | int ret; | 5320 | int ret; |
| @@ -5317,15 +5324,15 @@ regexec (preg, string, nmatch, pmatch, eflags) | |||
| 5317 | boolean want_reg_info = !preg->no_sub && nmatch > 0; | 5324 | boolean want_reg_info = !preg->no_sub && nmatch > 0; |
| 5318 | 5325 | ||
| 5319 | private_preg = *preg; | 5326 | private_preg = *preg; |
| 5320 | 5327 | ||
| 5321 | private_preg.not_bol = !!(eflags & REG_NOTBOL); | 5328 | private_preg.not_bol = !!(eflags & REG_NOTBOL); |
| 5322 | private_preg.not_eol = !!(eflags & REG_NOTEOL); | 5329 | private_preg.not_eol = !!(eflags & REG_NOTEOL); |
| 5323 | 5330 | ||
| 5324 | /* The user has told us exactly how many registers to return | 5331 | /* The user has told us exactly how many registers to return |
| 5325 | information about, via `nmatch'. We have to pass that on to the | 5332 | information about, via `nmatch'. We have to pass that on to the |
| 5326 | matching routines. */ | 5333 | matching routines. */ |
| 5327 | private_preg.regs_allocated = REGS_FIXED; | 5334 | private_preg.regs_allocated = REGS_FIXED; |
| 5328 | 5335 | ||
| 5329 | if (want_reg_info) | 5336 | if (want_reg_info) |
| 5330 | { | 5337 | { |
| 5331 | regs.num_regs = nmatch; | 5338 | regs.num_regs = nmatch; |
| @@ -5339,7 +5346,7 @@ regexec (preg, string, nmatch, pmatch, eflags) | |||
| 5339 | ret = re_search (&private_preg, string, len, | 5346 | ret = re_search (&private_preg, string, len, |
| 5340 | /* start: */ 0, /* range: */ len, | 5347 | /* start: */ 0, /* range: */ len, |
| 5341 | want_reg_info ? ®s : (struct re_registers *) 0); | 5348 | want_reg_info ? ®s : (struct re_registers *) 0); |
| 5342 | 5349 | ||
| 5343 | /* Copy the register information to the POSIX structure. */ | 5350 | /* Copy the register information to the POSIX structure. */ |
| 5344 | if (want_reg_info) | 5351 | if (want_reg_info) |
| 5345 | { | 5352 | { |
| @@ -5379,7 +5386,7 @@ regerror (errcode, preg, errbuf, errbuf_size) | |||
| 5379 | 5386 | ||
| 5380 | if (errcode < 0 | 5387 | if (errcode < 0 |
| 5381 | || errcode >= (sizeof (re_error_msgid) / sizeof (re_error_msgid[0]))) | 5388 | || errcode >= (sizeof (re_error_msgid) / sizeof (re_error_msgid[0]))) |
| 5382 | /* Only error codes returned by the rest of the code should be passed | 5389 | /* Only error codes returned by the rest of the code should be passed |
| 5383 | to this routine. If we are given anything else, or if other regex | 5390 | to this routine. If we are given anything else, or if other regex |
| 5384 | code generates an invalid error code, then the program has a bug. | 5391 | code generates an invalid error code, then the program has a bug. |
| 5385 | Dump core so we can fix it. */ | 5392 | Dump core so we can fix it. */ |
| @@ -5388,7 +5395,7 @@ regerror (errcode, preg, errbuf, errbuf_size) | |||
| 5388 | msg = gettext (re_error_msgid[errcode]); | 5395 | msg = gettext (re_error_msgid[errcode]); |
| 5389 | 5396 | ||
| 5390 | msg_size = strlen (msg) + 1; /* Includes the null. */ | 5397 | msg_size = strlen (msg) + 1; /* Includes the null. */ |
| 5391 | 5398 | ||
| 5392 | if (errbuf_size != 0) | 5399 | if (errbuf_size != 0) |
| 5393 | { | 5400 | { |
| 5394 | if (msg_size > errbuf_size) | 5401 | if (msg_size > errbuf_size) |
| @@ -5413,7 +5420,7 @@ regfree (preg) | |||
| 5413 | if (preg->buffer != NULL) | 5420 | if (preg->buffer != NULL) |
| 5414 | free (preg->buffer); | 5421 | free (preg->buffer); |
| 5415 | preg->buffer = NULL; | 5422 | preg->buffer = NULL; |
| 5416 | 5423 | ||
| 5417 | preg->allocated = 0; | 5424 | preg->allocated = 0; |
| 5418 | preg->used = 0; | 5425 | preg->used = 0; |
| 5419 | 5426 | ||