~ubuntu-branches/ubuntu/trusty/pcre3/trusty

« back to all changes in this revision

Viewing changes to pcre_exec.c

  • Committer: Package Import Robot
  • Author(s): Mark Baker
  • Date: 2012-03-23 22:34:54 UTC
  • mfrom: (23.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20120323223454-grhqqolk8a7x1h24
Tags: 1:8.30-4
* Reluctantly using an epoch, as it seems the funny version number with
  extra dots causes problems
* Bumped standard version to 3.9.3. No changes needed
* Converted to use new source format / quilt
* Put back obsolete pcre_info() API that upstream have dropped (Closes:
  #665300, #665356)
* Don't include pcregrep binary in debug package

Thanks to Elimar Riesebieter for the conversion to the new source format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
and semantics are as close as possible to those of the Perl 5 language.
7
7
 
8
8
                       Written by Philip Hazel
9
 
           Copyright (c) 1997-2010 University of Cambridge
 
9
           Copyright (c) 1997-2012 University of Cambridge
10
10
 
11
11
-----------------------------------------------------------------------------
12
12
Redistribution and use in source and binary forms, with or without
57
57
#undef min
58
58
#undef max
59
59
 
60
 
/* Flag bits for the match() function */
 
60
/* 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. */
61
63
 
62
 
#define match_condassert     0x01  /* Called to check a condition assertion */
63
 
#define match_cbegroup       0x02  /* Could-be-empty unlimited repeat group */
 
64
#define MATCH_CONDASSERT     1  /* Called to check a condition assertion */
 
65
#define MATCH_CBEGROUP       2  /* Could-be-empty unlimited repeat group */
64
66
 
65
67
/* Non-error returns from the match() function. Error returns are externally
66
68
defined PCRE_ERROR_xxx codes, which are all negative. */
73
75
 
74
76
#define MATCH_ACCEPT       (-999)
75
77
#define MATCH_COMMIT       (-998)
76
 
#define MATCH_PRUNE        (-997)
77
 
#define MATCH_SKIP         (-996)
78
 
#define MATCH_SKIP_ARG     (-995)
79
 
#define MATCH_THEN         (-994)
80
 
 
81
 
/* This is a convenience macro for code that occurs many times. */
82
 
 
83
 
#define MRRETURN(ra) \
84
 
  { \
85
 
  md->mark = markptr; \
86
 
  RRETURN(ra); \
87
 
  }
 
78
#define MATCH_KETRPOS      (-997)
 
79
#define MATCH_ONCE         (-996)
 
80
#define MATCH_PRUNE        (-995)
 
81
#define MATCH_SKIP         (-994)
 
82
#define MATCH_SKIP_ARG     (-993)
 
83
#define MATCH_THEN         (-992)
88
84
 
89
85
/* Maximum number of ints of offset to save on the stack for recursive calls.
90
86
If the offset vector is bigger, malloc is used. This should be a multiple of 3,
117
113
*/
118
114
 
119
115
static void
120
 
pchars(const uschar *p, int length, BOOL is_subject, match_data *md)
 
116
pchars(const pcre_uchar *p, int length, BOOL is_subject, match_data *md)
121
117
{
122
118
unsigned int c;
123
119
if (is_subject && length > md->end_subject - p) length = md->end_subject - p;
132
128
*          Match a back-reference                *
133
129
*************************************************/
134
130
 
135
 
/* If a back reference hasn't been set, the length that is passed is greater
136
 
than the number of characters left in the string, so the match fails.
 
131
/* Normally, if a back reference hasn't been set, the length that is passed is
 
132
negative, so the match always fails. However, in JavaScript compatibility mode,
 
133
the length passed is zero. Note that in caseless UTF-8 mode, the number of
 
134
subject bytes matched may be different to the number of reference bytes.
137
135
 
138
136
Arguments:
139
137
  offset      index into the offset vector
140
 
  eptr        points into the subject
141
 
  length      length to be matched
 
138
  eptr        pointer into the subject
 
139
  length      length of reference to be matched (number of bytes)
142
140
  md          points to match data block
143
 
  ims         the ims flags
 
141
  caseless    TRUE if caseless
144
142
 
145
 
Returns:      TRUE if matched
 
143
Returns:      < 0 if not matched, otherwise the number of subject bytes matched
146
144
*/
147
145
 
148
 
static BOOL
149
 
match_ref(int offset, register USPTR eptr, int length, match_data *md,
150
 
  unsigned long int ims)
 
146
static int
 
147
match_ref(int offset, register PCRE_PUCHAR eptr, int length, match_data *md,
 
148
  BOOL caseless)
151
149
{
152
 
USPTR p = md->start_subject + md->offset_vector[offset];
 
150
PCRE_PUCHAR eptr_start = eptr;
 
151
register PCRE_PUCHAR p = md->start_subject + md->offset_vector[offset];
153
152
 
154
153
#ifdef PCRE_DEBUG
155
154
if (eptr >= md->end_subject)
164
163
printf("\n");
165
164
#endif
166
165
 
167
 
/* Always fail if not enough characters left */
 
166
/* Always fail if reference not set (and not JavaScript compatible). */
168
167
 
169
 
if (length > md->end_subject - eptr) return FALSE;
 
168
if (length < 0) return -1;
170
169
 
171
170
/* Separate the caseless case for speed. In UTF-8 mode we can only do this
172
171
properly if Unicode properties are supported. Otherwise, we can check only
173
172
ASCII characters. */
174
173
 
175
 
if ((ims & PCRE_CASELESS) != 0)
 
174
if (caseless)
176
175
  {
177
 
#ifdef SUPPORT_UTF8
 
176
#ifdef SUPPORT_UTF
178
177
#ifdef SUPPORT_UCP
179
 
  if (md->utf8)
 
178
  if (md->utf)
180
179
    {
181
 
    USPTR endptr = eptr + length;
182
 
    while (eptr < endptr)
 
180
    /* Match characters up to the end of the reference. NOTE: the number of
 
181
    bytes matched may differ, because there are some characters whose upper and
 
182
    lower case versions code as different numbers of bytes. For example, U+023A
 
183
    (2 bytes in UTF-8) is the upper case version of U+2C65 (3 bytes in UTF-8);
 
184
    a sequence of 3 of the former uses 6 bytes, as does a sequence of two of
 
185
    the latter. It is important, therefore, to check the length along the
 
186
    reference, not along the subject (earlier code did this wrong). */
 
187
 
 
188
    PCRE_PUCHAR endptr = p + length;
 
189
    while (p < endptr)
183
190
      {
184
191
      int c, d;
 
192
      if (eptr >= md->end_subject) return -1;
185
193
      GETCHARINC(c, eptr);
186
194
      GETCHARINC(d, p);
187
 
      if (c != d && c != UCD_OTHERCASE(d)) return FALSE;
 
195
      if (c != d && c != UCD_OTHERCASE(d)) return -1;
188
196
      }
189
197
    }
190
198
  else
193
201
 
194
202
  /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
195
203
  is no UCP support. */
196
 
 
197
 
  while (length-- > 0)
198
 
    { if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; }
 
204
    {
 
205
    if (eptr + length > md->end_subject) return -1;
 
206
    while (length-- > 0)
 
207
      {
 
208
      if (TABLE_GET(*p, md->lcc, *p) != TABLE_GET(*eptr, md->lcc, *eptr)) return -1;
 
209
      p++;
 
210
      eptr++;
 
211
      }
 
212
    }
199
213
  }
200
214
 
201
215
/* In the caseful case, we can just compare the bytes, whether or not we
202
216
are in UTF-8 mode. */
203
217
 
204
218
else
205
 
  { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
 
219
  {
 
220
  if (eptr + length > md->end_subject) return -1;
 
221
  while (length-- > 0) if (*p++ != *eptr++) return -1;
 
222
  }
206
223
 
207
 
return TRUE;
 
224
return (int)(eptr - eptr_start);
208
225
}
209
226
 
210
227
 
256
273
       RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
257
274
       RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
258
275
       RM51,  RM52, RM53, RM54, RM55, RM56, RM57, RM58, RM59, RM60,
259
 
       RM61,  RM62 };
 
276
       RM61,  RM62, RM63, RM64, RM65, RM66 };
260
277
 
261
278
/* These versions of the macros use the stack, as normal. There are debugging
262
279
versions and production versions. Note that the "rw" argument of RMATCH isn't
266
283
#define REGISTER register
267
284
 
268
285
#ifdef PCRE_DEBUG
269
 
#define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
 
286
#define RMATCH(ra,rb,rc,rd,re,rw) \
270
287
  { \
271
288
  printf("match() called in line %d\n", __LINE__); \
272
 
  rrc = match(ra,rb,mstart,markptr,rc,rd,re,rf,rg,rdepth+1); \
 
289
  rrc = match(ra,rb,mstart,rc,rd,re,rdepth+1); \
273
290
  printf("to line %d\n", __LINE__); \
274
291
  }
275
292
#define RRETURN(ra) \
278
295
  return ra; \
279
296
  }
280
297
#else
281
 
#define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
282
 
  rrc = match(ra,rb,mstart,markptr,rc,rd,re,rf,rg,rdepth+1)
 
298
#define RMATCH(ra,rb,rc,rd,re,rw) \
 
299
  rrc = match(ra,rb,mstart,rc,rd,re,rdepth+1)
283
300
#define RRETURN(ra) return ra
284
301
#endif
285
302
 
292
309
 
293
310
#define REGISTER
294
311
 
295
 
#define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\
 
312
#define RMATCH(ra,rb,rc,rd,re,rw)\
296
313
  {\
297
 
  heapframe *newframe = (heapframe *)(pcre_stack_malloc)(sizeof(heapframe));\
 
314
  heapframe *newframe = (heapframe *)(PUBL(stack_malloc))(sizeof(heapframe));\
298
315
  if (newframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\
299
316
  frame->Xwhere = rw; \
300
317
  newframe->Xeptr = ra;\
301
318
  newframe->Xecode = rb;\
302
319
  newframe->Xmstart = mstart;\
303
 
  newframe->Xmarkptr = markptr;\
304
320
  newframe->Xoffset_top = rc;\
305
 
  newframe->Xims = re;\
306
 
  newframe->Xeptrb = rf;\
307
 
  newframe->Xflags = rg;\
 
321
  newframe->Xeptrb = re;\
308
322
  newframe->Xrdepth = frame->Xrdepth + 1;\
309
323
  newframe->Xprevframe = frame;\
310
324
  frame = newframe;\
318
332
  {\
319
333
  heapframe *oldframe = frame;\
320
334
  frame = oldframe->Xprevframe;\
321
 
  (pcre_stack_free)(oldframe);\
 
335
  if (oldframe != &frame_zero) (PUBL(stack_free))(oldframe);\
322
336
  if (frame != NULL)\
323
337
    {\
324
338
    rrc = ra;\
335
349
 
336
350
  /* Function arguments that may change */
337
351
 
338
 
  USPTR Xeptr;
339
 
  const uschar *Xecode;
340
 
  USPTR Xmstart;
341
 
  USPTR Xmarkptr;
 
352
  PCRE_PUCHAR Xeptr;
 
353
  const pcre_uchar *Xecode;
 
354
  PCRE_PUCHAR Xmstart;
342
355
  int Xoffset_top;
343
 
  long int Xims;
344
356
  eptrblock *Xeptrb;
345
 
  int Xflags;
346
357
  unsigned int Xrdepth;
347
358
 
348
359
  /* Function local variables */
349
360
 
350
 
  USPTR Xcallpat;
351
 
#ifdef SUPPORT_UTF8
352
 
  USPTR Xcharptr;
 
361
  PCRE_PUCHAR Xcallpat;
 
362
#ifdef SUPPORT_UTF
 
363
  PCRE_PUCHAR Xcharptr;
353
364
#endif
354
 
  USPTR Xdata;
355
 
  USPTR Xnext;
356
 
  USPTR Xpp;
357
 
  USPTR Xprev;
358
 
  USPTR Xsaved_eptr;
 
365
  PCRE_PUCHAR Xdata;
 
366
  PCRE_PUCHAR Xnext;
 
367
  PCRE_PUCHAR Xpp;
 
368
  PCRE_PUCHAR Xprev;
 
369
  PCRE_PUCHAR Xsaved_eptr;
359
370
 
360
371
  recursion_info Xnew_recursive;
361
372
 
363
374
  BOOL Xcondition;
364
375
  BOOL Xprev_is_word;
365
376
 
366
 
  unsigned long int Xoriginal_ims;
367
 
 
368
377
#ifdef SUPPORT_UCP
369
378
  int Xprop_type;
370
379
  int Xprop_value;
371
380
  int Xprop_fail_result;
372
 
  int Xprop_category;
373
 
  int Xprop_chartype;
374
 
  int Xprop_script;
375
381
  int Xoclength;
376
 
  uschar Xocchars[8];
 
382
  pcre_uchar Xocchars[6];
377
383
#endif
378
384
 
379
385
  int Xcodelink;
415
421
same response. */
416
422
 
417
423
/* These macros pack up tests that are used for partial matching, and which
418
 
appears several times in the code. We set the "hit end" flag if the pointer is
 
424
appear several times in the code. We set the "hit end" flag if the pointer is
419
425
at the end of the subject and also past the start of the subject (i.e.
420
426
something has been matched). For hard partial matching, we then return
421
427
immediately. The second one is used when we already know we are past the end of
426
432
      eptr > md->start_used_ptr) \
427
433
    { \
428
434
    md->hitend = TRUE; \
429
 
    if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL); \
 
435
    if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); \
430
436
    }
431
437
 
432
438
#define SCHECK_PARTIAL()\
433
439
  if (md->partial != 0 && eptr > md->start_used_ptr) \
434
440
    { \
435
441
    md->hitend = TRUE; \
436
 
    if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL); \
 
442
    if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); \
437
443
    }
438
444
 
439
445
 
440
446
/* Performance note: It might be tempting to extract commonly used fields from
441
 
the md structure (e.g. utf8, end_subject) into individual variables to improve
 
447
the md structure (e.g. utf, end_subject) into individual variables to improve
442
448
performance. Tests using gcc on a SPARC disproved this; in the first case, it
443
449
made performance worse.
444
450
 
447
453
   ecode       pointer to current position in compiled code
448
454
   mstart      pointer to the current match start position (can be modified
449
455
                 by encountering \K)
450
 
   markptr     pointer to the most recent MARK name, or NULL
451
456
   offset_top  current top pointer
452
457
   md          pointer to "static" info for the match
453
 
   ims         current /i, /m, and /s options
454
458
   eptrb       pointer to chain of blocks containing eptr at start of
455
459
                 brackets - for testing for empty matches
456
 
   flags       can contain
457
 
                 match_condassert - this is an assertion condition
458
 
                 match_cbegroup - this is the start of an unlimited repeat
459
 
                   group that can match an empty string
460
460
   rdepth      the recursion depth
461
461
 
462
462
Returns:       MATCH_MATCH if matched            )  these values are >= 0
467
467
*/
468
468
 
469
469
static int
470
 
match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,
471
 
  const uschar *markptr, int offset_top, match_data *md, unsigned long int ims,
472
 
  eptrblock *eptrb, int flags, unsigned int rdepth)
 
470
match(REGISTER PCRE_PUCHAR eptr, REGISTER const pcre_uchar *ecode,
 
471
  PCRE_PUCHAR mstart, int offset_top, match_data *md, eptrblock *eptrb,
 
472
  unsigned int rdepth)
473
473
{
474
474
/* These variables do not need to be preserved over recursion in this function,
475
475
so they can be ordinary variables in all cases. Mark some of them with
478
478
register int  rrc;         /* Returns from recursive calls */
479
479
register int  i;           /* Used for loops not involving calls to RMATCH() */
480
480
register unsigned int c;   /* Character values not kept over RMATCH() calls */
481
 
register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
 
481
register BOOL utf;         /* Local copy of UTF flag for speed */
482
482
 
483
483
BOOL minimize, possessive; /* Quantifier options */
 
484
BOOL caseless;
484
485
int condcode;
485
486
 
486
487
/* When recursion is not being used, all "local" variables that have to be
487
 
preserved over calls to RMATCH() are part of a "frame" which is obtained from
488
 
heap storage. Set up the top-level frame here; others are obtained from the
489
 
heap whenever RMATCH() does a "recursion". See the macro definitions above. */
 
488
preserved over calls to RMATCH() are part of a "frame". We set up the top-level
 
489
frame on the stack here; subsequent instantiations are obtained from the heap
 
490
whenever RMATCH() does a "recursion". See the macro definitions above. Putting
 
491
the top-level on the stack rather than malloc-ing them all gives a performance
 
492
boost in many cases where there is not much "recursion". */
490
493
 
491
494
#ifdef NO_RECURSE
492
 
heapframe *frame = (heapframe *)(pcre_stack_malloc)(sizeof(heapframe));
493
 
if (frame == NULL) RRETURN(PCRE_ERROR_NOMEMORY);
 
495
heapframe frame_zero;
 
496
heapframe *frame = &frame_zero;
494
497
frame->Xprevframe = NULL;            /* Marks the top level */
495
498
 
496
499
/* Copy in the original argument variables */
498
501
frame->Xeptr = eptr;
499
502
frame->Xecode = ecode;
500
503
frame->Xmstart = mstart;
501
 
frame->Xmarkptr = markptr;
502
504
frame->Xoffset_top = offset_top;
503
 
frame->Xims = ims;
504
505
frame->Xeptrb = eptrb;
505
 
frame->Xflags = flags;
506
506
frame->Xrdepth = rdepth;
507
507
 
508
508
/* This is where control jumps back to to effect "recursion" */
514
514
#define eptr               frame->Xeptr
515
515
#define ecode              frame->Xecode
516
516
#define mstart             frame->Xmstart
517
 
#define markptr            frame->Xmarkptr
518
517
#define offset_top         frame->Xoffset_top
519
 
#define ims                frame->Xims
520
518
#define eptrb              frame->Xeptrb
521
 
#define flags              frame->Xflags
522
519
#define rdepth             frame->Xrdepth
523
520
 
524
521
/* Ditto for the local variables */
525
522
 
526
 
#ifdef SUPPORT_UTF8
 
523
#ifdef SUPPORT_UTF
527
524
#define charptr            frame->Xcharptr
528
525
#endif
529
526
#define callpat            frame->Xcallpat
540
537
#define condition          frame->Xcondition
541
538
#define prev_is_word       frame->Xprev_is_word
542
539
 
543
 
#define original_ims       frame->Xoriginal_ims
544
 
 
545
540
#ifdef SUPPORT_UCP
546
541
#define prop_type          frame->Xprop_type
547
542
#define prop_value         frame->Xprop_value
548
543
#define prop_fail_result   frame->Xprop_fail_result
549
 
#define prop_category      frame->Xprop_category
550
 
#define prop_chartype      frame->Xprop_chartype
551
 
#define prop_script        frame->Xprop_script
552
544
#define oclength           frame->Xoclength
553
545
#define occhars            frame->Xocchars
554
546
#endif
578
570
#define fi i
579
571
#define fc c
580
572
 
581
 
 
582
 
#ifdef SUPPORT_UTF8                /* Many of these variables are used only  */
583
 
const uschar *charptr;             /* in small blocks of the code. My normal */
584
 
#endif                             /* style of coding would have declared    */
585
 
const uschar *callpat;             /* them within each of those blocks.      */
586
 
const uschar *data;                /* However, in order to accommodate the   */
587
 
const uschar *next;                /* version of this code that uses an      */
588
 
USPTR         pp;                  /* external "stack" implemented on the    */
589
 
const uschar *prev;                /* heap, it is easier to declare them all */
590
 
USPTR         saved_eptr;          /* here, so the declarations can be cut   */
591
 
                                   /* out in a block. The only declarations  */
592
 
recursion_info new_recursive;      /* within blocks below are for variables  */
593
 
                                   /* that do not have to be preserved over  */
594
 
BOOL cur_is_word;                  /* a recursive call to RMATCH().          */
 
573
/* Many of the following variables are used only in small blocks of the code.
 
574
My normal style of coding would have declared them within each of those blocks.
 
575
However, in order to accommodate the version of this code that uses an external
 
576
"stack" implemented on the heap, it is easier to declare them all here, so the
 
577
declarations can be cut out in a block. The only declarations within blocks
 
578
below are for variables that do not have to be preserved over a recursive call
 
579
to RMATCH(). */
 
580
 
 
581
#ifdef SUPPORT_UTF
 
582
const pcre_uchar *charptr;
 
583
#endif
 
584
const pcre_uchar *callpat;
 
585
const pcre_uchar *data;
 
586
const pcre_uchar *next;
 
587
PCRE_PUCHAR       pp;
 
588
const pcre_uchar *prev;
 
589
PCRE_PUCHAR       saved_eptr;
 
590
 
 
591
recursion_info new_recursive;
 
592
 
 
593
BOOL cur_is_word;
595
594
BOOL condition;
596
595
BOOL prev_is_word;
597
596
 
598
 
unsigned long int original_ims;
599
 
 
600
597
#ifdef SUPPORT_UCP
601
598
int prop_type;
602
599
int prop_value;
603
600
int prop_fail_result;
604
 
int prop_category;
605
 
int prop_chartype;
606
 
int prop_script;
607
601
int oclength;
608
 
uschar occhars[8];
 
602
pcre_uchar occhars[6];
609
603
#endif
610
604
 
611
605
int codelink;
621
615
int stacksave[REC_STACK_SAVE_MAX];
622
616
 
623
617
eptrblock newptrb;
 
618
 
 
619
/* There is a special fudge for calling match() in a way that causes it to
 
620
measure the size of its basic stack frame when the stack is being used for
 
621
recursion. The second argument (ecode) being NULL triggers this behaviour. It
 
622
cannot normally ever be NULL. The return is the negated value of the frame
 
623
size. */
 
624
 
 
625
if (ecode == NULL)
 
626
  {
 
627
  if (rdepth == 0)
 
628
    return match((PCRE_PUCHAR)&rdepth, NULL, NULL, 0, NULL, NULL, 1);
 
629
  else
 
630
    {
 
631
    int len = (char *)&rdepth - (char *)eptr;
 
632
    return (len > 0)? -len : len;
 
633
    }
 
634
  }
624
635
#endif     /* NO_RECURSE */
625
636
 
 
637
/* To save space on the stack and in the heap frame, I have doubled up on some
 
638
of the local variables that are used only in localised parts of the code, but
 
639
still need to be preserved over recursive calls of match(). These macros define
 
640
the alternative names that are used. */
 
641
 
 
642
#define allow_zero    cur_is_word
 
643
#define cbegroup      condition
 
644
#define code_offset   codelink
 
645
#define condassert    condition
 
646
#define matched_once  prev_is_word
 
647
#define foc           number
 
648
#define save_mark     data
 
649
 
626
650
/* These statements are here to stop the compiler complaining about unitialized
627
651
variables. */
628
652
 
647
671
complicated macro. It has to be used in one particular way. This shouldn't,
648
672
however, impact performance when true recursion is being used. */
649
673
 
650
 
#ifdef SUPPORT_UTF8
651
 
utf8 = md->utf8;       /* Local copy of the flag */
 
674
#ifdef SUPPORT_UTF
 
675
utf = md->utf;       /* Local copy of the flag */
652
676
#else
653
 
utf8 = FALSE;
 
677
utf = FALSE;
654
678
#endif
655
679
 
656
680
/* First check that we haven't called match() too many times, or that we
659
683
if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT);
660
684
if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);
661
685
 
662
 
original_ims = ims;    /* Save for resetting on ')' */
663
 
 
664
686
/* At the start of a group with an unlimited repeat that may match an empty
665
 
string, the match_cbegroup flag is set. When this is the case, add the current
666
 
subject pointer to the chain of such remembered pointers, to be checked when we
667
 
hit the closing ket, in order to break infinite loops that match no characters.
668
 
When match() is called in other circumstances, don't add to the chain. The
669
 
match_cbegroup flag must NOT be used with tail recursion, because the memory
670
 
block that is used is on the stack, so a new one may be required for each
671
 
match(). */
672
 
 
673
 
if ((flags & match_cbegroup) != 0)
 
687
string, the variable md->match_function_type is set to MATCH_CBEGROUP. It is
 
688
done this way to save having to use another function argument, which would take
 
689
up space on the stack. See also MATCH_CONDASSERT below.
 
690
 
 
691
When MATCH_CBEGROUP is set, add the current subject pointer to the chain of
 
692
such remembered pointers, to be checked when we hit the closing ket, in order
 
693
to break infinite loops that match no characters. When match() is called in
 
694
other circumstances, don't add to the chain. The MATCH_CBEGROUP feature must
 
695
NOT be used with tail recursion, because the memory block that is used is on
 
696
the stack, so a new one may be required for each match(). */
 
697
 
 
698
if (md->match_function_type == MATCH_CBEGROUP)
674
699
  {
675
700
  newptrb.epb_saved_eptr = eptr;
676
701
  newptrb.epb_prev = eptrb;
677
702
  eptrb = &newptrb;
 
703
  md->match_function_type = 0;
678
704
  }
679
705
 
680
706
/* Now start processing the opcodes. */
687
713
  switch(op)
688
714
    {
689
715
    case OP_MARK:
690
 
    markptr = ecode + 2;
691
 
    RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
692
 
      ims, eptrb, flags, RM55);
 
716
    md->nomatch_mark = ecode + 2;
 
717
    md->mark = NULL;    /* In case previously set by assertion */
 
718
    RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode] + ecode[1], offset_top, md,
 
719
      eptrb, RM55);
 
720
    if ((rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) &&
 
721
         md->mark == NULL) md->mark = ecode + 2;
693
722
 
694
723
    /* A return of MATCH_SKIP_ARG means that matching failed at SKIP with an
695
724
    argument, and we must check whether that argument matches this MARK's
698
727
    position and return MATCH_SKIP. Otherwise, pass back the return code
699
728
    unaltered. */
700
729
 
701
 
    if (rrc == MATCH_SKIP_ARG &&
702
 
        strcmp((char *)markptr, (char *)(md->start_match_ptr)) == 0)
 
730
    else if (rrc == MATCH_SKIP_ARG &&
 
731
        STRCMP_UC_UC(ecode + 2, md->start_match_ptr) == 0)
703
732
      {
704
733
      md->start_match_ptr = eptr;
705
734
      RRETURN(MATCH_SKIP);
706
735
      }
707
 
 
708
 
    if (md->mark == NULL) md->mark = markptr;
709
736
    RRETURN(rrc);
710
737
 
711
738
    case OP_FAIL:
712
 
    MRRETURN(MATCH_NOMATCH);
 
739
    RRETURN(MATCH_NOMATCH);
713
740
 
714
741
    /* COMMIT overrides PRUNE, SKIP, and THEN */
715
742
 
716
743
    case OP_COMMIT:
717
 
    RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
718
 
      ims, eptrb, flags, RM52);
 
744
    RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
 
745
      eptrb, RM52);
719
746
    if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE &&
720
747
        rrc != MATCH_SKIP && rrc != MATCH_SKIP_ARG &&
721
748
        rrc != MATCH_THEN)
722
749
      RRETURN(rrc);
723
 
    MRRETURN(MATCH_COMMIT);
 
750
    RRETURN(MATCH_COMMIT);
724
751
 
725
752
    /* PRUNE overrides THEN */
726
753
 
727
754
    case OP_PRUNE:
728
 
    RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
729
 
      ims, eptrb, flags, RM51);
 
755
    RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
 
756
      eptrb, RM51);
730
757
    if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
731
 
    MRRETURN(MATCH_PRUNE);
 
758
    RRETURN(MATCH_PRUNE);
732
759
 
733
760
    case OP_PRUNE_ARG:
734
 
    RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
735
 
      ims, eptrb, flags, RM56);
 
761
    md->nomatch_mark = ecode + 2;
 
762
    md->mark = NULL;    /* In case previously set by assertion */
 
763
    RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode] + ecode[1], offset_top, md,
 
764
      eptrb, RM56);
 
765
    if ((rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) &&
 
766
         md->mark == NULL) md->mark = ecode + 2;
736
767
    if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
737
 
    md->mark = ecode + 2;
738
768
    RRETURN(MATCH_PRUNE);
739
769
 
740
770
    /* SKIP overrides PRUNE and THEN */
741
771
 
742
772
    case OP_SKIP:
743
 
    RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
744
 
      ims, eptrb, flags, RM53);
 
773
    RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
 
774
      eptrb, RM53);
745
775
    if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)
746
776
      RRETURN(rrc);
747
777
    md->start_match_ptr = eptr;   /* Pass back current position */
748
 
    MRRETURN(MATCH_SKIP);
 
778
    RRETURN(MATCH_SKIP);
 
779
 
 
780
    /* Note that, for Perl compatibility, SKIP with an argument does NOT set
 
781
    nomatch_mark. There is a flag that disables this opcode when re-matching a
 
782
    pattern that ended with a SKIP for which there was not a matching MARK. */
749
783
 
750
784
    case OP_SKIP_ARG:
751
 
    RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
752
 
      ims, eptrb, flags, RM57);
 
785
    if (md->ignore_skip_arg)
 
786
      {
 
787
      ecode += PRIV(OP_lengths)[*ecode] + ecode[1];
 
788
      break;
 
789
      }
 
790
    RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode] + ecode[1], offset_top, md,
 
791
      eptrb, RM57);
753
792
    if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)
754
793
      RRETURN(rrc);
755
794
 
756
795
    /* Pass back the current skip name by overloading md->start_match_ptr and
757
796
    returning the special MATCH_SKIP_ARG return code. This will either be
758
 
    caught by a matching MARK, or get to the top, where it is treated the same
759
 
    as PRUNE. */
 
797
    caught by a matching MARK, or get to the top, where it causes a rematch
 
798
    with the md->ignore_skip_arg flag set. */
760
799
 
761
800
    md->start_match_ptr = ecode + 2;
762
801
    RRETURN(MATCH_SKIP_ARG);
763
802
 
764
 
    /* For THEN (and THEN_ARG) we pass back the address of the bracket or
765
 
    the alt that is at the start of the current branch. This makes it possible
766
 
    to skip back past alternatives that precede the THEN within the current
767
 
    branch. */
 
803
    /* For THEN (and THEN_ARG) we pass back the address of the opcode, so that
 
804
    the branch in which it occurs can be determined. Overload the start of
 
805
    match pointer to do this. */
768
806
 
769
807
    case OP_THEN:
770
 
    RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
771
 
      ims, eptrb, flags, RM54);
 
808
    RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
 
809
      eptrb, RM54);
772
810
    if (rrc != MATCH_NOMATCH) RRETURN(rrc);
773
 
    md->start_match_ptr = ecode - GET(ecode, 1);
774
 
    MRRETURN(MATCH_THEN);
 
811
    md->start_match_ptr = ecode;
 
812
    RRETURN(MATCH_THEN);
775
813
 
776
814
    case OP_THEN_ARG:
777
 
    RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1+LINK_SIZE],
778
 
      offset_top, md, ims, eptrb, flags, RM58);
 
815
    md->nomatch_mark = ecode + 2;
 
816
    md->mark = NULL;    /* In case previously set by assertion */
 
817
    RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode] + ecode[1], offset_top,
 
818
      md, eptrb, RM58);
 
819
    if ((rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) &&
 
820
         md->mark == NULL) md->mark = ecode + 2;
779
821
    if (rrc != MATCH_NOMATCH) RRETURN(rrc);
780
 
    md->start_match_ptr = ecode - GET(ecode, 1);
781
 
    md->mark = ecode + LINK_SIZE + 2;
 
822
    md->start_match_ptr = ecode;
782
823
    RRETURN(MATCH_THEN);
783
824
 
784
 
    /* Handle a capturing bracket. If there is space in the offset vector, save
785
 
    the current subject position in the working slot at the top of the vector.
786
 
    We mustn't change the current values of the data slot, because they may be
787
 
    set from a previous iteration of this group, and be referred to by a
788
 
    reference inside the group.
789
 
 
790
 
    If the bracket fails to match, we need to restore this value and also the
791
 
    values of the final offsets, in case they were set by a previous iteration
792
 
    of the same bracket.
 
825
    /* Handle an atomic group that does not contain any capturing parentheses.
 
826
    This can be handled like an assertion. Prior to 8.13, all atomic groups
 
827
    were handled this way. In 8.13, the code was changed as below for ONCE, so
 
828
    that backups pass through the group and thereby reset captured values.
 
829
    However, this uses a lot more stack, so in 8.20, atomic groups that do not
 
830
    contain any captures generate OP_ONCE_NC, which can be handled in the old,
 
831
    less stack intensive way.
 
832
 
 
833
    Check the alternative branches in turn - the matching won't pass the KET
 
834
    for this kind of subpattern. If any one branch matches, we carry on as at
 
835
    the end of a normal bracket, leaving the subject pointer, but resetting
 
836
    the start-of-match value in case it was changed by \K. */
 
837
 
 
838
    case OP_ONCE_NC:
 
839
    prev = ecode;
 
840
    saved_eptr = eptr;
 
841
    save_mark = md->mark;
 
842
    do
 
843
      {
 
844
      RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM64);
 
845
      if (rrc == MATCH_MATCH)  /* Note: _not_ MATCH_ACCEPT */
 
846
        {
 
847
        mstart = md->start_match_ptr;
 
848
        break;
 
849
        }
 
850
      if (rrc == MATCH_THEN)
 
851
        {
 
852
        next = ecode + GET(ecode,1);
 
853
        if (md->start_match_ptr < next &&
 
854
            (*ecode == OP_ALT || *next == OP_ALT))
 
855
          rrc = MATCH_NOMATCH;
 
856
        }
 
857
 
 
858
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
 
859
      ecode += GET(ecode,1);
 
860
      md->mark = save_mark;
 
861
      }
 
862
    while (*ecode == OP_ALT);
 
863
 
 
864
    /* If hit the end of the group (which could be repeated), fail */
 
865
 
 
866
    if (*ecode != OP_ONCE_NC && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);
 
867
 
 
868
    /* Continue as from after the group, updating the offsets high water
 
869
    mark, since extracts may have been taken. */
 
870
 
 
871
    do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
 
872
 
 
873
    offset_top = md->end_offset_top;
 
874
    eptr = md->end_match_ptr;
 
875
 
 
876
    /* For a non-repeating ket, just continue at this level. This also
 
877
    happens for a repeating ket if no characters were matched in the group.
 
878
    This is the forcible breaking of infinite loops as implemented in Perl
 
879
    5.005. */
 
880
 
 
881
    if (*ecode == OP_KET || eptr == saved_eptr)
 
