/[pcre]/code/trunk/pcretest.c
ViewVC logotype

Diff of /code/trunk/pcretest.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1030 by ph10, Sat Sep 8 15:58:38 2012 UTC revision 1313 by ph10, Wed Apr 24 12:07:09 2013 UTC
# Line 36  POSSIBILITY OF SUCH DAMAGE. Line 36  POSSIBILITY OF SUCH DAMAGE.
36  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
37  */  */
38    
39  /* This program now supports the testing of both the 8-bit and 16-bit PCRE  /* This program now supports the testing of all of the 8-bit, 16-bit, and
40  libraries in a single program. This is different from the modules such as  32-bit PCRE libraries in a single program. This is different from the modules
41  pcre_compile.c in the library itself, which are compiled separately for each  such as pcre_compile.c in the library itself, which are compiled separately for
42  mode. If both modes are enabled, for example, pcre_compile.c is compiled twice  each mode. If two modes are enabled, for example, pcre_compile.c is compiled
43  (the second time with COMPILE_PCRE16 defined). By contrast, pcretest.c is  twice. By contrast, pcretest.c is compiled only once. Therefore, it must not
44  compiled only once. Therefore, it must not make use of any of the macros from  make use of any of the macros from pcre_internal.h that depend on
45  pcre_internal.h that depend on COMPILE_PCRE8 or COMPILE_PCRE16. It does,  COMPILE_PCRE8, COMPILE_PCRE16, or COMPILE_PCRE32. It does, however, make use of
46  however, make use of SUPPORT_PCRE8 and SUPPORT_PCRE16 to ensure that it calls  SUPPORT_PCRE8, SUPPORT_PCRE16, and SUPPORT_PCRE32 to ensure that it calls only
47  only supported library functions. */  supported library functions. */
48    
49  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
50  #include "config.h"  #include "config.h"
# Line 121  input mode under Windows. */ Line 121  input mode under Windows. */
121  #endif  #endif
122  #endif  #endif
123    
124    #ifdef __VMS
125    #include <ssdef.h>
126    void vms_setsymbol( char *, char *, int );
127    #endif
128    
129    
130  #define PRIV(name) name  #define PRIV(name) name
131    
132  /* We have to include pcre_internal.h because we need the internal info for  /* We have to include pcre_internal.h because we need the internal info for
# Line 133  here before pcre_internal.h so that the Line 139  here before pcre_internal.h so that the
139  appropriately for an application, not for building PCRE. */  appropriately for an application, not for building PCRE. */
140    
141  #include "pcre.h"  #include "pcre.h"
   
 #if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8  
 /* Configure internal macros to 16 bit mode. */  
 #define COMPILE_PCRE16  
 #endif  
   
