42 |
pattern matching using an NFA algorithm, trying to mimic Perl as closely as |
pattern matching using an NFA algorithm, trying to mimic Perl as closely as |
43 |
possible. There are also some static supporting functions. */ |
possible. There are also some static supporting functions. */ |
44 |
|
|
45 |
|
#define NLBLOCK md /* The block containing newline information */ |
46 |
#include "pcre_internal.h" |
#include "pcre_internal.h" |
47 |
|
|
48 |
|
|
275 |
long int Xims; |
long int Xims; |
276 |
eptrblock *Xeptrb; |
eptrblock *Xeptrb; |
277 |
int Xflags; |
int Xflags; |
278 |
int Xrdepth; |
unsigned int Xrdepth; |
279 |
|
|
280 |
/* Function local variables */ |
/* Function local variables */ |
281 |
|
|
374 |
static int |
static int |
375 |
match(REGISTER USPTR eptr, REGISTER const uschar *ecode, |
match(REGISTER USPTR eptr, REGISTER const uschar *ecode, |
376 |
int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb, |
int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb, |
377 |
int flags, int rdepth) |
int flags, unsigned int rdepth) |
378 |
{ |
{ |
379 |
/* These variables do not need to be preserved over recursion in this function, |
/* These variables do not need to be preserved over recursion in this function, |
380 |
so they can be ordinary variables in all cases. Mark them with "register" |
so they can be ordinary variables in all cases. Mark them with "register" |
381 |
because they are used a lot in loops. */ |
because they are used a lot in loops. */ |
382 |
|
|
383 |
register int rrc; /* Returns from recursive calls */ |
register int rrc; /* Returns from recursive calls */ |
384 |
register int i; /* Used for loops not involving calls to RMATCH() */ |
register int i; /* Used for loops not involving calls to RMATCH() */ |
385 |
register int c; /* Character values not kept over RMATCH() calls */ |
register unsigned int c; /* Character values not kept over RMATCH() calls */ |
386 |
register BOOL utf8; /* Local copy of UTF-8 flag for speed */ |
register BOOL utf8; /* Local copy of UTF-8 flag for speed */ |
387 |
|
|
388 |
/* When recursion is not being used, all "local" variables that have to be |
/* When recursion is not being used, all "local" variables that have to be |
389 |
preserved over calls to RMATCH() are part of a "frame" which is obtained from |
preserved over calls to RMATCH() are part of a "frame" which is obtained from |
527 |
prop_test_variable = NULL; |
prop_test_variable = NULL; |
528 |
#endif |
#endif |
529 |
|
|
530 |
|
/* This label is used for tail recursion, which is used in a few cases even |
531 |
|
when NO_RECURSE is not defined, in order to reduce the amount of stack that is |
532 |
|
used. Thanks to Ian Taylor for noticing this possibility and sending the |
533 |
|
original patch. */ |
534 |
|
|
535 |
|
TAIL_RECURSE: |
536 |
|
|
537 |
/* OK, now we can get on with the real code of the function. Recursive calls |
/* OK, now we can get on with the real code of the function. Recursive calls |
538 |
are specified by the macro RMATCH and RRETURN is used to return. When |
are specified by the macro RMATCH and RRETURN is used to return. When |
539 |
NO_RECURSE is *not* defined, these just turn into a recursive call to match() |
NO_RECURSE is *not* defined, these just turn into a recursive call to match() |
549 |
if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT); |
if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT); |
550 |
|
|
551 |
original_ims = ims; /* Save for resetting on ')' */ |
original_ims = ims; /* Save for resetting on ')' */ |
552 |
|
|
553 |
|
#ifdef SUPPORT_UTF8 |
554 |
utf8 = md->utf8; /* Local copy of the flag */ |
utf8 = md->utf8; /* Local copy of the flag */ |
555 |
|
#else |
556 |
|
utf8 = FALSE; |
557 |
|
#endif |
558 |
|
|
559 |
/* At the start of a bracketed group, add the current subject pointer to the |
/* At the start of a bracketed group, add the current subject pointer to the |
560 |
stack of such pointers, to be re-instated at the end of the group when we hit |
stack of such pointers, to be re-instated at the end of the group when we hit |
654 |
{ |
{ |
655 |
case OP_BRA: /* Non-capturing bracket: optimized */ |
case OP_BRA: /* Non-capturing bracket: optimized */ |
656 |
DPRINTF(("start bracket 0\n")); |
DPRINTF(("start bracket 0\n")); |
657 |
do |
|
658 |
|
/* Loop for all the alternatives */ |
659 |
|
|
660 |
|
for (;;) |
661 |
{ |
{ |
662 |
|
/* When we get to the final alternative within the brackets, we would |
663 |
|
return the result of a recursive call to match() whatever happened. We |
664 |
|
can reduce stack usage by turning this into a tail recursion. */ |
665 |
|
|
666 |
|
if (ecode[GET(ecode, 1)] != OP_ALT) |
667 |
|
{ |
668 |
|
ecode += 1 + LINK_SIZE; |
669 |
|
flags = match_isgroup; |
670 |
|
DPRINTF(("bracket 0 tail recursion\n")); |
671 |
|
goto TAIL_RECURSE; |
672 |
|
} |
673 |
|
|
674 |
|
/* For non-final alternatives, continue the loop for a NOMATCH result; |
675 |
|
otherwise return. */ |
676 |
|
|
677 |
RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, |
RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, |
678 |
match_isgroup); |
match_isgroup); |
679 |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
680 |
ecode += GET(ecode, 1); |
ecode += GET(ecode, 1); |
681 |
} |
} |
682 |
while (*ecode == OP_ALT); |
/* Control never reaches here. */ |
|
DPRINTF(("bracket 0 failed\n")); |
|
|
RRETURN(MATCH_NOMATCH); |
|
683 |
|
|
684 |
/* Conditional group: compilation checked that there are no more than |
/* Conditional group: compilation checked that there are no more than |
685 |
two branches. If the condition is false, skipping the first branch takes us |
two branches. If the condition is false, skipping the first branch takes us |
686 |
past the end if there is only one branch, but that's OK because that is |
past the end if there is only one branch, but that's OK because that is |
687 |
exactly what going to the ket would do. */ |
exactly what going to the ket would do. As there is only one branch to be |
688 |
|
obeyed, we can use tail recursion to avoid using another stack frame. */ |
689 |
|
|
690 |
case OP_COND: |
case OP_COND: |
691 |
if (ecode[LINK_SIZE+1] == OP_CREF) /* Condition extract or recurse test */ |
if (ecode[LINK_SIZE+1] == OP_CREF) /* Condition extract or recurse test */ |
694 |
condition = (offset == CREF_RECURSE * 2)? |
condition = (offset == CREF_RECURSE * 2)? |
695 |
(md->recursive != NULL) : |
(md->recursive != NULL) : |
696 |
(offset < offset_top && md->offset_vector[offset] >= 0); |
(offset < offset_top && md->offset_vector[offset] >= 0); |
697 |
RMATCH(rrc, eptr, ecode + (condition? |
ecode += condition? (LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1)); |
698 |
(LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1))), |
flags = match_isgroup; |
699 |
offset_top, md, ims, eptrb, match_isgroup); |
goto TAIL_RECURSE; |
|
RRETURN(rrc); |
|
700 |
} |
} |
701 |
|
|
702 |
/* The condition is an assertion. Call match() to evaluate it - setting |
/* The condition is an assertion. Call match() to evaluate it - setting |
716 |
RRETURN(rrc); /* Need braces because of following else */ |
RRETURN(rrc); /* Need braces because of following else */ |
717 |
} |
} |
718 |
else ecode += GET(ecode, 1); |
else ecode += GET(ecode, 1); |
719 |
RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, |
|
720 |
match_isgroup); |
/* We are now at the branch that is to be obeyed. As there is only one, |
721 |
RRETURN(rrc); |
we can use tail recursion to avoid using another stack frame. */ |
722 |
|
|
723 |
|
ecode += 1 + LINK_SIZE; |
724 |
|
flags = match_isgroup; |
725 |
|
goto TAIL_RECURSE; |
726 |
} |
} |
727 |
/* Control never reaches here */ |
/* Control never reaches here */ |
728 |
|
|
977 |
the end of a normal bracket, leaving the subject pointer. */ |
the end of a normal bracket, leaving the subject pointer. */ |
978 |
|
|
979 |
case OP_ONCE: |
case OP_ONCE: |
980 |
{ |
prev = ecode; |
981 |
prev = ecode; |
saved_eptr = eptr; |
|
saved_eptr = eptr; |
|
982 |
|
|
983 |
do |
do |
984 |
{ |
{ |
985 |
RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, |
RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, |
986 |
eptrb, match_isgroup); |
eptrb, match_isgroup); |
987 |
if (rrc == MATCH_MATCH) break; |
if (rrc == MATCH_MATCH) break; |
988 |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
989 |
ecode += GET(ecode,1); |
ecode += GET(ecode,1); |
990 |
} |
} |
991 |
while (*ecode == OP_ALT); |
while (*ecode == OP_ALT); |
992 |
|
|
993 |
/* If hit the end of the group (which could be repeated), fail */ |
/* If hit the end of the group (which could be repeated), fail */ |
994 |
|
|
995 |
if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH); |
if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH); |
996 |
|
|
997 |
/* Continue as from after the assertion, updating the offsets high water |
/* Continue as from after the assertion, updating the offsets high water |
998 |
mark, since extracts may have been taken. */ |
mark, since extracts may have been taken. */ |
999 |
|
|
1000 |
do ecode += GET(ecode,1); while (*ecode == OP_ALT); |
do ecode += GET(ecode,1); while (*ecode == OP_ALT); |
1001 |
|
|
1002 |
offset_top = md->end_offset_top; |
offset_top = md->end_offset_top; |
1003 |
eptr = md->end_match_ptr; |
eptr = md->end_match_ptr; |
1004 |
|
|
1005 |
/* For a non-repeating ket, just continue at this level. This also |
/* For a non-repeating ket, just continue at this level. This also |
1006 |
happens for a repeating ket if no characters were matched in the group. |
happens for a repeating ket if no characters were matched in the group. |
1007 |
This is the forcible breaking of infinite loops as implemented in Perl |
This is the forcible breaking of infinite loops as implemented in Perl |
1008 |
5.005. If there is an options reset, it will get obeyed in the normal |
5.005. If there is an options reset, it will get obeyed in the normal |
1009 |
course of events. */ |
course of events. */ |
1010 |
|
|
1011 |
if (*ecode == OP_KET || eptr == saved_eptr) |
if (*ecode == OP_KET || eptr == saved_eptr) |
1012 |
{ |
{ |
1013 |
ecode += 1+LINK_SIZE; |
ecode += 1+LINK_SIZE; |
1014 |
break; |
break; |
1015 |
} |
} |
1016 |
|
|
1017 |
/* The repeating kets try the rest of the pattern or restart from the |
/* The repeating kets try the rest of the pattern or restart from the |
1018 |
preceding bracket, in the appropriate order. We need to reset any options |
preceding bracket, in the appropriate order. The second "call" of match() |
1019 |
that changed within the bracket before re-running it, so check the next |
uses tail recursion, to avoid using another stack frame. We need to reset |
1020 |
opcode. */ |
any options that changed within the bracket before re-running it, so |
1021 |
|
check the next opcode. */ |
1022 |
|
|
1023 |
if (ecode[1+LINK_SIZE] == OP_OPT) |
if (ecode[1+LINK_SIZE] == OP_OPT) |
1024 |
{ |
{ |
1025 |
ims = (ims & ~PCRE_IMS) | ecode[4]; |
ims = (ims & ~PCRE_IMS) | ecode[4]; |
1026 |
DPRINTF(("ims set to %02lx at group repeat\n", ims)); |
DPRINTF(("ims set to %02lx at group repeat\n", ims)); |
1027 |
} |
} |
1028 |
|
|
1029 |
if (*ecode == OP_KETRMIN) |
if (*ecode == OP_KETRMIN) |
1030 |
{ |
{ |
1031 |
RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0); |
RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0); |
1032 |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
1033 |
RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); |
ecode = prev; |
1034 |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
flags = match_isgroup; |
1035 |
} |
goto TAIL_RECURSE; |
1036 |
else /* OP_KETRMAX */ |
} |
1037 |
{ |
else /* OP_KETRMAX */ |
1038 |
RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); |
{ |
1039 |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); |
1040 |
RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0); |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
1041 |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
ecode += 1 + LINK_SIZE; |
1042 |
} |
flags = 0; |
1043 |
|
goto TAIL_RECURSE; |
1044 |
} |
} |
1045 |
RRETURN(MATCH_NOMATCH); |
/* Control never gets here */ |
1046 |
|
|
1047 |
/* An alternation is the end of a branch; scan along to find the end of the |
/* An alternation is the end of a branch; scan along to find the end of the |
1048 |
bracketed group and go to there. */ |
bracketed group and go to there. */ |
1086 |
case OP_KET: |
case OP_KET: |
1087 |
case OP_KETRMIN: |
case OP_KETRMIN: |
1088 |
case OP_KETRMAX: |
case OP_KETRMAX: |
1089 |
{ |
prev = ecode - GET(ecode, 1); |
1090 |
prev = ecode - GET(ecode, 1); |
saved_eptr = eptrb->epb_saved_eptr; |
|
saved_eptr = eptrb->epb_saved_eptr; |
|
1091 |
|
|
1092 |
/* Back up the stack of bracket start pointers. */ |
/* Back up the stack of bracket start pointers. */ |
1093 |
|
|
1094 |
eptrb = eptrb->epb_prev; |
eptrb = eptrb->epb_prev; |
1095 |
|
|
1096 |
if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || |
if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || |
1097 |
*prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT || |
*prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT || |
1098 |
*prev == OP_ONCE) |
*prev == OP_ONCE) |
1099 |
{ |
{ |
1100 |
md->end_match_ptr = eptr; /* For ONCE */ |
md->end_match_ptr = eptr; /* For ONCE */ |
1101 |
md->end_offset_top = offset_top; |
md->end_offset_top = offset_top; |
1102 |
RRETURN(MATCH_MATCH); |
RRETURN(MATCH_MATCH); |
1103 |
} |
} |
1104 |
|
|
1105 |
/* In all other cases except a conditional group we have to check the |
/* In all other cases except a conditional group we have to check the |
1106 |
group number back at the start and if necessary complete handling an |
group number back at the start and if necessary complete handling an |
1107 |
extraction by setting the offsets and bumping the high water mark. */ |
extraction by setting the offsets and bumping the high water mark. */ |
1108 |
|
|
1109 |
if (*prev != OP_COND) |
if (*prev != OP_COND) |
1110 |
{ |
{ |
1111 |
number = *prev - OP_BRA; |
number = *prev - OP_BRA; |
1112 |
|
|
1113 |
/* For extended extraction brackets (large number), we have to fish out |
/* For extended extraction brackets (large number), we have to fish out |
1114 |
the number from a dummy opcode at the start. */ |
the number from a dummy opcode at the start. */ |
1115 |
|
|
1116 |
if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE); |
if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE); |
1117 |
offset = number << 1; |
offset = number << 1; |
1118 |
|
|
1119 |
#ifdef DEBUG |
#ifdef DEBUG |
1120 |
printf("end bracket %d", number); |
printf("end bracket %d", number); |
1121 |
printf("\n"); |
printf("\n"); |
1122 |
#endif |
#endif |
1123 |
|
|
1124 |
/* Test for a numbered group. This includes groups called as a result |
/* Test for a numbered group. This includes groups called as a result |
1125 |
of recursion. Note that whole-pattern recursion is coded as a recurse |
of recursion. Note that whole-pattern recursion is coded as a recurse |
1126 |
into group 0, so it won't be picked up here. Instead, we catch it when |
into group 0, so it won't be picked up here. Instead, we catch it when |
1127 |
the OP_END is reached. */ |
the OP_END is reached. */ |
1128 |
|
|
1129 |
if (number > 0) |
if (number > 0) |
1130 |
|
{ |
1131 |
|
md->capture_last = number; |
1132 |
|
if (offset >= md->offset_max) md->offset_overflow = TRUE; else |
1133 |
{ |
{ |
1134 |
md->capture_last = number; |
md->offset_vector[offset] = |
1135 |
if (offset >= md->offset_max) md->offset_overflow = TRUE; else |
md->offset_vector[md->offset_end - number]; |
1136 |
{ |
md->offset_vector[offset+1] = eptr - md->start_subject; |
1137 |
md->offset_vector[offset] = |
if (offset_top <= offset) offset_top = offset + 2; |
1138 |
md->offset_vector[md->offset_end - number]; |
} |
|
md->offset_vector[offset+1] = eptr - md->start_subject; |
|
|
if (offset_top <= offset) offset_top = offset + 2; |
|
|
} |
|
1139 |
|
|
1140 |
/* Handle a recursively called group. Restore the offsets |
/* Handle a recursively called group. Restore the offsets |
1141 |
appropriately and continue from after the call. */ |
appropriately and continue from after the call. */ |
1142 |
|
|
1143 |
if (md->recursive != NULL && md->recursive->group_num == number) |
if (md->recursive != NULL && md->recursive->group_num == number) |
1144 |
{ |
{ |
1145 |
recursion_info *rec = md->recursive; |
recursion_info *rec = md->recursive; |
1146 |
DPRINTF(("Recursion (%d) succeeded - continuing\n", number)); |
DPRINTF(("Recursion (%d) succeeded - continuing\n", number)); |
1147 |
md->recursive = rec->prevrec; |
md->recursive = rec->prevrec; |
1148 |
md->start_match = rec->save_start; |
md->start_match = rec->save_start; |
1149 |
memcpy(md->offset_vector, rec->offset_save, |
memcpy(md->offset_vector, rec->offset_save, |
1150 |
rec->saved_max * sizeof(int)); |
rec->saved_max * sizeof(int)); |
1151 |
ecode = rec->after_call; |
ecode = rec->after_call; |
1152 |
ims = original_ims; |
ims = original_ims; |
1153 |
break; |
break; |
|
} |
|
1154 |
} |
} |
1155 |
} |
} |
1156 |
|
} |
1157 |
|
|
1158 |
/* Reset the value of the ims flags, in case they got changed during |
/* Reset the value of the ims flags, in case they got changed during |
1159 |
the group. */ |
the group. */ |
1160 |
|
|
1161 |
ims = original_ims; |
ims = original_ims; |
1162 |
DPRINTF(("ims reset to %02lx\n", ims)); |
DPRINTF(("ims reset to %02lx\n", ims)); |
1163 |
|
|
1164 |
/* For a non-repeating ket, just continue at this level. This also |
/* For a non-repeating ket, just continue at this level. This also |
1165 |
happens for a repeating ket if no characters were matched in the group. |
happens for a repeating ket if no characters were matched in the group. |
1166 |
This is the forcible breaking of infinite loops as implemented in Perl |
This is the forcible breaking of infinite loops as implemented in Perl |
1167 |
5.005. If there is an options reset, it will get obeyed in the normal |
5.005. If there is an options reset, it will get obeyed in the normal |
1168 |
course of events. */ |
course of events. */ |
1169 |
|
|
1170 |
if (*ecode == OP_KET || eptr == saved_eptr) |
if (*ecode == OP_KET || eptr == saved_eptr) |
1171 |
{ |
{ |
1172 |
ecode += 1 + LINK_SIZE; |
ecode += 1 + LINK_SIZE; |
1173 |
break; |
break; |
1174 |
} |
} |
1175 |
|
|
1176 |
/* The repeating kets try the rest of the pattern or restart from the |
/* The repeating kets try the rest of the pattern or restart from the |
1177 |
preceding bracket, in the appropriate order. */ |
preceding bracket, in the appropriate order. In the second case, we can use |
1178 |
|
tail recursion to avoid using another stack frame. */ |
1179 |
|
|
1180 |
if (*ecode == OP_KETRMIN) |
if (*ecode == OP_KETRMIN) |
1181 |
{ |
{ |
1182 |
RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0); |
RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0); |
1183 |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
1184 |
RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); |
ecode = prev; |
1185 |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
flags = match_isgroup; |
1186 |
} |
goto TAIL_RECURSE; |
|
else /* OP_KETRMAX */ |
|
|
{ |
|
|
RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); |
|
|
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
|
|
RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0); |
|
|
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
|
|
} |
|
1187 |
} |
} |
1188 |
|
else /* OP_KETRMAX */ |
1189 |
RRETURN(MATCH_NOMATCH); |
{ |
1190 |
|
RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); |
1191 |
|
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
1192 |
|
ecode += 1 + LINK_SIZE; |
1193 |
|
flags = 0; |
1194 |
|
goto TAIL_RECURSE; |
1195 |
|
} |
1196 |
|
/* Control never gets here */ |
1197 |
|
|
1198 |
/* Start of subject unless notbol, or after internal newline if multiline */ |
/* Start of subject unless notbol, or after internal newline if multiline */ |
1199 |
|
|
1201 |
if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH); |
if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH); |
1202 |
if ((ims & PCRE_MULTILINE) != 0) |
if ((ims & PCRE_MULTILINE) != 0) |
1203 |
{ |
{ |
1204 |
if (eptr != md->start_subject && eptr[-1] != NEWLINE) |
if (eptr != md->start_subject && |
1205 |
|
(eptr == md->end_subject || |
1206 |
|
eptr < md->start_subject + md->nllen || |
1207 |
|
!IS_NEWLINE(eptr - md->nllen))) |
1208 |
RRETURN(MATCH_NOMATCH); |
RRETURN(MATCH_NOMATCH); |
1209 |
ecode++; |
ecode++; |
1210 |
break; |
break; |
1232 |
if ((ims & PCRE_MULTILINE) != 0) |
if ((ims & PCRE_MULTILINE) != 0) |
1233 |
{ |
{ |
1234 |
if (eptr < md->end_subject) |
if (eptr < md->end_subject) |
1235 |
{ if (*eptr != NEWLINE) RRETURN(MATCH_NOMATCH); } |
{ if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); } |
1236 |
else |
else |
1237 |
{ if (md->noteol) RRETURN(MATCH_NOMATCH); } |
{ if (md->noteol) RRETURN(MATCH_NOMATCH); } |
1238 |
ecode++; |
ecode++; |
1243 |
if (md->noteol) RRETURN(MATCH_NOMATCH); |
if (md->noteol) RRETURN(MATCH_NOMATCH); |
1244 |
if (!md->endonly) |
if (!md->endonly) |
1245 |
{ |
{ |
1246 |
if (eptr < md->end_subject - 1 || |
if (eptr != md->end_subject && |
1247 |
(eptr == md->end_subject - 1 && *eptr != NEWLINE)) |
(eptr != md->end_subject - md->nllen || !IS_NEWLINE(eptr))) |
1248 |
RRETURN(MATCH_NOMATCH); |
RRETURN(MATCH_NOMATCH); |
1249 |
ecode++; |
ecode++; |
1250 |
break; |
break; |
1251 |
} |
} |
1252 |
} |
} |
1253 |
/* ... else fall through */ |
/* ... else fall through for endonly */ |
1254 |
|
|
1255 |
/* End of subject assertion (\z) */ |
/* End of subject assertion (\z) */ |
1256 |
|
|
1262 |
/* End of subject or ending \n assertion (\Z) */ |
/* End of subject or ending \n assertion (\Z) */ |
1263 |
|
|
1264 |
case OP_EODN: |
case OP_EODN: |
1265 |
if (eptr < md->end_subject - 1 || |
if (eptr != md->end_subject && |
1266 |
(eptr == md->end_subject - 1 && *eptr != NEWLINE)) RRETURN(MATCH_NOMATCH); |
(eptr != md->end_subject - md->nllen || !IS_NEWLINE(eptr))) |
1267 |
|
RRETURN(MATCH_NOMATCH); |
1268 |
ecode++; |
ecode++; |
1269 |
break; |
break; |
1270 |
|
|
1317 |
/* Match a single character type; inline for speed */ |
/* Match a single character type; inline for speed */ |
1318 |
|
|
1319 |
case OP_ANY: |
case OP_ANY: |
1320 |
if ((ims & PCRE_DOTALL) == 0 && eptr < md->end_subject && *eptr == NEWLINE) |
if ((ims & PCRE_DOTALL) == 0) |
1321 |
RRETURN(MATCH_NOMATCH); |
{ |
1322 |
|
if (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr)) |
1323 |
|
RRETURN(MATCH_NOMATCH); |
1324 |
|
} |
1325 |
if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH); |
if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH); |
|
#ifdef SUPPORT_UTF8 |
|
1326 |
if (utf8) |
if (utf8) |
1327 |
while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
|
#endif |
|
1328 |
ecode++; |
ecode++; |
1329 |
break; |
break; |
1330 |
|
|
2611 |
for (i = 1; i <= min; i++) |
for (i = 1; i <= min; i++) |
2612 |
{ |
{ |
2613 |
if (eptr >= md->end_subject || |
if (eptr >= md->end_subject || |
2614 |
(*eptr++ == NEWLINE && (ims & PCRE_DOTALL) == 0)) |
((ims & PCRE_DOTALL) == 0 && |
2615 |
|
eptr <= md->end_subject - md->nllen && |
2616 |
|
IS_NEWLINE(eptr))) |
2617 |
RRETURN(MATCH_NOMATCH); |
RRETURN(MATCH_NOMATCH); |
2618 |
|
eptr++; |
2619 |
while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
2620 |
} |
} |
2621 |
break; |
break; |
2700 |
if ((ims & PCRE_DOTALL) == 0) |
if ((ims & PCRE_DOTALL) == 0) |
2701 |
{ |
{ |
2702 |
for (i = 1; i <= min; i++) |
for (i = 1; i <= min; i++) |
2703 |
if (*eptr++ == NEWLINE) RRETURN(MATCH_NOMATCH); |
{ |
2704 |
|
if (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr)) |
2705 |
|
RRETURN(MATCH_NOMATCH); |
2706 |
|
eptr++; |
2707 |
|
} |
2708 |
} |
} |
2709 |
else eptr += min; |
else eptr += min; |
2710 |
break; |
break; |
2874 |
{ |
{ |
2875 |
RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); |
RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); |
2876 |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
2877 |
if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
if (fi >= max || eptr >= md->end_subject || |
2878 |
|
(ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 && |
2879 |
|
eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))) |
2880 |
|
RRETURN(MATCH_NOMATCH); |
2881 |
|
|
2882 |
GETCHARINC(c, eptr); |
GETCHARINC(c, eptr); |
2883 |
switch(ctype) |
switch(ctype) |
2884 |
{ |
{ |
2885 |
case OP_ANY: |
case OP_ANY: /* This is the DOTALL case */ |
|
if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH); |
|
2886 |
break; |
break; |
2887 |
|
|
2888 |
case OP_ANYBYTE: |
case OP_ANYBYTE: |
2931 |
{ |
{ |
2932 |
RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); |
RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); |
2933 |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
2934 |
if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
if (fi >= max || eptr >= md->end_subject || |
2935 |
|
((ims & PCRE_DOTALL) == 0 && |
2936 |
|
eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))) |
2937 |
|
RRETURN(MATCH_NOMATCH); |
2938 |
|
|
2939 |
c = *eptr++; |
c = *eptr++; |
2940 |
switch(ctype) |
switch(ctype) |
2941 |
{ |
{ |
2942 |
case OP_ANY: |
case OP_ANY: /* This is the DOTALL case */ |
|
if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH); |
|
2943 |
break; |
break; |
2944 |
|
|
2945 |
case OP_ANYBYTE: |
case OP_ANYBYTE: |
3125 |
{ |
{ |
3126 |
case OP_ANY: |
case OP_ANY: |
3127 |
|
|
3128 |
/* Special code is required for UTF8, but when the maximum is unlimited |
/* Special code is required for UTF8, but when the maximum is |
3129 |
we don't need it, so we repeat the non-UTF8 code. This is probably |
unlimited we don't need it, so we repeat the non-UTF8 code. This is |
3130 |
worth it, because .* is quite a common idiom. */ |
probably worth it, because .* is quite a common idiom. */ |
3131 |
|
|
3132 |
if (max < INT_MAX) |
if (max < INT_MAX) |
3133 |
{ |
{ |
3135 |
{ |
{ |
3136 |
for (i = min; i < max; i++) |
for (i = min; i < max; i++) |
3137 |
{ |
{ |
3138 |
if (eptr >= md->end_subject || *eptr == NEWLINE) break; |
if (eptr >= md->end_subject || |
3139 |
|
(eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))) |
3140 |
|
break; |
3141 |
eptr++; |
eptr++; |
3142 |
while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
3143 |
} |
} |
3146 |
{ |
{ |
3147 |
for (i = min; i < max; i++) |
for (i = min; i < max; i++) |
3148 |
{ |
{ |
3149 |
|
if (eptr >= md->end_subject) break; |
3150 |
eptr++; |
eptr++; |
3151 |
while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
3152 |
} |
} |
3161 |
{ |
{ |
3162 |
for (i = min; i < max; i++) |
for (i = min; i < max; i++) |
3163 |
{ |
{ |
3164 |
if (eptr >= md->end_subject || *eptr == NEWLINE) break; |
if (eptr >= md->end_subject || |
3165 |
|
(eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))) |
3166 |
|
break; |
3167 |
eptr++; |
eptr++; |
3168 |
} |
} |
3169 |
break; |
break; |
3277 |
{ |
{ |
3278 |
for (i = min; i < max; i++) |
for (i = min; i < max; i++) |
3279 |
{ |
{ |
3280 |
if (eptr >= md->end_subject || *eptr == NEWLINE) break; |
if (eptr >= md->end_subject || |
3281 |
|
(eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))) |
3282 |
|
break; |
3283 |
eptr++; |
eptr++; |
3284 |
} |
} |
3285 |
break; |
break; |
3476 |
int first_byte = -1; |
int first_byte = -1; |
3477 |
int req_byte = -1; |
int req_byte = -1; |
3478 |
int req_byte2 = -1; |
int req_byte2 = -1; |
3479 |
unsigned long int ims = 0; |
int newline; |
3480 |
|
unsigned long int ims; |
3481 |
BOOL using_temporary_offsets = FALSE; |
BOOL using_temporary_offsets = FALSE; |
3482 |
BOOL anchored; |
BOOL anchored; |
3483 |
BOOL startline; |
BOOL startline; |
3485 |
BOOL first_byte_caseless = FALSE; |
BOOL first_byte_caseless = FALSE; |
3486 |
BOOL req_byte_caseless = FALSE; |
BOOL req_byte_caseless = FALSE; |
3487 |
match_data match_block; |
match_data match_block; |
3488 |
|
match_data *md = &match_block; |
3489 |
const uschar *tables; |
const uschar *tables; |
3490 |
const uschar *start_bits = NULL; |
const uschar *start_bits = NULL; |
3491 |
USPTR start_match = (USPTR)subject + start_offset; |
USPTR start_match = (USPTR)subject + start_offset; |
3510 |
the default values. */ |
the default values. */ |
3511 |
|
|
3512 |
study = NULL; |
study = NULL; |
3513 |
match_block.match_limit = MATCH_LIMIT; |
md->match_limit = MATCH_LIMIT; |
3514 |
match_block.match_limit_recursion = MATCH_LIMIT_RECURSION; |
md->match_limit_recursion = MATCH_LIMIT_RECURSION; |
3515 |
match_block.callout_data = NULL; |
md->callout_data = NULL; |
3516 |
|
|
3517 |
/* The table pointer is always in native byte order. */ |
/* The table pointer is always in native byte order. */ |
3518 |
|
|
3524 |
if ((flags & PCRE_EXTRA_STUDY_DATA) != 0) |
if ((flags & PCRE_EXTRA_STUDY_DATA) != 0) |
3525 |
study = (const pcre_study_data *)extra_data->study_data; |
study = (const pcre_study_data *)extra_data->study_data; |
3526 |
if ((flags & PCRE_EXTRA_MATCH_LIMIT) != 0) |
if ((flags & PCRE_EXTRA_MATCH_LIMIT) != 0) |
3527 |
match_block.match_limit = extra_data->match_limit; |
md->match_limit = extra_data->match_limit; |
3528 |
if ((flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) != 0) |
if ((flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) != 0) |
3529 |
match_block.match_limit_recursion = extra_data->match_limit_recursion; |
md->match_limit_recursion = extra_data->match_limit_recursion; |
3530 |
if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0) |
if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0) |
3531 |
match_block.callout_data = extra_data->callout_data; |
md->callout_data = extra_data->callout_data; |
3532 |
if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables; |
if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables; |
3533 |
} |
} |
3534 |
|
|
3558 |
|
|
3559 |
/* The code starts after the real_pcre block and the capture name table. */ |
/* The code starts after the real_pcre block and the capture name table. */ |
3560 |
|
|
3561 |
match_block.start_code = (const uschar *)external_re + re->name_table_offset + |
md->start_code = (const uschar *)external_re + re->name_table_offset + |
3562 |
re->name_count * re->name_entry_size; |
re->name_count * re->name_entry_size; |
3563 |
|
|
3564 |
match_block.start_subject = (USPTR)subject; |
md->start_subject = (USPTR)subject; |
3565 |
match_block.start_offset = start_offset; |
md->start_offset = start_offset; |
3566 |
match_block.end_subject = match_block.start_subject + length; |
md->end_subject = md->start_subject + length; |
3567 |
end_subject = match_block.end_subject; |
end_subject = md->end_subject; |
3568 |
|
|
3569 |
match_block.endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0; |
md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0; |
3570 |
match_block.utf8 = (re->options & PCRE_UTF8) != 0; |
md->utf8 = (re->options & PCRE_UTF8) != 0; |
3571 |
|
|
3572 |
match_block.notbol = (options & PCRE_NOTBOL) != 0; |
md->notbol = (options & PCRE_NOTBOL) != 0; |
3573 |
match_block.noteol = (options & PCRE_NOTEOL) != 0; |
md->noteol = (options & PCRE_NOTEOL) != 0; |
3574 |
match_block.notempty = (options & PCRE_NOTEMPTY) != 0; |
md->notempty = (options & PCRE_NOTEMPTY) != 0; |
3575 |
match_block.partial = (options & PCRE_PARTIAL) != 0; |
md->partial = (options & PCRE_PARTIAL) != 0; |
3576 |
match_block.hitend = FALSE; |
md->hitend = FALSE; |
3577 |
|
|
3578 |
|
md->recursive = NULL; /* No recursion at top level */ |
3579 |
|
|
3580 |
|
md->lcc = tables + lcc_offset; |
3581 |
|
md->ctypes = tables + ctypes_offset; |
3582 |
|
|
3583 |
|
/* Handle different types of newline. The two bits give four cases. If nothing |
3584 |
|
is set at run time, whatever was used at compile time applies. */ |
3585 |
|
|
3586 |
match_block.recursive = NULL; /* No recursion at top level */ |
switch ((((options & PCRE_NEWLINE_CRLF) == 0)? re->options : options) & |
3587 |
|
PCRE_NEWLINE_CRLF) |
3588 |
|
{ |
3589 |
|
default: newline = NEWLINE; break; /* Compile-time default */ |
3590 |
|
case PCRE_NEWLINE_CR: newline = '\r'; break; |
3591 |
|
case PCRE_NEWLINE_LF: newline = '\n'; break; |
3592 |
|
case PCRE_NEWLINE_CR+ |
3593 |
|
PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break; |
3594 |
|
} |
3595 |
|
|
3596 |
match_block.lcc = tables + lcc_offset; |
if (newline > 255) |
3597 |
match_block.ctypes = tables + ctypes_offset; |
{ |
3598 |
|
md->nllen = 2; |
3599 |
|
md->nl[0] = (newline >> 8) & 255; |
3600 |
|
md->nl[1] = newline & 255; |
3601 |
|
} |
3602 |
|
else |
3603 |
|
{ |
3604 |
|
md->nllen = 1; |
3605 |
|
md->nl[0] = newline; |
3606 |
|
} |
3607 |
|
|
3608 |
/* Partial matching is supported only for a restricted set of regexes at the |
/* Partial matching is supported only for a restricted set of regexes at the |
3609 |
moment. */ |
moment. */ |
3610 |
|
|
3611 |
if (match_block.partial && (re->options & PCRE_NOPARTIAL) != 0) |
if (md->partial && (re->options & PCRE_NOPARTIAL) != 0) |
3612 |
return PCRE_ERROR_BADPARTIAL; |
return PCRE_ERROR_BADPARTIAL; |
3613 |
|
|
3614 |
/* Check a UTF-8 string if required. Unfortunately there's no way of passing |
/* Check a UTF-8 string if required. Unfortunately there's no way of passing |
3615 |
back the character offset. */ |
back the character offset. */ |
3616 |
|
|
3617 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
3618 |
if (match_block.utf8 && (options & PCRE_NO_UTF8_CHECK) == 0) |
if (md->utf8 && (options & PCRE_NO_UTF8_CHECK) == 0) |
3619 |
{ |
{ |
3620 |
if (_pcre_valid_utf8((uschar *)subject, length) >= 0) |
if (_pcre_valid_utf8((uschar *)subject, length) >= 0) |
3621 |
return PCRE_ERROR_BADUTF8; |
return PCRE_ERROR_BADUTF8; |
3647 |
if (re->top_backref > 0 && re->top_backref >= ocount/3) |
if (re->top_backref > 0 && re->top_backref >= ocount/3) |
3648 |
{ |
{ |
3649 |
ocount = re->top_backref * 3 + 3; |
ocount = re->top_backref * 3 + 3; |
3650 |
match_block.offset_vector = (int *)(pcre_malloc)(ocount * sizeof(int)); |
md->offset_vector = (int *)(pcre_malloc)(ocount * sizeof(int)); |
3651 |
if (match_block.offset_vector == NULL) return PCRE_ERROR_NOMEMORY; |
if (md->offset_vector == NULL) return PCRE_ERROR_NOMEMORY; |
3652 |
using_temporary_offsets = TRUE; |
using_temporary_offsets = TRUE; |
3653 |
DPRINTF(("Got memory to hold back references\n")); |
DPRINTF(("Got memory to hold back references\n")); |
3654 |
} |
} |
3655 |
else match_block.offset_vector = offsets; |
else md->offset_vector = offsets; |
3656 |
|
|
3657 |
match_block.offset_end = ocount; |
md->offset_end = ocount; |
3658 |
match_block.offset_max = (2*ocount)/3; |
md->offset_max = (2*ocount)/3; |
3659 |
match_block.offset_overflow = FALSE; |
md->offset_overflow = FALSE; |
3660 |
match_block.capture_last = -1; |
md->capture_last = -1; |
3661 |
|
|
3662 |
/* Compute the minimum number of offsets that we need to reset each time. Doing |
/* Compute the minimum number of offsets that we need to reset each time. Doing |
3663 |
this makes a huge difference to execution time when there aren't many brackets |
this makes a huge difference to execution time when there aren't many brackets |
3670 |
never be used unless previously set, but they get saved and restored, and so we |
never be used unless previously set, but they get saved and restored, and so we |
3671 |
initialize them to avoid reading uninitialized locations. */ |
initialize them to avoid reading uninitialized locations. */ |
3672 |
|
|
3673 |
if (match_block.offset_vector != NULL) |
if (md->offset_vector != NULL) |
3674 |
{ |
{ |
3675 |
register int *iptr = match_block.offset_vector + ocount; |
register int *iptr = md->offset_vector + ocount; |
3676 |
register int *iend = iptr - resetcount/2 + 1; |
register int *iend = iptr - resetcount/2 + 1; |
3677 |
while (--iptr >= iend) *iptr = -1; |
while (--iptr >= iend) *iptr = -1; |
3678 |
} |
} |
3689 |
{ |
{ |
3690 |
first_byte = re->first_byte & 255; |
first_byte = re->first_byte & 255; |
3691 |
if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE) |
if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE) |
3692 |
first_byte = match_block.lcc[first_byte]; |
first_byte = md->lcc[first_byte]; |
3693 |
} |
} |
3694 |
else |
else |
3695 |
if (!startline && study != NULL && |
if (!startline && study != NULL && |
3716 |
|
|
3717 |
/* Reset the maximum number of extractions we might see. */ |
/* Reset the maximum number of extractions we might see. */ |
3718 |
|
|
3719 |
if (match_block.offset_vector != NULL) |
if (md->offset_vector != NULL) |
3720 |
{ |
{ |
3721 |
register int *iptr = match_block.offset_vector; |
register int *iptr = md->offset_vector; |
3722 |
register int *iend = iptr + resetcount; |
register int *iend = iptr + resetcount; |
3723 |
while (iptr < iend) *iptr++ = -1; |
while (iptr < iend) *iptr++ = -1; |
3724 |
} |
} |
3732 |
if (firstline) |
if (firstline) |
3733 |
{ |
{ |
3734 |
USPTR t = start_match; |
USPTR t = start_match; |
3735 |
while (t < save_end_subject && *t != '\n') t++; |
while (t <= save_end_subject - md->nllen && !IS_NEWLINE(t)) t++; |
3736 |
end_subject = t; |
end_subject = t; |
3737 |
} |
} |
3738 |
|
|
3742 |
{ |
{ |
3743 |
if (first_byte_caseless) |
if (first_byte_caseless) |
3744 |
while (start_match < end_subject && |
while (start_match < end_subject && |
3745 |
match_block.lcc[*start_match] != first_byte) |
md->lcc[*start_match] != first_byte) |
3746 |
start_match++; |
start_match++; |
3747 |
else |
else |
3748 |
while (start_match < end_subject && *start_match != first_byte) |
while (start_match < end_subject && *start_match != first_byte) |
3749 |
start_match++; |
start_match++; |
3750 |
} |
} |
3751 |
|
|
3752 |
/* Or to just after \n for a multiline match if possible */ |
/* Or to just after a linebreak for a multiline match if possible */ |
3753 |
|
|
3754 |
else if (startline) |
else if (startline) |
3755 |
{ |
{ |
3756 |
if (start_match > match_block.start_subject + start_offset) |
if (start_match >= md->start_subject + md->nllen + |
3757 |
|
start_offset) |
3758 |
{ |
{ |
3759 |
while (start_match < end_subject && start_match[-1] != NEWLINE) |
while (start_match <= end_subject && |
3760 |
|
!IS_NEWLINE(start_match - md->nllen)) |
3761 |
start_match++; |
start_match++; |
3762 |
} |
} |
3763 |
} |
} |
3779 |
|
|
3780 |
#ifdef DEBUG /* Sigh. Some compilers never learn. */ |
#ifdef DEBUG /* Sigh. Some compilers never learn. */ |
3781 |
printf(">>>> Match against: "); |
printf(">>>> Match against: "); |
3782 |
pchars(start_match, end_subject - start_match, TRUE, &match_block); |
pchars(start_match, end_subject - start_match, TRUE, md); |
3783 |
printf("\n"); |
printf("\n"); |
3784 |
#endif |
#endif |
3785 |
|
|
3801 |
|
|
3802 |
if (req_byte >= 0 && |
if (req_byte >= 0 && |
3803 |
end_subject - start_match < REQ_BYTE_MAX && |
end_subject - start_match < REQ_BYTE_MAX && |
3804 |
!match_block.partial) |
!md->partial) |
3805 |
{ |
{ |
3806 |
register USPTR p = start_match + ((first_byte >= 0)? 1 : 0); |
register USPTR p = start_match + ((first_byte >= 0)? 1 : 0); |
3807 |
|
|
3845 |
those back references that we can. In this case there need not be overflow |
those back references that we can. In this case there need not be overflow |
3846 |
if certain parts of the pattern were not used. */ |
if certain parts of the pattern were not used. */ |
3847 |
|
|
3848 |
match_block.start_match = start_match; |
md->start_match = start_match; |
3849 |
match_block.match_call_count = 0; |
md->match_call_count = 0; |
3850 |
|
|
3851 |
rc = match(start_match, match_block.start_code, 2, &match_block, ims, NULL, |
rc = match(start_match, md->start_code, 2, md, ims, NULL, match_isgroup, 0); |
|
match_isgroup, 0); |
|
3852 |
|
|
3853 |
/* When the result is no match, if the subject's first character was a |
/* When the result is no match, if the subject's first character was a |
3854 |
newline and the PCRE_FIRSTLINE option is set, break (which will return |
newline and the PCRE_FIRSTLINE option is set, break (which will return |
3859 |
|
|
3860 |
if (rc == MATCH_NOMATCH) |
if (rc == MATCH_NOMATCH) |
3861 |
{ |
{ |
3862 |
if (firstline && *start_match == NEWLINE) break; |
if (firstline && |
3863 |
|
start_match <= md->end_subject - md->nllen && |
3864 |
|
IS_NEWLINE(start_match)) |
3865 |
|
break; |
3866 |
start_match++; |
start_match++; |
3867 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
3868 |
if (match_block.utf8) |
if (md->utf8) |
3869 |
while(start_match < end_subject && (*start_match & 0xc0) == 0x80) |
while(start_match < end_subject && (*start_match & 0xc0) == 0x80) |
3870 |
start_match++; |
start_match++; |
3871 |
#endif |
#endif |
3885 |
{ |
{ |
3886 |
if (offsetcount >= 4) |
if (offsetcount >= 4) |
3887 |
{ |
{ |
3888 |
memcpy(offsets + 2, match_block.offset_vector + 2, |
memcpy(offsets + 2, md->offset_vector + 2, |
3889 |
(offsetcount - 2) * sizeof(int)); |
(offsetcount - 2) * sizeof(int)); |
3890 |
DPRINTF(("Copied offsets from temporary memory\n")); |
DPRINTF(("Copied offsets from temporary memory\n")); |
3891 |
} |
} |
3892 |
if (match_block.end_offset_top > offsetcount) |
if (md->end_offset_top > offsetcount) |
3893 |
match_block.offset_overflow = TRUE; |
md->offset_overflow = TRUE; |
3894 |
|
|
3895 |
DPRINTF(("Freeing temporary memory\n")); |
DPRINTF(("Freeing temporary memory\n")); |
3896 |
(pcre_free)(match_block.offset_vector); |
(pcre_free)(md->offset_vector); |
3897 |
} |
} |
3898 |
|
|
3899 |
rc = match_block.offset_overflow? 0 : match_block.end_offset_top/2; |
rc = md->offset_overflow? 0 : md->end_offset_top/2; |
3900 |
|
|
3901 |
if (offsetcount < 2) rc = 0; else |
if (offsetcount < 2) rc = 0; else |
3902 |
{ |
{ |
3903 |
offsets[0] = start_match - match_block.start_subject; |
offsets[0] = start_match - md->start_subject; |
3904 |
offsets[1] = match_block.end_match_ptr - match_block.start_subject; |
offsets[1] = md->end_match_ptr - md->start_subject; |
3905 |
} |
} |
3906 |
|
|
3907 |
DPRINTF((">>>> returning %d\n", rc)); |
DPRINTF((">>>> returning %d\n", rc)); |
3915 |
if (using_temporary_offsets) |
if (using_temporary_offsets) |
3916 |
{ |
{ |
3917 |
DPRINTF(("Freeing temporary memory\n")); |
DPRINTF(("Freeing temporary memory\n")); |
3918 |
(pcre_free)(match_block.offset_vector); |
(pcre_free)(md->offset_vector); |
3919 |
} |
} |
3920 |
|
|
3921 |
if (match_block.partial && match_block.hitend) |
if (md->partial && md->hitend) |
3922 |
{ |
{ |
3923 |
DPRINTF((">>>> returning PCRE_ERROR_PARTIAL\n")); |
DPRINTF((">>>> returning PCRE_ERROR_PARTIAL\n")); |
3924 |
return PCRE_ERROR_PARTIAL; |
return PCRE_ERROR_PARTIAL; |