882
      {
 
883
      ecode += 1+LINK_SIZE;
 
884
      break;
 
885
      }
 
886
 
 
887
    /* The repeating kets try the rest of the pattern or restart from the
 
888
    preceding bracket, in the appropriate order. The second "call" of match()
 
889
    uses tail recursion, to avoid using another stack frame. */
 
890
 
 
891
    if (*ecode == OP_KETRMIN)
 
892
      {
 
893
      RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM65);
 
894
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
 
895
      ecode = prev;
 
896
      goto TAIL_RECURSE;
 
897
      }
 
898
    else  /* OP_KETRMAX */
 
899
      {
 
900
      md->match_function_type = MATCH_CBEGROUP;
 
901
      RMATCH(eptr, prev, offset_top, md, eptrb, RM66);
 
902
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
 
903
      ecode += 1 + LINK_SIZE;
 
904
      goto TAIL_RECURSE;
 
905
      }
 
906
    /* Control never gets here */
 
907
 
 
908
    /* Handle a capturing bracket, other than those that are possessive with an
 
909
    unlimited repeat. If there is space in the offset vector, save the current
 
910
    subject position in the working slot at the top of the vector. We mustn't
 
911
    change the current values of the data slot, because they may be set from a
 
912
    previous iteration of this group, and be referred to by a reference inside
 
913
    the group. A failure to match might occur after the group has succeeded,
 
914
    if something later on doesn't match. For this reason, we need to restore
 
915
    the working value and also the values of the final offsets, in case they
 
916
    were set by a previous iteration of the same bracket.
793
917
 
794
918
    If there isn't enough space in the offset vector, treat this as if it were
795
919
    a non-capturing bracket. Don't worry about setting the flag for the error
813
937
      save_offset2 = md->offset_vector[offset+1];
814
938
      save_offset3 = md->offset_vector[md->offset_end - number];
815
939
      save_capture_last = md->capture_last;
 
940
      save_mark = md->mark;
816
941
 
817
942
      DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
818
943
      md->offset_vector[md->offset_end - number] =
819
944
        (int)(eptr - md->start_subject);
820
945
 
821
 
      flags = (op == OP_SCBRA)? match_cbegroup : 0;
822
 
      do
 
946
      for (;;)
823
947
        {
824
 
        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
825
 
          ims, eptrb, flags, RM1);
826
 
        if (rrc != MATCH_NOMATCH &&
827
 
            (rrc != MATCH_THEN || md->start_match_ptr != ecode))
828
 
          RRETURN(rrc);
 
948
        if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
 
949
        RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
 
950
          eptrb, RM1);
 
951
        if (rrc == MATCH_ONCE) break;  /* Backing up through an atomic group */
 
952
 
 
953
        /* If we backed up to a THEN, check whether it is within the current
 
954
        branch by comparing the address of the THEN that is passed back with
 
955
        the end of the branch. If it is within the current branch, and the
 
956
        branch is one of two or more alternatives (it either starts or ends
 
957
        with OP_ALT), we have reached the limit of THEN's action, so convert
 
958
        the return code to NOMATCH, which will cause normal backtracking to
 
959
        happen from now on. Otherwise, THEN is passed back to an outer
 
960
        alternative. This implements Perl's treatment of parenthesized groups,
 
961
        where a group not containing | does not affect the current alternative,
 
962
        that is, (X) is NOT the same as (X|(*F)). */
 
963
 
 
964
        if (rrc == MATCH_THEN)
 
965
          {
 
966
          next = ecode + GET(ecode,1);
 
967
          if (md->start_match_ptr < next &&
 
968
              (*ecode == OP_ALT || *next == OP_ALT))
 
969
            rrc = MATCH_NOMATCH;
 
970
          }
 
971
 
 
972
        /* Anything other than NOMATCH is passed back. */
 
973
 
 
974
        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
829
975
        md->capture_last = save_capture_last;
830
976
        ecode += GET(ecode, 1);
 
977
        md->mark = save_mark;
 
978
        if (*ecode != OP_ALT) break;
831
979
        }
832
 
      while (*ecode == OP_ALT);
833
980
 
834
981
      DPRINTF(("bracket %d failed\n", number));
835
 
 
836
982
      md->offset_vector[offset] = save_offset1;
837
983
      md->offset_vector[offset+1] = save_offset2;
838
984
      md->offset_vector[md->offset_end - number] = save_offset3;
839
985
 
840
 
      if (rrc != MATCH_THEN) md->mark = markptr;
841
 
      RRETURN(MATCH_NOMATCH);
 
986
      /* At this point, rrc will be one of MATCH_ONCE or MATCH_NOMATCH. */
 
987
 
 
988
      RRETURN(rrc);
842
989
      }
843
990
 
844
991
    /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
852
999
    /* VVVVVVVVVVVVVVVVVVVVVVVVV */
853
1000
    /* VVVVVVVVVVVVVVVVVVVVVVVVV */
854
1001
 
855
 
    /* Non-capturing bracket. Loop for all the alternatives. When we get to the
856
 
    final alternative within the brackets, we would return the result of a
857
 
    recursive call to match() whatever happened. We can reduce stack usage by
858
 
    turning this into a tail recursion, except in the case when match_cbegroup
859
 
    is set.*/
860
 
 
 
1002
    /* Non-capturing or atomic group, except for possessive with unlimited
 
1003
    repeat and ONCE group with no captures. Loop for all the alternatives.
 
1004
 
 
1005
    When we get to the final alternative within the brackets, we used to return
 
1006
    the result of a recursive call to match() whatever happened so it was
 
1007
    possible to reduce stack usage by turning this into a tail recursion,
 
1008
    except in the case of a possibly empty group. However, now that there is
 
1009
    the possiblity of (*THEN) occurring in the final alternative, this
 
1010
    optimization is no longer always possible.
 
1011
 
 
1012
    We can optimize if we know there are no (*THEN)s in the pattern; at present
 
1013
    this is the best that can be done.
 
1014
 
 
1015
    MATCH_ONCE is returned when the end of an atomic group is successfully
 
1016
    reached, but subsequent matching fails. It passes back up the tree (causing
 
1017
    captured values to be reset) until the original atomic group level is
 
1018
    reached. This is tested by comparing md->once_target with the start of the
 
1019
    group. At this point, the return is converted into MATCH_NOMATCH so that
 
1020
    previous backup points can be taken. */
 
1021
 
 
1022
    case OP_ONCE:
861
1023
    case OP_BRA:
862
1024
    case OP_SBRA:
863
1025
    DPRINTF(("start non-capturing bracket\n"));
864
 
    flags = (op >= OP_SBRA)? match_cbegroup : 0;
865
 
    for (;;)
866
 
      {
867
 
      if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */
868
 
        {
869
 
        if (flags == 0)    /* Not a possibly empty group */
870
 
          {
871
 
          ecode += _pcre_OP_lengths[*ecode];
872
 
          DPRINTF(("bracket 0 tail recursion\n"));
873
 
          goto TAIL_RECURSE;
874
 
          }
875
 
 
876
 
        /* Possibly empty group; can't use tail recursion. */
877
 
 
878
 
        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
879
 
          eptrb, flags, RM48);
880
 
        if (rrc == MATCH_NOMATCH) md->mark = markptr;
881
 
        RRETURN(rrc);
882
 
        }
883
 
 
884
 
      /* For non-final alternatives, continue the loop for a NOMATCH result;
885
 
      otherwise return. */
886
 
 
887
 
      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
888
 
        eptrb, flags, RM2);
889
 
      if (rrc != MATCH_NOMATCH &&
890
 
          (rrc != MATCH_THEN || md->start_match_ptr != ecode))
891
 
        RRETURN(rrc);
892
 
      ecode += GET(ecode, 1);
893
 
      }
 
1026
 
 
1027
    for (;;)
 
1028
      {
 
1029
      if (op >= OP_SBRA || op == OP_ONCE) md->match_function_type = MATCH_CBEGROUP;
 
1030
 
 
1031
      /* If this is not a possibly empty group, and there are no (*THEN)s in
 
1032
      the pattern, and this is the final alternative, optimize as described
 
1033
      above. */
 
1034
 
 
1035
      else if (!md->hasthen && ecode[GET(ecode, 1)] != OP_ALT)
 
1036
        {
 
1037
        ecode += PRIV(OP_lengths)[*ecode];
 
1038
        goto TAIL_RECURSE;
 
1039
        }
 
1040
 
 
1041
      /* In all other cases, we have to make another call to match(). */
 
1042
 
 
1043
      save_mark = md->mark;
 
1044
      RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md, eptrb,
 
1045
        RM2);
 
1046
 
 
1047
      /* See comment in the code for capturing groups above about handling
 
1048
      THEN. */
 
1049
 
 
1050
      if (rrc == MATCH_THEN)
 
1051
        {
 
1052
        next = ecode + GET(ecode,1);
 
1053
        if (md->start_match_ptr < next &&
 
1054
            (*ecode == OP_ALT || *next == OP_ALT))
 
1055
          rrc = MATCH_NOMATCH;
 
1056
        }
 
1057
 
 
1058
      if (rrc != MATCH_NOMATCH)
 
1059
        {
 
1060
        if (rrc == MATCH_ONCE)
 
1061
          {
 
1062
          const pcre_uchar *scode = ecode;
 
1063
          if (*scode != OP_ONCE)           /* If not at start, find it */
 
1064
            {
 
1065
            while (*scode == OP_ALT) scode += GET(scode, 1);
 
1066
            scode -= GET(scode, 1);
 
1067
            }
 
1068
          if (md->once_target == scode) rrc = MATCH_NOMATCH;
 
1069
          }
 
1070
        RRETURN(rrc);
 
1071
        }
 
1072
      ecode += GET(ecode, 1);
 
1073
      md->mark = save_mark;
 
1074
      if (*ecode != OP_ALT) break;
 
1075
      }
 
1076
 
 
1077
    RRETURN(MATCH_NOMATCH);
 
1078
 
 
1079
    /* Handle possessive capturing brackets with an unlimited repeat. We come
 
1080
    here from BRAZERO with allow_zero set TRUE. The offset_vector values are
 
1081
    handled similarly to the normal case above. However, the matching is
 
1082
    different. The end of these brackets will always be OP_KETRPOS, which
 
1083
    returns MATCH_KETRPOS without going further in the pattern. By this means
 
1084
    we can handle the group by iteration rather than recursion, thereby
 
1085
    reducing the amount of stack needed. */
 
1086
 
 
1087
    case OP_CBRAPOS:
 
1088
    case OP_SCBRAPOS:
 
1089
    allow_zero = FALSE;
 
1090
 
 
1091
    POSSESSIVE_CAPTURE:
 
1092
    number = GET2(ecode, 1+LINK_SIZE);
 
1093
    offset = number << 1;
 
1094
 
 
1095
#ifdef PCRE_DEBUG
 
1096
    printf("start possessive bracket %d\n", number);
 
1097
    printf("subject=");
 
1098
    pchars(eptr, 16, TRUE, md);
 
1099
    printf("\n");
 
1100
#endif
 
1101
 
 
1102
    if (offset < md->offset_max)
 
1103
      {
 
1104
      matched_once = FALSE;
 
1105
      code_offset = (int)(ecode - md->start_code);
 
1106
 
 
1107
      save_offset1 = md->offset_vector[offset];
 
1108
      save_offset2 = md->offset_vector[offset+1];
 
1109
      save_offset3 = md->offset_vector[md->offset_end - number];
 
1110
      save_capture_last = md->capture_last;
 
1111
 
 
1112
      DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
 
1113
 
 
1114
      /* Each time round the loop, save the current subject position for use
 
1115
      when the group matches. For MATCH_MATCH, the group has matched, so we
 
1116
      restart it with a new subject starting position, remembering that we had
 
1117
      at least one match. For MATCH_NOMATCH, carry on with the alternatives, as
 
1118
      usual. If we haven't matched any alternatives in any iteration, check to
 
1119
      see if a previous iteration matched. If so, the group has matched;
 
1120
      continue from afterwards. Otherwise it has failed; restore the previous
 
1121
      capture values before returning NOMATCH. */
 
1122
 
 
1123
      for (;;)
 
1124
        {
 
1125
        md->offset_vector[md->offset_end - number] =
 
1126
          (int)(eptr - md->start_subject);
 
1127
        if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
 
1128
        RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
 
1129
          eptrb, RM63);
 
1130
        if (rrc == MATCH_KETRPOS)
 
1131
          {
 
1132
          offset_top = md->end_offset_top;
 
1133
          eptr = md->end_match_ptr;
 
1134
          ecode = md->start_code + code_offset;
 
1135
          save_capture_last = md->capture_last;
 
1136
          matched_once = TRUE;
 
1137
          continue;
 
1138
          }
 
1139
 
 
1140
        /* See comment in the code for capturing groups above about handling
 
1141
        THEN. */
 
1142
 
 
1143
        if (rrc == MATCH_THEN)
 
1144
          {
 
1145
          next = ecode + GET(ecode,1);
 
1146
          if (md->start_match_ptr < next &&
 
1147
              (*ecode == OP_ALT || *next == OP_ALT))
 
1148
            rrc = MATCH_NOMATCH;
 
1149
          }
 
1150
 
 
1151
        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
 
1152
        md->capture_last = save_capture_last;
 
1153
        ecode += GET(ecode, 1);
 
1154
        if (*ecode != OP_ALT) break;
 
1155
        }
 
1156
 
 
1157
      if (!matched_once)
 
1158
        {
 
1159
        md->offset_vector[offset] = save_offset1;
 
1160
        md->offset_vector[offset+1] = save_offset2;
 
1161
        md->offset_vector[md->offset_end - number] = save_offset3;
 
1162
        }
 
1163
 
 
1164
      if (allow_zero || matched_once)
 
1165
        {
 
1166
        ecode += 1 + LINK_SIZE;
 
1167
        break;
 
1168
        }
 
1169
 
 
1170
      RRETURN(MATCH_NOMATCH);
 
1171
      }
 
1172
 
 
1173
    /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
 
1174
    as a non-capturing bracket. */
 
1175
 
 
1176
    /* VVVVVVVVVVVVVVVVVVVVVVVVV */
 
1177
    /* VVVVVVVVVVVVVVVVVVVVVVVVV */
 
1178
 
 
1179
    DPRINTF(("insufficient capture room: treat as non-capturing\n"));
 
1180
 
 
1181
    /* VVVVVVVVVVVVVVVVVVVVVVVVV */
 
1182
    /* VVVVVVVVVVVVVVVVVVVVVVVVV */
 
1183
 
 
1184
    /* Non-capturing possessive bracket with unlimited repeat. We come here
 
1185
    from BRAZERO with allow_zero = TRUE. The code is similar to the above,
 
1186
    without the capturing complication. It is written out separately for speed
 
1187
    and cleanliness. */
 
1188
 
 
1189
    case OP_BRAPOS:
 
1190
    case OP_SBRAPOS:
 
1191
    allow_zero = FALSE;
 
1192
 
 
1193
    POSSESSIVE_NON_CAPTURE:
 
1194
    matched_once = FALSE;
 
1195
    code_offset = (int)(ecode - md->start_code);
 
1196
 
 
1197
    for (;;)
 
1198
      {
 
1199
      if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
 
1200
      RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
 
1201
        eptrb, RM48);
 
1202
      if (rrc == MATCH_KETRPOS)
 
1203
        {
 
1204
        offset_top = md->end_offset_top;
 
1205
        eptr = md->end_match_ptr;
 
1206
        ecode = md->start_code + code_offset;
 
1207
        matched_once = TRUE;
 
1208
        continue;
 
1209
        }
 
1210
 
 
1211
      /* See comment in the code for capturing groups above about handling
 
1212
      THEN. */
 
1213
 
 
1214
      if (rrc == MATCH_THEN)
 
1215
        {
 
1216
        next = ecode + GET(ecode,1);
 
1217
        if (md->start_match_ptr < next &&
 
1218
            (*ecode == OP_ALT || *next == OP_ALT))
 
1219
          rrc = MATCH_NOMATCH;
 
1220
        }
 
1221
 
 
1222
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
 
1223
      ecode += GET(ecode, 1);
 
1224
      if (*ecode != OP_ALT) break;
 
1225
      }
 
1226
 
 
1227
    if (matched_once || allow_zero)
 
1228
      {
 
1229
      ecode += 1 + LINK_SIZE;
 
1230
      break;
 
1231
      }
 
1232
    RRETURN(MATCH_NOMATCH);
 
1233
 
894
1234
    /* Control never reaches here. */
895
1235
 
896
1236
    /* Conditional group: compilation checked that there are no more than
897
1237
    two branches. If the condition is false, skipping the first branch takes us
898
1238
    past the end if there is only one branch, but that's OK because that is
899
 
    exactly what going to the ket would do. As there is only one branch to be
900
 
    obeyed, we can use tail recursion to avoid using another stack frame. */
 
1239
    exactly what going to the ket would do. */
901
1240
 
902
1241
    case OP_COND:
903
1242
    case OP_SCOND:
904
 
    codelink= GET(ecode, 1);
 
1243
    codelink = GET(ecode, 1);
905
1244
 
906
1245
    /* Because of the way auto-callout works during compile, a callout item is
907
1246
    inserted between OP_COND and an assertion condition. */
908
1247
 
909
1248
    if (ecode[LINK_SIZE+1] == OP_CALLOUT)
910
1249
      {
911
 
      if (pcre_callout != NULL)
 
1250
      if (PUBL(callout) != NULL)
912
1251
        {
913
 
        pcre_callout_block cb;
914
 
        cb.version          = 1;   /* Version 1 of the callout block */
 
1252
        PUBL(callout_block) cb;
 
1253
        cb.version          = 2;   /* Version 1 of the callout block */
915
1254
        cb.callout_number   = ecode[LINK_SIZE+2];
916
1255
        cb.offset_vector    = md->offset_vector;
 
1256
#ifdef COMPILE_PCRE8
917
1257
        cb.subject          = (PCRE_SPTR)md->start_subject;
 
1258
#else
 
1259
        cb.subject          = (PCRE_SPTR16)md->start_subject;
 
1260
#endif
918
1261
        cb.subject_length   = (int)(md->end_subject - md->start_subject);
919
1262
        cb.start_match      = (int)(mstart - md->start_subject);
920
1263
        cb.current_position = (int)(eptr - md->start_subject);
923
1266
        cb.capture_top      = offset_top/2;
924
1267
        cb.capture_last     = md->capture_last;
925
1268
        cb.callout_data     = md->callout_data;
926
 
        if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH);
 
1269
        cb.mark             = md->nomatch_mark;
 
1270
        if ((rrc = (*PUBL(callout))(&cb)) > 0) RRETURN(MATCH_NOMATCH);
927
1271
        if (rrc < 0) RRETURN(rrc);
928
1272
        }
929
 
      ecode += _pcre_OP_lengths[OP_CALLOUT];
 
1273
      ecode += PRIV(OP_lengths)[OP_CALLOUT];
930
1274
      }
931
1275
 
932
1276
    condcode = ecode[LINK_SIZE+1];
943
1287
      else
944
1288
        {
945
1289
        int recno = GET2(ecode, LINK_SIZE + 2);   /* Recursion group number*/
946
 
        condition =  (recno == RREF_ANY || recno == md->recursive->group_num);
 
1290
        condition = (recno == RREF_ANY || recno == md->recursive->group_num);
947
1291
 
948
1292
        /* If the test is for recursion into a specific subpattern, and it is
949
1293
        false, but the test was set up by name, scan the table to see if the
950
1294
        name refers to any other numbers, and test them. The condition is true
951
1295
        if any one is set. */
952
1296
 
953
 
        if (!condition && condcode == OP_NRREF && recno != RREF_ANY)
 
1297
        if (!condition && condcode == OP_NRREF)
954
1298
          {
955
 
          uschar *slotA = md->name_table;
 
1299
          pcre_uchar *slotA = md->name_table;
956
1300
          for (i = 0; i < md->name_count; i++)
957
1301
            {
958
1302
            if (GET2(slotA, 0) == recno) break;
965
1309
 
966
1310
          if (i < md->name_count)
967
1311
            {
968
 
            uschar *slotB = slotA;
 
1312
            pcre_uchar *slotB = slotA;
969
1313
            while (slotB > md->name_table)
970
1314
              {
971
1315
              slotB -= md->name_entry_size;
972
 
              if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
 
1316
              if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
973
1317
                {
974
1318
                condition = GET2(slotB, 0) == md->recursive->group_num;
975
1319
                if (condition) break;
985
1329
              for (i++; i < md->name_count; i++)
986
1330
                {
987
1331
                slotB += md->name_entry_size;
988
 
                if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
 
1332
                if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
989
1333
                  {
990
1334
                  condition = GET2(slotB, 0) == md->recursive->group_num;
991
1335
                  if (condition) break;
998
1342
 
999
1343
        /* Chose branch according to the condition */
1000
1344
 
1001
 
        ecode += condition? 3 : GET(ecode, 1);
 
1345
        ecode += condition? 1 + IMM2_SIZE : GET(ecode, 1);
1002
1346
        }
1003
1347
      }
1004
1348
 
1015
1359
      if (!condition && condcode == OP_NCREF)
1016
1360
        {
1017
1361
        int refno = offset >> 1;
1018
 
        uschar *slotA = md->name_table;
 
1362
        pcre_uchar *slotA = md->name_table;
1019
1363
 
1020
1364
        for (i = 0; i < md->name_count; i++)
1021
1365
          {
1029
1373
 
1030
1374
        if (i < md->name_count)
1031
1375
          {
1032
 
          uschar *slotB = slotA;
 
1376
          pcre_uchar *slotB = slotA;
1033
1377
          while (slotB > md->name_table)
1034
1378
            {
1035
1379
            slotB -= md->name_entry_size;
1036
 
            if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
 
1380
            if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
1037
1381
              {
1038
1382
              offset = GET2(slotB, 0) << 1;
1039
1383
              condition = offset < offset_top &&
1051
1395
            for (i++; i < md->name_count; i++)
1052
1396
              {
1053
1397
              slotB += md->name_entry_size;
1054
 
              if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
 
1398
              if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
1055
1399
                {
1056
1400
                offset = GET2(slotB, 0) << 1;
1057
1401
                condition = offset < offset_top &&
1066
1410
 
1067
1411
      /* Chose branch according to the condition */
1068
1412
 
1069
 
      ecode += condition? 3 : GET(ecode, 1);
 
1413
      ecode += condition? 1 + IMM2_SIZE : GET(ecode, 1);
1070
1414
      }
1071
1415
 
1072
1416
    else if (condcode == OP_DEF)     /* DEFINE - always false */
1076
1420
      }
1077
1421
 
1078
1422
    /* The condition is an assertion. Call match() to evaluate it - setting
1079
 
    the final argument match_condassert causes it to stop at the end of an
1080
 
    assertion. */
 
1423
    md->match_function_type to MATCH_CONDASSERT causes it to stop at the end of
 
1424
    an assertion. */
1081
1425
 
1082
1426
    else
1083
1427
      {
1084
 
      RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
1085
 
          match_condassert, RM3);
 
1428
      md->match_function_type = MATCH_CONDASSERT;
 
1429
      RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM3);
1086
1430
      if (rrc == MATCH_MATCH)
1087
1431
        {
 
1432
        if (md->end_offset_top > offset_top)
 
1433
          offset_top = md->end_offset_top;  /* Captures may have happened */
1088
1434
        condition = TRUE;
1089
1435
        ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
1090
1436
        while (*ecode == OP_ALT) ecode += GET(ecode, 1);
1091
1437
        }
1092
 
      else if (rrc != MATCH_NOMATCH &&
1093
 
              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
 
1438
 
 
1439
      /* PCRE doesn't allow the effect of (*THEN) to escape beyond an
 
1440
      assertion; it is therefore treated as NOMATCH. */
 
1441
 
 
1442
      else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1094
1443
        {
1095
1444
        RRETURN(rrc);         /* Need braces because of following else */
1096
1445
        }
1101
1450
        }
1102
1451
      }
1103
1452
 
1104
 
    /* We are now at the branch that is to be obeyed. As there is only one,
1105
 
    we can use tail recursion to avoid using another stack frame, except when
1106
 
    match_cbegroup is required for an unlimited repeat of a possibly empty
1107
 
    group. If the second alternative doesn't exist, we can just plough on. */
 
1453
    /* We are now at the branch that is to be obeyed. As there is only one, can
 
1454
    use tail recursion to avoid using another stack frame, except when there is
 
1455
    unlimited repeat of a possibly empty group. In the latter case, a recursive
 
1456
    call to match() is always required, unless the second alternative doesn't
 
1457
    exist, in which case we can just plough on. Note that, for compatibility
 
1458
    with Perl, the | in a conditional group is NOT treated as creating two
 
1459
    alternatives. If a THEN is encountered in the branch, it propagates out to
 
1460
    the enclosing alternative (unless nested in a deeper set of alternatives,
 
1461
    of course). */
1108
1462
 
1109
1463
    if (condition || *ecode == OP_ALT)
1110
1464
      {
1111
 
      ecode += 1 + LINK_SIZE;
1112
 
      if (op == OP_SCOND)        /* Possibly empty group */
1113
 
        {
1114
 
        RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
1115
 
        RRETURN(rrc);
1116
 
        }
1117
 
      else                       /* Group must match something */
1118
 
        {
1119
 
        flags = 0;
 
1465
      if (op != OP_SCOND)
 
1466
        {
 
1467
        ecode += 1 + LINK_SIZE;
1120
1468
        goto TAIL_RECURSE;
1121
1469
        }
 
1470
 
 
1471
      md->match_function_type = MATCH_CBEGROUP;
 
1472
      RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM49);
 
1473
      RRETURN(rrc);
1122
1474
      }
1123
 
    else                         /* Condition false & no alternative */
 
1475
 
 
1476
     /* Condition false & no alternative; continue after the group. */
 
1477
 
 
1478
    else
1124
1479
      {
1125
1480
      ecode += 1 + LINK_SIZE;
1126
1481
      }
1147
1502
      md->offset_vector[offset+1] = (int)(eptr - md->start_subject);
1148
1503
      if (offset_top <= offset) offset_top = offset + 2;
1149
1504
      }
1150
 
    ecode += 3;
 
1505
    ecode += 1 + IMM2_SIZE;
1151
1506
    break;
1152
1507
 
1153
1508
 
1154
 
    /* End of the pattern, either real or forced. If we are in a top-level
1155
 
    recursion, we should restore the offsets appropriately and continue from
1156
 
    after the call. */
 
1509
    /* End of the pattern, either real or forced. */
1157
1510
 
 
1511
    case OP_END:
1158
1512
    case OP_ACCEPT:
1159
 
    case OP_END:
1160
 
    if (md->recursive != NULL && md->recursive->group_num == 0)
1161
 
      {
1162
 
      recursion_info *rec = md->recursive;
1163
 
      DPRINTF(("End of pattern in a (?0) recursion\n"));
1164
 
      md->recursive = rec->prevrec;
1165
 
      memmove(md->offset_vector, rec->offset_save,
1166
 
        rec->saved_max * sizeof(int));
1167
 
      offset_top = rec->save_offset_top;
1168
 
      ims = original_ims;
1169
 
      ecode = rec->after_call;
1170
 
      break;
1171
 
      }
1172
 
 
1173
 
    /* Otherwise, if we have matched an empty string, fail if PCRE_NOTEMPTY is
1174
 
    set, or if PCRE_NOTEMPTY_ATSTART is set and we have matched at the start of
1175
 
    the subject. In both cases, backtracking will then try other alternatives,
1176
 
    if any. */
1177
 
 
1178
 
    if (eptr == mstart &&
1179
 
        (md->notempty ||
1180
 
          (md->notempty_atstart &&
1181
 
            mstart == md->start_subject + md->start_offset)))
1182
 
      MRRETURN(MATCH_NOMATCH);
 
1513
    case OP_ASSERT_ACCEPT:
 
1514
 
 
1515
    /* If we have matched an empty string, fail if not in an assertion and not
 
1516
    in a recursion if either PCRE_NOTEMPTY is set, or if PCRE_NOTEMPTY_ATSTART
 
1517
    is set and we have matched at the start of the subject. In both cases,
 
1518
    backtracking will then try other alternatives, if any. */
 
1519
 
 
1520
    if (eptr == mstart && op != OP_ASSERT_ACCEPT &&
 
1521
         md->recursive == NULL &&
 
1522
         (md->notempty ||
 
1523
           (md->notempty_atstart &&
 
1524
             mstart == md->start_subject + md->start_offset)))
 
1525
      RRETURN(MATCH_NOMATCH);
1183
1526
 
1184
1527
    /* Otherwise, we have a match. */
1185
1528
 
1188
1531
    md->start_match_ptr = mstart;       /* and the start (\K can modify) */
1189
1532
 
1190
1533
    /* For some reason, the macros don't work properly if an expression is
1191
 
    given as the argument to MRRETURN when the heap is in use. */
 
1534
    given as the argument to RRETURN when the heap is in use. */
1192
1535
 
1193
1536
    rrc = (op == OP_END)? MATCH_MATCH : MATCH_ACCEPT;
1194
 
    MRRETURN(rrc);
1195
 
 
1196
 
    /* Change option settings */
1197
 
 
1198
 
    case OP_OPT:
1199
 
    ims = ecode[1];
1200
 
    ecode += 2;
1201
 
    DPRINTF(("ims set to %02lx\n", ims));
1202
 
    break;
 
1537
    RRETURN(rrc);
1203
1538
 
1204
1539
    /* Assertion brackets. Check the alternative branches in turn - the
1205
1540
    matching won't pass the KET for an assertion. If any one branch matches,
1206
1541
    the assertion is true. Lookbehind assertions have an OP_REVERSE item at the
1207
1542
    start of each branch to move the current point backwards, so the code at
1208
 
    this level is identical to the lookahead case. */
 
1543
    this level is identical to the lookahead case. When the assertion is part
 
1544
    of a condition, we want to return immediately afterwards. The caller of
 
1545
    this incarnation of the match() function will have set MATCH_CONDASSERT in
 
1546
    md->match_function type, and one of these opcodes will be the first opcode
 
1547
    that is processed. We use a local variable that is preserved over calls to
 
1548
    match() to remember this case. */
1209
1549
 
1210
1550
    case OP_ASSERT:
1211
1551
    case OP_ASSERTBACK:
 
1552
    save_mark = md->mark;
 
1553
    if (md->match_function_type == MATCH_CONDASSERT)
 
1554
      {
 
1555
      condassert = TRUE;
 
1556
      md->match_function_type = 0;
 
1557
      }
 
1558
    else condassert = FALSE;
 
1559
 
1212
1560
    do
1213
1561
      {
1214
 
      RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1215
 
        RM4);
 
1562
      RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM4);
1216
1563
      if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1217
1564
        {
1218
1565
        mstart = md->start_match_ptr;   /* In case \K reset it */
1219
1566
        break;
1220
1567
        }
1221
 
      if (rrc != MATCH_NOMATCH &&
1222
 
          (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1223
 
        RRETURN(rrc);
 
1568
 
 
1569
      /* PCRE does not allow THEN to escape beyond an assertion; it is treated
 
1570
      as NOMATCH. */
 
1571
 
 
1572
      if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1224
1573
      ecode += GET(ecode, 1);
 
1574
      md->mark = save_mark;
1225
1575
      }
1226
1576
    while (*ecode == OP_ALT);
1227
 
    if (*ecode == OP_KET) MRRETURN(MATCH_NOMATCH);
 
1577
 
 
1578
    if (*ecode == OP_KET) RRETURN(MATCH_NOMATCH);
1228
1579
 
1229
1580
    /* If checking an assertion for a condition, return MATCH_MATCH. */
1230
1581
 
1231
 
    if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH);
 
1582
    if (condassert) RRETURN(MATCH_MATCH);
1232
1583
 
1233
1584
    /* Continue from after the assertion, updating the offsets high water
1234
1585
    mark, since extracts may have been taken during the assertion. */
1244
1595
 
1245
1596
    case OP_ASSERT_NOT:
1246
1597
    case OP_ASSERTBACK_NOT:
 
1598
    save_mark = md->mark;
 
1599
    if (md->match_function_type == MATCH_CONDASSERT)
 
1600
      {
 
1601
      condassert = TRUE;
 
1602
      md->match_function_type = 0;
 
1603
      }
 
1604
    else condassert = FALSE;
 
1605
 
1247
1606
    do
1248
1607
      {
1249
 
      RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1250
 
        RM5);
1251
 
      if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) MRRETURN(MATCH_NOMATCH);
 
1608
      RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5);
 
1609
      md->mark = save_mark;
 
1610
      if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) RRETURN(MATCH_NOMATCH);
1252
1611
      if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1253
1612
        {
1254
1613
        do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1255
1614
        break;
1256
1615
        }
1257
 
      if (rrc != MATCH_NOMATCH &&
1258
 
          (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1259
 
        RRETURN(rrc);
 
1616
 
 
1617
      /* PCRE does not allow THEN to escape beyond an assertion; it is treated
 
1618
      as NOMATCH. */
 
1619
 
 
1620
      if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1260
1621
      ecode += GET(ecode,1);
1261
1622
      }
1262
1623
    while (*ecode == OP_ALT);
1263
1624
 
1264
 
    if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH);
 
1625
    if (condassert) RRETURN(MATCH_MATCH);  /* Condition assertion */
1265
1626
 
1266
1627
    ecode += 1 + LINK_SIZE;
1267
1628
    continue;
1272
1633
    back a number of characters, not bytes. */
1273
1634
 
1274
1635
    case OP_REVERSE:
1275
 
#ifdef SUPPORT_UTF8
1276
 
    if (utf8)
 
1636
#ifdef SUPPORT_UTF
 
1637
    if (utf)
1277
1638
      {
1278
1639
      i = GET(ecode, 1);
1279
1640
      while (i-- > 0)
1280
1641
        {
1281
1642
        eptr--;
1282
 
        if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH);
 
1643
        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1283
1644
        BACKCHAR(eptr);
1284
1645
        }
1285
1646
      }
1290
1651
 
1291
1652
      {
1292
1653
      eptr -= GET(ecode, 1);
1293
 
      if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH);
 
1654
      if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1294
1655
      }
1295
1656
 
1296
1657
    /* Save the earliest consulted character, then skip to next op code */
1304
1665
    function is able to force a failure. */
1305
1666
 
1306
1667
    case OP_CALLOUT:
1307
 
    if (pcre_callout != NULL)
 
1668
    if (PUBL(callout) != NULL)
1308
1669
      {
1309
 
      pcre_callout_block cb;
1310
 
      cb.version          = 1;   /* Version 1 of the callout block */
 
1670
      PUBL(callout_block) cb;
 
1671
      cb.version          = 2;   /* Version 1 of the callout block */
1311
1672
      cb.callout_number   = ecode[1];
1312
1673
      cb.offset_vector    = md->offset_vector;
 
1674
#ifdef COMPILE_PCRE8
1313
1675
      cb.subject          = (PCRE_SPTR)md->start_subject;
 
1676
#else
 
1677
      cb.subject          = (PCRE_SPTR16)md->start_subject;
 
1678
#endif
1314
1679
      cb.subject_length   = (int)(md->end_subject - md->start_subject);
1315
1680
      cb.start_match      = (int)(mstart - md->start_subject);
1316
1681
      cb.current_position = (int)(eptr - md->start_subject);
1319
1684
      cb.capture_top      = offset_top/2;
1320
1685
      cb.capture_last     = md->capture_last;
1321
1686
      cb.callout_data     = md->callout_data;
1322
 
      if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH);
 
1687
      cb.mark             = md->nomatch_mark;
 
1688
      if ((rrc = (*PUBL(callout))(&cb)) > 0) RRETURN(MATCH_NOMATCH);
1323
1689
      if (rrc < 0) RRETURN(rrc);
1324
1690
      }
1325
1691
    ecode += 2 + 2*LINK_SIZE;
1329
1695
    offset data is the offset to the starting bracket from the start of the
1330
1696
    whole pattern. (This is so that it works from duplicated subpatterns.)
1331
1697
 
1332
 
    If there are any capturing brackets started but not finished, we have to
1333
 
    save their starting points and reinstate them after the recursion. However,
1334
 
    we don't know how many such there are (offset_top records the completed
1335
 
    total) so we just have to save all the potential data. There may be up to