142  #include "pcre_internal.h"  #include "pcre_internal.h"
143    
144  /* The pcre_printint() function, which prints the internal form of a compiled  /* The pcre_printint() function, which prints the internal form of a compiled
145  regex, is held in a separate file so that (a) it can be compiled in either  regex, is held in a separate file so that (a) it can be compiled in either
146  8-bit or 16-bit mode, and (b) it can be #included directly in pcre_compile.c  8-, 16- or 32-bit mode, and (b) it can be #included directly in pcre_compile.c
147  when that is compiled in debug mode. */  when that is compiled in debug mode. */
148    
149  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
# Line 152  void pcre_printint(pcre *external_re, FI Line 152  void pcre_printint(pcre *external_re, FI
152  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
153  void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths);  void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths);
154  #endif  #endif
155    #ifdef SUPPORT_PCRE32
156    void pcre32_printint(pcre *external_re, FILE *f, BOOL print_lengths);
157    #endif
158    
159  /* We need access to some of the data tables that PCRE uses. So as not to have  /* We need access to some of the data tables that PCRE uses. So as not to have
160  to keep two copies, we include the source file here, changing the names of the  to keep two copies, we include the source files here, changing the names of the
161  external symbols to prevent clashes. */  external symbols to prevent clashes. */
162    
163  #define PCRE_INCLUDED  #define PCRE_INCLUDED
164    
165  #include "pcre_tables.c"  #include "pcre_tables.c"
166    #include "pcre_ucd.c"
167    
168  /* The definition of the macro PRINTABLE, which determines whether to print an  /* The definition of the macro PRINTABLE, which determines whether to print an
169  output character as-is or as a hex value when showing compiled patterns, is  output character as-is or as a hex value when showing compiled patterns, is
# Line 175  that differ in their output from isprint Line 179  that differ in their output from isprint
179    
180  #define PRINTOK(c) (locale_set? isprint(c) : PRINTABLE(c))  #define PRINTOK(c) (locale_set? isprint(c) : PRINTABLE(c))
181    
182  /* Posix support is disabled in 16 bit only mode. */  /* Posix support is disabled in 16 or 32 bit only mode. */
183  #if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8 && !defined NOPOSIX  #if !defined SUPPORT_PCRE8 && !defined NOPOSIX
184  #define NOPOSIX  #define NOPOSIX
185  #endif  #endif
186    
# Line 199  automatically cut out the UTF support if Line 203  automatically cut out the UTF support if
203  #endif  #endif
204  #endif  #endif
205    
206  /* To make the code a bit tidier for 8-bit and 16-bit support, we define macros  /* To make the code a bit tidier for 8/16/32-bit support, we define macros
207  for all the pcre[16]_xxx functions (except pcre16_fullinfo, which is called  for all the pcre[16]_xxx functions (except pcre16_fullinfo, which is called
208  only from one place and is handled differently). I couldn't dream up any way of  only from one place and is handled differently). I couldn't dream up any way of
209  using a single macro to do this in a generic way, because of the many different  using a single macro to do this in a generic way, because of the many different
# Line 221  argument, the casting might be incorrect Line 225  argument, the casting might be incorrect
225  #define PCHARSV8(p, offset, len, f) \  #define PCHARSV8(p, offset, len, f) \
226    (void)pchars((pcre_uint8 *)(p) + offset, len, f)    (void)pchars((pcre_uint8 *)(p) + offset, len, f)
227    
228  #define READ_CAPTURE_NAME8(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME8(p, cn8, cn16, cn32, re) \
229    p = read_capture_name8(p, cn8, re)    p = read_capture_name8(p, cn8, re)
230    
231  #define STRLEN8(p) ((int)strlen((char *)p))  #define STRLEN8(p) ((int)strlen((char *)p))
# Line 291  argument, the casting might be incorrect Line 295  argument, the casting might be incorrect
295  #define PCRE_JIT_STACK_FREE8(stack) \  #define PCRE_JIT_STACK_FREE8(stack) \
296    pcre_jit_stack_free(stack)    pcre_jit_stack_free(stack)
297    
298    #define pcre8_maketables pcre_maketables
299    
300  #endif /* SUPPORT_PCRE8 */  #endif /* SUPPORT_PCRE8 */
301    
302  /* -----------------------------------------------------------*/  /* -----------------------------------------------------------*/
# Line 303  argument, the casting might be incorrect Line 309  argument, the casting might be incorrect
309  #define PCHARSV16(p, offset, len, f) \  #define PCHARSV16(p, offset, len, f) \
310    (void)pchars16((PCRE_SPTR16)(p) + offset, len, f)    (void)pchars16((PCRE_SPTR16)(p) + offset, len, f)
311    
312  #define READ_CAPTURE_NAME16(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME16(p, cn8, cn16, cn32, re) \
313    p = read_capture_name16(p, cn16, re)    p = read_capture_name16(p, cn16, re)
314    
315  #define STRLEN16(p) ((int)strlen16((PCRE_SPTR16)p))  #define STRLEN16(p) ((int)strlen16((PCRE_SPTR16)p))
# Line 382  argument, the casting might be incorrect Line 388  argument, the casting might be incorrect
388    
389  #endif /* SUPPORT_PCRE16 */  #endif /* SUPPORT_PCRE16 */
390    
391    /* -----------------------------------------------------------*/
392    
393    #ifdef SUPPORT_PCRE32
394    
395    #define PCHARS32(lv, p, offset, len, f) \
396      lv = pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
397    
398    #define PCHARSV32(p, offset, len, f)                \
399      (void)pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
400    
401    #define READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re) \
402      p = read_capture_name32(p, cn32, re)
403    
404    #define STRLEN32(p) ((int)strlen32((PCRE_SPTR32)p))
405    
406    #define SET_PCRE_CALLOUT32(callout) \
407      pcre32_callout = (int (*)(pcre32_callout_block *))callout
408    
409    #define PCRE_ASSIGN_JIT_STACK32(extra, callback, userdata) \
410      pcre32_assign_jit_stack((pcre32_extra *)extra, \
411        (pcre32_jit_callback)callback, userdata)
412    
413    #define PCRE_COMPILE32(re, pat, options, error, erroffset, tables) \
414      re = (pcre *)pcre32_compile((PCRE_SPTR32)pat, options, error, erroffset, \
415        tables)
416    
417    #define PCRE_COPY_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
418        namesptr, cbuffer, size) \
419      rc = pcre32_copy_named_substring((pcre32 *)re, (PCRE_SPTR32)bptr, offsets, \
420        count, (PCRE_SPTR32)namesptr, (PCRE_UCHAR32 *)cbuffer, size/2)
421    
422    #define PCRE_COPY_SUBSTRING32(rc, bptr, offsets, count, i, cbuffer, size) \
423      rc = pcre32_copy_substring((PCRE_SPTR32)bptr, offsets, count, i, \
424        (PCRE_UCHAR32 *)cbuffer, size/2)
425    
426    #define PCRE_DFA_EXEC32(count, re, extra, bptr, len, start_offset, options, \
427        offsets, size_offsets, workspace, size_workspace) \
428      count = pcre32_dfa_exec((pcre32 *)re, (pcre32_extra *)extra, \
429        (PCRE_SPTR32)bptr, len, start_offset, options, offsets, size_offsets, \
430        workspace, size_workspace)
431    
432    #define PCRE_EXEC32(count, re, extra, bptr, len, start_offset, options, \
433        offsets, size_offsets) \
434      count = pcre32_exec((pcre32 *)re, (pcre32_extra *)extra, (PCRE_SPTR32)bptr, \
435        len, start_offset, options, offsets, size_offsets)
436    
437    #define PCRE_FREE_STUDY32(extra) \
438      pcre32_free_study((pcre32_extra *)extra)
439    
440    #define PCRE_FREE_SUBSTRING32(substring) \
441      pcre32_free_substring((PCRE_SPTR32)substring)
442    
443    #define PCRE_FREE_SUBSTRING_LIST32(listptr) \
444      pcre32_free_substring_list((PCRE_SPTR32 *)listptr)
445    
446    #define PCRE_GET_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
447        getnamesptr, subsptr) \
448      rc = pcre32_get_named_substring((pcre32 *)re, (PCRE_SPTR32)bptr, offsets, \
449        count, (PCRE_SPTR32)getnamesptr, (PCRE_SPTR32 *)(void*)subsptr)
450    
451    #define PCRE_GET_STRINGNUMBER32(n, rc, ptr) \
452      n = pcre32_get_stringnumber(re, (PCRE_SPTR32)ptr)
453    
454    #define PCRE_GET_SUBSTRING32(rc, bptr, offsets, count, i, subsptr) \
455      rc = pcre32_get_substring((PCRE_SPTR32)bptr, offsets, count, i, \
456        (PCRE_SPTR32 *)(void*)subsptr)
457    
458    #define PCRE_GET_SUBSTRING_LIST32(rc, bptr, offsets, count, listptr) \
459      rc = pcre32_get_substring_list((PCRE_SPTR32)bptr, offsets, count, \
460        (PCRE_SPTR32 **)(void*)listptr)
461    
462    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER32(rc, re, extra, tables) \
463      rc = pcre32_pattern_to_host_byte_order((pcre32 *)re, (pcre32_extra *)extra, \
464        tables)
465    
466    #define PCRE_PRINTINT32(re, outfile, debug_lengths) \
467      pcre32_printint(re, outfile, debug_lengths)
468    
469    #define PCRE_STUDY32(extra, re, options, error) \
470      extra = (pcre_extra *)pcre32_study((pcre32 *)re, options, error)
471    
472  /* ----- Both modes are supported; a runtime test is needed, except for  #define PCRE_JIT_STACK_ALLOC32(startsize, maxsize) \
473      (pcre_jit_stack *)pcre32_jit_stack_alloc(startsize, maxsize)
474    
475    #define PCRE_JIT_STACK_FREE32(stack) \
476      pcre32_jit_stack_free((pcre32_jit_stack *)stack)
477    
478    #endif /* SUPPORT_PCRE32 */
479    
480    
481    /* ----- More than one mode is supported; a runtime test is needed, except for
482  pcre_config(), and the JIT stack functions, when it doesn't matter which  pcre_config(), and the JIT stack functions, when it doesn't matter which
483  version is called. ----- */  available version is called. ----- */
484    
485    enum {
486      PCRE8_MODE,
487      PCRE16_MODE,
488      PCRE32_MODE
489    };
490    
491  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #if (defined (SUPPORT_PCRE8) + defined (SUPPORT_PCRE16) + \
492         defined (SUPPORT_PCRE32)) >= 2
493    
494  #define CHAR_SIZE (use_pcre16? 2:1)  #define CHAR_SIZE (1 << pcre_mode)
495    
496    /* There doesn't seem to be an easy way of writing these macros that can cope
497    with the 3 pairs of bit sizes plus all three bit sizes. So just handle all the
498    cases separately. */
499    
500    /* ----- All three modes supported ----- */
501    
502    #if defined(SUPPORT_PCRE8) && defined(SUPPORT_PCRE16) && defined(SUPPORT_PCRE32)
503    
504  #define PCHARS(lv, p, offset, len, f) \  #define PCHARS(lv, p, offset, len, f) \
505    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
506        PCHARS32(lv, p, offset, len, f); \
507      else if (pcre_mode == PCRE16_MODE) \
508      PCHARS16(lv, p, offset, len, f); \      PCHARS16(lv, p, offset, len, f); \
509    else \    else \
510      PCHARS8(lv, p, offset, len, f)      PCHARS8(lv, p, offset, len, f)
511    
512  #define PCHARSV(p, offset, len, f) \  #define PCHARSV(p, offset, len, f) \
513    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
514        PCHARSV32(p, offset, len, f); \
515      else if (pcre_mode == PCRE16_MODE) \
516      PCHARSV16(p, offset, len, f); \      PCHARSV16(p, offset, len, f); \
517    else \    else \
518      PCHARSV8(p, offset, len, f)      PCHARSV8(p, offset, len, f)
519    
520  #define READ_CAPTURE_NAME(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME(p, cn8, cn16, cn32, re) \
521    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
522      READ_CAPTURE_NAME16(p, cn8, cn16, re); \      READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re); \
523      else if (pcre_mode == PCRE16_MODE) \
524        READ_CAPTURE_NAME16(p, cn8, cn16, cn32, re); \
525    else \    else \
526      READ_CAPTURE_NAME8(p, cn8, cn16, re)      READ_CAPTURE_NAME8(p, cn8, cn16, cn32, re)
527    
528  #define SET_PCRE_CALLOUT(callout) \  #define SET_PCRE_CALLOUT(callout) \
529    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
530        SET_PCRE_CALLOUT32(callout); \
531      else if (pcre_mode == PCRE16_MODE) \
532      SET_PCRE_CALLOUT16(callout); \      SET_PCRE_CALLOUT16(callout); \
533    else \    else \
534      SET_PCRE_CALLOUT8(callout)      SET_PCRE_CALLOUT8(callout)
535    
536  #define STRLEN(p) (use_pcre16? STRLEN16(p) : STRLEN8(p))  #define STRLEN(p) (pcre_mode == PCRE32_MODE ? STRLEN32(p) : pcre_mode == PCRE16_MODE ? STRLEN16(p) : STRLEN8(p))
537    
538  #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \  #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
539    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
540        PCRE_ASSIGN_JIT_STACK32(extra, callback, userdata); \
541      else if (pcre_mode == PCRE16_MODE) \
542      PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata); \      PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata); \
543    else \    else \
544      PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata)      PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata)
545    
546  #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \  #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
547    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
548        PCRE_COMPILE32(re, pat, options, error, erroffset, tables); \
549      else if (pcre_mode == PCRE16_MODE) \
550      PCRE_COMPILE16(re, pat, options, error, erroffset, tables); \      PCRE_COMPILE16(re, pat, options, error, erroffset, tables); \
551    else \    else \
552      PCRE_COMPILE8(re, pat, options, error, erroffset, tables)      PCRE_COMPILE8(re, pat, options, error, erroffset, tables)
# Line 433  version is called. ----- */ Line 555  version is called. ----- */
555    
556  #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \  #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
557      namesptr, cbuffer, size) \      namesptr, cbuffer, size) \
558    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
559        PCRE_COPY_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
560          namesptr, cbuffer, size); \
561      else if (pcre_mode == PCRE16_MODE) \
562      PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \      PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
563        namesptr, cbuffer, size); \        namesptr, cbuffer, size); \
564    else \    else \
# Line 441  version is called. ----- */ Line 566  version is called. ----- */
566        namesptr, cbuffer, size)        namesptr, cbuffer, size)
567    
568  #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \  #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \
569    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
570        PCRE_COPY_SUBSTRING32(rc, bptr, offsets, count, i, cbuffer, size); \
571      else if (pcre_mode == PCRE16_MODE) \
572      PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size); \      PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size); \
573    else \    else \
574      PCRE_COPY_SUBSTRING8(rc, bptr, offsets, count, i, cbuffer, size)      PCRE_COPY_SUBSTRING8(rc, bptr, offsets, count, i, cbuffer, size)
575    
576  #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \
577      offsets, size_offsets, workspace, size_workspace) \      offsets, size_offsets, workspace, size_workspace) \
578    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
579        PCRE_DFA_EXEC32(count, re, extra, bptr, len, start_offset, options, \
580          offsets, size_offsets, workspace, size_workspace); \
581      else if (pcre_mode == PCRE16_MODE) \
582      PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \      PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \
583        offsets, size_offsets, workspace, size_workspace); \        offsets, size_offsets, workspace, size_workspace); \
584    else \    else \
# Line 457  version is called. ----- */ Line 587  version is called. ----- */
587    
588  #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
589      offsets, size_offsets) \      offsets, size_offsets) \
590    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
591        PCRE_EXEC32(count, re, extra, bptr, len, start_offset, options, \
592          offsets, size_offsets); \
593      else if (pcre_mode == PCRE16_MODE) \
594      PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \      PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \
595        offsets, size_offsets); \        offsets, size_offsets); \
596    else \    else \
# Line 465  version is called. ----- */ Line 598  version is called. ----- */
598        offsets, size_offsets)        offsets, size_offsets)
599    
600  #define PCRE_FREE_STUDY(extra) \  #define PCRE_FREE_STUDY(extra) \
601    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
602        PCRE_FREE_STUDY32(extra); \
603      else if (pcre_mode == PCRE16_MODE) \
604      PCRE_FREE_STUDY16(extra); \      PCRE_FREE_STUDY16(extra); \
605    else \    else \
606      PCRE_FREE_STUDY8(extra)      PCRE_FREE_STUDY8(extra)
607    
608  #define PCRE_FREE_SUBSTRING(substring) \  #define PCRE_FREE_SUBSTRING(substring) \
609    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
610        PCRE_FREE_SUBSTRING32(substring); \
611      else if (pcre_mode == PCRE16_MODE) \
612      PCRE_FREE_SUBSTRING16(substring); \      PCRE_FREE_SUBSTRING16(substring); \
613    else \    else \
614      PCRE_FREE_SUBSTRING8(substring)      PCRE_FREE_SUBSTRING8(substring)
615    
616  #define PCRE_FREE_SUBSTRING_LIST(listptr) \  #define PCRE_FREE_SUBSTRING_LIST(listptr) \
617    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
618        PCRE_FREE_SUBSTRING_LIST32(listptr); \
619      else if (pcre_mode == PCRE16_MODE) \
620      PCRE_FREE_SUBSTRING_LIST16(listptr); \      PCRE_FREE_SUBSTRING_LIST16(listptr); \
621    else \    else \
622      PCRE_FREE_SUBSTRING_LIST8(listptr)      PCRE_FREE_SUBSTRING_LIST8(listptr)
623    
624  #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \  #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
625      getnamesptr, subsptr) \      getnamesptr, subsptr) \
626    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
627        PCRE_GET_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
628          getnamesptr, subsptr); \
629      else if (pcre_mode == PCRE16_MODE) \
630      PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \      PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
631        getnamesptr, subsptr); \        getnamesptr, subsptr); \
632    else \    else \
# Line 492  version is called. ----- */ Line 634  version is called. ----- */
634        getnamesptr, subsptr)        getnamesptr, subsptr)
635    
636  #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \  #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \
637    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
638        PCRE_GET_STRINGNUMBER32(n, rc, ptr); \
639      else if (pcre_mode == PCRE16_MODE) \
640      PCRE_GET_STRINGNUMBER16(n, rc, ptr); \      PCRE_GET_STRINGNUMBER16(n, rc, ptr); \
641    else \    else \
642      PCRE_GET_STRINGNUMBER8(n, rc, ptr)      PCRE_GET_STRINGNUMBER8(n, rc, ptr)
643    
644  #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \  #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \
645    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
646        PCRE_GET_SUBSTRING32(rc, bptr, use_offsets, count, i, subsptr); \
647      else if (pcre_mode == PCRE16_MODE) \
648      PCRE_GET_SUBSTRING16(rc, bptr, use_offsets, count, i, subsptr); \      PCRE_GET_SUBSTRING16(rc, bptr, use_offsets, count, i, subsptr); \
649    else \    else \
650      PCRE_GET_SUBSTRING8(rc, bptr, use_offsets, count, i, subsptr)      PCRE_GET_SUBSTRING8(rc, bptr, use_offsets, count, i, subsptr)
651    
652  #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \  #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \
653    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
654        PCRE_GET_SUBSTRING_LIST32(rc, bptr, offsets, count, listptr); \
655      else if (pcre_mode == PCRE16_MODE) \
656      PCRE_GET_SUBSTRING_LIST16(rc, bptr, offsets, count, listptr); \      PCRE_GET_SUBSTRING_LIST16(rc, bptr, offsets, count, listptr); \
657    else \    else \
658      PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)      PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)
659    
660  #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \  #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
661    (use_pcre16 ? \    (pcre_mode == PCRE32_MODE ? \
662       PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \       PCRE_JIT_STACK_ALLOC32(startsize, maxsize) \
663      :PCRE_JIT_STACK_ALLOC8(startsize, maxsize))      : pcre_mode == PCRE16_MODE ? \
664          PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \
665          : PCRE_JIT_STACK_ALLOC8(startsize, maxsize))
666    
667  #define PCRE_JIT_STACK_FREE(stack) \  #define PCRE_JIT_STACK_FREE(stack) \
668    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
669        PCRE_JIT_STACK_FREE32(stack); \
670      else if (pcre_mode == PCRE16_MODE) \
671      PCRE_JIT_STACK_FREE16(stack); \      PCRE_JIT_STACK_FREE16(stack); \
672    else \    else \
673      PCRE_JIT_STACK_FREE8(stack)      PCRE_JIT_STACK_FREE8(stack)
674    
675  #define PCRE_MAKETABLES \  #define PCRE_MAKETABLES \
676    (use_pcre16? pcre16_maketables() : pcre_maketables())    (pcre_mode == PCRE32_MODE ? pcre32_maketables() : pcre_mode == PCRE16_MODE ? pcre16_maketables() : pcre_maketables())
677    
678  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \
679    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
680        PCRE_PATTERN_TO_HOST_BYTE_ORDER32(rc, re, extra, tables); \
681      else if (pcre_mode == PCRE16_MODE) \
682      PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables); \      PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables); \
683    else \    else \
684      PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables)      PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables)
685    
686  #define PCRE_PRINTINT(re, outfile, debug_lengths) \  #define PCRE_PRINTINT(re, outfile, debug_lengths) \
687    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
688        PCRE_PRINTINT32(re, outfile, debug_lengths); \
689      else if (pcre_mode == PCRE16_MODE) \
690      PCRE_PRINTINT16(re, outfile, debug_lengths); \      PCRE_PRINTINT16(re, outfile, debug_lengths); \
691    else \    else \
692      PCRE_PRINTINT8(re, outfile, debug_lengths)      PCRE_PRINTINT8(re, outfile, debug_lengths)
693    
694  #define PCRE_STUDY(extra, re, options, error) \  #define PCRE_STUDY(extra, re, options, error) \
695    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
696        PCRE_STUDY32(extra, re, options, error); \
697      else if (pcre_mode == PCRE16_MODE) \
698      PCRE_STUDY16(extra, re, options, error); \      PCRE_STUDY16(extra, re, options, error); \
699    else \    else \
700      PCRE_STUDY8(extra, re, options, error)      PCRE_STUDY8(extra, re, options, error)
701    
702    
703    /* ----- Two out of three modes are supported ----- */
704    
705    #else
706    
707    /* We can use some macro trickery to make a single set of definitions work in
708    the three different cases. */
709    
710    /* ----- 32-bit and 16-bit but not 8-bit supported ----- */
711    
712    #if defined(SUPPORT_PCRE32) && defined(SUPPORT_PCRE16)
713    #define BITONE 32
714    #define BITTWO 16
715    
716    /* ----- 32-bit and 8-bit but not 16-bit supported ----- */
717    
718    #elif defined(SUPPORT_PCRE32) && defined(SUPPORT_PCRE8)
719    #define BITONE 32
720    #define BITTWO 8
721    
722    /* ----- 16-bit and 8-bit but not 32-bit supported ----- */
723    
724    #else
725    #define BITONE 16
726    #define BITTWO 8
727    #endif
728    
729    #define glue(a,b) a##b
730    #define G(a,b) glue(a,b)
731    
732    
733    /* ----- Common macros for two-mode cases ----- */
734    
735    #define PCHARS(lv, p, offset, len, f) \
736      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
737        G(PCHARS,BITONE)(lv, p, offset, len, f); \
738      else \
739        G(PCHARS,BITTWO)(lv, p, offset, len, f)
740    
741    #define PCHARSV(p, offset, len, f) \
742      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
743        G(PCHARSV,BITONE)(p, offset, len, f); \
744      else \
745        G(PCHARSV,BITTWO)(p, offset, len, f)
746    
747    #define READ_CAPTURE_NAME(p, cn8, cn16, cn32, re) \
748      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
749        G(READ_CAPTURE_NAME,BITONE)(p, cn8, cn16, cn32, re); \
750      else \
751        G(READ_CAPTURE_NAME,BITTWO)(p, cn8, cn16, cn32, re)
752    
753    #define SET_PCRE_CALLOUT(callout) \
754      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
755        G(SET_PCRE_CALLOUT,BITONE)(callout); \
756      else \
757        G(SET_PCRE_CALLOUT,BITTWO)(callout)
758    
759    #define STRLEN(p) ((pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
760      G(STRLEN,BITONE)(p) : G(STRLEN,BITTWO)(p))
761    
762    #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
763      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
764        G(PCRE_ASSIGN_JIT_STACK,BITONE)(extra, callback, userdata); \
765      else \
766        G(PCRE_ASSIGN_JIT_STACK,BITTWO)(extra, callback, userdata)
767    
768    #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
769      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
770        G(PCRE_COMPILE,BITONE)(re, pat, options, error, erroffset, tables); \
771      else \
772        G(PCRE_COMPILE,BITTWO)(re, pat, options, error, erroffset, tables)
773    
774    #define PCRE_CONFIG G(G(pcre,BITONE),_config)
775    
776    #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
777        namesptr, cbuffer, size) \
778      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
779        G(PCRE_COPY_NAMED_SUBSTRING,BITONE)(rc, re, bptr, offsets, count, \
780          namesptr, cbuffer, size); \
781      else \
782        G(PCRE_COPY_NAMED_SUBSTRING,BITTWO)(rc, re, bptr, offsets, count, \
783          namesptr, cbuffer, size)
784    
785    #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \
786      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
787        G(PCRE_COPY_SUBSTRING,BITONE)(rc, bptr, offsets, count, i, cbuffer, size); \
788      else \
789        G(PCRE_COPY_SUBSTRING,BITTWO)(rc, bptr, offsets, count, i, cbuffer, size)
790    
791    #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \
792        offsets, size_offsets, workspace, size_workspace) \
793      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
794        G(PCRE_DFA_EXEC,BITONE)(count, re, extra, bptr, len, start_offset, options, \
795          offsets, size_offsets, workspace, size_workspace); \
796      else \
797        G(PCRE_DFA_EXEC,BITTWO)(count, re, extra, bptr, len, start_offset, options, \
798          offsets, size_offsets, workspace, size_workspace)
799    
800    #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
801        offsets, size_offsets) \
802      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
803        G(PCRE_EXEC,BITONE)(count, re, extra, bptr, len, start_offset, options, \
804          offsets, size_offsets); \
805      else \
806        G(PCRE_EXEC,BITTWO)(count, re, extra, bptr, len, start_offset, options, \
807          offsets, size_offsets)
808    
809    #define PCRE_FREE_STUDY(extra) \
810      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
811        G(PCRE_FREE_STUDY,BITONE)(extra); \
812      else \
813        G(PCRE_FREE_STUDY,BITTWO)(extra)
814    
815    #define PCRE_FREE_SUBSTRING(substring) \
816      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
817        G(PCRE_FREE_SUBSTRING,BITONE)(substring); \
818      else \
819        G(PCRE_FREE_SUBSTRING,BITTWO)(substring)
820    
821    #define PCRE_FREE_SUBSTRING_LIST(listptr) \
822      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
823        G(PCRE_FREE_SUBSTRING_LIST,BITONE)(listptr); \
824      else \
825        G(PCRE_FREE_SUBSTRING_LIST,BITTWO)(listptr)
826    
827    #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
828        getnamesptr, subsptr) \
829      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
830        G(PCRE_GET_NAMED_SUBSTRING,BITONE)(rc, re, bptr, offsets, count, \
831          getnamesptr, subsptr); \
832      else \
833        G(PCRE_GET_NAMED_SUBSTRING,BITTWO)(rc, re, bptr, offsets, count, \
834          getnamesptr, subsptr)
835    
836    #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \
837      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
838        G(PCRE_GET_STRINGNUMBER,BITONE)(n, rc, ptr); \
839      else \
840        G(PCRE_GET_STRINGNUMBER,BITTWO)(n, rc, ptr)
841    
842    #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \
843      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
844        G(PCRE_GET_SUBSTRING,BITONE)(rc, bptr, use_offsets, count, i, subsptr); \
845      else \
846        G(PCRE_GET_SUBSTRING,BITTWO)(rc, bptr, use_offsets, count, i, subsptr)
847    
848    #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \
849      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
850        G(PCRE_GET_SUBSTRING_LIST,BITONE)(rc, bptr, offsets, count, listptr); \
851      else \
852        G(PCRE_GET_SUBSTRING_LIST,BITTWO)(rc, bptr, offsets, count, listptr)
853    
854    #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
855      (pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
856         G(PCRE_JIT_STACK_ALLOC,BITONE)(startsize, maxsize) \
857        : G(PCRE_JIT_STACK_ALLOC,BITTWO)(startsize, maxsize)
858    
859    #define PCRE_JIT_STACK_FREE(stack) \
860      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
861        G(PCRE_JIT_STACK_FREE,BITONE)(stack); \
862      else \
863        G(PCRE_JIT_STACK_FREE,BITTWO)(stack)
864    
865    #define PCRE_MAKETABLES \
866      (pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
867        G(G(pcre,BITONE),_maketables)() : G(G(pcre,BITTWO),_maketables)()
868    
869    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \
870      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
871        G(PCRE_PATTERN_TO_HOST_BYTE_ORDER,BITONE)(rc, re, extra, tables); \
872      else \
873        G(PCRE_PATTERN_TO_HOST_BYTE_ORDER,BITTWO)(rc, re, extra, tables)
874    
875    #define PCRE_PRINTINT(re, outfile, debug_lengths) \
876      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
877        G(PCRE_PRINTINT,BITONE)(re, outfile, debug_lengths); \
878      else \
879        G(PCRE_PRINTINT,BITTWO)(re, outfile, debug_lengths)
880    
881    #define PCRE_STUDY(extra, re, options, error) \
882      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
883        G(PCRE_STUDY,BITONE)(extra, re, options, error); \
884      else \
885        G(PCRE_STUDY,BITTWO)(extra, re, options, error)
886    
887    #endif  /* Two out of three modes */
888    
889    /* ----- End of cases where more than one mode is supported ----- */
890    
891    
892  /* ----- Only 8-bit mode is supported ----- */  /* ----- Only 8-bit mode is supported ----- */
893    
894  #elif defined SUPPORT_PCRE8  #elif defined SUPPORT_PCRE8
# Line 573  version is called. ----- */ Line 921  version is called. ----- */
921    
922  /* ----- Only 16-bit mode is supported ----- */  /* ----- Only 16-bit mode is supported ----- */
923    
924  #else  #elif defined SUPPORT_PCRE16
925  #define CHAR_SIZE                 2  #define CHAR_SIZE                 2
926  #define PCHARS                    PCHARS16  #define PCHARS                    PCHARS16
927  #define PCHARSV                   PCHARSV16  #define PCHARSV                   PCHARSV16
# Line 600  version is called. ----- */ Line 948  version is called. ----- */
948  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER16  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER16
949  #define PCRE_PRINTINT             PCRE_PRINTINT16  #define PCRE_PRINTINT             PCRE_PRINTINT16
950  #define PCRE_STUDY                PCRE_STUDY16  #define PCRE_STUDY                PCRE_STUDY16
951    
952    /* ----- Only 32-bit mode is supported ----- */
953    
954    #elif defined SUPPORT_PCRE32
955    #define CHAR_SIZE                 4
956    #define PCHARS                    PCHARS32
957    #define PCHARSV                   PCHARSV32
958    #define READ_CAPTURE_NAME         READ_CAPTURE_NAME32
959    #define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT32
960    #define STRLEN                    STRLEN32
961    #define PCRE_ASSIGN_JIT_STACK     PCRE_ASSIGN_JIT_STACK32
962    #define PCRE_COMPILE              PCRE_COMPILE32
963    #define PCRE_CONFIG               pcre32_config
964    #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING32
965    #define PCRE_COPY_SUBSTRING       PCRE_COPY_SUBSTRING32
966    #define PCRE_DFA_EXEC             PCRE_DFA_EXEC32
967    #define PCRE_EXEC                 PCRE_EXEC32
968    #define PCRE_FREE_STUDY           PCRE_FREE_STUDY32
969    #define PCRE_FREE_SUBSTRING       PCRE_FREE_SUBSTRING32
970    #define PCRE_FREE_SUBSTRING_LIST  PCRE_FREE_SUBSTRING_LIST32
971    #define PCRE_GET_NAMED_SUBSTRING  PCRE_GET_NAMED_SUBSTRING32
972    #define PCRE_GET_STRINGNUMBER     PCRE_GET_STRINGNUMBER32
973    #define PCRE_GET_SUBSTRING        PCRE_GET_SUBSTRING32
974    #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST32
975    #define PCRE_JIT_STACK_ALLOC      PCRE_JIT_STACK_ALLOC32
976    #define PCRE_JIT_STACK_FREE       PCRE_JIT_STACK_FREE32
977    #define PCRE_MAKETABLES           pcre32_maketables()
978    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER32
979    #define PCRE_PRINTINT             PCRE_PRINTINT32
980    #define PCRE_STUDY                PCRE_STUDY32
981    
982  #endif  #endif
983    
984  /* ----- End of mode-specific function call macros ----- */  /* ----- End of mode-specific function call macros ----- */
# Line 645  static const unsigned char *last_callout Line 1024  static const unsigned char *last_callout
1024    
1025  static int buffer_size = 50000;  static int buffer_size = 50000;
1026  static pcre_uint8 *buffer = NULL;  static pcre_uint8 *buffer = NULL;
 static pcre_uint8 *dbuffer = NULL;  
1027  static pcre_uint8 *pbuffer = NULL;  static pcre_uint8 *pbuffer = NULL;
1028    
1029  /* Another buffer is needed translation to 16-bit character strings. It will  /* Just as a safety check, make sure that COMPILE_PCRE[16|32] are *not* set. */
 obtained and extended as required. */  
   
 #ifdef SUPPORT_PCRE16  
 static int buffer16_size = 0;  
 static pcre_uint16 *buffer16 = NULL;  
   
 #ifdef SUPPORT_PCRE8  
   
 /* We need the table of operator lengths that is used for 16-bit compiling, in  
 order to swap bytes in a pattern for saving/reloading testing. Luckily, the  
 data is defined as a macro. However, we must ensure that LINK_SIZE is adjusted  
 appropriately for the 16-bit world. Just as a safety check, make sure that  
 COMPILE_PCRE16 is *not* set. */  
1030    
1031  #ifdef COMPILE_PCRE16  #ifdef COMPILE_PCRE16
1032  #error COMPILE_PCRE16 must not be set when compiling pcretest.c  #error COMPILE_PCRE16 must not be set when compiling pcretest.c
1033  #endif  #endif
1034    
1035    #ifdef COMPILE_PCRE32
1036    #error COMPILE_PCRE32 must not be set when compiling pcretest.c
1037    #endif
1038    
1039    /* We need buffers for building 16/32-bit strings, and the tables of operator
1040    lengths that are used for 16/32-bit compiling, in order to swap bytes in a
1041    pattern for saving/reloading testing. Luckily, the data for these tables is
1042    defined as a macro. However, we must ensure that LINK_SIZE and IMM2_SIZE (which
1043    are used in the tables) are adjusted appropriately for the 16/32-bit world.
1044    LINK_SIZE is also used later in this program. */
1045    
1046    #ifdef SUPPORT_PCRE16
1047    #undef IMM2_SIZE
1048    #define IMM2_SIZE 1
1049    
1050  #if LINK_SIZE == 2  #if LINK_SIZE == 2
1051  #undef LINK_SIZE  #undef LINK_SIZE
1052  #define LINK_SIZE 1  #define LINK_SIZE 1
# Line 677  COMPILE_PCRE16 is *not* set. */ Line 1057  COMPILE_PCRE16 is *not* set. */
1057  #error LINK_SIZE must be either 2, 3, or 4  #error LINK_SIZE must be either 2, 3, or 4
1058  #endif  #endif
1059    
1060  #undef IMM2_SIZE  static int buffer16_size = 0;
1061  #define IMM2_SIZE 1  static pcre_uint16 *buffer16 = NULL;
   
 #endif /* SUPPORT_PCRE8 */  
   
1062  static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };  static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };
1063  #endif  /* SUPPORT_PCRE16 */  #endif  /* SUPPORT_PCRE16 */
1064    
1065  /* If we have 8-bit support, default use_pcre16 to false; if there is also  #ifdef SUPPORT_PCRE32
1066  16-bit support, it can be changed by an option. If there is no 8-bit support,  #undef IMM2_SIZE
1067  there must be 16-bit support, so default it to 1. */  #define IMM2_SIZE 1
1068    #undef LINK_SIZE
1069    #define LINK_SIZE 1
1070    
1071    static int buffer32_size = 0;
1072    static pcre_uint32 *buffer32 = NULL;
1073    static const pcre_uint32 OP_lengths32[] = { OP_LENGTHS };
1074    #endif  /* SUPPORT_PCRE32 */
1075    
1076    /* If we have 8-bit support, default to it; if there is also 16-or 32-bit
1077    support, it can be changed by an option. If there is no 8-bit support, there
1078    must be 16-or 32-bit support, so default it to 1. */
1079    
1080  #ifdef SUPPORT_PCRE8  #if defined SUPPORT_PCRE8
1081  static int use_pcre16 = 0;  static int pcre_mode = PCRE8_MODE;
1082  #else  #elif defined SUPPORT_PCRE16
1083  static int use_pcre16 = 1;  static int pcre_mode = PCRE16_MODE;
1084    #elif defined SUPPORT_PCRE32
1085    static int pcre_mode = PCRE32_MODE;
1086  #endif  #endif
1087    
1088  /* JIT study options for -s+n and /S+n where '1' <= n <= '7'. */  /* JIT study options for -s+n and /S+n where '1' <= n <= '7'. */
# Line 745  static const char *errtexts[] = { Line 1135  static const char *errtexts[] = {
1135    "JIT stack limit reached",    "JIT stack limit reached",
1136    "pattern compiled in wrong mode: 8-bit/16-bit error",    "pattern compiled in wrong mode: 8-bit/16-bit error",
1137    "pattern compiled with other endianness",    "pattern compiled with other endianness",
1138    "invalid data in workspace for DFA restart"    "invalid data in workspace for DFA restart",
1139      "bad JIT option",
1140      "bad length"
1141  };  };
1142    
1143    
# Line 1102  return sys_errlist[n]; Line 1494  return sys_errlist[n];
1494  *       Print newline configuration              *  *       Print newline configuration              *
1495  *************************************************/  *************************************************/
1496    
1497  /*  /*
1498  Argument: the return code from PCRE_CONFIG_NEWLINE  Arguments:
1499  Returns:  nothing    rc         the return code from PCRE_CONFIG_NEWLINE
1500      isc        TRUE if called from "-C newline"
1501    Returns:     nothing
1502  */  */
1503    
1504  static void  static void
1505  print_newline_config(int rc)  print_newline_config(int rc, BOOL isc)
1506  {  {
1507  const char *s = NULL;  const char *s = NULL;
1508  printf("  Newline sequence is ");  if (!isc) printf("  Newline sequence is ");
1509  switch(rc)  switch(rc)
1510    {    {
1511    case CHAR_CR: s = "CR"; break;    case CHAR_CR: s = "CR"; break;
# Line 1119  switch(rc) Line 1513  switch(rc)
1513    case (CHAR_CR<<8 | CHAR_LF): s = "CRLF"; break;    case (CHAR_CR<<8 | CHAR_LF): s = "CRLF"; break;
1514    case -1: s = "ANY"; break;    case -1: s = "ANY"; break;
1515    case -2: s = "ANYCRLF"; break;    case -2: s = "ANYCRLF"; break;
1516    
1517    default:    default:
1518    printf("a non-standard value: 0x%04x\n", rc);    printf("a non-standard value: 0x%04x\n", rc);
1519    return;    return;
1520    }    }
1521    
1522  printf("%s\n", s);  printf("%s\n", s);
1523  }  }
# Line 1141  return (pcre_jit_stack *)arg; Line 1535  return (pcre_jit_stack *)arg;
1535  }  }
1536    
1537    
1538  #if !defined NOUTF || defined SUPPORT_PCRE16  #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32
1539  /*************************************************  /*************************************************
1540  *            Convert UTF-8 string to value       *  *            Convert UTF-8 string to value       *
1541  *************************************************/  *************************************************/
# Line 1158  Returns:      >  0 => the number of byte Line 1552  Returns:      >  0 => the number of byte
1552  */  */
1553    
1554  static int  static int
1555  utf82ord(pcre_uint8 *utf8bytes, int *vptr)  utf82ord(pcre_uint8 *utf8bytes, pcre_uint32 *vptr)
1556  {  {
1557  int c = *utf8bytes++;  pcre_uint32 c = *utf8bytes++;
1558  int d = c;  pcre_uint32 d = c;
1559  int i, j, s;  int i, j, s;
1560    
1561  for (i = -1; i < 6; i++)               /* i is number of additional bytes */  for (i = -1; i < 6; i++)               /* i is number of additional bytes */
# Line 1189  for (j = 0; j < i; j++) Line 1583  for (j = 0; j < i; j++)
1583  /* Check that encoding was the correct unique one */  /* Check that encoding was the correct unique one */
1584    
1585  for (j = 0; j < utf8_table1_size; j++)  for (j = 0; j < utf8_table1_size; j++)
1586    if (d <= utf8_table1[j]) break;    if (d <= (pcre_uint32)utf8_table1[j]) break;
1587  if (j != i) return -(i+1);  if (j != i) return -(i+1);
1588    
1589  /* Valid value */  /* Valid value */
# Line 1201  return i+1; Line 1595  return i+1;
1595    
1596    
1597    
1598  #if !defined NOUTF || defined SUPPORT_PCRE16  #if defined SUPPORT_PCRE8 && !defined NOUTF
1599  /*************************************************  /*************************************************
1600  *       Convert character value to UTF-8         *  *       Convert character value to UTF-8         *
1601  *************************************************/  *************************************************/
# Line 1217  Returns:     number of characters placed Line 1611  Returns:     number of characters placed
1611  */  */
1612    
1613  static int  static int
1614  ord2utf8(int cvalue, pcre_uint8 *utf8bytes)  ord2utf8(pcre_uint32 cvalue, pcre_uint8 *utf8bytes)
1615  {  {
1616  register int i, j;  register int i, j;
1617    if (cvalue > 0x7fffffffu)
1618      return -1;
1619  for (i = 0; i < utf8_table1_size; i++)  for (i = 0; i < utf8_table1_size; i++)
1620    if (cvalue <= utf8_table1[i]) break;    if (cvalue <= (pcre_uint32)utf8_table1[i]) break;
1621  utf8bytes += i;  utf8bytes += i;
1622  for (j = i; j > 0; j--)  for (j = i; j > 0; j--)
1623   {   {
# Line 1290  if (!utf && !data) Line 1686  if (!utf && !data)
1686    
1687  else  else
1688    {    {
1689    int c = 0;    pcre_uint32 c = 0;
1690    while (len > 0)    while (len > 0)
1691      {      {
1692      int chlen = utf82ord(p, &c);      int chlen = utf82ord(p, &c);
# Line 1313  return pp - buffer16; Line 1709  return pp - buffer16;
1709  }  }
1710  #endif  #endif
1711    
1712    #ifdef SUPPORT_PCRE32
1713    /*************************************************
1714    *         Convert a string to 32-bit             *
1715    *************************************************/
1716    
1717    /* In non-UTF mode, the space needed for a 32-bit string is exactly four times the
1718    8-bit size. For a UTF-8 string, the size needed for UTF-32 is no more than four
1719    times, because up to 0xffff uses no more than 3 bytes in UTF-8 but possibly 4
1720    in UTF-32. Higher values use 4 bytes in UTF-8 and up to 4 bytes in UTF-32. The
1721    result is always left in buffer32.
1722    
1723    Note that this function does not object to surrogate values. This is
1724    deliberate; it makes it possible to construct UTF-32 strings that are invalid,
1725    for the purpose of testing that they are correctly faulted.
1726    
1727    Patterns to be converted are either plain ASCII or UTF-8; data lines are always
1728    in UTF-8 so that values greater than 255 can be handled.
1729    
1730    Arguments:
1731      data       TRUE if converting a data line; FALSE for a regex
1732      p          points to a byte string
1733      utf        true if UTF-8 (to be converted to UTF-32)
1734      len        number of bytes in the string (excluding trailing zero)
1735    
1736    Returns:     number of 32-bit data items used (excluding trailing zero)
1737                 OR -1 if a UTF-8 string is malformed
1738                 OR -2 if a value > 0x10ffff is encountered
1739                 OR -3 if an ill-formed value is encountered (i.e. a surrogate)
1740    */
1741    
1742    static int
1743    to32(int data, pcre_uint8 *p, int utf, int len)
1744    {
1745    pcre_uint32 *pp;
1746    
1747    if (buffer32_size < 4*len + 4)
1748      {
1749      if (buffer32 != NULL) free(buffer32);
1750      buffer32_size = 4*len + 4;
1751      buffer32 = (pcre_uint32 *)malloc(buffer32_size);
1752      if (buffer32 == NULL)
1753        {
1754        fprintf(stderr, "pcretest: malloc(%d) failed for buffer32\n", buffer32_size);
1755        exit(1);
1756        }
1757      }
1758    
1759    pp = buffer32;
1760    
1761    if (!utf && !data)
1762      {
1763      while (len-- > 0) *pp++ = *p++;
1764      }
1765    
1766    else
1767      {
1768      pcre_uint32 c = 0;
1769      while (len > 0)
1770        {
1771        int chlen = utf82ord(p, &c);
1772        if (chlen <= 0) return -1;
1773        if (utf)
1774          {
1775          if (c > 0x10ffff) return -2;
1776          if (!data && (c & 0xfffff800u) == 0xd800u) return -3;
1777          }
1778    
1779        p += chlen;
1780        len -= chlen;
1781        *pp++ = c;
1782        }
1783      }
1784    
1785    *pp = 0;
1786    return pp - buffer32;
1787    }
1788    
1789    /* Check that a 32-bit character string is valid UTF-32.
1790    
1791    Arguments:
1792      string       points to the string
1793      length       length of string, or -1 if the string is zero-terminated
1794    
1795    Returns:       TRUE  if the string is a valid UTF-32 string
1796                   FALSE otherwise
1797    */
1798    
1799    #ifdef NEVER   /* Not used */
1800    #ifdef SUPPORT_UTF
1801    static BOOL
1802    valid_utf32(pcre_uint32 *string, int length)
1803    {
1804    register pcre_uint32 *p;
1805    register pcre_uint32 c;
1806    
1807    for (p = string; length-- > 0; p++)
1808      {
1809      c = *p;
1810      if (c > 0x10ffffu) return FALSE;                 /* Too big */
1811      if ((c & 0xfffff800u) == 0xd800u) return FALSE;  /* Surrogate */
1812      }
1813    
1814    return TRUE;
1815    }
1816    #endif /* SUPPORT_UTF */
1817    #endif /* NEVER */
1818    #endif /* SUPPORT_PCRE32 */
1819    
1820    
1821  /*************************************************  /*************************************************
1822  *        Read or extend an input line            *  *        Read or extend an input line            *
# Line 1388  for (;;) Line 1892  for (;;)
1892      {      {
1893      int new_buffer_size = 2*buffer_size;      int new_buffer_size = 2*buffer_size;
1894      pcre_uint8 *new_buffer = (pcre_uint8 *)malloc(new_buffer_size);      pcre_uint8 *new_buffer = (pcre_uint8 *)malloc(new_buffer_size);
     pcre_uint8 *new_dbuffer = (pcre_uint8 *)malloc(new_buffer_size);  
1895      pcre_uint8 *new_pbuffer = (pcre_uint8 *)malloc(new_buffer_size);      pcre_uint8 *new_pbuffer = (pcre_uint8 *)malloc(new_buffer_size);
1896    
1897      if (new_buffer == NULL || new_dbuffer == NULL || new_pbuffer == NULL)      if (new_buffer == NULL || new_pbuffer == NULL)
1898        {        {
1899        fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);        fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);
1900        exit(1);        exit(1);
# Line 1406  for (;;) Line 1909  for (;;)
1909      here = new_buffer + (here - buffer);      here = new_buffer + (here - buffer);
1910    
1911      free(buffer);      free(buffer);
     free(dbuffer);  
1912      free(pbuffer);      free(pbuffer);
1913    
1914      buffer = new_buffer;      buffer = new_buffer;
     dbuffer = new_dbuffer;  
1915      pbuffer = new_pbuffer;      pbuffer = new_pbuffer;
1916      }      }
1917    }    }
# Line 1453  return(result); Line 1954  return(result);
1954    
1955  /* Print a single character either literally, or as a hex escape. */  /* Print a single character either literally, or as a hex escape. */
1956    
1957  static int pchar(int c, FILE *f)  static int pchar(pcre_uint32 c, FILE *f)
1958  {  {
1959    int n = 0;
1960  if (PRINTOK(c))  if (PRINTOK(c))
1961    {    {
1962    if (f != NULL) fprintf(f, "%c", c);    if (f != NULL) fprintf(f, "%c", c);
# Line 1475  if (c < 0x100) Line 1977  if (c < 0x100)
1977      }      }
1978    }    }
1979    
1980  if (f != NULL) fprintf(f, "\\x{%02x}", c);  if (f != NULL) n = fprintf(f, "\\x{%02x}", c);
1981  return (c <= 0x000000ff)? 6 :  return n >= 0 ? n : 0;
        (c <= 0x00000fff)? 7 :  
        (c <= 0x0000ffff)? 8 :  
        (c <= 0x000fffff)? 9 : 10;  
1982  }  }
1983    
1984    
# Line 1494  If handed a NULL file, just counts chars Line 1993  If handed a NULL file, just counts chars
1993    
1994  static int pchars(pcre_uint8 *p, int length, FILE *f)  static int pchars(pcre_uint8 *p, int length, FILE *f)
1995  {  {
1996  int c = 0;  pcre_uint32 c = 0;
1997  int yield = 0;  int yield = 0;
1998    
1999  if (length < 0)  if (length < 0)
# Line 1539  return len; Line 2038  return len;
2038  #endif  /* SUPPORT_PCRE16 */  #endif  /* SUPPORT_PCRE16 */
2039    
2040    
2041    
2042    #ifdef SUPPORT_PCRE32
2043    /*************************************************
2044    *    Find length of 0-terminated 32-bit string   *
2045    *************************************************/
2046    
2047    static int strlen32(PCRE_SPTR32 p)
2048    {
2049    int len = 0;
2050    while (*p++ != 0) len++;
2051    return len;
2052    }
2053    #endif  /* SUPPORT_PCRE32 */
2054    
2055    
2056    
2057  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2058  /*************************************************  /*************************************************
2059  *           Print 16-bit character string        *  *           Print 16-bit character string        *
# Line 1556  if (length < 0) Line 2071  if (length < 0)
2071    
2072  while (length-- > 0)  while (length-- > 0)
2073    {    {
2074    int c = *p++ & 0xffff;    pcre_uint32 c = *p++ & 0xffff;
2075  #if !defined NOUTF  #if !defined NOUTF
2076    if (use_utf && c >= 0xD800 && c < 0xDC00 && length > 0)    if (use_utf && c >= 0xD800 && c < 0xDC00 && length > 0)
2077      {      {
2078      int d = *p & 0xffff;      int d = *p & 0xffff;
2079      if (d >= 0xDC00 && d < 0xDFFF)      if (d >= 0xDC00 && d <= 0xDFFF)
2080        {        {
2081        c = ((c & 0x3ff) << 10) + (d & 0x3ff) + 0x10000;        c = ((c & 0x3ff) << 10) + (d & 0x3ff) + 0x10000;
2082        length--;        length--;
# Line 1578  return yield; Line 2093  return yield;
2093    
2094    
2095    
2096    #ifdef SUPPORT_PCRE32
2097    /*************************************************
2098    *           Print 32-bit character string        *
2099    *************************************************/
2100    
2101    /* Must handle UTF-32 strings in utf mode. Yields number of characters printed.
2102    If handed a NULL file, just counts chars without printing. */
2103    
2104    static int pchars32(PCRE_SPTR32 p, int length, BOOL utf, FILE *f)
2105    {
2106    int yield = 0;
2107    
2108    (void)(utf);  /* Avoid compiler warning */
2109    
2110    if (length < 0)
2111      length = strlen32(p);
2112    
2113    while (length-- > 0)
2114      {
2115      pcre_uint32 c = *p++;
2116      yield += pchar(c, f);
2117      }
2118    
2119    return yield;
2120    }
2121    #endif  /* SUPPORT_PCRE32 */
2122    
2123    
2124    
2125  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
2126  /*************************************************  /*************************************************
2127  *     Read a capture name (8-bit) and check it   *  *     Read a capture name (8-bit) and check it   *
# Line 1631  return p; Line 2175  return p;
2175    
2176    
2177    
2178    #ifdef SUPPORT_PCRE32
2179    /*************************************************
2180    *     Read a capture name (32-bit) and check it  *
2181    *************************************************/
2182    
2183    /* Note that the text being read is 8-bit. */
2184    
2185    static pcre_uint8 *
2186    read_capture_name32(pcre_uint8 *p, pcre_uint32 **pp, pcre *re)
2187    {
2188    pcre_uint32 *npp = *pp;
2189    while (isalnum(*p)) *npp++ = *p++;
2190    *npp++ = 0;
2191    *npp = 0;
2192    if (pcre32_get_stringnumber((pcre32 *)re, (PCRE_SPTR32)(*pp)) < 0)
2193      {
2194      fprintf(outfile, "no parentheses with name \"");
2195      PCHARSV(*pp, 0, -1, outfile);
2196      fprintf(outfile, "\"\n");
2197      }
2198    *pp = npp;
2199    return p;
2200    }
2201    #endif  /* SUPPORT_PCRE32 */
2202    
2203    
2204    
2205  /*************************************************  /*************************************************
2206  *              Callout function                  *  *              Callout function                  *
2207  *************************************************/  *************************************************/
# Line 1788  free(block); Line 2359  free(block);
2359  *************************************************/  *************************************************/
2360    
2361  /* Get one piece of information from the pcre_fullinfo() function. When only  /* Get one piece of information from the pcre_fullinfo() function. When only
2362  one of 8-bit or 16-bit is supported, use_pcre16 should always have the correct  one of 8-, 16- or 32-bit is supported, pcre_mode should always have the correct
2363  value, but the code is defensive.  value, but the code is defensive.
2364    
2365  Arguments:  Arguments:
# Line 1805  new_info(pcre *re, pcre_extra *study, in Line 2376  new_info(pcre *re, pcre_extra *study, in
2376  {  {
2377  int rc;  int rc;
2378    
2379  if (use_pcre16)  if (pcre_mode == PCRE32_MODE)
2380    #ifdef SUPPORT_PCRE32
2381      rc = pcre32_fullinfo((pcre32 *)re, (pcre32_extra *)study, option, ptr);
2382    #else
2383      rc = PCRE_ERROR_BADMODE;
2384    #endif
2385    else if (pcre_mode == PCRE16_MODE)
2386  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2387    rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);    rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);
2388  #else  #else
# Line 1818  else Line 2395  else
2395    rc = PCRE_ERROR_BADMODE;    rc = PCRE_ERROR_BADMODE;
2396  #endif  #endif
2397    
2398  if (rc < 0)  if (rc < 0 && rc != PCRE_ERROR_UNSET)
2399    {    {
2400    fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,    fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
2401      use_pcre16? "16" : "", option);      pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "", option);
2402    if (rc == PCRE_ERROR_BADMODE)    if (rc == PCRE_ERROR_BADMODE)
2403      fprintf(outfile, "Running in %s-bit mode but pattern was compiled in "      fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
2404        "%s-bit mode\n", use_pcre16? "16":"8", use_pcre16? "8":"16");        "%d-bit mode\n", 8 * CHAR_SIZE,
2405          8 * (REAL_PCRE_FLAGS(re) & PCRE_MODE_MASK));
2406    }    }
2407    
2408  return rc;  return rc;
# Line 1873  bytes in the pattern itself. This is to Line 2451  bytes in the pattern itself. This is to
2451  ability to reload byte-flipped patterns, e.g. those compiled on a different  ability to reload byte-flipped patterns, e.g. those compiled on a different
2452  architecture. */  architecture. */
2453    
2454    #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
2455  static void  static void
2456  regexflip(pcre *ere, pcre_extra *extra)  regexflip8_or_16(pcre *ere, pcre_extra *extra)
2457  {  {
2458  REAL_PCRE *re = (REAL_PCRE *)ere;  real_pcre8_or_16 *re = (real_pcre8_or_16 *)ere;
2459  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2460  int op;  int op;
2461  pcre_uint16 *ptr = (pcre_uint16 *)re + re->name_table_offset;  pcre_uint16 *ptr = (pcre_uint16 *)re + re->name_table_offset;
# Line 1892  BOOL utf16_char = FALSE; Line 2471  BOOL utf16_char = FALSE;
2471  re->magic_number = REVERSED_MAGIC_NUMBER;  re->magic_number = REVERSED_MAGIC_NUMBER;
2472  re->size = swap_uint32(re->size);  re->size = swap_uint32(re->size);
2473  re->options = swap_uint32(re->options);  re->options = swap_uint32(re->options);
2474  re->flags = swap_uint16(re->flags);  re->flags = swap_uint32(re->flags);
2475  re->top_bracket = swap_uint16(re->top_bracket);  re->limit_match = swap_uint32(re->limit_match);
2476  re->top_backref = swap_uint16(re->top_backref);  re->limit_recursion = swap_uint32(re->limit_recursion);
2477  re->first_char = swap_uint16(re->first_char);  re->first_char = swap_uint16(re->first_char);
2478  re->req_char = swap_uint16(re->req_char);  re->req_char = swap_uint16(re->req_char);
2479    re->max_lookbehind = swap_uint16(re->max_lookbehind);
2480    re->top_bracket = swap_uint16(re->top_bracket);
2481    re->top_backref = swap_uint16(re->top_backref);
2482  re->name_table_offset = swap_uint16(re->name_table_offset);  re->name_table_offset = swap_uint16(re->name_table_offset);
2483  re->name_entry_size = swap_uint16(re->name_entry_size);  re->name_entry_size = swap_uint16(re->name_entry_size);
2484  re->name_count = swap_uint16(re->name_count);  re->name_count = swap_uint16(re->name_count);
2485    re->ref_count = swap_uint16(re->ref_count);
2486    
2487  if (extra != NULL)  if (extra != NULL)
2488    {    {
# Line 1913  if (extra != NULL) Line 2496  if (extra != NULL)
2496  in the name table, if present, and then in the pattern itself. */  in the name table, if present, and then in the pattern itself. */
2497    
2498  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2499  if (!use_pcre16) return;  if (pcre_mode != PCRE16_MODE) return;
2500    
2501  while(TRUE)  while(TRUE)
2502    {    {
# Line 2051  while(TRUE) Line 2634  while(TRUE)
2634  /* Control should never reach here in 16 bit mode. */  /* Control should never reach here in 16 bit mode. */
2635  #endif /* SUPPORT_PCRE16 */  #endif /* SUPPORT_PCRE16 */
2636  }  }
2637    #endif /* SUPPORT_PCRE[8|16] */
2638    
2639    
2640    
2641    #if defined SUPPORT_PCRE32
2642    static void
2643    regexflip_32(pcre *ere, pcre_extra *extra)
2644    {
2645    real_pcre32 *re = (real_pcre32 *)ere;
2646    int op;
2647    pcre_uint32 *ptr = (pcre_uint32 *)re + re->name_table_offset;
2648    int length = re->name_count * re->name_entry_size;
2649    
2650    /* Always flip the bytes in the main data block and study blocks. */
2651    
2652    re->magic_number = REVERSED_MAGIC_NUMBER;
2653    re->size = swap_uint32(re->size);
2654    re->options = swap_uint32(re->options);
2655    re->flags = swap_uint32(re->flags);
2656    re->limit_match = swap_uint32(re->limit_match);
2657    re->limit_recursion = swap_uint32(re->limit_recursion);
2658    re->first_char = swap_uint32(re->first_char);
2659    re->req_char = swap_uint32(re->req_char);
2660    re->max_lookbehind = swap_uint16(re->max_lookbehind);
2661    re->top_bracket = swap_uint16(re->top_bracket);
2662    re->top_backref = swap_uint16(re->top_backref);
2663    re->name_table_offset = swap_uint16(re->name_table_offset);
2664    re->name_entry_size = swap_uint16(re->name_entry_size);
2665    re->name_count = swap_uint16(re->name_count);
2666    re->ref_count = swap_uint16(re->ref_count);
2667    
2668    if (extra != NULL)
2669      {
2670      pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
2671      rsd->size = swap_uint32(rsd->size);
2672      rsd->flags = swap_uint32(rsd->flags);
2673      rsd->minlength = swap_uint32(rsd->minlength);
2674      }
2675    
2676    /* In 32-bit mode we must swap bytes in the name table, if present, and then in
2677    the pattern itself. */
2678    
2679    while(TRUE)
2680      {
2681      /* Swap previous characters. */
2682      while (length-- > 0)
2683        {
2684        *ptr = swap_uint32(*ptr);
2685        ptr++;
2686        }
2687    
2688      /* Get next opcode. */
2689    
2690      length = 0;
2691      op = *ptr;
2692      *ptr++ = swap_uint32(op);
2693    
2694      switch (op)
2695        {
2696        case OP_END:
2697        return;
2698    
2699        default:
2700        length = OP_lengths32[op] - 1;
2701        break;
2702    
2703        case OP_CLASS:
2704        case OP_NCLASS:
2705        /* Skip the character bit map. */
2706        ptr += 32/sizeof(pcre_uint32);
2707        length = 0;
2708        break;
2709    
2710        case OP_XCLASS:
2711        /* LINK_SIZE can only be 1 in 32-bit mode. */
2712        length = (int)((unsigned int)(ptr[0]) - (1 + LINK_SIZE + 1));
2713    
2714        /* Reverse the size of the XCLASS instance. */
2715        *ptr = swap_uint32(*ptr);
2716        ptr++;
2717    
2718        op = *ptr;
2719        *ptr = swap_uint32(op);
2720        ptr++;
2721        if ((op & XCL_MAP) != 0)
2722          {
2723          /* Skip the character bit map. */
2724          ptr += 32/sizeof(pcre_uint32);
2725          length -= 32/sizeof(pcre_uint32);
2726          }
2727        break;
2728        }
2729      }
2730    /* Control should never reach here in 32 bit mode. */
2731    }
2732    
2733    #endif /* SUPPORT_PCRE32 */
2734    
2735    
2736    
2737    static void
2738    regexflip(pcre *ere, pcre_extra *extra)
2739    {
2740    #if defined SUPPORT_PCRE32
2741      if (REAL_PCRE_FLAGS(ere) & PCRE_MODE32)
2742        regexflip_32(ere, extra);
2743    #endif
2744    #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
2745      if (REAL_PCRE_FLAGS(ere) & (PCRE_MODE8 | PCRE_MODE16))
2746        regexflip8_or_16(ere, extra);
2747    #endif
2748    }
2749    
2750    
2751    
# Line 2179  printf("\nOptions:\n"); Line 2874  printf("\nOptions:\n");
2874  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2875  printf("  -16      use the 16-bit library\n");  printf("  -16      use the 16-bit library\n");
2876  #endif  #endif
2877    #ifdef SUPPORT_PCRE32
2878    printf("  -32      use the 32-bit library\n");
2879    #endif
2880  printf("  -b       show compiled code\n");  printf("  -b       show compiled code\n");
2881  printf("  -C       show PCRE compile-time options and exit\n");  printf("  -C       show PCRE compile-time options and exit\n");
2882  printf("  -C arg   show a specific compile-time option\n");  printf("  -C arg   show a specific compile-time option\n");
# Line 2186  printf("           and exit with its val Line 2884  printf("           and exit with its val
2884  printf("     linksize     internal link size [2, 3, 4]\n");  printf("     linksize     internal link size [2, 3, 4]\n");
2885  printf("     pcre8        8 bit library support enabled [0, 1]\n");  printf("     pcre8        8 bit library support enabled [0, 1]\n");
2886  printf("     pcre16       16 bit library support enabled [0, 1]\n");  printf("     pcre16       16 bit library support enabled [0, 1]\n");
2887    printf("     pcre32       32 bit library support enabled [0, 1]\n");
2888  printf("     utf          Unicode Transformation Format supported [0, 1]\n");  printf("     utf          Unicode Transformation Format supported [0, 1]\n");
2889  printf("     ucp          Unicode Properties supported [0, 1]\n");  printf("     ucp          Unicode Properties supported [0, 1]\n");
2890  printf("     jit          Just-in-time compiler supported [0, 1]\n");  printf("     jit          Just-in-time compiler supported [0, 1]\n");
# Line 2250  int all_use_dfa = 0; Line 2949  int all_use_dfa = 0;
2949  int verify_jit = 0;  int verify_jit = 0;
2950  int yield = 0;  int yield = 0;
2951  int stack_size;  int stack_size;
2952    pcre_uint8 *dbuffer = NULL;
2953    size_t dbuffer_size = 1u << 14;
2954    
2955  #if !defined NOPOSIX  #if !defined NOPOSIX
2956  int posix = 0;  int posix = 0;
# Line 2263  pcre_jit_stack *jit_stack = NULL; Line 2964  pcre_jit_stack *jit_stack = NULL;
2964  /* These vectors store, end-to-end, a list of zero-terminated captured  /* These vectors store, end-to-end, a list of zero-terminated captured
2965  substring names, each list itself being terminated by an empty name. Assume  substring names, each list itself being terminated by an empty name. Assume
2966  that 1024 is plenty long enough for the few names we'll be testing. It is  that 1024 is plenty long enough for the few names we'll be testing. It is
2967  easiest to keep separate 8-bit and 16-bit versions, using the 16-bit version  easiest to keep separate 8-, 16- and 32-bit versions, using the 32-bit version
2968  for the actual memory, to ensure alignment. */  for the actual memory, to ensure alignment. */
2969    
2970  pcre_uint16 copynames[1024];  pcre_uint32 copynames[1024];
2971  pcre_uint16 getnames[1024];  pcre_uint32 getnames[1024];
2972    
2973    #ifdef SUPPORT_PCRE32
2974    pcre_uint32 *cn32ptr;
2975    pcre_uint32 *gn32ptr;
2976    #endif
2977    
2978  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2979    pcre_uint16 *copynames16 = (pcre_uint16 *)copynames;
2980    pcre_uint16 *getnames16 = (pcre_uint16 *)getnames;
2981  pcre_uint16 *cn16ptr;  pcre_uint16 *cn16ptr;
2982  pcre_uint16 *gn16ptr;  pcre_uint16 *gn16ptr;
2983  #endif  #endif
# Line 2282  pcre_uint8 *gn8ptr; Line 2990  pcre_uint8 *gn8ptr;
2990  #endif  #endif
2991    
2992  /* Get buffers from malloc() so that valgrind will check their misuse when  /* Get buffers from malloc() so that valgrind will check their misuse when
2993  debugging. They grow automatically when very long lines are read. The 16-bit  debugging. They grow automatically when very long lines are read. The 16-
2994  buffer (buffer16) is obtained only if needed. */  and 32-bit buffers (buffer16, buffer32) are obtained only if needed. */
2995    
2996  buffer = (pcre_uint8 *)malloc(buffer_size);  buffer = (pcre_uint8 *)malloc(buffer_size);
 dbuffer = (pcre_uint8 *)malloc(buffer_size);  
2997  pbuffer = (pcre_uint8 *)malloc(buffer_size);  pbuffer = (pcre_uint8 *)malloc(buffer_size);
2998    
2999  /* The outfile variable is static so that new_malloc can use it. */  /* The outfile variable is static so that new_malloc can use it. */
# Line 2305  _setmode( _fileno( stdout ), _O_BINARY ) Line 3012  _setmode( _fileno( stdout ), _O_BINARY )
3012  /* Get the version number: both pcre_version() and pcre16_version() give the  /* Get the version number: both pcre_version() and pcre16_version() give the
3013  same answer. We just need to ensure that we call one that is available. */  same answer. We just need to ensure that we call one that is available. */
3014    
3015  #ifdef SUPPORT_PCRE8  #if defined SUPPORT_PCRE8
3016  version = pcre_version();  version = pcre_version();
3017  #else  #elif defined SUPPORT_PCRE16
3018  version = pcre16_version();  version = pcre16_version();
3019    #elif defined SUPPORT_PCRE32
3020    version = pcre32_version();
3021  #endif  #endif
3022    
3023  /* Scan options */  /* Scan options */
# Line 2332  while (argc > 1 && argv[op][0] == '-') Line 3041  while (argc > 1 && argv[op][0] == '-')
3041        force_study_options = jit_study_bits[*arg - '1'];        force_study_options = jit_study_bits[*arg - '1'];
3042      else goto BAD_ARG;      else goto BAD_ARG;
3043      }      }
3044      else if (strcmp(arg, "-8") == 0)
3045        {
3046    #ifdef SUPPORT_PCRE8
3047        pcre_mode = PCRE8_MODE;
3048    #else
3049        printf("** This version of PCRE was built without 8-bit support\n");
3050        exit(1);
3051    #endif
3052        }
3053    else if (strcmp(arg, "-16") == 0)    else if (strcmp(arg, "-16") == 0)
3054      {      {
3055  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3056      use_pcre16 = 1;      pcre_mode = PCRE16_MODE;
3057  #else  #else
3058      printf("** This version of PCRE was built without 16-bit support\n");      printf("** This version of PCRE was built without 16-bit support\n");
3059      exit(1);      exit(1);
3060  #endif  #endif
3061      }      }
3062      else if (strcmp(arg, "-32") == 0)
3063        {
3064    #ifdef SUPPORT_PCRE32
3065        pcre_mode = PCRE32_MODE;
3066    #else
3067        printf("** This version of PCRE was built without 32-bit support\n");
3068        exit(1);
3069    #endif
3070        }
3071    else if (strcmp(arg, "-q") == 0) quiet = 1;    else if (strcmp(arg, "-q") == 0) quiet = 1;
3072    else if (strcmp(arg, "-b") == 0) debug = 1;    else if (strcmp(arg, "-b") == 0) debug = 1;
3073    else if (strcmp(arg, "-i") == 0) showinfo = 1;    else if (strcmp(arg, "-i") == 0) showinfo = 1;
# Line 2374  while (argc > 1 && argv[op][0] == '-') Line 3101  while (argc > 1 && argv[op][0] == '-')
3101        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),
3102          *endptr == 0))          *endptr == 0))
3103      {      {
3104  #if defined(_WIN32) || defined(WIN32) || defined(__minix) || defined(NATIVE_ZOS)  #if defined(_WIN32) || defined(WIN32) || defined(__minix) || defined(NATIVE_ZOS) || defined(__VMS)
3105      printf("PCRE: -S not supported on this OS\n");      printf("PCRE: -S not supported on this OS\n");
3106      exit(1);      exit(1);
3107  #else  #else
# Line 2407  while (argc > 1 && argv[op][0] == '-') Line 3134  while (argc > 1 && argv[op][0] == '-')
3134          (void)PCRE_CONFIG(PCRE_CONFIG_LINK_SIZE, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_LINK_SIZE, &rc);
3135          printf("%d\n", rc);          printf("%d\n", rc);
3136          yield = rc;          yield = rc;
3137          goto EXIT;  
3138    #ifdef __VMS
3139            vms_setsymbol("LINKSIZE",0,yield );
3140    #endif
3141          }          }
3142        if (strcmp(argv[op + 1], "pcre8") == 0)        else if (strcmp(argv[op + 1], "pcre8") == 0)
3143          {          {
3144  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
3145          printf("1\n");          printf("1\n");
# Line 2418  while (argc > 1 && argv[op][0] == '-') Line 3148  while (argc > 1 && argv[op][0] == '-')
3148          printf("0\n");          printf("0\n");
3149          yield = 0;          yield = 0;
3150  #endif  #endif
3151          goto EXIT;  #ifdef __VMS
3152            vms_setsymbol("PCRE8",0,yield );
3153    #endif
3154          }          }
3155        if (strcmp(argv[op + 1], "pcre16") == 0)        else if (strcmp(argv[op + 1], "pcre16") == 0)
3156          {          {
3157  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3158          printf("1\n");          printf("1\n");
# Line 2429  while (argc > 1 && argv[op][0] == '-') Line 3161  while (argc > 1 && argv[op][0] == '-')
3161          printf("0\n");          printf("0\n");
3162          yield = 0;          yield = 0;
3163  #endif  #endif
3164          goto EXIT;  #ifdef __VMS
3165            vms_setsymbol("PCRE16",0,yield );
3166    #endif
3167          }          }
3168        if (strcmp(argv[op + 1], "utf") == 0)        else if (strcmp(argv[op + 1], "pcre32") == 0)
3169          {          {
3170  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE32
3171          (void)pcre_config(PCRE_CONFIG_UTF8, &rc);          printf("1\n");
3172          printf("%d\n", rc);          yield = 1;
         yield = rc;  
3173  #else  #else
3174          (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);          printf("0\n");
3175            yield = 0;
3176    #endif
3177    #ifdef __VMS
3178            vms_setsymbol("PCRE32",0,yield );
3179    #endif
3180            }
3181          else if (strcmp(argv[op + 1], "utf") == 0)
3182            {
3183    #ifdef SUPPORT_PCRE8
3184            if (pcre_mode == PCRE8_MODE)
3185              (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
3186    #endif
3187    #ifdef SUPPORT_PCRE16
3188            if (pcre_mode == PCRE16_MODE)
3189              (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
3190    #endif
3191    #ifdef SUPPORT_PCRE32
3192            if (pcre_mode == PCRE32_MODE)
3193              (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
3194    #endif
3195          printf("%d\n", rc);          printf("%d\n", rc);
3196          yield = rc;          yield = rc;
3197    #ifdef __VMS
3198            vms_setsymbol("UTF",0,yield );
3199  #endif  #endif
         goto EXIT;  
3200          }          }
3201        if (strcmp(argv[op + 1], "ucp") == 0)        else if (strcmp(argv[op + 1], "ucp") == 0)
3202          {          {
3203          (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
3204          printf("%d\n", rc);          printf("%d\n", rc);
3205          yield = rc;          yield = rc;
         goto EXIT;  
3206          }          }
3207        if (strcmp(argv[op + 1], "jit") == 0)        else if (strcmp(argv[op + 1], "jit") == 0)
3208          {          {
3209          (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);
3210          printf("%d\n", rc);          printf("%d\n", rc);
3211          yield = rc;          yield = rc;
         goto EXIT;  
3212          }          }
3213        if (strcmp(argv[op + 1], "newline") == 0)        else if (strcmp(argv[op + 1], "newline") == 0)
3214          {          {
3215          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3216          print_newline_config(rc);          print_newline_config(rc, TRUE);
3217          goto EXIT;          }
3218          else if (strcmp(argv[op + 1], "ebcdic") == 0)
3219            {
3220    #ifdef EBCDIC
3221            printf("1\n");
3222            yield = 1;
3223    #else
3224            printf("0\n");
3225    #endif
3226            }
3227          else if (strcmp(argv[op + 1], "ebcdic-nl") == 0)
3228            {
3229    #ifdef EBCDIC
3230            printf("0x%02x\n", CHAR_LF);
3231    #else
3232            printf("0\n");
3233    #endif
3234            }
3235          else
3236            {
3237            printf("Unknown -C option: %s\n", argv[op + 1]);
3238          }          }
       printf("Unknown -C option: %s\n", argv[op + 1]);  
3239        goto EXIT;        goto EXIT;
3240        }        }
3241    
3242        /* No argument for -C: output all configuration information. */
3243    
3244      printf("PCRE version %s\n", version);      printf("PCRE version %s\n", version);
3245      printf("Compiled with\n");      printf("Compiled with\n");
3246    
3247  #ifdef EBCDIC  #ifdef EBCDIC
3248      printf("  EBCDIC code support: LF is 0x%02x\n", CHAR_LF);      printf("  EBCDIC code support: LF is 0x%02x\n", CHAR_LF);
3249  #endif  #endif
3250    
3251  /* At least one of SUPPORT_PCRE8 and SUPPORT_PCRE16 will be set. If both  /* At least one of SUPPORT_PCRE8 and SUPPORT_PCRE16 will be set. If both
3252  are set, either both UTFs are supported or both are not supported. */  are set, either both UTFs are supported or both are not supported. */
3253    
3254  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE8
3255      printf("  8-bit and 16-bit support\n");      printf("  8-bit support\n");
     (void)pcre_config(PCRE_CONFIG_UTF8, &rc);  
     if (rc)  
       printf("  UTF-8 and UTF-16 support\n");  
     else  
       printf("  No UTF-8 or UTF-16 support\n");  
 #elif defined SUPPORT_PCRE8  
     printf("  8-bit support only\n");  
3256      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
3257      printf("  %sUTF-8 support\n", rc? "" : "No ");        printf ("  %sUTF-8 support\n", rc ? "" : "No ");
3258  #else  #endif
3259      printf("  16-bit support only\n");  #ifdef SUPPORT_PCRE16
3260        printf("  16-bit support\n");
3261      (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);      (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
3262      printf("  %sUTF-16 support\n", rc? "" : "No ");      printf ("  %sUTF-16 support\n", rc ? "" : "No ");
3263    #endif
3264    #ifdef SUPPORT_PCRE32
3265        printf("  32-bit support\n");
3266        (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
3267        printf ("  %sUTF-32 support\n", rc ? "" : "No ");
3268  #endif  #endif
3269    
3270      (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
# Line 2507  are set, either both UTFs are supported Line 3279  are set, either both UTFs are supported
3279      else      else
3280        printf("  No just-in-time compiler support\n");        printf("  No just-in-time compiler support\n");
3281      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3282      print_newline_config(rc);      print_newline_config(rc, FALSE);
3283      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);
3284      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :
3285                                       "all Unicode newlines");                                       "all Unicode newlines");
# Line 2599  pcre16_stack_malloc = stack_malloc; Line 3371  pcre16_stack_malloc = stack_malloc;
3371  pcre16_stack_free = stack_free;  pcre16_stack_free = stack_free;
3372  #endif  #endif
3373    
3374    #ifdef SUPPORT_PCRE32
3375    pcre32_malloc = new_malloc;
3376    pcre32_free = new_free;
3377    pcre32_stack_malloc = stack_malloc;
3378    pcre32_stack_free = stack_free;
3379    #endif
3380    
3381  /* Heading line unless quiet, then prompt for first regex if stdin */  /* Heading line unless quiet, then prompt for first regex if stdin */
3382    
3383  if (!quiet) fprintf(outfile, "PCRE version %s\n\n", version);  if (!quiet) fprintf(outfile, "PCRE version %s\n\n", version);
# Line 2698  while (!done) Line 3477  while (!done)
3477    
3478      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;
3479    
3480      magic = ((REAL_PCRE *)re)->magic_number;      magic = REAL_PCRE_MAGIC(re);
3481      if (magic != MAGIC_NUMBER)      if (magic != MAGIC_NUMBER)
3482        {        {
3483        if (swap_uint32(magic) == MAGIC_NUMBER)        if (swap_uint32(magic) == MAGIC_NUMBER)
# Line 2754  while (!done) Line 3533  while (!done)
3533        PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, NULL);        PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, NULL);
3534        if (rc == PCRE_ERROR_BADMODE)        if (rc == PCRE_ERROR_BADMODE)
3535          {          {
3536            pcre_uint32 flags_in_host_byte_order;
3537            if (REAL_PCRE_MAGIC(re) == MAGIC_NUMBER)
3538              flags_in_host_byte_order = REAL_PCRE_FLAGS(re);
3539            else
3540              flags_in_host_byte_order = swap_uint32(REAL_PCRE_FLAGS(re));
3541          /* Simulate the result of the function call below. */          /* Simulate the result of the function call below. */
3542          fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,          fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
3543            use_pcre16? "16" : "", PCRE_INFO_OPTIONS);            pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "",
3544          fprintf(outfile, "Running in %s-bit mode but pattern was compiled in "            PCRE_INFO_OPTIONS);
3545            "%s-bit mode\n", use_pcre16? "16":"8", use_pcre16? "8":"16");          fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
3546              "%d-bit mode\n", 8 * CHAR_SIZE, 8 * (flags_in_host_byte_order & PCRE_MODE_MASK));
3547          new_free(re);          new_free(re);
3548          fclose(f);          fclose(f);
3549          continue;          continue;
# Line 2912  while (!done) Line 3697  while (!done)
3697        case 'Y': options |= PCRE_NO_START_OPTIMISE; break;        case 'Y': options |= PCRE_NO_START_OPTIMISE; break;
3698        case 'Z': debug_lengths = 0; break;        case 'Z': debug_lengths = 0; break;
3699        case '8': options |= PCRE_UTF8; use_utf = 1; break;        case '8': options |= PCRE_UTF8; use_utf = 1; break;
3700          case '9': options |= PCRE_NEVER_UTF; break;
3701        case '?': options |= PCRE_NO_UTF8_CHECK; break;        case '?': options |= PCRE_NO_UTF8_CHECK; break;
3702    
3703        case 'T':        case 'T':
# Line 3022  while (!done) Line 3808  while (!done)
3808  #endif  /* !defined NOPOSIX */  #endif  /* !defined NOPOSIX */
3809    
3810      {      {
3811      /* In 16-bit mode, convert the input. */      /* In 16- or 32-bit mode, convert the input. */
3812    
3813  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3814      if (use_pcre16)      if (pcre_mode == PCRE16_MODE)
3815        {        {
3816        switch(to16(FALSE, p, options & PCRE_UTF8, (int)strlen((char *)p)))        switch(to16(FALSE, p, options & PCRE_UTF8, (int)strlen((char *)p)))
3817          {          {
# Line 3051  while (!done) Line 3837  while (!done)
3837        }        }
3838  #endif  #endif
3839    
3840    #ifdef SUPPORT_PCRE32
3841        if (pcre_mode == PCRE32_MODE)
3842          {
3843          switch(to32(FALSE, p, options & PCRE_UTF32, (int)strlen((char *)p)))
3844            {
3845            case -1:
3846            fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "
3847              "converted to UTF-32\n");
3848            goto SKIP_DATA;
3849    
3850            case -2:
3851            fprintf(outfile, "**Failed: character value greater than 0x10ffff "
3852              "cannot be converted to UTF-32\n");
3853            goto SKIP_DATA;
3854    
3855            case -3:
3856            fprintf(outfile, "**Failed: character value is ill-formed UTF-32\n");
3857            goto SKIP_DATA;
3858    
3859            default:
3860            break;
3861            }
3862          p = (pcre_uint8 *)buffer32;
3863          }
3864    #endif
3865    
3866      /* Compile many times when timing */      /* Compile many times when timing */
3867    
3868      if (timeit > 0)      if (timeit > 0)
# Line 3108  while (!done) Line 3920  while (!done)
3920      /* Extract the size for possible writing before possibly flipping it,      /* Extract the size for possible writing before possibly flipping it,
3921      and remember the store that was got. */      and remember the store that was got. */
3922    
3923      true_size = ((REAL_PCRE *)re)->size;      true_size = REAL_PCRE_SIZE(re);
3924      regex_gotten_store = first_gotten_store;      regex_gotten_store = first_gotten_store;
3925    
3926      /* Output code size information if requested */      /* Output code size information if requested */
3927    
3928      if (log_store)      if (log_store)
3929          {
3930          int name_count, name_entry_size, real_pcre_size;
3931    
3932          new_info(re, NULL, PCRE_INFO_NAMECOUNT, &name_count);
3933          new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
3934          real_pcre_size = 0;
3935    #ifdef SUPPORT_PCRE8
3936          if (REAL_PCRE_FLAGS(re) & PCRE_MODE8)
3937            real_pcre_size = sizeof(real_pcre);
3938    #endif
3939    #ifdef SUPPORT_PCRE16
3940          if (REAL_PCRE_FLAGS(re) & PCRE_MODE16)
3941            real_pcre_size = sizeof(real_pcre16);
3942    #endif
3943    #ifdef SUPPORT_PCRE32
3944          if (REAL_PCRE_FLAGS(re) & PCRE_MODE32)
3945            real_pcre_size = sizeof(real_pcre32);
3946    #endif
3947        fprintf(outfile, "Memory allocation (code space): %d\n",        fprintf(outfile, "Memory allocation (code space): %d\n",
3948          (int)(first_gotten_store -          (int)(first_gotten_store - real_pcre_size - name_count * name_entry_size));
3949                sizeof(REAL_PCRE) -        }
               ((REAL_PCRE *)re)->name_count * ((REAL_PCRE *)re)->name_entry_size));  
3950    
3951      /* If -s or /S was present, study the regex to generate additional info to      /* If -s or /S was present, study the regex to generate additional info to
3952      help with the matching, unless the pattern has the SS option, which      help with the matching, unless the pattern has the SS option, which
# Line 3188  while (!done) Line 4017  while (!done)
4017      if (do_showinfo)      if (do_showinfo)
4018        {        {
4019        unsigned long int all_options;        unsigned long int all_options;
4020        int count, backrefmax, first_char, need_char, okpartial, jchanged,        pcre_uint32 first_char, need_char;
4021          pcre_uint32 match_limit, recursion_limit;
4022          int count, backrefmax, first_char_set, need_char_set, okpartial, jchanged,
4023          hascrorlf, maxlookbehind;          hascrorlf, maxlookbehind;
4024        int nameentrysize, namecount;        int nameentrysize, namecount;
4025        const pcre_uint8 *nametable;        const pcre_uint8 *nametable;
# Line 3196  while (!done) Line 4027  while (!done)
4027        if (new_info(re, NULL, PCRE_INFO_SIZE, &size) +        if (new_info(re, NULL, PCRE_INFO_SIZE, &size) +
4028            new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) +            new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) +
4029            new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax) +            new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax) +
4030            new_info(re, NULL, PCRE_INFO_FIRSTBYTE, &first_char) +            new_info(re, NULL, PCRE_INFO_FIRSTCHARACTER, &first_char) +
4031            new_info(re, NULL, PCRE_INFO_LASTLITERAL, &need_char) +            new_info(re, NULL, PCRE_INFO_FIRSTCHARACTERFLAGS, &first_char_set) +
4032              new_info(re, NULL, PCRE_INFO_REQUIREDCHAR, &need_char) +
4033              new_info(re, NULL, PCRE_INFO_REQUIREDCHARFLAGS, &need_char_set) +
4034            new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize) +            new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize) +
4035            new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount) +            new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount) +
4036            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +
# Line 3213  while (!done) Line 4046  while (!done)
4046          (int)size, (int)regex_gotten_store);          (int)size, (int)regex_gotten_store);
4047    
4048        fprintf(outfile, "Capturing subpattern count = %d\n", count);        fprintf(outfile, "Capturing subpattern count = %d\n", count);
4049    
4050        if (backrefmax > 0)        if (backrefmax > 0)
4051          fprintf(outfile, "Max back reference = %d\n", backrefmax);          fprintf(outfile, "Max back reference = %d\n", backrefmax);
4052    
4053          if (maxlookbehind > 0)
4054            fprintf(outfile, "Max lookbehind = %d\n", maxlookbehind);
4055    
4056          if (new_info(re, NULL, PCRE_INFO_MATCHLIMIT, &match_limit) == 0)
4057            fprintf(outfile, "Match limit = %u\n", match_limit);
4058    
4059          if (new_info(re, NULL, PCRE_INFO_RECURSIONLIMIT, &recursion_limit) == 0)
4060            fprintf(outfile, "Recursion limit = %u\n", recursion_limit);
4061    
4062        if (namecount > 0)        if (namecount > 0)
4063          {          {
4064          fprintf(outfile, "Named capturing subpatterns:\n");          fprintf(outfile, "Named capturing subpatterns:\n");
4065          while (namecount-- > 0)          while (namecount-- > 0)
4066            {            {
4067  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16            int imm2_size = pcre_mode == PCRE8_MODE ? 2 : 1;
           int imm2_size = use_pcre16 ? 1 : 2;  
 #else  
           int imm2_size = IMM2_SIZE;  
 #endif  
4068            int length = (int)STRLEN(nametable + imm2_size);            int length = (int)STRLEN(nametable + imm2_size);
4069            fprintf(outfile, "  ");            fprintf(outfile, "  ");
4070            PCHARSV(nametable, imm2_size, length, outfile);            PCHARSV(nametable, imm2_size, length, outfile);
4071            while (length++ < nameentrysize - imm2_size) putc(' ', outfile);            while (length++ < nameentrysize - imm2_size) putc(' ', outfile);
4072  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE32
4073            fprintf(outfile, "%3d\n", use_pcre16?            if (pcre_mode == PCRE32_MODE)
4074               (int)(((PCRE_SPTR16)nametable)[0])              fprintf(outfile, "%3d\n", (int)(((PCRE_SPTR32)nametable)[0]));
4075              :((int)nametable[0] << 8) | (int)nametable[1]);  #endif
4076            nametable += nameentrysize * (use_pcre16 ? 2 : 1);  #ifdef SUPPORT_PCRE16
4077  #else            if (pcre_mode == PCRE16_MODE)
4078            fprintf(outfile, "%3d\n", GET2(nametable, 0));              fprintf(outfile, "%3d\n", (int)(((PCRE_SPTR16)nametable)[0]));
 #ifdef SUPPORT_PCRE8  
           nametable += nameentrysize;  
 #else  
           nametable += nameentrysize * 2;  
4079  #endif  #endif
4080    #ifdef SUPPORT_PCRE8
4081              if (pcre_mode == PCRE8_MODE)
4082                fprintf(outfile, "%3d\n", ((int)nametable[0] << 8) | (int)nametable[1]);
4083  #endif  #endif
4084              nametable += nameentrysize * CHAR_SIZE;
4085            }            }
4086          }          }
4087    
4088        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");
4089        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");
4090    
4091        all_options = ((REAL_PCRE *)re)->options;        all_options = REAL_PCRE_OPTIONS(re);
4092        if (do_flip) all_options = swap_uint32(all_options);        if (do_flip) all_options = swap_uint32(all_options);
4093    
4094        if (get_options == 0) fprintf(outfile, "No options\n");        if (get_options == 0) fprintf(outfile, "No options\n");
4095          else fprintf(outfile, "Options:%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",          else fprintf(outfile, "Options:%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
4096            ((get_options & PCRE_ANCHORED) != 0)? " anchored" : "",            ((get_options & PCRE_ANCHORED) != 0)? " anchored" : "",
4097            ((get_options & PCRE_CASELESS) != 0)? " caseless" : "",            ((get_options & PCRE_CASELESS) != 0)? " caseless" : "",
4098            ((get_options & PCRE_EXTENDED) != 0)? " extended" : "",            ((get_options & PCRE_EXTENDED) != 0)? " extended" : "",
# Line 3270  while (!done) Line 4109  while (!done)
4109            ((get_options & PCRE_UCP) != 0)? " ucp" : "",            ((get_options & PCRE_UCP) != 0)? " ucp" : "",
4110            ((get_options & PCRE_NO_UTF8_CHECK) != 0)? " no_utf_check" : "",            ((get_options & PCRE_NO_UTF8_CHECK) != 0)? " no_utf_check" : "",
4111            ((get_options & PCRE_NO_START_OPTIMIZE) != 0)? " no_start_optimize" : "",            ((get_options & PCRE_NO_START_OPTIMIZE) != 0)? " no_start_optimize" : "",
4112            ((get_options & PCRE_DUPNAMES) != 0)? " dupnames" : "");            ((get_options & PCRE_DUPNAMES) != 0)? " dupnames" : "",
4113              ((get_options & PCRE_NEVER_UTF) != 0)? " never_utf" : "");
4114    
4115        if (jchanged) fprintf(outfile, "Duplicate name status changes\n");        if (jchanged) fprintf(outfile, "Duplicate name status changes\n");
4116    
# Line 3300  while (!done) Line 4140  while (!done)
4140          break;          break;
4141          }          }
4142    
4143        if (first_char == -1)        if (first_char_set == 2)
4144          {          {
4145          fprintf(outfile, "First char at start or follows newline\n");          fprintf(outfile, "First char at start or follows newline\n");
4146          }          }
4147        else if (first_char < 0)        else if (first_char_set == 1)
         {  
         fprintf(outfile, "No first char\n");  
         }  
       else  
4148          {          {
4149          const char *caseless =          const char *caseless =
4150            ((((REAL_PCRE *)re)->flags & PCRE_FCH_CASELESS) == 0)?            ((REAL_PCRE_FLAGS(re) & PCRE_FCH_CASELESS) == 0)?
4151            "" : " (caseless)";            "" : " (caseless)";
4152    
4153          if (PRINTOK(first_char))          if (PRINTOK(first_char))
# Line 3323  while (!done) Line 4159  while (!done)
4159            fprintf(outfile, "%s\n", caseless);            fprintf(outfile, "%s\n", caseless);
4160            }            }
4161          }          }
4162          else
4163            {
4164            fprintf(outfile, "No first char\n");
4165            }
4166    
4167        if (need_char < 0)        if (need_char_set == 0)
4168          {          {
4169          fprintf(outfile, "No need char\n");          fprintf(outfile, "No need char\n");
4170          }          }
4171        else        else
4172          {          {
4173          const char *caseless =          const char *caseless =
4174            ((((REAL_PCRE *)re)->flags & PCRE_RCH_CASELESS) == 0)?            ((REAL_PCRE_FLAGS(re) & PCRE_RCH_CASELESS) == 0)?
4175            "" : " (caseless)";            "" : " (caseless)";
4176    
4177          if (PRINTOK(need_char))          if (PRINTOK(need_char))
# Line 3344  while (!done) Line 4184  while (!done)
4184            }            }
4185          }          }
4186    
       if (maxlookbehind > 0)  
         fprintf(outfile, "Max lookbehind = %d\n", maxlookbehind);  
   
4187        /* Don't output study size; at present it is in any case a fixed        /* Don't output study size; at present it is in any case a fixed
4188        value, but it varies, depending on the computer architecture, and        value, but it varies, depending on the computer architecture, and
4189        so messes up the test suite. (And with the /F option, it might be        so messes up the test suite. (And with the /F option, it might be
# Line 3492  while (!done) Line 4329  while (!done)
4329    
4330    for (;;)    for (;;)
4331      {      {
4332      pcre_uint8 *q;  #ifdef SUPPORT_PCRE8
4333        pcre_uint8 *q8;
4334    #endif
4335    #ifdef SUPPORT_PCRE16
4336        pcre_uint16 *q16;
4337    #endif
4338    #ifdef SUPPORT_PCRE32
4339        pcre_uint32 *q32;
4340    #endif
4341      pcre_uint8 *bptr;      pcre_uint8 *bptr;
4342      int *use_offsets = offsets;      int *use_offsets = offsets;
4343      int use_size_offsets = size_offsets;      int use_size_offsets = size_offsets;
4344      int callout_data = 0;      int callout_data = 0;
4345      int callout_data_set = 0;      int callout_data_set = 0;
4346      int count, c;      int count;
4347        pcre_uint32 c;
4348      int copystrings = 0;      int copystrings = 0;
4349      int find_match_limit = default_find_match_limit;      int find_match_limit = default_find_match_limit;
4350      int getstrings = 0;      int getstrings = 0;
# Line 3512  while (!done) Line 4358  while (!done)
4358      *copynames = 0;      *copynames = 0;
4359      *getnames = 0;      *getnames = 0;
4360    
4361    #ifdef SUPPORT_PCRE32
4362        cn32ptr = copynames;
4363        gn32ptr = getnames;
4364    #endif
4365  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
4366      cn16ptr = copynames;      cn16ptr = copynames16;
4367      gn16ptr = getnames;      gn16ptr = getnames16;
4368  #endif  #endif
4369  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
4370      cn8ptr = copynames8;      cn8ptr = copynames8;
# Line 3559  while (!done) Line 4409  while (!done)
4409      p = buffer;      p = buffer;
4410      while (isspace(*p)) p++;      while (isspace(*p)) p++;
4411    
4412      bptr = q = dbuffer;  #ifndef NOUTF
4413        /* Check that the data is well-formed UTF-8 if we're in UTF mode. To create
4414           invalid input to pcre_exec, you must use \x?? or \x{} sequences. */
4415        if (use_utf)
4416          {
4417          pcre_uint8 *q;
4418          pcre_uint32 cc;
4419          int n = 1;
4420    
4421          for (q = p; n > 0 && *q; q += n) n = utf82ord(q, &cc);
4422          if (n <= 0)
4423            {
4424            fprintf(outfile, "**Failed: invalid UTF-8 string cannot be used as input in UTF mode\n");
4425            goto NEXT_DATA;
4426            }
4427          }
4428    #endif
4429    
4430    #ifdef SUPPORT_VALGRIND
4431        /* Mark the dbuffer as addressable but undefined again. */
4432        if (dbuffer != NULL)
4433          {
4434          VALGRIND_MAKE_MEM_UNDEFINED(dbuffer, dbuffer_size * CHAR_SIZE);
4435          }
4436    #endif
4437    
4438        /* Allocate a buffer to hold the data line. len+1 is an upper bound on
4439           the number of pcre_uchar units that will be needed. */
4440        if (dbuffer == NULL || (size_t)len >= dbuffer_size)
4441          {
4442          dbuffer_size *= 2;
4443          dbuffer = (pcre_uint8 *)realloc(dbuffer, dbuffer_size * CHAR_SIZE);
4444          if (dbuffer == NULL)
4445            {
4446            fprintf(stderr, "pcretest: malloc(%d) failed\n", (int)dbuffer_size);
4447            exit(1);
4448            }
4449          }
4450    
4451    #ifdef SUPPORT_PCRE8
4452        q8 = (pcre_uint8 *) dbuffer;
4453    #endif
4454    #ifdef SUPPORT_PCRE16
4455        q16 = (pcre_uint16 *) dbuffer;
4456    #endif
4457    #ifdef SUPPORT_PCRE32
4458        q32 = (pcre_uint32 *) dbuffer;
4459    #endif
4460    
4461      while ((c = *p++) != 0)      while ((c = *p++) != 0)
4462        {        {
4463        int i = 0;        int i = 0;
# Line 3568  while (!done) Line 4466  while (!done)
4466        /* In UTF mode, input can be UTF-8, so just copy all non-backslash bytes.        /* In UTF mode, input can be UTF-8, so just copy all non-backslash bytes.
4467        In non-UTF mode, allow the value of the byte to fall through to later,        In non-UTF mode, allow the value of the byte to fall through to later,
4468        where values greater than 127 are turned into UTF-8 when running in        where values greater than 127 are turned into UTF-8 when running in
4469        16-bit mode. */        16-bit or 32-bit mode. */
4470    
4471        if (c != '\\')        if (c != '\\')
4472          {          {
4473          if (use_utf)  #ifndef NOUTF
4474            {          if (use_utf && HASUTF8EXTRALEN(c)) { GETUTF8INC(c, p); }
4475            *q++ = c;  #endif
           continue;  
           }  
4476          }          }
4477    
4478        /* Handle backslash escapes */        /* Handle backslash escapes */
# Line 3629  while (!done) Line 4525  while (!done)
4525          allows UTF-8 characters to be constructed byte by byte, and also allows          allows UTF-8 characters to be constructed byte by byte, and also allows
4526          invalid UTF-8 sequences to be made. Just copy the byte in UTF mode.          invalid UTF-8 sequences to be made. Just copy the byte in UTF mode.
4527          Otherwise, pass it down to later code so that it can be turned into          Otherwise, pass it down to later code so that it can be turned into
4528          UTF-8 when running in 16-bit mode. */          UTF-8 when running in 16/32-bit mode. */
4529    
4530          c = 0;          c = 0;
4531          while (i++ < 2 && isxdigit(*p))          while (i++ < 2 && isxdigit(*p))
# Line 3637  while (!done) Line 4533  while (!done)
4533            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);
4534            p++;            p++;
4535            }            }
4536          if (use_utf)  #if !defined NOUTF && defined SUPPORT_PCRE8
4537            if (use_utf && (pcre_mode == PCRE8_MODE))
4538            {            {
4539            *q++ = c;            *q8++ = c;
4540            continue;            continue;
4541            }            }
4542    #endif
4543          break;          break;
4544    
4545          case 0:   /* \ followed by EOF allows for an empty line */          case 0:   /* \ followed by EOF allows for an empty line */
# Line 3674  while (!done) Line 4572  while (!done)
4572            }            }
4573          else if (isalnum(*p))          else if (isalnum(*p))
4574            {            {
4575            READ_CAPTURE_NAME(p, &cn8ptr, &cn16ptr, re);            READ_CAPTURE_NAME(p, &cn8ptr, &cn16ptr, &cn32ptr, re);
4576            }            }
4577          else if (*p == '+')          else if (*p == '+')
4578            {            {
# Line 3737  while (!done) Line 4635  while (!done)
4635            }            }
4636          else if (isalnum(*p))          else if (isalnum(*p))
4637            {            {
4638            READ_CAPTURE_NAME(p, &gn8ptr, &gn16ptr, re);            READ_CAPTURE_NAME(p, &gn8ptr, &gn16ptr, &gn32ptr, re);
4639            }            }
4640          continue;          continue;
4641    
# Line 3847  while (!done) Line 4745  while (!done)
4745          continue;          continue;
4746          }          }
4747    
4748        /* We now have a character value in c that may be greater than 255. In        /* We now have a character value in c that may be greater than 255.
4749        16-bit mode, we always convert characters to UTF-8 so that values greater        In 8-bit mode we convert to UTF-8 if we are in UTF mode. Values greater
4750        than 255 can be passed to non-UTF 16-bit strings. In 8-bit mode we        than 127 in UTF mode must have come from \x{...} or octal constructs
4751        convert to UTF-8 if we are in UTF mode. Values greater than 127 in UTF        because values from \x.. get this far only in non-UTF mode. */
4752        mode must have come from \x{...} or octal constructs because values from  
4753        \x.. get this far only in non-UTF mode. */  #ifdef SUPPORT_PCRE8
4754          if (pcre_mode == PCRE8_MODE)
4755  #if !defined NOUTF || defined SUPPORT_PCRE16          {
4756        if (use_pcre16 || use_utf)  #ifndef NOUTF
4757          {          if (use_utf)
4758          pcre_uint8 buff8[8];            {
4759          int ii, utn;            if (c > 0x7fffffff)
4760          utn = ord2utf8(c, buff8);              {
4761          for (ii = 0; ii < utn; ii++) *q++ = buff8[ii];              fprintf(outfile, "** Character \\x{%x} is greater than 0x7fffffff "
4762                  "and so cannot be converted to UTF-8\n", c);
4763                goto NEXT_DATA;
4764                }
4765              q8 += ord2utf8(c, q8);
4766              }
4767            else
4768    #endif
4769              {
4770              if (c > 0xffu)
4771                {
4772                fprintf(outfile, "** Character \\x{%x} is greater than 255 "
4773                  "and UTF-8 mode is not enabled.\n", c);
4774                fprintf(outfile, "** Truncation will probably give the wrong "
4775                  "result.\n");
4776                }
4777              *q8++ = c;
4778              }
4779          }          }
       else  
4780  #endif  #endif
4781    #ifdef SUPPORT_PCRE16
4782          if (pcre_mode == PCRE16_MODE)
4783          {          {
4784          if (c > 255)  #ifndef NOUTF
4785            if (use_utf)
4786              {
4787              if (c > 0x10ffffu)
4788                {
4789                fprintf(outfile, "** Failed: character \\x{%x} is greater than "
4790                  "0x10ffff and so cannot be converted to UTF-16\n", c);
4791                goto NEXT_DATA;
4792                }
4793              else if (c >= 0x10000u)
4794                {
4795                c-= 0x10000u;
4796                *q16++ = 0xD800 | (c >> 10);
4797                *q16++ = 0xDC00 | (c & 0x3ff);
4798                }
4799              else
4800                *q16++ = c;
4801              }
4802            else
4803    #endif
4804            {            {
4805            fprintf(outfile, "** Character \\x{%x} is greater than 255 "            if (c > 0xffffu)
4806              "and UTF-8 mode is not enabled.\n", c);              {
4807            fprintf(outfile, "** Truncation will probably give the wrong "              fprintf(outfile, "** Character \\x{%x} is greater than 0xffff "
4808              "result.\n");                "and UTF-16 mode is not enabled.\n", c);
4809                fprintf(outfile, "** Truncation will probably give the wrong "
4810                  "result.\n");
4811                }
4812    
4813              *q16++ = c;
4814            }            }
         *q++ = c;  
4815          }          }
4816    #endif
4817    #ifdef SUPPORT_PCRE32
4818          if (pcre_mode == PCRE32_MODE)
4819            {
4820            *q32++ = c;
4821            }
4822    #endif
4823    
4824        }        }
4825    
4826      /* Reached end of subject string */      /* Reached end of subject string */
4827    
4828      *q = 0;  #ifdef SUPPORT_PCRE8
4829      len = (int)(q - dbuffer);      if (pcre_mode == PCRE8_MODE)
4830        {
4831          *q8 = 0;
4832          len = (int)(q8 - (pcre_uint8 *)dbuffer);
4833        }
4834    #endif
4835    #ifdef SUPPORT_PCRE16
4836        if (pcre_mode == PCRE16_MODE)
4837        {
4838          *q16 = 0;
4839          len = (int)(q16 - (pcre_uint16 *)dbuffer);
4840        }
4841    #endif
4842    #ifdef SUPPORT_PCRE32
4843        if (pcre_mode == PCRE32_MODE)
4844        {
4845          *q32 = 0;
4846          len = (int)(q32 - (pcre_uint32 *)dbuffer);
4847        }
4848    #endif
4849    
4850        /* If we're compiling with explicit valgrind support, Mark the data from after
4851        its end to the end of the buffer as unaddressable, so that a read over the end
4852        of the buffer will be seen by valgrind, even if it doesn't cause a crash.
4853        If we're not building with valgrind support, at least move the data to the end
4854        of the buffer so that it might at least cause a crash.
4855        If we are using the POSIX interface, we must include the terminating zero. */
4856    
4857      /* Move the data to the end of the buffer so that a read over the end of      bptr = dbuffer;
     the buffer will be seen by valgrind, even if it doesn't cause a crash. If  
     we are using the POSIX interface, we must include the terminating zero. */  
4858    
4859  #if !defined NOPOSIX  #if !defined NOPOSIX
4860      if (posix || do_posix)      if (posix || do_posix)
4861        {        {
4862        memmove(bptr + buffer_size - len - 1, bptr, len + 1);  #ifdef SUPPORT_VALGRIND
4863        bptr += buffer_size - len - 1;        VALGRIND_MAKE_MEM_NOACCESS(dbuffer + len + 1, dbuffer_size - (len + 1));
4864    #else
4865          memmove(bptr + dbuffer_size - len - 1, bptr, len + 1);
4866          bptr += dbuffer_size - len - 1;
4867    #endif
4868        }        }
4869      else      else
4870  #endif  #endif
4871        {        {
4872        memmove(bptr + buffer_size - len, bptr, len);  #ifdef SUPPORT_VALGRIND
4873        bptr += buffer_size - len;        VALGRIND_MAKE_MEM_NOACCESS(dbuffer + len * CHAR_SIZE, (dbuffer_size - len) * CHAR_SIZE);
4874    #else
4875          bptr = memmove(bptr + (dbuffer_size - len) * CHAR_SIZE, bptr, len * CHAR_SIZE);
4876    #endif
4877        }        }
4878    
4879      if ((all_use_dfa || use_dfa) && find_match_limit)      if ((all_use_dfa || use_dfa) && find_match_limit)
# Line 3926  while (!done) Line 4904  while (!done)
4904          (void)regerror(rc, &preg, (char *)buffer, buffer_size);          (void)regerror(rc, &preg, (char *)buffer, buffer_size);
4905          fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);          fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);
4906          }          }
4907        else if ((((const pcre *)preg.re_pcre)->options & PCRE_NO_AUTO_CAPTURE)        else if ((REAL_PCRE_OPTIONS(preg.re_pcre) & PCRE_NO_AUTO_CAPTURE) != 0)
               != 0)  
