Parent Directory
|
Revision Log
|
Patch
| revision 199 by ph10, Tue Jul 31 14:39:09 2007 UTC | revision 614 by ph10, Sat Jul 9 10:48:16 2011 UTC | |
|---|---|---|
| # | Line 6 | Line 6 |
| 6 | and semantics are as close as possible to those of the Perl 5 language. | and semantics are as close as possible to those of the Perl 5 language. |
| 7 | ||
| 8 | Written by Philip Hazel | Written by Philip Hazel |
| 9 | Copyright (c) 1997-2007 University of Cambridge | Copyright (c) 1997-2011 University of Cambridge |
| 10 | ||
| 11 | ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| 12 | Redistribution and use in source and binary forms, with or without | Redistribution and use in source and binary forms, with or without |
| # | Line 42 POSSIBILITY OF SUCH DAMAGE. | Line 42 POSSIBILITY OF SUCH DAMAGE. |
| 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 | #ifdef HAVE_CONFIG_H | #ifdef HAVE_CONFIG_H |
| 46 | #include <config.h> | #include "config.h" |
| 47 | #endif | #endif |
| 48 | ||
| 49 | #define NLBLOCK md /* Block containing newline information */ | #define NLBLOCK md /* Block containing newline information */ |
| 50 | #define PSSTART start_subject /* Field containing processed string start */ | #define PSSTART start_subject /* Field containing processed string start */ |
| # | Line 57 possible. There are also some static sup | Line 57 possible. There are also some static sup |
| 57 | #undef min | #undef min |
| 58 | #undef max | #undef max |
| 59 | ||
| 60 | /* Flag bits for the match() function */ | /* Values for setting in md->match_function_type to indicate two special types |
| 61 | of call to match(). We do it this way to save on using another stack variable, | |
| 62 | as stack usage is to be discouraged. */ | |
| 63 | ||
| 64 | #define match_condassert 0x01 /* Called to check a condition assertion */ | #define MATCH_CONDASSERT 1 /* Called to check a condition assertion */ |
| 65 | #define match_cbegroup 0x02 /* Could-be-empty unlimited repeat group */ | #define MATCH_CBEGROUP 2 /* Could-be-empty unlimited repeat group */ |
| 66 | ||
| 67 | /* Non-error returns from the match() function. Error returns are externally | /* Non-error returns from the match() function. Error returns are externally |
| 68 | defined PCRE_ERROR_xxx codes, which are all negative. */ | defined PCRE_ERROR_xxx codes, which are all negative. */ |
| # | Line 68 defined PCRE_ERROR_xxx codes, which are | Line 70 defined PCRE_ERROR_xxx codes, which are |
| 70 | #define MATCH_MATCH 1 | #define MATCH_MATCH 1 |
| 71 | #define MATCH_NOMATCH 0 | #define MATCH_NOMATCH 0 |
| 72 | ||
| 73 | /* Special internal returns from the match() function. Make them sufficiently | |
| 74 | negative to avoid the external error codes. */ | |
| 75 | ||
| 76 | #define MATCH_ACCEPT (-999) | |
| 77 | #define MATCH_COMMIT (-998) | |
| 78 | #define MATCH_KETRPOS (-997) | |
| 79 | #define MATCH_PRUNE (-996) | |
| 80 | #define MATCH_SKIP (-995) | |
| 81 | #define MATCH_SKIP_ARG (-994) | |
| 82 | #define MATCH_THEN (-993) | |
| 83 | ||
| 84 | /* This is a convenience macro for code that occurs many times. */ | |
| 85 | ||
| 86 | #define MRRETURN(ra) \ | |
| 87 | { \ | |
| 88 | md->mark = markptr; \ | |
| 89 | RRETURN(ra); \ | |
| 90 | } | |
| 91 | ||
| 92 | /* Maximum number of ints of offset to save on the stack for recursive calls. | /* Maximum number of ints of offset to save on the stack for recursive calls. |
| 93 | If the offset vector is bigger, malloc is used. This should be a multiple of 3, | If the offset vector is bigger, malloc is used. This should be a multiple of 3, |
| 94 | because the offset vector is always a multiple of 3 long. */ | because the offset vector is always a multiple of 3 long. */ |
| # | Line 81 static const char rep_max[] = { 0, 0, 0, | Line 102 static const char rep_max[] = { 0, 0, 0, |
| 102 | ||
| 103 | ||
| 104 | ||
| 105 | #ifdef DEBUG | #ifdef PCRE_DEBUG |
| 106 | /************************************************* | /************************************************* |
| 107 | * Debugging function to print chars * | * Debugging function to print chars * |
| 108 | *************************************************/ | *************************************************/ |
| # | Line 114 while (length-- > 0) | Line 135 while (length-- > 0) |
| 135 | * Match a back-reference * | * Match a back-reference * |
| 136 | *************************************************/ | *************************************************/ |
| 137 | ||
| 138 | /* If a back reference hasn't been set, the length that is passed is greater | /* Normally, if a back reference hasn't been set, the length that is passed is |
| 139 | than the number of characters left in the string, so the match fails. | negative, so the match always fails. However, in JavaScript compatibility mode, |
| 140 | the length passed is zero. Note that in caseless UTF-8 mode, the number of | |
| 141 | subject bytes matched may be different to the number of reference bytes. | |
| 142 | ||
| 143 | Arguments: | Arguments: |
| 144 | offset index into the offset vector | offset index into the offset vector |
| 145 | eptr points into the subject | eptr pointer into the subject |
| 146 | length length to be matched | length length of reference to be matched (number of bytes) |
| 147 | md points to match data block | md points to match data block |
| 148 | ims the ims flags | caseless TRUE if caseless |
| 149 | ||
| 150 | Returns: TRUE if matched | Returns: < 0 if not matched, otherwise the number of subject bytes matched |
| 151 | */ | */ |
| 152 | ||
| 153 | static BOOL | static int |
| 154 | match_ref(int offset, register USPTR eptr, int length, match_data *md, | match_ref(int offset, register USPTR eptr, int length, match_data *md, |
| 155 | unsigned long int ims) | BOOL caseless) |
| 156 | { | { |
| 157 | USPTR p = md->start_subject + md->offset_vector[offset]; | USPTR eptr_start = eptr; |
| 158 | register USPTR p = md->start_subject + md->offset_vector[offset]; | |
| 159 | ||
| 160 | #ifdef DEBUG | #ifdef PCRE_DEBUG |
| 161 | if (eptr >= md->end_subject) | if (eptr >= md->end_subject) |
| 162 | printf("matching subject <null>"); | printf("matching subject <null>"); |
| 163 | else | else |
| # | Line 146 pchars(p, length, FALSE, md); | Line 170 pchars(p, length, FALSE, md); |
| 170 | printf("\n"); | printf("\n"); |
| 171 | #endif | #endif |
| 172 | ||
| 173 | /* Always fail if not enough characters left */ | /* Always fail if reference not set (and not JavaScript compatible). */ |
| 174 | ||
| 175 | if (length > md->end_subject - eptr) return FALSE; | if (length < 0) return -1; |
| 176 | ||
| 177 | /* Separate the caselesss case for speed */ | /* Separate the caseless case for speed. In UTF-8 mode we can only do this |
| 178 | properly if Unicode properties are supported. Otherwise, we can check only | |
| 179 | ASCII characters. */ | |
| 180 | ||
| 181 | if ((ims & PCRE_CASELESS) != 0) | if (caseless) |
| 182 | { | { |
| 183 | while (length-- > 0) | #ifdef SUPPORT_UTF8 |
| 184 | if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; | #ifdef SUPPORT_UCP |
| 185 | if (md->utf8) | |
| 186 | { | |
| 187 | /* Match characters up to the end of the reference. NOTE: the number of | |
| 188 | bytes matched may differ, because there are some characters whose upper and | |
| 189 | lower case versions code as different numbers of bytes. For example, U+023A | |
| 190 | (2 bytes in UTF-8) is the upper case version of U+2C65 (3 bytes in UTF-8); | |
| 191 | a sequence of 3 of the former uses 6 bytes, as does a sequence of two of | |
| 192 | the latter. It is important, therefore, to check the length along the | |
| 193 | reference, not along the subject (earlier code did this wrong). */ | |
| 194 | ||
| 195 | USPTR endptr = p + length; | |
| 196 | while (p < endptr) | |
| 197 | { | |
| 198 | int c, d; | |
| 199 | if (eptr >= md->end_subject) return -1; | |
| 200 | GETCHARINC(c, eptr); | |
| 201 | GETCHARINC(d, p); | |
| 202 | if (c != d && c != UCD_OTHERCASE(d)) return -1; | |
| 203 | } | |
| 204 | } | |
| 205 | else | |
| 206 | #endif | |
| 207 | #endif | |
| 208 | ||
| 209 | /* The same code works when not in UTF-8 mode and in UTF-8 mode when there | |
| 210 | is no UCP support. */ | |
| 211 | { | |
| 212 | if (eptr + length > md->end_subject) return -1; | |
| 213 | while (length-- > 0) | |
| 214 | { if (md->lcc[*p++] != md->lcc[*eptr++]) return -1; } | |
| 215 | } | |
| 216 | } | } |
| 217 | ||
| 218 | /* In the caseful case, we can just compare the bytes, whether or not we | |
| 219 | are in UTF-8 mode. */ | |
| 220 | ||
| 221 | else | else |
| 222 | { while (length-- > 0) if (*p++ != *eptr++) return FALSE; } | { |
| 223 | if (eptr + length > md->end_subject) return -1; | |
| 224 | while (length-- > 0) if (*p++ != *eptr++) return -1; | |
| 225 | } | |
| 226 | ||
| 227 | return TRUE; | return eptr - eptr_start; |
| 228 | } | } |
| 229 | ||
| 230 | ||
| # | Line 203 variable instead of being passed in the | Line 267 variable instead of being passed in the |
| 267 | **************************************************************************** | **************************************************************************** |
| 268 | ***************************************************************************/ | ***************************************************************************/ |
| 269 | ||
| 270 | /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN | |
| 271 | /* Numbers for RMATCH calls */ | below must be updated in sync. */ |
| 272 | ||
| 273 | enum { RM1=1, RM2, RM3, RM4, RM5, RM6, RM7, RM8, RM9, RM10, | enum { RM1=1, RM2, RM3, RM4, RM5, RM6, RM7, RM8, RM9, RM10, |
| 274 | RM11, RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20, | RM11, RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20, |
| 275 | RM21, RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30, | RM21, RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30, |
| 276 | RM31, RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40, | RM31, RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40, |
| 277 | RM41, RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50 }; | RM41, RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50, |
| 278 | RM51, RM52, RM53, RM54, RM55, RM56, RM57, RM58, RM59, RM60, | |
| 279 | RM61, RM62, RM63}; | |
| 280 | ||
| 281 | /* These versions of the macros use the stack, as normal. There are debugging | /* These versions of the macros use the stack, as normal. There are debugging |
| 282 | versions and production versions. Note that the "rw" argument of RMATCH isn't | versions and production versions. Note that the "rw" argument of RMATCH isn't |
| 283 | actuall used in this definition. */ | actually used in this definition. */ |
| 284 | ||
| 285 | #ifndef NO_RECURSE | #ifndef NO_RECURSE |
| 286 | #define REGISTER register | #define REGISTER register |
| 287 | ||
| 288 | #ifdef DEBUG | #ifdef PCRE_DEBUG |
| 289 | #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \ | #define RMATCH(ra,rb,rc,rd,re,rw) \ |
| 290 | { \ | { \ |
| 291 | printf("match() called in line %d\n", __LINE__); \ | printf("match() called in line %d\n", __LINE__); \ |
| 292 | rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \ | rrc = match(ra,rb,mstart,markptr,rc,rd,re,rdepth+1); \ |
| 293 | printf("to line %d\n", __LINE__); \ | printf("to line %d\n", __LINE__); \ |
| 294 | } | } |
| 295 | #define RRETURN(ra) \ | #define RRETURN(ra) \ |
| # | Line 233 actuall used in this definition. */ | Line 298 actuall used in this definition. */ |
| 298 | return ra; \ | return ra; \ |
| 299 | } | } |
| 300 | #else | #else |
| 301 | #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \ | #define RMATCH(ra,rb,rc,rd,re,rw) \ |
| 302 | rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1) | rrc = match(ra,rb,mstart,markptr,rc,rd,re,rdepth+1) |
| 303 | #define RRETURN(ra) return ra | #define RRETURN(ra) return ra |
| 304 | #endif | #endif |
| 305 | ||
| # | Line 247 argument of match(), which never changes | Line 312 argument of match(), which never changes |
| 312 | ||
| 313 | #define REGISTER | #define REGISTER |
| 314 | ||
| 315 | #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\ | #define RMATCH(ra,rb,rc,rd,re,rw)\ |
| 316 | {\ | {\ |
| 317 | heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\ | heapframe *newframe = (heapframe *)(pcre_stack_malloc)(sizeof(heapframe));\ |
| 318 | if (newframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\ | |
| 319 | frame->Xwhere = rw; \ | frame->Xwhere = rw; \ |
| 320 | newframe->Xeptr = ra;\ | newframe->Xeptr = ra;\ |
| 321 | newframe->Xecode = rb;\ | newframe->Xecode = rb;\ |
| 322 | newframe->Xmstart = mstart;\ | newframe->Xmstart = mstart;\ |
| 323 | newframe->Xmarkptr = markptr;\ | |
| 324 | newframe->Xoffset_top = rc;\ | newframe->Xoffset_top = rc;\ |
| 325 | newframe->Xims = re;\ | newframe->Xeptrb = re;\ |
| newframe->Xeptrb = rf;\ | ||
| newframe->Xflags = rg;\ | ||
| 326 | newframe->Xrdepth = frame->Xrdepth + 1;\ | newframe->Xrdepth = frame->Xrdepth + 1;\ |
| 327 | newframe->Xprevframe = frame;\ | newframe->Xprevframe = frame;\ |
| 328 | frame = newframe;\ | frame = newframe;\ |
| # | Line 269 argument of match(), which never changes | Line 334 argument of match(), which never changes |
| 334 | ||
| 335 | #define RRETURN(ra)\ | #define RRETURN(ra)\ |
| 336 | {\ | {\ |
| 337 | heapframe *newframe = frame;\ | heapframe *oldframe = frame;\ |
| 338 | frame = newframe->Xprevframe;\ | frame = oldframe->Xprevframe;\ |
| 339 | (pcre_stack_free)(newframe);\ | (pcre_stack_free)(oldframe);\ |
| 340 | if (frame != NULL)\ | if (frame != NULL)\ |
| 341 | {\ | {\ |
| 342 | rrc = ra;\ | rrc = ra;\ |
| # | Line 288 typedef struct heapframe { | Line 353 typedef struct heapframe { |
| 353 | ||
| 354 | /* Function arguments that may change */ | /* Function arguments that may change */ |
| 355 | ||
| 356 | const uschar *Xeptr; | USPTR Xeptr; |
| 357 | const uschar *Xecode; | const uschar *Xecode; |
| 358 | const uschar *Xmstart; | USPTR Xmstart; |
| 359 | USPTR Xmarkptr; | |
| 360 | int Xoffset_top; | int Xoffset_top; |
| long int Xims; | ||
| 361 | eptrblock *Xeptrb; | eptrblock *Xeptrb; |
| int Xflags; | ||
| 362 | unsigned int Xrdepth; | unsigned int Xrdepth; |
| 363 | ||
| 364 | /* Function local variables */ | /* Function local variables */ |
| 365 | ||
| 366 | const uschar *Xcallpat; | USPTR Xcallpat; |
| 367 | const uschar *Xcharptr; | #ifdef SUPPORT_UTF8 |
| 368 | const uschar *Xdata; | USPTR Xcharptr; |
| 369 | const uschar *Xnext; | #endif |
| 370 | const uschar *Xpp; | USPTR Xdata; |
| 371 | const uschar *Xprev; | USPTR Xnext; |
| 372 | const uschar *Xsaved_eptr; | USPTR Xpp; |
| 373 | USPTR Xprev; | |
| 374 | USPTR Xsaved_eptr; | |
| 375 | ||
| 376 | recursion_info Xnew_recursive; | recursion_info Xnew_recursive; |
| 377 | ||
| # | Line 313 typedef struct heapframe { | Line 379 typedef struct heapframe { |
| 379 | BOOL Xcondition; | BOOL Xcondition; |
| 380 | BOOL Xprev_is_word; | BOOL Xprev_is_word; |
| 381 | ||
| unsigned long int Xoriginal_ims; | ||
| 382 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 383 | int Xprop_type; | int Xprop_type; |
| 384 | int Xprop_value; | int Xprop_value; |
| # | Line 326 typedef struct heapframe { | Line 390 typedef struct heapframe { |
| 390 | uschar Xocchars[8]; | uschar Xocchars[8]; |
| 391 | #endif | #endif |
| 392 | ||
| 393 | int Xcodelink; | |
| 394 | int Xctype; | int Xctype; |
| 395 | unsigned int Xfc; | unsigned int Xfc; |
| 396 | int Xfi; | int Xfi; |
| # | Line 361 typedef struct heapframe { | Line 426 typedef struct heapframe { |
| 426 | ||
| 427 | /* This function is called recursively in many circumstances. Whenever it | /* This function is called recursively in many circumstances. Whenever it |
| 428 | returns a negative (error) response, the outer incarnation must also return the | returns a negative (error) response, the outer incarnation must also return the |
| 429 | same response. | same response. */ |
| 430 | ||
| 431 | /* These macros pack up tests that are used for partial matching, and which | |
| 432 | appears several times in the code. We set the "hit end" flag if the pointer is | |
| 433 | at the end of the subject and also past the start of the subject (i.e. | |
| 434 | something has been matched). For hard partial matching, we then return | |
| 435 | immediately. The second one is used when we already know we are past the end of | |
| 436 | the subject. */ | |
| 437 | ||
| 438 | #define CHECK_PARTIAL()\ | |
| 439 | if (md->partial != 0 && eptr >= md->end_subject && \ | |
| 440 | eptr > md->start_used_ptr) \ | |
| 441 | { \ | |
| 442 | md->hitend = TRUE; \ | |
| 443 | if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL); \ | |
| 444 | } | |
| 445 | ||
| 446 | Performance note: It might be tempting to extract commonly used fields from the | #define SCHECK_PARTIAL()\ |
| 447 | md structure (e.g. utf8, end_subject) into individual variables to improve | if (md->partial != 0 && eptr > md->start_used_ptr) \ |
| 448 | { \ | |
| 449 | md->hitend = TRUE; \ | |
| 450 | if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL); \ | |
| 451 | } | |
| 452 | ||
| 453 | ||
| 454 | /* Performance note: It might be tempting to extract commonly used fields from | |
| 455 | the md structure (e.g. utf8, end_subject) into individual variables to improve | |
| 456 | performance. Tests using gcc on a SPARC disproved this; in the first case, it | performance. Tests using gcc on a SPARC disproved this; in the first case, it |
| 457 | made performance worse. | made performance worse. |
| 458 | ||
| # | Line 373 Arguments: | Line 461 Arguments: |
| 461 | ecode pointer to current position in compiled code | ecode pointer to current position in compiled code |
| 462 | mstart pointer to the current match start position (can be modified | mstart pointer to the current match start position (can be modified |
| 463 | by encountering \K) | by encountering \K) |
| 464 | markptr pointer to the most recent MARK name, or NULL | |
| 465 | offset_top current top pointer | offset_top current top pointer |
| 466 | md pointer to "static" info for the match | md pointer to "static" info for the match |
| ims current /i, /m, and /s options | ||
| 467 | eptrb pointer to chain of blocks containing eptr at start of | eptrb pointer to chain of blocks containing eptr at start of |
| 468 | brackets - for testing for empty matches | brackets - for testing for empty matches |
| flags can contain | ||
| match_condassert - this is an assertion condition | ||
| match_cbegroup - this is the start of an unlimited repeat | ||
| group that can match an empty string | ||
| 469 | rdepth the recursion depth | rdepth the recursion depth |
| 470 | ||
| 471 | Returns: MATCH_MATCH if matched ) these values are >= 0 | Returns: MATCH_MATCH if matched ) these values are >= 0 |
| 472 | MATCH_NOMATCH if failed to match ) | MATCH_NOMATCH if failed to match ) |
| 473 | a negative MATCH_xxx value for PRUNE, SKIP, etc | |
| 474 | a negative PCRE_ERROR_xxx value if aborted by an error condition | a negative PCRE_ERROR_xxx value if aborted by an error condition |
| 475 | (e.g. stopped by repeated call or recursion limit) | (e.g. stopped by repeated call or recursion limit) |
| 476 | */ | */ |
| 477 | ||
| 478 | static int | static int |
| 479 | match(REGISTER USPTR eptr, REGISTER const uschar *ecode, const uschar *mstart, | match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart, |
| 480 | int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb, | const uschar *markptr, int offset_top, match_data *md, eptrblock *eptrb, |
| 481 | int flags, unsigned int rdepth) | unsigned int rdepth) |
| 482 | { | { |
| 483 | /* 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, |
| 484 | so they can be ordinary variables in all cases. Mark some of them with | so they can be ordinary variables in all cases. Mark some of them with |
| # | Line 405 register unsigned int c; /* Character | Line 490 register unsigned int c; /* Character |
| 490 | register BOOL utf8; /* Local copy of UTF-8 flag for speed */ | register BOOL utf8; /* Local copy of UTF-8 flag for speed */ |
| 491 | ||
| 492 | BOOL minimize, possessive; /* Quantifier options */ | BOOL minimize, possessive; /* Quantifier options */ |
| 493 | BOOL caseless; | |
| 494 | int condcode; | |
| 495 | ||
| 496 | /* 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 |
| 497 | 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 |
| # | Line 412 heap storage. Set up the top-level frame | Line 499 heap storage. Set up the top-level frame |
| 499 | heap whenever RMATCH() does a "recursion". See the macro definitions above. */ | heap whenever RMATCH() does a "recursion". See the macro definitions above. */ |
| 500 | ||
| 501 | #ifdef NO_RECURSE | #ifdef NO_RECURSE |
| 502 | heapframe *frame = (pcre_stack_malloc)(sizeof(heapframe)); | heapframe *frame = (heapframe *)(pcre_stack_malloc)(sizeof(heapframe)); |
| 503 | if (frame == NULL) RRETURN(PCRE_ERROR_NOMEMORY); | |
| 504 | frame->Xprevframe = NULL; /* Marks the top level */ | frame->Xprevframe = NULL; /* Marks the top level */ |
| 505 | ||
| 506 | /* Copy in the original argument variables */ | /* Copy in the original argument variables */ |
| # | Line 420 frame->Xprevframe = NULL; /* | Line 508 frame->Xprevframe = NULL; /* |
| 508 | frame->Xeptr = eptr; | frame->Xeptr = eptr; |
| 509 | frame->Xecode = ecode; | frame->Xecode = ecode; |
| 510 | frame->Xmstart = mstart; | frame->Xmstart = mstart; |
| 511 | frame->Xmarkptr = markptr; | |
| 512 | frame->Xoffset_top = offset_top; | frame->Xoffset_top = offset_top; |
| frame->Xims = ims; | ||
| 513 | frame->Xeptrb = eptrb; | frame->Xeptrb = eptrb; |
| frame->Xflags = flags; | ||
| 514 | frame->Xrdepth = rdepth; | frame->Xrdepth = rdepth; |
| 515 | ||
| 516 | /* This is where control jumps back to to effect "recursion" */ | /* This is where control jumps back to to effect "recursion" */ |
| # | Line 435 HEAP_RECURSE: | Line 522 HEAP_RECURSE: |
| 522 | #define eptr frame->Xeptr | #define eptr frame->Xeptr |
| 523 | #define ecode frame->Xecode | #define ecode frame->Xecode |
| 524 | #define mstart frame->Xmstart | #define mstart frame->Xmstart |
| 525 | #define markptr frame->Xmarkptr | |
| 526 | #define offset_top frame->Xoffset_top | #define offset_top frame->Xoffset_top |
| #define ims frame->Xims | ||
| 527 | #define eptrb frame->Xeptrb | #define eptrb frame->Xeptrb |
| #define flags frame->Xflags | ||
| 528 | #define rdepth frame->Xrdepth | #define rdepth frame->Xrdepth |
| 529 | ||
| 530 | /* Ditto for the local variables */ | /* Ditto for the local variables */ |
| # | Line 447 HEAP_RECURSE: | Line 533 HEAP_RECURSE: |
| 533 | #define charptr frame->Xcharptr | #define charptr frame->Xcharptr |
| 534 | #endif | #endif |
| 535 | #define callpat frame->Xcallpat | #define callpat frame->Xcallpat |
| 536 | #define codelink frame->Xcodelink | |
| 537 | #define data frame->Xdata | #define data frame->Xdata |
| 538 | #define next frame->Xnext | #define next frame->Xnext |
| 539 | #define pp frame->Xpp | #define pp frame->Xpp |
| # | Line 459 HEAP_RECURSE: | Line 546 HEAP_RECURSE: |
| 546 | #define condition frame->Xcondition | #define condition frame->Xcondition |
| 547 | #define prev_is_word frame->Xprev_is_word | #define prev_is_word frame->Xprev_is_word |
| 548 | ||
| #define original_ims frame->Xoriginal_ims | ||
| 549 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 550 | #define prop_type frame->Xprop_type | #define prop_type frame->Xprop_type |
| 551 | #define prop_value frame->Xprop_value | #define prop_value frame->Xprop_value |
| # | Line 497 i, and fc and c, can be the same variabl | Line 582 i, and fc and c, can be the same variabl |
| 582 | #define fi i | #define fi i |
| 583 | #define fc c | #define fc c |
| 584 | ||
| 585 | /* Many of the following variables are used only in small blocks of the code. | |
| 586 | #ifdef SUPPORT_UTF8 /* Many of these variables are used only */ | My normal style of coding would have declared them within each of those blocks. |
| 587 | const uschar *charptr; /* in small blocks of the code. My normal */ | However, in order to accommodate the version of this code that uses an external |
| 588 | #endif /* style of coding would have declared */ | "stack" implemented on the heap, it is easier to declare them all here, so the |
| 589 | const uschar *callpat; /* them within each of those blocks. */ | declarations can be cut out in a block. The only declarations within blocks |
| 590 | const uschar *data; /* However, in order to accommodate the */ | below are for variables that do not have to be preserved over a recursive call |
| 591 | const uschar *next; /* version of this code that uses an */ | to RMATCH(). */ |
| 592 | USPTR pp; /* external "stack" implemented on the */ | |
| 593 | const uschar *prev; /* heap, it is easier to declare them all */ | #ifdef SUPPORT_UTF8 |
| 594 | USPTR saved_eptr; /* here, so the declarations can be cut */ | const uschar *charptr; |
| 595 | /* out in a block. The only declarations */ | #endif |
| 596 | recursion_info new_recursive; /* within blocks below are for variables */ | const uschar *callpat; |
| 597 | /* that do not have to be preserved over */ | const uschar *data; |
| 598 | BOOL cur_is_word; /* a recursive call to RMATCH(). */ | const uschar *next; |
| 599 | USPTR pp; | |
| 600 | const uschar *prev; | |
| 601 | USPTR saved_eptr; | |
| 602 | ||
| 603 | recursion_info new_recursive; | |
| 604 | ||
| 605 | BOOL cur_is_word; | |
| 606 | BOOL condition; | BOOL condition; |
| 607 | BOOL prev_is_word; | BOOL prev_is_word; |
| 608 | ||
| unsigned long int original_ims; | ||
| 609 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 610 | int prop_type; | int prop_type; |
| 611 | int prop_value; | int prop_value; |
| # | Line 527 int oclength; | Line 617 int oclength; |
| 617 | uschar occhars[8]; | uschar occhars[8]; |
| 618 | #endif | #endif |
| 619 | ||
| 620 | int codelink; | |
| 621 | int ctype; | int ctype; |
| 622 | int length; | int length; |
| 623 | int max; | int max; |
| # | Line 541 int stacksave[REC_STACK_SAVE_MAX]; | Line 632 int stacksave[REC_STACK_SAVE_MAX]; |
| 632 | eptrblock newptrb; | eptrblock newptrb; |
| 633 | #endif /* NO_RECURSE */ | #endif /* NO_RECURSE */ |
| 634 | ||
| 635 | /* To save space on the stack and in the heap frame, I have doubled up on some | |
| 636 | of the local variables that are used only in localised parts of the code, but | |
| 637 | still need to be preserved over recursive calls of match(). These macros define | |
| 638 | the alternative names that are used. */ | |
| 639 | ||
| 640 | #define allow_zero cur_is_word | |
| 641 | #define cbegroup condition | |
| 642 | #define code_offset codelink | |
| 643 | #define condassert condition | |
| 644 | #define matched_once prev_is_word | |
| 645 | ||
| 646 | /* These statements are here to stop the compiler complaining about unitialized | /* These statements are here to stop the compiler complaining about unitialized |
| 647 | variables. */ | variables. */ |
| 648 | ||
| # | Line 560 TAIL_RECURSE: | Line 662 TAIL_RECURSE: |
| 662 | /* 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 |
| 663 | 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 |
| 664 | 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() |
| 665 | and a "return", respectively (possibly with some debugging if DEBUG is | and a "return", respectively (possibly with some debugging if PCRE_DEBUG is |
| 666 | defined). However, RMATCH isn't like a function call because it's quite a | defined). However, RMATCH isn't like a function call because it's quite a |
| 667 | complicated macro. It has to be used in one particular way. This shouldn't, | complicated macro. It has to be used in one particular way. This shouldn't, |
| 668 | however, impact performance when true recursion is being used. */ | however, impact performance when true recursion is being used. */ |
| # | Line 577 haven't exceeded the recursive call limi | Line 679 haven't exceeded the recursive call limi |
| 679 | if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT); | if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT); |
| 680 | if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT); | if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT); |
| 681 | ||
| original_ims = ims; /* Save for resetting on ')' */ | ||
| 682 | /* At the start of a group with an unlimited repeat that may match an empty | /* At the start of a group with an unlimited repeat that may match an empty |
| 683 | string, the match_cbegroup flag is set. When this is the case, add the current | string, the variable md->match_function_type is set to MATCH_CBEGROUP. It is |
| 684 | subject pointer to the chain of such remembered pointers, to be checked when we | done this way to save having to use another function argument, which would take |
| 685 | hit the closing ket, in order to break infinite loops that match no characters. | up space on the stack. See also MATCH_CONDASSERT below. |
| 686 | When match() is called in other circumstances, don't add to the chain. The | |
| 687 | match_cbegroup flag must NOT be used with tail recursion, because the memory | When MATCH_CBEGROUP is set, add the current subject pointer to the chain of |
| 688 | block that is used is on the stack, so a new one may be required for each | such remembered pointers, to be checked when we hit the closing ket, in order |
| 689 | match(). */ | to break infinite loops that match no characters. When match() is called in |
| 690 | other circumstances, don't add to the chain. The MATCH_CBEGROUP feature must | |
| 691 | NOT be used with tail recursion, because the memory block that is used is on | |
| 692 | the stack, so a new one may be required for each match(). */ | |
| 693 | ||
| 694 | if ((flags & match_cbegroup) != 0) | if (md->match_function_type == MATCH_CBEGROUP) |
| 695 | { | { |
| 696 | newptrb.epb_saved_eptr = eptr; | newptrb.epb_saved_eptr = eptr; |
| 697 | newptrb.epb_prev = eptrb; | newptrb.epb_prev = eptrb; |
| 698 | eptrb = &newptrb; | eptrb = &newptrb; |
| 699 | md->match_function_type = 0; | |
| 700 | } | } |
| 701 | ||
| 702 | /* Now start processing the opcodes. */ | /* Now start processing the opcodes. */ |
| # | Line 601 for (;;) | Line 705 for (;;) |
| 705 | { | { |
| 706 | minimize = possessive = FALSE; | minimize = possessive = FALSE; |
| 707 | op = *ecode; | op = *ecode; |
| 708 | ||
| /* For partial matching, remember if we ever hit the end of the subject after | ||
| matching at least one subject character. */ | ||
| if (md->partial && | ||
| eptr >= md->end_subject && | ||
| eptr > mstart) | ||
| md->hitend = TRUE; | ||
| 709 | switch(op) | switch(op) |
| 710 | { | { |
| 711 | /* Handle a capturing bracket. If there is space in the offset vector, save | case OP_MARK: |
| 712 | the current subject position in the working slot at the top of the vector. | markptr = ecode + 2; |
| 713 | We mustn't change the current values of the data slot, because they may be | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md, |
| 714 | set from a previous iteration of this group, and be referred to by a | eptrb, RM55); |
| 715 | reference inside the group. | |
| 716 | /* A return of MATCH_SKIP_ARG means that matching failed at SKIP with an | |
| 717 | If the bracket fails to match, we need to restore this value and also the | argument, and we must check whether that argument matches this MARK's |
| 718 | argument. It is passed back in md->start_match_ptr (an overloading of that | |
| 719 | variable). If it does match, we reset that variable to the current subject | |
| 720 | position and return MATCH_SKIP. Otherwise, pass back the return code | |
| 721 | unaltered. */ | |
| 722 | ||
| 723 | if (rrc == MATCH_SKIP_ARG && | |
| 724 | strcmp((char *)markptr, (char *)(md->start_match_ptr)) == 0) | |
| 725 | { | |
| 726 | md->start_match_ptr = eptr; | |
| 727 | RRETURN(MATCH_SKIP); | |
| 728 | } | |
| 729 | ||
| 730 | if (md->mark == NULL) md->mark = markptr; | |
| 731 | RRETURN(rrc); | |
| 732 | ||
| 733 | case OP_FAIL: | |
| 734 | MRRETURN(MATCH_NOMATCH); | |
| 735 | ||
| 736 | /* COMMIT overrides PRUNE, SKIP, and THEN */ | |
| 737 | ||
| 738 | case OP_COMMIT: | |
| 739 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
| 740 | eptrb, RM52); | |
| 741 | if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && | |
| 742 | rrc != MATCH_SKIP && rrc != MATCH_SKIP_ARG && | |
| 743 | rrc != MATCH_THEN) | |
| 744 | RRETURN(rrc); | |
| 745 | MRRETURN(MATCH_COMMIT); | |
| 746 | ||
| 747 | /* PRUNE overrides THEN */ | |
| 748 | ||
| 749 | case OP_PRUNE: | |
| 750 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
| 751 | eptrb, RM51); | |
| 752 | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); | |
| 753 | MRRETURN(MATCH_PRUNE); | |
| 754 | ||
| 755 | case OP_PRUNE_ARG: | |
| 756 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md, | |
| 757 | eptrb, RM56); | |
| 758 | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); | |
| 759 | md->mark = ecode + 2; | |
| 760 | RRETURN(MATCH_PRUNE); | |
| 761 | ||
| 762 | /* SKIP overrides PRUNE and THEN */ | |
| 763 | ||
| 764 | case OP_SKIP: | |
| 765 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
| 766 | eptrb, RM53); | |
| 767 | if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN) | |
| 768 | RRETURN(rrc); | |
| 769 | md->start_match_ptr = eptr; /* Pass back current position */ | |
| 770 | MRRETURN(MATCH_SKIP); | |
| 771 | ||
| 772 | case OP_SKIP_ARG: | |
| 773 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md, | |
| 774 | eptrb, RM57); | |
| 775 | if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN) | |
| 776 | RRETURN(rrc); | |
| 777 | ||
| 778 | /* Pass back the current skip name by overloading md->start_match_ptr and | |
| 779 | returning the special MATCH_SKIP_ARG return code. This will either be | |
| 780 | caught by a matching MARK, or get to the top, where it is treated the same | |
| 781 | as PRUNE. */ | |
| 782 | ||
| 783 | md->start_match_ptr = ecode + 2; | |
| 784 | RRETURN(MATCH_SKIP_ARG); | |
| 785 | ||
| 786 | /* For THEN (and THEN_ARG) we pass back the address of the bracket or | |
| 787 | the alt that is at the start of the current branch. This makes it possible | |
| 788 | to skip back past alternatives that precede the THEN within the current | |
| 789 | branch. */ | |
| 790 | ||
| 791 | case OP_THEN: | |
| 792 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
| 793 | eptrb, RM54); | |
| 794 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 795 | md->start_match_ptr = ecode - GET(ecode, 1); | |
| 796 | MRRETURN(MATCH_THEN); | |
| 797 | ||
| 798 | case OP_THEN_ARG: | |
| 799 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1+LINK_SIZE], | |
| 800 | offset_top, md, eptrb, RM58); | |
| 801 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 802 | md->start_match_ptr = ecode - GET(ecode, 1); | |
| 803 | md->mark = ecode + LINK_SIZE + 2; | |
| 804 | RRETURN(MATCH_THEN); | |
| 805 | ||
| 806 | /* Handle a capturing bracket, other than those that are possessive with an | |
| 807 | unlimited repeat. If there is space in the offset vector, save the current | |
| 808 | subject position in the working slot at the top of the vector. We mustn't | |
| 809 | change the current values of the data slot, because they may be set from a | |
| 810 | previous iteration of this group, and be referred to by a reference inside | |
| 811 | the group. If we fail to match, we need to restore this value and also the | |
| 812 | values of the final offsets, in case they were set by a previous iteration | values of the final offsets, in case they were set by a previous iteration |
| 813 | of the same bracket. | of the same bracket. |
| 814 | ||
| # | Line 630 for (;;) | Line 820 for (;;) |
| 820 | case OP_SCBRA: | case OP_SCBRA: |
| 821 | number = GET2(ecode, 1+LINK_SIZE); | number = GET2(ecode, 1+LINK_SIZE); |
| 822 | offset = number << 1; | offset = number << 1; |
| 823 | ||
| 824 | #ifdef DEBUG | #ifdef PCRE_DEBUG |
| 825 | printf("start bracket %d\n", number); | printf("start bracket %d\n", number); |
| 826 | printf("subject="); | printf("subject="); |
| 827 | pchars(eptr, 16, TRUE, md); | pchars(eptr, 16, TRUE, md); |
| # | Line 646 for (;;) | Line 836 for (;;) |
| 836 | save_capture_last = md->capture_last; | save_capture_last = md->capture_last; |
| 837 | ||
| 838 | DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3)); | DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3)); |
| 839 | md->offset_vector[md->offset_end - number] = eptr - md->start_subject; | md->offset_vector[md->offset_end - number] = |
| 840 | (int)(eptr - md->start_subject); | |
| 841 | ||
| 842 | flags = (op == OP_SCBRA)? match_cbegroup : 0; | for (;;) |
| do | ||
| 843 | { | { |
| 844 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP; |
| 845 | ims, eptrb, flags, RM1); | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, |
| 846 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | eptrb, RM1); |
| 847 | if (rrc != MATCH_NOMATCH && | |
| 848 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
| 849 | RRETURN(rrc); | |
| 850 | ||
| 851 | /* If md->end_offset_top is greater than offset_top, it means that the | |
| 852 | branch we have just failed to match did manage to match some capturing | |
| 853 | parentheses within an atomic group or an assertion. Although offset_top | |
| 854 | reverts to its original value at this level, we must unset the captured | |
| 855 | values in case a later match sets a higher capturing number. Example: | |
| 856 | matching /((?>(a))b|(a)c)/ against "ac". This captures 3, but we need | |
| 857 | to ensure that 2 - which was captured in the atomic matching - is | |
| 858 | unset. */ | |
| 859 | ||
| 860 | if (md->end_offset_top > offset_top) | |
| 861 | { | |
| 862 | register int *iptr = md->offset_vector + offset_top; | |
| 863 | register int *iend = md->offset_vector + md->end_offset_top; | |
| 864 | while (iptr < iend) *iptr++ = -1; | |
| 865 | } | |
| 866 | ||
| 867 | md->capture_last = save_capture_last; | md->capture_last = save_capture_last; |
| 868 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
| 869 | if (*ecode != OP_ALT) break; | |
| 870 | } | } |
| while (*ecode == OP_ALT); | ||
| 871 | ||
| 872 | DPRINTF(("bracket %d failed\n", number)); | DPRINTF(("bracket %d failed\n", number)); |
| 873 | ||
| # | Line 665 for (;;) | Line 875 for (;;) |
| 875 | md->offset_vector[offset+1] = save_offset2; | md->offset_vector[offset+1] = save_offset2; |
| 876 | md->offset_vector[md->offset_end - number] = save_offset3; | md->offset_vector[md->offset_end - number] = save_offset3; |
| 877 | ||
| 878 | if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr; | |
| 879 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 880 | } | } |
| 881 | ||
| # | Line 679 for (;;) | Line 890 for (;;) |
| 890 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 891 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 892 | ||
| 893 | /* Non-capturing bracket. Loop for all the alternatives. When we get to the | /* Non-capturing bracket, except for possessive with unlimited repeat. Loop |
| 894 | final alternative within the brackets, we would return the result of a | for all the alternatives. When we get to the final alternative within the |
| 895 | recursive call to match() whatever happened. We can reduce stack usage by | brackets, we used to return the result of a recursive call to match() |
| 896 | turning this into a tail recursion, except in the case when match_cbegroup | whatever happened so it was possible to reduce stack usage by turning this |
| 897 | is set.*/ | into a tail recursion, except in the case of a possibly empty group. |
| 898 | However, now that there is the possiblity of (*THEN) occurring in the final | |
| 899 | alternative, this optimization is no longer possible. */ | |
| 900 | ||
| 901 | case OP_BRA: | case OP_BRA: |
| 902 | case OP_SBRA: | case OP_SBRA: |
| 903 | DPRINTF(("start non-capturing bracket\n")); | DPRINTF(("start non-capturing bracket\n")); |
| flags = (op >= OP_SBRA)? match_cbegroup : 0; | ||
| 904 | for (;;) | for (;;) |
| 905 | { | { |
| 906 | if (ecode[GET(ecode, 1)] != OP_ALT) /* Final alternative */ | if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP; |
| 907 | { | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, eptrb, |
| 908 | if (flags == 0) /* Not a possibly empty group */ | RM2); |
| 909 | if (rrc != MATCH_NOMATCH && | |
| 910 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
| 911 | RRETURN(rrc); | |
| 912 | ||
| 913 | /* See explanatory comment above under OP_CBRA. */ | |
| 914 | ||
| 915 | if (md->end_offset_top > offset_top) | |
| 916 | { | |
| 917 | register int *iptr = md->offset_vector + offset_top; | |
| 918 | register int *iend = md->offset_vector + md->end_offset_top; | |
| 919 | while (iptr < iend) *iptr++ = -1; | |
| 920 | } | |
| 921 | ||
| 922 | ecode += GET(ecode, 1); | |
| 923 | if (*ecode != OP_ALT) break; | |
| 924 | } | |
| 925 | ||
| 926 | if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr; | |
| 927 | RRETURN(MATCH_NOMATCH); | |
| 928 | ||
| 929 | /* Handle possessive capturing brackets with an unlimited repeat. We come | |
| 930 | here from BRAZERO with allow_zero set TRUE. The offset_vector values are | |
| 931 | handled similarly to the normal case above. However, the matching is | |
| 932 | different. The end of these brackets will always be OP_KETRPOS, which | |
| 933 | returns MATCH_KETRPOS without going further in the pattern. By this means | |
| 934 | we can handle the group by iteration rather than recursion, thereby | |
| 935 | reducing the amount of stack needed. */ | |
| 936 | ||
| 937 | case OP_CBRAPOS: | |
| 938 | case OP_SCBRAPOS: | |
| 939 | allow_zero = FALSE; | |
| 940 | ||
| 941 | POSSESSIVE_CAPTURE: | |
| 942 | number = GET2(ecode, 1+LINK_SIZE); | |
| 943 | offset = number << 1; | |
| 944 | ||
| 945 | #ifdef PCRE_DEBUG | |
| 946 | printf("start possessive bracket %d\n", number); | |
| 947 | printf("subject="); | |
| 948 | pchars(eptr, 16, TRUE, md); | |
| 949 | printf("\n"); | |
| 950 | #endif | |
| 951 | ||
| 952 | if (offset < md->offset_max) | |
| 953 | { | |
| 954 | matched_once = FALSE; | |
| 955 | code_offset = ecode - md->start_code; | |
| 956 | ||
| 957 | save_offset1 = md->offset_vector[offset]; | |
| 958 | save_offset2 = md->offset_vector[offset+1]; | |
| 959 | save_offset3 = md->offset_vector[md->offset_end - number]; | |
| 960 | save_capture_last = md->capture_last; | |
| 961 | ||
| 962 | DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3)); | |
| 963 | ||
| 964 | /* Each time round the loop, save the current subject position for use | |
| 965 | when the group matches. For MATCH_MATCH, the group has matched, so we | |
| 966 | restart it with a new subject starting position, remembering that we had | |
| 967 | at least one match. For MATCH_NOMATCH, carry on with the alternatives, as | |
| 968 | usual. If we haven't matched any alternatives in any iteration, check to | |
| 969 | see if a previous iteration matched. If so, the group has matched; | |
| 970 | continue from afterwards. Otherwise it has failed; restore the previous | |
| 971 | capture values before returning NOMATCH. */ | |
| 972 | ||
| 973 | for (;;) | |
| 974 | { | |
| 975 | md->offset_vector[md->offset_end - number] = | |
| 976 | (int)(eptr - md->start_subject); | |
| 977 | if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP; | |
| 978 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
| 979 | eptrb, RM63); | |
| 980 | if (rrc == MATCH_KETRPOS) | |
| 981 | { | { |
| 982 | ecode += _pcre_OP_lengths[*ecode]; | offset_top = md->end_offset_top; |
| 983 | DPRINTF(("bracket 0 tail recursion\n")); | eptr = md->end_match_ptr; |
| 984 | goto TAIL_RECURSE; | ecode = md->start_code + code_offset; |
| 985 | save_capture_last = md->capture_last; | |
| 986 | matched_once = TRUE; | |
| 987 | continue; | |
| 988 | } | |
| 989 | if (rrc != MATCH_NOMATCH && | |
| 990 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
| 991 | RRETURN(rrc); | |
| 992 | ||
| 993 | /* See explanatory comment above under OP_CBRA. */ | |
| 994 | ||
| 995 | if (md->end_offset_top > offset_top) | |
| 996 | { | |
| 997 | register int *iptr = md->offset_vector + offset_top; | |
| 998 | register int *iend = md->offset_vector + md->end_offset_top; | |
| 999 | while (iptr < iend) *iptr++ = -1; | |
| 1000 | } | } |
| 1001 | ||
| 1002 | /* Possibly empty group; can't use tail recursion. */ | md->capture_last = save_capture_last; |
| 1003 | ecode += GET(ecode, 1); | |
| 1004 | if (*ecode != OP_ALT) break; | |
| 1005 | } | |
| 1006 | ||
| 1007 | if (!matched_once) | |
| 1008 | { | |
| 1009 | md->offset_vector[offset] = save_offset1; | |
| 1010 | md->offset_vector[offset+1] = save_offset2; | |
| 1011 | md->offset_vector[md->offset_end - number] = save_offset3; | |
| 1012 | } | |
| 1013 | ||
| 1014 | if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr; | |
| 1015 | if (allow_zero || matched_once) | |
| 1016 | { | |
| 1017 | ecode += 1 + LINK_SIZE; | |
| 1018 | break; | |
| 1019 | } | |
| 1020 | ||
| 1021 | RRETURN(MATCH_NOMATCH); | |
| 1022 | } | |
| 1023 | ||
| 1024 | /* FALL THROUGH ... Insufficient room for saving captured contents. Treat | |
| 1025 | as a non-capturing bracket. */ | |
| 1026 | ||
| 1027 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | |
| 1028 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | |
| 1029 | ||
| 1030 | DPRINTF(("insufficient capture room: treat as non-capturing\n")); | |
| 1031 | ||
| 1032 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | |
| 1033 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | |
| 1034 | ||
| 1035 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims, | /* Non-capturing possessive bracket with unlimited repeat. We come here |
| 1036 | eptrb, flags, RM48); | from BRAZERO with allow_zero = TRUE. The code is similar to the above, |
| 1037 | without the capturing complication. It is written out separately for speed | |
| 1038 | and cleanliness. */ | |
| 1039 | ||
| 1040 | case OP_BRAPOS: | |
| 1041 | case OP_SBRAPOS: | |
| 1042 | allow_zero = FALSE; | |
| 1043 | ||
| 1044 | POSSESSIVE_NON_CAPTURE: | |
| 1045 | matched_once = FALSE; | |
| 1046 | code_offset = ecode - md->start_code; | |
| 1047 | ||
| 1048 | for (;;) | |
| 1049 | { | |
| 1050 | if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP; | |
| 1051 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
| 1052 | eptrb, RM48); | |
| 1053 | if (rrc == MATCH_KETRPOS) | |
| 1054 | { | |
| 1055 | offset_top = md->end_offset_top; | |
| 1056 | eptr = md->end_match_ptr; | |
| 1057 | ecode = md->start_code + code_offset; | |
| 1058 | matched_once = TRUE; | |
| 1059 | continue; | |
| 1060 | } | |
| 1061 | if (rrc != MATCH_NOMATCH && | |
| 1062 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
| 1063 | RRETURN(rrc); | RRETURN(rrc); |
| 1064 | ||
| 1065 | /* See explanatory comment above under OP_CBRA. */ | |
| 1066 | ||
| 1067 | if (md->end_offset_top > offset_top) | |
| 1068 | { | |
| 1069 | register int *iptr = md->offset_vector + offset_top; | |
| 1070 | register int *iend = md->offset_vector + md->end_offset_top; | |
| 1071 | while (iptr < iend) *iptr++ = -1; | |
| 1072 | } | } |
| 1073 | ||
| /* For non-final alternatives, continue the loop for a NOMATCH result; | ||
| otherwise return. */ | ||
| RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims, | ||
| eptrb, flags, RM2); | ||
| if (rrc != MATCH_NOMATCH) RRETURN(rrc); | ||
| 1074 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
| 1075 | if (*ecode != OP_ALT) break; | |
| 1076 | } | } |
| 1077 | ||
| 1078 | if (matched_once || allow_zero) | |
| 1079 | { | |
| 1080 | ecode += 1 + LINK_SIZE; | |
| 1081 | break; | |
| 1082 | } | |
| 1083 | RRETURN(MATCH_NOMATCH); | |
| 1084 | ||
| 1085 | /* Control never reaches here. */ | /* Control never reaches here. */ |
| 1086 | ||
| 1087 | /* Conditional group: compilation checked that there are no more than | /* Conditional group: compilation checked that there are no more than |
| 1088 | 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 |
| 1089 | 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 |
| 1090 | exactly what going to the ket would do. As there is only one branch to be | exactly what going to the ket would do. */ |
| obeyed, we can use tail recursion to avoid using another stack frame. */ | ||
| 1091 | ||
| 1092 | case OP_COND: | case OP_COND: |
| 1093 | case OP_SCOND: | case OP_SCOND: |
| 1094 | if (ecode[LINK_SIZE+1] == OP_RREF) /* Recursion test */ | codelink = GET(ecode, 1); |
| 1095 | ||
| 1096 | /* Because of the way auto-callout works during compile, a callout item is | |
| 1097 | inserted between OP_COND and an assertion condition. */ | |
| 1098 | ||
| 1099 | if (ecode[LINK_SIZE+1] == OP_CALLOUT) | |
| 1100 | { | { |
| 1101 | offset = GET2(ecode, LINK_SIZE + 2); /* Recursion group number*/ | if (pcre_callout != NULL) |
| 1102 | condition = md->recursive != NULL && | { |
| 1103 | (offset == RREF_ANY || offset == md->recursive->group_num); | pcre_callout_block cb; |
| 1104 | ecode += condition? 3 : GET(ecode, 1); | cb.version = 1; /* Version 1 of the callout block */ |
| 1105 | cb.callout_number = ecode[LINK_SIZE+2]; | |
| 1106 | cb.offset_vector = md->offset_vector; | |
| 1107 | cb.subject = (PCRE_SPTR)md->start_subject; | |
| 1108 | cb.subject_length = (int)(md->end_subject - md->start_subject); | |
| 1109 | cb.start_match = (int)(mstart - md->start_subject); | |
| 1110 | cb.current_position = (int)(eptr - md->start_subject); | |
| 1111 | cb.pattern_position = GET(ecode, LINK_SIZE + 3); | |
| 1112 | cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE); | |
| 1113 | cb.capture_top = offset_top/2; | |
| 1114 | cb.capture_last = md->capture_last; | |
| 1115 | cb.callout_data = md->callout_data; | |
| 1116 | if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH); | |
| 1117 | if (rrc < 0) RRETURN(rrc); | |
| 1118 | } | |
| 1119 | ecode += _pcre_OP_lengths[OP_CALLOUT]; | |
| 1120 | } | |
| 1121 | ||
| 1122 | condcode = ecode[LINK_SIZE+1]; | |
| 1123 | ||
| 1124 | /* Now see what the actual condition is */ | |
| 1125 | ||
| 1126 | if (condcode == OP_RREF || condcode == OP_NRREF) /* Recursion test */ | |
| 1127 | { | |
| 1128 | if (md->recursive == NULL) /* Not recursing => FALSE */ | |
| 1129 | { | |
| 1130 | condition = FALSE; | |
| 1131 | ecode += GET(ecode, 1); | |
| 1132 | } | |
| 1133 | else | |
| 1134 | { | |
| 1135 | int recno = GET2(ecode, LINK_SIZE + 2); /* Recursion group number*/ | |
| 1136 | condition = (recno == RREF_ANY || recno == md->recursive->group_num); | |
| 1137 | ||
| 1138 | /* If the test is for recursion into a specific subpattern, and it is | |
| 1139 | false, but the test was set up by name, scan the table to see if the | |
| 1140 | name refers to any other numbers, and test them. The condition is true | |
| 1141 | if any one is set. */ | |
| 1142 | ||
| 1143 | if (!condition && condcode == OP_NRREF && recno != RREF_ANY) | |
| 1144 | { | |
| 1145 | uschar *slotA = md->name_table; | |
| 1146 | for (i = 0; i < md->name_count; i++) | |
| 1147 | { | |
| 1148 | if (GET2(slotA, 0) == recno) break; | |
| 1149 | slotA += md->name_entry_size; | |
| 1150 | } | |
| 1151 | ||
| 1152 | /* Found a name for the number - there can be only one; duplicate | |
| 1153 | names for different numbers are allowed, but not vice versa. First | |
| 1154 | scan down for duplicates. */ | |
| 1155 | ||
| 1156 | if (i < md->name_count) | |
| 1157 | { | |
| 1158 | uschar *slotB = slotA; | |
| 1159 | while (slotB > md->name_table) | |
| 1160 | { | |
| 1161 | slotB -= md->name_entry_size; | |
| 1162 | if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0) | |
| 1163 | { | |
| 1164 | condition = GET2(slotB, 0) == md->recursive->group_num; | |
| 1165 | if (condition) break; | |
| 1166 | } | |
| 1167 | else break; | |
| 1168 | } | |
| 1169 | ||
| 1170 | /* Scan up for duplicates */ | |
| 1171 | ||
| 1172 | if (!condition) | |
| 1173 | { | |
| 1174 | slotB = slotA; | |
| 1175 | for (i++; i < md->name_count; i++) | |
| 1176 | { | |
| 1177 | slotB += md->name_entry_size; | |
| 1178 | if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0) | |
| 1179 | { | |
| 1180 | condition = GET2(slotB, 0) == md->recursive->group_num; | |
| 1181 | if (condition) break; | |
| 1182 | } | |
| 1183 | else break; | |
| 1184 | } | |
| 1185 | } | |
| 1186 | } | |
| 1187 | } | |
| 1188 | ||
| 1189 | /* Chose branch according to the condition */ | |
| 1190 | ||
| 1191 | ecode += condition? 3 : GET(ecode, 1); | |
| 1192 | } | |
| 1193 | } | } |
| 1194 | ||
| 1195 | else if (ecode[LINK_SIZE+1] == OP_CREF) /* Group used test */ | else if (condcode == OP_CREF || condcode == OP_NCREF) /* Group used test */ |
| 1196 | { | { |
| 1197 | offset = GET2(ecode, LINK_SIZE+2) << 1; /* Doubled ref number */ | offset = GET2(ecode, LINK_SIZE+2) << 1; /* Doubled ref number */ |
| 1198 | condition = offset < offset_top && md->offset_vector[offset] >= 0; | condition = offset < offset_top && md->offset_vector[offset] >= 0; |
| 1199 | ||
| 1200 | /* If the numbered capture is unset, but the reference was by name, | |
| 1201 | scan the table to see if the name refers to any other numbers, and test | |
| 1202 | them. The condition is true if any one is set. This is tediously similar | |
| 1203 | to the code above, but not close enough to try to amalgamate. */ | |
| 1204 | ||
| 1205 | if (!condition && condcode == OP_NCREF) | |
| 1206 | { | |
| 1207 | int refno = offset >> 1; | |
| 1208 | uschar *slotA = md->name_table; | |
| 1209 | ||
| 1210 | for (i = 0; i < md->name_count; i++) | |
| 1211 | { | |
| 1212 | if (GET2(slotA, 0) == refno) break; | |
| 1213 | slotA += md->name_entry_size; | |
| 1214 | } | |
| 1215 | ||
| 1216 | /* Found a name for the number - there can be only one; duplicate names | |
| 1217 | for different numbers are allowed, but not vice versa. First scan down | |
| 1218 | for duplicates. */ | |
| 1219 | ||
| 1220 | if (i < md->name_count) | |
| 1221 | { | |
| 1222 | uschar *slotB = slotA; | |
| 1223 | while (slotB > md->name_table) | |
| 1224 | { | |
| 1225 | slotB -= md->name_entry_size; | |
| 1226 | if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0) | |
| 1227 | { | |
| 1228 | offset = GET2(slotB, 0) << 1; | |
| 1229 | condition = offset < offset_top && | |
| 1230 | md->offset_vector[offset] >= 0; | |
| 1231 | if (condition) break; | |
| 1232 | } | |
| 1233 | else break; | |
| 1234 | } | |
| 1235 | ||
| 1236 | /* Scan up for duplicates */ | |
| 1237 | ||
| 1238 | if (!condition) | |
| 1239 | { | |
| 1240 | slotB = slotA; | |
| 1241 | for (i++; i < md->name_count; i++) | |
| 1242 | { | |
| 1243 | slotB += md->name_entry_size; | |
| 1244 | if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0) | |
| 1245 | { | |
| 1246 | offset = GET2(slotB, 0) << 1; | |
| 1247 | condition = offset < offset_top && | |
| 1248 | md->offset_vector[offset] >= 0; | |
| 1249 | if (condition) break; | |
| 1250 | } | |
| 1251 | else break; | |
| 1252 | } | |
| 1253 | } | |
| 1254 | } | |
| 1255 | } | |
| 1256 | ||
| 1257 | /* Chose branch according to the condition */ | |
| 1258 | ||
| 1259 | ecode += condition? 3 : GET(ecode, 1); | ecode += condition? 3 : GET(ecode, 1); |
| 1260 | } | } |
| 1261 | ||
| 1262 | else if (ecode[LINK_SIZE+1] == OP_DEF) /* DEFINE - always false */ | else if (condcode == OP_DEF) /* DEFINE - always false */ |
| 1263 | { | { |
| 1264 | condition = FALSE; | condition = FALSE; |
| 1265 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
| 1266 | } | } |
| 1267 | ||
| 1268 | /* The condition is an assertion. Call match() to evaluate it - setting | /* The condition is an assertion. Call match() to evaluate it - setting |
| 1269 | the final argument match_condassert causes it to stop at the end of an | md->match_function_type to MATCH_CONDASSERT causes it to stop at the end of |
| 1270 | assertion. */ | an assertion. */ |
| 1271 | ||
| 1272 | else | else |
| 1273 | { | { |
| 1274 | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, | md->match_function_type = MATCH_CONDASSERT; |
| 1275 | match_condassert, RM3); | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM3); |
| 1276 | if (rrc == MATCH_MATCH) | if (rrc == MATCH_MATCH) |
| 1277 | { | { |
| 1278 | condition = TRUE; | condition = TRUE; |
| 1279 | ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2); | ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2); |
| 1280 | while (*ecode == OP_ALT) ecode += GET(ecode, 1); | while (*ecode == OP_ALT) ecode += GET(ecode, 1); |
| 1281 | } | } |
| 1282 | else if (rrc != MATCH_NOMATCH) | else if (rrc != MATCH_NOMATCH && |
| 1283 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
| 1284 | { | { |
| 1285 | RRETURN(rrc); /* Need braces because of following else */ | RRETURN(rrc); /* Need braces because of following else */ |
| 1286 | } | } |
| 1287 | else | else |
| 1288 | { | { |
| 1289 | condition = FALSE; | condition = FALSE; |
| 1290 | ecode += GET(ecode, 1); | ecode += codelink; |
| 1291 | } | } |
| 1292 | } | } |
| 1293 | ||
| 1294 | /* We are now at the branch that is to be obeyed. As there is only one, | /* We are now at the branch that is to be obeyed. As there is only one, |
| 1295 | we can use tail recursion to avoid using another stack frame, except when | we used to use tail recursion to avoid using another stack frame, except |
| 1296 | match_cbegroup is required for an unlimited repeat of a possibly empty | when there was unlimited repeat of a possibly empty group. However, that |
| 1297 | group. If the second alternative doesn't exist, we can just plough on. */ | strategy no longer works because of the possibilty of (*THEN) being |
| 1298 | encountered in the branch. A recursive call to match() is always required, | |
| 1299 | unless the second alternative doesn't exist, in which case we can just | |
| 1300 | plough on. */ | |
| 1301 | ||
| 1302 | if (condition || *ecode == OP_ALT) | if (condition || *ecode == OP_ALT) |
| 1303 | { | { |
| 1304 | ecode += 1 + LINK_SIZE; | if (op == OP_SCOND) md->match_function_type = MATCH_CBEGROUP; |
| 1305 | if (op == OP_SCOND) /* Possibly empty group */ | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM49); |
| 1306 | { | if (rrc == MATCH_THEN && md->start_match_ptr == ecode) |
| 1307 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49); | rrc = MATCH_NOMATCH; |
| 1308 | RRETURN(rrc); | RRETURN(rrc); |
| } | ||
| else /* Group must match something */ | ||
| { | ||
| flags = 0; | ||
| goto TAIL_RECURSE; | ||
| } | ||
| 1309 | } | } |
| 1310 | else /* Condition false & no 2nd alternative */ | else /* Condition false & no alternative */ |
| 1311 | { | { |
| 1312 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
| 1313 | } | } |
| 1314 | break; | break; |
| 1315 | ||
| 1316 | ||
| 1317 | /* End of the pattern. If we are in a top-level recursion, we should | /* Before OP_ACCEPT there may be any number of OP_CLOSE opcodes, |
| 1318 | restore the offsets appropriately and continue from after the call. */ | to close any currently open capturing brackets. */ |
| 1319 | ||
| 1320 | case OP_CLOSE: | |
| 1321 | number = GET2(ecode, 1); | |
| 1322 | offset = number << 1; | |
| 1323 | ||
| 1324 | #ifdef PCRE_DEBUG | |
| 1325 | printf("end bracket %d at *ACCEPT", number); | |
| 1326 | printf("\n"); | |
| 1327 | #endif | |
| 1328 | ||
| 1329 | md->capture_last = number; | |
| 1330 | if (offset >= md->offset_max) md->offset_overflow = TRUE; else | |
| 1331 | { | |
| 1332 | md->offset_vector[offset] = | |
| 1333 | md->offset_vector[md->offset_end - number]; | |
| 1334 | md->offset_vector[offset+1] = (int)(eptr - md->start_subject); | |
| 1335 | if (offset_top <= offset) offset_top = offset + 2; | |
| 1336 | } | |
| 1337 | ecode += 3; | |
| 1338 | break; | |
| 1339 | ||
| 1340 | ||
| 1341 | /* End of the pattern, either real or forced. If we are in a recursion, we | |
| 1342 | should restore the offsets appropriately, and if it's a top-level | |
| 1343 | recursion, continue from after the call. */ | |
| 1344 | ||
| 1345 | case OP_ACCEPT: | |
| 1346 | case OP_ASSERT_ACCEPT: | |
| 1347 | case OP_END: | case OP_END: |
| 1348 | if (md->recursive != NULL && md->recursive->group_num == 0) | if (md->recursive != NULL) |
| 1349 | { | { |
| 1350 | recursion_info *rec = md->recursive; | recursion_info *rec = md->recursive; |
| DPRINTF(("End of pattern in a (?0) recursion\n")); | ||
| 1351 | md->recursive = rec->prevrec; | md->recursive = rec->prevrec; |
| 1352 | memmove(md->offset_vector, rec->offset_save, | memmove(md->offset_vector, rec->offset_save, |
| 1353 | rec->saved_max * sizeof(int)); | rec->saved_max * sizeof(int)); |
| 1354 | mstart = rec->save_start; | offset_top = rec->save_offset_top; |
| 1355 | ims = original_ims; | if (rec->group_num == 0) |
| 1356 | ecode = rec->after_call; | { |
| 1357 | break; | ecode = rec->after_call; |
| 1358 | break; | |
| 1359 | } | |
| 1360 | } | } |
| 1361 | ||
| 1362 | /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty | /* Otherwise, if we have matched an empty string, fail if not in an |
| 1363 | string - backtracking will then try other alternatives, if any. */ | assertion and if either PCRE_NOTEMPTY is set, or if PCRE_NOTEMPTY_ATSTART |
| 1364 | is set and we have matched at the start of the subject. In both cases, | |
| 1365 | backtracking will then try other alternatives, if any. */ | |
| 1366 | ||
| 1367 | else if (eptr == mstart && op != OP_ASSERT_ACCEPT && | |
| 1368 | (md->notempty || | |
| 1369 | (md->notempty_atstart && | |
| 1370 | mstart == md->start_subject + md->start_offset))) | |
| 1371 | MRRETURN(MATCH_NOMATCH); | |
| 1372 | ||
| 1373 | if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH); | /* Otherwise, we have a match. */ |
| 1374 | ||
| 1375 | md->end_match_ptr = eptr; /* Record where we ended */ | md->end_match_ptr = eptr; /* Record where we ended */ |
| 1376 | md->end_offset_top = offset_top; /* and how many extracts were taken */ | md->end_offset_top = offset_top; /* and how many extracts were taken */ |
| 1377 | md->start_match_ptr = mstart; /* and the start (\K can modify) */ | md->start_match_ptr = mstart; /* and the start (\K can modify) */ |
| RRETURN(MATCH_MATCH); | ||
| 1378 | ||
| 1379 | /* Change option settings */ | /* For some reason, the macros don't work properly if an expression is |
| 1380 | given as the argument to MRRETURN when the heap is in use. */ | |
| 1381 | ||
| 1382 | case OP_OPT: | rrc = (op == OP_END)? MATCH_MATCH : MATCH_ACCEPT; |
| 1383 | ims = ecode[1]; | MRRETURN(rrc); |
| ecode += 2; | ||
| DPRINTF(("ims set to %02lx\n", ims)); | ||
| break; | ||
| 1384 | ||
| 1385 | /* Assertion brackets. Check the alternative branches in turn - the | /* Assertion brackets. Check the alternative branches in turn - the |
| 1386 | matching won't pass the KET for an assertion. If any one branch matches, | matching won't pass the KET for an assertion. If any one branch matches, |
| 1387 | the assertion is true. Lookbehind assertions have an OP_REVERSE item at the | the assertion is true. Lookbehind assertions have an OP_REVERSE item at the |
| 1388 | start of each branch to move the current point backwards, so the code at | start of each branch to move the current point backwards, so the code at |
| 1389 | this level is identical to the lookahead case. */ | this level is identical to the lookahead case. When the assertion is part |
| 1390 | of a condition, we want to return immediately afterwards. The caller of | |
| 1391 | this incarnation of the match() function will have set MATCH_CONDASSERT in | |
| 1392 | md->match_function type, and one of these opcodes will be the first opcode | |
| 1393 | that is processed. We use a local variable that is preserved over calls to | |
| 1394 | match() to remember this case. */ | |
| 1395 | ||
| 1396 | case OP_ASSERT: | case OP_ASSERT: |
| 1397 | case OP_ASSERTBACK: | case OP_ASSERTBACK: |
| 1398 | if (md->match_function_type == MATCH_CONDASSERT) | |
| 1399 | { | |
| 1400 | condassert = TRUE; | |
| 1401 | md->match_function_type = 0; | |
| 1402 | } | |
| 1403 | else condassert = FALSE; | |
| 1404 | ||
| 1405 | do | do |
| 1406 | { | { |
| 1407 | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM4); |
| 1408 | RM4); | if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) |
| 1409 | if (rrc == MATCH_MATCH) break; | { |
| 1410 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | mstart = md->start_match_ptr; /* In case \K reset it */ |
| 1411 | break; | |
| 1412 | } | |
| 1413 | if (rrc != MATCH_NOMATCH && | |
| 1414 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
| 1415 | RRETURN(rrc); | |
| 1416 | ||
| 1417 | /* See explanatory comment above under OP_CBRA. */ | |
| 1418 | ||
| 1419 | if (md->end_offset_top > offset_top) | |
| 1420 | { | |
| 1421 | register int *iptr = md->offset_vector + offset_top; | |
| 1422 | register int *iend = md->offset_vector + md->end_offset_top; | |
| 1423 | while (iptr < iend) *iptr++ = -1; | |
| 1424 | } | |
| 1425 | ||
| 1426 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
| 1427 | } | } |
| 1428 | while (*ecode == OP_ALT); | while (*ecode == OP_ALT); |
| 1429 | if (*ecode == OP_KET) RRETURN(MATCH_NOMATCH); | |
| 1430 | if (*ecode == OP_KET) MRRETURN(MATCH_NOMATCH); | |
| 1431 | ||
| 1432 | /* If checking an assertion for a condition, return MATCH_MATCH. */ | /* If checking an assertion for a condition, return MATCH_MATCH. */ |
| 1433 | ||
| 1434 | if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH); | if (condassert) RRETURN(MATCH_MATCH); |
| 1435 | ||
| 1436 | /* Continue from after the assertion, updating the offsets high water | /* Continue from after the assertion, updating the offsets high water |
| 1437 | mark, since extracts may have been taken during the assertion. */ | mark, since extracts may have been taken during the assertion. */ |
| # | Line 862 for (;;) | Line 1441 for (;;) |
| 1441 | offset_top = md->end_offset_top; | offset_top = md->end_offset_top; |
| 1442 | continue; | continue; |
| 1443 | ||
| 1444 | /* Negative assertion: all branches must fail to match */ | /* Negative assertion: all branches must fail to match. Encountering SKIP, |
| 1445 | PRUNE, or COMMIT means we must assume failure without checking subsequent | |
| 1446 | branches. */ | |
| 1447 | ||
| 1448 | case OP_ASSERT_NOT: | case OP_ASSERT_NOT: |
| 1449 | case OP_ASSERTBACK_NOT: | case OP_ASSERTBACK_NOT: |
| 1450 | if (md->match_function_type == MATCH_CONDASSERT) | |
| 1451 | { | |
| 1452 | condassert = TRUE; | |
| 1453 | md->match_function_type = 0; | |
| 1454 | } | |
| 1455 | else condassert = FALSE; | |
| 1456 | ||
| 1457 | do | do |
| 1458 | { | { |
| 1459 | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5); |
| 1460 | RM5); | if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) MRRETURN(MATCH_NOMATCH); |
| 1461 | if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH); | if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT) |
| 1462 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | { |
| 1463 | do ecode += GET(ecode,1); while (*ecode == OP_ALT); | |
| 1464 | break; | |
| 1465 | } | |
| 1466 | if (rrc != MATCH_NOMATCH && | |
| 1467 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
| 1468 | RRETURN(rrc); | |
| 1469 | ecode += GET(ecode,1); | ecode += GET(ecode,1); |
| 1470 | } | } |
| 1471 | while (*ecode == OP_ALT); | while (*ecode == OP_ALT); |
| 1472 | ||
| 1473 | if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH); | if (condassert) RRETURN(MATCH_MATCH); /* Condition assertion */ |
| 1474 | ||
| 1475 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
| 1476 | continue; | continue; |
| 1477 | ||
| # | Line 894 for (;;) | Line 1488 for (;;) |
| 1488 | while (i-- > 0) | while (i-- > 0) |
| 1489 | { | { |
| 1490 | eptr--; | eptr--; |
| 1491 | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); | if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH); |
| 1492 | BACKCHAR(eptr) | BACKCHAR(eptr); |
| 1493 | } | } |
| 1494 | } | } |
| 1495 | else | else |
| # | Line 905 for (;;) | Line 1499 for (;;) |
| 1499 | ||
| 1500 | { | { |
| 1501 | eptr -= GET(ecode, 1); | eptr -= GET(ecode, 1); |
| 1502 | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); | if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH); |
| 1503 | } | } |
| 1504 | ||
| 1505 | /* Skip to next op code */ | /* Save the earliest consulted character, then skip to next op code */ |
| 1506 | ||
| 1507 | if (eptr < md->start_used_ptr) md->start_used_ptr = eptr; | |
| 1508 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
| 1509 | break; | break; |
| 1510 | ||
| # | Line 925 for (;;) | Line 1520 for (;;) |
| 1520 | cb.callout_number = ecode[1]; | cb.callout_number = ecode[1]; |
| 1521 | cb.offset_vector = md->offset_vector; | cb.offset_vector = md->offset_vector; |
| 1522 | cb.subject = (PCRE_SPTR)md->start_subject; | cb.subject = (PCRE_SPTR)md->start_subject; |
| 1523 | cb.subject_length = md->end_subject - md->start_subject; | cb.subject_length = (int)(md->end_subject - md->start_subject); |
| 1524 | cb.start_match = mstart - md->start_subject; | cb.start_match = (int)(mstart - md->start_subject); |
| 1525 | cb.current_position = eptr - md->start_subject; | cb.current_position = (int)(eptr - md->start_subject); |
| 1526 | cb.pattern_position = GET(ecode, 2); | cb.pattern_position = GET(ecode, 2); |
| 1527 | cb.next_item_length = GET(ecode, 2 + LINK_SIZE); | cb.next_item_length = GET(ecode, 2 + LINK_SIZE); |
| 1528 | cb.capture_top = offset_top/2; | cb.capture_top = offset_top/2; |
| 1529 | cb.capture_last = md->capture_last; | cb.capture_last = md->capture_last; |
| 1530 | cb.callout_data = md->callout_data; | cb.callout_data = md->callout_data; |
| 1531 | if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH); | if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH); |
| 1532 | if (rrc < 0) RRETURN(rrc); | if (rrc < 0) RRETURN(rrc); |
| 1533 | } | } |
| 1534 | ecode += 2 + 2*LINK_SIZE; | ecode += 2 + 2*LINK_SIZE; |
| # | Line 988 for (;;) | Line 1583 for (;;) |
| 1583 | ||
| 1584 | memcpy(new_recursive.offset_save, md->offset_vector, | memcpy(new_recursive.offset_save, md->offset_vector, |
| 1585 | new_recursive.saved_max * sizeof(int)); | new_recursive.saved_max * sizeof(int)); |
| 1586 | new_recursive.save_start = mstart; | new_recursive.save_offset_top = offset_top; |
| 1587 | mstart = eptr; | |
| 1588 | /* OK, now we can do the recursion. For each top-level alternative we | /* OK, now we can do the recursion. For each top-level alternative we |
| 1589 | restore the offset and recursion data. */ | restore the offset and recursion data. */ |
| 1590 | ||
| 1591 | DPRINTF(("Recursing into group %d\n", new_recursive.group_num)); | DPRINTF(("Recursing into group %d\n", new_recursive.group_num)); |
| 1592 | flags = (*callpat >= OP_SBRA)? match_cbegroup : 0; | cbegroup = (*callpat >= OP_SBRA); |
| 1593 | do | do |
| 1594 | { | { |
| 1595 | if (cbegroup) md->match_function_type = MATCH_CBEGROUP; | |
| 1596 | RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top, | RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top, |
| 1597 | md, ims, eptrb, flags, RM6); | md, eptrb, RM6); |
| 1598 | if (rrc == MATCH_MATCH) | if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) |
| 1599 | { | { |
| 1600 | DPRINTF(("Recursion matched\n")); | DPRINTF(("Recursion matched\n")); |
| 1601 | md->recursive = new_recursive.prevrec; | md->recursive = new_recursive.prevrec; |
| 1602 | if (new_recursive.offset_save != stacksave) | if (new_recursive.offset_save != stacksave) |
| 1603 | (pcre_free)(new_recursive.offset_save); | (pcre_free)(new_recursive.offset_save); |
| 1604 | RRETURN(MATCH_MATCH); | MRRETURN(MATCH_MATCH); |
| 1605 | } | } |
| 1606 | else if (rrc != MATCH_NOMATCH) | else if (rrc != MATCH_NOMATCH && |
| 1607 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
| 1608 | { | { |
| 1609 | DPRINTF(("Recursion gave error %d\n", rrc)); | DPRINTF(("Recursion gave error %d\n", rrc)); |
| 1610 | if (new_recursive.offset_save != stacksave) | |
| 1611 | (pcre_free)(new_recursive.offset_save); | |
| 1612 | RRETURN(rrc); | RRETURN(rrc); |
| 1613 | } | } |
| 1614 | ||
| # | Line 1025 for (;;) | Line 1623 for (;;) |
| 1623 | md->recursive = new_recursive.prevrec; | md->recursive = new_recursive.prevrec; |
| 1624 | if (new_recursive.offset_save != stacksave) | if (new_recursive.offset_save != stacksave) |
| 1625 | (pcre_free)(new_recursive.offset_save); | (pcre_free)(new_recursive.offset_save); |
| 1626 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 1627 | } | } |
| 1628 | /* Control never reaches here */ | /* Control never reaches here */ |
| 1629 | ||
| # | Line 1034 for (;;) | Line 1632 for (;;) |
| 1632 | a move back into the brackets. Friedl calls these "atomic" subpatterns. | a move back into the brackets. Friedl calls these "atomic" subpatterns. |
| 1633 | Check the alternative branches in turn - the matching won't pass the KET | Check the alternative branches in turn - the matching won't pass the KET |
| 1634 | for this kind of subpattern. If any one branch matches, we carry on as at | for this kind of subpattern. If any one branch matches, we carry on as at |
| 1635 | the end of a normal bracket, leaving the subject pointer. */ | the end of a normal bracket, leaving the subject pointer, but resetting |
| 1636 | the start-of-match value in case it was changed by \K. */ | |
| 1637 | ||
| 1638 | case OP_ONCE: | case OP_ONCE: |
| 1639 | prev = ecode; | prev = ecode; |
| # | Line 1042 for (;;) | Line 1641 for (;;) |
| 1641 | ||
| 1642 | do | do |
| 1643 | { | { |
| 1644 | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7); | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM7); |
| 1645 | if (rrc == MATCH_MATCH) break; | if (rrc == MATCH_MATCH) /* Note: _not_ MATCH_ACCEPT */ |
| 1646 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | { |
| 1647 | mstart = md->start_match_ptr; | |
| 1648 | break; | |
| 1649 | } | |
| 1650 | if (rrc != MATCH_NOMATCH && | |
| 1651 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
| 1652 | RRETURN(rrc); | |
| 1653 | ||
| 1654 | /* See explanatory comment above under OP_CBRA. */ | |
| 1655 | ||
| 1656 | if (md->end_offset_top > offset_top) | |
| 1657 | { | |
| 1658 | register int *iptr = md->offset_vector + offset_top; | |
| 1659 | register int *iend = md->offset_vector + md->end_offset_top; | |
| 1660 | while (iptr < iend) *iptr++ = -1; | |
| 1661 | } | |
| 1662 | ||
| 1663 | ecode += GET(ecode,1); | ecode += GET(ecode,1); |
| 1664 | } | } |
| 1665 | while (*ecode == OP_ALT); | while (*ecode == OP_ALT); |
| # | Line 1053 for (;;) | Line 1668 for (;;) |
| 1668 | ||
| 1669 | if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH); | if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH); |
| 1670 | ||
| 1671 | /* Continue as from after the assertion, updating the offsets high water | /* Continue after the group, updating the offsets high water mark, since |
| 1672 | mark, since extracts may have been taken. */ | extracts may have been taken. */ |
| 1673 | ||
| 1674 | do ecode += GET(ecode, 1); while (*ecode == OP_ALT); | do ecode += GET(ecode, 1); while (*ecode == OP_ALT); |
| 1675 | ||
| # | Line 1075 for (;;) | Line 1690 for (;;) |
| 1690 | ||
| 1691 | /* 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 |
| 1692 | preceding bracket, in the appropriate order. The second "call" of match() | preceding bracket, in the appropriate order. The second "call" of match() |
| 1693 | uses tail recursion, to avoid using another stack frame. We need to reset | uses tail recursion, to avoid using another stack frame. */ |
| any options that changed within the bracket before re-running it, so | ||
| check the next opcode. */ | ||
| if (ecode[1+LINK_SIZE] == OP_OPT) | ||
| { | ||
| ims = (ims & ~PCRE_IMS) | ecode[4]; | ||
| DPRINTF(("ims set to %02lx at group repeat\n", ims)); | ||
| } | ||
| 1694 | ||
| 1695 | if (*ecode == OP_KETRMIN) | if (*ecode == OP_KETRMIN) |
| 1696 | { | { |
| 1697 | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8); | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM8); |
| 1698 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1699 | ecode = prev; | ecode = prev; |
| flags = 0; | ||
| 1700 | goto TAIL_RECURSE; | goto TAIL_RECURSE; |
| 1701 | } | } |
| 1702 | else /* OP_KETRMAX */ | else /* OP_KETRMAX */ |
| 1703 | { | { |
| 1704 | RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9); | md->match_function_type = MATCH_CBEGROUP; |
| 1705 | RMATCH(eptr, prev, offset_top, md, eptrb, RM9); | |
| 1706 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1707 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
| flags = 0; | ||
| 1708 | goto TAIL_RECURSE; | goto TAIL_RECURSE; |
| 1709 | } | } |
| 1710 | /* Control never gets here */ | /* Control never gets here */ |
| # | Line 1110 for (;;) | Line 1716 for (;;) |
| 1716 | do ecode += GET(ecode,1); while (*ecode == OP_ALT); | do ecode += GET(ecode,1); while (*ecode == OP_ALT); |
| 1717 | break; | break; |
| 1718 | ||
| 1719 | /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating | /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group, |
| 1720 | that it may occur zero times. It may repeat infinitely, or not at all - | indicating that it may occur zero times. It may repeat infinitely, or not |
| 1721 | i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper | at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets |
| 1722 | repeat limits are compiled as a number of copies, with the optional ones | with fixed upper repeat limits are compiled as a number of copies, with the |
| 1723 | preceded by BRAZERO or BRAMINZERO. */ | optional ones preceded by BRAZERO or BRAMINZERO. */ |
| 1724 | ||
| 1725 | case OP_BRAZERO: | case OP_BRAZERO: |
| 1726 | { | next = ecode + 1; |
| 1727 | next = ecode+1; | RMATCH(eptr, next, offset_top, md, eptrb, RM10); |
| 1728 | RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1729 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | do next += GET(next, 1); while (*next == OP_ALT); |
| 1730 | do next += GET(next,1); while (*next == OP_ALT); | ecode = next + 1 + LINK_SIZE; |
| ecode = next + 1 + LINK_SIZE; | ||
| } | ||
| 1731 | break; | break; |
| 1732 | ||
| 1733 | case OP_BRAMINZERO: | case OP_BRAMINZERO: |
| 1734 | { | next = ecode + 1; |
| 1735 | next = ecode+1; | do next += GET(next, 1); while (*next == OP_ALT); |
| 1736 | do next += GET(next, 1); while (*next == OP_ALT); | RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, eptrb, RM11); |
| 1737 | RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1738 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | ecode++; |
| ecode++; | ||
| } | ||
| 1739 | break; | break; |
| 1740 | ||
| 1741 | case OP_SKIPZERO: | |
| 1742 | next = ecode+1; | |
| 1743 | do next += GET(next,1); while (*next == OP_ALT); | |
| 1744 | ecode = next + 1 + LINK_SIZE; | |
| 1745 | break; | |
| 1746 | ||
| 1747 | /* BRAPOSZERO occurs before a possessive bracket group. Don't do anything | |
| 1748 | here; just jump to the group, with allow_zero set TRUE. */ | |
| 1749 | ||
| 1750 | case OP_BRAPOSZERO: | |
| 1751 | op = *(++ecode); | |
| 1752 | allow_zero = TRUE; | |
| 1753 | if (op == OP_CBRAPOS || op == OP_SCBRAPOS) goto POSSESSIVE_CAPTURE; | |
| 1754 | goto POSSESSIVE_NON_CAPTURE; | |
| 1755 | ||
| 1756 | /* End of a group, repeated or non-repeating. */ | /* End of a group, repeated or non-repeating. */ |
| 1757 | ||
| 1758 | case OP_KET: | case OP_KET: |
| 1759 | case OP_KETRMIN: | case OP_KETRMIN: |
| 1760 | case OP_KETRMAX: | case OP_KETRMAX: |
| 1761 | case OP_KETRPOS: | |
| 1762 | prev = ecode - GET(ecode, 1); | prev = ecode - GET(ecode, 1); |
| 1763 | ||
| 1764 | /* If this was a group that remembered the subject start, in order to break | /* If this was a group that remembered the subject start, in order to break |
| # | Line 1154 for (;;) | Line 1772 for (;;) |
| 1772 | } | } |
| 1773 | else saved_eptr = NULL; | else saved_eptr = NULL; |
| 1774 | ||
| 1775 | /* If we are at the end of an assertion group, stop matching and return | /* If we are at the end of an assertion group or an atomic group, stop |
| 1776 | MATCH_MATCH, but record the current high water mark for use by positive | matching and return MATCH_MATCH, but record the current high water mark for |
| 1777 | assertions. Do this also for the "once" (atomic) groups. */ | use by positive assertions. We also need to record the match start in case |
| 1778 | it was changed by \K. */ | |
| 1779 | ||
| 1780 | if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || | if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || |
| 1781 | *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT || | *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT || |
| # | Line 1164 for (;;) | Line 1783 for (;;) |
| 1783 | { | { |
| 1784 | md->end_match_ptr = eptr; /* For ONCE */ | md->end_match_ptr = eptr; /* For ONCE */ |
| 1785 | md->end_offset_top = offset_top; | md->end_offset_top = offset_top; |
| 1786 | RRETURN(MATCH_MATCH); | md->start_match_ptr = mstart; |
| 1787 | MRRETURN(MATCH_MATCH); | |
| 1788 | } | } |
| 1789 | ||
| 1790 | /* For capturing groups we have to check the group number back at the start | /* For capturing groups we have to check the group number back at the start |
| # | Line 1173 for (;;) | Line 1793 for (;;) |
| 1793 | a recurse into group 0, so it won't be picked up here. Instead, we catch it | a recurse into group 0, so it won't be picked up here. Instead, we catch it |
| 1794 | when the OP_END is reached. Other recursion is handled here. */ | when the OP_END is reached. Other recursion is handled here. */ |
| 1795 | ||
| 1796 | if (*prev == OP_CBRA || *prev == OP_SCBRA) | if (*prev == OP_CBRA || *prev == OP_SCBRA || |
| 1797 | *prev == OP_CBRAPOS || *prev == OP_SCBRAPOS) | |
| 1798 | { | { |
| 1799 | number = GET2(prev, 1+LINK_SIZE); | number = GET2(prev, 1+LINK_SIZE); |
| 1800 | offset = number << 1; | offset = number << 1; |
| 1801 | ||
| 1802 | #ifdef DEBUG | #ifdef PCRE_DEBUG |
| 1803 | printf("end bracket %d", number); | printf("end bracket %d", number); |
| 1804 | printf("\n"); | printf("\n"); |
| 1805 | #endif | #endif |
| # | Line 1188 for (;;) | Line 1809 for (;;) |
| 1809 | { | { |
| 1810 | md->offset_vector[offset] = | md->offset_vector[offset] = |
| 1811 | md->offset_vector[md->offset_end - number]; | md->offset_vector[md->offset_end - number]; |
| 1812 | md->offset_vector[offset+1] = eptr - md->start_subject; | md->offset_vector[offset+1] = (int)(eptr - md->start_subject); |
| 1813 | if (offset_top <= offset) offset_top = offset + 2; | if (offset_top <= offset) offset_top = offset + 2; |
| 1814 | } | } |
| 1815 | ||
| # | Line 1200 for (;;) | Line 1821 for (;;) |
| 1821 | recursion_info *rec = md->recursive; | recursion_info *rec = md->recursive; |
| 1822 | DPRINTF(("Recursion (%d) succeeded - continuing\n", number)); | DPRINTF(("Recursion (%d) succeeded - continuing\n", number)); |
| 1823 | md->recursive = rec->prevrec; | md->recursive = rec->prevrec; |
| mstart = rec->save_start; | ||
| 1824 | memcpy(md->offset_vector, rec->offset_save, | memcpy(md->offset_vector, rec->offset_save, |
| 1825 | rec->saved_max * sizeof(int)); | rec->saved_max * sizeof(int)); |
| 1826 | offset_top = rec->save_offset_top; | |
| 1827 | ecode = rec->after_call; | ecode = rec->after_call; |
| ims = original_ims; | ||
| 1828 | break; | break; |
| 1829 | } | } |
| 1830 | } | } |
| 1831 | ||
| /* For both capturing and non-capturing groups, reset the value of the ims | ||
| flags, in case they got changed during the group. */ | ||
| ims = original_ims; | ||
| DPRINTF(("ims reset to %02lx\n", ims)); | ||
| 1832 | /* For a non-repeating ket, just continue at this level. This also | /* For a non-repeating ket, just continue at this level. This also |
| 1833 | 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. |
| 1834 | This is the forcible breaking of infinite loops as implemented in Perl | This is the forcible breaking of infinite loops as implemented in Perl |
| # | Line 1226 for (;;) | Line 1840 for (;;) |
| 1840 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
| 1841 | break; | break; |
| 1842 | } | } |
| 1843 | ||
| 1844 | /* The repeating kets try the rest of the pattern or restart from the | /* OP_KETRPOS is a possessive repeating ket. Remember the current position, |
| 1845 | preceding bracket, in the appropriate order. In the second case, we can use | and return the MATCH_KETRPOS. This makes it possible to do the repeats one |
| 1846 | tail recursion to avoid using another stack frame, unless we have an | at a time from the outer level, thus saving stack. */ |
| 1847 | ||
| 1848 | if (*ecode == OP_KETRPOS) | |
| 1849 | { | |
| 1850 | md->end_match_ptr = eptr; | |
| 1851 | md->end_offset_top = offset_top; | |
| 1852 | RRETURN(MATCH_KETRPOS); | |
| 1853 | } | |
| 1854 | ||
| 1855 | /* The normal repeating kets try the rest of the pattern or restart from | |
| 1856 | the preceding bracket, in the appropriate order. In the second case, we can | |
| 1857 | use tail recursion to avoid using another stack frame, unless we have an | |
| 1858 | unlimited repeat of a group that can match an empty string. */ | unlimited repeat of a group that can match an empty string. */ |
| 1859 | ||
| flags = (*prev >= OP_SBRA)? match_cbegroup : 0; | ||
| 1860 | if (*ecode == OP_KETRMIN) | if (*ecode == OP_KETRMIN) |
| 1861 | { | { |
| 1862 | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12); | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM12); |
| 1863 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1864 | if (flags != 0) /* Could match an empty string */ | if (*prev >= OP_SBRA) /* Could match an empty string */ |
| 1865 | { | { |
| 1866 | RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50); | md->match_function_type = MATCH_CBEGROUP; |
| 1867 | RMATCH(eptr, prev, offset_top, md, eptrb, RM50); | |
| 1868 | RRETURN(rrc); | RRETURN(rrc); |
| 1869 | } | } |
| 1870 | ecode = prev; | ecode = prev; |
| # | Line 1248 for (;;) | Line 1872 for (;;) |
| 1872 | } | } |
| 1873 | else /* OP_KETRMAX */ | else /* OP_KETRMAX */ |
| 1874 | { | { |
| 1875 | RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13); | if (*prev >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP; |
| 1876 | RMATCH(eptr, prev, offset_top, md, eptrb, RM13); | |
| 1877 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1878 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
| flags = 0; | ||
| 1879 | goto TAIL_RECURSE; | goto TAIL_RECURSE; |
| 1880 | } | } |
| 1881 | /* Control never gets here */ | /* Control never gets here */ |
| 1882 | ||
| 1883 | /* Start of subject unless notbol, or after internal newline if multiline */ | /* Not multiline mode: start of subject assertion, unless notbol. */ |
| 1884 | ||
| 1885 | case OP_CIRC: | case OP_CIRC: |
| 1886 | if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH); | if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH); |
| 1887 | if ((ims & PCRE_MULTILINE) != 0) | |
| { | ||
| if (eptr != md->start_subject && | ||
| (eptr == md->end_subject || !WAS_NEWLINE(eptr))) | ||
| RRETURN(MATCH_NOMATCH); | ||
| ecode++; | ||
| break; | ||
| } | ||
| /* ... else fall through */ | ||
| 1888 | /* Start of subject assertion */ | /* Start of subject assertion */ |
| 1889 | ||
| 1890 | case OP_SOD: | case OP_SOD: |
| 1891 | if (eptr != md->start_subject) RRETURN(MATCH_NOMATCH); | if (eptr != md->start_subject) MRRETURN(MATCH_NOMATCH); |
| 1892 | ecode++; | |
| 1893 | break; | |
| 1894 | ||
| 1895 | /* Multiline mode: start of subject unless notbol, or after any newline. */ | |
| 1896 | ||
| 1897 | case OP_CIRCM: | |
| 1898 | if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH); | |
| 1899 | if (eptr != md->start_subject && | |
| 1900 | (eptr == md->end_subject || !WAS_NEWLINE(eptr))) | |
| 1901 | MRRETURN(MATCH_NOMATCH); | |
| 1902 | ecode++; | ecode++; |
| 1903 | break; | break; |
| 1904 | ||
| 1905 | /* Start of match assertion */ | /* Start of match assertion */ |
| 1906 | ||
| 1907 | case OP_SOM: | case OP_SOM: |
| 1908 | if (eptr != md->start_subject + md->start_offset) RRETURN(MATCH_NOMATCH); | if (eptr != md->start_subject + md->start_offset) MRRETURN(MATCH_NOMATCH); |
| 1909 | ecode++; | ecode++; |
| 1910 | break; | break; |
| 1911 | ||
| # | Line 1291 for (;;) | Line 1916 for (;;) |
| 1916 | ecode++; | ecode++; |
| 1917 | break; | break; |
| 1918 | ||
| 1919 | /* Assert before internal newline if multiline, or before a terminating | /* Multiline mode: assert before any newline, or before end of subject |
| 1920 | newline unless endonly is set, else end of subject unless noteol is set. */ | unless noteol is set. */ |
| 1921 | ||
| 1922 | case OP_DOLL: | case OP_DOLLM: |
| 1923 | if ((ims & PCRE_MULTILINE) != 0) | if (eptr < md->end_subject) |
| 1924 | { if (!IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH); } | |
| 1925 | else | |
| 1926 | { | { |
| 1927 | if (eptr < md->end_subject) | if (md->noteol) MRRETURN(MATCH_NOMATCH); |
| 1928 | { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); } | SCHECK_PARTIAL(); |
| else | ||
| { if (md->noteol) RRETURN(MATCH_NOMATCH); } | ||
| ecode++; | ||
| break; | ||
| } | ||
| else | ||
| { | ||
| if (md->noteol) RRETURN(MATCH_NOMATCH); | ||
| if (!md->endonly) | ||
| { | ||
| if (eptr != md->end_subject && | ||
| (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen)) | ||
| RRETURN(MATCH_NOMATCH); | ||
| ecode++; | ||
| break; | ||
| } | ||
| 1929 | } | } |
| 1930 | ecode++; | |
| 1931 | break; | |
| 1932 | ||
| 1933 | /* Not multiline mode: assert before a terminating newline or before end of | |
| 1934 | subject unless noteol is set. */ | |
| 1935 | ||
| 1936 | case OP_DOLL: | |
| 1937 | if (md->noteol) MRRETURN(MATCH_NOMATCH); | |
| 1938 | if (!md->endonly) goto ASSERT_NL_OR_EOS; | |
| 1939 | ||
| 1940 | /* ... else fall through for endonly */ | /* ... else fall through for endonly */ |
| 1941 | ||
| 1942 | /* End of subject assertion (\z) */ | /* End of subject assertion (\z) */ |
| 1943 | ||
| 1944 | case OP_EOD: | case OP_EOD: |
| 1945 | if (eptr < md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr < md->end_subject) MRRETURN(MATCH_NOMATCH); |
| 1946 | SCHECK_PARTIAL(); | |
| 1947 | ecode++; | ecode++; |
| 1948 | break; | break; |
| 1949 | ||
| 1950 | /* End of subject or ending \n assertion (\Z) */ | /* End of subject or ending \n assertion (\Z) */ |
| 1951 | ||
| 1952 | case OP_EODN: | case OP_EODN: |
| 1953 | if (eptr != md->end_subject && | ASSERT_NL_OR_EOS: |
| 1954 | if (eptr < md->end_subject && | |
| 1955 | (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen)) | (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen)) |
| 1956 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 1957 | ||
| 1958 | /* Either at end of string or \n before end. */ | |
| 1959 | ||
| 1960 | SCHECK_PARTIAL(); | |
| 1961 | ecode++; | ecode++; |
| 1962 | break; | break; |
| 1963 | ||
| # | Line 1342 for (;;) | Line 1969 for (;;) |
| 1969 | ||
| 1970 | /* Find out if the previous and current characters are "word" characters. | /* Find out if the previous and current characters are "word" characters. |
| 1971 | It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to | It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to |
| 1972 | be "non-word" characters. */ | be "non-word" characters. Remember the earliest consulted character for |
| 1973 | partial matching. */ | |
| 1974 | ||
| 1975 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| 1976 | if (utf8) | if (utf8) |
| 1977 | { | { |
| 1978 | /* Get status of previous character */ | |
| 1979 | ||
| 1980 | if (eptr == md->start_subject) prev_is_word = FALSE; else | if (eptr == md->start_subject) prev_is_word = FALSE; else |
| 1981 | { | { |
| 1982 | const uschar *lastptr = eptr - 1; | USPTR lastptr = eptr - 1; |
| 1983 | while((*lastptr & 0xc0) == 0x80) lastptr--; | while((*lastptr & 0xc0) == 0x80) lastptr--; |
| 1984 | if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr; | |
| 1985 | GETCHAR(c, lastptr); | GETCHAR(c, lastptr); |
| 1986 | #ifdef SUPPORT_UCP | |
| 1987 | if (md->use_ucp) | |
| 1988 | { | |
| 1989 | if (c == '_') prev_is_word = TRUE; else | |
| 1990 | { | |
| 1991 | int cat = UCD_CATEGORY(c); | |
| 1992 | prev_is_word = (cat == ucp_L || cat == ucp_N); | |
| 1993 | } | |
| 1994 | } | |
| 1995 | else | |
| 1996 | #endif | |
| 1997 | prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; | prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; |
| 1998 | } | } |
| 1999 | if (eptr >= md->end_subject) cur_is_word = FALSE; else | |
| 2000 | /* Get status of next character */ | |
| 2001 | ||
| 2002 | if (eptr >= md->end_subject) | |
| 2003 | { | |
| 2004 | SCHECK_PARTIAL(); | |
| 2005 | cur_is_word = FALSE; | |
| 2006 | } | |
| 2007 | else | |
| 2008 | { | { |
| 2009 | GETCHAR(c, eptr); | GETCHAR(c, eptr); |
| 2010 | #ifdef SUPPORT_UCP | |
| 2011 | if (md->use_ucp) | |
| 2012 | { | |
| 2013 | if (c == '_') cur_is_word = TRUE; else | |
| 2014 | { | |
| 2015 | int cat = UCD_CATEGORY(c); | |
| 2016 | cur_is_word = (cat == ucp_L || cat == ucp_N); | |
| 2017 | } | |
| 2018 | } | |
| 2019 | else | |
| 2020 | #endif | |
| 2021 | cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; | cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; |
| 2022 | } | } |
| 2023 | } | } |
| 2024 | else | else |
| 2025 | #endif | #endif |
| 2026 | ||
| 2027 | /* More streamlined when not in UTF-8 mode */ | /* Not in UTF-8 mode, but we may still have PCRE_UCP set, and for |
| 2028 | consistency with the behaviour of \w we do use it in this case. */ | |
| 2029 | ||
| 2030 | { | { |
| 2031 | prev_is_word = (eptr != md->start_subject) && | /* Get status of previous character */ |
| 2032 | ((md->ctypes[eptr[-1]] & ctype_word) != 0); | |
| 2033 | cur_is_word = (eptr < md->end_subject) && | if (eptr == md->start_subject) prev_is_word = FALSE; else |
| 2034 | ((md->ctypes[*eptr] & ctype_word) != 0); | { |
| 2035 | if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1; | |
| 2036 | #ifdef SUPPORT_UCP | |
| 2037 | if (md->use_ucp) | |
| 2038 | { | |
| 2039 | c = eptr[-1]; | |
| 2040 | if (c == '_') prev_is_word = TRUE; else | |
| 2041 | { | |
| 2042 | int cat = UCD_CATEGORY(c); | |
| 2043 | prev_is_word = (cat == ucp_L || cat == ucp_N); | |
| 2044 | } | |
| 2045 | } | |
| 2046 | else | |
| 2047 | #endif | |
| 2048 | prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0); | |
| 2049 | } | |
| 2050 | ||
| 2051 | /* Get status of next character */ | |
| 2052 | ||
| 2053 | if (eptr >= md->end_subject) | |
| 2054 | { | |
| 2055 | SCHECK_PARTIAL(); | |
| 2056 | cur_is_word = FALSE; | |
| 2057 | } | |
| 2058 | else | |
| 2059 | #ifdef SUPPORT_UCP | |
| 2060 | if (md->use_ucp) | |
| 2061 | { | |
| 2062 | c = *eptr; | |
| 2063 | if (c == '_') cur_is_word = TRUE; else | |
| 2064 | { | |
| 2065 | int cat = UCD_CATEGORY(c); | |
| 2066 | cur_is_word = (cat == ucp_L || cat == ucp_N); | |
| 2067 | } | |
| 2068 | } | |
| 2069 | else | |
| 2070 | #endif | |
| 2071 | cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0); | |
| 2072 | } | } |
| 2073 | ||
| 2074 | /* Now see if the situation is what we want */ | /* Now see if the situation is what we want */ |
| 2075 | ||
| 2076 | if ((*ecode++ == OP_WORD_BOUNDARY)? | if ((*ecode++ == OP_WORD_BOUNDARY)? |
| 2077 | cur_is_word == prev_is_word : cur_is_word != prev_is_word) | cur_is_word == prev_is_word : cur_is_word != prev_is_word) |
| 2078 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 2079 | } | } |
| 2080 | break; | break; |
| 2081 | ||
| 2082 | /* Match a single character type; inline for speed */ | /* Match a single character type; inline for speed */ |
| 2083 | ||
| 2084 | case OP_ANY: | case OP_ANY: |
| 2085 | if ((ims & PCRE_DOTALL) == 0) | if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH); |
| 2086 | /* Fall through */ | |
| 2087 | ||
| 2088 | case OP_ALLANY: | |
| 2089 | if (eptr++ >= md->end_subject) | |
| 2090 | { | { |
| 2091 | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); | SCHECK_PARTIAL(); |
| 2092 | MRRETURN(MATCH_NOMATCH); | |
| 2093 | } | } |
| 2094 | if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
| if (utf8) | ||
| while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | ||
| 2095 | ecode++; | ecode++; |
| 2096 | break; | break; |
| 2097 | ||
| # | Line 1397 for (;;) | Line 2099 for (;;) |
| 2099 | any byte, even newline, independent of the setting of PCRE_DOTALL. */ | any byte, even newline, independent of the setting of PCRE_DOTALL. */ |
| 2100 | ||
| 2101 | case OP_ANYBYTE: | case OP_ANYBYTE: |
| 2102 | if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr++ >= md->end_subject) |
| 2103 | { | |
| 2104 | SCHECK_PARTIAL(); | |
| 2105 | MRRETURN(MATCH_NOMATCH); | |
| 2106 | } | |
| 2107 | ecode++; | ecode++; |
| 2108 | break; | break; |
| 2109 | ||
| 2110 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| 2111 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2112 | { | |
| 2113 | SCHECK_PARTIAL(); | |
| 2114 | MRRETURN(MATCH_NOMATCH); | |
| 2115 | } | |
| 2116 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2117 | if ( | if ( |
| 2118 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1410 for (;;) | Line 2120 for (;;) |
| 2120 | #endif | #endif |
| 2121 | (md->ctypes[c] & ctype_digit) != 0 | (md->ctypes[c] & ctype_digit) != 0 |
| 2122 | ) | ) |
| 2123 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 2124 | ecode++; | ecode++; |
| 2125 | break; | break; |
| 2126 | ||
| 2127 | case OP_DIGIT: | case OP_DIGIT: |
| 2128 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2129 | { | |
| 2130 | SCHECK_PARTIAL(); | |
| 2131 | MRRETURN(MATCH_NOMATCH); | |
| 2132 | } | |
| 2133 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2134 | if ( | if ( |
| 2135 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1423 for (;;) | Line 2137 for (;;) |
| 2137 | #endif | #endif |
| 2138 | (md->ctypes[c] & ctype_digit) == 0 | (md->ctypes[c] & ctype_digit) == 0 |
| 2139 | ) | ) |
| 2140 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 2141 | ecode++; | ecode++; |
| 2142 | break; | break; |
| 2143 | ||
| 2144 | case OP_NOT_WHITESPACE: | case OP_NOT_WHITESPACE: |
| 2145 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2146 | { | |
| 2147 | SCHECK_PARTIAL(); | |
| 2148 | MRRETURN(MATCH_NOMATCH); | |
| 2149 | } | |
| 2150 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2151 | if ( | if ( |
| 2152 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1436 for (;;) | Line 2154 for (;;) |
| 2154 | #endif | #endif |
| 2155 | (md->ctypes[c] & ctype_space) != 0 | (md->ctypes[c] & ctype_space) != 0 |
| 2156 | ) | ) |
| 2157 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 2158 | ecode++; | ecode++; |
| 2159 | break; | break; |
| 2160 | ||
| 2161 | case OP_WHITESPACE: | case OP_WHITESPACE: |
| 2162 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2163 | { | |
| 2164 | SCHECK_PARTIAL(); | |
| 2165 | MRRETURN(MATCH_NOMATCH); | |
| 2166 | } | |
| 2167 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2168 | if ( | if ( |
| 2169 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1449 for (;;) | Line 2171 for (;;) |
| 2171 | #endif | #endif |
| 2172 | (md->ctypes[c] & ctype_space) == 0 | (md->ctypes[c] & ctype_space) == 0 |
| 2173 | ) | ) |
| 2174 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 2175 | ecode++; | ecode++; |
| 2176 | break; | break; |
| 2177 | ||
| 2178 | case OP_NOT_WORDCHAR: | case OP_NOT_WORDCHAR: |
| 2179 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2180 | { | |
| 2181 | SCHECK_PARTIAL(); | |
| 2182 | MRRETURN(MATCH_NOMATCH); | |
| 2183 | } | |
| 2184 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2185 | if ( | if ( |
| 2186 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1462 for (;;) | Line 2188 for (;;) |
| 2188 | #endif | #endif |
| 2189 | (md->ctypes[c] & ctype_word) != 0 | (md->ctypes[c] & ctype_word) != 0 |
| 2190 | ) | ) |
| 2191 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 2192 | ecode++; | ecode++; |
| 2193 | break; | break; |
| 2194 | ||
| 2195 | case OP_WORDCHAR: | case OP_WORDCHAR: |
| 2196 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2197 | { | |
| 2198 | SCHECK_PARTIAL(); | |
| 2199 | MRRETURN(MATCH_NOMATCH); | |
| 2200 | } | |
| 2201 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2202 | if ( | if ( |
| 2203 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1475 for (;;) | Line 2205 for (;;) |
| 2205 | #endif | #endif |
| 2206 | (md->ctypes[c] & ctype_word) == 0 | (md->ctypes[c] & ctype_word) == 0 |
| 2207 | ) | ) |
| 2208 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 2209 | ecode++; | ecode++; |
| 2210 | break; | break; |
| 2211 | ||
| 2212 | case OP_ANYNL: | case OP_ANYNL: |
| 2213 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2214 | { | |
| 2215 | SCHECK_PARTIAL(); | |
| 2216 | MRRETURN(MATCH_NOMATCH); | |
| 2217 | } | |
| 2218 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2219 | switch(c) | switch(c) |
| 2220 | { | { |
| 2221 | default: RRETURN(MATCH_NOMATCH); | default: MRRETURN(MATCH_NOMATCH); |
| 2222 | ||
| 2223 | case 0x000d: | case 0x000d: |
| 2224 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; |
| 2225 | break; | break; |
| 2226 | ||
| 2227 | case 0x000a: | case 0x000a: |
| 2228 | break; | |
| 2229 | ||
| 2230 | case 0x000b: | case 0x000b: |
| 2231 | case 0x000c: | case 0x000c: |
| 2232 | case 0x0085: | case 0x0085: |
| 2233 | case 0x2028: | case 0x2028: |
| 2234 | case 0x2029: | case 0x2029: |
| 2235 | if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH); | |
| 2236 | break; | break; |
| 2237 | } | } |
| 2238 | ecode++; | ecode++; |
| 2239 | break; | break; |
| 2240 | ||
| 2241 | case OP_NOT_HSPACE: | case OP_NOT_HSPACE: |
| 2242 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2243 | { | |
| 2244 | SCHECK_PARTIAL(); | |
| 2245 | MRRETURN(MATCH_NOMATCH); | |
| 2246 | } | |
| 2247 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2248 | switch(c) | switch(c) |
| 2249 | { | { |
| # | Line 1524 for (;;) | Line 2267 for (;;) |
| 2267 | case 0x202f: /* NARROW NO-BREAK SPACE */ | case 0x202f: /* NARROW NO-BREAK SPACE */ |
| 2268 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ |
| 2269 | case 0x3000: /* IDEOGRAPHIC SPACE */ | case 0x3000: /* IDEOGRAPHIC SPACE */ |
| 2270 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 2271 | } | } |
| 2272 | ecode++; | ecode++; |
| 2273 | break; | break; |
| 2274 | ||
| 2275 | case OP_HSPACE: | case OP_HSPACE: |
| 2276 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2277 | { | |
| 2278 | SCHECK_PARTIAL(); | |
| 2279 | MRRETURN(MATCH_NOMATCH); | |
| 2280 | } | |
| 2281 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2282 | switch(c) | switch(c) |
| 2283 | { | { |
| 2284 | default: RRETURN(MATCH_NOMATCH); | default: MRRETURN(MATCH_NOMATCH); |
| 2285 | case 0x09: /* HT */ | case 0x09: /* HT */ |
| 2286 | case 0x20: /* SPACE */ | case 0x20: /* SPACE */ |
| 2287 | case 0xa0: /* NBSP */ | case 0xa0: /* NBSP */ |
| # | Line 1560 for (;;) | Line 2307 for (;;) |
| 2307 | break; | break; |
| 2308 | ||
| 2309 | case OP_NOT_VSPACE: | case OP_NOT_VSPACE: |
| 2310 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2311 | { | |
| 2312 | SCHECK_PARTIAL(); | |
| 2313 | MRRETURN(MATCH_NOMATCH); | |
| 2314 | } | |
| 2315 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2316 | switch(c) | switch(c) |
| 2317 | { | { |
| # | Line 1572 for (;;) | Line 2323 for (;;) |
| 2323 | case 0x85: /* NEL */ | case 0x85: /* NEL */ |
| 2324 | case 0x2028: /* LINE SEPARATOR */ | case 0x2028: /* LINE SEPARATOR */ |
| 2325 | case 0x2029: /* PARAGRAPH SEPARATOR */ | case 0x2029: /* PARAGRAPH SEPARATOR */ |
| 2326 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 2327 | } | } |
| 2328 | ecode++; | ecode++; |
| 2329 | break; | break; |
| 2330 | ||
| 2331 | case OP_VSPACE: | case OP_VSPACE: |
| 2332 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2333 | { | |
| 2334 | SCHECK_PARTIAL(); | |
| 2335 | MRRETURN(MATCH_NOMATCH); | |
| 2336 | } | |
| 2337 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2338 | switch(c) | switch(c) |
| 2339 | { | { |
| 2340 | default: RRETURN(MATCH_NOMATCH); | default: MRRETURN(MATCH_NOMATCH); |
| 2341 | case 0x0a: /* LF */ | case 0x0a: /* LF */ |
| 2342 | case 0x0b: /* VT */ | case 0x0b: /* VT */ |
| 2343 | case 0x0c: /* FF */ | case 0x0c: /* FF */ |
| # | Line 1601 for (;;) | Line 2356 for (;;) |
| 2356 | ||
| 2357 | case OP_PROP: | case OP_PROP: |
| 2358 | case OP_NOTPROP: | case OP_NOTPROP: |
| 2359 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2360 | { | |
| 2361 | SCHECK_PARTIAL(); | |
| 2362 | MRRETURN(MATCH_NOMATCH); | |
| 2363 | } | |
| 2364 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2365 | { | { |
| 2366 | int chartype, script; | const ucd_record *prop = GET_UCD(c); |
| int category = _pcre_ucp_findprop(c, &chartype, &script); | ||
| 2367 | ||
| 2368 | switch(ecode[1]) | switch(ecode[1]) |
| 2369 | { | { |
| 2370 | case PT_ANY: | case PT_ANY: |
| 2371 | if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH); | if (op == OP_NOTPROP) MRRETURN(MATCH_NOMATCH); |
| 2372 | break; | break; |
| 2373 | ||
| 2374 | case PT_LAMP: | case PT_LAMP: |
| 2375 | if ((chartype == ucp_Lu || | if ((prop->chartype == ucp_Lu || |
| 2376 | chartype == ucp_Ll || | prop->chartype == ucp_Ll || |
| 2377 | chartype == ucp_Lt) == (op == OP_NOTPROP)) | prop->chartype == ucp_Lt) == (op == OP_NOTPROP)) |
| 2378 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 2379 | break; | break; |
| 2380 | ||
| 2381 | case PT_GC: | case PT_GC: |
| 2382 | if ((ecode[2] != category) == (op == OP_PROP)) | if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP)) |
| 2383 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 2384 | break; | break; |
| 2385 | ||
| 2386 | case PT_PC: | case PT_PC: |
| 2387 | if ((ecode[2] != chartype) == (op == OP_PROP)) | if ((ecode[2] != prop->chartype) == (op == OP_PROP)) |
| 2388 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 2389 | break; | break; |
| 2390 | ||
| 2391 | case PT_SC: | case PT_SC: |
| 2392 | if ((ecode[2] != script) == (op == OP_PROP)) | if ((ecode[2] != prop->script) == (op == OP_PROP)) |
| 2393 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 2394 | break; | |
| 2395 | ||
| 2396 | /* These are specials */ | |
| 2397 | ||
| 2398 | case PT_ALNUM: | |
| 2399 | if ((_pcre_ucp_gentype[prop->chartype] == ucp_L || | |
| 2400 | _pcre_ucp_gentype[prop->chartype] == ucp_N) == (op == OP_NOTPROP)) | |
| 2401 | MRRETURN(MATCH_NOMATCH); | |
| 2402 | break; | |
| 2403 | ||
| 2404 | case PT_SPACE: /* Perl space */ | |
| 2405 | if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z || | |
| 2406 | c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR) | |
| 2407 | == (op == OP_NOTPROP)) | |
| 2408 | MRRETURN(MATCH_NOMATCH); | |
| 2409 | break; | break; |
| 2410 | ||
| 2411 | case PT_PXSPACE: /* POSIX space */ | |
| 2412 | if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z || | |
| 2413 | c == CHAR_HT || c == CHAR_NL || c == CHAR_VT || | |
| 2414 | c == CHAR_FF || c == CHAR_CR) | |
| 2415 | == (op == OP_NOTPROP)) | |
| 2416 | MRRETURN(MATCH_NOMATCH); | |
| 2417 | break; | |
| 2418 | ||
| 2419 | case PT_WORD: | |
| 2420 | if ((_pcre_ucp_gentype[prop->chartype] == ucp_L || | |
| 2421 | _pcre_ucp_gentype[prop->chartype] == ucp_N || | |
| 2422 | c == CHAR_UNDERSCORE) == (op == OP_NOTPROP)) | |
| 2423 | MRRETURN(MATCH_NOMATCH); | |
| 2424 | break; | |
| 2425 | ||
| 2426 | /* This should never occur */ | |
| 2427 | ||
| 2428 | default: | default: |
| 2429 | RRETURN(PCRE_ERROR_INTERNAL); | RRETURN(PCRE_ERROR_INTERNAL); |
| 2430 | } | } |
| # | Line 1647 for (;;) | Line 2437 for (;;) |
| 2437 | is in the binary; otherwise a compile-time error occurs. */ | is in the binary; otherwise a compile-time error occurs. */ |
| 2438 | ||
| 2439 | case OP_EXTUNI: | case OP_EXTUNI: |
| 2440 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2441 | { | |
| 2442 | SCHECK_PARTIAL(); | |
| 2443 | MRRETURN(MATCH_NOMATCH); | |
| 2444 | } | |
| 2445 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2446 | { | { |
| 2447 | int chartype, script; | int category = UCD_CATEGORY(c); |
| 2448 | int category = _pcre_ucp_findprop(c, &chartype, &script); | if (category == ucp_M) MRRETURN(MATCH_NOMATCH); |
| if (category == ucp_M) RRETURN(MATCH_NOMATCH); | ||
| 2449 | while (eptr < md->end_subject) | while (eptr < md->end_subject) |
| 2450 | { | { |
| 2451 | int len = 1; | int len = 1; |
| # | Line 1660 for (;;) | Line 2453 for (;;) |
| 2453 | { | { |
| 2454 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
| 2455 | } | } |
| 2456 | category = _pcre_ucp_findprop(c, &chartype, &script); | category = UCD_CATEGORY(c); |
| 2457 | if (category != ucp_M) break; | if (category != ucp_M) break; |
| 2458 | eptr += len; | eptr += len; |
| 2459 | } | } |
| # | Line 1679 for (;;) | Line 2472 for (;;) |
| 2472 | loops). */ | loops). */ |
| 2473 | ||
| 2474 | case OP_REF: | case OP_REF: |
| 2475 | { | case OP_REFI: |
| 2476 | offset = GET2(ecode, 1) << 1; /* Doubled ref number */ | caseless = op == OP_REFI; |
| 2477 | ecode += 3; /* Advance past item */ | offset = GET2(ecode, 1) << 1; /* Doubled ref number */ |
| 2478 | ecode += 3; | |
| 2479 | ||
| 2480 | /* If the reference is unset, set the length to be longer than the amount | /* If the reference is unset, there are two possibilities: |
| of subject left; this ensures that every attempt at a match fails. We | ||
| can't just fail here, because of the possibility of quantifiers with zero | ||
| minima. */ | ||
| length = (offset >= offset_top || md->offset_vector[offset] < 0)? | ||
| md->end_subject - eptr + 1 : | ||
| md->offset_vector[offset+1] - md->offset_vector[offset]; | ||
| 2481 | ||
| 2482 | /* Set up for repetition, or handle the non-repeated case */ | (a) In the default, Perl-compatible state, set the length negative; |
| 2483 | this ensures that every attempt at a match fails. We can't just fail | |
| 2484 | here, because of the possibility of quantifiers with zero minima. | |
| 2485 | ||
| 2486 | switch (*ecode) | (b) If the JavaScript compatibility flag is set, set the length to zero |
| 2487 | { | so that the back reference matches an empty string. |
| case OP_CRSTAR: | ||
| case OP_CRMINSTAR: | ||
| case OP_CRPLUS: | ||
| case OP_CRMINPLUS: | ||
| case OP_CRQUERY: | ||
| case OP_CRMINQUERY: | ||
| c = *ecode++ - OP_CRSTAR; | ||
| minimize = (c & 1) != 0; | ||
| min = rep_min[c]; /* Pick up values from tables; */ | ||
| max = rep_max[c]; /* zero for max => infinity */ | ||
| if (max == 0) max = INT_MAX; | ||
| break; | ||
| 2488 | ||
| 2489 | case OP_CRRANGE: | Otherwise, set the length to the length of what was matched by the |
| 2490 | case OP_CRMINRANGE: | referenced subpattern. */ |
| minimize = (*ecode == OP_CRMINRANGE); | ||
| min = GET2(ecode, 1); | ||
| max = GET2(ecode, 3); | ||
| if (max == 0) max = INT_MAX; | ||
| ecode += 5; | ||
| break; | ||
| 2491 | ||
| 2492 | default: /* No repeat follows */ | if (offset >= offset_top || md->offset_vector[offset] < 0) |
| 2493 | if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH); | length = (md->jscript_compat)? 0 : -1; |
| 2494 | eptr += length; | else |
| 2495 | continue; /* With the main loop */ | length = md->offset_vector[offset+1] - md->offset_vector[offset]; |
| 2496 | ||
| 2497 | /* Set up for repetition, or handle the non-repeated case */ | |
| 2498 | ||
| 2499 | switch (*ecode) | |
| 2500 | { | |
| 2501 | case OP_CRSTAR: | |
| 2502 | case OP_CRMINSTAR: | |
| 2503 | case OP_CRPLUS: | |
| 2504 | case OP_CRMINPLUS: | |
| 2505 | case OP_CRQUERY: | |
| 2506 | case OP_CRMINQUERY: | |
| 2507 | c = *ecode++ - OP_CRSTAR; | |
| 2508 | minimize = (c & 1) != 0; | |
| 2509 | min = rep_min[c]; /* Pick up values from tables; */ | |
| 2510 | max = rep_max[c]; /* zero for max => infinity */ | |
| 2511 | if (max == 0) max = INT_MAX; | |
| 2512 | break; | |
| 2513 | ||
| 2514 | case OP_CRRANGE: | |
| 2515 | case OP_CRMINRANGE: | |
| 2516 | minimize = (*ecode == OP_CRMINRANGE); | |
| 2517 | min = GET2(ecode, 1); | |
| 2518 | max = GET2(ecode, 3); | |
| 2519 | if (max == 0) max = INT_MAX; | |
| 2520 | ecode += 5; | |
| 2521 | break; | |
| 2522 | ||
| 2523 | default: /* No repeat follows */ | |
| 2524 | if ((length = match_ref(offset, eptr, length, md, caseless)) < 0) | |
| 2525 | { | |
| 2526 | CHECK_PARTIAL(); | |
| 2527 | MRRETURN(MATCH_NOMATCH); | |
| 2528 | } | } |
| 2529 | eptr += length; | |
| 2530 | continue; /* With the main loop */ | |
| 2531 | } | |
| 2532 | ||
| 2533 | /* If the length of the reference is zero, just continue with the | /* Handle repeated back references. If the length of the reference is |
| 2534 | main loop. */ | zero, just continue with the main loop. */ |
| 2535 | ||
| 2536 | if (length == 0) continue; | if (length == 0) continue; |
| 2537 | ||
| 2538 | /* First, ensure the minimum number of matches are present. We get back | /* First, ensure the minimum number of matches are present. We get back |
| 2539 | the length of the reference string explicitly rather than passing the | the length of the reference string explicitly rather than passing the |
| 2540 | address of eptr, so that eptr can be a register variable. */ | address of eptr, so that eptr can be a register variable. */ |
| 2541 | ||
| 2542 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2543 | { | |
| 2544 | int slength; | |
| 2545 | if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0) | |
| 2546 | { | { |
| 2547 | if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH); | CHECK_PARTIAL(); |
| 2548 | eptr += length; | MRRETURN(MATCH_NOMATCH); |
| 2549 | } | } |
| 2550 | eptr += slength; | |
| 2551 | } | |
| 2552 | ||
| 2553 | /* If min = max, continue at the same level without recursion. | /* If min = max, continue at the same level without recursion. |
| 2554 | They are not both allowed to be zero. */ | They are not both allowed to be zero. */ |
| 2555 | ||
| 2556 | if (min == max) continue; | if (min == max) continue; |
| 2557 | ||
| 2558 | /* If minimizing, keep trying and advancing the pointer */ | /* If minimizing, keep trying and advancing the pointer */ |
| 2559 | ||
| 2560 | if (minimize) | if (minimize) |
| 2561 | { | |
| 2562 | for (fi = min;; fi++) | |
| 2563 | { | { |
| 2564 | for (fi = min;; fi++) | int slength; |
| 2565 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM14); | |
| 2566 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 2567 | if (fi >= max) MRRETURN(MATCH_NOMATCH); | |
| 2568 | if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0) | |
| 2569 | { | { |
| 2570 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14); | CHECK_PARTIAL(); |
| 2571 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | MRRETURN(MATCH_NOMATCH); |
| if (fi >= max || !match_ref(offset, eptr, length, md, ims)) | ||
| RRETURN(MATCH_NOMATCH); | ||
| eptr += length; | ||
| 2572 | } | } |
| 2573 | /* Control never gets here */ | eptr += slength; |
| 2574 | } | } |
| 2575 | /* Control never gets here */ | |
| 2576 | } | |
| 2577 | ||
| 2578 | /* If maximizing, find the longest string and work backwards */ | /* If maximizing, find the longest string and work backwards */ |
| 2579 | ||
| 2580 | else | else |
| 2581 | { | |
| 2582 | pp = eptr; | |
| 2583 | for (i = min; i < max; i++) | |
| 2584 | { | { |
| 2585 | pp = eptr; | int slength; |
| 2586 | for (i = min; i < max; i++) | if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0) |
| { | ||
| if (!match_ref(offset, eptr, length, md, ims)) break; | ||
| eptr += length; | ||
| } | ||
| while (eptr >= pp) | ||
| 2587 | { | { |
| 2588 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15); | CHECK_PARTIAL(); |
| 2589 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | break; |
| eptr -= length; | ||
| 2590 | } | } |
| 2591 | RRETURN(MATCH_NOMATCH); | eptr += slength; |
| 2592 | } | |
| 2593 | while (eptr >= pp) | |
| 2594 | { | |
| 2595 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM15); | |
| 2596 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 2597 | eptr -= length; | |
| 2598 | } | } |
| 2599 | MRRETURN(MATCH_NOMATCH); | |
| 2600 | } | } |
| 2601 | /* Control never gets here */ | /* Control never gets here */ |
| 2602 | ||
| 2603 | /* Match a bit-mapped character class, possibly repeatedly. This op code is | /* Match a bit-mapped character class, possibly repeatedly. This op code is |
| 2604 | used when all the characters in the class have values in the range 0-255, | used when all the characters in the class have values in the range 0-255, |
| 2605 | and either the matching is caseful, or the characters are in the range | and either the matching is caseful, or the characters are in the range |
| # | Line 1836 for (;;) | Line 2654 for (;;) |
| 2654 | { | { |
| 2655 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2656 | { | { |
| 2657 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2658 | { | |
| 2659 | SCHECK_PARTIAL(); | |
| 2660 | MRRETURN(MATCH_NOMATCH); | |
| 2661 | } | |
| 2662 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 2663 | if (c > 255) | if (c > 255) |
| 2664 | { | { |
| 2665 | if (op == OP_CLASS) RRETURN(MATCH_NOMATCH); | if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH); |
| 2666 | } | } |
| 2667 | else | else |
| 2668 | { | { |
| 2669 | if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); | if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH); |
| 2670 | } | } |
| 2671 | } | } |
| 2672 | } | } |
| # | Line 1854 for (;;) | Line 2676 for (;;) |
| 2676 | { | { |
| 2677 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2678 | { | { |
| 2679 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2680 | { | |
| 2681 | SCHECK_PARTIAL(); | |
| 2682 | MRRETURN(MATCH_NOMATCH); | |
| 2683 | } | |
| 2684 | c = *eptr++; | c = *eptr++; |
| 2685 | if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); | if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH); |
| 2686 | } | } |
| 2687 | } | } |
| 2688 | ||
| # | Line 1876 for (;;) | Line 2702 for (;;) |
| 2702 | { | { |
| 2703 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2704 | { | { |
| 2705 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM16); |
| 2706 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2707 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) MRRETURN(MATCH_NOMATCH); |
| 2708 | if (eptr >= md->end_subject) | |
| 2709 | { | |
| 2710 | SCHECK_PARTIAL(); | |
| 2711 | MRRETURN(MATCH_NOMATCH); | |
| 2712 | } | |
| 2713 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 2714 | if (c > 255) | if (c > 255) |
| 2715 | { | { |
| 2716 | if (op == OP_CLASS) RRETURN(MATCH_NOMATCH); | if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH); |
| 2717 | } | } |
| 2718 | else | else |
| 2719 | { | { |
| 2720 | if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); | if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH); |
| 2721 | } | } |
| 2722 | } | } |
| 2723 | } | } |
| # | Line 1896 for (;;) | Line 2727 for (;;) |
| 2727 | { | { |
| 2728 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2729 | { | { |
| 2730 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM17); |
| 2731 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2732 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) MRRETURN(MATCH_NOMATCH); |
| 2733 | if (eptr >= md->end_subject) | |
| 2734 | { | |
| 2735 | SCHECK_PARTIAL(); | |
| 2736 | MRRETURN(MATCH_NOMATCH); | |
| 2737 | } | |
| 2738 | c = *eptr++; | c = *eptr++; |
| 2739 | if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); | if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH); |
| 2740 | } | } |
| 2741 | } | } |
| 2742 | /* Control never gets here */ | /* Control never gets here */ |
| # | Line 1919 for (;;) | Line 2755 for (;;) |
| 2755 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2756 | { | { |
| 2757 | int len = 1; | int len = 1; |
| 2758 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) |
| 2759 | { | |
| 2760 | SCHECK_PARTIAL(); | |
| 2761 | break; | |
| 2762 | } | |
| 2763 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
| 2764 | if (c > 255) | if (c > 255) |
| 2765 | { | { |
| # | Line 1933 for (;;) | Line 2773 for (;;) |
| 2773 | } | } |
| 2774 | for (;;) | for (;;) |
| 2775 | { | { |
| 2776 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM18); |
| 2777 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2778 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 2779 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| # | Line 1945 for (;;) | Line 2785 for (;;) |
| 2785 | { | { |
| 2786 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2787 | { | { |
| 2788 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) |
| 2789 | { | |
| 2790 | SCHECK_PARTIAL(); | |
| 2791 | break; | |
| 2792 | } | |
| 2793 | c = *eptr; | c = *eptr; |
| 2794 | if ((data[c/8] & (1 << (c&7))) == 0) break; | if ((data[c/8] & (1 << (c&7))) == 0) break; |
| 2795 | eptr++; | eptr++; |
| 2796 | } | } |
| 2797 | while (eptr >= pp) | while (eptr >= pp) |
| 2798 | { | { |
| 2799 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM19); |
| 2800 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2801 | eptr--; | eptr--; |
| 2802 | } | } |
| 2803 | } | } |
| 2804 | ||
| 2805 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 2806 | } | } |
| 2807 | } | } |
| 2808 | /* Control never gets here */ | /* Control never gets here */ |
| 2809 | ||
| 2810 | ||
| 2811 | /* Match an extended character class. This opcode is encountered only | /* Match an extended character class. This opcode is encountered only |
| 2812 | in UTF-8 mode, because that's the only time it is compiled. */ | when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8 |
| 2813 | mode, because Unicode properties are supported in non-UTF-8 mode. */ | |
| 2814 | ||
| 2815 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| 2816 | case OP_XCLASS: | case OP_XCLASS: |
| # | Line 2006 for (;;) | Line 2851 for (;;) |
| 2851 | ||
| 2852 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2853 | { | { |
| 2854 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2855 | GETCHARINC(c, eptr); | { |
| 2856 | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); | SCHECK_PARTIAL(); |
| 2857 | MRRETURN(MATCH_NOMATCH); | |
| 2858 | } | |
| 2859 | GETCHARINCTEST(c, eptr); | |
| 2860 | if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH); | |
| 2861 | } | } |
| 2862 | ||
| 2863 | /* If max == min we can continue with the main loop without the | /* If max == min we can continue with the main loop without the |
| # | Line 2023 for (;;) | Line 2872 for (;;) |
| 2872 | { | { |
| 2873 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2874 | { | { |
| 2875 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM20); |
| 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) MRRETURN(MATCH_NOMATCH); |
| 2878 | GETCHARINC(c, eptr); | if (eptr >= md->end_subject) |
| 2879 | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); | { |
| 2880 | SCHECK_PARTIAL(); | |
| 2881 | MRRETURN(MATCH_NOMATCH); | |
| 2882 | } | |
| 2883 | GETCHARINCTEST(c, eptr); | |
| 2884 | if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH); | |
| 2885 | } | } |
| 2886 | /* Control never gets here */ | /* Control never gets here */ |
| 2887 | } | } |
| # | Line 2040 for (;;) | Line 2894 for (;;) |
| 2894 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2895 | { | { |
| 2896 | int len = 1; | int len = 1; |
| 2897 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) |
| 2898 | GETCHARLEN(c, eptr, len); | { |
| 2899 | SCHECK_PARTIAL(); | |
| 2900 | break; | |
| 2901 | } | |
| 2902 | GETCHARLENTEST(c, eptr, len); | |
| 2903 | if (!_pcre_xclass(c, data)) break; | if (!_pcre_xclass(c, data)) break; |
| 2904 | eptr += len; | eptr += len; |
| 2905 | } | } |
| 2906 | for(;;) | for(;;) |
| 2907 | { | { |
| 2908 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM21); |
| 2909 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2910 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 2911 | BACKCHAR(eptr) | if (utf8) BACKCHAR(eptr); |
| 2912 | } | } |
| 2913 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 2914 | } | } |
| 2915 | ||
| 2916 | /* Control never gets here */ | /* Control never gets here */ |
| # | Line 2068 for (;;) | Line 2926 for (;;) |
| 2926 | length = 1; | length = 1; |
| 2927 | ecode++; | ecode++; |
| 2928 | GETCHARLEN(fc, ecode, length); | GETCHARLEN(fc, ecode, length); |
| 2929 | if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | if (length > md->end_subject - eptr) |
| 2930 | while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH); | { |
| 2931 | CHECK_PARTIAL(); /* Not SCHECK_PARTIAL() */ | |
| 2932 | MRRETURN(MATCH_NOMATCH); | |
| 2933 | } | |
| 2934 | while (length-- > 0) if (*ecode++ != *eptr++) MRRETURN(MATCH_NOMATCH); | |
| 2935 | } | } |
| 2936 | else | else |
| 2937 | #endif | #endif |
| 2938 | ||
| 2939 | /* Non-UTF-8 mode */ | /* Non-UTF-8 mode */ |
| 2940 | { | { |
| 2941 | if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH); | if (md->end_subject - eptr < 1) |
| 2942 | if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH); | { |
| 2943 | SCHECK_PARTIAL(); /* This one can use SCHECK_PARTIAL() */ | |
| 2944 | MRRETURN(MATCH_NOMATCH); | |
| 2945 | } | |
| 2946 | if (ecode[1] != *eptr++) MRRETURN(MATCH_NOMATCH); | |
| 2947 | ecode += 2; | ecode += 2; |
| 2948 | } | } |
| 2949 | break; | break; |
| 2950 | ||
| 2951 | /* Match a single character, caselessly */ | /* Match a single character, caselessly */ |
| 2952 | ||
| 2953 | case OP_CHARNC: | case OP_CHARI: |
| 2954 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| 2955 | if (utf8) | if (utf8) |
| 2956 | { | { |
| # | Line 2092 for (;;) | Line 2958 for (;;) |
| 2958 | ecode++; | ecode++; |
| 2959 | GETCHARLEN(fc, ecode, length); | GETCHARLEN(fc, ecode, length); |
| 2960 | ||
| 2961 | if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | if (length > md->end_subject - eptr) |
| 2962 | { | |
| 2963 | CHECK_PARTIAL(); /* Not SCHECK_PARTIAL() */ | |
| 2964 | MRRETURN(MATCH_NOMATCH); | |
| 2965 | } | |
| 2966 | ||
| 2967 | /* If the pattern character's value is < 128, we have only one byte, and | /* If the pattern character's value is < 128, we have only one byte, and |
| 2968 | can use the fast lookup table. */ | can use the fast lookup table. */ |
| 2969 | ||
| 2970 | if (fc < 128) | if (fc < 128) |
| 2971 | { | { |
| 2972 | if (md->lcc[*ecode++] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | if (md->lcc[*ecode++] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH); |
| 2973 | } | } |
| 2974 | ||
| 2975 | /* Otherwise we must pick up the subject character */ | /* Otherwise we must pick up the subject character */ |
| # | Line 2116 for (;;) | Line 2986 for (;;) |
| 2986 | if (fc != dc) | if (fc != dc) |
| 2987 | { | { |
| 2988 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 2989 | if (dc != _pcre_ucp_othercase(fc)) | if (dc != UCD_OTHERCASE(fc)) |
| 2990 | #endif | #endif |
| 2991 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 2992 | } | } |
| 2993 | } | } |
| 2994 | } | } |
| # | Line 2127 for (;;) | Line 2997 for (;;) |
| 2997 | ||
| 2998 | /* Non-UTF-8 mode */ | /* Non-UTF-8 mode */ |
| 2999 | { | { |
| 3000 | if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH); | if (md->end_subject - eptr < 1) |
| 3001 | if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | { |
| 3002 | SCHECK_PARTIAL(); /* This one can use SCHECK_PARTIAL() */ | |
| 3003 | MRRETURN(MATCH_NOMATCH); | |
| 3004 | } | |
| 3005 | if (md->lcc[ecode[1]] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH); | |
| 3006 | ecode += 2; | ecode += 2; |
| 3007 | } | } |
| 3008 | break; | break; |
| # | Line 2136 for (;;) | Line 3010 for (;;) |
| 3010 | /* Match a single character repeatedly. */ | /* Match a single character repeatedly. */ |
| 3011 | ||
| 3012 | case OP_EXACT: | case OP_EXACT: |
| 3013 | case OP_EXACTI: | |
| 3014 | min = max = GET2(ecode, 1); | min = max = GET2(ecode, 1); |
| 3015 | ecode += 3; | ecode += 3; |
| 3016 | goto REPEATCHAR; | goto REPEATCHAR; |
| 3017 | ||
| 3018 | case OP_POSUPTO: | case OP_POSUPTO: |
| 3019 | case OP_POSUPTOI: | |
| 3020 | possessive = TRUE; | possessive = TRUE; |
| 3021 | /* Fall through */ | /* Fall through */ |
| 3022 | ||
| 3023 | case OP_UPTO: | case OP_UPTO: |
| 3024 | case OP_UPTOI: | |
| 3025 | case OP_MINUPTO: | case OP_MINUPTO: |
| 3026 | case OP_MINUPTOI: | |
| 3027 | min = 0; | min = 0; |
| 3028 | max = GET2(ecode, 1); | max = GET2(ecode, 1); |
| 3029 | minimize = *ecode == OP_MINUPTO; | minimize = *ecode == OP_MINUPTO || *ecode == OP_MINUPTOI; |
| 3030 | ecode += 3; | ecode += 3; |
| 3031 | goto REPEATCHAR; | goto REPEATCHAR; |
| 3032 | ||
| 3033 | case OP_POSSTAR: | case OP_POSSTAR: |
| 3034 | case OP_POSSTARI: | |
| 3035 | possessive = TRUE; | possessive = TRUE; |
| 3036 | min = 0; | min = 0; |
| 3037 | max = INT_MAX; | max = INT_MAX; |
| # | Line 2160 for (;;) | Line 3039 for (;;) |
| 3039 | goto REPEATCHAR; | goto REPEATCHAR; |
| 3040 | ||
| 3041 | case OP_POSPLUS: | case OP_POSPLUS: |
| 3042 | case OP_POSPLUSI: | |
| 3043 | possessive = TRUE; | possessive = TRUE; |
| 3044 | min = 1; | min = 1; |
| 3045 | max = INT_MAX; | max = INT_MAX; |
| # | Line 2167 for (;;) | Line 3047 for (;;) |
| 3047 | goto REPEATCHAR; | goto REPEATCHAR; |
| 3048 | ||
| 3049 | case OP_POSQUERY: | case OP_POSQUERY: |
| 3050 | case OP_POSQUERYI: | |
| 3051 | possessive = TRUE; | possessive = TRUE; |
| 3052 | min = 0; | min = 0; |
| 3053 | max = 1; | max = 1; |
| # | Line 2174 for (;;) | Line 3055 for (;;) |
| 3055 | goto REPEATCHAR; | goto REPEATCHAR; |
| 3056 | ||
| 3057 | case OP_STAR: | case OP_STAR: |
| 3058 | case OP_STARI: | |
| 3059 | case OP_MINSTAR: | case OP_MINSTAR: |
| 3060 | case OP_MINSTARI: | |
| 3061 | case OP_PLUS: | case OP_PLUS: |
| 3062 | case OP_PLUSI: | |
| 3063 | case OP_MINPLUS: | case OP_MINPLUS: |
| 3064 | case OP_MINPLUSI: | |
| 3065 | case OP_QUERY: | case OP_QUERY: |
| 3066 | case OP_QUERYI: | |
| 3067 | case OP_MINQUERY: | case OP_MINQUERY: |
| 3068 | c = *ecode++ - OP_STAR; | case OP_MINQUERYI: |
| 3069 | c = *ecode++ - ((op < OP_STARI)? OP_STAR : OP_STARI); | |
| 3070 | minimize = (c & 1) != 0; | minimize = (c & 1) != 0; |
| 3071 | min = rep_min[c]; /* Pick up values from tables; */ | min = rep_min[c]; /* Pick up values from tables; */ |
| 3072 | max = rep_max[c]; /* zero for max => infinity */ | max = rep_max[c]; /* zero for max => infinity */ |
| 3073 | if (max == 0) max = INT_MAX; | if (max == 0) max = INT_MAX; |
| 3074 | ||
| 3075 | /* Common code for all repeated single-character matches. We can give | /* Common code for all repeated single-character matches. */ |
| up quickly if there are fewer than the minimum number of characters left in | ||
| the subject. */ | ||
| 3076 | ||
| 3077 | REPEATCHAR: | REPEATCHAR: |
| 3078 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 2196 for (;;) | Line 3081 for (;;) |
| 3081 | length = 1; | length = 1; |
| 3082 | charptr = ecode; | charptr = ecode; |
| 3083 | GETCHARLEN(fc, ecode, length); | GETCHARLEN(fc, ecode, length); |
| if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | ||
| 3084 | ecode += length; | ecode += length; |
| 3085 | ||
| 3086 | /* Handle multibyte character matching specially here. There is | /* Handle multibyte character matching specially here. There is |
| # | Line 2206 for (;;) | Line 3090 for (;;) |
| 3090 | { | { |
| 3091 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 3092 | unsigned int othercase; | unsigned int othercase; |
| 3093 | if ((ims & PCRE_CASELESS) != 0 && | if (op >= OP_STARI && /* Caseless */ |
| 3094 | (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR) | (othercase = UCD_OTHERCASE(fc)) != fc) |
| 3095 | oclength = _pcre_ord2utf8(othercase, occhars); | oclength = _pcre_ord2utf8(othercase, occhars); |
| 3096 | else oclength = 0; | else oclength = 0; |
| 3097 | #endif /* SUPPORT_UCP */ | #endif /* SUPPORT_UCP */ |
| 3098 | ||
| 3099 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3100 | { | { |
| 3101 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | if (eptr <= md->end_subject - length && |
| 3102 | memcmp(eptr, charptr, length) == 0) eptr += length; | |
| 3103 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 3104 | /* Need braces because of following else */ | else if (oclength > 0 && |
| 3105 | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } | eptr <= md->end_subject - oclength && |
| 3106 | memcmp(eptr, occhars, oclength) == 0) eptr += oclength; | |
| 3107 | #endif /* SUPPORT_UCP */ | |
| 3108 | else | else |
| 3109 | { | { |
| 3110 | if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); | CHECK_PARTIAL(); |
| 3111 | eptr += oclength; | MRRETURN(MATCH_NOMATCH); |
| 3112 | } | } |
| #else /* without SUPPORT_UCP */ | ||
| else { RRETURN(MATCH_NOMATCH); } | ||
| #endif /* SUPPORT_UCP */ | ||
| 3113 | } | } |
| 3114 | ||
| 3115 | if (min == max) continue; | if (min == max) continue; |
| # | Line 2234 for (;;) | Line 3118 for (;;) |
| 3118 | { | { |
| 3119 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3120 | { | { |
| 3121 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM22); |
| 3122 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3123 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) MRRETURN(MATCH_NOMATCH); |
| 3124 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | if (eptr <= md->end_subject - length && |
| 3125 | memcmp(eptr, charptr, length) == 0) eptr += length; | |
| 3126 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 3127 | /* Need braces because of following else */ | else if (oclength > 0 && |
| 3128 | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } | eptr <= md->end_subject - oclength && |
| 3129 | memcmp(eptr, occhars, oclength) == 0) eptr += oclength; | |
| 3130 | #endif /* SUPPORT_UCP */ | |
| 3131 | else | else |
| 3132 | { | { |
| 3133 | if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); | CHECK_PARTIAL(); |
| 3134 | eptr += oclength; | MRRETURN(MATCH_NOMATCH); |
| 3135 | } | } |
| #else /* without SUPPORT_UCP */ | ||
| else { RRETURN (MATCH_NOMATCH); } | ||
| #endif /* SUPPORT_UCP */ | ||
| 3136 | } | } |
| 3137 | /* Control never gets here */ | /* Control never gets here */ |
| 3138 | } | } |
| # | Line 2258 for (;;) | Line 3142 for (;;) |
| 3142 | pp = eptr; | pp = eptr; |
| 3143 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 3144 | { | { |
| 3145 | if (eptr > md->end_subject - length) break; | if (eptr <= md->end_subject - length && |
| 3146 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | memcmp(eptr, charptr, length) == 0) eptr += length; |
| 3147 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 3148 | else if (oclength == 0) break; | else if (oclength > 0 && |
| 3149 | eptr <= md->end_subject - oclength && | |
| 3150 | memcmp(eptr, occhars, oclength) == 0) eptr += oclength; | |
| 3151 | #endif /* SUPPORT_UCP */ | |
| 3152 | else | else |
| 3153 | { | { |
| 3154 | if (memcmp(eptr, occhars, oclength) != 0) break; | CHECK_PARTIAL(); |
| 3155 | eptr += oclength; | break; |
| 3156 | } | } |
| #else /* without SUPPORT_UCP */ | ||
| else break; | ||
| #endif /* SUPPORT_UCP */ | ||
| 3157 | } | } |
| 3158 | ||
| 3159 | if (possessive) continue; | if (possessive) continue; |
| 3160 | ||
| 3161 | for(;;) | for(;;) |
| 3162 | { | { |
| 3163 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM23); |
| 3164 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3165 | if (eptr == pp) RRETURN(MATCH_NOMATCH); | if (eptr == pp) { MRRETURN(MATCH_NOMATCH); } |
| 3166 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 3167 | eptr--; | eptr--; |
| 3168 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| 3169 | #else /* without SUPPORT_UCP */ | #else /* without SUPPORT_UCP */ |
| 3170 | eptr -= length; | eptr -= length; |
| 3171 | #endif /* SUPPORT_UCP */ | #endif /* SUPPORT_UCP */ |
| 3172 | } | } |
| 3173 | } | } |
| 3174 | /* Control never gets here */ | /* Control never gets here */ |
| 3175 | } | } |
| # | Line 2297 for (;;) | Line 3182 for (;;) |
| 3182 | #endif /* SUPPORT_UTF8 */ | #endif /* SUPPORT_UTF8 */ |
| 3183 | ||
| 3184 | /* When not in UTF-8 mode, load a single-byte character. */ | /* When not in UTF-8 mode, load a single-byte character. */ |
| 3185 | { | |
| 3186 | if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | fc = *ecode++; |
| fc = *ecode++; | ||
| } | ||
| 3187 | ||
| 3188 | /* The value of fc at this point is always less than 256, though we may or | /* The value of fc at this point is always less than 256, though we may or |
| 3189 | may not be in UTF-8 mode. The code is duplicated for the caseless and | may not be in UTF-8 mode. The code is duplicated for the caseless and |
| # | Line 2314 for (;;) | Line 3197 for (;;) |
| 3197 | DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max, | DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max, |
| 3198 | max, eptr)); | max, eptr)); |
| 3199 | ||
| 3200 | if ((ims & PCRE_CASELESS) != 0) | if (op >= OP_STARI) /* Caseless */ |
| 3201 | { | { |
| 3202 | fc = md->lcc[fc]; | fc = md->lcc[fc]; |
| 3203 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3204 | if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | { |
| 3205 | if (eptr >= md->end_subject) | |
| 3206 | { | |
| 3207 | SCHECK_PARTIAL(); | |
| 3208 | MRRETURN(MATCH_NOMATCH); | |
| 3209 | } | |
| 3210 | if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH); | |
| 3211 | } | |
| 3212 | if (min == max) continue; | if (min == max) continue; |
| 3213 | if (minimize) | if (minimize) |
| 3214 | { | { |
| 3215 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3216 | { | { |
| 3217 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM24); |
| 3218 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3219 | if (fi >= max || eptr >= md->end_subject || | if (fi >= max) MRRETURN(MATCH_NOMATCH); |
| 3220 | fc != md->lcc[*eptr++]) | if (eptr >= md->end_subject) |
| 3221 | RRETURN(MATCH_NOMATCH); | { |
| 3222 | SCHECK_PARTIAL(); | |
| 3223 | MRRETURN(MATCH_NOMATCH); | |
| 3224 | } | |
| 3225 | if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH); | |
| 3226 | } | } |
| 3227 | /* Control never gets here */ | /* Control never gets here */ |
| 3228 | } | } |
| # | Line 2337 for (;;) | Line 3231 for (;;) |
| 3231 | pp = eptr; | pp = eptr; |
| 3232 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 3233 | { | { |
| 3234 | if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break; | if (eptr >= md->end_subject) |
| 3235 | { | |
| 3236 | SCHECK_PARTIAL(); | |
| 3237 | break; | |
| 3238 | } | |
| 3239 | if (fc != md->lcc[*eptr]) break; | |
| 3240 | eptr++; | eptr++; |
| 3241 | } | } |
| 3242 | ||
| 3243 | if (possessive) continue; | if (possessive) continue; |
| 3244 | ||
| 3245 | while (eptr >= pp) | while (eptr >= pp) |
| 3246 | { | { |
| 3247 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM25); |
| 3248 | eptr--; | eptr--; |
| 3249 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3250 | } | } |
| 3251 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 3252 | } | } |
| 3253 | /* Control never gets here */ | /* Control never gets here */ |
| 3254 | } | } |
| # | Line 2356 for (;;) | Line 3257 for (;;) |
| 3257 | ||
| 3258 | else | else |
| 3259 | { | { |
| 3260 | for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH); | for (i = 1; i <= min; i++) |
| 3261 | { | |
| 3262 | if (eptr >= md->end_subject) | |
| 3263 | { | |
| 3264 | SCHECK_PARTIAL(); | |
| 3265 | MRRETURN(MATCH_NOMATCH); | |
| 3266 | } | |
| 3267 | if (fc != *eptr++) MRRETURN(MATCH_NOMATCH); | |
| 3268 | } | |
| 3269 | ||
| 3270 | if (min == max) continue; | if (min == max) continue; |
| 3271 | ||
| 3272 | if (minimize) | if (minimize) |
| 3273 | { | { |
| 3274 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3275 | { | { |
| 3276 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM26); |
| 3277 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3278 | if (fi >= max || eptr >= md->end_subject || fc != *eptr++) | if (fi >= max) MRRETURN(MATCH_NOMATCH); |
| 3279 | RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3280 | { | |
| 3281 | SCHECK_PARTIAL(); | |
| 3282 | MRRETURN(MATCH_NOMATCH); | |
| 3283 | } | |
| 3284 | if (fc != *eptr++) MRRETURN(MATCH_NOMATCH); | |
| 3285 | } | } |
| 3286 | /* Control never gets here */ | /* Control never gets here */ |
| 3287 | } | } |
| # | Line 2374 for (;;) | Line 3290 for (;;) |
| 3290 | pp = eptr; | pp = eptr; |
| 3291 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 3292 | { | { |
| 3293 | if (eptr >= md->end_subject || fc != *eptr) break; | if (eptr >= md->end_subject) |
| 3294 | { | |
| 3295 | SCHECK_PARTIAL(); | |
| 3296 | break; | |
| 3297 | } | |
| 3298 | if (fc != *eptr) break; | |
| 3299 | eptr++; | eptr++; |
| 3300 | } | } |
| 3301 | if (possessive) continue; | if (possessive) continue; |
| 3302 | ||
| 3303 | while (eptr >= pp) | while (eptr >= pp) |
| 3304 | { | { |
| 3305 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM27); |
| 3306 | eptr--; | eptr--; |
| 3307 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3308 | } | } |
| 3309 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 3310 | } | } |
| 3311 | } | } |
| 3312 | /* Control never gets here */ | /* Control never gets here */ |
| # | Line 2393 for (;;) | Line 3315 for (;;) |
| 3315 | checking can be multibyte. */ | checking can be multibyte. */ |
| 3316 | ||
| 3317 | case OP_NOT: | case OP_NOT: |
| 3318 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | case OP_NOTI: |
| 3319 | if (eptr >= md->end_subject) | |
| 3320 | { | |
| 3321 | SCHECK_PARTIAL(); | |
| 3322 | MRRETURN(MATCH_NOMATCH); | |
| 3323 | } | |
| 3324 | ecode++; | ecode++; |
| 3325 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 3326 | if ((ims & PCRE_CASELESS) != 0) | if (op == OP_NOTI) /* The caseless case */ |
| 3327 | { | { |
| 3328 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| 3329 | if (c < 256) | if (c < 256) |
| 3330 | #endif | #endif |
| 3331 | c = md->lcc[c]; | c = md->lcc[c]; |
| 3332 | if (md->lcc[*ecode++] == c) RRETURN(MATCH_NOMATCH); | if (md->lcc[*ecode++] == c) MRRETURN(MATCH_NOMATCH); |
| 3333 | } | } |
| 3334 | else | else /* Caseful */ |
| 3335 | { | { |
| 3336 | if (*ecode++ == c) RRETURN(MATCH_NOMATCH); | if (*ecode++ == c) MRRETURN(MATCH_NOMATCH); |
| 3337 | } | } |
| 3338 | break; | break; |
| 3339 | ||
| # | Line 2418 for (;;) | Line 3345 for (;;) |
| 3345 | about... */ | about... */ |
| 3346 | ||
| 3347 | case OP_NOTEXACT: | case OP_NOTEXACT: |
| 3348 | case OP_NOTEXACTI: | |
| 3349 | min = max = GET2(ecode, 1); | min = max = GET2(ecode, 1); |
| 3350 | ecode += 3; | ecode += 3; |
| 3351 | goto REPEATNOTCHAR; | goto REPEATNOTCHAR; |
| 3352 | ||
| 3353 | case OP_NOTUPTO: | case OP_NOTUPTO: |
| 3354 | case OP_NOTUPTOI: | |
| 3355 | case OP_NOTMINUPTO: | case OP_NOTMINUPTO: |
| 3356 | case OP_NOTMINUPTOI: | |
| 3357 | min = 0; | min = 0; |
| 3358 | max = GET2(ecode, 1); | max = GET2(ecode, 1); |
| 3359 | minimize = *ecode == OP_NOTMINUPTO; | minimize = *ecode == OP_NOTMINUPTO || *ecode == OP_NOTMINUPTOI; |
| 3360 | ecode += 3; | ecode += 3; |
| 3361 | goto REPEATNOTCHAR; | goto REPEATNOTCHAR; |
| 3362 | ||
| 3363 | case OP_NOTPOSSTAR: | case OP_NOTPOSSTAR: |
| 3364 | case OP_NOTPOSSTARI: | |
| 3365 | possessive = TRUE; | possessive = TRUE; |
| 3366 | min = 0; | min = 0; |
| 3367 | max = INT_MAX; | max = INT_MAX; |
| # | Line 2438 for (;;) | Line 3369 for (;;) |
| 3369 | goto REPEATNOTCHAR; | goto REPEATNOTCHAR; |
| 3370 | ||
| 3371 | case OP_NOTPOSPLUS: | case OP_NOTPOSPLUS: |
| 3372 | case OP_NOTPOSPLUSI: | |
| 3373 | possessive = TRUE; | possessive = TRUE; |
| 3374 | min = 1; | min = 1; |
| 3375 | max = INT_MAX; | max = INT_MAX; |
| # | Line 2445 for (;;) | Line 3377 for (;;) |
| 3377 | goto REPEATNOTCHAR; | goto REPEATNOTCHAR; |
| 3378 | ||
| 3379 | case OP_NOTPOSQUERY: | case OP_NOTPOSQUERY: |
| 3380 | case OP_NOTPOSQUERYI: | |
| 3381 | possessive = TRUE; | possessive = TRUE; |
| 3382 | min = 0; | min = 0; |
| 3383 | max = 1; | max = 1; |
| # | Line 2452 for (;;) | Line 3385 for (;;) |
| 3385 | goto REPEATNOTCHAR; | goto REPEATNOTCHAR; |
| 3386 | ||
| 3387 | case OP_NOTPOSUPTO: | case OP_NOTPOSUPTO: |
| 3388 | case OP_NOTPOSUPTOI: | |
| 3389 | possessive = TRUE; | possessive = TRUE; |
| 3390 | min = 0; | min = 0; |
| 3391 | max = GET2(ecode, 1); | max = GET2(ecode, 1); |
| # | Line 2459 for (;;) | Line 3393 for (;;) |
| 3393 | goto REPEATNOTCHAR; | goto REPEATNOTCHAR; |
| 3394 | ||
| 3395 | case OP_NOTSTAR: | case OP_NOTSTAR: |
| 3396 | case OP_NOTSTARI: | |
| 3397 | case OP_NOTMINSTAR: | case OP_NOTMINSTAR: |
| 3398 | case OP_NOTMINSTARI: | |
| 3399 | case OP_NOTPLUS: | case OP_NOTPLUS: |
| 3400 | case OP_NOTPLUSI: | |
| 3401 | case OP_NOTMINPLUS: | case OP_NOTMINPLUS: |
| 3402 | case OP_NOTMINPLUSI: | |
| 3403 | case OP_NOTQUERY: | case OP_NOTQUERY: |
| 3404 | case OP_NOTQUERYI: | |
| 3405 | case OP_NOTMINQUERY: | case OP_NOTMINQUERY: |
| 3406 | c = *ecode++ - OP_NOTSTAR; | case OP_NOTMINQUERYI: |
| 3407 | c = *ecode++ - ((op >= OP_NOTSTARI)? OP_NOTSTARI: OP_NOTSTAR); | |
| 3408 | minimize = (c & 1) != 0; | minimize = (c & 1) != 0; |
| 3409 | min = rep_min[c]; /* Pick up values from tables; */ | min = rep_min[c]; /* Pick up values from tables; */ |
| 3410 | max = rep_max[c]; /* zero for max => infinity */ | max = rep_max[c]; /* zero for max => infinity */ |
| 3411 | if (max == 0) max = INT_MAX; | if (max == 0) max = INT_MAX; |
| 3412 | ||
| 3413 | /* Common code for all repeated single-byte matches. We can give up quickly | /* Common code for all repeated single-byte matches. */ |
| if there are fewer than the minimum number of bytes left in the | ||
| subject. */ | ||
| 3414 | ||
| 3415 | REPEATNOTCHAR: | REPEATNOTCHAR: |
| if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | ||
| 3416 | fc = *ecode++; | fc = *ecode++; |
| 3417 | ||
| 3418 | /* The code is duplicated for the caseless and caseful cases, for speed, | /* The code is duplicated for the caseless and caseful cases, for speed, |
| # | Line 2489 for (;;) | Line 3426 for (;;) |
| 3426 | DPRINTF(("negative matching %c{%d,%d} against subject %.*s\n", fc, min, max, | DPRINTF(("negative matching %c{%d,%d} against subject %.*s\n", fc, min, max, |
| 3427 | max, eptr)); | max, eptr)); |
| 3428 | ||
| 3429 | if ((ims & PCRE_CASELESS) != 0) | if (op >= OP_NOTSTARI) /* Caseless */ |
| 3430 | { | { |
| 3431 | fc = md->lcc[fc]; | fc = md->lcc[fc]; |
| 3432 | ||
| # | Line 2500 for (;;) | Line 3437 for (;;) |
| 3437 | register unsigned int d; | register unsigned int d; |
| 3438 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3439 | { | { |
| 3440 | GETCHARINC(d, eptr); | if (eptr >= md->end_subject) |
| 3441 | { | |
| 3442 | SCHECK_PARTIAL(); | |
| 3443 | MRRETURN(MATCH_NOMATCH); | |
| 3444 | } | |
| 3445 | GETCHARINC(d, eptr); | |
| 3446 | if (d < 256) d = md->lcc[d]; | if (d < 256) d = md->lcc[d]; |
| 3447 | if (fc == d) RRETURN(MATCH_NOMATCH); | if (fc == d) MRRETURN(MATCH_NOMATCH); |
| 3448 | } | } |
| 3449 | } | } |
| 3450 | else | else |
| # | Line 2511 for (;;) | Line 3453 for (;;) |
| 3453 | /* Not UTF-8 mode */ | /* Not UTF-8 mode */ |
| 3454 | { | { |
| 3455 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3456 | if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | { |
| 3457 | if (eptr >= md->end_subject) | |
| 3458 | { | |
| 3459 | SCHECK_PARTIAL(); | |
| 3460 | MRRETURN(MATCH_NOMATCH); | |
| 3461 | } | |
| 3462 | if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH); | |
| 3463 | } | |
| 3464 | } | } |
| 3465 | ||
| 3466 | if (min == max) continue; | if (min == max) continue; |
| # | Line 2525 for (;;) | Line 3474 for (;;) |
| 3474 | register unsigned int d; | register unsigned int d; |
| 3475 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3476 | { | { |
| 3477 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM28); |
| 3478 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3479 | if (fi >= max) MRRETURN(MATCH_NOMATCH); | |
| 3480 | if (eptr >= md->end_subject) | |
| 3481 | { | |
| 3482 | SCHECK_PARTIAL(); | |
| 3483 | MRRETURN(MATCH_NOMATCH); | |
| 3484 | } | |
| 3485 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
| 3486 | if (d < 256) d = md->lcc[d]; | if (d < 256) d = md->lcc[d]; |
| 3487 | if (fi >= max || eptr >= md->end_subject || fc == d) | if (fc == d) MRRETURN(MATCH_NOMATCH); |
| RRETURN(MATCH_NOMATCH); | ||
| 3488 | } | } |
| 3489 | } | } |
| 3490 | else | else |
| # | Line 2539 for (;;) | Line 3493 for (;;) |
| 3493 | { | { |
| 3494 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3495 | { | { |
| 3496 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM29); |
| 3497 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3498 | if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++]) | if (fi >= max) MRRETURN(MATCH_NOMATCH); |
| 3499 | RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3500 | { | |
| 3501 | SCHECK_PARTIAL(); | |
| 3502 | MRRETURN(MATCH_NOMATCH); | |
| 3503 | } | |
| 3504 | if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH); | |
| 3505 | } | } |
| 3506 | } | } |
| 3507 | /* Control never gets here */ | /* Control never gets here */ |
| # | Line 2562 for (;;) | Line 3521 for (;;) |
| 3521 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 3522 | { | { |
| 3523 | int len = 1; | int len = 1; |
| 3524 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) |
| 3525 | { | |
| 3526 | SCHECK_PARTIAL(); | |
| 3527 | break; | |
| 3528 | } | |
| 3529 | GETCHARLEN(d, eptr, len); | GETCHARLEN(d, eptr, len); |
| 3530 | if (d < 256) d = md->lcc[d]; | if (d < 256) d = md->lcc[d]; |
| 3531 | if (fc == d) break; | if (fc == d) break; |
| # | Line 2571 for (;;) | Line 3534 for (;;) |
| 3534 | if (possessive) continue; | if (possessive) continue; |
| 3535 | for(;;) | for(;;) |
| 3536 | { | { |
| 3537 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM30); |
| 3538 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3539 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 3540 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| # | Line 2583 for (;;) | Line 3546 for (;;) |
| 3546 | { | { |
| 3547 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 3548 | { | { |
| 3549 | if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break; | if (eptr >= md->end_subject) |
| 3550 | { | |
| 3551 | SCHECK_PARTIAL(); | |
| 3552 | break; | |
| 3553 | } | |
| 3554 | if (fc == md->lcc[*eptr]) break; | |
| 3555 | eptr++; | eptr++; |
| 3556 | } | } |
| 3557 | if (possessive) continue; | if (possessive) continue; |
| 3558 | while (eptr >= pp) | while (eptr >= pp) |
| 3559 | { | { |
| 3560 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM31); |
| 3561 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3562 | eptr--; | eptr--; |
| 3563 | } | } |
| 3564 | } | } |
| 3565 | ||
| 3566 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 3567 | } | } |
| 3568 | /* Control never gets here */ | /* Control never gets here */ |
| 3569 | } | } |
| # | Line 2611 for (;;) | Line 3579 for (;;) |
| 3579 | register unsigned int d; | register unsigned int d; |
| 3580 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3581 | { | { |
| 3582 | if (eptr >= md->end_subject) | |
| 3583 | { | |
| 3584 | SCHECK_PARTIAL(); | |
| 3585 | MRRETURN(MATCH_NOMATCH); | |
| 3586 | } | |
| 3587 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
| 3588 | if (fc == d) RRETURN(MATCH_NOMATCH); | if (fc == d) MRRETURN(MATCH_NOMATCH); |
| 3589 | } | } |
| 3590 | } | } |
| 3591 | else | else |
| # | Line 2620 for (;;) | Line 3593 for (;;) |
| 3593 | /* Not UTF-8 mode */ | /* Not UTF-8 mode */ |
| 3594 | { | { |
| 3595 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3596 | if (fc == *eptr++) RRETURN(MATCH_NOMATCH); | { |
| 3597 | if (eptr >= md->end_subject) | |
| 3598 | { | |
| 3599 | SCHECK_PARTIAL(); | |
| 3600 | MRRETURN(MATCH_NOMATCH); | |
| 3601 | } | |
| 3602 | if (fc == *eptr++) MRRETURN(MATCH_NOMATCH); | |
| 3603 | } | |
| 3604 | } | } |
| 3605 | ||
| 3606 | if (min == max) continue; | if (min == max) continue; |
| # | Line 2634 for (;;) | Line 3614 for (;;) |
| 3614 | register unsigned int d; | register unsigned int d; |
| 3615 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3616 | { | { |
| 3617 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM32); |
| 3618 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3619 | if (fi >= max) MRRETURN(MATCH_NOMATCH); | |
| 3620 | if (eptr >= md->end_subject) | |
| 3621 | { | |
| 3622 | SCHECK_PARTIAL(); | |
| 3623 | MRRETURN(MATCH_NOMATCH); | |
| 3624 | } | |
| 3625 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
| 3626 | if (fi >= max || eptr >= md->end_subject || fc == d) | if (fc == d) MRRETURN(MATCH_NOMATCH); |
| RRETURN(MATCH_NOMATCH); | ||
| 3627 | } | } |
| 3628 | } | } |
| 3629 | else | else |
| # | Line 2647 for (;;) | Line 3632 for (;;) |
| 3632 | { | { |
| 3633 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3634 | { | { |
| 3635 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM33); |
| 3636 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3637 | if (fi >= max || eptr >= md->end_subject || fc == *eptr++) | if (fi >= max) MRRETURN(MATCH_NOMATCH); |
| 3638 | RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3639 | { | |
| 3640 | SCHECK_PARTIAL(); | |
| 3641 | MRRETURN(MATCH_NOMATCH); | |
| 3642 | } | |
| 3643 | if (fc == *eptr++) MRRETURN(MATCH_NOMATCH); | |
| 3644 | } | } |
| 3645 | } | } |
| 3646 | /* Control never gets here */ | /* Control never gets here */ |
| # | Line 2670 for (;;) | Line 3660 for (;;) |
| 3660 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 3661 | { | { |
| 3662 | int len = 1; | int len = 1; |
| 3663 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) |
| 3664 | { | |
| 3665 | SCHECK_PARTIAL(); | |
| 3666 | break; | |
| 3667 | } | |
| 3668 | GETCHARLEN(d, eptr, len); | GETCHARLEN(d, eptr, len); |
| 3669 | if (fc == d) break; | if (fc == d) break; |
| 3670 | eptr += len; | eptr += len; |
| # | Line 2678 for (;;) | Line 3672 for (;;) |
| 3672 | if (possessive) continue; | if (possessive) continue; |
| 3673 | for(;;) | for(;;) |
| 3674 | { | { |
| 3675 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM34); |
| 3676 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3677 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 3678 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| # | Line 2690 for (;;) | Line 3684 for (;;) |
| 3684 | { | { |
| 3685 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 3686 | { | { |
| 3687 | if (eptr >= md->end_subject || fc == *eptr) break; | if (eptr >= md->end_subject) |
| 3688 | { | |
| 3689 | SCHECK_PARTIAL(); | |
| 3690 | break; | |
| 3691 | } | |
| 3692 | if (fc == *eptr) break; | |
| 3693 | eptr++; | eptr++; |
| 3694 | } | } |
| 3695 | if (possessive) continue; | if (possessive) continue; |
| 3696 | while (eptr >= pp) | while (eptr >= pp) |
| 3697 | { | { |
| 3698 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM35); |
| 3699 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3700 | eptr--; | eptr--; |
| 3701 | } | } |
| 3702 | } | } |
| 3703 | ||
| 3704 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 3705 | } | } |
| 3706 | } | } |
| 3707 | /* Control never gets here */ | /* Control never gets here */ |
| # | Line 2784 for (;;) | Line 3783 for (;;) |
| 3783 | ||
| 3784 | /* First, ensure the minimum number of matches are present. Use inline | /* First, ensure the minimum number of matches are present. Use inline |
| 3785 | code for maximizing the speed, and do the type test once at the start | code for maximizing the speed, and do the type test once at the start |
| 3786 | (i.e. keep it out of the loop). Also we can test that there are at least | (i.e. keep it out of the loop). Separate the UTF-8 code completely as that |
| the minimum number of bytes before we start. This isn't as effective in | ||
| UTF-8 mode, but it does no harm. Separate the UTF-8 code completely as that | ||
| 3787 | is tidier. Also separate the UCP code, which can be the same for both UTF-8 | is tidier. Also separate the UCP code, which can be the same for both UTF-8 |
| 3788 | and single-bytes. */ | and single-bytes. */ |
| 3789 | ||
| if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | ||
| 3790 | if (min > 0) | if (min > 0) |
| 3791 | { | { |
| 3792 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| # | Line 2799 for (;;) | Line 3795 for (;;) |
| 3795 | switch(prop_type) | switch(prop_type) |
| 3796 | { | { |
| 3797 | case PT_ANY: | case PT_ANY: |
| 3798 | if (prop_fail_result) RRETURN(MATCH_NOMATCH); | if (prop_fail_result) MRRETURN(MATCH_NOMATCH); |
| 3799 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3800 | { | { |
| 3801 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3802 | { | |
| 3803 | SCHECK_PARTIAL(); | |
| 3804 | MRRETURN(MATCH_NOMATCH); | |
| 3805 | } | |
| 3806 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 3807 | } | } |
| 3808 | break; | break; |
| # | Line 2810 for (;;) | Line 3810 for (;;) |
| 3810 | case PT_LAMP: | case PT_LAMP: |
| 3811 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3812 | { | { |
| 3813 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3814 | { | |
| 3815 | SCHECK_PARTIAL(); | |
| 3816 | MRRETURN(MATCH_NOMATCH); | |
| 3817 | } | |
| 3818 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 3819 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_chartype = UCD_CHARTYPE(c); |
| 3820 | if ((prop_chartype == ucp_Lu || | if ((prop_chartype == ucp_Lu || |
| 3821 | prop_chartype == ucp_Ll || | prop_chartype == ucp_Ll || |
| 3822 | prop_chartype == ucp_Lt) == prop_fail_result) | prop_chartype == ucp_Lt) == prop_fail_result) |
| 3823 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 3824 | } | } |
| 3825 | break; | break; |
| 3826 | ||
| 3827 | case PT_GC: | case PT_GC: |
| 3828 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3829 | { | { |
| 3830 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3831 | { | |
| 3832 | SCHECK_PARTIAL(); | |
| 3833 | MRRETURN(MATCH_NOMATCH); | |
| 3834 | } | |
| 3835 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 3836 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_category = UCD_CATEGORY(c); |
| 3837 | if ((prop_category == prop_value) == prop_fail_result) | if ((prop_category == prop_value) == prop_fail_result) |
| 3838 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 3839 | } | } |
| 3840 | break; | break; |
| 3841 | ||
| 3842 | case PT_PC: | case PT_PC: |
| 3843 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3844 | { | { |
| 3845 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3846 | { | |
| 3847 | SCHECK_PARTIAL(); | |
| 3848 | MRRETURN(MATCH_NOMATCH); | |
| 3849 | } | |
| 3850 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 3851 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_chartype = UCD_CHARTYPE(c); |
| 3852 | if ((prop_chartype == prop_value) == prop_fail_result) | if ((prop_chartype == prop_value) == prop_fail_result) |
| 3853 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 3854 | } | } |
| 3855 | break; | break; |
| 3856 | ||
| 3857 | case PT_SC: | case PT_SC: |
| 3858 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3859 | { | { |
| 3860 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3861 | { | |
| 3862 | SCHECK_PARTIAL(); | |
| 3863 | MRRETURN(MATCH_NOMATCH); | |
| 3864 | } | |
| 3865 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 3866 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_script = UCD_SCRIPT(c); |
| 3867 | if ((prop_script == prop_value) == prop_fail_result) | if ((prop_script == prop_value) == prop_fail_result) |
| 3868 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
| 3869 | } | |
| 3870 | break; | |
| 3871 | ||
| 3872 | case PT_ALNUM: | |
| 3873 | for (i = 1; i <= min; i++) | |
| 3874 | { | |
| 3875 | if (eptr >= md->end_subject) | |
| 3876 | { | |
| 3877 | SCHECK_PARTIAL(); | |
| 3878 | MRRETURN(MATCH_NOMATCH); | |
| 3879 | } | |
| 3880 | GETCHARINCTEST(c, eptr); | |
| 3881 | prop_category = UCD_CATEGORY(c); | |
| 3882 | if ((prop_category == ucp_L || prop_category == ucp_N) | |
| 3883 | == prop_fail_result) | |
| 3884 | MRRETURN(MATCH_NOMATCH); | |
| 3885 | } | |
| 3886 | break; | |
| 3887 | ||
| 3888 | case PT_SPACE: /* Perl space */ | |
| 3889 | for (i = 1; i <= min; i++) | |
| 3890 | { | |
| 3891 | if (eptr >= md->end_subject) | |
| 3892 | { | |
| 3893 | SCHECK_PARTIAL(); | |
| 3894 | MRRETURN(MATCH_NOMATCH); | |
| 3895 | } | |
| 3896 | GETCHARINCTEST(c, eptr); | |
| 3897 | prop_category = UCD_CATEGORY(c); | |
| 3898 | if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL || | |
| 3899 | c == CHAR_FF || c == CHAR_CR) | |
| 3900 | == prop_fail_result) | |
| 3901 | MRRETURN(MATCH_NOMATCH); | |
| 3902 | } | |
| 3903 | break; | |
| 3904 | ||
| 3905 | case PT_PXSPACE: /* POSIX space */ | |
| 3906 | for (i = 1; i <= min; i++) | |
| 3907 | { | |
| 3908 | if (eptr >= md->end_subject) | |
| 3909 | { | |
| 3910 | SCHECK_PARTIAL(); | |
| 3911 | MRRETURN(MATCH_NOMATCH); | |
| 3912 | } | |
| 3913 | GETCHARINCTEST(c, eptr); | |
| 3914 | prop_category = UCD_CATEGORY(c); | |
| 3915 | if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL || | |
| 3916 | c == CHAR_VT || c == CHAR_FF || c == CHAR_CR) | |
| 3917 | == prop_fail_result) | |
| 3918 | MRRETURN(MATCH_NOMATCH); | |
| 3919 | } | |
| 3920 | break; | |
| 3921 | ||
| 3922 | case PT_WORD: | |
| 3923 | for (i = 1; i <= min; i++) | |
| 3924 | { | |
| 3925 | if (eptr >= md->end_subject) | |
| 3926 | { | |
| 3927 | SCHECK_PARTIAL(); | |
| 3928 | MRRETURN(MATCH_NOMATCH); | |
| 3929 | } | |
| 3930 | GETCHARINCTEST(c, eptr); | |
| 3931 | prop_category = UCD_CATEGORY(c); | |
| 3932 | if ((prop_category == ucp_L || prop_category == ucp_N || | |
| 3933 | c == CHAR_UNDERSCORE) | |
| 3934 | == prop_fail_result) | |
| 3935 | MRRETURN(MATCH_NOMATCH); | |
| 3936 | } | } |
| 3937 | break; | break; |
| 3938 | ||
| 3939 | /* This should not occur */ | |
| 3940 | ||
| 3941 | default: | default: |
| 3942 | RRETURN(PCRE_ERROR_INTERNAL); | RRETURN(PCRE_ERROR_INTERNAL); |
| 3943 | } | } |
| # | Line 2865 for (;;) | Line 3950 for (;;) |