1336
 
    65535 such values, which is too large to put on the stack, but using malloc
1337
 
    for small numbers seems expensive. As a compromise, the stack is used when
1338
 
    there are no more than REC_STACK_SAVE_MAX values to store; otherwise malloc
1339
 
    is used. A problem is what to do if the malloc fails ... there is no way of
1340
 
    returning to the top level with an error. Save the top REC_STACK_SAVE_MAX
1341
 
    values on the stack, and accept that the rest may be wrong.
 
1698
    The state of the capturing groups is preserved over recursion, and
 
1699
    re-instated afterwards. We don't know how many are started and not yet
 
1700
    finished (offset_top records the completed total) so we just have to save
 
1701
    all the potential data. There may be up to 65535 such values, which is too
 
1702
    large to put on the stack, but using malloc for small numbers seems
 
1703
    expensive. As a compromise, the stack is used when there are no more than
 
1704
    REC_STACK_SAVE_MAX values to store; otherwise malloc is used.
1342
1705
 
1343
1706
    There are also other values that have to be saved. We use a chained
1344
1707
    sequence of blocks that actually live on the stack. Thanks to Robin Houston
1345
 
    for the original version of this logic. */
 
1708
    for the original version of this logic. It has, however, been hacked around
 
1709
    a lot, so he is not to blame for the current way it works. */
1346
1710
 
1347
1711
    case OP_RECURSE:
1348
1712
      {
 
1713
      recursion_info *ri;
 
1714
      int recno;
 
1715
 
1349
1716
      callpat = md->start_code + GET(ecode, 1);
1350
 
      new_recursive.group_num = (callpat == md->start_code)? 0 :
 
1717
      recno = (callpat == md->start_code)? 0 :
1351
1718
        GET2(callpat, 1 + LINK_SIZE);
1352
1719
 
 
1720
      /* Check for repeating a recursion without advancing the subject pointer.
 
1721
      This should catch convoluted mutual recursions. (Some simple cases are
 
1722
      caught at compile time.) */
 
1723
 
 
1724
      for (ri = md->recursive; ri != NULL; ri = ri->prevrec)
 
1725
        if (recno == ri->group_num && eptr == ri->subject_position)
 
1726
          RRETURN(PCRE_ERROR_RECURSELOOP);
 
1727
 
1353
1728
      /* Add to "recursing stack" */
1354
1729
 
 
1730
      new_recursive.group_num = recno;
 
1731
      new_recursive.subject_position = eptr;
1355
1732
      new_recursive.prevrec = md->recursive;
1356
1733
      md->recursive = &new_recursive;
1357
1734
 
1358
 
      /* Find where to continue from afterwards */
 
1735
      /* Where to continue from afterwards */
1359
1736
 
1360
1737
      ecode += 1 + LINK_SIZE;
1361
 
      new_recursive.after_call = ecode;
1362
1738
 
1363
 
      /* Now save the offset data. */
 
1739
      /* Now save the offset data */
1364
1740
 
1365
1741
      new_recursive.saved_max = md->offset_end;
1366
1742
      if (new_recursive.saved_max <= REC_STACK_SAVE_MAX)
1368
1744
      else
1369
1745
        {
1370
1746
        new_recursive.offset_save =
1371
 
          (int *)(pcre_malloc)(new_recursive.saved_max * sizeof(int));
 
1747
          (int *)(PUBL(malloc))(new_recursive.saved_max * sizeof(int));
1372
1748
        if (new_recursive.offset_save == NULL) RRETURN(PCRE_ERROR_NOMEMORY);
1373
1749
        }
1374
 
 
1375
1750
      memcpy(new_recursive.offset_save, md->offset_vector,
1376
1751
            new_recursive.saved_max * sizeof(int));
1377
 
      new_recursive.save_offset_top = offset_top;
1378
1752
 
1379
 
      /* OK, now we can do the recursion. For each top-level alternative we
1380
 
      restore the offset and recursion data. */
 
1753
      /* OK, now we can do the recursion. After processing each alternative,
 
1754
      restore the offset data. If there were nested recursions, md->recursive
 
1755
      might be changed, so reset it before looping. */
1381
1756
 
1382
1757
      DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
1383
 
      flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
 
1758
      cbegroup = (*callpat >= OP_SBRA);
1384
1759
      do
1385
1760
        {
1386
 
        RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1387
 
          md, ims, eptrb, flags, RM6);
 
1761
        if (cbegroup) md->match_function_type = MATCH_CBEGROUP;
 
1762
        RMATCH(eptr, callpat + PRIV(OP_lengths)[*callpat], offset_top,
 
1763
          md, eptrb, RM6);
 
1764
        memcpy(md->offset_vector, new_recursive.offset_save,
 
1765
            new_recursive.saved_max * sizeof(int));
 
1766
        md->recursive = new_recursive.prevrec;
1388
1767
        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1389
1768
          {
1390
1769
          DPRINTF(("Recursion matched\n"));
1391
 
          md->recursive = new_recursive.prevrec;
1392
1770
          if (new_recursive.offset_save != stacksave)
1393
 
            (pcre_free)(new_recursive.offset_save);
1394
 
          MRRETURN(MATCH_MATCH);
 
1771
            (PUBL(free))(new_recursive.offset_save);
 
1772
 
 
1773
          /* Set where we got to in the subject, and reset the start in case
 
1774
          it was changed by \K. This *is* propagated back out of a recursion,
 
1775
          for Perl compatibility. */
 
1776
 
 
1777
          eptr = md->end_match_ptr;
 
1778
          mstart = md->start_match_ptr;
 
1779
          goto RECURSION_MATCHED;        /* Exit loop; end processing */
1395
1780
          }
1396
 
        else if (rrc != MATCH_NOMATCH &&
1397
 
                (rrc != MATCH_THEN || md->start_match_ptr != ecode))
 
1781
 
 
1782
        /* PCRE does not allow THEN to escape beyond a recursion; it is treated
 
1783
        as NOMATCH. */
 
1784
 
 
1785
        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1398
1786
          {
1399
1787
          DPRINTF(("Recursion gave error %d\n", rrc));
1400
1788
          if (new_recursive.offset_save != stacksave)
1401
 
            (pcre_free)(new_recursive.offset_save);
 
1789
            (PUBL(free))(new_recursive.offset_save);
1402
1790
          RRETURN(rrc);
1403
1791
          }
1404
1792
 
1405
1793
        md->recursive = &new_recursive;
1406
 
        memcpy(md->offset_vector, new_recursive.offset_save,
1407
 
            new_recursive.saved_max * sizeof(int));
1408
1794
        callpat += GET(callpat, 1);
1409
1795
        }
1410
1796
      while (*callpat == OP_ALT);
1412
1798
      DPRINTF(("Recursion didn't match\n"));
1413
1799
      md->recursive = new_recursive.prevrec;
1414
1800
      if (new_recursive.offset_save != stacksave)
1415
 
        (pcre_free)(new_recursive.offset_save);
1416
 
      MRRETURN(MATCH_NOMATCH);
1417
 
      }
1418
 
    /* Control never reaches here */
1419
 
 
1420
 
    /* "Once" brackets are like assertion brackets except that after a match,
1421
 
    the point in the subject string is not moved back. Thus there can never be
1422
 
    a move back into the brackets. Friedl calls these "atomic" subpatterns.
1423
 
    Check the alternative branches in turn - the matching won't pass the KET
1424
 
    for this kind of subpattern. If any one branch matches, we carry on as at
1425
 
    the end of a normal bracket, leaving the subject pointer, but resetting
1426
 
    the start-of-match value in case it was changed by \K. */
1427
 
 
1428
 
    case OP_ONCE:
1429
 
    prev = ecode;
1430
 
    saved_eptr = eptr;
1431
 
 
1432
 
    do
1433
 
      {
1434
 
      RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
1435
 
      if (rrc == MATCH_MATCH)  /* Note: _not_ MATCH_ACCEPT */
1436
 
        {
1437
 
        mstart = md->start_match_ptr;
1438
 
        break;
1439
 
        }
1440
 
      if (rrc != MATCH_NOMATCH &&
1441
 
          (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1442
 
        RRETURN(rrc);
1443
 
      ecode += GET(ecode,1);
1444
 
      }
1445
 
    while (*ecode == OP_ALT);
1446
 
 
1447
 
    /* If hit the end of the group (which could be repeated), fail */
1448
 
 
1449
 
    if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);
1450
 
 
1451
 
    /* Continue as from after the assertion, updating the offsets high water
1452
 
    mark, since extracts may have been taken. */
1453
 
 
1454
 
    do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
1455
 
 
1456
 
    offset_top = md->end_offset_top;
1457
 
    eptr = md->end_match_ptr;
1458
 
 
1459
 
    /* For a non-repeating ket, just continue at this level. This also
1460
 
    happens for a repeating ket if no characters were matched in the group.
1461
 
    This is the forcible breaking of infinite loops as implemented in Perl
1462
 
    5.005. If there is an options reset, it will get obeyed in the normal
1463
 
    course of events. */
1464
 
 
1465
 
    if (*ecode == OP_KET || eptr == saved_eptr)
1466
 
      {
1467
 
      ecode += 1+LINK_SIZE;
1468
 
      break;
1469
 
      }
1470
 
 
1471
 
    /* The repeating kets try the rest of the pattern or restart from the
1472
 
    preceding bracket, in the appropriate order. The second "call" of match()
1473
 
    uses tail recursion, to avoid using another stack frame. We need to reset
1474
 
    any options that changed within the bracket before re-running it, so
1475
 
    check the next opcode. */
1476
 
 
1477
 
    if (ecode[1+LINK_SIZE] == OP_OPT)
1478
 
      {
1479
 
      ims = (ims & ~PCRE_IMS) | ecode[4];
1480
 
      DPRINTF(("ims set to %02lx at group repeat\n", ims));
1481
 
      }
1482
 
 
1483
 
    if (*ecode == OP_KETRMIN)
1484
 
      {
1485
 
      RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8);
1486
 
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1487
 
      ecode = prev;
1488
 
      flags = 0;
1489
 
      goto TAIL_RECURSE;
1490
 
      }
1491
 
    else  /* OP_KETRMAX */
1492
 
      {
1493
 
      RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1494
 
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1495
 
      ecode += 1 + LINK_SIZE;
1496
 
      flags = 0;
1497
 
      goto TAIL_RECURSE;
1498
 
      }
1499
 
    /* Control never gets here */
 
1801
        (PUBL(free))(new_recursive.offset_save);
 
1802
      RRETURN(MATCH_NOMATCH);
 
1803
      }
 
1804
 
 
1805
    RECURSION_MATCHED:
 
1806
    break;
1500
1807
 
1501
1808
    /* An alternation is the end of a branch; scan along to find the end of the
1502
1809
    bracketed group and go to there. */
1512
1819
    optional ones preceded by BRAZERO or BRAMINZERO. */
1513
1820
 
1514
1821
    case OP_BRAZERO:
1515
 
      {
1516
 
      next = ecode+1;
1517
 
      RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
1518
 
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1519
 
      do next += GET(next,1); while (*next == OP_ALT);
1520
 
      ecode = next + 1 + LINK_SIZE;
1521
 
      }
 
1822
    next = ecode + 1;
 
1823
    RMATCH(eptr, next, offset_top, md, eptrb, RM10);
 
1824
    if (rrc != MATCH_NOMATCH) RRETURN(rrc);
 
1825
    do next += GET(next, 1); while (*next == OP_ALT);
 
1826
    ecode = next + 1 + LINK_SIZE;
1522
1827
    break;
1523
1828
 
1524
1829
    case OP_BRAMINZERO:
1525
 
      {
1526
 
      next = ecode+1;
1527
 
      do next += GET(next, 1); while (*next == OP_ALT);
1528
 
      RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11);
1529
 
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1530
 
      ecode++;
1531
 
      }
 
1830
    next = ecode + 1;
 
1831
    do next += GET(next, 1); while (*next == OP_ALT);
 
1832
    RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, eptrb, RM11);
 
1833
    if (rrc != MATCH_NOMATCH) RRETURN(rrc);
 
1834
    ecode++;
1532
1835
    break;
1533
1836
 
1534
1837
    case OP_SKIPZERO:
1535
 
      {
1536
 
      next = ecode+1;
1537
 
      do next += GET(next,1); while (*next == OP_ALT);
1538
 
      ecode = next + 1 + LINK_SIZE;
1539
 
      }
 
1838
    next = ecode+1;
 
1839
    do next += GET(next,1); while (*next == OP_ALT);
 
1840
    ecode = next + 1 + LINK_SIZE;
1540
1841
    break;
1541
1842
 
 
1843
    /* BRAPOSZERO occurs before a possessive bracket group. Don't do anything
 
1844
    here; just jump to the group, with allow_zero set TRUE. */
 
1845
 
 
1846
    case OP_BRAPOSZERO:
 
1847
    op = *(++ecode);
 
1848
    allow_zero = TRUE;
 
1849
    if (op == OP_CBRAPOS || op == OP_SCBRAPOS) goto POSSESSIVE_CAPTURE;
 
1850
      goto POSSESSIVE_NON_CAPTURE;
 
1851
 
1542
1852
    /* End of a group, repeated or non-repeating. */
1543
1853
 
1544
1854
    case OP_KET:
1545
1855
    case OP_KETRMIN:
1546
1856
    case OP_KETRMAX:
 
1857
    case OP_KETRPOS:
1547
1858
    prev = ecode - GET(ecode, 1);
1548
1859
 
1549
1860
    /* If this was a group that remembered the subject start, in order to break
1550
1861
    infinite repeats of empty string matches, retrieve the subject start from
1551
1862
    the chain. Otherwise, set it NULL. */
1552
1863
 
1553
 
    if (*prev >= OP_SBRA)
 
1864
    if (*prev >= OP_SBRA || *prev == OP_ONCE)
1554
1865
      {
1555
1866
      saved_eptr = eptrb->epb_saved_eptr;   /* Value at start of group */
1556
1867
      eptrb = eptrb->epb_prev;              /* Backup to previous group */
1557
1868
      }
1558
1869
    else saved_eptr = NULL;
1559
1870
 
1560
 
    /* If we are at the end of an assertion group or an atomic group, stop
1561
 
    matching and return MATCH_MATCH, but record the current high water mark for
1562
 
    use by positive assertions. We also need to record the match start in case
1563
 
    it was changed by \K. */
 
1871
    /* If we are at the end of an assertion group or a non-capturing atomic
 
1872
    group, stop matching and return MATCH_MATCH, but record the current high
 
1873
    water mark for use by positive assertions. We also need to record the match
 
1874
    start in case it was changed by \K. */
1564
1875
 
1565
 
    if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
1566
 
        *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
1567
 
        *prev == OP_ONCE)
 
1876
    if ((*prev >= OP_ASSERT && *prev <= OP_ASSERTBACK_NOT) ||
 
1877
         *prev == OP_ONCE_NC)
1568
1878
      {
1569
 
      md->end_match_ptr = eptr;      /* For ONCE */
 
1879
      md->end_match_ptr = eptr;      /* For ONCE_NC */
1570
1880
      md->end_offset_top = offset_top;
1571
1881
      md->start_match_ptr = mstart;
1572
 
      MRRETURN(MATCH_MATCH);
 
1882
      RRETURN(MATCH_MATCH);         /* Sets md->mark */
1573
1883
      }
1574
1884
 
1575
1885
    /* For capturing groups we have to check the group number back at the start
1576
1886
    and if necessary complete handling an extraction by setting the offsets and
1577
 
    bumping the high water mark. Note that whole-pattern recursion is coded as
1578
 
    a recurse into group 0, so it won't be picked up here. Instead, we catch it
1579
 
    when the OP_END is reached. Other recursion is handled here. */
 
1887
    bumping the high water mark. Whole-pattern recursion is coded as a recurse
 
1888
    into group 0, so it won't be picked up here. Instead, we catch it when the
 
1889
    OP_END is reached. Other recursion is handled here. We just have to record
 
1890
    the current subject position and start match pointer and give a MATCH
 
1891
    return. */
1580
1892
 
1581
 
    if (*prev == OP_CBRA || *prev == OP_SCBRA)
 
1893
    if (*prev == OP_CBRA || *prev == OP_SCBRA ||
 
1894
        *prev == OP_CBRAPOS || *prev == OP_SCBRAPOS)
1582
1895
      {
1583
1896
      number = GET2(prev, 1+LINK_SIZE);
1584
1897
      offset = number << 1;
1588
1901
      printf("\n");
1589
1902
#endif
1590
1903
 
 
1904
      /* Handle a recursively called group. */
 
1905
 
 
1906
      if (md->recursive != NULL && md->recursive->group_num == number)
 
1907
        {
 
1908
        md->end_match_ptr = eptr;
 
1909
        md->start_match_ptr = mstart;
 
1910
        RRETURN(MATCH_MATCH);
 
1911
        }
 
1912
 
 
1913
      /* Deal with capturing */
 
1914
 
1591
1915
      md->capture_last = number;
1592
1916
      if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1593
1917
        {
 
1918
        /* If offset is greater than offset_top, it means that we are
 
1919
        "skipping" a capturing group, and that group's offsets must be marked
 
1920
        unset. In earlier versions of PCRE, all the offsets were unset at the
 
1921
        start of matching, but this doesn't work because atomic groups and
 
1922
        assertions can cause a value to be set that should later be unset.
 
1923
        Example: matching /(?>(a))b|(a)c/ against "ac". This sets group 1 as
 
1924
        part of the atomic group, but this is not on the final matching path,
 
1925
        so must be unset when 2 is set. (If there is no group 2, there is no
 
1926
        problem, because offset_top will then be 2, indicating no capture.) */
 
1927
 
 
1928
        if (offset > offset_top)
 
1929
          {
 
1930
          register int *iptr = md->offset_vector + offset_top;
 
1931
          register int *iend = md->offset_vector + offset;
 
1932
          while (iptr < iend) *iptr++ = -1;
 
1933
          }
 
1934
 
 
1935
        /* Now make the extraction */
 
1936
 
1594
1937
        md->offset_vector[offset] =
1595
1938
          md->offset_vector[md->offset_end - number];
1596
1939
        md->offset_vector[offset+1] = (int)(eptr - md->start_subject);
1597
1940
        if (offset_top <= offset) offset_top = offset + 2;
1598
1941
        }
1599
 
 
1600
 
      /* Handle a recursively called group. Restore the offsets
1601
 
      appropriately and continue from after the call. */
1602
 
 
1603
 
      if (md->recursive != NULL && md->recursive->group_num == number)
1604
 
        {
1605
 
        recursion_info *rec = md->recursive;
1606
 
        DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1607
 
        md->recursive = rec->prevrec;
1608
 
        memcpy(md->offset_vector, rec->offset_save,
1609
 
          rec->saved_max * sizeof(int));
1610
 
        offset_top = rec->save_offset_top;
1611
 
        ecode = rec->after_call;
1612
 
        ims = original_ims;
1613
 
        break;
1614
 
        }
1615
1942
      }
1616
1943
 
1617
 
    /* For both capturing and non-capturing groups, reset the value of the ims
1618
 
    flags, in case they got changed during the group. */
1619
 
 
1620
 
    ims = original_ims;
1621
 
    DPRINTF(("ims reset to %02lx\n", ims));
1622
 
 
1623
 
    /* For a non-repeating ket, just continue at this level. This also
1624
 
    happens for a repeating ket if no characters were matched in the group.
1625
 
    This is the forcible breaking of infinite loops as implemented in Perl
1626
 
    5.005. If there is an options reset, it will get obeyed in the normal
1627
 
    course of events. */
 
1944
    /* For an ordinary non-repeating ket, just continue at this level. This
 
1945
    also happens for a repeating ket if no characters were matched in the
 
1946
    group. This is the forcible breaking of infinite loops as implemented in
 
1947
    Perl 5.005. For a non-repeating atomic group that includes captures,
 
1948
    establish a backup point by processing the rest of the pattern at a lower
 
1949
    level. If this results in a NOMATCH return, pass MATCH_ONCE back to the
 
1950
    original OP_ONCE level, thereby bypassing intermediate backup points, but
 
1951
    resetting any captures that happened along the way. */
1628
1952
 
1629
1953
    if (*ecode == OP_KET || eptr == saved_eptr)
1630
1954
      {
1631
 
      ecode += 1 + LINK_SIZE;
 
1955
      if (*prev == OP_ONCE)
 
1956
        {
 
1957
        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM12);
 
1958
        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
 
1959
        md->once_target = prev;  /* Level at which to change to MATCH_NOMATCH */
 
1960
        RRETURN(MATCH_ONCE);
 
1961
        }
 
1962
      ecode += 1 + LINK_SIZE;    /* Carry on at this level */
1632
1963
      break;
1633
1964
      }
1634
1965
 
1635
 
    /* The repeating kets try the rest of the pattern or restart from the
1636
 
    preceding bracket, in the appropriate order. In the second case, we can use
1637
 
    tail recursion to avoid using another stack frame, unless we have an
1638
 
    unlimited repeat of a group that can match an empty string. */
1639
 
 
1640
 
    flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
 
1966
    /* OP_KETRPOS is a possessive repeating ket. Remember the current position,
 
1967
    and return the MATCH_KETRPOS. This makes it possible to do the repeats one
 
1968
    at a time from the outer level, thus saving stack. */
 
1969
 
 
1970
    if (*ecode == OP_KETRPOS)
 
1971
      {
 
1972
      md->end_match_ptr = eptr;
 
1973
      md->end_offset_top = offset_top;
 
1974
      RRETURN(MATCH_KETRPOS);
 
1975
      }
 
1976
 
 
1977
    /* The normal repeating kets try the rest of the pattern or restart from
 
1978
    the preceding bracket, in the appropriate order. In the second case, we can
 
1979
    use tail recursion to avoid using another stack frame, unless we have an
 
1980
    an atomic group or an unlimited repeat of a group that can match an empty
 
1981
    string. */
1641
1982
 
1642
1983
    if (*ecode == OP_KETRMIN)
1643
1984
      {
1644
 
      RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
 
1985
      RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM7);
1645
1986
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1646
 
      if (flags != 0)    /* Could match an empty string */
1647
 
        {
1648
 
        RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
 
1987
      if (*prev == OP_ONCE)
 
1988
        {
 
1989
        RMATCH(eptr, prev, offset_top, md, eptrb, RM8);
 
1990
        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
 
1991
        md->once_target = prev;  /* Level at which to change to MATCH_NOMATCH */
 
1992
        RRETURN(MATCH_ONCE);
 
1993
        }
 
1994
      if (*prev >= OP_SBRA)    /* Could match an empty string */
 
1995
        {
 
1996
        md->match_function_type = MATCH_CBEGROUP;
 
1997
        RMATCH(eptr, prev, offset_top, md, eptrb, RM50);
1649
1998
        RRETURN(rrc);
1650
1999
        }
1651
2000
      ecode = prev;
1653
2002
      }
1654
2003
    else  /* OP_KETRMAX */
1655
2004
      {
1656
 
      RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
 
2005
      if (*prev >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
 
2006
      RMATCH(eptr, prev, offset_top, md, eptrb, RM13);
 
2007
      if (rrc == MATCH_ONCE && md->once_target == prev) rrc = MATCH_NOMATCH;
1657
2008
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
 
2009
      if (*prev == OP_ONCE)
 
2010
        {
 
2011
        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM9);
 
2012
        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
 
2013
        md->once_target = prev;
 
2014
        RRETURN(MATCH_ONCE);
 
2015
        }
1658
2016
      ecode += 1 + LINK_SIZE;
1659
 
      flags = 0;
1660
2017
      goto TAIL_RECURSE;
1661
2018
      }
1662
2019
    /* Control never gets here */
1663
2020
 
1664
 
    /* Start of subject unless notbol, or after internal newline if multiline */
 
2021
    /* Not multiline mode: start of subject assertion, unless notbol. */
1665
2022
 
1666
2023
    case OP_CIRC:
1667
 
    if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);
1668
 
    if ((ims & PCRE_MULTILINE) != 0)
1669
 
      {
1670
 
      if (eptr != md->start_subject &&
1671
 
          (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
1672
 
        MRRETURN(MATCH_NOMATCH);
1673
 
      ecode++;
1674
 
      break;
1675
 
      }
1676
 
    /* ... else fall through */
 
2024
    if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);
1677
2025
 
1678
2026
    /* Start of subject assertion */
1679
2027
 
1680
2028
    case OP_SOD:
1681
 
    if (eptr != md->start_subject) MRRETURN(MATCH_NOMATCH);
 
2029
    if (eptr != md->start_subject) RRETURN(MATCH_NOMATCH);
 
2030
    ecode++;
 
2031
    break;
 
2032
 
 
2033
    /* Multiline mode: start of subject unless notbol, or after any newline. */
 
2034
 
 
2035
    case OP_CIRCM:
 
2036
    if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);
 
2037
    if (eptr != md->start_subject &&
 
2038
        (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
 
2039
      RRETURN(MATCH_NOMATCH);
1682
2040
    ecode++;
1683
2041
    break;
1684
2042
 
1685
2043
    /* Start of match assertion */
1686
2044
 
1687
2045
    case OP_SOM:
1688
 
    if (eptr != md->start_subject + md->start_offset) MRRETURN(MATCH_NOMATCH);
 
2046
    if (eptr != md->start_subject + md->start_offset) RRETURN(MATCH_NOMATCH);
1689
2047
    ecode++;
1690
2048
    break;
1691
2049
 
1696
2054
    ecode++;
1697
2055
    break;
1698
2056
 
1699
 
    /* Assert before internal newline if multiline, or before a terminating
1700
 
    newline unless endonly is set, else end of subject unless noteol is set. */
 
2057
    /* Multiline mode: assert before any newline, or before end of subject
 
2058
    unless noteol is set. */
 
2059
 
 
2060
    case OP_DOLLM:
 
2061
    if (eptr < md->end_subject)
 
2062
      { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }
 
2063
    else
 
2064
      {
 
2065
      if (md->noteol) RRETURN(MATCH_NOMATCH);
 
2066
      SCHECK_PARTIAL();
 
2067
      }
 
2068
    ecode++;
 
2069
    break;
 
2070
 
 
2071
    /* Not multiline mode: assert before a terminating newline or before end of
 
2072
    subject unless noteol is set. */
1701
2073
 
1702
2074
    case OP_DOLL:
1703
 
    if ((ims & PCRE_MULTILINE) != 0)
1704
 
      {
1705
 
      if (eptr < md->end_subject)
1706
 
        { if (!IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH); }
1707
 
      else
1708
 
        {
1709
 
        if (md->noteol) MRRETURN(MATCH_NOMATCH);
1710
 
        SCHECK_PARTIAL();
1711
 
        }
1712
 
      ecode++;
1713
 
      break;
1714
 
      }
1715
 
    else  /* Not multiline */
1716
 
      {
1717
 
      if (md->noteol) MRRETURN(MATCH_NOMATCH);
1718
 
      if (!md->endonly) goto ASSERT_NL_OR_EOS;
1719
 
      }
 
2075
    if (md->noteol) RRETURN(MATCH_NOMATCH);
 
2076
    if (!md->endonly) goto ASSERT_NL_OR_EOS;
1720
2077
 
1721
2078
    /* ... else fall through for endonly */
1722
2079
 
1723
2080
    /* End of subject assertion (\z) */
1724
2081
 
1725
2082
    case OP_EOD:
1726
 
    if (eptr < md->end_subject) MRRETURN(MATCH_NOMATCH);
 
2083
    if (eptr < md->end_subject) RRETURN(MATCH_NOMATCH);
1727
2084
    SCHECK_PARTIAL();
1728
2085
    ecode++;
1729
2086
    break;
1734
2091
    ASSERT_NL_OR_EOS:
1735
2092
    if (eptr < md->end_subject &&
1736
2093
        (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1737
 
      MRRETURN(MATCH_NOMATCH);
 
2094
      RRETURN(MATCH_NOMATCH);
1738
2095
 
1739
2096
    /* Either at end of string or \n before end. */
1740
2097
 
1753
2110
      be "non-word" characters. Remember the earliest consulted character for
1754
2111
      partial matching. */
1755
2112
 
1756
 
#ifdef SUPPORT_UTF8
1757
 
      if (utf8)
 
2113
#ifdef SUPPORT_UTF
 
2114
      if (utf)
1758
2115
        {
1759
2116
        /* Get status of previous character */
1760
2117
 
1761
2118
        if (eptr == md->start_subject) prev_is_word = FALSE; else
1762
2119
          {
1763
 
          USPTR lastptr = eptr - 1;
1764
 
          while((*lastptr & 0xc0) == 0x80) lastptr--;
 
2120
          PCRE_PUCHAR lastptr = eptr - 1;
 
2121
          BACKCHAR(lastptr);
1765
2122
          if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;
1766
2123
          GETCHAR(c, lastptr);
1767
2124
#ifdef SUPPORT_UCP
1826
2183
            }
1827
2184
          else
1828
2185
#endif
1829
 
          prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);
 
2186
          prev_is_word = MAX_255(eptr[-1])
 
2187
            && ((md->ctypes[eptr[-1]] & ctype_word) != 0);
1830
2188
          }
1831
2189
 
1832
2190
        /* Get status of next character */
1849
2207
          }
1850
2208
        else
1851
2209
#endif
1852
 
        cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);
 
2210
        cur_is_word = MAX_255(*eptr)
 
2211
          && ((md->ctypes[*eptr] & ctype_word) != 0);
1853
2212
        }
1854
2213
 
1855
2214
      /* Now see if the situation is what we want */
1856
2215
 
1857
2216
      if ((*ecode++ == OP_WORD_BOUNDARY)?
1858
2217
           cur_is_word == prev_is_word : cur_is_word != prev_is_word)
1859
 
        MRRETURN(MATCH_NOMATCH);
 
2218
        RRETURN(MATCH_NOMATCH);
1860
2219
      }
1861
2220
    break;
1862
2221
 
1863
2222
    /* Match a single character type; inline for speed */
1864
2223
 
1865
2224
    case OP_ANY:
1866
 
    if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);
 
2225
    if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1867
2226
    /* Fall through */
1868
2227
 
1869
2228
    case OP_ALLANY:
1870
 
    if (eptr++ >= md->end_subject)
