diff options
| author | Tom Tromey | 2013-06-03 12:25:05 -0600 |
|---|---|---|
| committer | Tom Tromey | 2013-06-03 12:25:05 -0600 |
| commit | 68359abba96d7ec4db8aab3d3dd9cf1105c3bab5 (patch) | |
| tree | 862703e7e1a1888170136a8296a5750d6b2ae2eb /src/regex.c | |
| parent | cbcba8ce7f980b01c18c0fd561ef6687b1361507 (diff) | |
| parent | e2d8a6f0a229b4ebe26484b892ec4f14888f58b6 (diff) | |
| download | emacs-68359abba96d7ec4db8aab3d3dd9cf1105c3bab5.tar.gz emacs-68359abba96d7ec4db8aab3d3dd9cf1105c3bab5.zip | |
merge from trunk; clean up some issues
Diffstat (limited to 'src/regex.c')
| -rw-r--r-- | src/regex.c | 398 |
1 files changed, 192 insertions, 206 deletions
diff --git a/src/regex.c b/src/regex.c index b5522f19079..73a735cea65 100644 --- a/src/regex.c +++ b/src/regex.c | |||
| @@ -33,10 +33,9 @@ | |||
| 33 | 33 | ||
| 34 | /* Ignore some GCC warnings for now. This section should go away | 34 | /* Ignore some GCC warnings for now. This section should go away |
| 35 | once the Emacs and Gnulib regex code is merged. */ | 35 | once the Emacs and Gnulib regex code is merged. */ |
| 36 | #if (__GNUC__ == 4 && 5 <= __GNUC_MINOR__) || 4 < __GNUC__ | 36 | #if 4 < __GNUC__ + (5 <= __GNUC_MINOR__) || defined __clang__ |
| 37 | # pragma GCC diagnostic ignored "-Wstrict-overflow" | 37 | # pragma GCC diagnostic ignored "-Wstrict-overflow" |
| 38 | # ifndef emacs | 38 | # ifndef emacs |
| 39 | # pragma GCC diagnostic ignored "-Wunused-but-set-variable" | ||
| 40 | # pragma GCC diagnostic ignored "-Wunused-function" | 39 | # pragma GCC diagnostic ignored "-Wunused-function" |
| 41 | # pragma GCC diagnostic ignored "-Wunused-macros" | 40 | # pragma GCC diagnostic ignored "-Wunused-macros" |
| 42 | # pragma GCC diagnostic ignored "-Wunused-result" | 41 | # pragma GCC diagnostic ignored "-Wunused-result" |
| @@ -44,6 +43,10 @@ | |||
| 44 | # endif | 43 | # endif |
| 45 | #endif | 44 | #endif |
| 46 | 45 | ||
| 46 | #if 4 < __GNUC__ + (5 <= __GNUC_MINOR__) && ! defined __clang__ | ||
| 47 | # pragma GCC diagnostic ignored "-Wunused-but-set-variable" | ||
| 48 | #endif | ||
| 49 | |||
| 47 | #include <config.h> | 50 | #include <config.h> |
| 48 | 51 | ||
| 49 | #include <stddef.h> | 52 | #include <stddef.h> |
| @@ -710,51 +713,27 @@ typedef enum | |||
| 710 | at SOURCE. */ | 713 | at SOURCE. */ |
| 711 | 714 | ||
| 712 | #define EXTRACT_NUMBER(destination, source) \ | 715 | #define EXTRACT_NUMBER(destination, source) \ |
| 713 | do { \ | 716 | ((destination) = extract_number (source)) |
| 714 | (destination) = *(source) & 0377; \ | ||
| 715 | (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \ | ||
| 716 | } while (0) | ||
| 717 | 717 | ||
| 718 | #ifdef DEBUG | 718 | static int |
| 719 | static void | 719 | extract_number (re_char *source) |
| 720 | extract_number (int *dest, re_char *source) | ||
| 721 | { | 720 | { |
| 722 | int temp = SIGN_EXTEND_CHAR (*(source + 1)); | 721 | return (SIGN_EXTEND_CHAR (source[1]) << 8) + source[0]; |
| 723 | *dest = *source & 0377; | ||
| 724 | *dest += temp << 8; | ||
| 725 | } | 722 | } |
| 726 | 723 | ||
| 727 | # ifndef EXTRACT_MACROS /* To debug the macros. */ | ||
| 728 | # undef EXTRACT_NUMBER | ||
| 729 | # define EXTRACT_NUMBER(dest, src) extract_number (&dest, src) | ||
| 730 | # endif /* not EXTRACT_MACROS */ | ||
| 731 | |||
| 732 | #endif /* DEBUG */ | ||
| 733 | |||
| 734 | /* Same as EXTRACT_NUMBER, except increment SOURCE to after the number. | 724 | /* Same as EXTRACT_NUMBER, except increment SOURCE to after the number. |
| 735 | SOURCE must be an lvalue. */ | 725 | SOURCE must be an lvalue. */ |
| 736 | 726 | ||
| 737 | #define EXTRACT_NUMBER_AND_INCR(destination, source) \ | 727 | #define EXTRACT_NUMBER_AND_INCR(destination, source) \ |
| 738 | do { \ | 728 | ((destination) = extract_number_and_incr (&source)) |
| 739 | EXTRACT_NUMBER (destination, source); \ | ||
| 740 | (source) += 2; \ | ||
| 741 | } while (0) | ||
| 742 | 729 | ||
| 743 | #ifdef DEBUG | 730 | static int |
| 744 | static void | 731 | extract_number_and_incr (re_char **source) |
| 745 | extract_number_and_incr (int *destination, re_char **source) | ||
| 746 | { | 732 | { |
| 747 | extract_number (destination, *source); | 733 | int num = extract_number (*source); |
| 748 | *source += 2; | 734 | *source += 2; |
| 735 | return num; | ||
| 749 | } | 736 | } |
| 750 | |||
| 751 | # ifndef EXTRACT_MACROS | ||
| 752 | # undef EXTRACT_NUMBER_AND_INCR | ||
| 753 | # define EXTRACT_NUMBER_AND_INCR(dest, src) \ | ||
| 754 | extract_number_and_incr (&dest, &src) | ||
| 755 | # endif /* not EXTRACT_MACROS */ | ||
| 756 | |||
| 757 | #endif /* DEBUG */ | ||
| 758 | 737 | ||
| 759 | /* Store a multibyte character in three contiguous bytes starting | 738 | /* Store a multibyte character in three contiguous bytes starting |
| 760 | DESTINATION, and increment DESTINATION to the byte after where the | 739 | DESTINATION, and increment DESTINATION to the byte after where the |
| @@ -861,10 +840,8 @@ extract_number_and_incr (int *destination, re_char **source) | |||
| 861 | static int debug = -100000; | 840 | static int debug = -100000; |
| 862 | 841 | ||
| 863 | # define DEBUG_STATEMENT(e) e | 842 | # define DEBUG_STATEMENT(e) e |
| 864 | # define DEBUG_PRINT1(x) if (debug > 0) printf (x) | 843 | # define DEBUG_PRINT(...) if (debug > 0) printf (__VA_ARGS__) |
| 865 | # define DEBUG_PRINT2(x1, x2) if (debug > 0) printf (x1, x2) | 844 | # define DEBUG_COMPILES_ARGUMENTS |
| 866 | # define DEBUG_PRINT3(x1, x2, x3) if (debug > 0) printf (x1, x2, x3) | ||
| 867 | # define DEBUG_PRINT4(x1, x2, x3, x4) if (debug > 0) printf (x1, x2, x3, x4) | ||
| 868 | # define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \ | 845 | # define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \ |
| 869 | if (debug > 0) print_partial_compiled_pattern (s, e) | 846 | if (debug > 0) print_partial_compiled_pattern (s, e) |
| 870 | # define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \ | 847 | # define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \ |
| @@ -873,9 +850,8 @@ static int debug = -100000; | |||
| 873 | 850 | ||
| 874 | /* Print the fastmap in human-readable form. */ | 851 | /* Print the fastmap in human-readable form. */ |
| 875 | 852 | ||
| 876 | void | 853 | static void |
| 877 | print_fastmap (fastmap) | 854 | print_fastmap (char *fastmap) |
| 878 | char *fastmap; | ||
| 879 | { | 855 | { |
| 880 | unsigned was_a_range = 0; | 856 | unsigned was_a_range = 0; |
| 881 | unsigned i = 0; | 857 | unsigned i = 0; |
| @@ -905,10 +881,8 @@ print_fastmap (fastmap) | |||
| 905 | /* Print a compiled pattern string in human-readable form, starting at | 881 | /* Print a compiled pattern string in human-readable form, starting at |
| 906 | the START pointer into it and ending just before the pointer END. */ | 882 | the START pointer into it and ending just before the pointer END. */ |
| 907 | 883 | ||
| 908 | void | 884 | static void |
| 909 | print_partial_compiled_pattern (start, end) | 885 | print_partial_compiled_pattern (re_char *start, re_char *end) |
| 910 | re_char *start; | ||
| 911 | re_char *end; | ||
| 912 | { | 886 | { |
| 913 | int mcnt, mcnt2; | 887 | int mcnt, mcnt2; |
| 914 | re_char *p = start; | 888 | re_char *p = start; |
| @@ -923,7 +897,7 @@ print_partial_compiled_pattern (start, end) | |||
| 923 | /* Loop over pattern commands. */ | 897 | /* Loop over pattern commands. */ |
| 924 | while (p < pend) | 898 | while (p < pend) |
| 925 | { | 899 | { |
| 926 | fprintf (stderr, "%d:\t", p - start); | 900 | fprintf (stderr, "%td:\t", p - start); |
| 927 | 901 | ||
| 928 | switch ((re_opcode_t) *p++) | 902 | switch ((re_opcode_t) *p++) |
| 929 | { | 903 | { |
| @@ -1027,51 +1001,58 @@ print_partial_compiled_pattern (start, end) | |||
| 1027 | break; | 1001 | break; |
| 1028 | 1002 | ||
| 1029 | case on_failure_jump: | 1003 | case on_failure_jump: |
| 1030 | extract_number_and_incr (&mcnt, &p); | 1004 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 1031 | fprintf (stderr, "/on_failure_jump to %d", p + mcnt - start); | 1005 | fprintf (stderr, "/on_failure_jump to %td", p + mcnt - start); |
| 1032 | break; | 1006 | break; |
| 1033 | 1007 | ||
| 1034 | case on_failure_keep_string_jump: | 1008 | case on_failure_keep_string_jump: |
| 1035 | extract_number_and_incr (&mcnt, &p); | 1009 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 1036 | fprintf (stderr, "/on_failure_keep_string_jump to %d", p + mcnt - start); | 1010 | fprintf (stderr, "/on_failure_keep_string_jump to %td", |
| 1011 | p + mcnt - start); | ||
| 1037 | break; | 1012 | break; |
| 1038 | 1013 | ||
| 1039 | case on_failure_jump_nastyloop: | 1014 | case on_failure_jump_nastyloop: |
| 1040 | extract_number_and_incr (&mcnt, &p); | 1015 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 1041 | fprintf (stderr, "/on_failure_jump_nastyloop to %d", p + mcnt - start); | 1016 | fprintf (stderr, "/on_failure_jump_nastyloop to %td", |
| 1017 | p + mcnt - start); | ||
| 1042 | break; | 1018 | break; |
| 1043 | 1019 | ||
| 1044 | case on_failure_jump_loop: | 1020 | case on_failure_jump_loop: |
| 1045 | extract_number_and_incr (&mcnt, &p); | 1021 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 1046 | fprintf (stderr, "/on_failure_jump_loop to %d", p + mcnt - start); | 1022 | fprintf (stderr, "/on_failure_jump_loop to %td", |
| 1023 | p + mcnt - start); | ||
| 1047 | break; | 1024 | break; |
| 1048 | 1025 | ||
| 1049 | case on_failure_jump_smart: | 1026 | case on_failure_jump_smart: |
| 1050 | extract_number_and_incr (&mcnt, &p); | 1027 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 1051 | fprintf (stderr, "/on_failure_jump_smart to %d", p + mcnt - start); | 1028 | fprintf (stderr, "/on_failure_jump_smart to %td", |
| 1029 | p + mcnt - start); | ||
| 1052 | break; | 1030 | break; |
| 1053 | 1031 | ||
| 1054 | case jump: | 1032 | case jump: |
| 1055 | extract_number_and_incr (&mcnt, &p); | 1033 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 1056 | fprintf (stderr, "/jump to %d", p + mcnt - start); | 1034 | fprintf (stderr, "/jump to %td", p + mcnt - start); |
| 1057 | break; | 1035 | break; |
| 1058 | 1036 | ||
| 1059 | case succeed_n: | 1037 | case succeed_n: |
| 1060 | extract_number_and_incr (&mcnt, &p); | 1038 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 1061 | extract_number_and_incr (&mcnt2, &p); | 1039 | EXTRACT_NUMBER_AND_INCR (mcnt2, p); |
| 1062 | fprintf (stderr, "/succeed_n to %d, %d times", p - 2 + mcnt - start, mcnt2); | 1040 | fprintf (stderr, "/succeed_n to %td, %d times", |
| 1041 | p - 2 + mcnt - start, mcnt2); | ||
| 1063 | break; | 1042 | break; |
| 1064 | 1043 | ||
| 1065 | case jump_n: | 1044 | case jump_n: |
| 1066 | extract_number_and_incr (&mcnt, &p); | 1045 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 1067 | extract_number_and_incr (&mcnt2, &p); | 1046 | EXTRACT_NUMBER_AND_INCR (mcnt2, p); |
| 1068 | fprintf (stderr, "/jump_n to %d, %d times", p - 2 + mcnt - start, mcnt2); | 1047 | fprintf (stderr, "/jump_n to %td, %d times", |
| 1048 | p - 2 + mcnt - start, mcnt2); | ||
| 1069 | break; | 1049 | break; |
| 1070 | 1050 | ||
| 1071 | case set_number_at: | 1051 | case set_number_at: |
| 1072 | extract_number_and_incr (&mcnt, &p); | 1052 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 1073 | extract_number_and_incr (&mcnt2, &p); | 1053 | EXTRACT_NUMBER_AND_INCR (mcnt2, p); |
| 1074 | fprintf (stderr, "/set_number_at location %d to %d", p - 2 + mcnt - start, mcnt2); | 1054 | fprintf (stderr, "/set_number_at location %td to %d", |
| 1055 | p - 2 + mcnt - start, mcnt2); | ||
| 1075 | break; | 1056 | break; |
| 1076 | 1057 | ||
| 1077 | case wordbound: | 1058 | case wordbound: |
| @@ -1151,13 +1132,12 @@ print_partial_compiled_pattern (start, end) | |||
| 1151 | fprintf (stderr, "\n"); | 1132 | fprintf (stderr, "\n"); |
| 1152 | } | 1133 | } |
| 1153 | 1134 | ||
| 1154 | fprintf (stderr, "%d:\tend of pattern.\n", p - start); | 1135 | fprintf (stderr, "%td:\tend of pattern.\n", p - start); |
| 1155 | } | 1136 | } |
| 1156 | 1137 | ||
| 1157 | 1138 | ||
| 1158 | void | 1139 | static void |
| 1159 | print_compiled_pattern (bufp) | 1140 | print_compiled_pattern (struct re_pattern_buffer *bufp) |
| 1160 | struct re_pattern_buffer *bufp; | ||
| 1161 | { | 1141 | { |
| 1162 | re_char *buffer = bufp->buffer; | 1142 | re_char *buffer = bufp->buffer; |
| 1163 | 1143 | ||
| @@ -1171,7 +1151,7 @@ print_compiled_pattern (bufp) | |||
| 1171 | print_fastmap (bufp->fastmap); | 1151 | print_fastmap (bufp->fastmap); |
| 1172 | } | 1152 | } |
| 1173 | 1153 | ||
| 1174 | printf ("re_nsub: %d\t", bufp->re_nsub); | 1154 | printf ("re_nsub: %zu\t", bufp->re_nsub); |
| 1175 | printf ("regs_alloc: %d\t", bufp->regs_allocated); | 1155 | printf ("regs_alloc: %d\t", bufp->regs_allocated); |
| 1176 | printf ("can_be_null: %d\t", bufp->can_be_null); | 1156 | printf ("can_be_null: %d\t", bufp->can_be_null); |
| 1177 | printf ("no_sub: %d\t", bufp->no_sub); | 1157 | printf ("no_sub: %d\t", bufp->no_sub); |
| @@ -1183,13 +1163,9 @@ print_compiled_pattern (bufp) | |||
| 1183 | } | 1163 | } |
| 1184 | 1164 | ||
| 1185 | 1165 | ||
| 1186 | void | 1166 | static void |
| 1187 | print_double_string (where, string1, size1, string2, size2) | 1167 | print_double_string (re_char *where, re_char *string1, ssize_t size1, |
| 1188 | re_char *where; | 1168 | re_char *string2, ssize_t size2) |
| 1189 | re_char *string1; | ||
| 1190 | re_char *string2; | ||
| 1191 | ssize_t size1; | ||
| 1192 | ssize_t size2; | ||
| 1193 | { | 1169 | { |
| 1194 | ssize_t this_char; | 1170 | ssize_t this_char; |
| 1195 | 1171 | ||
| @@ -1216,10 +1192,12 @@ print_double_string (where, string1, size1, string2, size2) | |||
| 1216 | # define assert(e) | 1192 | # define assert(e) |
| 1217 | 1193 | ||
| 1218 | # define DEBUG_STATEMENT(e) | 1194 | # define DEBUG_STATEMENT(e) |
| 1219 | # define DEBUG_PRINT1(x) | 1195 | # if __STDC_VERSION__ < 199901L |
| 1220 | # define DEBUG_PRINT2(x1, x2) | 1196 | # define DEBUG_COMPILES_ARGUMENTS |
| 1221 | # define DEBUG_PRINT3(x1, x2, x3) | 1197 | # define DEBUG_PRINT /* 'DEBUG_PRINT (x, y)' discards X and Y. */ (void) |
| 1222 | # define DEBUG_PRINT4(x1, x2, x3, x4) | 1198 | # else |
| 1199 | # define DEBUG_PRINT(...) | ||
| 1200 | # endif | ||
| 1223 | # define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) | 1201 | # define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) |
| 1224 | # define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) | 1202 | # define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) |
| 1225 | 1203 | ||
| @@ -1473,20 +1451,21 @@ typedef struct | |||
| 1473 | while (REMAINING_AVAIL_SLOTS <= space) { \ | 1451 | while (REMAINING_AVAIL_SLOTS <= space) { \ |
| 1474 | if (!GROW_FAIL_STACK (fail_stack)) \ | 1452 | if (!GROW_FAIL_STACK (fail_stack)) \ |
| 1475 | return -2; \ | 1453 | return -2; \ |
| 1476 | DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", (fail_stack).size);\ | 1454 | DEBUG_PRINT ("\n Doubled stack; size now: %zd\n", (fail_stack).size);\ |
| 1477 | DEBUG_PRINT2 (" slots available: %d\n", REMAINING_AVAIL_SLOTS);\ | 1455 | DEBUG_PRINT (" slots available: %zd\n", REMAINING_AVAIL_SLOTS);\ |
| 1478 | } | 1456 | } |
| 1479 | 1457 | ||
| 1480 | /* Push register NUM onto the stack. */ | 1458 | /* Push register NUM onto the stack. */ |
| 1481 | #define PUSH_FAILURE_REG(num) \ | 1459 | #define PUSH_FAILURE_REG(num) \ |
| 1482 | do { \ | 1460 | do { \ |
| 1483 | char *destination; \ | 1461 | char *destination; \ |
| 1462 | long n = num; \ | ||
| 1484 | ENSURE_FAIL_STACK(3); \ | 1463 | ENSURE_FAIL_STACK(3); \ |
| 1485 | DEBUG_PRINT4 (" Push reg %d (spanning %p -> %p)\n", \ | 1464 | DEBUG_PRINT (" Push reg %ld (spanning %p -> %p)\n", \ |
| 1486 | num, regstart[num], regend[num]); \ | 1465 | n, regstart[n], regend[n]); \ |
| 1487 | PUSH_FAILURE_POINTER (regstart[num]); \ | 1466 | PUSH_FAILURE_POINTER (regstart[n]); \ |
| 1488 | PUSH_FAILURE_POINTER (regend[num]); \ | 1467 | PUSH_FAILURE_POINTER (regend[n]); \ |
| 1489 | PUSH_FAILURE_INT (num); \ | 1468 | PUSH_FAILURE_INT (n); \ |
| 1490 | } while (0) | 1469 | } while (0) |
| 1491 | 1470 | ||
| 1492 | /* Change the counter's value to VAL, but make sure that it will | 1471 | /* Change the counter's value to VAL, but make sure that it will |
| @@ -1497,7 +1476,7 @@ do { \ | |||
| 1497 | int c; \ | 1476 | int c; \ |
| 1498 | ENSURE_FAIL_STACK(3); \ | 1477 | ENSURE_FAIL_STACK(3); \ |
| 1499 | EXTRACT_NUMBER (c, ptr); \ | 1478 | EXTRACT_NUMBER (c, ptr); \ |
| 1500 | DEBUG_PRINT4 (" Push number %p = %d -> %d\n", ptr, c, val); \ | 1479 | DEBUG_PRINT (" Push number %p = %d -> %d\n", ptr, c, val); \ |
| 1501 | PUSH_FAILURE_INT (c); \ | 1480 | PUSH_FAILURE_INT (c); \ |
| 1502 | PUSH_FAILURE_POINTER (ptr); \ | 1481 | PUSH_FAILURE_POINTER (ptr); \ |
| 1503 | PUSH_FAILURE_INT (-1); \ | 1482 | PUSH_FAILURE_INT (-1); \ |
| @@ -1515,14 +1494,14 @@ do { \ | |||
| 1515 | unsigned char *ptr = (unsigned char*) POP_FAILURE_POINTER (); \ | 1494 | unsigned char *ptr = (unsigned char*) POP_FAILURE_POINTER (); \ |
| 1516 | pfreg = POP_FAILURE_INT (); \ | 1495 | pfreg = POP_FAILURE_INT (); \ |
| 1517 | STORE_NUMBER (ptr, pfreg); \ | 1496 | STORE_NUMBER (ptr, pfreg); \ |
| 1518 | DEBUG_PRINT3 (" Pop counter %p = %d\n", ptr, pfreg); \ | 1497 | DEBUG_PRINT (" Pop counter %p = %ld\n", ptr, pfreg); \ |
| 1519 | } \ | 1498 | } \ |
| 1520 | else \ | 1499 | else \ |
| 1521 | { \ | 1500 | { \ |
| 1522 | regend[pfreg] = POP_FAILURE_POINTER (); \ | 1501 | regend[pfreg] = POP_FAILURE_POINTER (); \ |
| 1523 | regstart[pfreg] = POP_FAILURE_POINTER (); \ | 1502 | regstart[pfreg] = POP_FAILURE_POINTER (); \ |
| 1524 | DEBUG_PRINT4 (" Pop reg %d (spanning %p -> %p)\n", \ | 1503 | DEBUG_PRINT (" Pop reg %ld (spanning %p -> %p)\n", \ |
| 1525 | pfreg, regstart[pfreg], regend[pfreg]); \ | 1504 | pfreg, regstart[pfreg], regend[pfreg]); \ |
| 1526 | } \ | 1505 | } \ |
| 1527 | } while (0) | 1506 | } while (0) |
| 1528 | 1507 | ||
| @@ -1542,10 +1521,10 @@ do { \ | |||
| 1542 | cycle = 1; \ | 1521 | cycle = 1; \ |
| 1543 | break; \ | 1522 | break; \ |
| 1544 | } \ | 1523 | } \ |
| 1545 | DEBUG_PRINT2 (" Other pattern: %p\n", FAILURE_PAT (failure)); \ | 1524 | DEBUG_PRINT (" Other pattern: %p\n", FAILURE_PAT (failure)); \ |
| 1546 | failure = NEXT_FAILURE_HANDLE(failure); \ | 1525 | failure = NEXT_FAILURE_HANDLE(failure); \ |
| 1547 | } \ | 1526 | } \ |
| 1548 | DEBUG_PRINT2 (" Other string: %p\n", FAILURE_STR (failure)); \ | 1527 | DEBUG_PRINT (" Other string: %p\n", FAILURE_STR (failure)); \ |
| 1549 | } while (0) | 1528 | } while (0) |
| 1550 | 1529 | ||
| 1551 | /* Push the information about the state we will need | 1530 | /* Push the information about the state we will need |
| @@ -1564,23 +1543,23 @@ do { \ | |||
| 1564 | of 0 + -1 isn't done as unsigned. */ \ | 1543 | of 0 + -1 isn't done as unsigned. */ \ |
| 1565 | \ | 1544 | \ |
| 1566 | DEBUG_STATEMENT (nfailure_points_pushed++); \ | 1545 | DEBUG_STATEMENT (nfailure_points_pushed++); \ |
| 1567 | DEBUG_PRINT1 ("\nPUSH_FAILURE_POINT:\n"); \ | 1546 | DEBUG_PRINT ("\nPUSH_FAILURE_POINT:\n"); \ |
| 1568 | DEBUG_PRINT2 (" Before push, next avail: %d\n", (fail_stack).avail); \ | 1547 | DEBUG_PRINT (" Before push, next avail: %zd\n", (fail_stack).avail); \ |
| 1569 | DEBUG_PRINT2 (" size: %d\n", (fail_stack).size);\ | 1548 | DEBUG_PRINT (" size: %zd\n", (fail_stack).size);\ |
| 1570 | \ | 1549 | \ |
| 1571 | ENSURE_FAIL_STACK (NUM_NONREG_ITEMS); \ | 1550 | ENSURE_FAIL_STACK (NUM_NONREG_ITEMS); \ |
| 1572 | \ | 1551 | \ |
| 1573 | DEBUG_PRINT1 ("\n"); \ | 1552 | DEBUG_PRINT ("\n"); \ |
| 1574 | \ | 1553 | \ |
| 1575 | DEBUG_PRINT2 (" Push frame index: %d\n", fail_stack.frame); \ | 1554 | DEBUG_PRINT (" Push frame index: %zd\n", fail_stack.frame); \ |
| 1576 | PUSH_FAILURE_INT (fail_stack.frame); \ | 1555 | PUSH_FAILURE_INT (fail_stack.frame); \ |
| 1577 | \ | 1556 | \ |
| 1578 | DEBUG_PRINT2 (" Push string %p: `", string_place); \ | 1557 | DEBUG_PRINT (" Push string %p: `", string_place); \ |
| 1579 | DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, size2);\ | 1558 | DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, size2);\ |
| 1580 | DEBUG_PRINT1 ("'\n"); \ | 1559 | DEBUG_PRINT ("'\n"); \ |
| 1581 | PUSH_FAILURE_POINTER (string_place); \ | 1560 | PUSH_FAILURE_POINTER (string_place); \ |
| 1582 | \ | 1561 | \ |
| 1583 | DEBUG_PRINT2 (" Push pattern %p: ", pattern); \ | 1562 | DEBUG_PRINT (" Push pattern %p: ", pattern); \ |
| 1584 | DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern, pend); \ | 1563 | DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern, pend); \ |
| 1585 | PUSH_FAILURE_POINTER (pattern); \ | 1564 | PUSH_FAILURE_POINTER (pattern); \ |
| 1586 | \ | 1565 | \ |
| @@ -1613,28 +1592,28 @@ do { \ | |||
| 1613 | assert (!FAIL_STACK_EMPTY ()); \ | 1592 | assert (!FAIL_STACK_EMPTY ()); \ |
| 1614 | \ | 1593 | \ |
| 1615 | /* Remove failure points and point to how many regs pushed. */ \ | 1594 | /* Remove failure points and point to how many regs pushed. */ \ |
| 1616 | DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \ | 1595 | DEBUG_PRINT ("POP_FAILURE_POINT:\n"); \ |
| 1617 | DEBUG_PRINT2 (" Before pop, next avail: %d\n", fail_stack.avail); \ | 1596 | DEBUG_PRINT (" Before pop, next avail: %zd\n", fail_stack.avail); \ |
| 1618 | DEBUG_PRINT2 (" size: %d\n", fail_stack.size); \ | 1597 | DEBUG_PRINT (" size: %zd\n", fail_stack.size); \ |
| 1619 | \ | 1598 | \ |
| 1620 | /* Pop the saved registers. */ \ | 1599 | /* Pop the saved registers. */ \ |
| 1621 | while (fail_stack.frame < fail_stack.avail) \ | 1600 | while (fail_stack.frame < fail_stack.avail) \ |
| 1622 | POP_FAILURE_REG_OR_COUNT (); \ | 1601 | POP_FAILURE_REG_OR_COUNT (); \ |
| 1623 | \ | 1602 | \ |
| 1624 | pat = POP_FAILURE_POINTER (); \ | 1603 | pat = POP_FAILURE_POINTER (); \ |
| 1625 | DEBUG_PRINT2 (" Popping pattern %p: ", pat); \ | 1604 | DEBUG_PRINT (" Popping pattern %p: ", pat); \ |
| 1626 | DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \ | 1605 | DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \ |
| 1627 | \ | 1606 | \ |
| 1628 | /* If the saved string location is NULL, it came from an \ | 1607 | /* If the saved string location is NULL, it came from an \ |
| 1629 | on_failure_keep_string_jump opcode, and we want to throw away the \ | 1608 | on_failure_keep_string_jump opcode, and we want to throw away the \ |
| 1630 | saved NULL, thus retaining our current position in the string. */ \ | 1609 | saved NULL, thus retaining our current position in the string. */ \ |
| 1631 | str = POP_FAILURE_POINTER (); \ | 1610 | str = POP_FAILURE_POINTER (); \ |
| 1632 | DEBUG_PRINT2 (" Popping string %p: `", str); \ | 1611 | DEBUG_PRINT (" Popping string %p: `", str); \ |
| 1633 | DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \ | 1612 | DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \ |
| 1634 | DEBUG_PRINT1 ("'\n"); \ | 1613 | DEBUG_PRINT ("'\n"); \ |
| 1635 | \ | 1614 | \ |
| 1636 | fail_stack.frame = POP_FAILURE_INT (); \ | 1615 | fail_stack.frame = POP_FAILURE_INT (); \ |
| 1637 | DEBUG_PRINT2 (" Popping frame index: %d\n", fail_stack.frame); \ | 1616 | DEBUG_PRINT (" Popping frame index: %zd\n", fail_stack.frame); \ |
| 1638 | \ | 1617 | \ |
| 1639 | assert (fail_stack.avail >= 0); \ | 1618 | assert (fail_stack.avail >= 0); \ |
| 1640 | assert (fail_stack.frame <= fail_stack.avail); \ | 1619 | assert (fail_stack.frame <= fail_stack.avail); \ |
| @@ -2497,7 +2476,7 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct | |||
| 2497 | 2476 | ||
| 2498 | #ifdef DEBUG | 2477 | #ifdef DEBUG |
| 2499 | debug++; | 2478 | debug++; |
| 2500 | DEBUG_PRINT1 ("\nCompiling pattern: "); | 2479 | DEBUG_PRINT ("\nCompiling pattern: "); |
| 2501 | if (debug > 0) | 2480 | if (debug > 0) |
| 2502 | { | 2481 | { |
| 2503 | unsigned debug_count; | 2482 | unsigned debug_count; |
| @@ -2650,7 +2629,7 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct | |||
| 2650 | goto normal_char; | 2629 | goto normal_char; |
| 2651 | handle_plus: | 2630 | handle_plus: |
| 2652 | case '*': | 2631 | case '*': |
| 2653 | /* If there is no previous pattern... */ | 2632 | /* If there is no previous pattern... */ |
| 2654 | if (!laststart) | 2633 | if (!laststart) |
| 2655 | { | 2634 | { |
| 2656 | if (syntax & RE_CONTEXT_INVALID_OPS) | 2635 | if (syntax & RE_CONTEXT_INVALID_OPS) |
| @@ -2758,7 +2737,7 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct | |||
| 2758 | } | 2737 | } |
| 2759 | } | 2738 | } |
| 2760 | else /* not greedy */ | 2739 | else /* not greedy */ |
| 2761 | { /* I wish the greedy and non-greedy cases could be merged. */ | 2740 | { /* I wish the greedy and non-greedy cases could be merged. */ |
| 2762 | 2741 | ||
| 2763 | GET_BUFFER_SPACE (7); /* We might use less. */ | 2742 | GET_BUFFER_SPACE (7); /* We might use less. */ |
| 2764 | if (many_times_ok) | 2743 | if (many_times_ok) |
| @@ -3062,7 +3041,7 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct | |||
| 3062 | 3041 | ||
| 3063 | /* Allocate space for COUNT + RANGE_TABLE. Needs two | 3042 | /* Allocate space for COUNT + RANGE_TABLE. Needs two |
| 3064 | bytes for flags, two for COUNT, and three bytes for | 3043 | bytes for flags, two for COUNT, and three bytes for |
| 3065 | each character. */ | 3044 | each character. */ |
| 3066 | GET_BUFFER_SPACE (4 + used * 3); | 3045 | GET_BUFFER_SPACE (4 + used * 3); |
| 3067 | 3046 | ||
| 3068 | /* Indicate the existence of range table. */ | 3047 | /* Indicate the existence of range table. */ |
| @@ -3489,6 +3468,7 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct | |||
| 3489 | /* There is no way to specify the before_dot and after_dot | 3468 | /* There is no way to specify the before_dot and after_dot |
| 3490 | operators. rms says this is ok. --karl */ | 3469 | operators. rms says this is ok. --karl */ |
| 3491 | case '=': | 3470 | case '=': |
| 3471 | laststart = b; | ||
| 3492 | BUF_PUSH (at_dot); | 3472 | BUF_PUSH (at_dot); |
| 3493 | break; | 3473 | break; |
| 3494 | 3474 | ||
| @@ -3537,12 +3517,14 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct | |||
| 3537 | case '<': | 3517 | case '<': |
| 3538 | if (syntax & RE_NO_GNU_OPS) | 3518 | if (syntax & RE_NO_GNU_OPS) |
| 3539 | goto normal_char; | 3519 | goto normal_char; |
| 3520 | laststart = b; | ||
| 3540 | BUF_PUSH (wordbeg); | 3521 | BUF_PUSH (wordbeg); |
| 3541 | break; | 3522 | break; |
| 3542 | 3523 | ||
| 3543 | case '>': | 3524 | case '>': |
| 3544 | if (syntax & RE_NO_GNU_OPS) | 3525 | if (syntax & RE_NO_GNU_OPS) |
| 3545 | goto normal_char; | 3526 | goto normal_char; |
| 3527 | laststart = b; | ||
| 3546 | BUF_PUSH (wordend); | 3528 | BUF_PUSH (wordend); |
| 3547 | break; | 3529 | break; |
| 3548 | 3530 | ||
| @@ -3701,7 +3683,7 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct | |||
| 3701 | if (debug > 0) | 3683 | if (debug > 0) |
| 3702 | { | 3684 | { |
| 3703 | re_compile_fastmap (bufp); | 3685 | re_compile_fastmap (bufp); |
| 3704 | DEBUG_PRINT1 ("\nCompiled pattern: \n"); | 3686 | DEBUG_PRINT ("\nCompiled pattern: \n"); |
| 3705 | print_compiled_pattern (bufp); | 3687 | print_compiled_pattern (bufp); |
| 3706 | } | 3688 | } |
| 3707 | debug--; | 3689 | debug--; |
| @@ -4527,8 +4509,8 @@ static int bcmp_translate (re_char *s1, re_char *s2, | |||
| 4527 | and `string2' into an offset from the beginning of that string. */ | 4509 | and `string2' into an offset from the beginning of that string. */ |
| 4528 | #define POINTER_TO_OFFSET(ptr) \ | 4510 | #define POINTER_TO_OFFSET(ptr) \ |
| 4529 | (FIRST_STRING_P (ptr) \ | 4511 | (FIRST_STRING_P (ptr) \ |
| 4530 | ? ((regoff_t) ((ptr) - string1)) \ | 4512 | ? (ptr) - string1 \ |
| 4531 | : ((regoff_t) ((ptr) - string2 + size1))) | 4513 | : (ptr) - string2 + (ptrdiff_t) size1) |
| 4532 | 4514 | ||
| 4533 | /* Call before fetching a character with *d. This switches over to | 4515 | /* Call before fetching a character with *d. This switches over to |
| 4534 | string2 if necessary. | 4516 | string2 if necessary. |
| @@ -4715,7 +4697,7 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r | |||
| 4715 | /* If we're at the end of the pattern, we can change. */ | 4697 | /* If we're at the end of the pattern, we can change. */ |
| 4716 | if (skip_one_char (p1)) | 4698 | if (skip_one_char (p1)) |
| 4717 | { | 4699 | { |
| 4718 | DEBUG_PRINT1 (" End of pattern: fast loop.\n"); | 4700 | DEBUG_PRINT (" End of pattern: fast loop.\n"); |
| 4719 | return 1; | 4701 | return 1; |
| 4720 | } | 4702 | } |
| 4721 | break; | 4703 | break; |
| @@ -4731,7 +4713,7 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r | |||
| 4731 | { | 4713 | { |
| 4732 | if (c != RE_STRING_CHAR (p1 + 2, multibyte)) | 4714 | if (c != RE_STRING_CHAR (p1 + 2, multibyte)) |
| 4733 | { | 4715 | { |
| 4734 | DEBUG_PRINT3 (" '%c' != '%c' => fast loop.\n", c, p1[2]); | 4716 | DEBUG_PRINT (" '%c' != '%c' => fast loop.\n", c, p1[2]); |
| 4735 | return 1; | 4717 | return 1; |
| 4736 | } | 4718 | } |
| 4737 | } | 4719 | } |
| @@ -4756,14 +4738,14 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r | |||
| 4756 | that we can't change to pop_failure_jump. */ | 4738 | that we can't change to pop_failure_jump. */ |
| 4757 | if (!not) | 4739 | if (!not) |
| 4758 | { | 4740 | { |
| 4759 | DEBUG_PRINT1 (" No match => fast loop.\n"); | 4741 | DEBUG_PRINT (" No match => fast loop.\n"); |
| 4760 | return 1; | 4742 | return 1; |
| 4761 | } | 4743 | } |
| 4762 | } | 4744 | } |
| 4763 | else if ((re_opcode_t) *p1 == anychar | 4745 | else if ((re_opcode_t) *p1 == anychar |
| 4764 | && c == '\n') | 4746 | && c == '\n') |
| 4765 | { | 4747 | { |
| 4766 | DEBUG_PRINT1 (" . != \\n => fast loop.\n"); | 4748 | DEBUG_PRINT (" . != \\n => fast loop.\n"); |
| 4767 | return 1; | 4749 | return 1; |
| 4768 | } | 4750 | } |
| 4769 | } | 4751 | } |
| @@ -4806,7 +4788,7 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r | |||
| 4806 | if (idx == p2[1] | 4788 | if (idx == p2[1] |
| 4807 | || idx == CHARSET_BITMAP_SIZE (p1)) | 4789 | || idx == CHARSET_BITMAP_SIZE (p1)) |
| 4808 | { | 4790 | { |
| 4809 | DEBUG_PRINT1 (" No match => fast loop.\n"); | 4791 | DEBUG_PRINT (" No match => fast loop.\n"); |
| 4810 | return 1; | 4792 | return 1; |
| 4811 | } | 4793 | } |
| 4812 | } | 4794 | } |
| @@ -4823,7 +4805,7 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r | |||
| 4823 | 4805 | ||
| 4824 | if (idx == p2[1]) | 4806 | if (idx == p2[1]) |
| 4825 | { | 4807 | { |
| 4826 | DEBUG_PRINT1 (" No match => fast loop.\n"); | 4808 | DEBUG_PRINT (" No match => fast loop.\n"); |
| 4827 | return 1; | 4809 | return 1; |
| 4828 | } | 4810 | } |
| 4829 | } | 4811 | } |
| @@ -4943,7 +4925,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 4943 | ssize_t pos, struct re_registers *regs, ssize_t stop) | 4925 | ssize_t pos, struct re_registers *regs, ssize_t stop) |
| 4944 | { | 4926 | { |
| 4945 | /* General temporaries. */ | 4927 | /* General temporaries. */ |
| 4946 | ssize_t mcnt; | 4928 | int mcnt; |
| 4947 | size_t reg; | 4929 | size_t reg; |
| 4948 | 4930 | ||
| 4949 | /* Just past the end of the corresponding string. */ | 4931 | /* Just past the end of the corresponding string. */ |
| @@ -4985,7 +4967,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 4985 | #ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */ | 4967 | #ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */ |
| 4986 | fail_stack_type fail_stack; | 4968 | fail_stack_type fail_stack; |
| 4987 | #endif | 4969 | #endif |
| 4988 | #ifdef DEBUG | 4970 | #ifdef DEBUG_COMPILES_ARGUMENTS |
| 4989 | unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0; | 4971 | unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0; |
| 4990 | #endif | 4972 | #endif |
| 4991 | 4973 | ||
| @@ -5030,12 +5012,12 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5030 | and need to test it, it's not garbage. */ | 5012 | and need to test it, it's not garbage. */ |
| 5031 | re_char *match_end = NULL; | 5013 | re_char *match_end = NULL; |
| 5032 | 5014 | ||
| 5033 | #ifdef DEBUG | 5015 | #ifdef DEBUG_COMPILES_ARGUMENTS |
| 5034 | /* Counts the total number of registers pushed. */ | 5016 | /* Counts the total number of registers pushed. */ |
| 5035 | unsigned num_regs_pushed = 0; | 5017 | unsigned num_regs_pushed = 0; |
| 5036 | #endif | 5018 | #endif |
| 5037 | 5019 | ||
| 5038 | DEBUG_PRINT1 ("\n\nEntering re_match_2.\n"); | 5020 | DEBUG_PRINT ("\n\nEntering re_match_2.\n"); |
| 5039 | 5021 | ||
| 5040 | INIT_FAIL_STACK (); | 5022 | INIT_FAIL_STACK (); |
| 5041 | 5023 | ||
| @@ -5131,22 +5113,25 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5131 | dend = end_match_1; | 5113 | dend = end_match_1; |
| 5132 | } | 5114 | } |
| 5133 | 5115 | ||
| 5134 | DEBUG_PRINT1 ("The compiled pattern is: "); | 5116 | DEBUG_PRINT ("The compiled pattern is: "); |
| 5135 | DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend); | 5117 | DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend); |
| 5136 | DEBUG_PRINT1 ("The string to match is: `"); | 5118 | DEBUG_PRINT ("The string to match is: `"); |
| 5137 | DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2); | 5119 | DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2); |
| 5138 | DEBUG_PRINT1 ("'\n"); | 5120 | DEBUG_PRINT ("'\n"); |
| 5139 | 5121 | ||
| 5140 | /* This loops over pattern commands. It exits by returning from the | 5122 | /* This loops over pattern commands. It exits by returning from the |
| 5141 | function if the match is complete, or it drops through if the match | 5123 | function if the match is complete, or it drops through if the match |
| 5142 | fails at this starting point in the input data. */ | 5124 | fails at this starting point in the input data. */ |
| 5143 | for (;;) | 5125 | for (;;) |
| 5144 | { | 5126 | { |
| 5145 | DEBUG_PRINT2 ("\n%p: ", p); | 5127 | DEBUG_PRINT ("\n%p: ", p); |
| 5146 | 5128 | ||
| 5147 | if (p == pend) | 5129 | if (p == pend) |
| 5148 | { /* End of pattern means we might have succeeded. */ | 5130 | { |
| 5149 | DEBUG_PRINT1 ("end of pattern ... "); | 5131 | ptrdiff_t dcnt; |
| 5132 | |||
| 5133 | /* End of pattern means we might have succeeded. */ | ||
| 5134 | DEBUG_PRINT ("end of pattern ... "); | ||
| 5150 | 5135 | ||
| 5151 | /* If we haven't matched the entire string, and we want the | 5136 | /* If we haven't matched the entire string, and we want the |
| 5152 | longest match, try backtracking. */ | 5137 | longest match, try backtracking. */ |
| @@ -5166,7 +5151,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5166 | else | 5151 | else |
| 5167 | best_match_p = !FIRST_STRING_P (d); | 5152 | best_match_p = !FIRST_STRING_P (d); |
| 5168 | 5153 | ||
| 5169 | DEBUG_PRINT1 ("backtracking.\n"); | 5154 | DEBUG_PRINT ("backtracking.\n"); |
| 5170 | 5155 | ||
| 5171 | if (!FAIL_STACK_EMPTY ()) | 5156 | if (!FAIL_STACK_EMPTY ()) |
| 5172 | { /* More failure points to try. */ | 5157 | { /* More failure points to try. */ |
| @@ -5177,7 +5162,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5177 | best_regs_set = true; | 5162 | best_regs_set = true; |
| 5178 | match_end = d; | 5163 | match_end = d; |
| 5179 | 5164 | ||
| 5180 | DEBUG_PRINT1 ("\nSAVING match as best so far.\n"); | 5165 | DEBUG_PRINT ("\nSAVING match as best so far.\n"); |
| 5181 | 5166 | ||
| 5182 | for (reg = 1; reg < num_regs; reg++) | 5167 | for (reg = 1; reg < num_regs; reg++) |
| 5183 | { | 5168 | { |
| @@ -5199,7 +5184,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5199 | For example, the pattern `x.*y.*z' against the | 5184 | For example, the pattern `x.*y.*z' against the |
| 5200 | strings `x-' and `y-z-', if the two strings are | 5185 | strings `x-' and `y-z-', if the two strings are |
| 5201 | not consecutive in memory. */ | 5186 | not consecutive in memory. */ |
| 5202 | DEBUG_PRINT1 ("Restoring best registers.\n"); | 5187 | DEBUG_PRINT ("Restoring best registers.\n"); |
| 5203 | 5188 | ||
| 5204 | d = match_end; | 5189 | d = match_end; |
| 5205 | dend = ((d >= string1 && d <= end1) | 5190 | dend = ((d >= string1 && d <= end1) |
| @@ -5214,7 +5199,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5214 | } /* d != end_match_2 */ | 5199 | } /* d != end_match_2 */ |
| 5215 | 5200 | ||
| 5216 | succeed_label: | 5201 | succeed_label: |
| 5217 | DEBUG_PRINT1 ("Accepting match.\n"); | 5202 | DEBUG_PRINT ("Accepting match.\n"); |
| 5218 | 5203 | ||
| 5219 | /* If caller wants register contents data back, do it. */ | 5204 | /* If caller wants register contents data back, do it. */ |
| 5220 | if (regs && !bufp->no_sub) | 5205 | if (regs && !bufp->no_sub) |
| @@ -5274,10 +5259,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5274 | regs->start[reg] = regs->end[reg] = -1; | 5259 | regs->start[reg] = regs->end[reg] = -1; |
| 5275 | else | 5260 | else |
| 5276 | { | 5261 | { |
| 5277 | regs->start[reg] | 5262 | regs->start[reg] = POINTER_TO_OFFSET (regstart[reg]); |
| 5278 | = (regoff_t) POINTER_TO_OFFSET (regstart[reg]); | 5263 | regs->end[reg] = POINTER_TO_OFFSET (regend[reg]); |
| 5279 | regs->end[reg] | ||
| 5280 | = (regoff_t) POINTER_TO_OFFSET (regend[reg]); | ||
| 5281 | } | 5264 | } |
| 5282 | } | 5265 | } |
| 5283 | 5266 | ||
| @@ -5290,17 +5273,17 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5290 | regs->start[reg] = regs->end[reg] = -1; | 5273 | regs->start[reg] = regs->end[reg] = -1; |
| 5291 | } /* regs && !bufp->no_sub */ | 5274 | } /* regs && !bufp->no_sub */ |
| 5292 | 5275 | ||
| 5293 | DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n", | 5276 | DEBUG_PRINT ("%u failure points pushed, %u popped (%u remain).\n", |
| 5294 | nfailure_points_pushed, nfailure_points_popped, | 5277 | nfailure_points_pushed, nfailure_points_popped, |
| 5295 | nfailure_points_pushed - nfailure_points_popped); | 5278 | nfailure_points_pushed - nfailure_points_popped); |
| 5296 | DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed); | 5279 | DEBUG_PRINT ("%u registers pushed.\n", num_regs_pushed); |
| 5297 | 5280 | ||
| 5298 | mcnt = POINTER_TO_OFFSET (d) - pos; | 5281 | dcnt = POINTER_TO_OFFSET (d) - pos; |
| 5299 | 5282 | ||
| 5300 | DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt); | 5283 | DEBUG_PRINT ("Returning %td from re_match_2.\n", dcnt); |
| 5301 | 5284 | ||
| 5302 | FREE_VARIABLES (); | 5285 | FREE_VARIABLES (); |
| 5303 | return mcnt; | 5286 | return dcnt; |
| 5304 | } | 5287 | } |
| 5305 | 5288 | ||
| 5306 | /* Otherwise match next pattern command. */ | 5289 | /* Otherwise match next pattern command. */ |
| @@ -5309,11 +5292,11 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5309 | /* Ignore these. Used to ignore the n of succeed_n's which | 5292 | /* Ignore these. Used to ignore the n of succeed_n's which |
| 5310 | currently have n == 0. */ | 5293 | currently have n == 0. */ |
| 5311 | case no_op: | 5294 | case no_op: |
| 5312 | DEBUG_PRINT1 ("EXECUTING no_op.\n"); | 5295 | DEBUG_PRINT ("EXECUTING no_op.\n"); |
| 5313 | break; | 5296 | break; |
| 5314 | 5297 | ||
| 5315 | case succeed: | 5298 | case succeed: |
| 5316 | DEBUG_PRINT1 ("EXECUTING succeed.\n"); | 5299 | DEBUG_PRINT ("EXECUTING succeed.\n"); |
| 5317 | goto succeed_label; | 5300 | goto succeed_label; |
| 5318 | 5301 | ||
| 5319 | /* Match the next n pattern characters exactly. The following | 5302 | /* Match the next n pattern characters exactly. The following |
| @@ -5321,7 +5304,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5321 | are the characters to match. */ | 5304 | are the characters to match. */ |
| 5322 | case exactn: | 5305 | case exactn: |
| 5323 | mcnt = *p++; | 5306 | mcnt = *p++; |
| 5324 | DEBUG_PRINT2 ("EXECUTING exactn %d.\n", mcnt); | 5307 | DEBUG_PRINT ("EXECUTING exactn %d.\n", mcnt); |
| 5325 | 5308 | ||
| 5326 | /* Remember the start point to rollback upon failure. */ | 5309 | /* Remember the start point to rollback upon failure. */ |
| 5327 | dfail = d; | 5310 | dfail = d; |
| @@ -5427,7 +5410,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5427 | int buf_charlen; | 5410 | int buf_charlen; |
| 5428 | re_wchar_t buf_ch; | 5411 | re_wchar_t buf_ch; |
| 5429 | 5412 | ||
| 5430 | DEBUG_PRINT1 ("EXECUTING anychar.\n"); | 5413 | DEBUG_PRINT ("EXECUTING anychar.\n"); |
| 5431 | 5414 | ||
| 5432 | PREFETCH (); | 5415 | PREFETCH (); |
| 5433 | buf_ch = RE_STRING_CHAR_AND_LENGTH (d, buf_charlen, | 5416 | buf_ch = RE_STRING_CHAR_AND_LENGTH (d, buf_charlen, |
| @@ -5440,7 +5423,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5440 | && buf_ch == '\000')) | 5423 | && buf_ch == '\000')) |
| 5441 | goto fail; | 5424 | goto fail; |
| 5442 | 5425 | ||
| 5443 | DEBUG_PRINT2 (" Matched `%d'.\n", *d); | 5426 | DEBUG_PRINT (" Matched `%d'.\n", *d); |
| 5444 | d += buf_charlen; | 5427 | d += buf_charlen; |
| 5445 | } | 5428 | } |
| 5446 | break; | 5429 | break; |
| @@ -5467,7 +5450,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5467 | /* Whether matching against a unibyte character. */ | 5450 | /* Whether matching against a unibyte character. */ |
| 5468 | boolean unibyte_char = false; | 5451 | boolean unibyte_char = false; |
| 5469 | 5452 | ||
| 5470 | DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : ""); | 5453 | DEBUG_PRINT ("EXECUTING charset%s.\n", not ? "_not" : ""); |
| 5471 | 5454 | ||
| 5472 | range_table_exists = CHARSET_RANGE_TABLE_EXISTS_P (&p[-1]); | 5455 | range_table_exists = CHARSET_RANGE_TABLE_EXISTS_P (&p[-1]); |
| 5473 | 5456 | ||
| @@ -5551,14 +5534,14 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5551 | matched within the group is recorded (in the internal | 5534 | matched within the group is recorded (in the internal |
| 5552 | registers data structure) under the register number. */ | 5535 | registers data structure) under the register number. */ |
| 5553 | case start_memory: | 5536 | case start_memory: |
| 5554 | DEBUG_PRINT2 ("EXECUTING start_memory %d:\n", *p); | 5537 | DEBUG_PRINT ("EXECUTING start_memory %d:\n", *p); |
| 5555 | 5538 | ||
| 5556 | /* In case we need to undo this operation (via backtracking). */ | 5539 | /* In case we need to undo this operation (via backtracking). */ |
| 5557 | PUSH_FAILURE_REG ((unsigned int)*p); | 5540 | PUSH_FAILURE_REG (*p); |
| 5558 | 5541 | ||
| 5559 | regstart[*p] = d; | 5542 | regstart[*p] = d; |
| 5560 | regend[*p] = NULL; /* probably unnecessary. -sm */ | 5543 | regend[*p] = NULL; /* probably unnecessary. -sm */ |
| 5561 | DEBUG_PRINT2 (" regstart: %d\n", POINTER_TO_OFFSET (regstart[*p])); | 5544 | DEBUG_PRINT (" regstart: %td\n", POINTER_TO_OFFSET (regstart[*p])); |
| 5562 | 5545 | ||
| 5563 | /* Move past the register number and inner group count. */ | 5546 | /* Move past the register number and inner group count. */ |
| 5564 | p += 1; | 5547 | p += 1; |
| @@ -5568,7 +5551,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5568 | /* The stop_memory opcode represents the end of a group. Its | 5551 | /* The stop_memory opcode represents the end of a group. Its |
| 5569 | argument is the same as start_memory's: the register number. */ | 5552 | argument is the same as start_memory's: the register number. */ |
| 5570 | case stop_memory: | 5553 | case stop_memory: |
| 5571 | DEBUG_PRINT2 ("EXECUTING stop_memory %d:\n", *p); | 5554 | DEBUG_PRINT ("EXECUTING stop_memory %d:\n", *p); |
| 5572 | 5555 | ||
| 5573 | assert (!REG_UNSET (regstart[*p])); | 5556 | assert (!REG_UNSET (regstart[*p])); |
| 5574 | /* Strictly speaking, there should be code such as: | 5557 | /* Strictly speaking, there should be code such as: |
| @@ -5586,7 +5569,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5586 | is *not* undone. */ | 5569 | is *not* undone. */ |
| 5587 | 5570 | ||
| 5588 | regend[*p] = d; | 5571 | regend[*p] = d; |
| 5589 | DEBUG_PRINT2 (" regend: %d\n", POINTER_TO_OFFSET (regend[*p])); | 5572 | DEBUG_PRINT (" regend: %td\n", POINTER_TO_OFFSET (regend[*p])); |
| 5590 | 5573 | ||
| 5591 | /* Move past the register number and the inner group count. */ | 5574 | /* Move past the register number and the inner group count. */ |
| 5592 | p += 1; | 5575 | p += 1; |
| @@ -5599,7 +5582,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5599 | { | 5582 | { |
| 5600 | register re_char *d2, *dend2; | 5583 | register re_char *d2, *dend2; |
| 5601 | int regno = *p++; /* Get which register to match against. */ | 5584 | int regno = *p++; /* Get which register to match against. */ |
| 5602 | DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno); | 5585 | DEBUG_PRINT ("EXECUTING duplicate %d.\n", regno); |
| 5603 | 5586 | ||
| 5604 | /* Can't back reference a group which we've never matched. */ | 5587 | /* Can't back reference a group which we've never matched. */ |
| 5605 | if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno])) | 5588 | if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno])) |
| @@ -5621,6 +5604,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5621 | ? regend[regno] : end_match_1); | 5604 | ? regend[regno] : end_match_1); |
| 5622 | for (;;) | 5605 | for (;;) |
| 5623 | { | 5606 | { |
| 5607 | ptrdiff_t dcnt; | ||
| 5608 | |||
| 5624 | /* If necessary, advance to next segment in register | 5609 | /* If necessary, advance to next segment in register |
| 5625 | contents. */ | 5610 | contents. */ |
| 5626 | while (d2 == dend2) | 5611 | while (d2 == dend2) |
| @@ -5639,23 +5624,23 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5639 | PREFETCH (); | 5624 | PREFETCH (); |
| 5640 | 5625 | ||
| 5641 | /* How many characters left in this segment to match. */ | 5626 | /* How many characters left in this segment to match. */ |
| 5642 | mcnt = dend - d; | 5627 | dcnt = dend - d; |
| 5643 | 5628 | ||
| 5644 | /* Want how many consecutive characters we can match in | 5629 | /* Want how many consecutive characters we can match in |
| 5645 | one shot, so, if necessary, adjust the count. */ | 5630 | one shot, so, if necessary, adjust the count. */ |
| 5646 | if (mcnt > dend2 - d2) | 5631 | if (dcnt > dend2 - d2) |
| 5647 | mcnt = dend2 - d2; | 5632 | dcnt = dend2 - d2; |
| 5648 | 5633 | ||
| 5649 | /* Compare that many; failure if mismatch, else move | 5634 | /* Compare that many; failure if mismatch, else move |
| 5650 | past them. */ | 5635 | past them. */ |
| 5651 | if (RE_TRANSLATE_P (translate) | 5636 | if (RE_TRANSLATE_P (translate) |
| 5652 | ? bcmp_translate (d, d2, mcnt, translate, target_multibyte) | 5637 | ? bcmp_translate (d, d2, dcnt, translate, target_multibyte) |
| 5653 | : memcmp (d, d2, mcnt)) | 5638 | : memcmp (d, d2, dcnt)) |
| 5654 | { | 5639 | { |
| 5655 | d = dfail; | 5640 | d = dfail; |
| 5656 | goto fail; | 5641 | goto fail; |
| 5657 | } | 5642 | } |
| 5658 | d += mcnt, d2 += mcnt; | 5643 | d += dcnt, d2 += dcnt; |
| 5659 | } | 5644 | } |
| 5660 | } | 5645 | } |
| 5661 | break; | 5646 | break; |
| @@ -5664,7 +5649,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5664 | /* begline matches the empty string at the beginning of the string | 5649 | /* begline matches the empty string at the beginning of the string |
| 5665 | (unless `not_bol' is set in `bufp'), and after newlines. */ | 5650 | (unless `not_bol' is set in `bufp'), and after newlines. */ |
| 5666 | case begline: | 5651 | case begline: |
| 5667 | DEBUG_PRINT1 ("EXECUTING begline.\n"); | 5652 | DEBUG_PRINT ("EXECUTING begline.\n"); |
| 5668 | 5653 | ||
| 5669 | if (AT_STRINGS_BEG (d)) | 5654 | if (AT_STRINGS_BEG (d)) |
| 5670 | { | 5655 | { |
| @@ -5683,7 +5668,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5683 | 5668 | ||
| 5684 | /* endline is the dual of begline. */ | 5669 | /* endline is the dual of begline. */ |
| 5685 | case endline: | 5670 | case endline: |
| 5686 | DEBUG_PRINT1 ("EXECUTING endline.\n"); | 5671 | DEBUG_PRINT ("EXECUTING endline.\n"); |
| 5687 | 5672 | ||
| 5688 | if (AT_STRINGS_END (d)) | 5673 | if (AT_STRINGS_END (d)) |
| 5689 | { | 5674 | { |
| @@ -5700,7 +5685,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5700 | 5685 | ||
| 5701 | /* Match at the very beginning of the data. */ | 5686 | /* Match at the very beginning of the data. */ |
| 5702 | case begbuf: | 5687 | case begbuf: |
| 5703 | DEBUG_PRINT1 ("EXECUTING begbuf.\n"); | 5688 | DEBUG_PRINT ("EXECUTING begbuf.\n"); |
| 5704 | if (AT_STRINGS_BEG (d)) | 5689 | if (AT_STRINGS_BEG (d)) |
| 5705 | break; | 5690 | break; |
| 5706 | goto fail; | 5691 | goto fail; |
| @@ -5708,7 +5693,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5708 | 5693 | ||
| 5709 | /* Match at the very end of the data. */ | 5694 | /* Match at the very end of the data. */ |
| 5710 | case endbuf: | 5695 | case endbuf: |
| 5711 | DEBUG_PRINT1 ("EXECUTING endbuf.\n"); | 5696 | DEBUG_PRINT ("EXECUTING endbuf.\n"); |
| 5712 | if (AT_STRINGS_END (d)) | 5697 | if (AT_STRINGS_END (d)) |
| 5713 | break; | 5698 | break; |
| 5714 | goto fail; | 5699 | goto fail; |
| @@ -5732,8 +5717,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5732 | case; that seems worse than this. */ | 5717 | case; that seems worse than this. */ |
| 5733 | case on_failure_keep_string_jump: | 5718 | case on_failure_keep_string_jump: |
| 5734 | EXTRACT_NUMBER_AND_INCR (mcnt, p); | 5719 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 5735 | DEBUG_PRINT3 ("EXECUTING on_failure_keep_string_jump %d (to %p):\n", | 5720 | DEBUG_PRINT ("EXECUTING on_failure_keep_string_jump %d (to %p):\n", |
| 5736 | mcnt, p + mcnt); | 5721 | mcnt, p + mcnt); |
| 5737 | 5722 | ||
| 5738 | PUSH_FAILURE_POINT (p - 3, NULL); | 5723 | PUSH_FAILURE_POINT (p - 3, NULL); |
| 5739 | break; | 5724 | break; |
| @@ -5754,8 +5739,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5754 | the loop. */ | 5739 | the loop. */ |
| 5755 | case on_failure_jump_nastyloop: | 5740 | case on_failure_jump_nastyloop: |
| 5756 | EXTRACT_NUMBER_AND_INCR (mcnt, p); | 5741 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 5757 | DEBUG_PRINT3 ("EXECUTING on_failure_jump_nastyloop %d (to %p):\n", | 5742 | DEBUG_PRINT ("EXECUTING on_failure_jump_nastyloop %d (to %p):\n", |
| 5758 | mcnt, p + mcnt); | 5743 | mcnt, p + mcnt); |
| 5759 | 5744 | ||
| 5760 | assert ((re_opcode_t)p[-4] == no_op); | 5745 | assert ((re_opcode_t)p[-4] == no_op); |
| 5761 | { | 5746 | { |
| @@ -5775,8 +5760,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5775 | case on_failure_jump_loop: | 5760 | case on_failure_jump_loop: |
| 5776 | on_failure: | 5761 | on_failure: |
| 5777 | EXTRACT_NUMBER_AND_INCR (mcnt, p); | 5762 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 5778 | DEBUG_PRINT3 ("EXECUTING on_failure_jump_loop %d (to %p):\n", | 5763 | DEBUG_PRINT ("EXECUTING on_failure_jump_loop %d (to %p):\n", |
| 5779 | mcnt, p + mcnt); | 5764 | mcnt, p + mcnt); |
| 5780 | { | 5765 | { |
| 5781 | int cycle = 0; | 5766 | int cycle = 0; |
| 5782 | CHECK_INFINITE_LOOP (p - 3, d); | 5767 | CHECK_INFINITE_LOOP (p - 3, d); |
| @@ -5807,8 +5792,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5807 | pop_failure_jump back to this on_failure_jump. */ | 5792 | pop_failure_jump back to this on_failure_jump. */ |
| 5808 | case on_failure_jump: | 5793 | case on_failure_jump: |
| 5809 | EXTRACT_NUMBER_AND_INCR (mcnt, p); | 5794 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 5810 | DEBUG_PRINT3 ("EXECUTING on_failure_jump %d (to %p):\n", | 5795 | DEBUG_PRINT ("EXECUTING on_failure_jump %d (to %p):\n", |
| 5811 | mcnt, p + mcnt); | 5796 | mcnt, p + mcnt); |
| 5812 | 5797 | ||
| 5813 | PUSH_FAILURE_POINT (p -3, d); | 5798 | PUSH_FAILURE_POINT (p -3, d); |
| 5814 | break; | 5799 | break; |
| @@ -5822,8 +5807,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5822 | on_failure_keep_string_jump instead of on_failure_jump. */ | 5807 | on_failure_keep_string_jump instead of on_failure_jump. */ |
| 5823 | case on_failure_jump_smart: | 5808 | case on_failure_jump_smart: |
| 5824 | EXTRACT_NUMBER_AND_INCR (mcnt, p); | 5809 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 5825 | DEBUG_PRINT3 ("EXECUTING on_failure_jump_smart %d (to %p).\n", | 5810 | DEBUG_PRINT ("EXECUTING on_failure_jump_smart %d (to %p).\n", |
| 5826 | mcnt, p + mcnt); | 5811 | mcnt, p + mcnt); |
| 5827 | { | 5812 | { |
| 5828 | re_char *p1 = p; /* Next operation. */ | 5813 | re_char *p1 = p; /* Next operation. */ |
| 5829 | /* Here, we discard `const', making re_match non-reentrant. */ | 5814 | /* Here, we discard `const', making re_match non-reentrant. */ |
| @@ -5843,14 +5828,14 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5843 | if (mutually_exclusive_p (bufp, p1, p2)) | 5828 | if (mutually_exclusive_p (bufp, p1, p2)) |
| 5844 | { | 5829 | { |
| 5845 | /* Use a fast `on_failure_keep_string_jump' loop. */ | 5830 | /* Use a fast `on_failure_keep_string_jump' loop. */ |
| 5846 | DEBUG_PRINT1 (" smart exclusive => fast loop.\n"); | 5831 | DEBUG_PRINT (" smart exclusive => fast loop.\n"); |
| 5847 | *p3 = (unsigned char) on_failure_keep_string_jump; | 5832 | *p3 = (unsigned char) on_failure_keep_string_jump; |
| 5848 | STORE_NUMBER (p2 - 2, mcnt + 3); | 5833 | STORE_NUMBER (p2 - 2, mcnt + 3); |
| 5849 | } | 5834 | } |
| 5850 | else | 5835 | else |
| 5851 | { | 5836 | { |
| 5852 | /* Default to a safe `on_failure_jump' loop. */ | 5837 | /* Default to a safe `on_failure_jump' loop. */ |
| 5853 | DEBUG_PRINT1 (" smart default => slow loop.\n"); | 5838 | DEBUG_PRINT (" smart default => slow loop.\n"); |
| 5854 | *p3 = (unsigned char) on_failure_jump; | 5839 | *p3 = (unsigned char) on_failure_jump; |
| 5855 | } | 5840 | } |
| 5856 | DEBUG_STATEMENT (debug -= 2); | 5841 | DEBUG_STATEMENT (debug -= 2); |
| @@ -5862,9 +5847,9 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5862 | unconditional_jump: | 5847 | unconditional_jump: |
| 5863 | IMMEDIATE_QUIT_CHECK; | 5848 | IMMEDIATE_QUIT_CHECK; |
| 5864 | EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */ | 5849 | EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */ |
| 5865 | DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt); | 5850 | DEBUG_PRINT ("EXECUTING jump %d ", mcnt); |
| 5866 | p += mcnt; /* Do the jump. */ | 5851 | p += mcnt; /* Do the jump. */ |
| 5867 | DEBUG_PRINT2 ("(to %p).\n", p); | 5852 | DEBUG_PRINT ("(to %p).\n", p); |
| 5868 | break; | 5853 | break; |
| 5869 | 5854 | ||
| 5870 | 5855 | ||
| @@ -5873,7 +5858,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5873 | case succeed_n: | 5858 | case succeed_n: |
| 5874 | /* Signedness doesn't matter since we only compare MCNT to 0. */ | 5859 | /* Signedness doesn't matter since we only compare MCNT to 0. */ |
| 5875 | EXTRACT_NUMBER (mcnt, p + 2); | 5860 | EXTRACT_NUMBER (mcnt, p + 2); |
| 5876 | DEBUG_PRINT2 ("EXECUTING succeed_n %d.\n", mcnt); | 5861 | DEBUG_PRINT ("EXECUTING succeed_n %d.\n", mcnt); |
| 5877 | 5862 | ||
| 5878 | /* Originally, mcnt is how many times we HAVE to succeed. */ | 5863 | /* Originally, mcnt is how many times we HAVE to succeed. */ |
| 5879 | if (mcnt != 0) | 5864 | if (mcnt != 0) |
| @@ -5892,7 +5877,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5892 | case jump_n: | 5877 | case jump_n: |
| 5893 | /* Signedness doesn't matter since we only compare MCNT to 0. */ | 5878 | /* Signedness doesn't matter since we only compare MCNT to 0. */ |
| 5894 | EXTRACT_NUMBER (mcnt, p + 2); | 5879 | EXTRACT_NUMBER (mcnt, p + 2); |
| 5895 | DEBUG_PRINT2 ("EXECUTING jump_n %d.\n", mcnt); | 5880 | DEBUG_PRINT ("EXECUTING jump_n %d.\n", mcnt); |
| 5896 | 5881 | ||
| 5897 | /* Originally, this is how many times we CAN jump. */ | 5882 | /* Originally, this is how many times we CAN jump. */ |
| 5898 | if (mcnt != 0) | 5883 | if (mcnt != 0) |
| @@ -5911,14 +5896,14 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5911 | case set_number_at: | 5896 | case set_number_at: |
| 5912 | { | 5897 | { |
| 5913 | unsigned char *p2; /* Location of the counter. */ | 5898 | unsigned char *p2; /* Location of the counter. */ |
| 5914 | DEBUG_PRINT1 ("EXECUTING set_number_at.\n"); | 5899 | DEBUG_PRINT ("EXECUTING set_number_at.\n"); |
| 5915 | 5900 | ||
| 5916 | EXTRACT_NUMBER_AND_INCR (mcnt, p); | 5901 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 5917 | /* Here, we discard `const', making re_match non-reentrant. */ | 5902 | /* Here, we discard `const', making re_match non-reentrant. */ |
| 5918 | p2 = (unsigned char*) p + mcnt; | 5903 | p2 = (unsigned char*) p + mcnt; |
| 5919 | /* Signedness doesn't matter since we only copy MCNT's bits . */ | 5904 | /* Signedness doesn't matter since we only copy MCNT's bits . */ |
| 5920 | EXTRACT_NUMBER_AND_INCR (mcnt, p); | 5905 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 5921 | DEBUG_PRINT3 (" Setting %p to %d.\n", p2, mcnt); | 5906 | DEBUG_PRINT (" Setting %p to %d.\n", p2, mcnt); |
| 5922 | PUSH_NUMBER (p2, mcnt); | 5907 | PUSH_NUMBER (p2, mcnt); |
| 5923 | break; | 5908 | break; |
| 5924 | } | 5909 | } |
| @@ -5927,7 +5912,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5927 | case notwordbound: | 5912 | case notwordbound: |
| 5928 | { | 5913 | { |
| 5929 | boolean not = (re_opcode_t) *(p - 1) == notwordbound; | 5914 | boolean not = (re_opcode_t) *(p - 1) == notwordbound; |
| 5930 | DEBUG_PRINT2 ("EXECUTING %swordbound.\n", not?"not":""); | 5915 | DEBUG_PRINT ("EXECUTING %swordbound.\n", not ? "not" : ""); |
| 5931 | 5916 | ||
| 5932 | /* We SUCCEED (or FAIL) in one of the following cases: */ | 5917 | /* We SUCCEED (or FAIL) in one of the following cases: */ |
| 5933 | 5918 | ||
| @@ -5969,7 +5954,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 5969 | } | 5954 | } |
| 5970 | 5955 | ||
| 5971 | case wordbeg: | 5956 | case wordbeg: |
| 5972 | DEBUG_PRINT1 ("EXECUTING wordbeg.\n"); | 5957 | DEBUG_PRINT ("EXECUTING wordbeg.\n"); |
| 5973 | 5958 | ||
| 5974 | /* We FAIL in one of the following cases: */ | 5959 | /* We FAIL in one of the following cases: */ |
| 5975 | 5960 | ||
| @@ -6014,7 +5999,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 6014 | break; | 5999 | break; |
| 6015 | 6000 | ||
| 6016 | case wordend: | 6001 | case wordend: |
| 6017 | DEBUG_PRINT1 ("EXECUTING wordend.\n"); | 6002 | DEBUG_PRINT ("EXECUTING wordend.\n"); |
| 6018 | 6003 | ||
| 6019 | /* We FAIL in one of the following cases: */ | 6004 | /* We FAIL in one of the following cases: */ |
| 6020 | 6005 | ||
| @@ -6059,7 +6044,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 6059 | break; | 6044 | break; |
| 6060 | 6045 | ||
| 6061 | case symbeg: | 6046 | case symbeg: |
| 6062 | DEBUG_PRINT1 ("EXECUTING symbeg.\n"); | 6047 | DEBUG_PRINT ("EXECUTING symbeg.\n"); |
| 6063 | 6048 | ||
| 6064 | /* We FAIL in one of the following cases: */ | 6049 | /* We FAIL in one of the following cases: */ |
| 6065 | 6050 | ||
| @@ -6102,7 +6087,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 6102 | break; | 6087 | break; |
| 6103 | 6088 | ||
| 6104 | case symend: | 6089 | case symend: |
| 6105 | DEBUG_PRINT1 ("EXECUTING symend.\n"); | 6090 | DEBUG_PRINT ("EXECUTING symend.\n"); |
| 6106 | 6091 | ||
| 6107 | /* We FAIL in one of the following cases: */ | 6092 | /* We FAIL in one of the following cases: */ |
| 6108 | 6093 | ||
| @@ -6149,7 +6134,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 6149 | { | 6134 | { |
| 6150 | boolean not = (re_opcode_t) *(p - 1) == notsyntaxspec; | 6135 | boolean not = (re_opcode_t) *(p - 1) == notsyntaxspec; |
| 6151 | mcnt = *p++; | 6136 | mcnt = *p++; |
| 6152 | DEBUG_PRINT3 ("EXECUTING %ssyntaxspec %d.\n", not?"not":"", mcnt); | 6137 | DEBUG_PRINT ("EXECUTING %ssyntaxspec %d.\n", not ? "not" : "", |
| 6138 | mcnt); | ||
| 6153 | PREFETCH (); | 6139 | PREFETCH (); |
| 6154 | #ifdef emacs | 6140 | #ifdef emacs |
| 6155 | { | 6141 | { |
| @@ -6172,19 +6158,19 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 6172 | 6158 | ||
| 6173 | #ifdef emacs | 6159 | #ifdef emacs |
| 6174 | case before_dot: | 6160 | case before_dot: |
| 6175 | DEBUG_PRINT1 ("EXECUTING before_dot.\n"); | 6161 | DEBUG_PRINT ("EXECUTING before_dot.\n"); |
| 6176 | if (PTR_BYTE_POS (d) >= PT_BYTE) | 6162 | if (PTR_BYTE_POS (d) >= PT_BYTE) |
| 6177 | goto fail; | 6163 | goto fail; |
| 6178 | break; | 6164 | break; |
| 6179 | 6165 | ||
| 6180 | case at_dot: | 6166 | case at_dot: |
| 6181 | DEBUG_PRINT1 ("EXECUTING at_dot.\n"); | 6167 | DEBUG_PRINT ("EXECUTING at_dot.\n"); |
| 6182 | if (PTR_BYTE_POS (d) != PT_BYTE) | 6168 | if (PTR_BYTE_POS (d) != PT_BYTE) |
| 6183 | goto fail; | 6169 | goto fail; |
| 6184 | break; | 6170 | break; |
| 6185 | 6171 | ||
| 6186 | case after_dot: | 6172 | case after_dot: |
| 6187 | DEBUG_PRINT1 ("EXECUTING after_dot.\n"); | 6173 | DEBUG_PRINT ("EXECUTING after_dot.\n"); |
| 6188 | if (PTR_BYTE_POS (d) <= PT_BYTE) | 6174 | if (PTR_BYTE_POS (d) <= PT_BYTE) |
| 6189 | goto fail; | 6175 | goto fail; |
| 6190 | break; | 6176 | break; |
| @@ -6194,8 +6180,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 6194 | { | 6180 | { |
| 6195 | boolean not = (re_opcode_t) *(p - 1) == notcategoryspec; | 6181 | boolean not = (re_opcode_t) *(p - 1) == notcategoryspec; |
| 6196 | mcnt = *p++; | 6182 | mcnt = *p++; |
| 6197 | DEBUG_PRINT3 ("EXECUTING %scategoryspec %d.\n", | 6183 | DEBUG_PRINT ("EXECUTING %scategoryspec %d.\n", |
| 6198 | not?"not":"", mcnt); | 6184 | not ? "not" : "", mcnt); |
| 6199 | PREFETCH (); | 6185 | PREFETCH (); |
| 6200 | 6186 | ||
| 6201 | { | 6187 | { |
| @@ -6224,7 +6210,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 6224 | { | 6210 | { |
| 6225 | re_char *str, *pat; | 6211 | re_char *str, *pat; |
| 6226 | /* A restart point is known. Restore to that state. */ | 6212 | /* A restart point is known. Restore to that state. */ |
| 6227 | DEBUG_PRINT1 ("\nFAIL:\n"); | 6213 | DEBUG_PRINT ("\nFAIL:\n"); |
| 6228 | POP_FAILURE_POINT (str, pat); | 6214 | POP_FAILURE_POINT (str, pat); |
| 6229 | switch (*pat++) | 6215 | switch (*pat++) |
| 6230 | { | 6216 | { |
| @@ -6269,7 +6255,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, | |||
| 6269 | FREE_VARIABLES (); | 6255 | FREE_VARIABLES (); |
| 6270 | 6256 | ||
| 6271 | return -1; /* Failure to match. */ | 6257 | return -1; /* Failure to match. */ |
| 6272 | } /* re_match_2 */ | 6258 | } |
| 6273 | 6259 | ||
| 6274 | /* Subroutine definitions for re_match_2. */ | 6260 | /* Subroutine definitions for re_match_2. */ |
| 6275 | 6261 | ||
| @@ -6402,8 +6388,8 @@ weak_function | |||
| 6402 | re_exec (const char *s) | 6388 | re_exec (const char *s) |
| 6403 | { | 6389 | { |
| 6404 | const size_t len = strlen (s); | 6390 | const size_t len = strlen (s); |
| 6405 | return | 6391 | return (re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0) |
| 6406 | 0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0); | 6392 | >= 0); |
| 6407 | } | 6393 | } |
| 6408 | #endif /* _REGEX_RE_COMP */ | 6394 | #endif /* _REGEX_RE_COMP */ |
| 6409 | 6395 | ||