4908          {          {
4909          fprintf(outfile, "Matched with REG_NOSUB\n");          fprintf(outfile, "Matched with REG_NOSUB\n");
4910          }          }
# Line 3960  while (!done) Line 4937  while (!done)
4937    
4938      /* Handle matching via the native interface - repeats for /g and /G */      /* Handle matching via the native interface - repeats for /g and /G */
4939    
 #ifdef SUPPORT_PCRE16  
     if (use_pcre16)  
       {  
       len = to16(TRUE, bptr, (((REAL_PCRE *)re)->options) & PCRE_UTF8, len);  
       switch(len)  
         {  
         case -1:  
         fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "  
           "converted to UTF-16\n");  
         goto NEXT_DATA;  
   
         case -2:  
         fprintf(outfile, "**Failed: character value greater than 0x10ffff "  
           "cannot be converted to UTF-16\n");  
         goto NEXT_DATA;  
   
         case -3:  
         fprintf(outfile, "**Failed: character value greater than 0xffff "  
           "cannot be converted to 16-bit in non-UTF mode\n");  
         goto NEXT_DATA;  
   
         default:  
         break;  
         }  
       bptr = (pcre_uint8 *)buffer16;  
       }  
 #endif  
   
4940      /* Ensure that there is a JIT callback if we want to verify that JIT was      /* Ensure that there is a JIT callback if we want to verify that JIT was
4941      actually used. If jit_stack == NULL, no stack has yet been assigned. */      actually used. If jit_stack == NULL, no stack has yet been assigned. */
4942    
# Line 4104  while (!done) Line 5053  while (!done)
5053          if (count == 0)          if (count == 0)
5054            {            {
5055            fprintf(outfile, "Matched, but too many substrings\n");            fprintf(outfile, "Matched, but too many substrings\n");
5056            count = use_size_offsets/3;            /* 2 is a special case; match can be returned */
5057              count = (use_size_offsets == 2)? 1 : use_size_offsets/3;
5058            }            }
5059          }          }
5060    
# Line 4118  while (!done) Line 5068  while (!done)
5068  #if !defined NODFA  #if !defined NODFA
5069          if (all_use_dfa || use_dfa) maxcount = use_size_offsets/2; else          if (all_use_dfa || use_dfa) maxcount = use_size_offsets/2; else
5070  #endif  #endif
5071            maxcount = use_size_offsets/3;            /* 2 is a special case; match can be returned */
5072              maxcount = (use_size_offsets == 2)? 1 : use_size_offsets/3;
5073    
5074          /* This is a check against a lunatic return value. */          /* This is a check against a lunatic return value. */
5075    
# Line 4209  while (!done) Line 5160  while (!done)
5160            int rc;            int rc;
5161            char copybuffer[256];            char copybuffer[256];
5162    
5163            if (use_pcre16)  #ifdef SUPPORT_PCRE32
5164              if (pcre_mode == PCRE32_MODE)
5165                {
5166                if (*(pcre_uint32 *)cnptr == 0) break;
5167                }
5168    #endif
5169    #ifdef SUPPORT_PCRE16
5170              if (pcre_mode == PCRE16_MODE)
5171              {              {
5172              if (*(pcre_uint16 *)cnptr == 0) break;              if (*(pcre_uint16 *)cnptr == 0) break;
5173              }              }
5174            else  #endif
5175    #ifdef SUPPORT_PCRE8
5176              if (pcre_mode == PCRE8_MODE)
5177              {              {
5178              if (*(pcre_uint8 *)cnptr == 0) break;              if (*(pcre_uint8 *)cnptr == 0) break;
5179              }              }
5180    #endif
5181    
5182            PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,            PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,
5183              cnptr, copybuffer, sizeof(copybuffer));              cnptr, copybuffer, sizeof(copybuffer));
# Line 4264  while (!done) Line 5225  while (!done)
5225            int rc;            int rc;
5226            const char *substring;            const char *substring;
5227    
5228            if (use_pcre16)  #ifdef SUPPORT_PCRE32
5229              if (pcre_mode == PCRE32_MODE)
5230                {
5231                if (*(pcre_uint32 *)gnptr == 0) break;
5232                }
5233    #endif
5234    #ifdef SUPPORT_PCRE16
5235              if (pcre_mode == PCRE16_MODE)
5236              {              {
5237              if (*(pcre_uint16 *)gnptr == 0) break;              if (*(pcre_uint16 *)gnptr == 0) break;
5238              }              }
5239            else  #endif
5240    #ifdef SUPPORT_PCRE8
5241              if (pcre_mode == PCRE8_MODE)
5242              {              {
5243              if (*(pcre_uint8 *)gnptr == 0) break;              if (*(pcre_uint8 *)gnptr == 0) break;
5244              }              }
5245    #endif
5246    
5247            PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,            PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,
5248              gnptr, &substring);              gnptr, &substring);
# Line 4316  while (!done) Line 5287  while (!done)
5287            }            }
5288          }          }
5289    
5290        /* There was a partial match */        /* There was a partial match. If the bumpalong point is not the same as
5291          the first inspected character, show the offset explicitly. */
5292    
5293        else if (count == PCRE_ERROR_PARTIAL)        else if (count == PCRE_ERROR_PARTIAL)
5294          {          {
5295          if (markptr == NULL) fprintf(outfile, "Partial match");          fprintf(outfile, "Partial match");
5296          else          if (use_size_offsets > 2 && use_offsets[0] != use_offsets[2])
5297              fprintf(outfile, " at offset %d", use_offsets[2]);
5298            if (markptr != NULL)
5299            {            {
5300            fprintf(outfile, "Partial match, mark=");            fprintf(outfile, ", mark=");
5301            PCHARSV(markptr, 0, -1, outfile);            PCHARSV(markptr, 0, -1, outfile);
5302            }            }
5303          if (use_size_offsets > 1)          if (use_size_offsets > 1)
# Line 4358  while (!done) Line 5332  while (!done)
5332          if (g_notempty != 0)          if (g_notempty != 0)
5333            {            {
5334            int onechar = 1;            int onechar = 1;
5335            unsigned int obits = ((REAL_PCRE *)re)->options;            unsigned int obits = REAL_PCRE_OPTIONS(re);
5336            use_offsets[0] = start_offset;            use_offsets[0] = start_offset;
5337            if ((obits & PCRE_NEWLINE_BITS) == 0)            if ((obits & PCRE_NEWLINE_BITS) == 0)
5338              {              {
# Line 4376  while (!done) Line 5350  while (!done)
5350                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||
5351                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)
5352                &&                &&
5353                start_offset < len - 1 &&                start_offset < len - 1 && (
5354  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE8
5355                (use_pcre16?                (pcre_mode == PCRE8_MODE &&
5356                     ((PCRE_SPTR16)bptr)[start_offset] == '\r'                 bptr[start_offset] == '\r' &&
5357                  && ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n'                 bptr[start_offset + 1] == '\n') ||
5358                :  #endif
5359                     bptr[start_offset] == '\r'  #ifdef SUPPORT_PCRE16
5360                  && bptr[start_offset + 1] == '\n')                (pcre_mode == PCRE16_MODE &&
5361  #elif defined SUPPORT_PCRE16                 ((PCRE_SPTR16)bptr)[start_offset] == '\r' &&
5362                   ((PCRE_SPTR16)bptr)[start_offset] == '\r'                 ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n') ||
5363                && ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n'  #endif
5364  #else  #ifdef SUPPORT_PCRE32
5365                   bptr[start_offset] == '\r'                (pcre_mode == PCRE32_MODE &&
5366                && bptr[start_offset + 1] == '\n'                 ((PCRE_SPTR32)bptr)[start_offset] == '\r' &&
5367                   ((PCRE_SPTR32)bptr)[start_offset + 1] == '\n') ||
5368  #endif  #endif
5369                )                0))
5370              onechar++;              onechar++;
5371            else if (use_utf)            else if (use_utf)
5372              {              {
# Line 4426  while (!done) Line 5401  while (!done)
5401    
5402              case PCRE_ERROR_BADUTF8:              case PCRE_ERROR_BADUTF8:
5403              case PCRE_ERROR_SHORTUTF8:              case PCRE_ERROR_SHORTUTF8:
5404              fprintf(outfile, "Error %d (%s UTF-%s string)", count,              fprintf(outfile, "Error %d (%s UTF-%d string)", count,
5405                (count == PCRE_ERROR_BADUTF8)? "bad" : "short",                (count == PCRE_ERROR_BADUTF8)? "bad" : "short",
5406                use_pcre16? "16" : "8");                8 * CHAR_SIZE);
5407              if (use_size_offsets >= 2)              if (use_size_offsets >= 2)
5408                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],
5409                  use_offsets[1]);                  use_offsets[1]);
# Line 4436  while (!done) Line 5411  while (!done)
5411              break;              break;
5412    
5413              case PCRE_ERROR_BADUTF8_OFFSET:              case PCRE_ERROR_BADUTF8_OFFSET:
5414              fprintf(outfile, "Error %d (bad UTF-%s offset)\n", count,              fprintf(outfile, "Error %d (bad UTF-%d offset)\n", count,
5415                use_pcre16? "16" : "8");                8 * CHAR_SIZE);
5416              break;              break;
5417    
5418              default:              default:
# Line 4527  free(offsets); Line 5502  free(offsets);
5502  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
5503  if (buffer16 != NULL) free(buffer16);  if (buffer16 != NULL) free(buffer16);
5504  #endif  #endif
5505    #ifdef SUPPORT_PCRE32
5506    if (buffer32 != NULL) free(buffer32);
5507    #endif
5508    
5509  #if !defined NODFA  #if !defined NODFA
5510  if (dfa_workspace != NULL)  if (dfa_workspace != NULL)
5511    free(dfa_workspace);    free(dfa_workspace);
5512  #endif  #endif
5513    
5514    #if defined(__VMS)
5515      yield = SS$_NORMAL;  /* Return values via DCL symbols */
5516    #endif
5517    
5518  return yield;  return yield;
5519  }  }
5520    

Legend:
Removed from v.1030  
changed lines
  Added in v.1313

  ViewVC Help
Powered by ViewVC 1.1.5