1871
 
      {
 
2229
    if (eptr >= md->end_subject)   /* DO NOT merge the eptr++ here; it must */
 
2230
      {                            /* not be updated before SCHECK_PARTIAL. */
1872
2231
      SCHECK_PARTIAL();
1873
 
      MRRETURN(MATCH_NOMATCH);
 
2232
      RRETURN(MATCH_NOMATCH);
1874
2233
      }
1875
 
    if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
 
2234
    eptr++;
 
2235
#ifdef SUPPORT_UTF
 
2236
    if (utf) ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
 
2237
#endif
1876
2238
    ecode++;
1877
2239
    break;
1878
2240
 
1880
2242
    any byte, even newline, independent of the setting of PCRE_DOTALL. */
1881
2243
 
1882
2244
    case OP_ANYBYTE:
1883
 
    if (eptr++ >= md->end_subject)
1884
 
      {
 
2245
    if (eptr >= md->end_subject)   /* DO NOT merge the eptr++ here; it must */
 
2246
      {                            /* not be updated before SCHECK_PARTIAL. */
1885
2247
      SCHECK_PARTIAL();
1886
 
      MRRETURN(MATCH_NOMATCH);
 
2248
      RRETURN(MATCH_NOMATCH);
1887
2249
      }
 
2250
    eptr++;
1888
2251
    ecode++;
1889
2252
    break;
1890
2253
 
1892
2255
    if (eptr >= md->end_subject)
1893
2256
      {
1894
2257
      SCHECK_PARTIAL();
1895
 
      MRRETURN(MATCH_NOMATCH);
 
2258
      RRETURN(MATCH_NOMATCH);
1896
2259
      }
1897
2260
    GETCHARINCTEST(c, eptr);
1898
2261
    if (
1899
 
#ifdef SUPPORT_UTF8
 
2262
#if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
1900
2263
       c < 256 &&
1901
2264
#endif
1902
2265
       (md->ctypes[c] & ctype_digit) != 0
1903
2266
       )
1904
 
      MRRETURN(MATCH_NOMATCH);
 
2267
      RRETURN(MATCH_NOMATCH);
1905
2268
    ecode++;
1906
2269
    break;
1907
2270
 
1909
2272
    if (eptr >= md->end_subject)
1910
2273
      {
1911
2274
      SCHECK_PARTIAL();
1912
 
      MRRETURN(MATCH_NOMATCH);
 
2275
      RRETURN(MATCH_NOMATCH);
1913
2276
      }
1914
2277
    GETCHARINCTEST(c, eptr);
1915
2278
    if (
1916
 
#ifdef SUPPORT_UTF8
1917
 
       c >= 256 ||
 
2279
#if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
 
2280
       c > 255 ||
1918
2281
#endif
1919
2282
       (md->ctypes[c] & ctype_digit) == 0
1920
2283
       )
1921
 
      MRRETURN(MATCH_NOMATCH);
 
2284
      RRETURN(MATCH_NOMATCH);
1922
2285
    ecode++;
1923
2286
    break;
1924
2287
 
1926
2289
    if (eptr >= md->end_subject)
1927
2290
      {
1928
2291
      SCHECK_PARTIAL();
1929
 
      MRRETURN(MATCH_NOMATCH);
 
2292
      RRETURN(MATCH_NOMATCH);
1930
2293
      }
1931
2294
    GETCHARINCTEST(c, eptr);
1932
2295
    if (
1933
 
#ifdef SUPPORT_UTF8
 
2296
#if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
1934
2297
       c < 256 &&
1935
2298
#endif
1936
2299
       (md->ctypes[c] & ctype_space) != 0
1937
2300
       )
1938
 
      MRRETURN(MATCH_NOMATCH);
 
2301
      RRETURN(MATCH_NOMATCH);
1939
2302
    ecode++;
1940
2303
    break;
1941
2304
 
1943
2306
    if (eptr >= md->end_subject)
1944
2307
      {
1945
2308
      SCHECK_PARTIAL();
1946
 
      MRRETURN(MATCH_NOMATCH);
 
2309
      RRETURN(MATCH_NOMATCH);
1947
2310
      }
1948
2311
    GETCHARINCTEST(c, eptr);
1949
2312
    if (
1950
 
#ifdef SUPPORT_UTF8
1951
 
       c >= 256 ||
 
2313
#if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
 
2314
       c > 255 ||
1952
2315
#endif
1953
2316
       (md->ctypes[c] & ctype_space) == 0
1954
2317
       )
1955
 
      MRRETURN(MATCH_NOMATCH);
 
2318
      RRETURN(MATCH_NOMATCH);
1956
2319
    ecode++;
1957
2320
    break;
1958
2321
 
1960
2323
    if (eptr >= md->end_subject)
1961
2324
      {
1962
2325
      SCHECK_PARTIAL();
1963
 
      MRRETURN(MATCH_NOMATCH);
 
2326
      RRETURN(MATCH_NOMATCH);
1964
2327
      }
1965
2328
    GETCHARINCTEST(c, eptr);
1966
2329
    if (
1967
 
#ifdef SUPPORT_UTF8
 
2330
#if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
1968
2331
       c < 256 &&
1969
2332
#endif
1970
2333
       (md->ctypes[c] & ctype_word) != 0
1971
2334
       )
1972
 
      MRRETURN(MATCH_NOMATCH);
 
2335
      RRETURN(MATCH_NOMATCH);
1973
2336
    ecode++;
1974
2337
    break;
1975
2338
 
1977
2340
    if (eptr >= md->end_subject)
1978
2341
      {
1979
2342
      SCHECK_PARTIAL();
1980
 
      MRRETURN(MATCH_NOMATCH);
 
2343
      RRETURN(MATCH_NOMATCH);
1981
2344
      }
1982
2345
    GETCHARINCTEST(c, eptr);
1983
2346
    if (
1984
 
#ifdef SUPPORT_UTF8
1985
 
       c >= 256 ||
 
2347
#if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
 
2348
       c > 255 ||
1986
2349
#endif
1987
2350
       (md->ctypes[c] & ctype_word) == 0
1988
2351
       )
1989
 
      MRRETURN(MATCH_NOMATCH);
 
2352
      RRETURN(MATCH_NOMATCH);
1990
2353
    ecode++;
1991
2354
    break;
1992
2355
 
1994
2357
    if (eptr >= md->end_subject)
1995
2358
      {
1996
2359
      SCHECK_PARTIAL();
1997
 
      MRRETURN(MATCH_NOMATCH);
 
2360
      RRETURN(MATCH_NOMATCH);
1998
2361
      }
1999
2362
    GETCHARINCTEST(c, eptr);
2000
2363
    switch(c)
2001
2364
      {
2002
 
      default: MRRETURN(MATCH_NOMATCH);
 
2365
      default: RRETURN(MATCH_NOMATCH);
 
2366
 
2003
2367
      case 0x000d:
2004
2368
      if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
2005
2369
      break;
2012
2376
      case 0x0085:
2013
2377
      case 0x2028:
2014
2378
      case 0x2029:
2015
 
      if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
 
2379
      if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
2016
2380
      break;
2017
2381
      }
2018
2382
    ecode++;
2022
2386
    if (eptr >= md->end_subject)
2023
2387
      {
2024
2388
      SCHECK_PARTIAL();
2025
 
      MRRETURN(MATCH_NOMATCH);
 
2389
      RRETURN(MATCH_NOMATCH);
2026
2390
      }
2027
2391
    GETCHARINCTEST(c, eptr);
2028
2392
    switch(c)
2047
2411
      case 0x202f:    /* NARROW NO-BREAK SPACE */
2048
2412
      case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
2049
2413
      case 0x3000:    /* IDEOGRAPHIC SPACE */
2050
 
      MRRETURN(MATCH_NOMATCH);
 
2414
      RRETURN(MATCH_NOMATCH);
2051
2415
      }
2052
2416
    ecode++;
2053
2417
    break;
2056
2420
    if (eptr >= md->end_subject)
2057
2421
      {
2058
2422
      SCHECK_PARTIAL();
2059
 
      MRRETURN(MATCH_NOMATCH);
 
2423
      RRETURN(MATCH_NOMATCH);
2060
2424
      }
2061
2425
    GETCHARINCTEST(c, eptr);
2062
2426
    switch(c)
2063
2427
      {
2064
 
      default: MRRETURN(MATCH_NOMATCH);
 
2428
      default: RRETURN(MATCH_NOMATCH);
2065
2429
      case 0x09:      /* HT */
2066
2430
      case 0x20:      /* SPACE */
2067
2431
      case 0xa0:      /* NBSP */
2090
2454
    if (eptr >= md->end_subject)
2091
2455
      {
2092
2456
      SCHECK_PARTIAL();
2093
 
      MRRETURN(MATCH_NOMATCH);
 
2457
      RRETURN(MATCH_NOMATCH);
2094
2458
      }
2095
2459
    GETCHARINCTEST(c, eptr);
2096
2460
    switch(c)
2103
2467
      case 0x85:      /* NEL */
2104
2468
      case 0x2028:    /* LINE SEPARATOR */
2105
2469
      case 0x2029:    /* PARAGRAPH SEPARATOR */
2106
 
      MRRETURN(MATCH_NOMATCH);
 
2470
      RRETURN(MATCH_NOMATCH);
2107
2471
      }
2108
2472
    ecode++;
2109
2473
    break;
2112
2476
    if (eptr >= md->end_subject)
2113
2477
      {
2114
2478
      SCHECK_PARTIAL();
2115
 
      MRRETURN(MATCH_NOMATCH);
 
2479
      RRETURN(MATCH_NOMATCH);
2116
2480
      }
2117
2481
    GETCHARINCTEST(c, eptr);
2118
2482
    switch(c)
2119
2483
      {
2120
 
      default: MRRETURN(MATCH_NOMATCH);
 
2484
      default: RRETURN(MATCH_NOMATCH);
2121
2485
      case 0x0a:      /* LF */
2122
2486
      case 0x0b:      /* VT */
2123
2487
      case 0x0c:      /* FF */
2139
2503
    if (eptr >= md->end_subject)
2140
2504
      {
2141
2505
      SCHECK_PARTIAL();
2142
 
      MRRETURN(MATCH_NOMATCH);
 
2506
      RRETURN(MATCH_NOMATCH);
2143
2507
      }
2144
2508
    GETCHARINCTEST(c, eptr);
2145
2509
      {
2148
2512
      switch(ecode[1])
2149
2513
        {
2150
2514
        case PT_ANY:
2151
 
        if (op == OP_NOTPROP) MRRETURN(MATCH_NOMATCH);
 
2515
        if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH);
2152
2516
        break;
2153
2517
 
2154
2518
        case PT_LAMP:
2155
2519
        if ((prop->chartype == ucp_Lu ||
2156
2520
             prop->chartype == ucp_Ll ||
2157
2521
             prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
2158
 
          MRRETURN(MATCH_NOMATCH);
 
2522
          RRETURN(MATCH_NOMATCH);
2159
2523
        break;
2160
2524
 
2161
2525
        case PT_GC:
2162
 
        if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
2163
 
          MRRETURN(MATCH_NOMATCH);
 
2526
        if ((ecode[2] != PRIV(ucp_gentype)[prop->chartype]) == (op == OP_PROP))
 
2527
          RRETURN(MATCH_NOMATCH);
2164
2528
        break;
2165
2529
 
2166
2530
        case PT_PC:
2167
2531
        if ((ecode[2] != prop->chartype) == (op == OP_PROP))
2168
 
          MRRETURN(MATCH_NOMATCH);
 
2532
          RRETURN(MATCH_NOMATCH);
2169
2533
        break;
2170
2534
 
2171
2535
        case PT_SC:
2172
2536
        if ((ecode[2] != prop->script) == (op == OP_PROP))
2173
 
          MRRETURN(MATCH_NOMATCH);
 
2537
          RRETURN(MATCH_NOMATCH);
2174
2538
        break;
2175
2539
 
2176
2540
        /* These are specials */
2177
2541
 
2178
2542
        case PT_ALNUM:
2179
 
        if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||
2180
 
             _pcre_ucp_gentype[prop->chartype] == ucp_N) == (op == OP_NOTPROP))
2181
 
          MRRETURN(MATCH_NOMATCH);
 
2543
        if ((PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
 
2544
             PRIV(ucp_gentype)[prop->chartype] == ucp_N) == (op == OP_NOTPROP))
 
2545
          RRETURN(MATCH_NOMATCH);
2182
2546
        break;
2183
2547
 
2184
2548
        case PT_SPACE:    /* Perl space */
2185
 
        if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||
 
2549
        if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z ||
2186
2550
             c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)
2187
2551
               == (op == OP_NOTPROP))
2188
 
          MRRETURN(MATCH_NOMATCH);
 
2552
          RRETURN(MATCH_NOMATCH);
2189
2553
        break;
2190
2554
 
2191
2555
        case PT_PXSPACE:  /* POSIX space */
2192
 
        if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||
 
2556
        if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z ||
2193
2557
             c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
2194
2558
             c == CHAR_FF || c == CHAR_CR)
2195
2559
               == (op == OP_NOTPROP))
2196
 
          MRRETURN(MATCH_NOMATCH);
 
2560
          RRETURN(MATCH_NOMATCH);
2197
2561
        break;
2198
2562
 
2199
2563
        case PT_WORD:
2200
 
        if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||
2201
 
             _pcre_ucp_gentype[prop->chartype] == ucp_N ||
 
2564
        if ((PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
 
2565
             PRIV(ucp_gentype)[prop->chartype] == ucp_N ||
2202
2566
             c == CHAR_UNDERSCORE) == (op == OP_NOTPROP))
2203
 
          MRRETURN(MATCH_NOMATCH);
 
2567
          RRETURN(MATCH_NOMATCH);
2204
2568
        break;
2205
2569
 
2206
2570
        /* This should never occur */
2220
2584
    if (eptr >= md->end_subject)
2221
2585
      {
2222
2586
      SCHECK_PARTIAL();
2223
 
      MRRETURN(MATCH_NOMATCH);
 
2587
      RRETURN(MATCH_NOMATCH);
2224
2588
      }
2225
2589
    GETCHARINCTEST(c, eptr);
 
2590
    if (UCD_CATEGORY(c) == ucp_M) RRETURN(MATCH_NOMATCH);
 
2591
    while (eptr < md->end_subject)
2226
2592
      {
2227
 
      int category = UCD_CATEGORY(c);
2228
 
      if (category == ucp_M) MRRETURN(MATCH_NOMATCH);
2229
 
      while (eptr < md->end_subject)
2230
 
        {
2231
 
        int len = 1;
2232
 
        if (!utf8) c = *eptr; else
2233
 
          {
2234
 
          GETCHARLEN(c, eptr, len);
2235
 
          }
2236
 
        category = UCD_CATEGORY(c);
2237
 
        if (category != ucp_M) break;
2238
 
        eptr += len;
2239
 
        }
 
2593
      int len = 1;
 
2594
      if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); }
 
2595
      if (UCD_CATEGORY(c) != ucp_M) break;
 
2596
      eptr += len;
2240
2597
      }
2241
2598
    ecode++;
2242
2599
    break;
2252
2609
    loops). */
2253
2610
 
2254
2611
    case OP_REF:
2255
 
      {
2256
 
      offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
2257
 
      ecode += 3;
2258
 
 
2259
 
      /* If the reference is unset, there are two possibilities:
2260
 
 
2261
 
      (a) In the default, Perl-compatible state, set the length to be longer
2262
 
      than the amount of subject left; this ensures that every attempt at a
2263
 
      match fails. We can't just fail here, because of the possibility of
2264
 
      quantifiers with zero minima.
2265
 
 
2266
 
      (b) If the JavaScript compatibility flag is set, set the length to zero
2267
 
      so that the back reference matches an empty string.
2268
 
 
2269
 
      Otherwise, set the length to the length of what was matched by the
2270
 
      referenced subpattern. */
2271
 
 
2272
 
      if (offset >= offset_top || md->offset_vector[offset] < 0)
2273
 
        length = (md->jscript_compat)? 0 : (int)(md->end_subject - eptr + 1);
2274
 
      else
2275
 
        length = md->offset_vector[offset+1] - md->offset_vector[offset];
2276
 
 
2277
 
      /* Set up for repetition, or handle the non-repeated case */
2278
 
 
2279
 
      switch (*ecode)
2280
 
        {
2281
 
        case OP_CRSTAR:
2282
 
        case OP_CRMINSTAR:
2283
 
        case OP_CRPLUS:
2284
 
        case OP_CRMINPLUS:
2285
 
        case OP_CRQUERY:
2286
 
        case OP_CRMINQUERY:
2287
 
        c = *ecode++ - OP_CRSTAR;
2288
 
        minimize = (c & 1) != 0;
2289
 
        min = rep_min[c];                 /* Pick up values from tables; */
2290
 
        max = rep_max[c];                 /* zero for max => infinity */
2291
 
        if (max == 0) max = INT_MAX;
2292
 
        break;
2293
 
 
2294
 
        case OP_CRRANGE:
2295
 
        case OP_CRMINRANGE:
2296
 
        minimize = (*ecode == OP_CRMINRANGE);
2297
 
        min = GET2(ecode, 1);
2298
 
        max = GET2(ecode, 3);
2299
 
        if (max == 0) max = INT_MAX;
2300
 
        ecode += 5;
2301
 
        break;
2302
 
 
2303
 
        default:               /* No repeat follows */
2304
 
        if (!match_ref(offset, eptr, length, md, ims))
2305
 
          {
2306
 
          CHECK_PARTIAL();
2307
 
          MRRETURN(MATCH_NOMATCH);
2308
 
          }
2309
 
        eptr += length;
2310
 
        continue;              /* With the main loop */
2311
 
        }
2312
 
 
2313
 
      /* If the length of the reference is zero, just continue with the
2314
 
      main loop. */
2315
 
 
2316
 
      if (length == 0) continue;
2317
 
 
2318
 
      /* First, ensure the minimum number of matches are present. We get back
2319
 
      the length of the reference string explicitly rather than passing the
2320
 
      address of eptr, so that eptr can be a register variable. */
2321
 
 
2322
 
      for (i = 1; i <= min; i++)
2323
 
        {
2324
 
        if (!match_ref(offset, eptr, length, md, ims))
2325
 
          {
2326
 
          CHECK_PARTIAL();
2327
 
          MRRETURN(MATCH_NOMATCH);
2328
 
          }
2329
 
        eptr += length;
2330
 
        }
2331
 
 
2332
 
      /* If min = max, continue at the same level without recursion.
2333
 
      They are not both allowed to be zero. */
2334
 
 
2335
 
      if (min == max) continue;
2336
 
 
2337
 
      /* If minimizing, keep trying and advancing the pointer */
2338
 
 
2339
 
      if (minimize)
2340
 
        {
2341
 
        for (fi = min;; fi++)
2342
 
          {
2343
 
          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
2344
 
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2345
 
          if (fi >= max) MRRETURN(MATCH_NOMATCH);
2346
 
          if (!match_ref(offset, eptr, length, md, ims))
2347
 
            {
2348
 
            CHECK_PARTIAL();
2349
 
            MRRETURN(MATCH_NOMATCH);
2350
 
            }
2351
 
          eptr += length;
2352
 
          }
2353
 
        /* Control never gets here */
2354
 
        }
2355
 
 
2356
 
      /* If maximizing, find the longest string and work backwards */
2357
 
 
2358
 
      else
2359
 
        {
2360
 
        pp = eptr;
2361
 
        for (i = min; i < max; i++)
2362
 
          {
2363
 
          if (!match_ref(offset, eptr, length, md, ims))
2364
 
            {
2365
 
            CHECK_PARTIAL();
2366
 
            break;
2367
 
            }
2368
 
          eptr += length;
2369
 
          }
2370
 
        while (eptr >= pp)
2371
 
          {
2372
 
          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
2373
 
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2374
 
          eptr -= length;
2375
 
          }
2376
 
        MRRETURN(MATCH_NOMATCH);
2377
 
        }
 
2612
    case OP_REFI:
 
2613
    caseless = op == OP_REFI;
 
2614
    offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
 
2615
    ecode += 1 + IMM2_SIZE;
 
2616
 
 
2617
    /* If the reference is unset, there are two possibilities:
 
2618
 
 
2619
    (a) In the default, Perl-compatible state, set the length negative;
 
2620
    this ensures that every attempt at a match fails. We can't just fail
 
2621
    here, because of the possibility of quantifiers with zero minima.
 
2622
 
 
2623
    (b) If the JavaScript compatibility flag is set, set the length to zero
 
2624
    so that the back reference matches an empty string.
 
2625
 
 
2626
    Otherwise, set the length to the length of what was matched by the
 
2627
    referenced subpattern. */
 
2628
 
 
2629
    if (offset >= offset_top || md->offset_vector[offset] < 0)
 
2630
      length = (md->jscript_compat)? 0 : -1;
 
2631
    else
 
2632
      length = md->offset_vector[offset+1] - md->offset_vector[offset];
 
2633
 
 
2634
    /* Set up for repetition, or handle the non-repeated case */
 
2635
 
 
2636
    switch (*ecode)
 
2637
      {
 
2638
      case OP_CRSTAR:
 
2639
      case OP_CRMINSTAR:
 
2640
      case OP_CRPLUS:
 
2641
      case OP_CRMINPLUS:
 
2642
      case OP_CRQUERY:
 
2643
      case OP_CRMINQUERY:
 
2644
      c = *ecode++ - OP_CRSTAR;
 
2645
      minimize = (c & 1) != 0;
 
2646
      min = rep_min[c];                 /* Pick up values from tables; */
 
2647
      max = rep_max[c];                 /* zero for max => infinity */
 
2648
      if (max == 0) max = INT_MAX;
 
2649
      break;
 
2650
 
 
2651
      case OP_CRRANGE:
 
2652
      case OP_CRMINRANGE:
 
2653
      minimize = (*ecode == OP_CRMINRANGE);
 
2654
      min = GET2(ecode, 1);
 
2655
      max = GET2(ecode, 1 + IMM2_SIZE);
 
2656
      if (max == 0) max = INT_MAX;
 
2657
      ecode += 1 + 2 * IMM2_SIZE;
 
2658
      break;
 
2659
 
 
2660
      default:               /* No repeat follows */
 
2661
      if ((length = match_ref(offset, eptr, length, md, caseless)) < 0)
 
2662
        {
 
2663
        CHECK_PARTIAL();
 
2664
        RRETURN(MATCH_NOMATCH);
 
2665
        }
 
2666
      eptr += length;
 
2667
      continue;              /* With the main loop */
 
2668
      }
 
2669
 
 
2670
    /* Handle repeated back references. If the length of the reference is
 
2671
    zero, just continue with the main loop. If the length is negative, it
 
2672
    means the reference is unset in non-Java-compatible mode. If the minimum is
 
2673
    zero, we can continue at the same level without recursion. For any other
 
2674
    minimum, carrying on will result in NOMATCH. */
 
2675
 
 
2676
    if (length == 0) continue;
 
2677
    if (length < 0 && min == 0) continue;
 
2678
 
 
2679
    /* First, ensure the minimum number of matches are present. We get back
 
2680
    the length of the reference string explicitly rather than passing the
 
2681
    address of eptr, so that eptr can be a register variable. */
 
2682
 
 
2683
    for (i = 1; i <= min; i++)
 
2684
      {
 
2685
      int slength;
 
2686
      if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
 
2687
        {
 
2688
        CHECK_PARTIAL();
 
2689
        RRETURN(MATCH_NOMATCH);
 
2690
        }
 
2691
      eptr += slength;
 
2692
      }
 
2693
 
 
2694
    /* If min = max, continue at the same level without recursion.
 
2695
    They are not both allowed to be zero. */
 
2696
 
 
2697
    if (min == max) continue;
 
2698
 
 
2699
    /* If minimizing, keep trying and advancing the pointer */
 
2700
 
 
2701
    if (minimize)
 
2702
      {
 
2703
      for (fi = min;; fi++)
 
2704
        {
 
2705
        int slength;
 
2706
        RMATCH(eptr, ecode, offset_top, md, eptrb, RM14);
 
2707
        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
 
2708
        if (fi >= max) RRETURN(MATCH_NOMATCH);
 
2709
        if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
 
2710
          {
 
2711
          CHECK_PARTIAL();
 
2712
          RRETURN(MATCH_NOMATCH);
 
2713
          }
 
2714
        eptr += slength;
 
2715
        }
 
2716
      /* Control never gets here */
 
2717
      }
 
2718
 
 
2719
    /* If maximizing, find the longest string and work backwards */
 
2720
 
 
2721
    else
 
2722
      {
 
2723
      pp = eptr;
 
2724
      for (i = min; i < max; i++)
 
2725
        {
 
2726
        int slength;
 
2727
        if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
 
2728
          {
 
2729
          CHECK_PARTIAL();
 
2730
          break;
 
2731
          }
 
2732
        eptr += slength;
 
2733
        }
 
2734
      while (eptr >= pp)
 
2735
        {
 
2736
        RMATCH(eptr, ecode, offset_top, md, eptrb, RM15);
 
2737
        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
 
2738
        eptr -= length;
 
2739
        }
 
2740
      RRETURN(MATCH_NOMATCH);
2378
2741
      }
2379
2742
    /* Control never gets here */
2380
2743
 
2392
2755
    case OP_NCLASS:
2393
2756
    case OP_CLASS:
2394
2757
      {
 
2758
      /* The data variable is saved across frames, so the byte map needs to
 
2759
      be stored there. */
 
2760
#define BYTE_MAP ((pcre_uint8 *)data)
2395
2761
      data = ecode + 1;                /* Save for matching */
2396
 
      ecode += 33;                     /* Advance past the item */
 
2762
      ecode += 1 + (32 / sizeof(pcre_uchar)); /* Advance past the item */
2397
2763
 
2398
2764
      switch (*ecode)
2399
2765
        {
2414
2780
        case OP_CRMINRANGE:
2415
2781
        minimize = (*ecode == OP_CRMINRANGE);
2416
2782
        min = GET2(ecode, 1);
2417
 
        max = GET2(ecode, 3);
 
2783
        max = GET2(ecode, 1 + IMM2_SIZE);
2418
2784
        if (max == 0) max = INT_MAX;
2419
 
        ecode += 5;
 
2785
        ecode += 1 + 2 * IMM2_SIZE;
2420
2786
        break;
2421
2787
 
2422
2788
        default:               /* No repeat follows */
2426
2792
 
2427
2793
      /* First, ensure the minimum number of matches are present. */
2428
2794
 
2429
 
#ifdef SUPPORT_UTF8
2430
 
      /* UTF-8 mode */
2431
 
      if (utf8)
 
2795
#ifdef SUPPORT_UTF
 
2796
      if (utf)
2432
2797
        {
2433
2798
        for (i = 1; i <= min; i++)
2434
2799
          {
2435
2800
          if (eptr >= md->end_subject)
2436
2801
            {
2437
2802
            SCHECK_PARTIAL();
2438
 
            MRRETURN(MATCH_NOMATCH);
 
2803
            RRETURN(MATCH_NOMATCH);
2439
2804
            }
2440
2805
          GETCHARINC(c, eptr);
2441
2806
          if (c > 255)
2442
2807
            {
2443
 
            if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH);
 
2808
            if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
2444
2809
            }
2445
2810
          else
2446
 
            {
2447
 
            if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2448
 
            }
 
2811
            if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2449
2812
          }
2450
2813
        }
2451
2814
      else
2452
2815
#endif
2453
 
      /* Not UTF-8 mode */
 
2816
      /* Not UTF mode */
2454
2817
        {
2455
2818
        for (i = 1; i <= min; i++)
2456
2819
          {
2457
2820
          if (eptr >= md->end_subject)
2458
2821
            {
2459
2822
            SCHECK_PARTIAL();
2460
 
            MRRETURN(MATCH_NOMATCH);
 
2823
            RRETURN(MATCH_NOMATCH);
2461
2824
            }
2462
2825
          c = *eptr++;
2463
 
          if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
 
2826
#ifndef COMPILE_PCRE8
 
2827
          if (c > 255)
 
2828
            {
 
2829
            if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
 
2830
            }
 
2831
          else
 
2832
#endif
 
2833
            if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2464
2834
          }
2465
2835
        }
2466
2836
 
2474
2844
 
2475
2845
      if (minimize)
2476
2846
        {
2477
 
#ifdef SUPPORT_UTF8
2478
 
        /* UTF-8 mode */
2479
 
        if (utf8)
 
2847
#ifdef SUPPORT_UTF
 
2848
        if (utf)
2480
2849
          {
2481
2850
          for (fi = min;; fi++)
2482
2851
            {
2483
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
 
2852
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM16);
2484
2853
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2485
 
            if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
2854
            if (fi >= max) RRETURN(MATCH_NOMATCH);
2486
2855
            if (eptr >= md->end_subject)
2487
2856
              {
2488
2857
              SCHECK_PARTIAL();
2489
 
              MRRETURN(MATCH_NOMATCH);
 
2858
              RRETURN(MATCH_NOMATCH);
2490
2859
              }
2491
2860
            GETCHARINC(c, eptr);
2492
2861
            if (c > 255)
2493
2862
              {
2494
 
              if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH);
 
2863
              if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
2495
2864
              }
2496
2865
            else
2497
 
              {
2498
 
              if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2499
 
              }
 
2866
              if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2500
2867
            }
2501
2868
          }
2502
2869
        else
2503
2870
#endif
2504
 
        /* Not UTF-8 mode */
 
2871
        /* Not UTF mode */
2505
2872
          {
2506
2873
          for (fi = min;; fi++)
2507
2874
            {
2508
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
 
2875
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM17);
2509
2876
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2510
 
            if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
2877
            if (fi >= max) RRETURN(MATCH_NOMATCH);
2511
2878
            if (eptr >= md->end_subject)
2512
2879
              {
2513
2880
              SCHECK_PARTIAL();
2514
 
              MRRETURN(MATCH_NOMATCH);
 
2881
              RRETURN(MATCH_NOMATCH);
2515
2882
              }
2516
2883
            c = *eptr++;
2517
 
            if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
 
2884
#ifndef COMPILE_PCRE8
 
2885
            if (c > 255)
 
2886
              {
 
2887
              if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
 
2888
              }
 
2889
            else
 
2890
#endif
 
2891
              if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2518
2892
            }
2519
2893
          }
2520
2894
        /* Control never gets here */
2526
2900
        {
2527
2901
        pp = eptr;
2528
2902
 
2529
 
#ifdef SUPPORT_UTF8
2530
 
        /* UTF-8 mode */
2531
 
        if (utf8)
 
2903
#ifdef SUPPORT_UTF
 
2904
        if (utf)
2532
2905
          {
2533
2906
          for (i = min; i < max; i++)
2534
2907
            {
2544
2917
              if (op == OP_CLASS) break;
2545
2918
              }
2546
2919
            else
2547
 
              {
2548
 
              if ((data[c/8] & (1 << (c&7))) == 0) break;
2549
 
              }
 
2920
              if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) break;
2550
2921
            eptr += len;
2551
2922
            }
2552
2923
          for (;;)
2553
2924
            {
2554
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
 
2925
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM18);
2555
2926
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2556
2927
            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2557
2928
            BACKCHAR(eptr);
2559
2930
          }
2560
2931
        else
2561
2932
#endif
2562
 
          /* Not UTF-8 mode */
 
2933
          /* Not UTF mode */
2563
2934
          {
2564
2935
          for (i = min; i < max; i++)
2565
2936
            {
2569
2940
              break;
2570
2941
              }
2571
2942
            c = *eptr;
2572
 
            if ((data[c/8] & (1 << (c&7))) == 0) break;
 
2943
#ifndef COMPILE_PCRE8
 
2944
            if (c > 255)
 
2945
              {
 
2946
              if (op == OP_CLASS) break;
 
2947
              }
 
2948
            else
 
2949
#endif
 
2950
              if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) break;
2573
2951
            eptr++;
2574
2952
            }
2575
2953
          while (eptr >= pp)
2576
2954
            {
2577
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
 
2955
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM19);
2578
2956
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2579
2957
            eptr--;
2580
2958
            }
2581
2959
          }
2582
2960
 
2583
 
        MRRETURN(MATCH_NOMATCH);
 
2961
        RRETURN(MATCH_NOMATCH);
2584
2962
        }
 
2963
#undef BYTE_MAP
2585
2964
      }
2586
2965
    /* Control never gets here */
2587
2966
 
2590
2969
    when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8
2591
2970
    mode, because Unicode properties are supported in non-UTF-8 mode. */
2592
2971
 
2593
 
#ifdef SUPPORT_UTF8
 
2972
#if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2594
2973
    case OP_XCLASS:
2595
2974
      {
2596
2975
      data = ecode + 1 + LINK_SIZE;                /* Save for matching */
2615
2994
        case OP_CRMINRANGE:
2616
2995
        minimize = (*ecode == OP_CRMINRANGE);
2617
2996
        min = GET2(ecode, 1);
2618
 
        max = GET2(ecode, 3);
 
2997
        max = GET2(ecode, 1 + IMM2_SIZE);
2619
2998
        if (max == 0) max = INT_MAX;
2620
 
        ecode += 5;
 
2999
        ecode += 1 + 2 * IMM2_SIZE;
2621
3000
        break;
2622
3001
 
2623
3002
        default:               /* No repeat follows */
2632
3011
        if (eptr >= md->end_subject)
2633
3012
          {
2634
3013
          SCHECK_PARTIAL();
2635
 
          MRRETURN(MATCH_NOMATCH);
 
3014
          RRETURN(MATCH_NOMATCH);
2636
3015
          }
2637
3016
        GETCHARINCTEST(c, eptr);
2638
 
        if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH);
 
3017
        if (!PRIV(xclass)(c, data, utf)) RRETURN(MATCH_NOMATCH);
2639
3018
        }
2640
3019
 
2641
3020
      /* If max == min we can continue with the main loop without the
2650
3029
        {
2651
3030
        for (fi = min;; fi++)
2652
3031
          {
2653
 
          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
 
3032
          RMATCH(eptr, ecode, offset_top, md, eptrb, RM20);
2654
3033
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2655
 
          if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
3034
          if (fi >= max) RRETURN(MATCH_NOMATCH);
2656
3035
          if (eptr >= md->end_subject)
2657
3036
            {
2658
3037
            SCHECK_PARTIAL();
2659
 
            MRRETURN(MATCH_NOMATCH);
 
3038
            RRETURN(MATCH_NOMATCH);
2660
3039
            }
2661
3040
          GETCHARINCTEST(c, eptr);
2662
 
          if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH);
 
3041
          if (!PRIV(xclass)(c, data, utf)) RRETURN(MATCH_NOMATCH);
2663
3042
          }
2664
3043
        /* Control never gets here */
2665
3044
        }
2677
3056
            SCHECK_PARTIAL();
2678
3057
            break;
2679
3058
            }
 
3059
#ifdef SUPPORT_UTF
2680
3060
          GETCHARLENTEST(c, eptr, len);
2681
 
          if (!_pcre_xclass(c, data)) break;
 
3061
#else
 
3062
          c = *eptr;
 
3063
#endif
 
3064
          if (!PRIV(xclass)(c, data, utf)) break;
2682
3065
          eptr += len;
2683
3066
          }
2684
3067
        for(;;)
2685
3068
          {
2686
 
          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
 
3069
          RMATCH(eptr, ecode, offset_top, md, eptrb, RM21);
2687
3070
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2688
3071
          if (eptr-- == pp) break;        /* Stop if tried at original pos */
2689
 
          if (utf8) BACKCHAR(eptr);
 
3072
#ifdef SUPPORT_UTF
 
3073
          if (utf) BACKCHAR(eptr);
 
3074
#endif
2690
3075
          }
2691
 
        MRRETURN(MATCH_NOMATCH);
 
3076
        RRETURN(MATCH_NOMATCH);
2692
3077
        }
2693
3078
 
2694
3079
      /* Control never gets here */
2698
3083
    /* Match a single character, casefully */
2699
3084
 
2700
3085
    case OP_CHAR:
2701
 
#ifdef SUPPORT_UTF8
2702
 
    if (utf8)
 
3086
#ifdef SUPPORT_UTF
 
3087
    if (utf)
2703
3088
      {
2704
3089
      length = 1;
2705
3090
      ecode++;
2707
3092
      if (length > md->end_subject - eptr)
2708
3093
        {
2709
3094
        CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2710
 
        MRRETURN(MATCH_NOMATCH);
 
3095
        RRETURN(MATCH_NOMATCH);
2711
3096
        }
2712
 
      while (length-- > 0) if (*ecode++ != *eptr++) MRRETURN(MATCH_NOMATCH);
 
3097
      while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);
2713
3098
      }
2714
3099
    else
2715
3100
#endif
2716
 
 
2717
 
    /* Non-UTF-8 mode */
 
3101
    /* Not UTF mode */
2718
3102
      {
2719
3103
      if (md->end_subject - eptr < 1)
2720
3104
        {
2721
3105
        SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2722
 
        MRRETURN(MATCH_NOMATCH);
 
3106
        RRETURN(MATCH_NOMATCH);
2723
3107
        }
2724
 
      if (ecode[1] != *eptr++) MRRETURN(MATCH_NOMATCH);
 
3108
      if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);
2725
3109
      ecode += 2;
2726
3110
      }
2727
3111
    break;
2728
3112
 
2729
 
    /* Match a single character, caselessly */
2730
 
 
2731
 
    case OP_CHARNC:
2732
 
#ifdef SUPPORT_UTF8
2733
 
    if (utf8)
 
3113
    /* Match a single character, caselessly. If we are at the end of the
 
3114
    subject, give up immediately. */
 
3115
 
 
3116
    case OP_CHARI:
 
3117
    if (eptr >= md->end_subject)
 
3118
      {
 
3119
      SCHECK_PARTIAL();
 
3120
      RRETURN(MATCH_NOMATCH);
 
3121
      }
 
3122
 
 
3123
#ifdef SUPPORT_UTF
 
3124
    if (utf)
2734
3125
      {
2735
3126
      length = 1;
2736
3127
      ecode++;
2737
3128
      GETCHARLEN(fc, ecode, length);
2738
3129
 
2739
 
      if (length > md->end_subject - eptr)
2740
 
        {
2741
 
        CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2742
 
        MRRETURN(MATCH_NOMATCH);
2743
 
        }
2744
 
 
2745
3130
      /* If the pattern character's value is < 128, we have only one byte, and
2746
 
      can use the fast lookup table. */
 
3131
      we know that its other case must also be one byte long, so we can use the
 
3132
      fast lookup table. We know that there is at least one byte left in the
 
3133
      subject. */
2747
3134
 
2748
3135
      if (fc < 128)
2749
3136
        {
2750
 
        if (md->lcc[*ecode++] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
 
3137
        if (md->lcc[fc]
 
3138
            != TABLE_GET(*eptr, md->lcc, *eptr)) RRETURN(MATCH_NOMATCH);
 
3139
        ecode++;
 
3140
        eptr++;
2751
3141
        }
2752
3142
 
2753
 
      /* Otherwise we must pick up the subject character */
 
3143
      /* Otherwise we must pick up the subject character. Note that we cannot
 
3144
      use the value of "length" to check for sufficient bytes left, because the
 
3145
      other case of the character may have more or fewer bytes.  */
2754
3146
 
2755
3147
      else
2756
3148
        {
2766
3158
#ifdef SUPPORT_UCP
2767
3159
          if (dc != UCD_OTHERCASE(fc))
2768
3160
#endif
2769
 
            MRRETURN(MATCH_NOMATCH);
 
3161
            RRETURN(MATCH_NOMATCH);
2770
3162
          }
2771
3163
        }
2772
3164
      }
2773
3165
    else
2774
 
#endif   /* SUPPORT_UTF8 */
 
3166
#endif   /* SUPPORT_UTF */
2775
3167
 
2776
 
    /* Non-UTF-8 mode */
 
3168
    /* Not UTF mode */
2777
3169
      {
2778
 
      if (md->end_subject - eptr < 1)
2779
 
        {
2780
 
        SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2781
 
        MRRETURN(MATCH_NOMATCH);
2782
 
        }
2783
 
      if (md->lcc[ecode[1]] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
 
3170
      if (TABLE_GET(ecode[1], md->lcc, ecode[1])
 
3171
          != TABLE_GET(*eptr, md->lcc, *eptr)) RRETURN(MATCH_NOMATCH);
 
3172
      eptr++;
2784
3173
      ecode += 2;
2785
3174
      }
2786
3175
    break;
2788
3177
    /* Match a single character repeatedly. */
2789
3178
 
2790
3179
    case OP_EXACT:
 
3180
    case OP_EXACTI:
2791
3181
    min = max = GET2(ecode, 1);
2792
 
    ecode += 3;
 
3182
    ecode += 1 + IMM2_SIZE;
2793
3183
    goto REPEATCHAR;
2794
3184
 
2795
3185
    case OP_POSUPTO:
 
3186
    case OP_POSUPTOI:
2796
3187
    possessive = TRUE;
2797
3188
    /* Fall through */
2798
3189
 
2799
3190
    case OP_UPTO:
 
3191
    case OP_UPTOI:
2800
3192
    case OP_MINUPTO:
 
3193
    case OP_MINUPTOI:
2801
3194
    min = 0;
2802
3195
    max = GET2(ecode, 1);
2803
 
    minimize = *ecode == OP_MINUPTO;
2804
 
    ecode += 3;
 
3196
    minimize = *ecode == OP_MINUPTO || *ecode == OP_MINUPTOI;
 
3197
    ecode += 1 + IMM2_SIZE;
2805
3198
    goto REPEATCHAR;
2806
3199
 
2807
3200
    case OP_POSSTAR:
 
3201
    case OP_POSSTARI:
2808
3202
    possessive = TRUE;
2809
3203
    min = 0;
2810
3204
    max = INT_MAX;
2812
3206
    goto REPEATCHAR;
2813
3207
 
2814
3208
    case OP_POSPLUS:
 
3209
    case OP_POSPLUSI:
2815
3210
    possessive = TRUE;
2816
3211
    min = 1;
2817
3212
    max = INT_MAX;
2819
3214
    goto REPEATCHAR;
2820
3215
 
2821
3216
    case OP_POSQUERY:
 
3217
    case OP_POSQUERYI:
2822
3218
    possessive = TRUE;
2823
3219
    min = 0;
2824
3220
    max = 1;
2826
3222
    goto REPEATCHAR;
2827
3223
 
2828
3224
    case OP_STAR:
 
3225
    case OP_STARI:
2829
3226
    case OP_MINSTAR:
 
3227
    case OP_MINSTARI:
2830
3228
    case OP_PLUS:
 
3229
    case OP_PLUSI:
2831
3230
    case OP_MINPLUS:
 
3231
    case OP_MINPLUSI:
2832
3232
    case OP_QUERY:
 
3233
    case OP_QUERYI:
2833
3234
    case OP_MINQUERY:
2834
 
    c = *ecode++ - OP_STAR;
 
3235
    case OP_MINQUERYI:
 
3236
    c = *ecode++ - ((op < OP_STARI)? OP_STAR : OP_STARI);
2835
3237
    minimize = (c & 1) != 0;
2836
 
 
2837
3238
    min = rep_min[c];                 /* Pick up values from tables; */
2838
3239
    max = rep_max[c];                 /* zero for max => infinity */
2839
3240
    if (max == 0) max = INT_MAX;
2841
3242
    /* Common code for all repeated single-character matches. */
2842
3243
 
2843
3244
    REPEATCHAR:
2844
 
#ifdef SUPPORT_UTF8
2845
 
    if (utf8)
 
3245
#ifdef SUPPORT_UTF
 
3246
    if (utf)
2846
3247
      {
2847
3248
      length = 1;
2848
3249
      charptr = ecode;
2856
3257
        {
2857
3258
#ifdef SUPPORT_UCP
2858
3259
        unsigned int othercase;
2859
 
        if ((ims & PCRE_CASELESS) != 0 &&
 
3260
        if (op >= OP_STARI &&     /* Caseless */
2860
3261
            (othercase = UCD_OTHERCASE(fc)) != fc)
2861
 
          oclength = _pcre_ord2utf8(othercase, occhars);
 
3262
          oclength = PRIV(ord2utf)(othercase, occhars);
2862
3263
        else oclength = 0;
2863
3264
#endif  /* SUPPORT_UCP */
2864
3265
 
2865
3266
        for (i = 1; i <= min; i++)
2866
3267
          {
2867
3268
          if (eptr <= md->end_subject - length &&
2868
 
            memcmp(eptr, charptr, length) == 0) eptr += length;
 
3269
            memcmp(eptr, charptr, IN_UCHARS(length)) == 0) eptr += length;
2869
3270
#ifdef SUPPORT_UCP
2870
3271
          else if (oclength > 0 &&
2871
3272
                   eptr <= md->end_subject - oclength &&
2872
 
                   memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
 
3273
                   memcmp(eptr, occhars, IN_UCHARS(oclength)) == 0) eptr += oclength;
2873
3274
#endif  /* SUPPORT_UCP */
2874
3275
          else
2875
3276
            {
2876
3277
            CHECK_PARTIAL();
2877
 
            MRRETURN(MATCH_NOMATCH);
 
3278
            RRETURN(MATCH_NOMATCH);
2878
3279
            }
2879
3280
          }
2880
3281
 
2884
3285
          {
2885
3286
          for (fi = min;; fi++)
2886
3287
            {
2887
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
 
3288
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM22);
2888
3289
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2889
 
            if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
3290
            if (fi >= max) RRETURN(MATCH_NOMATCH);
2890
3291
            if (eptr <= md->end_subject - length &&
2891
 
              memcmp(eptr, charptr, length) == 0) eptr += length;
 
3292
              memcmp(eptr, charptr, IN_UCHARS(length)) == 0) eptr += length;
2892
3293
#ifdef SUPPORT_UCP
2893
3294
            else if (oclength > 0 &&
2894
3295
                     eptr <= md->end_subject - oclength &&
2895
 
                     memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
 
3296
                     memcmp(eptr, occhars, IN_UCHARS(oclength)) == 0) eptr += oclength;
2896
3297
#endif  /* SUPPORT_UCP */
2897
3298
            else
2898
3299
              {
2899
3300
              CHECK_PARTIAL();
2900
 
              MRRETURN(MATCH_NOMATCH);
 
3301
              RRETURN(MATCH_NOMATCH);
2901
3302
              }
2902
3303
            }
2903
3304
          /* Control never gets here */
2909
3310
          for (i = min; i < max; i++)
2910
3311
            {
2911
3312
            if (eptr <= md->end_subject - length &&
2912
 
                memcmp(eptr, charptr, length) == 0) eptr += length;
 
3313
                memcmp(eptr, charptr, IN_UCHARS(length)) == 0) eptr += length;
2913
3314
#ifdef SUPPORT_UCP
2914
3315
            else if (oclength > 0 &&
2915
3316
                     eptr <= md->end_subject - oclength &&
2916
 
                     memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
 
3317
                     memcmp(eptr, occhars, IN_UCHARS(oclength)) == 0) eptr += oclength;
2917
3318
#endif  /* SUPPORT_UCP */
2918
3319
            else
2919
3320
              {
2926
3327
 
2927
3328
          for(;;)
2928
3329
            {
2929
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
 
3330
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM23);
2930
3331
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2931
 
            if (eptr == pp) { MRRETURN(MATCH_NOMATCH); }
 
3332
            if (eptr == pp) { RRETURN(MATCH_NOMATCH); }
2932
3333
#ifdef SUPPORT_UCP
2933
3334
            eptr--;
2934
3335
            BACKCHAR(eptr);
2945
3346
      value of fc will always be < 128. */
2946
3347
      }
2947
3348
    else
2948
 
#endif  /* SUPPORT_UTF8 */
2949
 
 
2950
 
    /* When not in UTF-8 mode, load a single-byte character. */
2951
 
 
2952
 
    fc = *ecode++;
2953
 
 
2954
 
    /* The value of fc at this point is always less than 256, though we may or
2955
 
    may not be in UTF-8 mode. The code is duplicated for the caseless and
 
3349
#endif  /* SUPPORT_UTF */
 
3350
      /* When not in UTF-8 mode, load a single-byte character. */
 
3351
      fc = *ecode++;
 
3352
 
 
3353
    /* The value of fc at this point is always one character, though we may
 
3354
    or may not be in UTF mode. The code is duplicated for the caseless and
2956
3355
    caseful cases, for speed, since matching characters is likely to be quite
2957
3356
    common. First, ensure the minimum number of matches are present. If min =
2958
3357
    max, continue at the same level without recursing. Otherwise, if
2963
3362
    DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max,
2964
3363
      max, eptr));
2965
3364
 
2966
 
    if ((ims & PCRE_CASELESS) != 0)
 
3365
    if (op >= OP_STARI)  /* Caseless */
2967
3366
      {
2968
 
      fc = md->lcc[fc];
 
3367
#ifdef COMPILE_PCRE8
 
3368
      /* fc must be < 128 if UTF is enabled. */
 
3369
      foc = md->fcc[fc];
 
3370
#else
 
3371
#ifdef SUPPORT_UTF
 
3372
#ifdef SUPPORT_UCP
 
3373
      if (utf && fc > 127)
 
3374
        foc = UCD_OTHERCASE(fc);
 
3375
#else
 
3376
      if (utf && fc > 127)
 
3377
        foc = fc;
 
3378
#endif /* SUPPORT_UCP */
 
3379
      else
 
3380
#endif /* SUPPORT_UTF */
 
3381
        foc = TABLE_GET(fc, md->fcc, fc);
 
3382
#endif /* COMPILE_PCRE8 */
 
3383
 
2969
3384
      for (i = 1; i <= min; i++)
2970
3385
        {
2971
3386
        if (eptr >= md->end_subject)
2972
3387
          {
2973
3388
          SCHECK_PARTIAL();
2974
 
          MRRETURN(MATCH_NOMATCH);
 
3389
          RRETURN(MATCH_NOMATCH);
2975
3390
          }
2976
 
        if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
 
3391
        if (fc != *eptr && foc != *eptr) RRETURN(MATCH_NOMATCH);
 
3392
        eptr++;
2977
3393
        }
2978
3394
      if (min == max) continue;
2979
3395
      if (minimize)
2980
3396
        {
2981
3397
        for (fi = min;; fi++)
2982
3398
          {
2983
 
          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
 
3399
          RMATCH(eptr, ecode, offset_top, md, eptrb, RM24);
2984
3400
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2985
 
          if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
3401
          if (fi >= max) RRETURN(MATCH_NOMATCH);
2986
3402
          if (eptr >= md->end_subject)
2987
3403
            {
2988
3404
            SCHECK_PARTIAL();
2989
 
            MRRETURN(MATCH_NOMATCH);
 
3405
            RRETURN(MATCH_NOMATCH);
2990
3406
            }
2991
 
          if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
 
3407
          if (fc != *eptr && foc != *eptr) RRETURN(MATCH_NOMATCH);
 
3408
          eptr++;
2992
3409
          }
2993
3410
        /* Control never gets here */
2994
3411
        }
3002
3419
            SCHECK_PARTIAL();
3003
3420
            break;
3004
3421
            }
3005
 
          if (fc != md->lcc[*eptr]) break;
 
3422
          if (fc != *eptr && foc != *eptr) break;
3006
3423
          eptr++;
3007
3424
          }
3008
3425
 
3010
3427
 
3011
3428
        while (eptr >= pp)
3012
3429
          {
3013
 
          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
 
3430
          RMATCH(eptr, ecode, offset_top, md, eptrb, RM25);
3014
3431
          eptr--;
3015
3432
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3016
3433
          }
3017
 
        MRRETURN(MATCH_NOMATCH);
 
3434
        RRETURN(MATCH_NOMATCH);
3018
3435
        }
3019
3436
      /* Control never gets here */
3020
3437
      }
3028
3445
        if (eptr >= md->end_subject)
3029
3446
          {
3030
3447
          SCHECK_PARTIAL();
3031
 
          MRRETURN(MATCH_NOMATCH);
 
3448
          RRETURN(MATCH_NOMATCH);
3032
3449
          }
3033
 
        if (fc != *eptr++) MRRETURN(MATCH_NOMATCH);
 
3450
        if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
3034
3451
        }
3035
3452
 
3036
3453
      if (min == max) continue;
3039
3456
        {
3040
3457
        for (fi = min;; fi++)
3041
3458
          {
3042
 
          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
 
3459
          RMATCH(eptr, ecode, offset_top, md, eptrb, RM26);
3043
3460
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3044
 
          if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
3461
          if (fi >= max) RRETURN(MATCH_NOMATCH);
3045
3462
          if (eptr >= md->end_subject)
3046
3463
            {
3047
3464
            SCHECK_PARTIAL();
3048
 
            MRRETURN(MATCH_NOMATCH);
 
3465
            RRETURN(MATCH_NOMATCH);
3049
3466
            }
3050
 
          if (fc != *eptr++) MRRETURN(MATCH_NOMATCH);
 
3467
          if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
3051
3468
          }
3052
3469
        /* Control never gets here */
3053
3470
        }
3068
3485
 
3069
3486
        while (eptr >= pp)
3070
3487
          {
3071
 
          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
 
3488
          RMATCH(eptr, ecode, offset_top, md, eptrb, RM27);
3072
3489
          eptr--;
3073
3490
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3074
3491
          }
3075
 
        MRRETURN(MATCH_NOMATCH);
 
3492
        RRETURN(MATCH_NOMATCH);
3076
3493
        }
3077
3494
      }
3078
3495
    /* Control never gets here */
3081
3498
    checking can be multibyte. */
3082
3499
 
3083
3500
    case OP_NOT:
 
3501
    case OP_NOTI:
3084
3502
    if (eptr >= md->end_subject)
3085
3503
      {
3086
3504
      SCHECK_PARTIAL();
3087
 
      MRRETURN(MATCH_NOMATCH);
 
3505
      RRETURN(MATCH_NOMATCH);
3088
3506
      }
3089
3507
    ecode++;
3090
3508
    GETCHARINCTEST(c, eptr);
3091
 
    if ((ims & PCRE_CASELESS) != 0)
 
3509
    if (op == OP_NOTI)         /* The caseless case */
3092
3510
      {
3093
 
#ifdef SUPPORT_UTF8
3094
 
      if (c < 256)
3095
 
#endif
3096
 
      c = md->lcc[c];
3097
 
      if (md->lcc[*ecode++] == c) MRRETURN(MATCH_NOMATCH);
 
3511
      register unsigned int ch, och;
 
3512
      ch = *ecode++;
 
3513
#ifdef COMPILE_PCRE8
 
3514
      /* ch must be < 128 if UTF is enabled. */
 
3515
      och = md->fcc[ch];
 
3516
#else
 
3517
#ifdef SUPPORT_UTF
 
3518
#ifdef SUPPORT_UCP
 
3519
      if (utf && ch > 127)
 
3520
        och = UCD_OTHERCASE(ch);
 
3521
#else
 
3522
      if (utf && ch > 127)
 
3523
        och = ch;
 
3524
#endif /* SUPPORT_UCP */
 
3525
      else
 
3526
#endif /* SUPPORT_UTF */
 
3527
        och = TABLE_GET(ch, md->fcc, ch);
 
3528
#endif /* COMPILE_PCRE8 */
 
3529
      if (ch == c || och == c) RRETURN(MATCH_NOMATCH);
3098
3530
      }
3099
 
    else
 
3531
    else    /* Caseful */
3100
3532
      {
3101
 
      if (*ecode++ == c) MRRETURN(MATCH_NOMATCH);
 
3533
      if (*ecode++ == c) RRETURN(MATCH_NOMATCH);
3102
3534
      }
3103
3535
    break;
3104
3536
 
3110
3542
    about... */
3111
3543
 
3112
3544
    case OP_NOTEXACT:
 
3545
    case OP_NOTEXACTI:
3113
3546
    min = max = GET2(ecode, 1);
3114
 
    ecode += 3;
 
3547
    ecode += 1 + IMM2_SIZE;
3115
3548
    goto REPEATNOTCHAR;
3116
3549
 
3117
3550
    case OP_NOTUPTO:
 
3551
    case OP_NOTUPTOI:
3118
3552
    case OP_NOTMINUPTO:
 
3553
    case OP_NOTMINUPTOI:
3119
3554
    min = 0;
3120
3555
    max = GET2(ecode, 1);
3121
 
    minimize = *ecode == OP_NOTMINUPTO;
3122
 
    ecode += 3;
 
3556
    minimize = *ecode == OP_NOTMINUPTO || *ecode == OP_NOTMINUPTOI;
 
3557
    ecode += 1 + IMM2_SIZE;
3123
3558
    goto REPEATNOTCHAR;
3124
3559
 
3125
3560
    case OP_NOTPOSSTAR:
 
3561
    case OP_NOTPOSSTARI:
3126
3562
    possessive = TRUE;
3127
3563
    min = 0;
3128
3564
    max = INT_MAX;
3130
3566
    goto REPEATNOTCHAR;
3131
3567
 
3132
3568
    case OP_NOTPOSPLUS:
 
3569
    case OP_NOTPOSPLUSI:
3133
3570
    possessive = TRUE;
3134
3571
    min = 1;
3135
3572
    max = INT_MAX;
3137
3574
    goto REPEATNOTCHAR;
3138
3575
 
3139
3576
    case OP_NOTPOSQUERY:
 
3577
    case OP_NOTPOSQUERYI:
3140
3578
    possessive = TRUE;
3141
3579
    min = 0;
3142
3580
    max = 1;
3144
3582
    goto REPEATNOTCHAR;
3145
3583
 
3146
3584
    case OP_NOTPOSUPTO:
 
3585
    case OP_NOTPOSUPTOI:
3147
3586
    possessive = TRUE;
3148
3587
    min = 0;
3149
3588
    max = GET2(ecode, 1);
3150
 
    ecode += 3;
 
3589
    ecode += 1 + IMM2_SIZE;
3151
3590
    goto REPEATNOTCHAR;
3152
3591
 
3153
3592
    case OP_NOTSTAR:
 
3593
    case OP_NOTSTARI:
3154
3594
    case OP_NOTMINSTAR:
 
3595
    case OP_NOTMINSTARI:
3155
3596
    case OP_NOTPLUS:
 
3597
    case OP_NOTPLUSI:
3156
3598
    case OP_NOTMINPLUS:
 
3599
    case OP_NOTMINPLUSI:
3157
3600
    case OP_NOTQUERY:
 
3601
    case OP_NOTQUERYI:
3158
3602
    case OP_NOTMINQUERY:
3159
 
    c = *ecode++ - OP_NOTSTAR;
 
3603
    case OP_NOTMINQUERYI:
 
3604
    c = *ecode++ - ((op >= OP_NOTSTARI)? OP_NOTSTARI: OP_NOTSTAR);
3160
3605
    minimize = (c & 1) != 0;
3161
3606
    min = rep_min[c];                 /* Pick up values from tables; */
3162
3607
    max = rep_max[c];                 /* zero for max => infinity */
3178
3623
    DPRINTF(("negative matching %c{%d,%d} against subject %.*s\n", fc, min, max,
3179
3624
      max, eptr));
3180
3625
 
3181
 
    if ((ims & PCRE_CASELESS) != 0)
 
3626
    if (op >= OP_NOTSTARI)     /* Caseless */
3182
3627
      {
3183
 
      fc = md->lcc[fc];
 
3628
#ifdef COMPILE_PCRE8
 
3629
      /* fc must be < 128 if UTF is enabled. */
 
3630
      foc = md->fcc[fc];
 
3631
#else
 
3632
#ifdef SUPPORT_UTF
 
3633
#ifdef SUPPORT_UCP
 
3634
      if (utf && fc > 127)
 
3635
        foc = UCD_OTHERCASE(fc);
 
3636
#else
 
3637
      if (utf && fc > 127)
 
3638
        foc = fc;
 
3639
#endif /* SUPPORT_UCP */
 
3640
      else
 
3641
#endif /* SUPPORT_UTF */
 
3642
        foc = TABLE_GET(fc, md->fcc, fc);
 
3643
#endif /* COMPILE_PCRE8 */
3184
3644
 
3185
 
#ifdef SUPPORT_UTF8
3186
 
      /* UTF-8 mode */
3187
 
      if (utf8)
 
3645
#ifdef SUPPORT_UTF
 
3646
      if (utf)
3188
3647
        {
3189
3648
        register unsigned int d;
3190
3649
        for (i = 1; i <= min; i++)
3192
3651
          if (eptr >= md->end_subject)
3193
3652
            {
3194
3653
            SCHECK_PARTIAL();
3195
 
            MRRETURN(MATCH_NOMATCH);
 
3654
            RRETURN(MATCH_NOMATCH);
3196
3655
            }
3197
3656
          GETCHARINC(d, eptr);
3198
 
          if (d < 256) d = md->lcc[d];
3199
 
          if (fc == d) MRRETURN(MATCH_NOMATCH);
 
3657
          if (fc == d || (unsigned int) foc == d) RRETURN(MATCH_NOMATCH);
3200
3658
          }
3201
3659
        }
3202
3660
      else
3203
3661
#endif
3204
 
 
3205
 
      /* Not UTF-8 mode */
 
3662
      /* Not UTF mode */
3206
3663
        {
3207
3664
        for (i = 1; i <= min; i++)
3208
3665
          {
3209
3666
          if (eptr >= md->end_subject)
3210
3667
            {
3211
3668
            SCHECK_PARTIAL();
3212
 
            MRRETURN(MATCH_NOMATCH);
 
3669
            RRETURN(MATCH_NOMATCH);
3213
3670
            }
3214
 
          if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
 
3671
          if (fc == *eptr || foc == *eptr) RRETURN(MATCH_NOMATCH);
 
3672
          eptr++;
3215
3673
          }
3216
3674
        }
3217
3675
 
3219
3677
 
3220
3678
      if (minimize)
3221
3679
        {
3222
 
#ifdef SUPPORT_UTF8
3223
 
        /* UTF-8 mode */
3224
 
        if (utf8)
 
3680
#ifdef SUPPORT_UTF
 
3681
        if (utf)
3225
3682
          {
3226
3683
          register unsigned int d;
3227
3684
          for (fi = min;; fi++)
3228
3685
            {
3229
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
 
3686
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM28);
3230
3687
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3231
 
            if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
3688
            if (fi >= max) RRETURN(MATCH_NOMATCH);
3232
3689
            if (eptr >= md->end_subject)
3233
3690
              {
3234
3691
              SCHECK_PARTIAL();
3235
 
              MRRETURN(MATCH_NOMATCH);
 
3692
              RRETURN(MATCH_NOMATCH);
3236
3693
              }
3237
3694
            GETCHARINC(d, eptr);
3238
 
            if (d < 256) d = md->lcc[d];
3239
 
            if (fc == d) MRRETURN(MATCH_NOMATCH);
 
3695
            if (fc == d || (unsigned int)foc == d) RRETURN(MATCH_NOMATCH);
3240
3696
            }
3241
3697
          }
3242
3698
        else
3243
3699
#endif
3244
 
        /* Not UTF-8 mode */
 
3700
        /* Not UTF mode */
3245
3701
          {
3246
3702
          for (fi = min;; fi++)
3247
3703
            {
3248
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
 
3704
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM29);
3249
3705
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3250
 
            if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
3706
            if (fi >= max) RRETURN(MATCH_NOMATCH);
3251
3707
            if (eptr >= md->end_subject)
3252
3708
              {
3253
3709
              SCHECK_PARTIAL();
3254
 
              MRRETURN(MATCH_NOMATCH);
 
3710
              RRETURN(MATCH_NOMATCH);
3255
3711
              }
3256
 
            if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
 
3712
            if (fc == *eptr || foc == *eptr) RRETURN(MATCH_NOMATCH);
 
3713
            eptr++;
3257
3714
            }
3258
3715
          }
3259
3716
        /* Control never gets here */
3265
3722
        {
3266
3723
        pp = eptr;
3267
3724
 
3268
 
#ifdef SUPPORT_UTF8
3269
 
        /* UTF-8 mode */
3270
 
        if (utf8)
 
3725
#ifdef SUPPORT_UTF
 
3726
        if (utf)
3271
3727
          {
3272
3728
          register unsigned int d;
3273
3729
          for (i = min; i < max; i++)
3279
3735
              break;
3280
3736
              }
3281
3737
            GETCHARLEN(d, eptr, len);
3282
 
            if (d < 256) d = md->lcc[d];
3283
 
            if (fc == d) break;
 
3738
            if (fc == d || (unsigned int)foc == d) break;
3284
3739
            eptr += len;
3285
3740
            }
3286
 
        if (possessive) continue;
3287
 
        for(;;)
 
3741
          if (possessive) continue;
 
3742
          for(;;)
3288
3743
            {
3289
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
 
3744
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM30);
3290
3745
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3291
3746
            if (eptr-- == pp) break;        /* Stop if tried at original pos */
3292
3747
            BACKCHAR(eptr);
3294
3749
          }
3295
3750
        else
3296
3751
#endif
3297
 
        /* Not UTF-8 mode */
 
3752
        /* Not UTF mode */
3298
3753
          {
3299
3754
          for (i = min; i < max; i++)
3300
3755
            {
3303
3758
              SCHECK_PARTIAL();
3304
3759
              break;
3305
3760
              }
3306
 
            if (fc == md->lcc[*eptr]) break;
 
3761
            if (fc == *eptr || foc == *eptr) break;
3307
3762
            eptr++;
3308
3763
            }
3309
3764
          if (possessive) continue;
3310
3765
          while (eptr >= pp)
3311
3766
            {
3312
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
 
3767
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM31);
3313
3768
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3314
3769
            eptr--;
3315
3770
            }
3316
3771
          }
3317
3772
 
3318
 
        MRRETURN(MATCH_NOMATCH);
 
3773
        RRETURN(MATCH_NOMATCH);
3319
3774
        }
3320
3775
      /* Control never gets here */
3321
3776
      }
3324
3779
 
3325
3780
    else
3326
3781
      {
3327
 
#ifdef SUPPORT_UTF8
3328
 
      /* UTF-8 mode */
3329
 
      if (utf8)
 
3782
#ifdef SUPPORT_UTF
 
3783
      if (utf)
3330
3784
        {
3331
3785
        register unsigned int d;
3332
3786
        for (i = 1; i <= min; i++)
3334
3788
          if (eptr >= md->end_subject)
3335
3789
            {
3336
3790
            SCHECK_PARTIAL();
3337
 
            MRRETURN(MATCH_NOMATCH);
 
3791
            RRETURN(MATCH_NOMATCH);
3338
3792
            }
3339
3793
          GETCHARINC(d, eptr);
3340
 
          if (fc == d) MRRETURN(MATCH_NOMATCH);
 
3794
          if (fc == d) RRETURN(MATCH_NOMATCH);
3341
3795
          }
3342
3796
        }
3343
3797
      else
3344
3798
#endif
3345
 
      /* Not UTF-8 mode */
 
3799
      /* Not UTF mode */
3346
3800
        {
3347
3801
        for (i = 1; i <= min; i++)
3348
3802
          {
3349
3803
          if (eptr >= md->end_subject)
3350
3804
            {
3351
3805
            SCHECK_PARTIAL();
3352
 
            MRRETURN(MATCH_NOMATCH);
 
3806
            RRETURN(MATCH_NOMATCH);
3353
3807
            }
3354
 
          if (fc == *eptr++) MRRETURN(MATCH_NOMATCH);
 
3808
          if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
3355
3809
          }
3356
3810
        }
3357
3811
 
3359
3813
 
3360
3814
      if (minimize)
3361
3815
        {
3362
 
#ifdef SUPPORT_UTF8
3363
 
        /* UTF-8 mode */
3364
 
        if (utf8)
 
3816
#ifdef SUPPORT_UTF
 
3817
        if (utf)
3365
3818
          {
3366
3819
          register unsigned int d;
3367
3820
          for (fi = min;; fi++)
3368
3821
            {
3369
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
 
3822
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM32);
3370
3823
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3371
 
            if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
3824
            if (fi >= max) RRETURN(MATCH_NOMATCH);
3372
3825
            if (eptr >= md->end_subject)
3373
3826
              {
3374
3827
              SCHECK_PARTIAL();
3375
 
              MRRETURN(MATCH_NOMATCH);
 
3828
              RRETURN(MATCH_NOMATCH);
3376
3829
              }
3377
3830
            GETCHARINC(d, eptr);
3378
 
            if (fc == d) MRRETURN(MATCH_NOMATCH);
 
3831
            if (fc == d) RRETURN(MATCH_NOMATCH);
3379
3832
            }
3380
3833
          }
3381
3834
        else
3382
3835
#endif
3383
 
        /* Not UTF-8 mode */
 
3836
        /* Not UTF mode */
3384
3837
          {
3385
3838
          for (fi = min;; fi++)
3386
3839
            {
3387
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
 
3840
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM33);
3388
3841
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3389
 
            if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
3842
            if (fi >= max) RRETURN(MATCH_NOMATCH);
3390
3843
            if (eptr >= md->end_subject)
3391
3844
              {
3392
3845
              SCHECK_PARTIAL();
3393
 
              MRRETURN(MATCH_NOMATCH);
 
3846
              RRETURN(MATCH_NOMATCH);
3394
3847
              }
3395
 
            if (fc == *eptr++) MRRETURN(MATCH_NOMATCH);
 
3848
            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
3396
3849
            }
3397
3850
          }
3398
3851
        /* Control never gets here */
3404
3857
        {
3405
3858
        pp = eptr;
3406
3859
 
3407
 
#ifdef SUPPORT_UTF8
3408
 
        /* UTF-8 mode */
3409
 
        if (utf8)
 
3860
#ifdef SUPPORT_UTF
 
3861
        if (utf)
3410
3862
          {
3411
3863
          register unsigned int d;
3412
3864
          for (i = min; i < max; i++)
3424
3876
          if (possessive) continue;
3425
3877
          for(;;)
3426
3878
            {
3427
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
 
3879
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM34);
3428
3880
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3429
3881
            if (eptr-- == pp) break;        /* Stop if tried at original pos */
3430
3882
            BACKCHAR(eptr);
3432
3884
          }
3433
3885
        else
3434
3886
#endif
3435
 
        /* Not UTF-8 mode */
 
3887
        /* Not UTF mode */
3436
3888
          {
3437
3889
          for (i = min; i < max; i++)
3438
3890
            {
3447
3899
          if (possessive) continue;
3448
3900
          while (eptr >= pp)
3449
3901
            {
3450
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
 
3902
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM35);
3451
3903
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3452
3904
            eptr--;
3453
3905
            }
3454
3906
          }
3455
3907
 
3456
 
        MRRETURN(MATCH_NOMATCH);
 
3908
        RRETURN(MATCH_NOMATCH);
3457
3909
        }
3458
3910
      }
3459
3911
    /* Control never gets here */
3465
3917
    case OP_TYPEEXACT:
3466
3918
    min = max = GET2(ecode, 1);
3467
3919
    minimize = TRUE;
3468
 
    ecode += 3;
 
3920
    ecode += 1 + IMM2_SIZE;
3469
3921
    goto REPEATTYPE;
3470
3922
 
3471
3923
    case OP_TYPEUPTO:
3473
3925
    min = 0;
3474
3926
    max = GET2(ecode, 1);
3475
3927
    minimize = *ecode == OP_TYPEMINUPTO;
3476
 
    ecode += 3;
 
3928
    ecode += 1 + IMM2_SIZE;
3477
3929
    goto REPEATTYPE;
3478
3930
 
3479
3931
    case OP_TYPEPOSSTAR:
3501
3953
    possessive = TRUE;
3502
3954
    min = 0;
3503
3955
    max = GET2(ecode, 1);
3504
 
    ecode += 3;
 
3956
    ecode += 1 + IMM2_SIZE;
3505
3957
    goto REPEATTYPE;
3506
3958
 
3507
3959
    case OP_TYPESTAR:
3547
3999
        switch(prop_type)
3548
4000
          {
3549
4001
          case PT_ANY:
3550
 
          if (prop_fail_result) MRRETURN(MATCH_NOMATCH);
 
4002
          if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3551
4003
          for (i = 1; i <= min; i++)
3552
4004
            {
3553
4005
            if (eptr >= md->end_subject)
3554
4006
              {
3555
4007
              SCHECK_PARTIAL();
3556
 
              MRRETURN(MATCH_NOMATCH);
 
4008
              RRETURN(MATCH_NOMATCH);
3557
4009
              }
3558
4010
            GETCHARINCTEST(c, eptr);
3559
4011
            }
3562
4014
          case PT_LAMP:
3563
4015
          for (i = 1; i <= min; i++)
3564
4016
            {
 
4017
            int chartype;
3565
4018
            if (eptr >= md->end_subject)
3566
4019
              {
3567
4020
              SCHECK_PARTIAL();
3568
 
              MRRETURN(MATCH_NOMATCH);
 
4021
              RRETURN(MATCH_NOMATCH);
3569
4022
              }
3570
4023
            GETCHARINCTEST(c, eptr);
3571
 
            prop_chartype = UCD_CHARTYPE(c);
3572
 
            if ((prop_chartype == ucp_Lu ||
3573
 
                 prop_chartype == ucp_Ll ||
3574
 
                 prop_chartype == ucp_Lt) == prop_fail_result)
3575
 
              MRRETURN(MATCH_NOMATCH);
 
4024
            chartype = UCD_CHARTYPE(c);
 
4025
            if ((chartype == ucp_Lu ||
 
4026
                 chartype == ucp_Ll ||
 
4027
                 chartype == ucp_Lt) == prop_fail_result)
 
4028
              RRETURN(MATCH_NOMATCH);
3576
4029
            }
3577
4030
          break;
3578
4031
 
3582
4035
            if (eptr >= md->end_subject)
3583
4036
              {
3584
4037
              SCHECK_PARTIAL();
3585
 
              MRRETURN(MATCH_NOMATCH);
 
4038
              RRETURN(MATCH_NOMATCH);
3586
4039
              }
3587
4040
            GETCHARINCTEST(c, eptr);
3588
 
            prop_category = UCD_CATEGORY(c);
3589
 
            if ((prop_category == prop_value) == prop_fail_result)
3590
 
              MRRETURN(MATCH_NOMATCH);
 
4041
            if ((UCD_CATEGORY(c) == prop_value) == prop_fail_result)
 
4042
              RRETURN(MATCH_NOMATCH);
3591
4043
            }
3592
4044
          break;
3593
4045
 
3597
4049
            if (eptr >= md->end_subject)
3598
4050
              {
3599
4051
              SCHECK_PARTIAL();
3600
 
              MRRETURN(MATCH_NOMATCH);
 
4052
              RRETURN(MATCH_NOMATCH);
3601
4053
              }
3602
4054
            GETCHARINCTEST(c, eptr);
3603
 
            prop_chartype = UCD_CHARTYPE(c);
3604
 
            if ((prop_chartype == prop_value) == prop_fail_result)
3605
 
              MRRETURN(MATCH_NOMATCH);
 
4055
            if ((UCD_CHARTYPE(c) == prop_value) == prop_fail_result)
 
4056
              RRETURN(MATCH_NOMATCH);
3606
4057
            }
3607
4058
          break;
3608
4059
 
3612
4063
            if (eptr >= md->end_subject)
3613
4064
              {
3614
4065
              SCHECK_PARTIAL();
3615
 
              MRRETURN(MATCH_NOMATCH);
 
4066
              RRETURN(MATCH_NOMATCH);
3616
4067
              }
3617
4068
            GETCHARINCTEST(c, eptr);
3618
 
            prop_script = UCD_SCRIPT(c);
3619
 
            if ((prop_script == prop_value) == prop_fail_result)
3620
 
              MRRETURN(MATCH_NOMATCH);
 
4069
            if ((UCD_SCRIPT(c) == prop_value) == prop_fail_result)
 
4070
              RRETURN(MATCH_NOMATCH);
3621
4071
            }
3622
4072
          break;
3623
4073
 
3624
4074
          case PT_ALNUM:
3625
4075
          for (i = 1; i <= min; i++)
3626
4076
            {
 
4077
            int category;
3627
4078
            if (eptr >= md->end_subject)
3628
4079
              {
3629
4080
              SCHECK_PARTIAL();
3630
 
              MRRETURN(MATCH_NOMATCH);
 
4081
              RRETURN(MATCH_NOMATCH);
3631
4082
              }
3632
4083
            GETCHARINCTEST(c, eptr);
3633
 
            prop_category = UCD_CATEGORY(c);
3634
 
            if ((prop_category == ucp_L || prop_category == ucp_N)
3635
 
                   == prop_fail_result)
3636
 
              MRRETURN(MATCH_NOMATCH);
 
4084
            category = UCD_CATEGORY(c);
 
4085
            if ((category == ucp_L || category == ucp_N) == prop_fail_result)
 
4086
              RRETURN(MATCH_NOMATCH);
3637
4087
            }
3638
4088
          break;
3639
4089
 
3643
4093
            if (eptr >= md->end_subject)
3644
4094
              {
3645
4095
              SCHECK_PARTIAL();
3646
 
              MRRETURN(MATCH_NOMATCH);
 
4096
              RRETURN(MATCH_NOMATCH);
3647
4097
              }
3648
4098
            GETCHARINCTEST(c, eptr);
3649
 
            prop_category = UCD_CATEGORY(c);
3650
 
            if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
 
4099
            if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
3651
4100
                 c == CHAR_FF || c == CHAR_CR)
3652
4101
                   == prop_fail_result)
3653
 
              MRRETURN(MATCH_NOMATCH);
 
4102
              RRETURN(MATCH_NOMATCH);
3654
4103
            }
3655
4104
          break;
3656
4105
 
3660
4109
            if (eptr >= md->end_subject)
3661
4110
              {
3662
4111
              SCHECK_PARTIAL();
3663
 
              MRRETURN(MATCH_NOMATCH);
 
4112
              RRETURN(MATCH_NOMATCH);
3664
4113
              }
3665
4114
            GETCHARINCTEST(c, eptr);
3666
 
            prop_category = UCD_CATEGORY(c);
3667
 
            if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
 
4115
            if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
3668
4116
                 c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)
3669
4117
                   == prop_fail_result)
3670
 
              MRRETURN(MATCH_NOMATCH);
 
4118
              RRETURN(MATCH_NOMATCH);
3671
4119
            }
3672
4120
          break;
3673
4121
 
3674
4122
          case PT_WORD:
3675
4123
          for (i = 1; i <= min; i++)
3676
4124
            {
 
4125
            int category;
3677
4126
            if (eptr >= md->end_subject)
3678
4127
              {
3679
4128
              SCHECK_PARTIAL();
3680
 
              MRRETURN(MATCH_NOMATCH);
 
4129
              RRETURN(MATCH_NOMATCH);
3681
4130
              }
3682
4131
            GETCHARINCTEST(c, eptr);
3683
 
            prop_category = UCD_CATEGORY(c);
3684
 
            if ((prop_category == ucp_L || prop_category == ucp_N ||
3685
 
                 c == CHAR_UNDERSCORE)
 
4132
            category = UCD_CATEGORY(c);
 
4133
            if ((category == ucp_L || category == ucp_N || c == CHAR_UNDERSCORE)
3686
4134
                   == prop_fail_result)
3687
 
              MRRETURN(MATCH_NOMATCH);
 
4135
              RRETURN(MATCH_NOMATCH);
3688
4136
            }
3689
4137
          break;
3690
4138
 
3705
4153
          if (eptr >= md->end_subject)
3706
4154
            {
3707
4155
            SCHECK_PARTIAL();
3708
 
            MRRETURN(MATCH_NOMATCH);
 
4156
            RRETURN(MATCH_NOMATCH);
3709
4157
            }
3710
4158
          GETCHARINCTEST(c, eptr);
3711
 
          prop_category = UCD_CATEGORY(c);
3712
 
          if (prop_category == ucp_M) MRRETURN(MATCH_NOMATCH);
 
4159
          if (UCD_CATEGORY(c) == ucp_M) RRETURN(MATCH_NOMATCH);
3713
4160
          while (eptr < md->end_subject)
3714
4161
            {
3715
4162
            int len = 1;
3716
 
            if (!utf8) c = *eptr;
3717
 
              else { GETCHARLEN(c, eptr, len); }
3718
 
            prop_category = UCD_CATEGORY(c);
3719
 
            if (prop_category != ucp_M) break;
 
4163
            if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); }
 
4164
            if (UCD_CATEGORY(c) != ucp_M) break;
3720
4165
            eptr += len;
3721
4166
            }
3722
4167
          }
3727
4172
 
3728
4173
/* Handle all other cases when the coding is UTF-8 */
3729
4174
 
3730
 
#ifdef SUPPORT_UTF8
3731
 
      if (utf8) switch(ctype)
 
4175
#ifdef SUPPORT_UTF
 
4176
      if (utf) switch(ctype)
3732
4177
        {
3733
4178
        case OP_ANY:
3734
4179
        for (i = 1; i <= min; i++)
3736
4181
          if (eptr >= md->end_subject)
3737
4182
            {
3738
4183
            SCHECK_PARTIAL();
3739
 
            MRRETURN(MATCH_NOMATCH);
 
4184
            RRETURN(MATCH_NOMATCH);
3740
4185
            }
3741
 
          if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);
 
4186
          if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3742
4187
          eptr++;
3743
 
          while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
 
4188
          ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
3744
4189
          }
3745
4190
        break;
3746
4191
 
3750
4195
          if (eptr >= md->end_subject)
3751
4196
            {
3752
4197
            SCHECK_PARTIAL();
3753
 
            MRRETURN(MATCH_NOMATCH);
 
4198
            RRETURN(MATCH_NOMATCH);
3754
4199
            }
3755
4200
          eptr++;
3756
 
          while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
 
4201
          ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
3757
4202
          }
3758
4203
        break;
3759
4204
 
3760
4205
        case OP_ANYBYTE:
3761
 
        if (eptr > md->end_subject - min) MRRETURN(MATCH_NOMATCH);
 
4206
        if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH);
3762
4207
        eptr += min;
3763
4208
        break;
3764
4209
 
3768
4213
          if (eptr >= md->end_subject)
3769
4214
            {
3770
4215
            SCHECK_PARTIAL();
3771
 
            MRRETURN(MATCH_NOMATCH);
 
4216
            RRETURN(MATCH_NOMATCH);
3772
4217
            }
3773
4218
          GETCHARINC(c, eptr);
3774
4219
          switch(c)
3775
4220
            {
3776
 
            default: MRRETURN(MATCH_NOMATCH);
 
4221
            default: RRETURN(MATCH_NOMATCH);
 
4222
 
3777
4223
            case 0x000d:
3778
4224
            if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3779
4225
            break;
3786
4232
            case 0x0085:
3787
4233
            case 0x2028:
3788
4234
            case 0x2029:
3789
 
            if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
 
4235
            if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3790
4236
            break;
3791
4237
            }
3792
4238
          }
3798
4244
          if (eptr >= md->end_subject)
3799
4245
            {
3800
4246
            SCHECK_PARTIAL();
3801
 
            MRRETURN(MATCH_NOMATCH);
 
4247
            RRETURN(MATCH_NOMATCH);
3802
4248
            }
3803
4249
          GETCHARINC(c, eptr);
3804
4250
          switch(c)
3823
4269
            case 0x202f:    /* NARROW NO-BREAK SPACE */
3824
4270
            case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3825
4271
            case 0x3000:    /* IDEOGRAPHIC SPACE */
3826
 
            MRRETURN(MATCH_NOMATCH);
 
4272
            RRETURN(MATCH_NOMATCH);
3827
4273
            }
3828
4274
          }
3829
4275
        break;
3834
4280
          if (eptr >= md->end_subject)
3835
4281
            {
3836
4282
            SCHECK_PARTIAL();
3837
 
            MRRETURN(MATCH_NOMATCH);
 
4283
            RRETURN(MATCH_NOMATCH);
3838
4284
            }
3839
4285
          GETCHARINC(c, eptr);
3840
4286
          switch(c)
3841
4287
            {
3842
 
            default: MRRETURN(MATCH_NOMATCH);
 
4288
            default: RRETURN(MATCH_NOMATCH);
3843
4289
            case 0x09:      /* HT */
3844
4290
            case 0x20:      /* SPACE */
3845
4291
            case 0xa0:      /* NBSP */
3870
4316
          if (eptr >= md->end_subject)
3871
4317
            {
3872
4318
            SCHECK_PARTIAL();
3873
 
            MRRETURN(MATCH_NOMATCH);
 
4319
            RRETURN(MATCH_NOMATCH);
3874
4320
            }
3875
4321
          GETCHARINC(c, eptr);
3876
4322
          switch(c)
3883
4329
            case 0x85:      /* NEL */
3884
4330
            case 0x2028:    /* LINE SEPARATOR */
3885
4331
            case 0x2029:    /* PARAGRAPH SEPARATOR */
3886
 
            MRRETURN(MATCH_NOMATCH);
 
4332
            RRETURN(MATCH_NOMATCH);
3887
4333
            }
3888
4334
          }
3889
4335
        break;
3894
4340
          if (eptr >= md->end_subject)
3895
4341
            {
3896
4342
            SCHECK_PARTIAL();
3897
 
            MRRETURN(MATCH_NOMATCH);
 
4343
            RRETURN(MATCH_NOMATCH);
3898
4344
            }
3899
4345
          GETCHARINC(c, eptr);
3900
4346
          switch(c)
3901
4347
            {
3902
 
            default: MRRETURN(MATCH_NOMATCH);
 
4348
            default: RRETURN(MATCH_NOMATCH);
3903
4349
            case 0x0a:      /* LF */
3904
4350
            case 0x0b:      /* VT */
3905
4351
            case 0x0c:      /* FF */
3918
4364
          if (eptr >= md->end_subject)
3919
4365
            {
3920
4366
            SCHECK_PARTIAL();
3921
 
            MRRETURN(MATCH_NOMATCH);
 
4367
            RRETURN(MATCH_NOMATCH);
3922
4368
            }
3923
4369
          GETCHARINC(c, eptr);
3924
4370
          if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
3925
 
            MRRETURN(MATCH_NOMATCH);
 
4371
            RRETURN(MATCH_NOMATCH);
3926
4372
          }
3927
4373
        break;
3928
4374
 
3932
4378
          if (eptr >= md->end_subject)
3933
4379
            {
3934
4380
            SCHECK_PARTIAL();
3935
 
            MRRETURN(MATCH_NOMATCH);
 
4381
            RRETURN(MATCH_NOMATCH);
3936
4382
            }
3937
 
          if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)
3938
 
            MRRETURN(MATCH_NOMATCH);
 
4383
          if (*eptr >= 128 || (md->ctypes[*eptr] & ctype_digit) == 0)
 
4384
            RRETURN(MATCH_NOMATCH);
 
4385
          eptr++;
3939
4386
          /* No need to skip more bytes - we know it's a 1-byte character */
3940
4387
          }
3941
4388
        break;
3946
4393
          if (eptr >= md->end_subject)
3947
4394
            {
3948
4395
            SCHECK_PARTIAL();
3949
 
            MRRETURN(MATCH_NOMATCH);
 
4396
            RRETURN(MATCH_NOMATCH);
3950
4397
            }
3951
4398
          if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)
3952
 
            MRRETURN(MATCH_NOMATCH);
3953
 
          while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
 
4399
            RRETURN(MATCH_NOMATCH);
 
4400
          eptr++;
 
4401
          ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
3954
4402
          }
3955
4403
        break;
3956
4404
 
3960
4408
          if (eptr >= md->end_subject)
3961
4409
            {
3962
4410
            SCHECK_PARTIAL();
3963
 
            MRRETURN(MATCH_NOMATCH);
 
4411
            RRETURN(MATCH_NOMATCH);
3964
4412
            }
3965
 
          if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)
3966
 
            MRRETURN(MATCH_NOMATCH);
 
4413
          if (*eptr >= 128 || (md->ctypes[*eptr] & ctype_space) == 0)
 
4414
            RRETURN(MATCH_NOMATCH);
 
4415
          eptr++;
3967
4416
          /* No need to skip more bytes - we know it's a 1-byte character */
3968
4417
          }
3969
4418
        break;
3974
4423
          if (eptr >= md->end_subject)
3975
4424
            {
3976
4425
            SCHECK_PARTIAL();
3977
 
            MRRETURN(MATCH_NOMATCH);
 
4426
            RRETURN(MATCH_NOMATCH);
3978
4427
            }
3979
4428
          if (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)
3980
 
            MRRETURN(MATCH_NOMATCH);
3981
 
          while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
 
4429
            RRETURN(MATCH_NOMATCH);
 
4430
          eptr++;
 
4431
          ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
3982
4432
          }
3983
4433
        break;
3984
4434
 
3988
4438
          if (eptr >= md->end_subject)
3989
4439
            {
3990
4440
            SCHECK_PARTIAL();
3991
 
            MRRETURN(MATCH_NOMATCH);
 
4441
            RRETURN(MATCH_NOMATCH);
3992
4442
            }
3993
 
          if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)
3994
 
            MRRETURN(MATCH_NOMATCH);
 
4443
          if (*eptr >= 128 || (md->ctypes[*eptr] & ctype_word) == 0)
 
4444
            RRETURN(MATCH_NOMATCH);
 
4445
          eptr++;
3995
4446
          /* No need to skip more bytes - we know it's a 1-byte character */
3996
4447
          }
3997
4448
        break;
4001
4452
        }  /* End switch(ctype) */
4002
4453
 
4003
4454
      else
4004
 
#endif     /* SUPPORT_UTF8 */
 
4455
#endif     /* SUPPORT_UTF */
4005
4456
 
4006
4457
      /* Code for the non-UTF-8 case for minimum matching of operators other
4007
4458
      than OP_PROP and OP_NOTPROP. */
4014
4465
          if (eptr >= md->end_subject)
4015
4466
            {
4016
4467
            SCHECK_PARTIAL();
4017
 
            MRRETURN(MATCH_NOMATCH);
 
4468
            RRETURN(MATCH_NOMATCH);
4018
4469
            }
4019
 
          if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);
 
4470
          if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
4020
4471
          eptr++;
4021
4472
          }
4022
4473
        break;
4025
4476
        if (eptr > md->end_subject - min)
4026
4477
          {
4027
4478
          SCHECK_PARTIAL();
4028
 
          MRRETURN(MATCH_NOMATCH);
 
4479
          RRETURN(MATCH_NOMATCH);
4029
4480
          }
4030
4481
        eptr += min;
4031
4482
        break;
4034
4485
        if (eptr > md->end_subject - min)
4035
4486
          {
4036
4487
          SCHECK_PARTIAL();
4037
 
          MRRETURN(MATCH_NOMATCH);
 
4488
          RRETURN(MATCH_NOMATCH);
4038
4489
          }
4039
4490
        eptr += min;
4040
4491
        break;
4045
4496
          if (eptr >= md->end_subject)
4046
4497
            {
4047
4498
            SCHECK_PARTIAL();
4048
 
            MRRETURN(MATCH_NOMATCH);
 
4499
            RRETURN(MATCH_NOMATCH);
4049
4500
            }
4050
4501
          switch(*eptr++)
4051
4502
            {
4052
 
            default: MRRETURN(MATCH_NOMATCH);
 
4503
            default: RRETURN(MATCH_NOMATCH);
 
4504
 
4053
4505
            case 0x000d:
4054
4506
            if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
4055
4507
            break;
 
4508
 
4056
4509
            case 0x000a:
4057
4510
            break;
4058
4511
 
4059
4512
            case 0x000b:
4060
4513
            case 0x000c:
4061
4514
            case 0x0085:
4062
 
            if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
 
4515
#ifdef COMPILE_PCRE16
 
4516
            case 0x2028:
 
4517
            case 0x2029:
 
4518
#endif
 
4519
            if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
4063
4520
            break;
4064
4521
            }
4065
4522
          }
4071
4528
          if (eptr >= md->end_subject)
4072
4529
            {
4073
4530
            SCHECK_PARTIAL();
4074
 
            MRRETURN(MATCH_NOMATCH);
 
4531
            RRETURN(MATCH_NOMATCH);
4075
4532
            }
4076
4533
          switch(*eptr++)
4077
4534
            {
4079
4536
            case 0x09:      /* HT */
4080
4537
            case 0x20:      /* SPACE */
4081
4538
            case 0xa0:      /* NBSP */
4082
 
            MRRETURN(MATCH_NOMATCH);
 
4539
#ifdef COMPILE_PCRE16
 
4540
            case 0x1680:    /* OGHAM SPACE MARK */
 
4541
            case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
 
4542
            case 0x2000:    /* EN QUAD */
 
4543
            case 0x2001:    /* EM QUAD */
 
4544
            case 0x2002:    /* EN SPACE */
 
4545
            case 0x2003:    /* EM SPACE */
 
4546
            case 0x2004:    /* THREE-PER-EM SPACE */
 
4547
            case 0x2005:    /* FOUR-PER-EM SPACE */
 
4548
            case 0x2006:    /* SIX-PER-EM SPACE */
 
4549
            case 0x2007:    /* FIGURE SPACE */
 
4550
            case 0x2008:    /* PUNCTUATION SPACE */
 
4551
            case 0x2009:    /* THIN SPACE */
 
4552
            case 0x200A:    /* HAIR SPACE */
 
4553
            case 0x202f:    /* NARROW NO-BREAK SPACE */
 
4554
            case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
 
4555
            case 0x3000:    /* IDEOGRAPHIC SPACE */
 
4556
#endif
 
4557
            RRETURN(MATCH_NOMATCH);
4083
4558
            }
4084
4559
          }
4085
4560
        break;
4090
4565
          if (eptr >= md->end_subject)
4091
4566
            {
4092
4567
            SCHECK_PARTIAL();
4093
 
            MRRETURN(MATCH_NOMATCH);
 
4568
            RRETURN(MATCH_NOMATCH);
4094
4569
            }
4095
4570
          switch(*eptr++)
4096
4571
            {
4097
 
            default: MRRETURN(MATCH_NOMATCH);
 
4572
            default: RRETURN(MATCH_NOMATCH);
4098
4573
            case 0x09:      /* HT */
4099
4574
            case 0x20:      /* SPACE */
4100
4575
            case 0xa0:      /* NBSP */
 
4576
#ifdef COMPILE_PCRE16
 
4577
            case 0x1680:    /* OGHAM SPACE MARK */
 
4578
            case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
 
4579
            case 0x2000:    /* EN QUAD */
 
4580
            case 0x2001:    /* EM QUAD */
 
4581
            case 0x2002:    /* EN SPACE */
 
4582
            case 0x2003:    /* EM SPACE */
 
4583
            case 0x2004:    /* THREE-PER-EM SPACE */
 
4584
            case 0x2005:    /* FOUR-PER-EM SPACE */
 
4585
            case 0x2006:    /* SIX-PER-EM SPACE */
 
4586
            case 0x2007:    /* FIGURE SPACE */
 
4587
            case 0x2008:    /* PUNCTUATION SPACE */
 
4588
            case 0x2009:    /* THIN SPACE */
 
4589
            case 0x200A:    /* HAIR SPACE */
 
4590
            case 0x202f:    /* NARROW NO-BREAK SPACE */
 
4591
            case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
 
4592
            case 0x3000:    /* IDEOGRAPHIC SPACE */
 
4593
#endif
4101
4594
            break;
4102
4595
            }
4103
4596
          }
4109
4602
          if (eptr >= md->end_subject)
4110
4603
            {
4111
4604
            SCHECK_PARTIAL();
4112
 
            MRRETURN(MATCH_NOMATCH);
 
4605
            RRETURN(MATCH_NOMATCH);
4113
4606
            }
4114
4607
          switch(*eptr++)
4115
4608
            {
4119
4612
            case 0x0c:      /* FF */
4120
4613
            case 0x0d:      /* CR */
4121
4614
            case 0x85:      /* NEL */
4122
 
            MRRETURN(MATCH_NOMATCH);
 
4615
#ifdef COMPILE_PCRE16
 
4616
            case 0x2028:    /* LINE SEPARATOR */
 
4617
            case 0x2029:    /* PARAGRAPH SEPARATOR */
 
4618
#endif
 
4619
            RRETURN(MATCH_NOMATCH);
4123
4620
            }
4124
4621
          }
4125
4622
        break;
4130
4627
          if (eptr >= md->end_subject)
4131
4628
            {
4132
4629
            SCHECK_PARTIAL();
4133
 
            MRRETURN(MATCH_NOMATCH);
 
4630
            RRETURN(MATCH_NOMATCH);
4134
4631
            }
4135
4632
          switch(*eptr++)
4136
4633
            {
4137
 
            default: MRRETURN(MATCH_NOMATCH);
 
4634
            default: RRETURN(MATCH_NOMATCH);
4138
4635
            case 0x0a:      /* LF */
4139
4636
            case 0x0b:      /* VT */
4140
4637
            case 0x0c:      /* FF */
4141
4638
            case 0x0d:      /* CR */
4142
4639
            case 0x85:      /* NEL */
 
4640
#ifdef COMPILE_PCRE16
 
4641
            case 0x2028:    /* LINE SEPARATOR */
 
4642
            case 0x2029:    /* PARAGRAPH SEPARATOR */
 
4643
#endif
4143
4644
            break;
4144
4645
            }
4145
4646
          }
4151
4652
          if (eptr >= md->end_subject)
4152
4653
            {
4153
4654
            SCHECK_PARTIAL();
4154
 
            MRRETURN(MATCH_NOMATCH);
 
4655
            RRETURN(MATCH_NOMATCH);
4155
4656
            }
4156
 
          if ((md->ctypes[*eptr++] & ctype_digit) != 0) MRRETURN(MATCH_NOMATCH);
 
4657
          if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_digit) != 0)
 
4658
            RRETURN(MATCH_NOMATCH);
 
4659
          eptr++;
4157
4660
          }
4158
4661
        break;
4159
4662
 
4163
4666
          if (eptr >= md->end_subject)
4164
4667
            {
4165
4668
            SCHECK_PARTIAL();
4166
 
            MRRETURN(MATCH_NOMATCH);
 
4669
            RRETURN(MATCH_NOMATCH);
4167
4670
            }
4168
 
          if ((md->ctypes[*eptr++] & ctype_digit) == 0) MRRETURN(MATCH_NOMATCH);
 
4671
          if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_digit) == 0)
 
4672
            RRETURN(MATCH_NOMATCH);
 
4673
          eptr++;
4169
4674
          }
4170
4675
        break;
4171
4676
 
4175
4680
          if (eptr >= md->end_subject)
4176
4681
            {
4177
4682
            SCHECK_PARTIAL();
4178
 
            MRRETURN(MATCH_NOMATCH);
 
4683
            RRETURN(MATCH_NOMATCH);
4179
4684
            }
4180
 
          if ((md->ctypes[*eptr++] & ctype_space) != 0) MRRETURN(MATCH_NOMATCH);
 
4685
          if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_space) != 0)
 
4686
            RRETURN(MATCH_NOMATCH);
 
4687
          eptr++;
4181
4688
          }
4182
4689
        break;
4183
4690
 
4187
4694
          if (eptr >= md->end_subject)
4188
4695
            {
4189
4696
            SCHECK_PARTIAL();
4190
 
            MRRETURN(MATCH_NOMATCH);
 
4697
            RRETURN(MATCH_NOMATCH);
4191
4698
            }
4192
 
          if ((md->ctypes[*eptr++] & ctype_space) == 0) MRRETURN(MATCH_NOMATCH);
 
4699
          if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_space) == 0)
 
4700
            RRETURN(MATCH_NOMATCH);
 
4701
          eptr++;
4193
4702
          }
4194
4703
        break;
4195
4704
 
4199
4708
          if (eptr >= md->end_subject)
4200
4709
            {
4201
4710
            SCHECK_PARTIAL();
4202
 
            MRRETURN(MATCH_NOMATCH);
 
4711
            RRETURN(MATCH_NOMATCH);
4203
4712
            }
4204
 
          if ((md->ctypes[*eptr++] & ctype_word) != 0)
4205
 
            MRRETURN(MATCH_NOMATCH);
 
4713
          if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_word) != 0)
 
4714
            RRETURN(MATCH_NOMATCH);
 
4715
          eptr++;
4206
4716
          }
4207
4717
        break;
4208
4718
 
4212
4722
          if (eptr >= md->end_subject)
4213
4723
            {
4214
4724
            SCHECK_PARTIAL();
4215
 
            MRRETURN(MATCH_NOMATCH);
 
4725
            RRETURN(MATCH_NOMATCH);
4216
4726
            }
4217
 
          if ((md->ctypes[*eptr++] & ctype_word) == 0)
4218
 
            MRRETURN(MATCH_NOMATCH);
 
4727
          if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_word) == 0)
 
4728
            RRETURN(MATCH_NOMATCH);
 
4729
          eptr++;
4219
4730
          }
4220
4731
        break;
4221
4732
 
4242
4753
          case PT_ANY:
4243
4754
          for (fi = min;; fi++)
4244
4755
            {
4245
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
 
4756
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM36);
4246
4757
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4247
 
            if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
4758
            if (fi >= max) RRETURN(MATCH_NOMATCH);
4248
4759
            if (eptr >= md->end_subject)
4249
4760
              {
4250
4761
              SCHECK_PARTIAL();
4251
 
              MRRETURN(MATCH_NOMATCH);
 
4762
              RRETURN(MATCH_NOMATCH);
4252
4763
              }
4253
4764
            GETCHARINCTEST(c, eptr);
4254
 
            if (prop_fail_result) MRRETURN(MATCH_NOMATCH);
 
4765
            if (prop_fail_result) RRETURN(MATCH_NOMATCH);
4255
4766
            }
4256
4767
          /* Control never gets here */
4257
4768
 
4258
4769
          case PT_LAMP:
4259
4770
          for (fi = min;; fi++)
4260
4771
            {
4261
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
 
4772
            int chartype;
 
4773
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM37);
4262
4774
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4263
 
            if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
4775
            if (fi >= max) RRETURN(MATCH_NOMATCH);
4264
4776
            if (eptr >= md->end_subject)
4265
4777
              {
4266
4778
              SCHECK_PARTIAL();
4267
 
              MRRETURN(MATCH_NOMATCH);
 
4779
              RRETURN(MATCH_NOMATCH);
4268
4780
              }
4269
4781
            GETCHARINCTEST(c, eptr);
4270
 
            prop_chartype = UCD_CHARTYPE(c);
4271
 
            if ((prop_chartype == ucp_Lu ||
4272
 
                 prop_chartype == ucp_Ll ||
4273
 
                 prop_chartype == ucp_Lt) == prop_fail_result)
4274
 
              MRRETURN(MATCH_NOMATCH);
 
4782
            chartype = UCD_CHARTYPE(c);
 
4783
            if ((chartype == ucp_Lu ||
 
4784
                 chartype == ucp_Ll ||
 
4785
                 chartype == ucp_Lt) == prop_fail_result)
 
4786
              RRETURN(MATCH_NOMATCH);
4275
4787
            }
4276
4788
          /* Control never gets here */
4277
4789
 
4278
4790
          case PT_GC:
4279
4791
          for (fi = min;; fi++)
4280
4792
            {
4281
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
 
4793
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM38);
4282
4794
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4283
 
            if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
4795
            if (fi >= max) RRETURN(MATCH_NOMATCH);
4284
4796
            if (eptr >= md->end_subject)
4285
4797
              {
4286
4798
              SCHECK_PARTIAL();
4287
 
              MRRETURN(MATCH_NOMATCH);
 
4799
              RRETURN(MATCH_NOMATCH);
4288
4800
              }
4289
4801
            GETCHARINCTEST(c, eptr);
4290
 
            prop_category = UCD_CATEGORY(c);
4291
 
            if ((prop_category == prop_value) == prop_fail_result)
4292
 
              MRRETURN(MATCH_NOMATCH);
 
4802
            if ((UCD_CATEGORY(c) == prop_value) == prop_fail_result)
 
4803
              RRETURN(MATCH_NOMATCH);
4293
4804
            }
4294
4805
          /* Control never gets here */
4295
4806
 
4296
4807
          case PT_PC:
4297
4808
          for (fi = min;; fi++)
4298
4809
            {
4299
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
 
4810
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM39);
4300
4811
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4301
 
            if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
4812
            if (fi >= max) RRETURN(MATCH_NOMATCH);
4302
4813
            if (eptr >= md->end_subject)
4303
4814
              {
4304
4815
              SCHECK_PARTIAL();
4305
 
              MRRETURN(MATCH_NOMATCH);
 
4816
              RRETURN(MATCH_NOMATCH);
4306
4817
              }
4307
4818
            GETCHARINCTEST(c, eptr);
4308
 
            prop_chartype = UCD_CHARTYPE(c);
4309
 
            if ((prop_chartype == prop_value) == prop_fail_result)
4310
 
              MRRETURN(MATCH_NOMATCH);
 
4819
            if ((UCD_CHARTYPE(c) == prop_value) == prop_fail_result)
 
4820
              RRETURN(MATCH_NOMATCH);
4311
4821
            }
4312
4822
          /* Control never gets here */
4313
4823
 
4314
4824
          case PT_SC:
4315
4825
          for (fi = min;; fi++)
4316
4826
            {
4317
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
 
4827
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM40);
4318
4828
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4319
 
            if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
4829
            if (fi >= max) RRETURN(MATCH_NOMATCH);
4320
4830
            if (eptr >= md->end_subject)
4321
4831
              {
4322
4832
              SCHECK_PARTIAL();
4323
 
              MRRETURN(MATCH_NOMATCH);
 
4833
              RRETURN(MATCH_NOMATCH);
4324
4834
              }
4325
4835
            GETCHARINCTEST(c, eptr);
4326
 
            prop_script = UCD_SCRIPT(c);
4327
 
            if ((prop_script == prop_value) == prop_fail_result)
4328
 
              MRRETURN(MATCH_NOMATCH);
 
4836
            if ((UCD_SCRIPT(c) == prop_value) == prop_fail_result)
 
4837
              RRETURN(MATCH_NOMATCH);
4329
4838
            }
4330
4839
          /* Control never gets here */
4331
4840
 
4332
4841
          case PT_ALNUM:
4333
4842
          for (fi = min;; fi++)
4334
4843
            {
4335
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM59);
 
4844
            int category;
 
4845
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM59);
4336
4846
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4337
 
            if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
4847
            if (fi >= max) RRETURN(MATCH_NOMATCH);
4338
4848
            if (eptr >= md->end_subject)
4339
4849
              {
4340
4850
              SCHECK_PARTIAL();
4341
 
              MRRETURN(MATCH_NOMATCH);
 
4851
              RRETURN(MATCH_NOMATCH);
4342
4852
              }
4343
4853
            GETCHARINCTEST(c, eptr);
4344
 
            prop_category = UCD_CATEGORY(c);
4345
 
            if ((prop_category == ucp_L || prop_category == ucp_N)
4346
 
                   == prop_fail_result)
4347
 
              MRRETURN(MATCH_NOMATCH);
 
4854
            category = UCD_CATEGORY(c);
 
4855
            if ((category == ucp_L || category == ucp_N) == prop_fail_result)
 
4856
              RRETURN(MATCH_NOMATCH);
4348
4857
            }
4349
4858
          /* Control never gets here */
4350
4859
 
4351
4860
          case PT_SPACE:    /* Perl space */
4352
4861
          for (fi = min;; fi++)
4353
4862
            {
4354
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM60);
 
4863
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM60);
4355
4864
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4356
 
            if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
4865
            if (fi >= max) RRETURN(MATCH_NOMATCH);
4357
4866
            if (eptr >= md->end_subject)
4358
4867
              {
4359
4868
              SCHECK_PARTIAL();
4360
 
              MRRETURN(MATCH_NOMATCH);
 
4869
              RRETURN(MATCH_NOMATCH);
4361
4870
              }
4362
4871
            GETCHARINCTEST(c, eptr);
4363
 
            prop_category = UCD_CATEGORY(c);
4364
 
            if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
 
4872
            if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
4365
4873
                 c == CHAR_FF || c == CHAR_CR)
4366
4874
                   == prop_fail_result)
4367
 
              MRRETURN(MATCH_NOMATCH);
 
4875
              RRETURN(MATCH_NOMATCH);
4368
4876
            }
4369
4877
          /* Control never gets here */
4370
4878
 
4371
4879
          case PT_PXSPACE:  /* POSIX space */
4372
4880
          for (fi = min;; fi++)
4373
4881
            {
4374
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM61);
 
4882
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM61);
4375
4883
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4376
 
            if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
4884
            if (fi >= max) RRETURN(MATCH_NOMATCH);
4377
4885
            if (eptr >= md->end_subject)
4378
4886
              {
4379
4887
              SCHECK_PARTIAL();
4380
 
              MRRETURN(MATCH_NOMATCH);
 
4888
              RRETURN(MATCH_NOMATCH);
4381
4889
              }
4382
4890
            GETCHARINCTEST(c, eptr);
4383
 
            prop_category = UCD_CATEGORY(c);
4384
 
            if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
 
4891
            if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
4385
4892
                 c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)
4386
4893
                   == prop_fail_result)
4387
 
              MRRETURN(MATCH_NOMATCH);
 
4894
              RRETURN(MATCH_NOMATCH);
4388
4895
            }
4389
4896
          /* Control never gets here */
4390
4897
 
4391
4898
          case PT_WORD:
4392
4899
          for (fi = min;; fi++)
4393
4900
            {
4394
 
            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM62);
 
4901
            int category;
 
4902
            RMATCH(eptr, ecode, offset_top, md, eptrb, RM62);
4395
4903
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4396
 
            if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
4904
            if (fi >= max) RRETURN(MATCH_NOMATCH);
4397
4905
            if (eptr >= md->end_subject)
4398
4906
              {
4399
4907
              SCHECK_PARTIAL();
4400
 
              MRRETURN(MATCH_NOMATCH);
 
4908
              RRETURN(MATCH_NOMATCH);
4401
4909
              }
4402
4910
            GETCHARINCTEST(c, eptr);
4403
 
            prop_category = UCD_CATEGORY(c);
4404
 
            if ((prop_category == ucp_L ||
4405
 
                 prop_category == ucp_N ||
 
4911
            category = UCD_CATEGORY(c);
 
4912
            if ((category == ucp_L ||
 
4913
                 category == ucp_N ||
4406
4914
                 c == CHAR_UNDERSCORE)
4407
4915
                   == prop_fail_result)
4408
 
              MRRETURN(MATCH_NOMATCH);
 
4916
              RRETURN(MATCH_NOMATCH);
4409
4917
            }
4410
4918
          /* Control never gets here */
4411
4919
 
4423
4931
        {
4424
4932
        for (fi = min;; fi++)
4425
4933
          {
4426
 
          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
 
4934
          RMATCH(eptr, ecode, offset_top, md, eptrb, RM41);
4427
4935
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4428
 
          if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
4936
          if (fi >= max) RRETURN(MATCH_NOMATCH);
4429
4937
          if (eptr >= md->end_subject)
4430
4938
            {
4431
4939
            SCHECK_PARTIAL();
4432
 
            MRRETURN(MATCH_NOMATCH);
 
4940
            RRETURN(MATCH_NOMATCH);
4433
4941
            }
4434
4942
          GETCHARINCTEST(c, eptr);
4435
 
          prop_category = UCD_CATEGORY(c);
4436
 
          if (prop_category == ucp_M) MRRETURN(MATCH_NOMATCH);
 
4943
          if (UCD_CATEGORY(c) == ucp_M) RRETURN(MATCH_NOMATCH);
4437
4944
          while (eptr < md->end_subject)
4438
4945
            {
4439
4946
            int len = 1;
4440
 
            if (!utf8) c = *eptr;
4441
 
              else { GETCHARLEN(c, eptr, len); }
4442
 
            prop_category = UCD_CATEGORY(c);
4443
 
            if (prop_category != ucp_M) break;
 
4947
            if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); }
 
4948
            if (UCD_CATEGORY(c) != ucp_M) break;
4444
4949
            eptr += len;
4445
4950
            }
4446
4951
          }
4447
4952
        }
4448
 
 
4449
4953
      else
4450
4954
#endif     /* SUPPORT_UCP */
4451
4955
 
4452
 
#ifdef SUPPORT_UTF8
4453
 
      /* UTF-8 mode */
4454
 
      if (utf8)
 
4956
#ifdef SUPPORT_UTF
 
4957
      if (utf)
4455
4958
        {
4456
4959
        for (fi = min;; fi++)
4457
4960
          {
4458
 
          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
 
4961
          RMATCH(eptr, ecode, offset_top, md, eptrb, RM42);
4459
4962
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4460
 
          if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
4963
          if (fi >= max) RRETURN(MATCH_NOMATCH);
4461
4964
          if (eptr >= md->end_subject)
4462
4965
            {
4463
4966
            SCHECK_PARTIAL();
4464
 
            MRRETURN(MATCH_NOMATCH);
 
4967
            RRETURN(MATCH_NOMATCH);
4465
4968
            }
4466
4969
          if (ctype == OP_ANY && IS_NEWLINE(eptr))
4467
 
            MRRETURN(MATCH_NOMATCH);
 
4970
            RRETURN(MATCH_NOMATCH);
4468
4971
          GETCHARINC(c, eptr);
4469
4972
          switch(ctype)
4470
4973
            {
4476
4979
            case OP_ANYNL:
4477
4980
            switch(c)
4478
4981
              {
4479
 
              default: MRRETURN(MATCH_NOMATCH);
 
4982
              default: RRETURN(MATCH_NOMATCH);
4480
4983
              case 0x000d:
4481
4984
              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
4482
4985
              break;
4488
4991
              case 0x0085:
4489
4992
              case 0x2028:
4490
4993
              case 0x2029:
4491
 
              if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
 
4994
              if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
4492
4995
              break;
4493
4996
              }
4494
4997
            break;
4516
5019
              case 0x202f:    /* NARROW NO-BREAK SPACE */
4517
5020
              case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
4518
5021
              case 0x3000:    /* IDEOGRAPHIC SPACE */
4519
 
              MRRETURN(MATCH_NOMATCH);
 
5022
              RRETURN(MATCH_NOMATCH);
4520
5023
              }
4521
5024
            break;
4522
5025
 
4523
5026
            case OP_HSPACE:
4524
5027
            switch(c)
4525
5028
              {
4526
 
              default: MRRETURN(MATCH_NOMATCH);
 
5029
              default: RRETURN(MATCH_NOMATCH);
4527
5030
              case 0x09:      /* HT */
4528
5031
              case 0x20:      /* SPACE */
4529
5032
              case 0xa0:      /* NBSP */
4558
5061
              case 0x85:      /* NEL */
4559
5062
              case 0x2028:    /* LINE SEPARATOR */
4560
5063
              case 0x2029:    /* PARAGRAPH SEPARATOR */
4561
 
              MRRETURN(MATCH_NOMATCH);
 
5064
              RRETURN(MATCH_NOMATCH);
4562
5065
              }
4563
5066
            break;
4564
5067
 
4565
5068
            case OP_VSPACE:
4566
5069
            switch(c)
4567
5070
              {
4568
 
              default: MRRETURN(MATCH_NOMATCH);
 
5071
              default: RRETURN(MATCH_NOMATCH);
4569
5072
              case 0x0a:      /* LF */
4570
5073
              case 0x0b:      /* VT */
4571
5074
              case 0x0c:      /* FF */
4579
5082
 
4580
5083
            case OP_NOT_DIGIT:
4581
5084
            if (c < 256 && (md->ctypes[c] & ctype_digit) != 0)
4582
 
              MRRETURN(MATCH_NOMATCH);
 
5085
              RRETURN(MATCH_NOMATCH);
4583
5086
            break;
4584
5087
 
4585
5088
            case OP_DIGIT:
4586
5089
            if (c >= 256 || (md->ctypes[c] & ctype_digit) == 0)
4587
 
              MRRETURN(MATCH_NOMATCH);
 
5090
              RRETURN(MATCH_NOMATCH);
4588
5091
            break;
4589
5092
 
4590
5093
            case OP_NOT_WHITESPACE:
4591
5094
            if (c < 256 && (md->ctypes[c] & ctype_space) != 0)
4592
 
              MRRETURN(MATCH_NOMATCH);
 
5095
              RRETURN(MATCH_NOMATCH);
4593
5096
            break;
4594
5097
 
4595
5098
            case OP_WHITESPACE:
4596
 
            if  (c >= 256 || (md->ctypes[c] & ctype_space) == 0)
4597
 
              MRRETURN(MATCH_NOMATCH);
 
5099
            if (c >= 256 || (md->ctypes[c] & ctype_space) == 0)
 
5100
              RRETURN(MATCH_NOMATCH);
4598
5101
            break;
4599
5102
 
4600
5103
            case OP_NOT_WORDCHAR:
4601
5104
            if (c < 256 && (md->ctypes[c] & ctype_word) != 0)
4602
 
              MRRETURN(MATCH_NOMATCH);
 
5105
              RRETURN(MATCH_NOMATCH);
4603
5106
            break;
4604
5107
 
4605
5108
            case OP_WORDCHAR:
4606
5109
            if (c >= 256 || (md->ctypes[c] & ctype_word) == 0)
4607
 
              MRRETURN(MATCH_NOMATCH);
 
5110
              RRETURN(MATCH_NOMATCH);
4608
5111
            break;
4609
5112
 
4610
5113
            default:
4614
5117
        }
4615
5118
      else
4616
5119
#endif
4617
 
      /* Not UTF-8 mode */
 
5120
      /* Not UTF mode */
4618
5121
        {
4619
5122
        for (fi = min;; fi++)
4620
5123
          {
4621
 
          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
 
5124
          RMATCH(eptr, ecode, offset_top, md, eptrb, RM43);
4622
5125
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4623
 
          if (fi >= max) MRRETURN(MATCH_NOMATCH);
 
5126
          if (fi >= max) RRETURN(MATCH_NOMATCH);
4624
5127
          if (eptr >= md->end_subject)
4625
5128
            {
4626
5129
            SCHECK_PARTIAL();
4627
 
            MRRETURN(MATCH_NOMATCH);
 
5130
            RRETURN(MATCH_NOMATCH);
4628
5131
            }
4629
5132
          if (ctype == OP_ANY && IS_NEWLINE(eptr))
4630
 
            MRRETURN(MATCH_NOMATCH);
 
5133
            RRETURN(MATCH_NOMATCH);
4631
5134
          c = *eptr++;
4632
5135
          switch(ctype)
4633
5136
            {
4639
5142
            case OP_ANYNL:
4640
5143
            switch(c)
4641
5144
              {
4642
 
              default: MRRETURN(MATCH_NOMATCH);
 
5145
              default: RRETURN(MATCH_NOMATCH);
4643
5146
              case 0x000d:
4644
5147
              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
4645
5148
              break;
4650
5153
              case 0x000b:
4651
5154
              case 0x000c:
4652
5155
              case 0x0085:
4653
 
              if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
 
5156
#ifdef COMPILE_PCRE16
 
5157
              case 0x2028:
 
5158
              case 0x2029:
 
5159
#endif
 
5160
              if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
4654
5161
              break;
4655
5162
              }
4656
5163
            break;
4662
5169
              case 0x09:      /* HT */
4663
5170
              case 0x20:      /* SPACE */
4664
5171
              case 0xa0:      /* NBSP */
4665
 
              MRRETURN(MATCH_NOMATCH);
 
5172
#ifdef COMPILE_PCRE16
 
5173
              case 0x1680:    /* OGHAM SPACE MARK */
 
5174
              case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
 
5175
              case 0x2000:    /* EN QUAD */
 
5176
              case 0x2001:    /* EM QUAD */
 
5177
              case 0x2002:    /* EN SPACE */
 
5178
              case 0x2003:    /* EM SPACE */
 
5179
              case 0x2004:    /* THREE-PER-EM SPACE */
 
5180
              case 0x2005:    /* FOUR-PER-EM SPACE */
 
5181
              case 0x2006:    /* SIX-PER-EM SPACE */
 
5182
              case 0x2007:    /* FIGURE SPACE */
 
5183
              case 0x2008:    /* PUNCTUATION SPACE */
 
5184
              case 0x2009:    /* THIN SPACE */
 
5185
              case 0x200A:    /* HAIR SPACE */
 
5186
              case 0x202f:    /* NARROW NO-BREAK SPACE */
 
5187
              case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
 
5188
              case 0x3000:    /* IDEOGRAPHIC SPACE */
 
5189
#endif
 
5190
              RRETURN(MATCH_NOMATCH);
4666
5191
              }
4667
5192
            break;
4668
5193
 
4669
5194
            case OP_HSPACE:
4670
5195
            switch(c)
4671
5196
              {
4672
 
              default: MRRETURN(MATCH_NOMATCH);
 
5197
              default: RRETURN(MATCH_NOMATCH);
4673
5198
              case 0x09:      /* HT */
4674
5199
              case 0x20:      /* SPACE */
4675
5200
              case 0xa0:      /* NBSP */
 
5201
#ifdef COMPILE_PCRE16
 
5202
              case 0x1680:    /* OGHAM SPACE MARK */
 
5203
              case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
 
5204
              case 0x2000:    /* EN QUAD */
 
5205
              case 0x2001:    /* EM QUAD */
 
5206
              case 0x2002:    /* EN SPACE */
 
5207
              case 0x2003:    /* EM SPACE */
 
5208
              case 0x2004:    /* THREE-PER-EM SPACE */
 
5209
              case 0x2005:    /* FOUR-PER-EM SPACE */
 
5210
              case 0x2006:    /* SIX-PER-EM SPACE */
 
5211
              case 0x2007:    /* FIGURE SPACE */
 
5212
              case 0x2008:    /* PUNCTUATION SPACE */
 
5213
              case 0x2009:    /* THIN SPACE */
 
5214
              case 0x200A:    /* HAIR SPACE */
 
5215
              case 0x202f:    /* NARROW NO-BREAK SPACE */
 
5216
              case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
 
5217
              case 0x3000:    /* IDEOGRAPHIC SPACE */
 
5218
#endif
4676
5219
              break;
4677
5220
              }
4678
5221
            break;
4686
5229
              case 0x0c:      /* FF */
4687
5230
              case 0x0d:      /* CR */
4688
5231
              case 0x85:      /* NEL */
4689
 
              MRRETURN(MATCH_NOMATCH);
 
5232
#ifdef COMPILE_PCRE16
 
5233
              case 0x2028:    /* LINE SEPARATOR */
 
5234
              case 0x2029:    /* PARAGRAPH SEPARATOR */
 
5235
#endif
 
5236
              RRETURN(MATCH_NOMATCH);
4690
5237
              }
4691
5238
            break;
4692
5239
 
4693
5240
            case OP_VSPACE:
4694
5241
            switch(c)
4695
5242
              {
4696
 
              default: MRRETURN(MATCH_NOMATCH);
 
5243
              default: RRETURN(MATCH_NOMATCH);
4697
5244
              case 0x0a:      /* LF */
4698
5245
              case 0x0b:      /* VT */
4699
5246
              case 0x0c:      /* FF */
4700
5247
              case 0x0d:      /* CR */
4701
5248
              case 0x85:      /* NEL */
 
5249
#ifdef COMPILE_PCRE16
 
5250
              case 0x2028:    /* LINE SEPARATOR */
 
5251
              case 0x2029:    /* PARAGRAPH SEPARATOR */
 
5252
#endif
4702
5253
              break;
4703
5254
              }
4704
5255
            break;
4705
5256
 
4706
5257
            case OP_NOT_DIGIT:
4707
 
            if ((md->ctypes[c] & ctype_digit) != 0) MRRETURN(MATCH_NOMATCH);
 
5258
            if (MAX_255(c) && (md->ctypes[c] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
4708
5259
            break;
4709
5260
 
4710
5261
            case OP_DIGIT:
4711
 
            if ((md->ctypes[c] & ctype_digit) == 0) MRRETURN(MATCH_NOMATCH);
 
5262
            if (!MAX_255(c) || (md->ctypes[c] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
4712
5263
            break;
4713
5264
 
4714
5265
            case OP_NOT_WHITESPACE:
4715
 
            if ((md->ctypes[c] & ctype_space) != 0) MRRETURN(MATCH_NOMATCH);
 
5266
            if (MAX_255(c) && (md->ctypes[c] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
4716
5267
            break;
4717
5268
 
4718
5269
            case OP_WHITESPACE:
4719
 
            if  ((md->ctypes[c] & ctype_space) == 0) MRRETURN(MATCH_NOMATCH);
 
5270
            if (!MAX_255(c) || (md->ctypes[c] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
4720
5271
            break;
4721
5272
 
4722
5273
            case OP_NOT_WORDCHAR:
4723
 
            if ((md->ctypes[c] & ctype_word) != 0) MRRETURN(MATCH_NOMATCH);
 
5274
            if (MAX_255(c) && (md->ctypes[c] & ctype_word) != 0) RRETURN(MATCH_NOMATCH);
4724
5275
            break;
4725
5276
 
4726
5277
            case OP_WORDCHAR:
4727
 
            if ((md->ctypes[c] & ctype_word) == 0) MRRETURN(MATCH_NOMATCH);
 
5278
            if (!MAX_255(c) || (md->ctypes[c] & ctype_word) == 0) RRETURN(MATCH_NOMATCH);
4728
5279
            break;
4729
5280
 
4730
5281
            default:
4766
5317
          case PT_LAMP:
4767
5318
          for (i = min; i < max; i++)
4768
5319
            {
 
5320
            int chartype;
4769
5321
            int len = 1;
4770
5322
            if (eptr >= md->end_subject)
4771
5323
              {
4773
5325
              break;
4774
5326
              }
4775
5327
            GETCHARLENTEST(c, eptr, len);
4776
 
            prop_chartype = UCD_CHARTYPE(c);
4777
 
            if ((prop_chartype == ucp_Lu ||
4778
 
                 prop_chartype == ucp_Ll ||
4779
 
                 prop_chartype == ucp_Lt) == prop_fail_result)
 
5328
            chartype = UCD_CHARTYPE(c);
 
5329
            if ((chartype == ucp_Lu ||
 
5330
                 chartype == ucp_Ll ||
 
5331
                 chartype == ucp_Lt) == prop_fail_result)
4780
5332
              break;
4781
5333
            eptr+= len;
4782
5334
            }
4792
5344
              break;
4793
5345
              }
4794
5346
            GETCHARLENTEST(c, eptr, len);
4795
 
            prop_category = UCD_CATEGORY(c);
4796
 
            if ((prop_category == prop_value) == prop_fail_result)
4797
 
              break;
 
5347
            if ((UCD_CATEGORY(c) == prop_value) == prop_fail_result) break;
4798
5348
            eptr+= len;
4799
5349
            }
4800
5350
          break;
4809
5359
              break;
4810
5360
              }
4811
5361
            GETCHARLENTEST(c, eptr, len);
4812
 
            prop_chartype = UCD_CHARTYPE(c);
4813
 
            if ((prop_chartype == prop_value) == prop_fail_result)
4814
 
              break;
 
5362
            if ((UCD_CHARTYPE(c) == prop_value) == prop_fail_result) break;
4815
5363
            eptr+= len;
4816
5364
            }
4817
5365
          break;
4826
5374
              break;
4827
5375
              }
4828
5376
            GETCHARLENTEST(c, eptr, len);
4829
 
            prop_script = UCD_SCRIPT(c);
4830
 
            if ((prop_script == prop_value) == prop_fail_result)
4831
 
              break;
 
5377
            if ((UCD_SCRIPT(c) == prop_value) == prop_fail_result) break;
4832
5378
            eptr+= len;
4833
5379
            }
4834
5380
          break;
4836
5382
          case PT_ALNUM:
4837
5383
          for (i = min; i < max; i++)
4838
5384
            {
 
5385
            int category;
4839
5386
            int len = 1;
4840
5387
            if (eptr >= md->end_subject)
4841
5388
              {
4843
5390
              break;
4844
5391
              }
4845
5392
            GETCHARLENTEST(c, eptr, len);
4846
 
            prop_category = UCD_CATEGORY(c);
4847
 
            if ((prop_category == ucp_L || prop_category == ucp_N)
4848
 
                 == prop_fail_result)
 
5393
            category = UCD_CATEGORY(c);
 
5394
            if ((category == ucp_L || category == ucp_N) == prop_fail_result)
4849
5395
              break;
4850
5396
            eptr+= len;
4851
5397
            }
4861
5407
              break;
4862
5408
              }
4863
5409
            GETCHARLENTEST(c, eptr, len);
4864
 
            prop_category = UCD_CATEGORY(c);
4865
 
            if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
 
5410
            if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
4866
5411
                 c == CHAR_FF || c == CHAR_CR)
4867
5412
                 == prop_fail_result)
4868
5413
              break;
4880
5425
              break;
4881
5426
              }
4882
5427
            GETCHARLENTEST(c, eptr, len);
4883
 
            prop_category = UCD_CATEGORY(c);
4884
 
            if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
 
5428
            if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
4885
5429
                 c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)
4886
5430
                 == prop_fail_result)
4887
5431
              break;
4892
5436
          case PT_WORD:
4893
5437
          for (i = min; i < max; i++)
4894
5438
            {
 
5439
            int category;
4895
5440
            int len = 1;
4896
5441
            if (eptr >= md->end_subject)
4897
5442
              {
4899
5444
              break;
4900
5445
              }
4901
5446
            GETCHARLENTEST(c, eptr, len);
4902
 
            prop_category = UCD_CATEGORY(c);
4903
 
            if ((prop_category == ucp_L || prop_category == ucp_N ||
 
5447
            category = UCD_CATEGORY(c);
 
5448
            if ((category == ucp_L || category == ucp_N ||
4904
5449
                 c == CHAR_UNDERSCORE) == prop_fail_result)
4905
5450
              break;
4906
5451
            eptr+= len;
4916
5461
        if (possessive) continue;
4917
5462
        for(;;)
4918
5463
          {
4919
 
          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);
 
5464
          RMATCH(eptr, ecode, offset_top, md, eptrb, RM44);
4920
5465
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4921
5466
          if (eptr-- == pp) break;        /* Stop if tried at original pos */
4922
 
          if (utf8) BACKCHAR(eptr);
 
5467
          if (utf) BACKCHAR(eptr);
4923
5468
          }
4924
5469
        }
4925
5470
 
4930
5475
        {
4931
5476
        for (i = min; i < max; i++)
4932
5477
          {
 
5478
          int len = 1;
4933
5479
          if (eptr >= md->end_subject)
4934
5480
            {
4935
5481
            SCHECK_PARTIAL();
4936
5482
            break;
4937
5483
            }
4938
 
          GETCHARINCTEST(c, eptr);
4939
 
          prop_category = UCD_CATEGORY(c);
4940
 
          if (prop_category == ucp_M) break;
 
5484
          if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); }
 
5485
          if (UCD_CATEGORY(c) == ucp_M) break;
 
5486
          eptr += len;
4941
5487
          while (eptr < md->end_subject)
4942
5488
            {
4943
 
            int len = 1;
4944
 
            if (!utf8) c = *eptr; else
4945
 
              {
4946
 
              GETCHARLEN(c, eptr, len);
4947
 
              }
4948
 
            prop_category = UCD_CATEGORY(c);
4949
 
            if (prop_category != ucp_M) break;
 
5489
            len = 1;
 
5490
            if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); }
 
5491
            if (UCD_CATEGORY(c) != ucp_M) break;
4950
5492
            eptr += len;
4951
5493
            }
4952
5494
          }
4957
5499
 
4958
5500
        for(;;)
4959
5501
          {
4960
 
          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);
 
5502
          RMATCH(eptr, ecode, offset_top, md, eptrb, RM45);
4961
5503
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4962
5504
          if (eptr-- == pp) break;        /* Stop if tried at original pos */
4963
5505
          for (;;)                        /* Move back over one extended */
4964
5506
            {
4965
 
            int len = 1;
4966
 
            if (!utf8) c = *eptr; else
 
5507
            if (!utf) c = *eptr; else
4967
5508
              {
4968
5509
              BACKCHAR(eptr);
4969
 
              GETCHARLEN(c, eptr, len);
 
5510
              GETCHAR(c, eptr);
4970
5511
              }
4971
 
            prop_category = UCD_CATEGORY(c);
4972
 
            if (prop_category != ucp_M) break;
 
5512
            if (UCD_CATEGORY(c) != ucp_M) break;
4973
5513
            eptr--;
4974
5514
            }
4975
5515
          }
4978
5518
      else
4979
5519
#endif   /* SUPPORT_UCP */
4980
5520
 
4981
 
#ifdef SUPPORT_UTF8
4982
 
      /* UTF-8 mode */
4983
 
 
4984
 
      if (utf8)
 
5521
#ifdef SUPPORT_UTF
 
5522
      if (utf)
4985
5523
        {
4986
5524
        switch(ctype)
4987
5525
          {
4997
5535
                }
4998
5536
              if (IS_NEWLINE(eptr)) break;
4999
5537
              eptr++;
5000
 
              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
 
5538
              ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
5001
5539
              }
5002
5540
            }
5003
5541
 
5014
5552
                }
5015
5553
              if (IS_NEWLINE(eptr)) break;
5016
5554
              eptr++;
5017
 
              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
 
5555
              ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
5018
5556
              }
5019
5557
            }
5020
5558
          break;
5030
5568
                break;
5031
5569
                }
5032
5570
              eptr++;
5033
 
              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
 
5571
              ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
5034
5572
              }
5035
5573
            }
5036
 
          else eptr = md->end_subject;   /* Unlimited UTF-8 repeat */
 
5574
          else
 
5575
            {
 
5576
            eptr = md->end_subject;   /* Unlimited UTF-8 repeat */
 
5577
            SCHECK_PARTIAL();
 
5578
            }
5037
5579
          break;
5038
5580
 
5039
5581
          /* The byte case is the same as non-UTF8 */
5241
5783
          RRETURN(PCRE_ERROR_INTERNAL);
5242
5784
          }
5243
5785
 
5244
 
        /* eptr is now past the end of the maximum run */
 
5786
        /* eptr is now past the end of the maximum run. If possessive, we are
 
5787
        done (no backing up). Otherwise, match at this position; anything other
 
5788
        than no match is immediately returned. For nomatch, back up one
 
5789
        character, unless we are matching \R and the last thing matched was
 
5790
        \r\n, in which case, back up two bytes. */
5245
5791
 
5246
5792
        if (possessive) continue;
5247
5793
        for(;;)
5248
5794
          {
5249
 
          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46);
 
5795
          RMATCH(eptr, ecode, offset_top, md, eptrb, RM46);
5250
5796
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5251
5797
          if (eptr-- == pp) break;        /* Stop if tried at original pos */
5252
5798
          BACKCHAR(eptr);
 
5799
          if (ctype == OP_ANYNL && eptr > pp  && *eptr == '\n' &&
 
5800
              eptr[-1] == '\r') eptr--;
5253
5801
          }
5254
5802
        }
5255
5803
      else
5256
 
#endif  /* SUPPORT_UTF8 */
5257
 
 
5258
 
      /* Not UTF-8 mode */
 
5804
#endif  /* SUPPORT_UTF */
 
5805
      /* Not UTF mode */
5259
5806
        {
5260
5807
        switch(ctype)
5261
5808
          {
5299
5846
              }
5300
5847
            else
5301
5848
              {
5302
 
              if (c != 0x000a &&
5303
 
                  (md->bsr_anycrlf ||
5304
 
                    (c != 0x000b && c != 0x000c && c != 0x0085)))
5305
 
                break;
 
5849
              if (c != 0x000a && (md->bsr_anycrlf ||
 
5850
                (c != 0x000b && c != 0x000c && c != 0x0085
 
5851
#ifdef COMPILE_PCRE16
 
5852
                && c != 0x2028 && c != 0x2029
 
5853
#endif
 
5854
                ))) break;
5306
5855
              eptr++;
5307
5856
              }
5308
5857
            }
5317
5866
              break;
5318
5867
              }
5319
5868
            c = *eptr;
5320
 
            if (c == 0x09 || c == 0x20 || c == 0xa0) break;
 
5869
            if (c == 0x09 || c == 0x20 || c == 0xa0
 
5870
#ifdef COMPILE_PCRE16
 
5871
              || c == 0x1680 || c == 0x180e || (c >= 0x2000 && c <= 0x200A)
 
5872
              || c == 0x202f || c == 0x205f || c == 0x3000
 
5873
#endif
 
5874
              ) break;
5321
5875
            eptr++;
5322
5876
            }
5323
5877
          break;
5331
5885
              break;
5332
5886
              }
5333
5887
            c = *eptr;
5334
 
            if (c != 0x09 && c != 0x20 && c != 0xa0) break;
 
5888
            if (c != 0x09 && c != 0x20 && c != 0xa0
 
5889
#ifdef COMPILE_PCRE16
 
5890
              && c != 0x1680 && c != 0x180e && (c < 0x2000 || c > 0x200A)
 
5891
              && c != 0x202f && c != 0x205f && c != 0x3000
 
5892
#endif
 
5893
              ) break;
5335
5894
            eptr++;
5336
5895
            }
5337
5896
          break;
5345
5904
              break;
5346
5905
              }
5347
5906
            c = *eptr;
5348
 
            if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)
5349
 
              break;
 
5907
            if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85
 
5908
#ifdef COMPILE_PCRE16
 
5909
              || c == 0x2028 || c == 0x2029
 
5910
#endif
 
5911
              ) break;
5350
5912
            eptr++;
5351
5913
            }
5352
5914
          break;
5360
5922
              break;
5361
5923
              }
5362
5924
            c = *eptr;
5363
 
            if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)
5364
 
              break;
 
5925
            if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85
 
5926
#ifdef COMPILE_PCRE16
 
5927
              && c != 0x2028 && c != 0x2029
 
5928
#endif
 
5929
              ) break;
5365
5930
            eptr++;
5366
5931
            }
5367
5932
          break;
5374
5939
              SCHECK_PARTIAL();
5375
5940
              break;
5376
5941
              }
5377
 
            if ((md->ctypes[*eptr] & ctype_digit) != 0) break;
 
5942
            if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_digit) != 0) break;
5378
5943
            eptr++;
5379
5944
            }
5380
5945
          break;
5387
5952
              SCHECK_PARTIAL();
5388
5953
              break;
5389
5954
              }
5390
 
            if ((md->ctypes[*eptr] & ctype_digit) == 0) break;
 
5955
            if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_digit) == 0) break;
5391
5956
            eptr++;
5392
5957
            }
5393
5958
          break;
5400
5965
              SCHECK_PARTIAL();
5401
5966
              break;
5402
5967
              }
5403
 
            if ((md->ctypes[*eptr] & ctype_space) != 0) break;
 
5968
            if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_space) != 0) break;
5404
5969
            eptr++;
5405
5970
            }
5406
5971
          break;
5413
5978
              SCHECK_PARTIAL();
5414
5979
              break;
5415
5980
              }
5416
 
            if ((md->ctypes[*eptr] & ctype_space) == 0) break;
 
5981
            if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_space) == 0) break;
5417
5982
            eptr++;
5418
5983
            }
5419
5984
          break;
5426
5991
              SCHECK_PARTIAL();
5427
5992
              break;
5428
5993
              }
5429
 
            if ((md->ctypes[*eptr] & ctype_word) != 0) break;
 
5994
            if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_word) != 0) break;
5430
5995
            eptr++;
5431
5996
            }
5432
5997
          break;
5439
6004
              SCHECK_PARTIAL();
5440
6005
              break;
5441
6006
              }
5442
 
            if ((md->ctypes[*eptr] & ctype_word) == 0) break;
 
6007
            if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_word) == 0) break;
5443
6008
            eptr++;
5444
6009
            }
5445
6010
          break;
5448
6013
          RRETURN(PCRE_ERROR_INTERNAL);
5449
6014
          }
5450
6015
 
5451
 
        /* eptr is now past the end of the maximum run */
 
6016
        /* eptr is now past the end of the maximum run. If possessive, we are
 
6017
        done (no backing up). Otherwise, match at this position; anything other
 
6018
        than no match is immediately returned. For nomatch, back up one
 
6019
        character (byte), unless we are matching \R and the last thing matched
 
6020
        was \r\n, in which case, back up two bytes. */
5452
6021
 
5453
6022
        if (possessive) continue;
5454
6023
        while (eptr >= pp)
5455
6024
          {
5456
 
          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47);
 
6025
          RMATCH(eptr, ecode, offset_top, md, eptrb, RM47);
 
6026
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5457
6027
          eptr--;
5458
 
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
 
6028
          if (ctype == OP_ANYNL && eptr > pp  && *eptr == '\n' &&
 
6029
              eptr[-1] == '\r') eptr--;
5459
6030
          }
5460
6031
        }
5461
6032
 
5462
6033
      /* Get here if we can't make it match with any permitted repetitions */
5463
6034
 
5464
 
      MRRETURN(MATCH_NOMATCH);
 
6035
      RRETURN(MATCH_NOMATCH);
5465
6036
      }
5466
6037
    /* Control never gets here */
5467
6038
 
5494
6065
  LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
5495
6066
  LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
5496
6067
  LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
5497
 
  LBL(53) LBL(54) LBL(55) LBL(56) LBL(57) LBL(58)
5498
 
#ifdef SUPPORT_UTF8
5499
 
  LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
 
6068
  LBL(53) LBL(54) LBL(55) LBL(56) LBL(57) LBL(58) LBL(63) LBL(64)
 
6069
  LBL(65) LBL(66)
 
6070
#if defined SUPPORT_UTF || !defined COMPILE_PCRE8
 
6071
  LBL(21)
 
6072
#endif
 
6073
#ifdef SUPPORT_UTF
 
6074
  LBL(16) LBL(18) LBL(20)
 
6075
  LBL(22) LBL(23) LBL(28) LBL(30)
5500
6076
  LBL(32) LBL(34) LBL(42) LBL(46)
5501
6077
#ifdef SUPPORT_UCP
5502
6078
  LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
5503
6079
  LBL(59) LBL(60) LBL(61) LBL(62)
5504
6080
#endif  /* SUPPORT_UCP */
5505
 
#endif  /* SUPPORT_UTF8 */
 
6081
#endif  /* SUPPORT_UTF */
5506
6082
  default:
5507
6083
  DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));
 
6084
 
 
6085
printf("+++jump error in pcre match: label %d non-existent\n", frame->Xwhere);
 
6086
 
5508
6087
  return PCRE_ERROR_INTERNAL;
5509
6088
  }
5510
6089
#undef LBL
5523
6102
#undef ecode
5524
6103
#undef mstart
5525
6104
#undef offset_top
5526
 
#undef ims
5527
6105
#undef eptrb
5528
6106
#undef flags
5529
6107
 
5541
6119
#undef condition
5542
6120
#undef prev_is_word
5543
6121
 
5544
 
#undef original_ims
5545
 
 
5546
6122
#undef ctype
5547
6123
#undef length
5548
6124
#undef max
5594
6170
                 < -1 => some kind of unexpected problem
5595
6171
*/
5596
6172
 
 
6173
#ifdef COMPILE_PCRE8
5597
6174
PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
5598
6175
pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
5599
6176
  PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
5600
6177
  int offsetcount)
 
6178
#else
 
6179
PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
 
6180
pcre16_exec(const pcre16 *argument_re, const pcre16_extra *extra_data,
 
6181
  PCRE_SPTR16 subject, int length, int start_offset, int options, int *offsets,
 
6182
  int offsetcount)
 
6183
#endif
5601
6184
{
5602
 
int rc, resetcount, ocount;
5603
 
int first_byte = -1;
5604
 
int req_byte = -1;
5605
 
int req_byte2 = -1;
 
6185
int rc, ocount, arg_offset_max;
5606
6186
int newline;
5607
 
unsigned long int ims;
5608
6187
BOOL using_temporary_offsets = FALSE;
5609
6188
BOOL anchored;
5610
6189
BOOL startline;
5611
6190
BOOL firstline;
5612
 
BOOL first_byte_caseless = FALSE;
5613
 
BOOL req_byte_caseless = FALSE;
5614
 
BOOL utf8;
 
6191
BOOL utf;
 
6192
BOOL has_first_char = FALSE;
 
6193
BOOL has_req_char = FALSE;
 
6194
pcre_uchar first_char = 0;
 
6195
pcre_uchar first_char2 = 0;
 
6196
pcre_uchar req_char = 0;
 
6197
pcre_uchar req_char2 = 0;
5615
6198
match_data match_block;
5616
6199
match_data *md = &match_block;
5617
 
const uschar *tables;
5618
 
const uschar *start_bits = NULL;
5619
 
USPTR start_match = (USPTR)subject + start_offset;
5620
 
USPTR end_subject;
5621
 
USPTR start_partial = NULL;
5622
 
USPTR req_byte_ptr = start_match - 1;
 
6200
const pcre_uint8 *tables;
 
6201
const pcre_uint8 *start_bits = NULL;
 
6202
PCRE_PUCHAR start_match = (PCRE_PUCHAR)subject + start_offset;
 
6203
PCRE_PUCHAR end_subject;
 
6204
PCRE_PUCHAR start_partial = NULL;
 
6205
PCRE_PUCHAR req_char_ptr = start_match - 1;
5623
6206
 
5624
 
pcre_study_data internal_study;
5625
6207
const pcre_study_data *study;
5626
 
 
5627
 
real_pcre internal_re;
5628
 
const real_pcre *external_re = (const real_pcre *)argument_re;
5629
 
const real_pcre *re = external_re;
 
6208
const REAL_PCRE *re = (const REAL_PCRE *)argument_re;
 
6209
 
 
6210
/* Check for the special magic call that measures the size of the stack used
 
6211
per recursive call of match(). */
 
6212
 
 
6213
if (re == NULL && extra_data == NULL && subject == NULL && length == -999 &&
 
6214
    start_offset == -999)
 
6215
#ifdef NO_RECURSE
 
6216
  return -sizeof(heapframe);
 
6217
#else
 
6218
  return match(NULL, NULL, NULL, 0, NULL, NULL, 0);
 
6219
#endif
5630
6220
 
5631
6221
/* Plausibility checks */
5632
6222
 
5633
6223
if ((options & ~PUBLIC_EXEC_OPTIONS) != 0) return PCRE_ERROR_BADOPTION;
5634
 
if (re == NULL || subject == NULL ||
5635
 
   (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;
 
6224
if (re == NULL || subject == NULL || (offsets == NULL && offsetcount > 0))
 
6225
  return PCRE_ERROR_NULL;
5636
6226
if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
5637
6227
if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET;
5638
6228
 
5639
 
/* This information is for finding all the numbers associated with a given
5640
 
name, for condition testing. */
5641
 
 
5642
 
md->name_table = (uschar *)re + re->name_table_offset;
 
6229
/* Check that the first field in the block is the magic number. If it is not,
 
6230
return with PCRE_ERROR_BADMAGIC. However, if the magic number is equal to
 
6231
REVERSED_MAGIC_NUMBER we return with PCRE_ERROR_BADENDIANNESS, which
 
6232
means that the pattern is likely compiled with different endianness. */
 
6233
 
 
6234
if (re->magic_number != MAGIC_NUMBER)
 
6235
  return re->magic_number == REVERSED_MAGIC_NUMBER?
 
6236
    PCRE_ERROR_BADENDIANNESS:PCRE_ERROR_BADMAGIC;
 
6237
if ((re->flags & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE;
 
6238
 
 
6239
/* These two settings are used in the code for checking a UTF-8 string that
 
6240
follows immediately afterwards. Other values in the md block are used only
 
6241
during "normal" pcre_exec() processing, not when the JIT support is in use,
 
6242
so they are set up later. */
 
6243
 
 
6244
/* PCRE_UTF16 has the same value as PCRE_UTF8. */
 
6245
utf = md->utf = (re->options & PCRE_UTF8) != 0;
 
6246
md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 :
 
6247
              ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0;
 
6248
 
 
6249
/* Check a UTF-8 string if required. Pass back the character offset and error
 
6250
code for an invalid string if a results vector is available. */
 
6251
 
 
6252
#ifdef SUPPORT_UTF
 
6253
if (utf && (options & PCRE_NO_UTF8_CHECK) == 0)
 
6254
  {
 
6255
  int erroroffset;
 
6256
  int errorcode = PRIV(valid_utf)((PCRE_PUCHAR)subject, length, &erroroffset);
 
6257
  if (errorcode != 0)
 
6258
    {
 
6259
    if (offsetcount >= 2)
 
6260
      {
 
6261
      offsets[0] = erroroffset;
 
6262
      offsets[1] = errorcode;
 
6263
      }
 
6264
#ifdef COMPILE_PCRE16
 
6265
    return (errorcode <= PCRE_UTF16_ERR1 && md->partial > 1)?
 
6266
      PCRE_ERROR_SHORTUTF16 : PCRE_ERROR_BADUTF16;
 
6267
#else
 
6268
    return (errorcode <= PCRE_UTF8_ERR5 && md->partial > 1)?
 
6269
      PCRE_ERROR_SHORTUTF8 : PCRE_ERROR_BADUTF8;
 
6270
#endif
 
6271
    }
 
6272
 
 
6273
  /* Check that a start_offset points to the start of a UTF character. */
 
6274
  if (start_offset > 0 && start_offset < length &&
 
6275
      NOT_FIRSTCHAR(((PCRE_PUCHAR)subject)[start_offset]))
 
6276
    return PCRE_ERROR_BADUTF8_OFFSET;
 
6277
  }
 
6278
#endif
 
6279
 
 
6280
/* If the pattern was successfully studied with JIT support, run the JIT
 
6281
executable instead of the rest of this function. Most options must be set at
 
6282
compile time for the JIT code to be usable. Fallback to the normal code path if
 
6283
an unsupported flag is set. In particular, JIT does not support partial
 
6284
matching. */
 
6285
 
 
6286
#ifdef SUPPORT_JIT
 
6287
if (extra_data != NULL
 
6288
    && (extra_data->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0
 
6289
    && extra_data->executable_jit != NULL
 
6290
    && (extra_data->flags & PCRE_EXTRA_TABLES) == 0
 
6291
    && (options & ~(PCRE_NO_UTF8_CHECK | PCRE_NOTBOL | PCRE_NOTEOL |
 
6292
                    PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART)) == 0)
 
6293
  return PRIV(jit_exec)(re, extra_data->executable_jit,
 
6294
    (const pcre_uchar *)subject, length, start_offset, options,
 
6295
    ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0)
 
6296
    ? MATCH_LIMIT : extra_data->match_limit, offsets, offsetcount);
 
6297
#endif
 
6298
 
 
6299
/* Carry on with non-JIT matching. This information is for finding all the
 
6300
numbers associated with a given name, for condition testing. */
 
6301
 
 
6302
md->name_table = (pcre_uchar *)re + re->name_table_offset;
5643
6303
md->name_count = re->name_count;
5644
6304
md->name_entry_size = re->name_entry_size;
5645
6305
 
5653
6313
 
5654
6314
/* The table pointer is always in native byte order. */
5655
6315
 
5656
 
tables = external_re->tables;
 
6316
tables = re->tables;
5657
6317
 
5658
6318
if (extra_data != NULL)
5659
6319
  {
5673
6333
is a feature that makes it possible to save compiled regex and re-use them
5674
6334
in other programs later. */
5675
6335
 
5676
 
if (tables == NULL) tables = _pcre_default_tables;
5677
 
 
5678
 
/* Check that the first field in the block is the magic number. If it is not,
5679
 
test for a regex that was compiled on a host of opposite endianness. If this is
5680
 
the case, flipped values are put in internal_re and internal_study if there was
5681
 
study data too. */
5682
 
 
5683
 
if (re->magic_number != MAGIC_NUMBER)
5684
 
  {
5685
 
  re = _pcre_try_flipped(re, &internal_re, study, &internal_study);
5686
 
  if (re == NULL) return PCRE_ERROR_BADMAGIC;
5687
 
  if (study != NULL) study = &internal_study;
5688
 
  }
 
6336
if (tables == NULL) tables = PRIV(default_tables);
5689
6337
 
5690
6338
/* Set up other data */
5691
6339
 
5695
6343
 
5696
6344
/* The code starts after the real_pcre block and the capture name table. */
5697
6345
 
5698
 
md->start_code = (const uschar *)external_re + re->name_table_offset +
 
6346
md->start_code = (const pcre_uchar *)re + re->name_table_offset +
5699
6347
  re->name_count * re->name_entry_size;
5700
6348
 
5701
 
md->start_subject = (USPTR)subject;
 
6349
md->start_subject = (PCRE_PUCHAR)subject;
5702
6350
md->start_offset = start_offset;
5703
6351
md->end_subject = md->start_subject + length;
5704
6352
end_subject = md->end_subject;
5705
6353
 
5706
6354
md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
5707
 
utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
5708
6355
md->use_ucp = (re->options & PCRE_UCP) != 0;
5709
6356
md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
 
6357
md->ignore_skip_arg = FALSE;
 
6358
 
 
6359
/* Some options are unpacked into BOOL variables in the hope that testing
 
6360
them will be faster than individual option bits. */
5710
6361
 
5711
6362
md->notbol = (options & PCRE_NOTBOL) != 0;
5712
6363
md->noteol = (options & PCRE_NOTEOL) != 0;
5713
6364
md->notempty = (options & PCRE_NOTEMPTY) != 0;
5714
6365
md->notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;
5715
 
md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 :
5716
 
              ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0;
 
6366
 
5717
6367
md->hitend = FALSE;
5718
 
md->mark = NULL;                        /* In case never set */
 
6368
md->mark = md->nomatch_mark = NULL;     /* In case never set */
5719
6369
 
5720
6370
md->recursive = NULL;                   /* No recursion at top level */
 
6371
md->hasthen = (re->flags & PCRE_HASTHEN) != 0;
5721
6372
 
5722
6373
md->lcc = tables + lcc_offset;
 
6374
md->fcc = tables + fcc_offset;
5723
6375
md->ctypes = tables + ctypes_offset;
5724
6376
 
5725
6377
/* Handle different \R options. */
5795
6447
if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
5796
6448
  return PCRE_ERROR_BADPARTIAL;
5797
6449
 
5798
 
/* Check a UTF-8 string if required. Unfortunately there's no way of passing
5799
 
back the character offset. */
5800
 
 
5801
 
#ifdef SUPPORT_UTF8
5802
 
if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
5803
 
  {
5804
 
  int tb;
5805
 
  if ((tb = _pcre_valid_utf8((USPTR)subject, length)) >= 0)
5806
 
    return (tb == length && md->partial > 1)?
5807
 
      PCRE_ERROR_SHORTUTF8 : PCRE_ERROR_BADUTF8;
5808
 
  if (start_offset > 0 && start_offset < length)
5809
 
    {
5810
 
    tb = ((USPTR)subject)[start_offset] & 0xc0;
5811
 
    if (tb == 0x80) return PCRE_ERROR_BADUTF8_OFFSET;
5812
 
    }
5813
 
  }
5814
 
#endif
5815
 
 
5816
 
/* The ims options can vary during the matching as a result of the presence
5817
 
of (?ims) items in the pattern. They are kept in a local variable so that
5818
 
restoring at the exit of a group is easy. */
5819
 
 
5820
 
ims = re->options & (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL);
5821
 
 
5822
6450
/* If the expression has got more back references than the offsets supplied can
5823
6451
hold, we get a temporary chunk of working store to use during the matching.
5824
6452
Otherwise, we can use the vector supplied, rounding down its size to a multiple
5825
6453
of 3. */
5826
6454
 
5827
6455
ocount = offsetcount - (offsetcount % 3);
 
6456
arg_offset_max = (2*ocount)/3;
5828
6457
 
5829
6458
if (re->top_backref > 0 && re->top_backref >= ocount/3)
5830
6459
  {
5831
6460
  ocount = re->top_backref * 3 + 3;
5832
 
  md->offset_vector = (int *)(pcre_malloc)(ocount * sizeof(int));
 
6461
  md->offset_vector = (int *)(PUBL(malloc))(ocount * sizeof(int));
5833
6462
  if (md->offset_vector == NULL) return PCRE_ERROR_NOMEMORY;
5834
6463
  using_temporary_offsets = TRUE;
5835
6464
  DPRINTF(("Got memory to hold back references\n"));
5841
6470
md->offset_overflow = FALSE;
5842
6471
md->capture_last = -1;
5843
6472
 
5844
 
/* Compute the minimum number of offsets that we need to reset each time. Doing
5845
 
this makes a huge difference to execution time when there aren't many brackets
5846
 
in the pattern. */
5847
 
 
5848
 
resetcount = 2 + re->top_bracket * 2;
5849
 
if (resetcount > offsetcount) resetcount = ocount;
5850
 
 
5851
6473
/* Reset the working variable associated with each extraction. These should
5852
6474
never be used unless previously set, but they get saved and restored, and so we
5853
 
initialize them to avoid reading uninitialized locations. */
 
6475
initialize them to avoid reading uninitialized locations. Also, unset the
 
6476
offsets for the matched string. This is really just for tidiness with callouts,
 
6477
in case they inspect these fields. */
5854
6478
 
5855
6479
if (md->offset_vector != NULL)
5856
6480
  {
5857
6481
  register int *iptr = md->offset_vector + ocount;
5858
 
  register int *iend = iptr - resetcount/2 + 1;
 
6482
  register int *iend = iptr - re->top_bracket;
 
6483
  if (iend < md->offset_vector + 2) iend = md->offset_vector + 2;
5859
6484
  while (--iptr >= iend) *iptr = -1;
 
6485
  md->offset_vector[0] = md->offset_vector[1] = -1;
5860
6486
  }
5861
6487
 
5862
 
/* Set up the first character to match, if available. The first_byte value is
 
6488
/* Set up the first character to match, if available. The first_char value is
5863
6489
never set for an anchored regular expression, but the anchoring may be forced
5864
6490
at run time, so we have to test for anchoring. The first char may be unset for
5865
6491
an unanchored pattern, of course. If there's no first char and the pattern was
5869
6495
  {
5870
6496
  if ((re->flags & PCRE_FIRSTSET) != 0)
5871
6497
    {
5872
 
    first_byte = re->first_byte & 255;
5873
 
    if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)
5874
 
      first_byte = md->lcc[first_byte];
 
6498
    has_first_char = TRUE;
 
6499
    first_char = first_char2 = (pcre_uchar)(re->first_char);
 
6500
    if ((re->flags & PCRE_FCH_CASELESS) != 0)
 
6501
      {
 
6502
      first_char2 = TABLE_GET(first_char, md->fcc, first_char);
 
6503
#if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
 
6504
      if (utf && first_char > 127)
 
6505
        first_char2 = UCD_OTHERCASE(first_char);
 
6506
#endif
 
6507
      }
5875
6508
    }
5876
6509
  else
5877
6510
    if (!startline && study != NULL &&
5884
6517
 
5885
6518
if ((re->flags & PCRE_REQCHSET) != 0)
5886
6519
  {
5887
 
  req_byte = re->req_byte & 255;
5888
 
  req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;
5889
 
  req_byte2 = (tables + fcc_offset)[req_byte];  /* case flipped */
 
6520
  has_req_char = TRUE;
 
6521
  req_char = req_char2 = (pcre_uchar)(re->req_char);
 
6522
  if ((re->flags & PCRE_RCH_CASELESS) != 0)
 
6523
    {
 
6524
    req_char2 = TABLE_GET(req_char, md->fcc, req_char);
 
6525
#if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
 
6526
    if (utf && req_char > 127)
 
6527
      req_char2 = UCD_OTHERCASE(req_char);
 
6528
#endif
 
6529
    }
5890
6530
  }
5891
6531
 
5892
6532
 
5897
6537
 
5898
6538
for(;;)
5899
6539
  {
5900
 
  USPTR save_end_subject = end_subject;
5901
 
  USPTR new_start_match;
5902
 
 
5903
 
  /* Reset the maximum number of extractions we might see. */
5904
 
 
5905
 
  if (md->offset_vector != NULL)
5906
 
    {
5907
 
    register int *iptr = md->offset_vector;
5908
 
    register int *iend = iptr + resetcount;
5909
 
    while (iptr < iend) *iptr++ = -1;
5910
 
    }
 
6540
  PCRE_PUCHAR save_end_subject = end_subject;
 
6541
  PCRE_PUCHAR new_start_match;
5911
6542
 
5912
6543
  /* If firstline is TRUE, the start of the match is constrained to the first
5913
6544
  line of a multiline string. That is, the match must be before or at the first
5917
6548
 
5918
6549
  if (firstline)
5919
6550
    {
5920
 
    USPTR t = start_match;
5921
 
#ifdef SUPPORT_UTF8
5922
 
    if (utf8)
 
6551
    PCRE_PUCHAR t = start_match;
 
6552
#ifdef SUPPORT_UTF
 
6553
    if (utf)
5923
6554
      {
5924
6555
      while (t < md->end_subject && !IS_NEWLINE(t))
5925
6556
        {
5926
6557
        t++;
5927
 
        while (t < end_subject && (*t & 0xc0) == 0x80) t++;
 
6558
        ACROSSCHAR(t < end_subject, *t, t++);
5928
6559
        }
5929
6560
      }
5930
6561
    else
5941
6572
 
5942
6573
  if (((options | re->options) & PCRE_NO_START_OPTIMIZE) == 0)
5943
6574
    {
5944
 
    /* Advance to a unique first byte if there is one. */
 
6575
    /* Advance to a unique first char if there is one. */
5945
6576
 
5946
 
    if (first_byte >= 0)
 
6577
    if (has_first_char)
5947
6578
      {
5948
 
      if (first_byte_caseless)
5949
 
        while (start_match < end_subject && md->lcc[*start_match] != first_byte)
 
6579
      if (first_char != first_char2)
 
6580
        while (start_match < end_subject &&
 
6581
            *start_match != first_char && *start_match != first_char2)
5950
6582
          start_match++;
5951
6583
      else
5952
 
        while (start_match < end_subject && *start_match != first_byte)
 
6584
        while (start_match < end_subject && *start_match != first_char)
5953
6585
          start_match++;
5954
6586
      }
5955
6587
 
5959
6591
      {
5960
6592
      if (start_match > md->start_subject + start_offset)
5961
6593
        {
5962
 
#ifdef SUPPORT_UTF8
5963
 
        if (utf8)
 
6594
#ifdef SUPPORT_UTF
 
6595
        if (utf)
5964
6596
          {
5965
6597
          while (start_match < end_subject && !WAS_NEWLINE(start_match))
5966
6598
            {
5967
6599
            start_match++;
5968
 
            while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
5969
 
              start_match++;
 
6600
            ACROSSCHAR(start_match < end_subject, *start_match,
 
6601
              start_match++);
5970
6602
            }
5971
6603
          }
5972
6604
        else
5993
6625
      while (start_match < end_subject)
5994
6626
        {
5995
6627
        register unsigned int c = *start_match;
 
6628
#ifndef COMPILE_PCRE8
 
6629
        if (c > 255) c = 255;
 
6630
#endif
5996
6631
        if ((start_bits[c/8] & (1 << (c&7))) == 0)
5997
6632
          {
5998
6633
          start_match++;
5999
 
#ifdef SUPPORT_UTF8
6000
 
          if (utf8)
6001
 
            while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
6002
 
              start_match++;
 
6634
#if defined SUPPORT_UTF && defined COMPILE_PCRE8
 
6635
          /* In non 8-bit mode, the iteration will stop for
 
6636
          characters > 255 at the beginning or not stop at all. */
 
6637
          if (utf)
 
6638
            ACROSSCHAR(start_match < end_subject, *start_match,
 
6639
              start_match++);
6003
6640
#endif
6004
6641
          }
6005
6642
        else break;
6014
6651
  /* The following two optimizations are disabled for partial matching or if
6015
6652
  disabling is explicitly requested. */
6016
6653
 
6017
 
  if ((options & PCRE_NO_START_OPTIMIZE) == 0 && !md->partial)
 
6654
  if (((options | re->options) & PCRE_NO_START_OPTIMIZE) == 0 && !md->partial)
6018
6655
    {
6019
6656
    /* If the pattern was studied, a minimum subject length may be set. This is
6020
6657
    a lower bound; no actual string of that length may actually match the
6028
6665
      break;
6029
6666
      }
6030
6667
 
6031
 
    /* If req_byte is set, we know that that character must appear in the
6032
 
    subject for the match to succeed. If the first character is set, req_byte
 
6668
    /* If req_char is set, we know that that character must appear in the
 
6669
    subject for the match to succeed. If the first character is set, req_char
6033
6670
    must be later in the subject; otherwise the test starts at the match point.
6034
6671
    This optimization can save a huge amount of backtracking in patterns with
6035
6672
    nested unlimited repeats that aren't going to match. Writing separate code
6042
6679
    32-megabyte string... so we don't do this when the string is sufficiently
6043
6680
    long. */
6044
6681
 
6045
 
    if (req_byte >= 0 && end_subject - start_match < REQ_BYTE_MAX)
 
6682
    if (has_req_char && end_subject - start_match < REQ_BYTE_MAX)
6046
6683
      {
6047
 
      register USPTR p = start_match + ((first_byte >= 0)? 1 : 0);
 
6684
      register PCRE_PUCHAR p = start_match + (has_first_char? 1:0);
6048
6685
 
6049
6686
      /* We don't need to repeat the search if we haven't yet reached the
6050
6687
      place we found it at last time. */
6051
6688
 
6052
 
      if (p > req_byte_ptr)
 
6689
      if (p > req_char_ptr)
6053
6690
        {
6054
 
        if (req_byte_caseless)
 
6691
        if (req_char != req_char2)
6055
6692
          {
6056
6693
          while (p < end_subject)
6057
6694
            {
6058
6695
            register int pp = *p++;
6059
 
            if (pp == req_byte || pp == req_byte2) { p--; break; }
 
6696
            if (pp == req_char || pp == req_char2) { p--; break; }
6060
6697
            }
6061
6698
          }
6062
6699
        else
6063
6700
          {
6064
6701
          while (p < end_subject)
6065
6702
            {
6066
 
            if (*p++ == req_byte) { p--; break; }
 
6703
            if (*p++ == req_char) { p--; break; }
6067
6704
            }
6068
6705
          }
6069
6706
 
6080
6717
        found it, so that we don't search again next time round the loop if
6081
6718
        the start hasn't passed this character yet. */
6082
6719
 
6083
 
        req_byte_ptr = p;
 
6720
        req_char_ptr = p;
6084
6721
        }
6085
6722
      }
6086
6723
    }
6097
6734
  md->start_match_ptr = start_match;
6098
6735
  md->start_used_ptr = start_match;
6099
6736
  md->match_call_count = 0;
6100
 
  rc = match(start_match, md->start_code, start_match, NULL, 2, md, ims, NULL,
6101
 
    0, 0);
 
6737
  md->match_function_type = 0;
 
6738
  md->end_offset_top = 0;
 
6739
  rc = match(start_match, md->start_code, start_match, 2, md, NULL, 0);
6102
6740
  if (md->hitend && start_partial == NULL) start_partial = md->start_used_ptr;
6103
6741
 
6104
6742
  switch(rc)
6105
6743
    {
 
6744
    /* If MATCH_SKIP_ARG reaches this level it means that a MARK that matched
 
6745
    the SKIP's arg was not found. In this circumstance, Perl ignores the SKIP
 
6746
    entirely. The only way we can do that is to re-do the match at the same
 
6747
    point, with a flag to force SKIP with an argument to be ignored. Just
 
6748
    treating this case as NOMATCH does not work because it does not check other
 
6749
    alternatives in patterns such as A(*SKIP:A)B|AC when the subject is AC. */
 
6750
 
 
6751
    case MATCH_SKIP_ARG:
 
6752
    new_start_match = start_match;
 
6753
    md->ignore_skip_arg = TRUE;
 
6754
    break;
 
6755
 
6106
6756
    /* SKIP passes back the next starting point explicitly, but if it is the
6107
6757
    same as the match we have just done, treat it as NOMATCH. */
6108
6758
 
6114
6764
      }
6115
6765
    /* Fall through */
6116
6766
 
6117
 
    /* If MATCH_SKIP_ARG reaches this level it means that a MARK that matched
6118
 
    the SKIP's arg was not found. We also treat this as NOMATCH. */
6119
 
 
6120
 
    case MATCH_SKIP_ARG:
6121
 
    /* Fall through */
6122
 
 
6123
6767
    /* NOMATCH and PRUNE advance by one character. THEN at this level acts
6124
 
    exactly like PRUNE. */
 
6768
    exactly like PRUNE. Unset the ignore SKIP-with-argument flag. */
6125
6769
 
6126
6770
    case MATCH_NOMATCH:
6127
6771
    case MATCH_PRUNE:
6128
6772
    case MATCH_THEN:
 
6773
    md->ignore_skip_arg = FALSE;
6129
6774
    new_start_match = start_match + 1;
6130
 
#ifdef SUPPORT_UTF8
6131
 
    if (utf8)
6132
 
      while(new_start_match < end_subject && (*new_start_match & 0xc0) == 0x80)
6133
 
        new_start_match++;
 
6775
#ifdef SUPPORT_UTF
 
6776
    if (utf)
 
6777
      ACROSSCHAR(new_start_match < end_subject, *new_start_match,
 
6778
        new_start_match++);
6134
6779
#endif
6135
6780
    break;
6136
6781
 
6168
6813
 
6169
6814
  /* If we have just passed a CR and we are now at a LF, and the pattern does
6170
6815
  not contain any explicit matches for \r or \n, and the newline option is CRLF
6171
 
  or ANY or ANYCRLF, advance the match position by one more character. */
 
6816
  or ANY or ANYCRLF, advance the match position by one more character. In
 
6817
  normal matching start_match will aways be greater than the first position at
 
6818
  this stage, but a failed *SKIP can cause a return at the same point, which is
 
6819
  why the first test exists. */
6172
6820
 
6173
 
  if (start_match[-1] == CHAR_CR &&
 
6821
  if (start_match > (PCRE_PUCHAR)subject + start_offset &&
 
6822
      start_match[-1] == CHAR_CR &&
6174
6823
      start_match < end_subject &&
6175
6824
      *start_match == CHAR_NL &&
6176
6825
      (re->flags & PCRE_HASCRORLF) == 0 &&
6208
6857
  {
6209
6858
  if (using_temporary_offsets)
6210
6859
    {
6211
 
    if (offsetcount >= 4)
 
6860
    if (arg_offset_max >= 4)
6212
6861
      {
6213
6862
      memcpy(offsets + 2, md->offset_vector + 2,
6214
 
        (offsetcount - 2) * sizeof(int));
 
6863
        (arg_offset_max - 2) * sizeof(int));
6215
6864
      DPRINTF(("Copied offsets from temporary memory\n"));
6216
6865
      }
6217
 
    if (md->end_offset_top > offsetcount) md->offset_overflow = TRUE;
 
6866
    if (md->end_offset_top > arg_offset_max) md->offset_overflow = TRUE;
6218
6867
    DPRINTF(("Freeing temporary memory\n"));
6219
 
    (pcre_free)(md->offset_vector);
 
6868
    (PUBL(free))(md->offset_vector);
6220
6869
    }
6221
6870
 
6222
 
  /* Set the return code to the number of captured strings, or 0 if there are
 
6871
  /* Set the return code to the number of captured strings, or 0 if there were
6223
6872
  too many to fit into the vector. */
6224
6873
 
6225
 
  rc = md->offset_overflow? 0 : md->end_offset_top/2;
 
6874
  rc = (md->offset_overflow && md->end_offset_top >= arg_offset_max)?
 
6875
    0 : md->end_offset_top/2;
 
6876
 
 
6877
  /* If there is space in the offset vector, set any unused pairs at the end of
 
6878
  the pattern to -1 for backwards compatibility. It is documented that this
 
6879
  happens. In earlier versions, the whole set of potential capturing offsets
 
6880
  was set to -1 each time round the loop, but this is handled differently now.
 
6881
  "Gaps" are set to -1 dynamically instead (this fixes a bug). Thus, it is only
 
6882
  those at the end that need unsetting here. We can't just unset them all at
 
6883
  the start of the whole thing because they may get set in one branch that is
 
6884
  not the final matching branch. */
 
6885
 
 
6886
  if (md->end_offset_top/2 <= re->top_bracket && offsets != NULL)
 
6887
    {
 
6888
    register int *iptr, *iend;
 
6889
    int resetcount = 2 + re->top_bracket * 2;
 
6890
    if (resetcount > offsetcount) resetcount = ocount;
 
6891
    iptr = offsets + md->end_offset_top;
 
6892
    iend = offsets + resetcount;
 
6893
    while (iptr < iend) *iptr++ = -1;
 
6894
    }
6226
6895
 
6227
6896
  /* If there is space, set up the whole thing as substring 0. The value of
6228
6897
  md->start_match_ptr might be modified if \K was encountered on the success
6234
6903
    offsets[1] = (int)(md->end_match_ptr - md->start_subject);
6235
6904
    }
6236
6905
 
 
6906
  /* Return MARK data if requested */
 
6907
 
 
6908
  if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_MARK) != 0)
 
6909
    *(extra_data->mark) = (pcre_uchar *)md->mark;
6237
6910
  DPRINTF((">>>> returning %d\n", rc));
6238
 
  goto RETURN_MARK;
 
6911
  return rc;
6239
6912
  }
6240
6913
 
6241
6914
/* Control gets here if there has been an error, or if the overall match
6244
6917
if (using_temporary_offsets)
6245
6918
  {
6246
6919
  DPRINTF(("Freeing temporary memory\n"));
6247
 
  (pcre_free)(md->offset_vector);
 
6920
  (PUBL(free))(md->offset_vector);
6248
6921
  }
6249
6922
 
6250
6923
/* For anything other than nomatch or partial match, just return the code. */
6263
6936
  md->mark = NULL;
6264
6937
  if (offsetcount > 1)
6265
6938
    {
6266
 
    offsets[0] = (int)(start_partial - (USPTR)subject);
6267
 
    offsets[1] = (int)(end_subject - (USPTR)subject);
 
6939
    offsets[0] = (int)(start_partial - (PCRE_PUCHAR)subject);
 
6940
    offsets[1] = (int)(end_subject - (PCRE_PUCHAR)subject);
6268
6941
    }
6269
6942
  rc = PCRE_ERROR_PARTIAL;
6270
6943
  }
6279
6952
 
6280
6953
/* Return the MARK data if it has been requested. */
6281
6954
 
6282
 
RETURN_MARK:
6283
 
 
6284
6955
if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_MARK) != 0)
6285
 
  *(extra_data->mark) = (unsigned char *)(md->mark);
 
6956
  *(extra_data->mark) = (pcre_uchar *)md->nomatch_mark;
6286
6957
return rc;
6287
6958
}
6288
6959