/[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 908 by ph10, Mon Jan 30 12:19:29 2012 UTC revision 1190 by ph10, Tue Oct 30 16:49:19 2012 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 59  only supported library functions. */ Line 58  only supported library functions. */
58  #include <locale.h>  #include <locale.h>
59  #include <errno.h>  #include <errno.h>
60    
61  #ifdef SUPPORT_LIBREADLINE  /* Both libreadline and libedit are optionally supported. The user-supplied
62    original patch uses readline/readline.h for libedit, but in at least one system
63    it is installed as editline/readline.h, so the configuration code now looks for
64    that first, falling back to readline/readline.h. */
65    
66    #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
67  #ifdef HAVE_UNISTD_H  #ifdef HAVE_UNISTD_H
68  #include <unistd.h>  #include <unistd.h>
69  #endif  #endif
70    #if defined(SUPPORT_LIBREADLINE)
71  #include <readline/readline.h>  #include <readline/readline.h>
72  #include <readline/history.h>  #include <readline/history.h>
73    #else
74    #if defined(HAVE_EDITLINE_READLINE_H)
75    #include <editline/readline.h>
76    #else
77    #include <readline/readline.h>
78    #endif
79    #endif
80  #endif  #endif
   
81    
82  /* A number of things vary for Windows builds. Originally, pcretest opened its  /* A number of things vary for Windows builds. Originally, pcretest opened its
83  input and output without "b"; then I was told that "b" was needed in some  input and output without "b"; then I was told that "b" was needed in some
# Line 101  input mode under Windows. */ Line 112  input mode under Windows. */
112  #else  #else
113  #include <sys/time.h>          /* These two includes are needed */  #include <sys/time.h>          /* These two includes are needed */
114  #include <sys/resource.h>      /* for setrlimit(). */  #include <sys/resource.h>      /* for setrlimit(). */
115    #if defined NATIVE_ZOS         /* z/OS uses non-binary I/O */
116    #define INPUT_MODE   "r"
117    #define OUTPUT_MODE  "w"
118    #else
119  #define INPUT_MODE   "rb"  #define INPUT_MODE   "rb"
120  #define OUTPUT_MODE  "wb"  #define OUTPUT_MODE  "wb"
121  #endif  #endif
122    #endif
123    
124  #define PRIV(name) name  #define PRIV(name) name
125    
# Line 117  here before pcre_internal.h so that the Line 133  here before pcre_internal.h so that the
133  appropriately for an application, not for building PCRE. */  appropriately for an application, not for building PCRE. */
134    
135  #include "pcre.h"  #include "pcre.h"
   
 #if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8  
 /* Configure internal macros to 16 bit mode. */  
 #define COMPILE_PCRE16  
 #endif  
   
136  #include "pcre_internal.h"  #include "pcre_internal.h"
137    
138  /* The pcre_printint() function, which prints the internal form of a compiled  /* The pcre_printint() function, which prints the internal form of a compiled
139  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
140  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
141  when that is compiled in debug mode. */  when that is compiled in debug mode. */
142    
143  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
# Line 136  void pcre_printint(pcre *external_re, FI Line 146  void pcre_printint(pcre *external_re, FI
146  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
147  void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths);  void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths);
148  #endif  #endif
149    #ifdef SUPPORT_PCRE32
150    void pcre32_printint(pcre *external_re, FILE *f, BOOL print_lengths);
151    #endif
152    
153  /* 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
154  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
155  external symbols to prevent clashes. */  external symbols to prevent clashes. */
156    
157  #define PCRE_INCLUDED  #define PCRE_INCLUDED
158    
159  #include "pcre_tables.c"  #include "pcre_tables.c"
160    #include "pcre_ucd.c"
161    
162  /* The definition of the macro PRINTABLE, which determines whether to print an  /* The definition of the macro PRINTABLE, which determines whether to print an
163  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 159  that differ in their output from isprint Line 173  that differ in their output from isprint
173    
174  #define PRINTOK(c) (locale_set? isprint(c) : PRINTABLE(c))  #define PRINTOK(c) (locale_set? isprint(c) : PRINTABLE(c))
175    
176  /* Posix support is disabled in 16 bit only mode. */  /* Posix support is disabled in 16 or 32 bit only mode. */
177  #if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8 && !defined NOPOSIX  #if !defined SUPPORT_PCRE8 && !defined NOPOSIX
178  #define NOPOSIX  #define NOPOSIX
179  #endif  #endif
180    
# Line 183  automatically cut out the UTF support if Line 197  automatically cut out the UTF support if
197  #endif  #endif
198  #endif  #endif
199    
200  /* 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
201  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
202  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
203  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 205  argument, the casting might be incorrect Line 219  argument, the casting might be incorrect
219  #define PCHARSV8(p, offset, len, f) \  #define PCHARSV8(p, offset, len, f) \
220    (void)pchars((pcre_uint8 *)(p) + offset, len, f)    (void)pchars((pcre_uint8 *)(p) + offset, len, f)
221    
222  #define READ_CAPTURE_NAME8(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME8(p, cn8, cn16, cn32, re) \
223    p = read_capture_name8(p, cn8, re)    p = read_capture_name8(p, cn8, re)
224    
225  #define STRLEN8(p) ((int)strlen((char *)p))  #define STRLEN8(p) ((int)strlen((char *)p))
# Line 274  argument, the casting might be incorrect Line 288  argument, the casting might be incorrect
288    
289  #define PCRE_JIT_STACK_FREE8(stack) \  #define PCRE_JIT_STACK_FREE8(stack) \
290    pcre_jit_stack_free(stack)    pcre_jit_stack_free(stack)
291    
292    #define pcre8_maketables pcre_maketables
293    
294  #endif /* SUPPORT_PCRE8 */  #endif /* SUPPORT_PCRE8 */
295    
# Line 287  argument, the casting might be incorrect Line 303  argument, the casting might be incorrect
303  #define PCHARSV16(p, offset, len, f) \  #define PCHARSV16(p, offset, len, f) \
304    (void)pchars16((PCRE_SPTR16)(p) + offset, len, f)    (void)pchars16((PCRE_SPTR16)(p) + offset, len, f)
305    
306  #define READ_CAPTURE_NAME16(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME16(p, cn8, cn16, cn32, re) \
307    p = read_capture_name16(p, cn16, re)    p = read_capture_name16(p, cn16, re)
308    
309  #define STRLEN16(p) ((int)strlen16((PCRE_SPTR16)p))  #define STRLEN16(p) ((int)strlen16((PCRE_SPTR16)p))
# Line 366  argument, the casting might be incorrect Line 382  argument, the casting might be incorrect
382    
383  #endif /* SUPPORT_PCRE16 */  #endif /* SUPPORT_PCRE16 */
384    
385    /* -----------------------------------------------------------*/
386    
387    #ifdef SUPPORT_PCRE32
388    
389    #define PCHARS32(lv, p, offset, len, f) \
390      lv = pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
391    
392    #define PCHARSV32(p, offset, len, f)                \
393      (void)pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
394    
395    #define READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re) \
396      p = read_capture_name32(p, cn32, re)
397    
398    #define STRLEN32(p) ((int)strlen32((PCRE_SPTR32)p))
399    
400    #define SET_PCRE_CALLOUT32(callout) \
401      pcre32_callout = (int (*)(pcre32_callout_block *))callout
402    
403    #define PCRE_ASSIGN_JIT_STACK32(extra, callback, userdata) \
404      pcre32_assign_jit_stack((pcre32_extra *)extra, \
405        (pcre32_jit_callback)callback, userdata)
406    
407  /* ----- Both modes are supported; a runtime test is needed, except for  #define PCRE_COMPILE32(re, pat, options, error, erroffset, tables) \
408      re = (pcre *)pcre32_compile((PCRE_SPTR32)pat, options, error, erroffset, \
409        tables)
410    
411    #define PCRE_COPY_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
412        namesptr, cbuffer, size) \
413      rc = pcre32_copy_named_substring((pcre32 *)re, (PCRE_SPTR32)bptr, offsets, \
414        count, (PCRE_SPTR32)namesptr, (PCRE_UCHAR32 *)cbuffer, size/2)
415    
416    #define PCRE_COPY_SUBSTRING32(rc, bptr, offsets, count, i, cbuffer, size) \
417      rc = pcre32_copy_substring((PCRE_SPTR32)bptr, offsets, count, i, \
418        (PCRE_UCHAR32 *)cbuffer, size/2)
419    
420    #define PCRE_DFA_EXEC32(count, re, extra, bptr, len, start_offset, options, \
421        offsets, size_offsets, workspace, size_workspace) \
422      count = pcre32_dfa_exec((pcre32 *)re, (pcre32_extra *)extra, \
423        (PCRE_SPTR32)bptr, len, start_offset, options, offsets, size_offsets, \
424        workspace, size_workspace)
425    
426    #define PCRE_EXEC32(count, re, extra, bptr, len, start_offset, options, \
427        offsets, size_offsets) \
428      count = pcre32_exec((pcre32 *)re, (pcre32_extra *)extra, (PCRE_SPTR32)bptr, \
429        len, start_offset, options, offsets, size_offsets)
430    
431    #define PCRE_FREE_STUDY32(extra) \
432      pcre32_free_study((pcre32_extra *)extra)
433    
434    #define PCRE_FREE_SUBSTRING32(substring) \
435      pcre32_free_substring((PCRE_SPTR32)substring)
436    
437    #define PCRE_FREE_SUBSTRING_LIST32(listptr) \
438      pcre32_free_substring_list((PCRE_SPTR32 *)listptr)
439    
440    #define PCRE_GET_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
441        getnamesptr, subsptr) \
442      rc = pcre32_get_named_substring((pcre32 *)re, (PCRE_SPTR32)bptr, offsets, \
443        count, (PCRE_SPTR32)getnamesptr, (PCRE_SPTR32 *)(void*)subsptr)
444    
445    #define PCRE_GET_STRINGNUMBER32(n, rc, ptr) \
446      n = pcre32_get_stringnumber(re, (PCRE_SPTR32)ptr)
447    
448    #define PCRE_GET_SUBSTRING32(rc, bptr, offsets, count, i, subsptr) \
449      rc = pcre32_get_substring((PCRE_SPTR32)bptr, offsets, count, i, \
450        (PCRE_SPTR32 *)(void*)subsptr)
451    
452    #define PCRE_GET_SUBSTRING_LIST32(rc, bptr, offsets, count, listptr) \
453      rc = pcre32_get_substring_list((PCRE_SPTR32)bptr, offsets, count, \
454        (PCRE_SPTR32 **)(void*)listptr)
455    
456    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER32(rc, re, extra, tables) \
457      rc = pcre32_pattern_to_host_byte_order((pcre32 *)re, (pcre32_extra *)extra, \
458        tables)
459    
460    #define PCRE_PRINTINT32(re, outfile, debug_lengths) \
461      pcre32_printint(re, outfile, debug_lengths)
462    
463    #define PCRE_STUDY32(extra, re, options, error) \
464      extra = (pcre_extra *)pcre32_study((pcre32 *)re, options, error)
465    
466    #define PCRE_JIT_STACK_ALLOC32(startsize, maxsize) \
467      (pcre_jit_stack *)pcre32_jit_stack_alloc(startsize, maxsize)
468    
469    #define PCRE_JIT_STACK_FREE32(stack) \
470      pcre32_jit_stack_free((pcre32_jit_stack *)stack)
471    
472    #endif /* SUPPORT_PCRE32 */
473    
474    
475    /* ----- More than one mode is supported; a runtime test is needed, except for
476  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
477  version is called. ----- */  available version is called. ----- */
478    
479    enum {
480      PCRE8_MODE,
481      PCRE16_MODE,
482      PCRE32_MODE
483    };
484    
485    #if (defined (SUPPORT_PCRE8) + defined (SUPPORT_PCRE16) + \
486         defined (SUPPORT_PCRE32)) >= 2
487    
488  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #define CHAR_SIZE (1 << pcre_mode)
489    
490  #define CHAR_SIZE (use_pcre16? 2:1)  /* There doesn't seem to be an easy way of writing these macros that can cope
491    with the 3 pairs of bit sizes plus all three bit sizes. So just handle all the
492    cases separately. */
493    
494    /* ----- All three modes supported ----- */
495    
496    #if defined(SUPPORT_PCRE8) && defined(SUPPORT_PCRE16) && defined(SUPPORT_PCRE32)
497    
498  #define PCHARS(lv, p, offset, len, f) \  #define PCHARS(lv, p, offset, len, f) \
499    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
500        PCHARS32(lv, p, offset, len, f); \
501      else if (pcre_mode == PCRE16_MODE) \
502      PCHARS16(lv, p, offset, len, f); \      PCHARS16(lv, p, offset, len, f); \
503    else \    else \
504      PCHARS8(lv, p, offset, len, f)      PCHARS8(lv, p, offset, len, f)
505    
506  #define PCHARSV(p, offset, len, f) \  #define PCHARSV(p, offset, len, f) \
507    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
508        PCHARSV32(p, offset, len, f); \
509      else if (pcre_mode == PCRE16_MODE) \
510      PCHARSV16(p, offset, len, f); \      PCHARSV16(p, offset, len, f); \
511    else \    else \
512      PCHARSV8(p, offset, len, f)      PCHARSV8(p, offset, len, f)
513    
514  #define READ_CAPTURE_NAME(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME(p, cn8, cn16, cn32, re) \
515    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
516      READ_CAPTURE_NAME16(p, cn8, cn16, re); \      READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re); \
517      else if (pcre_mode == PCRE16_MODE) \
518        READ_CAPTURE_NAME16(p, cn8, cn16, cn32, re); \
519    else \    else \
520      READ_CAPTURE_NAME8(p, cn8, cn16, re)      READ_CAPTURE_NAME8(p, cn8, cn16, cn32, re)
521    
522  #define SET_PCRE_CALLOUT(callout) \  #define SET_PCRE_CALLOUT(callout) \
523    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
524        SET_PCRE_CALLOUT32(callout); \
525      else if (pcre_mode == PCRE16_MODE) \
526      SET_PCRE_CALLOUT16(callout); \      SET_PCRE_CALLOUT16(callout); \
527    else \    else \
528      SET_PCRE_CALLOUT8(callout)      SET_PCRE_CALLOUT8(callout)
529    
530  #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))
531    
532  #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \  #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
533    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
534        PCRE_ASSIGN_JIT_STACK32(extra, callback, userdata); \
535      else if (pcre_mode == PCRE16_MODE) \
536      PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata); \      PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata); \
537    else \    else \
538      PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata)      PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata)
539    
540  #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \  #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
541    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
542        PCRE_COMPILE32(re, pat, options, error, erroffset, tables); \
543      else if (pcre_mode == PCRE16_MODE) \
544      PCRE_COMPILE16(re, pat, options, error, erroffset, tables); \      PCRE_COMPILE16(re, pat, options, error, erroffset, tables); \
545    else \    else \
546      PCRE_COMPILE8(re, pat, options, error, erroffset, tables)      PCRE_COMPILE8(re, pat, options, error, erroffset, tables)
# Line 417  version is called. ----- */ Line 549  version is called. ----- */
549    
550  #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \  #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
551      namesptr, cbuffer, size) \      namesptr, cbuffer, size) \
552    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
553        PCRE_COPY_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
554          namesptr, cbuffer, size); \
555      else if (pcre_mode == PCRE16_MODE) \
556      PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \      PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
557        namesptr, cbuffer, size); \        namesptr, cbuffer, size); \
558    else \    else \
# Line 425  version is called. ----- */ Line 560  version is called. ----- */
560        namesptr, cbuffer, size)        namesptr, cbuffer, size)
561    
562  #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \  #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \
563    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
564        PCRE_COPY_SUBSTRING32(rc, bptr, offsets, count, i, cbuffer, size); \
565      else if (pcre_mode == PCRE16_MODE) \
566      PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size); \      PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size); \
567    else \    else \
568      PCRE_COPY_SUBSTRING8(rc, bptr, offsets, count, i, cbuffer, size)      PCRE_COPY_SUBSTRING8(rc, bptr, offsets, count, i, cbuffer, size)
569    
570  #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \
571      offsets, size_offsets, workspace, size_workspace) \      offsets, size_offsets, workspace, size_workspace) \
572    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
573        PCRE_DFA_EXEC32(count, re, extra, bptr, len, start_offset, options, \
574          offsets, size_offsets, workspace, size_workspace); \
575      else if (pcre_mode == PCRE16_MODE) \
576      PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \      PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \
577        offsets, size_offsets, workspace, size_workspace); \        offsets, size_offsets, workspace, size_workspace); \
578    else \    else \
# Line 441  version is called. ----- */ Line 581  version is called. ----- */
581    
582  #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
583      offsets, size_offsets) \      offsets, size_offsets) \
584    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
585        PCRE_EXEC32(count, re, extra, bptr, len, start_offset, options, \
586          offsets, size_offsets); \
587      else if (pcre_mode == PCRE16_MODE) \
588      PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \      PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \
589        offsets, size_offsets); \        offsets, size_offsets); \
590    else \    else \
# Line 449  version is called. ----- */ Line 592  version is called. ----- */
592        offsets, size_offsets)        offsets, size_offsets)
593    
594  #define PCRE_FREE_STUDY(extra) \  #define PCRE_FREE_STUDY(extra) \
595    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
596        PCRE_FREE_STUDY32(extra); \
597      else if (pcre_mode == PCRE16_MODE) \
598      PCRE_FREE_STUDY16(extra); \      PCRE_FREE_STUDY16(extra); \
599    else \    else \
600      PCRE_FREE_STUDY8(extra)      PCRE_FREE_STUDY8(extra)
601    
602  #define PCRE_FREE_SUBSTRING(substring) \  #define PCRE_FREE_SUBSTRING(substring) \
603    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
604        PCRE_FREE_SUBSTRING32(substring); \
605      else if (pcre_mode == PCRE16_MODE) \
606      PCRE_FREE_SUBSTRING16(substring); \      PCRE_FREE_SUBSTRING16(substring); \
607    else \    else \
608      PCRE_FREE_SUBSTRING8(substring)      PCRE_FREE_SUBSTRING8(substring)
609    
610  #define PCRE_FREE_SUBSTRING_LIST(listptr) \  #define PCRE_FREE_SUBSTRING_LIST(listptr) \
611    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
612        PCRE_FREE_SUBSTRING_LIST32(listptr); \
613      else if (pcre_mode == PCRE16_MODE) \
614      PCRE_FREE_SUBSTRING_LIST16(listptr); \      PCRE_FREE_SUBSTRING_LIST16(listptr); \
615    else \    else \
616      PCRE_FREE_SUBSTRING_LIST8(listptr)      PCRE_FREE_SUBSTRING_LIST8(listptr)
617    
618  #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \  #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
619      getnamesptr, subsptr) \      getnamesptr, subsptr) \
620    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
621        PCRE_GET_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
622          getnamesptr, subsptr); \
623      else if (pcre_mode == PCRE16_MODE) \
624      PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \      PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
625        getnamesptr, subsptr); \        getnamesptr, subsptr); \
626    else \    else \
# Line 476  version is called. ----- */ Line 628  version is called. ----- */
628        getnamesptr, subsptr)        getnamesptr, subsptr)
629    
630  #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \  #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \
631    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
632        PCRE_GET_STRINGNUMBER32(n, rc, ptr); \
633      else if (pcre_mode == PCRE16_MODE) \
634      PCRE_GET_STRINGNUMBER16(n, rc, ptr); \      PCRE_GET_STRINGNUMBER16(n, rc, ptr); \
635    else \    else \
636      PCRE_GET_STRINGNUMBER8(n, rc, ptr)      PCRE_GET_STRINGNUMBER8(n, rc, ptr)
637    
638  #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \  #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \
639    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
640        PCRE_GET_SUBSTRING32(rc, bptr, use_offsets, count, i, subsptr); \
641      else if (pcre_mode == PCRE16_MODE) \
642      PCRE_GET_SUBSTRING16(rc, bptr, use_offsets, count, i, subsptr); \      PCRE_GET_SUBSTRING16(rc, bptr, use_offsets, count, i, subsptr); \
643    else \    else \
644      PCRE_GET_SUBSTRING8(rc, bptr, use_offsets, count, i, subsptr)      PCRE_GET_SUBSTRING8(rc, bptr, use_offsets, count, i, subsptr)
645    
646  #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \  #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \
647    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
648        PCRE_GET_SUBSTRING_LIST32(rc, bptr, offsets, count, listptr); \
649      else if (pcre_mode == PCRE16_MODE) \
650      PCRE_GET_SUBSTRING_LIST16(rc, bptr, offsets, count, listptr); \      PCRE_GET_SUBSTRING_LIST16(rc, bptr, offsets, count, listptr); \
651    else \    else \
652      PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)      PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)
653    
654  #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \  #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
655    (use_pcre16 ? \    (pcre_mode == PCRE32_MODE ? \
656       PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \       PCRE_JIT_STACK_ALLOC32(startsize, maxsize) \
657      :PCRE_JIT_STACK_ALLOC8(startsize, maxsize))      : pcre_mode == PCRE16_MODE ? \
658          PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \
659          : PCRE_JIT_STACK_ALLOC8(startsize, maxsize))
660    
661  #define PCRE_JIT_STACK_FREE(stack) \  #define PCRE_JIT_STACK_FREE(stack) \
662    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
663        PCRE_JIT_STACK_FREE32(stack); \
664      else if (pcre_mode == PCRE16_MODE) \
665      PCRE_JIT_STACK_FREE16(stack); \      PCRE_JIT_STACK_FREE16(stack); \
666    else \    else \
667      PCRE_JIT_STACK_FREE8(stack)      PCRE_JIT_STACK_FREE8(stack)
668    
669  #define PCRE_MAKETABLES \  #define PCRE_MAKETABLES \
670    (use_pcre16? pcre16_maketables() : pcre_maketables())    (pcre_mode == PCRE32_MODE ? pcre32_maketables() : pcre_mode == PCRE16_MODE ? pcre16_maketables() : pcre_maketables())
671    
672  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \
673    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
674        PCRE_PATTERN_TO_HOST_BYTE_ORDER32(rc, re, extra, tables); \
675      else if (pcre_mode == PCRE16_MODE) \
676      PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables); \      PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables); \
677    else \    else \
678      PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables)      PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables)
679    
680  #define PCRE_PRINTINT(re, outfile, debug_lengths) \  #define PCRE_PRINTINT(re, outfile, debug_lengths) \
681    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
682        PCRE_PRINTINT32(re, outfile, debug_lengths); \
683      else if (pcre_mode == PCRE16_MODE) \
684      PCRE_PRINTINT16(re, outfile, debug_lengths); \      PCRE_PRINTINT16(re, outfile, debug_lengths); \
685    else \    else \
686      PCRE_PRINTINT8(re, outfile, debug_lengths)      PCRE_PRINTINT8(re, outfile, debug_lengths)
687    
688  #define PCRE_STUDY(extra, re, options, error) \  #define PCRE_STUDY(extra, re, options, error) \
689    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
690        PCRE_STUDY32(extra, re, options, error); \
691      else if (pcre_mode == PCRE16_MODE) \
692      PCRE_STUDY16(extra, re, options, error); \      PCRE_STUDY16(extra, re, options, error); \
693    else \    else \
694      PCRE_STUDY8(extra, re, options, error)      PCRE_STUDY8(extra, re, options, error)
695    
696    
697    /* ----- Two out of three modes are supported ----- */
698    
699    #else
700    
701    /* We can use some macro trickery to make a single set of definitions work in
702    the three different cases. */
703    
704    /* ----- 32-bit and 16-bit but not 8-bit supported ----- */
705    
706    #if defined(SUPPORT_PCRE32) && defined(SUPPORT_PCRE16)
707    #define BITONE 32
708    #define BITTWO 16
709    
710    /* ----- 32-bit and 8-bit but not 16-bit supported ----- */
711    
712    #elif defined(SUPPORT_PCRE32) && defined(SUPPORT_PCRE8)
713    #define BITONE 32
714    #define BITTWO 8
715    
716    /* ----- 16-bit and 8-bit but not 32-bit supported ----- */
717    
718    #else
719    #define BITONE 16
720    #define BITTWO 8
721    #endif
722    
723    #define glue(a,b) a##b
724    #define G(a,b) glue(a,b)
725    
726    
727    /* ----- Common macros for two-mode cases ----- */
728    
729    #define PCHARS(lv, p, offset, len, f) \
730      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
731        G(PCHARS,BITONE)(lv, p, offset, len, f); \
732      else \
733        G(PCHARS,BITTWO)(lv, p, offset, len, f)
734    
735    #define PCHARSV(p, offset, len, f) \
736      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
737        G(PCHARSV,BITONE)(p, offset, len, f); \
738      else \
739        G(PCHARSV,BITTWO)(p, offset, len, f)
740    
741    #define READ_CAPTURE_NAME(p, cn8, cn16, cn32, re) \
742      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
743        G(READ_CAPTURE_NAME,BITONE)(p, cn8, cn16, cn32, re); \
744      else \
745        G(READ_CAPTURE_NAME,BITTWO)(p, cn8, cn16, cn32, re)
746    
747    #define SET_PCRE_CALLOUT(callout) \
748      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
749        G(SET_PCRE_CALLOUT,BITONE)(callout); \
750      else \
751        G(SET_PCRE_CALLOUT,BITTWO)(callout)
752    
753    #define STRLEN(p) ((pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
754      G(STRLEN,BITONE)(p) : G(STRLEN,BITTWO)(p))
755    
756    #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
757      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
758        G(PCRE_ASSIGN_JIT_STACK,BITONE)(extra, callback, userdata); \
759      else \
760        G(PCRE_ASSIGN_JIT_STACK,BITTWO)(extra, callback, userdata)
761    
762    #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
763      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
764        G(PCRE_COMPILE,BITONE)(re, pat, options, error, erroffset, tables); \
765      else \
766        G(PCRE_COMPILE,BITTWO)(re, pat, options, error, erroffset, tables)
767    
768    #define PCRE_CONFIG G(G(pcre,BITONE),_config)
769    
770    #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
771        namesptr, cbuffer, size) \
772      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
773        G(PCRE_COPY_NAMED_SUBSTRING,BITONE)(rc, re, bptr, offsets, count, \
774          namesptr, cbuffer, size); \
775      else \
776        G(PCRE_COPY_NAMED_SUBSTRING,BITTWO)(rc, re, bptr, offsets, count, \
777          namesptr, cbuffer, size)
778    
779    #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \
780      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
781        G(PCRE_COPY_SUBSTRING,BITONE)(rc, bptr, offsets, count, i, cbuffer, size); \
782      else \
783        G(PCRE_COPY_SUBSTRING,BITTWO)(rc, bptr, offsets, count, i, cbuffer, size)
784    
785    #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \
786        offsets, size_offsets, workspace, size_workspace) \
787      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
788        G(PCRE_DFA_EXEC,BITONE)(count, re, extra, bptr, len, start_offset, options, \
789          offsets, size_offsets, workspace, size_workspace); \
790      else \
791        G(PCRE_DFA_EXEC,BITTWO)(count, re, extra, bptr, len, start_offset, options, \
792          offsets, size_offsets, workspace, size_workspace)
793    
794    #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
795        offsets, size_offsets) \
796      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
797        G(PCRE_EXEC,BITONE)(count, re, extra, bptr, len, start_offset, options, \
798          offsets, size_offsets); \
799      else \
800        G(PCRE_EXEC,BITTWO)(count, re, extra, bptr, len, start_offset, options, \
801          offsets, size_offsets)
802    
803    #define PCRE_FREE_STUDY(extra) \
804      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
805        G(PCRE_FREE_STUDY,BITONE)(extra); \
806      else \
807        G(PCRE_FREE_STUDY,BITTWO)(extra)
808    
809    #define PCRE_FREE_SUBSTRING(substring) \
810      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
811        G(PCRE_FREE_SUBSTRING,BITONE)(substring); \
812      else \
813        G(PCRE_FREE_SUBSTRING,BITTWO)(substring)
814    
815    #define PCRE_FREE_SUBSTRING_LIST(listptr) \
816      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
817        G(PCRE_FREE_SUBSTRING_LIST,BITONE)(listptr); \
818      else \
819        G(PCRE_FREE_SUBSTRING_LIST,BITTWO)(listptr)
820    
821    #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
822        getnamesptr, subsptr) \
823      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
824        G(PCRE_GET_NAMED_SUBSTRING,BITONE)(rc, re, bptr, offsets, count, \
825          getnamesptr, subsptr); \
826      else \
827        G(PCRE_GET_NAMED_SUBSTRING,BITTWO)(rc, re, bptr, offsets, count, \
828          getnamesptr, subsptr)
829    
830    #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \
831      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
832        G(PCRE_GET_STRINGNUMBER,BITONE)(n, rc, ptr); \
833      else \
834        G(PCRE_GET_STRINGNUMBER,BITTWO)(n, rc, ptr)
835    
836    #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \
837      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
838        G(PCRE_GET_SUBSTRING,BITONE)(rc, bptr, use_offsets, count, i, subsptr); \
839      else \
840        G(PCRE_GET_SUBSTRING,BITTWO)(rc, bptr, use_offsets, count, i, subsptr)
841    
842    #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \
843      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
844        G(PCRE_GET_SUBSTRING_LIST,BITONE)(rc, bptr, offsets, count, listptr); \
845      else \
846        G(PCRE_GET_SUBSTRING_LIST,BITTWO)(rc, bptr, offsets, count, listptr)
847    
848    #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
849      (pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
850         G(PCRE_JIT_STACK_ALLOC,BITONE)(startsize, maxsize) \
851        : G(PCRE_JIT_STACK_ALLOC,BITTWO)(startsize, maxsize)
852    
853    #define PCRE_JIT_STACK_FREE(stack) \
854      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
855        G(PCRE_JIT_STACK_FREE,BITONE)(stack); \
856      else \
857        G(PCRE_JIT_STACK_FREE,BITTWO)(stack)
858    
859    #define PCRE_MAKETABLES \
860      (pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
861        G(G(pcre,BITONE),_maketables)() : G(G(pcre,BITTWO),_maketables)()
862    
863    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \
864      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
865        G(PCRE_PATTERN_TO_HOST_BYTE_ORDER,BITONE)(rc, re, extra, tables); \
866      else \
867        G(PCRE_PATTERN_TO_HOST_BYTE_ORDER,BITTWO)(rc, re, extra, tables)
868    
869    #define PCRE_PRINTINT(re, outfile, debug_lengths) \
870      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
871        G(PCRE_PRINTINT,BITONE)(re, outfile, debug_lengths); \
872      else \
873        G(PCRE_PRINTINT,BITTWO)(re, outfile, debug_lengths)
874    
875    #define PCRE_STUDY(extra, re, options, error) \
876      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
877        G(PCRE_STUDY,BITONE)(extra, re, options, error); \
878      else \
879        G(PCRE_STUDY,BITTWO)(extra, re, options, error)
880    
881    #endif  /* Two out of three modes */
882    
883    /* ----- End of cases where more than one mode is supported ----- */
884    
885    
886  /* ----- Only 8-bit mode is supported ----- */  /* ----- Only 8-bit mode is supported ----- */
887    
888  #elif defined SUPPORT_PCRE8  #elif defined SUPPORT_PCRE8
# Line 557  version is called. ----- */ Line 915  version is called. ----- */
915    
916  /* ----- Only 16-bit mode is supported ----- */  /* ----- Only 16-bit mode is supported ----- */
917    
918  #else  #elif defined SUPPORT_PCRE16
919  #define CHAR_SIZE                 2  #define CHAR_SIZE                 2
920  #define PCHARS                    PCHARS16  #define PCHARS                    PCHARS16
921  #define PCHARSV                   PCHARSV16  #define PCHARSV                   PCHARSV16
# Line 584  version is called. ----- */ Line 942  version is called. ----- */
942  #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
943  #define PCRE_PRINTINT             PCRE_PRINTINT16  #define PCRE_PRINTINT             PCRE_PRINTINT16
944  #define PCRE_STUDY                PCRE_STUDY16  #define PCRE_STUDY                PCRE_STUDY16
945    
946    /* ----- Only 32-bit mode is supported ----- */
947    
948    #elif defined SUPPORT_PCRE32
949    #define CHAR_SIZE                 4
950    #define PCHARS                    PCHARS32
951    #define PCHARSV                   PCHARSV32
952    #define READ_CAPTURE_NAME         READ_CAPTURE_NAME32
953    #define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT32
954    #define STRLEN                    STRLEN32
955    #define PCRE_ASSIGN_JIT_STACK     PCRE_ASSIGN_JIT_STACK32
956    #define PCRE_COMPILE              PCRE_COMPILE32
957    #define PCRE_CONFIG               pcre32_config
958    #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING32
959    #define PCRE_COPY_SUBSTRING       PCRE_COPY_SUBSTRING32
960    #define PCRE_DFA_EXEC             PCRE_DFA_EXEC32
961    #define PCRE_EXEC                 PCRE_EXEC32
962    #define PCRE_FREE_STUDY           PCRE_FREE_STUDY32
963    #define PCRE_FREE_SUBSTRING       PCRE_FREE_SUBSTRING32
964    #define PCRE_FREE_SUBSTRING_LIST  PCRE_FREE_SUBSTRING_LIST32
965    #define PCRE_GET_NAMED_SUBSTRING  PCRE_GET_NAMED_SUBSTRING32
966    #define PCRE_GET_STRINGNUMBER     PCRE_GET_STRINGNUMBER32
967    #define PCRE_GET_SUBSTRING        PCRE_GET_SUBSTRING32
968    #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST32
969    #define PCRE_JIT_STACK_ALLOC      PCRE_JIT_STACK_ALLOC32
970    #define PCRE_JIT_STACK_FREE       PCRE_JIT_STACK_FREE32
971    #define PCRE_MAKETABLES           pcre32_maketables()
972    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER32
973    #define PCRE_PRINTINT             PCRE_PRINTINT32
974    #define PCRE_STUDY                PCRE_STUDY32
975    
976  #endif  #endif
977    
978  /* ----- End of mode-specific function call macros ----- */  /* ----- End of mode-specific function call macros ----- */
# Line 599  version is called. ----- */ Line 988  version is called. ----- */
988  #endif  #endif
989  #endif  #endif
990    
991    #if !defined NODFA
992    #define DFA_WS_DIMENSION 1000
993    #endif
994    
995  /* This is the default loop count for timing. */  /* This is the default loop count for timing. */
996    
997  #define LOOPREPEAT 500000  #define LOOPREPEAT 500000
# Line 613  static int callout_fail_count; Line 1006  static int callout_fail_count;
1006  static int callout_fail_id;  static int callout_fail_id;
1007  static int debug_lengths;  static int debug_lengths;
1008  static int first_callout;  static int first_callout;
1009    static int jit_was_used;
1010  static int locale_set = 0;  static int locale_set = 0;
1011  static int show_malloc;  static int show_malloc;
1012  static int use_utf;  static int use_utf;
# Line 624  static const unsigned char *last_callout Line 1018  static const unsigned char *last_callout
1018    
1019  static int buffer_size = 50000;  static int buffer_size = 50000;
1020  static pcre_uint8 *buffer = NULL;  static pcre_uint8 *buffer = NULL;
 static pcre_uint8 *dbuffer = NULL;  
1021  static pcre_uint8 *pbuffer = NULL;  static pcre_uint8 *pbuffer = NULL;
1022    
1023  /* 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. */  
1024    
1025  #ifdef COMPILE_PCRE16  #ifdef COMPILE_PCRE16
1026  #error COMPILE_PCRE16 must not be set when compiling pcretest.c  #error COMPILE_PCRE16 must not be set when compiling pcretest.c
1027  #endif  #endif
1028    
1029    #ifdef COMPILE_PCRE32
1030    #error COMPILE_PCRE32 must not be set when compiling pcretest.c
1031    #endif
1032    
1033    /* We need buffers for building 16/32-bit strings, and the tables of operator
1034    lengths that are used for 16/32-bit compiling, in order to swap bytes in a
1035    pattern for saving/reloading testing. Luckily, the data for these tables is
1036    defined as a macro. However, we must ensure that LINK_SIZE and IMM2_SIZE (which
1037    are used in the tables) are adjusted appropriately for the 16/32-bit world.
1038    LINK_SIZE is also used later in this program. */
1039    
1040    #ifdef SUPPORT_PCRE16
1041    #undef IMM2_SIZE
1042    #define IMM2_SIZE 1
1043    
1044  #if LINK_SIZE == 2  #if LINK_SIZE == 2
1045  #undef LINK_SIZE  #undef LINK_SIZE
1046  #define LINK_SIZE 1  #define LINK_SIZE 1
# Line 656  COMPILE_PCRE16 is *not* set. */ Line 1051  COMPILE_PCRE16 is *not* set. */
1051  #error LINK_SIZE must be either 2, 3, or 4  #error LINK_SIZE must be either 2, 3, or 4
1052  #endif  #endif
1053    
1054    static int buffer16_size = 0;
1055    static pcre_uint16 *buffer16 = NULL;
1056    static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };
1057    #endif  /* SUPPORT_PCRE16 */
1058    
1059    #ifdef SUPPORT_PCRE32
1060  #undef IMM2_SIZE  #undef IMM2_SIZE
1061  #define IMM2_SIZE 1  #define IMM2_SIZE 1
1062    #undef LINK_SIZE
1063    #define LINK_SIZE 1
1064    
1065  #endif /* SUPPORT_PCRE8 */  static int buffer32_size = 0;
1066    static pcre_uint32 *buffer32 = NULL;
1067    static const pcre_uint32 OP_lengths32[] = { OP_LENGTHS };
1068    #endif  /* SUPPORT_PCRE32 */
1069    
1070    /* If we have 8-bit support, default to it; if there is also 16-or 32-bit
1071    support, it can be changed by an option. If there is no 8-bit support, there
1072    must be 16-or 32-bit support, so default it to 1. */
1073    
1074  static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };  #if defined SUPPORT_PCRE8
1075  #endif  /* SUPPORT_PCRE16 */  static int pcre_mode = PCRE8_MODE;
1076    #elif defined SUPPORT_PCRE16
1077    static int pcre_mode = PCRE16_MODE;
1078    #elif defined SUPPORT_PCRE32
1079    static int pcre_mode = PCRE32_MODE;
1080    #endif
1081    
1082  /* If we have 8-bit support, default use_pcre16 to false; if there is also  /* JIT study options for -s+n and /S+n where '1' <= n <= '7'. */
 16-bit support, it can be changed by an option. If there is no 8-bit support,  
 there must be 16-bit support, so default it to 1. */  
1083    
1084  #ifdef SUPPORT_PCRE8  static int jit_study_bits[] =
1085  static int use_pcre16 = 0;    {
1086  #else    PCRE_STUDY_JIT_COMPILE,
1087  static int use_pcre16 = 1;    PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE,
1088  #endif    PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE,
1089      PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
1090      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
1091      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE + PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
1092      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE +
1093        PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE
1094    };
1095    
1096    #define PCRE_STUDY_ALLJIT (PCRE_STUDY_JIT_COMPILE | \
1097      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE | PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE)
1098    
1099  /* Textual explanations for runtime error codes */  /* Textual explanations for runtime error codes */
1100    
# Line 705  static const char *errtexts[] = { Line 1127  static const char *errtexts[] = {
1127    NULL,  /* SHORTUTF8/16 is handled specially */    NULL,  /* SHORTUTF8/16 is handled specially */
1128    "nested recursion at the same subject position",    "nested recursion at the same subject position",
1129    "JIT stack limit reached",    "JIT stack limit reached",
1130    "pattern compiled in wrong mode: 8-bit/16-bit error"    "pattern compiled in wrong mode: 8-bit/16-bit error",
1131      "pattern compiled with other endianness",
1132      "invalid data in workspace for DFA restart",
1133      "bad JIT option",
1134      "bad length"
1135  };  };
1136    
1137    
# Line 1057  return sys_errlist[n]; Line 1483  return sys_errlist[n];
1483  #endif /* HAVE_STRERROR */  #endif /* HAVE_STRERROR */
1484    
1485    
1486    
1487    /*************************************************
1488    *       Print newline configuration              *
1489    *************************************************/
1490    
1491    /*
1492    Arguments:
1493      rc         the return code from PCRE_CONFIG_NEWLINE
1494      isc        TRUE if called from "-C newline"
1495    Returns:     nothing
1496    */
1497    
1498    static void
1499    print_newline_config(int rc, BOOL isc)
1500    {
1501    const char *s = NULL;
1502    if (!isc) printf("  Newline sequence is ");
1503    switch(rc)
1504      {
1505      case CHAR_CR: s = "CR"; break;
1506      case CHAR_LF: s = "LF"; break;
1507      case (CHAR_CR<<8 | CHAR_LF): s = "CRLF"; break;
1508      case -1: s = "ANY"; break;
1509      case -2: s = "ANYCRLF"; break;
1510    
1511      default:
1512      printf("a non-standard value: 0x%04x\n", rc);
1513      return;
1514      }
1515    
1516    printf("%s\n", s);
1517    }
1518    
1519    
1520    
1521  /*************************************************  /*************************************************
1522  *         JIT memory callback                    *  *         JIT memory callback                    *
1523  *************************************************/  *************************************************/
1524    
1525  static pcre_jit_stack* jit_callback(void *arg)  static pcre_jit_stack* jit_callback(void *arg)
1526  {  {
1527    jit_was_used = TRUE;
1528  return (pcre_jit_stack *)arg;  return (pcre_jit_stack *)arg;
1529  }  }
1530    
1531    
1532  #if !defined NOUTF || defined SUPPORT_PCRE16  #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32
1533  /*************************************************  /*************************************************
1534  *            Convert UTF-8 string to value       *  *            Convert UTF-8 string to value       *
1535  *************************************************/  *************************************************/
# Line 1084  Returns:      >  0 => the number of byte Line 1546  Returns:      >  0 => the number of byte
1546  */  */
1547    
1548  static int  static int
1549  utf82ord(pcre_uint8 *utf8bytes, int *vptr)  utf82ord(pcre_uint8 *utf8bytes, pcre_uint32 *vptr)
1550  {  {
1551  int c = *utf8bytes++;  pcre_uint32 c = *utf8bytes++;
1552  int d = c;  pcre_uint32 d = c;
1553  int i, j, s;  int i, j, s;
1554    
1555  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 1115  for (j = 0; j < i; j++) Line 1577  for (j = 0; j < i; j++)
1577  /* Check that encoding was the correct unique one */  /* Check that encoding was the correct unique one */
1578    
1579  for (j = 0; j < utf8_table1_size; j++)  for (j = 0; j < utf8_table1_size; j++)
1580    if (d <= utf8_table1[j]) break;    if (d <= (pcre_uint32)utf8_table1[j]) break;
1581  if (j != i) return -(i+1);  if (j != i) return -(i+1);
1582    
1583  /* Valid value */  /* Valid value */
# Line 1127  return i+1; Line 1589  return i+1;
1589    
1590    
1591    
1592  #if !defined NOUTF || defined SUPPORT_PCRE16  #if defined SUPPORT_PCRE8 && !defined NOUTF
1593  /*************************************************  /*************************************************
1594  *       Convert character value to UTF-8         *  *       Convert character value to UTF-8         *
1595  *************************************************/  *************************************************/
# Line 1143  Returns:     number of characters placed Line 1605  Returns:     number of characters placed
1605  */  */
1606    
1607  static int  static int
1608  ord2utf8(int cvalue, pcre_uint8 *utf8bytes)  ord2utf8(pcre_uint32 cvalue, pcre_uint8 *utf8bytes)
1609  {  {
1610  register int i, j;  register int i, j;
1611    if (cvalue > 0x7fffffffu)
1612      return -1;
1613  for (i = 0; i < utf8_table1_size; i++)  for (i = 0; i < utf8_table1_size; i++)
1614    if (cvalue <= utf8_table1[i]) break;    if (cvalue <= (pcre_uint32)utf8_table1[i]) break;
1615  utf8bytes += i;  utf8bytes += i;
1616  for (j = i; j > 0; j--)  for (j = i; j > 0; j--)
1617   {   {
# Line 1216  if (!utf && !data) Line 1680  if (!utf && !data)
1680    
1681  else  else
1682    {    {
1683    int c = 0;    pcre_uint32 c = 0;
1684    while (len > 0)    while (len > 0)
1685      {      {
1686      int chlen = utf82ord(p, &c);      int chlen = utf82ord(p, &c);
# Line 1239  return pp - buffer16; Line 1703  return pp - buffer16;
1703  }  }
1704  #endif  #endif
1705    
1706    #ifdef SUPPORT_PCRE32
1707    /*************************************************
1708    *         Convert a string to 32-bit             *
1709    *************************************************/
1710    
1711    /* In non-UTF mode, the space needed for a 32-bit string is exactly four times the
1712    8-bit size. For a UTF-8 string, the size needed for UTF-32 is no more than four
1713    times, because up to 0xffff uses no more than 3 bytes in UTF-8 but possibly 4
1714    in UTF-32. Higher values use 4 bytes in UTF-8 and up to 4 bytes in UTF-32. The
1715    result is always left in buffer32.
1716    
1717    Note that this function does not object to surrogate values. This is
1718    deliberate; it makes it possible to construct UTF-32 strings that are invalid,
1719    for the purpose of testing that they are correctly faulted.
1720    
1721    Patterns to be converted are either plain ASCII or UTF-8; data lines are always
1722    in UTF-8 so that values greater than 255 can be handled.
1723    
1724    Arguments:
1725      data       TRUE if converting a data line; FALSE for a regex
1726      p          points to a byte string
1727      utf        true if UTF-8 (to be converted to UTF-32)
1728      len        number of bytes in the string (excluding trailing zero)
1729    
1730    Returns:     number of 32-bit data items used (excluding trailing zero)
1731                 OR -1 if a UTF-8 string is malformed
1732                 OR -2 if a value > 0x10ffff is encountered
1733                 OR -3 if an ill-formed value is encountered (i.e. a surrogate)
1734    */
1735    
1736    static int
1737    to32(int data, pcre_uint8 *p, int utf, int len)
1738    {
1739    pcre_uint32 *pp;
1740    
1741    if (buffer32_size < 4*len + 4)
1742      {
1743      if (buffer32 != NULL) free(buffer32);
1744      buffer32_size = 4*len + 4;
1745      buffer32 = (pcre_uint32 *)malloc(buffer32_size);
1746      if (buffer32 == NULL)
1747        {
1748        fprintf(stderr, "pcretest: malloc(%d) failed for buffer32\n", buffer32_size);
1749        exit(1);
1750        }
1751      }
1752    
1753    pp = buffer32;
1754    
1755    if (!utf && !data)
1756      {
1757      while (len-- > 0) *pp++ = *p++;
1758      }
1759    
1760    else
1761      {
1762      pcre_uint32 c = 0;
1763      while (len > 0)
1764        {
1765        int chlen = utf82ord(p, &c);
1766        if (chlen <= 0) return -1;
1767        if (utf)
1768          {
1769          if (c > 0x10ffff) return -2;
1770          if (!data && (c & 0xfffff800u) == 0xd800u) return -3;
1771          }
1772    
1773        p += chlen;
1774        len -= chlen;
1775        *pp++ = c;
1776        }
1777      }
1778    
1779    *pp = 0;
1780    return pp - buffer32;
1781    }
1782    
1783    /* Check that a 32-bit character string is valid UTF-32.
1784    
1785    Arguments:
1786      string       points to the string
1787      length       length of string, or -1 if the string is zero-terminated
1788    
1789    Returns:       TRUE  if the string is a valid UTF-32 string
1790                   FALSE otherwise
1791    */
1792    
1793    #ifdef SUPPORT_UTF
1794    static BOOL
1795    valid_utf32(pcre_uint32 *string, int length)
1796    {
1797    register pcre_uint32 *p;
1798    register pcre_uint32 c;
1799    
1800    for (p = string; length-- > 0; p++)
1801      {
1802      c = *p;
1803    
1804      if (c > 0x10ffffu)
1805        return FALSE;
1806    
1807      /* A surrogate */
1808      if ((c & 0xfffff800u) == 0xd800u)
1809        return FALSE;
1810    
1811      /* Non-character */
1812      if ((c & 0xfffeu) == 0xfffeu || (c >= 0xfdd0u && c <= 0xfdefu))
1813        return FALSE;
1814      }
1815    
1816    return TRUE;
1817    }
1818    #endif /* SUPPORT_UTF */
1819    
1820    #endif
1821    
1822  /*************************************************  /*************************************************
1823  *        Read or extend an input line            *  *        Read or extend an input line            *
# Line 1276  for (;;) Line 1855  for (;;)
1855      {      {
1856      int dlen;      int dlen;
1857    
1858      /* If libreadline support is required, use readline() to read a line if the      /* If libreadline or libedit support is required, use readline() to read a
1859      input is a terminal. Note that readline() removes the trailing newline, so      line if the input is a terminal. Note that readline() removes the trailing
1860      we must put it back again, to be compatible with fgets(). */      newline, so we must put it back again, to be compatible with fgets(). */
1861    
1862  #ifdef SUPPORT_LIBREADLINE  #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
1863      if (isatty(fileno(f)))      if (isatty(fileno(f)))
1864        {        {
1865        size_t len;        size_t len;
# Line 1314  for (;;) Line 1893  for (;;)
1893      {      {
1894      int new_buffer_size = 2*buffer_size;      int new_buffer_size = 2*buffer_size;
1895      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);  
1896      pcre_uint8 *new_pbuffer = (pcre_uint8 *)malloc(new_buffer_size);      pcre_uint8 *new_pbuffer = (pcre_uint8 *)malloc(new_buffer_size);
1897    
1898      if (new_buffer == NULL || new_dbuffer == NULL || new_pbuffer == NULL)      if (new_buffer == NULL || new_pbuffer == NULL)
1899        {        {
1900        fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);        fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);
1901        exit(1);        exit(1);
# Line 1332  for (;;) Line 1910  for (;;)
1910      here = new_buffer + (here - buffer);      here = new_buffer + (here - buffer);
1911    
1912      free(buffer);      free(buffer);
     free(dbuffer);  
1913      free(pbuffer);      free(pbuffer);
1914    
1915      buffer = new_buffer;      buffer = new_buffer;
     dbuffer = new_dbuffer;  
1916      pbuffer = new_pbuffer;      pbuffer = new_pbuffer;
1917      }      }
1918    }    }
# Line 1379  return(result); Line 1955  return(result);
1955    
1956  /* Print a single character either literally, or as a hex escape. */  /* Print a single character either literally, or as a hex escape. */
1957    
1958  static int pchar(int c, FILE *f)  static int pchar(pcre_uint32 c, FILE *f)
1959  {  {
1960    int n = 0;
1961  if (PRINTOK(c))  if (PRINTOK(c))
1962    {    {
1963    if (f != NULL) fprintf(f, "%c", c);    if (f != NULL) fprintf(f, "%c", c);
# Line 1401  if (c < 0x100) Line 1978  if (c < 0x100)
1978      }      }
1979    }    }
1980    
1981  if (f != NULL) fprintf(f, "\\x{%02x}", c);  if (f != NULL) n = fprintf(f, "\\x{%02x}", c);
1982  return (c <= 0x000000ff)? 6 :  return n >= 0 ? n : 0;
        (c <= 0x00000fff)? 7 :  
        (c <= 0x0000ffff)? 8 :  
        (c <= 0x000fffff)? 9 : 10;  
1983  }  }
1984    
1985    
# Line 1420  If handed a NULL file, just counts chars Line 1994  If handed a NULL file, just counts chars
1994    
1995  static int pchars(pcre_uint8 *p, int length, FILE *f)  static int pchars(pcre_uint8 *p, int length, FILE *f)
1996  {  {
1997  int c = 0;  pcre_uint32 c = 0;
1998  int yield = 0;  int yield = 0;
1999    
2000  if (length < 0)  if (length < 0)
# Line 1465  return len; Line 2039  return len;
2039  #endif  /* SUPPORT_PCRE16 */  #endif  /* SUPPORT_PCRE16 */
2040    
2041    
2042    
2043    #ifdef SUPPORT_PCRE32
2044    /*************************************************
2045    *    Find length of 0-terminated 32-bit string   *
2046    *************************************************/
2047    
2048    static int strlen32(PCRE_SPTR32 p)
2049    {
2050    int len = 0;
2051    while (*p++ != 0) len++;
2052    return len;
2053    }
2054    #endif  /* SUPPORT_PCRE32 */
2055    
2056    
2057    
2058  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2059  /*************************************************  /*************************************************
2060  *           Print 16-bit character string        *  *           Print 16-bit character string        *
# Line 1482  if (length < 0) Line 2072  if (length < 0)
2072    
2073  while (length-- > 0)  while (length-- > 0)
2074    {    {
2075    int c = *p++ & 0xffff;    pcre_uint32 c = *p++ & 0xffff;
2076  #if !defined NOUTF  #if !defined NOUTF
2077    if (use_utf && c >= 0xD800 && c < 0xDC00 && length > 0)    if (use_utf && c >= 0xD800 && c < 0xDC00 && length > 0)
2078      {      {
# Line 1504  return yield; Line 2094  return yield;
2094    
2095    
2096    
2097    #ifdef SUPPORT_PCRE32
2098    /*************************************************
2099    *           Print 32-bit character string        *
2100    *************************************************/
2101    
2102    /* Must handle UTF-32 strings in utf mode. Yields number of characters printed.
2103    If handed a NULL file, just counts chars without printing. */
2104    
2105    #define UTF32_MASK (0x1fffffu)
2106    
2107    static int pchars32(PCRE_SPTR32 p, int length, BOOL utf, FILE *f)
2108    {
2109    int yield = 0;
2110    
2111    if (length < 0)
2112      length = strlen32(p);
2113    
2114    while (length-- > 0)
2115      {
2116      pcre_uint32 c = *p++;
2117      if (utf) c &= UTF32_MASK;
2118      yield += pchar(c, f);
2119      }
2120    
2121    return yield;
2122    }
2123    #endif  /* SUPPORT_PCRE32 */
2124    
2125    
2126    
2127  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
2128  /*************************************************  /*************************************************
2129  *     Read a capture name (8-bit) and check it   *  *     Read a capture name (8-bit) and check it   *
# Line 1557  return p; Line 2177  return p;
2177    
2178    
2179    
2180    #ifdef SUPPORT_PCRE32
2181    /*************************************************
2182    *     Read a capture name (32-bit) and check it  *
2183    *************************************************/
2184    
2185    /* Note that the text being read is 8-bit. */
2186    
2187    static pcre_uint8 *
2188    read_capture_name32(pcre_uint8 *p, pcre_uint32 **pp, pcre *re)
2189    {
2190    pcre_uint32 *npp = *pp;
2191    while (isalnum(*p)) *npp++ = *p++;
2192    *npp++ = 0;
2193    *npp = 0;
2194    if (pcre32_get_stringnumber((pcre32 *)re, (PCRE_SPTR32)(*pp)) < 0)
2195      {
2196      fprintf(outfile, "no parentheses with name \"");
2197      PCHARSV(*pp, 0, -1, outfile);
2198      fprintf(outfile, "\"\n");
2199      }
2200    *pp = npp;
2201    return p;
2202    }
2203    #endif  /* SUPPORT_PCRE32 */
2204    
2205    
2206    
2207  /*************************************************  /*************************************************
2208  *              Callout function                  *  *              Callout function                  *
2209  *************************************************/  *************************************************/
# Line 1714  free(block); Line 2361  free(block);
2361  *************************************************/  *************************************************/
2362    
2363  /* Get one piece of information from the pcre_fullinfo() function. When only  /* Get one piece of information from the pcre_fullinfo() function. When only
2364  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
2365  value, but the code is defensive.  value, but the code is defensive.
2366    
2367  Arguments:  Arguments:
# Line 1731  new_info(pcre *re, pcre_extra *study, in Line 2378  new_info(pcre *re, pcre_extra *study, in
2378  {  {
2379  int rc;  int rc;
2380    
2381  if (use_pcre16)  if (pcre_mode == PCRE32_MODE)
2382    #ifdef SUPPORT_PCRE32
2383      rc = pcre32_fullinfo((pcre32 *)re, (pcre32_extra *)study, option, ptr);
2384    #else
2385      rc = PCRE_ERROR_BADMODE;
2386    #endif
2387    else if (pcre_mode == PCRE16_MODE)
2388  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2389    rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);    rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);
2390  #else  #else
# Line 1747  else Line 2400  else
2400  if (rc < 0)  if (rc < 0)
2401    {    {
2402    fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,    fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
2403      use_pcre16? "16" : "", option);      pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "", option);
2404    if (rc == PCRE_ERROR_BADMODE)    if (rc == PCRE_ERROR_BADMODE)
2405      fprintf(outfile, "Running in %s-bit mode but pattern was compiled in "      fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
2406        "%s-bit mode\n", use_pcre16? "16":"8", use_pcre16? "8":"16");        "%d-bit mode\n", 8 * CHAR_SIZE,
2407          8 * (REAL_PCRE_FLAGS(re) & PCRE_MODE_MASK));
2408    }    }
2409    
2410  return rc;  return rc;
# Line 1799  bytes in the pattern itself. This is to Line 2453  bytes in the pattern itself. This is to
2453  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
2454  architecture. */  architecture. */
2455    
2456    #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
2457  static void  static void
2458  regexflip(pcre *ere, pcre_extra *extra)  regexflip8_or_16(pcre *ere, pcre_extra *extra)
2459  {  {
2460  REAL_PCRE *re = (REAL_PCRE *)ere;  real_pcre8_or_16 *re = (real_pcre8_or_16 *)ere;
2461  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2462  int op;  int op;
2463  pcre_uint16 *ptr = (pcre_uint16 *)re + re->name_table_offset;  pcre_uint16 *ptr = (pcre_uint16 *)re + re->name_table_offset;
# Line 1839  if (extra != NULL) Line 2494  if (extra != NULL)
2494  in the name table, if present, and then in the pattern itself. */  in the name table, if present, and then in the pattern itself. */
2495    
2496  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2497  if (!use_pcre16) return;  if (pcre_mode != PCRE16_MODE) return;
2498    
2499  while(TRUE)  while(TRUE)
2500    {    {
# Line 1977  while(TRUE) Line 2632  while(TRUE)
2632  /* Control should never reach here in 16 bit mode. */  /* Control should never reach here in 16 bit mode. */
2633  #endif /* SUPPORT_PCRE16 */  #endif /* SUPPORT_PCRE16 */
2634  }  }
2635    #endif /* SUPPORT_PCRE[8|16] */
2636    
2637    
2638    
2639    #if defined SUPPORT_PCRE32
2640    static void
2641    regexflip_32(pcre *ere, pcre_extra *extra)
2642    {
2643    real_pcre32 *re = (real_pcre32 *)ere;
2644    int op;
2645    pcre_uint32 *ptr = (pcre_uint32 *)re + re->name_table_offset;
2646    int length = re->name_count * re->name_entry_size;
2647    
2648    /* Always flip the bytes in the main data block and study blocks. */
2649    
2650    re->magic_number = REVERSED_MAGIC_NUMBER;
2651    re->size = swap_uint32(re->size);
2652    re->options = swap_uint32(re->options);
2653    re->flags = swap_uint16(re->flags);
2654    re->top_bracket = swap_uint16(re->top_bracket);
2655    re->top_backref = swap_uint16(re->top_backref);
2656    re->first_char = swap_uint32(re->first_char);
2657    re->req_char = swap_uint32(re->req_char);
2658    re->name_table_offset = swap_uint16(re->name_table_offset);
2659    re->name_entry_size = swap_uint16(re->name_entry_size);
2660    re->name_count = swap_uint16(re->name_count);
2661    
2662    if (extra != NULL)
2663      {
2664      pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
2665      rsd->size = swap_uint32(rsd->size);
2666      rsd->flags = swap_uint32(rsd->flags);
2667      rsd->minlength = swap_uint32(rsd->minlength);
2668      }
2669    
2670    /* In 32-bit mode we must swap bytes in the name table, if present, and then in
2671    the pattern itself. */
2672    
2673    while(TRUE)
2674      {
2675      /* Swap previous characters. */
2676      while (length-- > 0)
2677        {
2678        *ptr = swap_uint32(*ptr);
2679        ptr++;
2680        }
2681    
2682      /* Get next opcode. */
2683    
2684      length = 0;
2685      op = *ptr;
2686      *ptr++ = swap_uint32(op);
2687    
2688      switch (op)
2689        {
2690        case OP_END:
2691        return;
2692    
2693        default:
2694        length = OP_lengths32[op] - 1;
2695        break;
2696    
2697        case OP_CLASS:
2698        case OP_NCLASS:
2699        /* Skip the character bit map. */
2700        ptr += 32/sizeof(pcre_uint32);
2701        length = 0;
2702        break;
2703    
2704        case OP_XCLASS:
2705        /* LINK_SIZE can only be 1 in 32-bit mode. */
2706        length = (int)((unsigned int)(ptr[0]) - (1 + LINK_SIZE + 1));
2707    
2708        /* Reverse the size of the XCLASS instance. */
2709        *ptr = swap_uint32(*ptr);
2710        ptr++;
2711    
2712        op = *ptr;
2713        *ptr = swap_uint32(op);
2714        ptr++;
2715        if ((op & XCL_MAP) != 0)
2716          {
2717          /* Skip the character bit map. */
2718          ptr += 32/sizeof(pcre_uint32);
2719          length -= 32/sizeof(pcre_uint32);
2720          }
2721        break;
2722        }
2723      }
2724    /* Control should never reach here in 32 bit mode. */
2725    }
2726    
2727    #endif /* SUPPORT_PCRE32 */
2728    
2729    
2730    
2731    static void
2732    regexflip(pcre *ere, pcre_extra *extra)
2733    {
2734    #if defined SUPPORT_PCRE32
2735      if (REAL_PCRE_FLAGS(ere) & PCRE_MODE32)
2736        regexflip_32(ere, extra);
2737    #endif
2738    #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
2739      if (REAL_PCRE_FLAGS(ere) & (PCRE_MODE8 | PCRE_MODE16))
2740        regexflip8_or_16(ere, extra);
2741    #endif
2742    }
2743    
2744    
2745    
# Line 2096  usage(void) Line 2859  usage(void)
2859  {  {
2860  printf("Usage:     pcretest [options] [<input file> [<output file>]]\n\n");  printf("Usage:     pcretest [options] [<input file> [<output file>]]\n\n");
2861  printf("Input and output default to stdin and stdout.\n");  printf("Input and output default to stdin and stdout.\n");
2862  #ifdef SUPPORT_LIBREADLINE  #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
2863  printf("If input is a terminal, readline() is used to read from it.\n");  printf("If input is a terminal, readline() is used to read from it.\n");
2864  #else  #else
2865  printf("This version of pcretest is not linked with readline().\n");  printf("This version of pcretest is not linked with readline().\n");
# Line 2105  printf("\nOptions:\n"); Line 2868  printf("\nOptions:\n");
2868  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2869  printf("  -16      use the 16-bit library\n");  printf("  -16      use the 16-bit library\n");
2870  #endif  #endif
2871    #ifdef SUPPORT_PCRE32
2872    printf("  -32      use the 32-bit library\n");
2873    #endif
2874  printf("  -b       show compiled code\n");  printf("  -b       show compiled code\n");
2875  printf("  -C       show PCRE compile-time options and exit\n");  printf("  -C       show PCRE compile-time options and exit\n");
2876  printf("  -C arg   show a specific compile-time option\n");  printf("  -C arg   show a specific compile-time option\n");
# Line 2112  printf("           and exit with its val Line 2878  printf("           and exit with its val
2878  printf("     linksize     internal link size [2, 3, 4]\n");  printf("     linksize     internal link size [2, 3, 4]\n");
2879  printf("     pcre8        8 bit library support enabled [0, 1]\n");  printf("     pcre8        8 bit library support enabled [0, 1]\n");
2880  printf("     pcre16       16 bit library support enabled [0, 1]\n");  printf("     pcre16       16 bit library support enabled [0, 1]\n");
2881    printf("     pcre32       32 bit library support enabled [0, 1]\n");
2882  printf("     utf          Unicode Transformation Format supported [0, 1]\n");  printf("     utf          Unicode Transformation Format supported [0, 1]\n");
2883  printf("     ucp          Unicode Properties supported [0, 1]\n");  printf("     ucp          Unicode Properties supported [0, 1]\n");
2884  printf("     jit          Just-in-time compiler supported [0, 1]\n");  printf("     jit          Just-in-time compiler supported [0, 1]\n");
# Line 2132  printf("  -q       quiet: do not output Line 2899  printf("  -q       quiet: do not output
2899  printf("  -S <n>   set stack size to <n> megabytes\n");  printf("  -S <n>   set stack size to <n> megabytes\n");
2900  printf("  -s       force each pattern to be studied at basic level\n"  printf("  -s       force each pattern to be studied at basic level\n"
2901         "  -s+      force each pattern to be studied, using JIT if available\n"         "  -s+      force each pattern to be studied, using JIT if available\n"
2902           "  -s++     ditto, verifying when JIT was actually used\n"
2903           "  -s+n     force each pattern to be studied, using JIT if available,\n"
2904           "             where 1 <= n <= 7 selects JIT options\n"
2905           "  -s++n    ditto, verifying when JIT was actually used\n"
2906         "  -t       time compilation and execution\n");         "  -t       time compilation and execution\n");
2907  printf("  -t <n>   time compilation and execution, repeating <n> times\n");  printf("  -t <n>   time compilation and execution, repeating <n> times\n");
2908  printf("  -tm      time execution (matching) only\n");  printf("  -tm      time execution (matching) only\n");
# Line 2166  int quiet = 0; Line 2937  int quiet = 0;
2937  int size_offsets = 45;  int size_offsets = 45;
2938  int size_offsets_max;  int size_offsets_max;
2939  int *offsets = NULL;  int *offsets = NULL;
 #if !defined NOPOSIX  
 int posix = 0;  
 #endif  
2940  int debug = 0;  int debug = 0;
2941  int done = 0;  int done = 0;
2942  int all_use_dfa = 0;  int all_use_dfa = 0;
2943    int verify_jit = 0;
2944  int yield = 0;  int yield = 0;
2945    #ifdef SUPPORT_PCRE32
2946    int mask_utf32 = 0;
2947    #endif
2948  int stack_size;  int stack_size;
2949    pcre_uint8 *dbuffer = NULL;
2950    size_t dbuffer_size = 1u << 14;
2951    
2952    #if !defined NOPOSIX
2953    int posix = 0;
2954    #endif
2955    #if !defined NODFA
2956    int *dfa_workspace = NULL;
2957    #endif
2958    
2959  pcre_jit_stack *jit_stack = NULL;  pcre_jit_stack *jit_stack = NULL;
2960    
2961  /* These vectors store, end-to-end, a list of zero-terminated captured  /* These vectors store, end-to-end, a list of zero-terminated captured
2962  substring names, each list itself being terminated by an empty name. Assume  substring names, each list itself being terminated by an empty name. Assume
2963  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
2964  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
2965  for the actual memory, to ensure alignment. */  for the actual memory, to ensure alignment. */
2966    
2967  pcre_uint16 copynames[1024];  pcre_uint32 copynames[1024];
2968  pcre_uint16 getnames[1024];  pcre_uint32 getnames[1024];
2969    
2970    #ifdef SUPPORT_PCRE32
2971    pcre_uint32 *cn32ptr;
2972    pcre_uint32 *gn32ptr;
2973    #endif
2974    
2975  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2976    pcre_uint16 *copynames16 = (pcre_uint16 *)copynames;
2977    pcre_uint16 *getnames16 = (pcre_uint16 *)getnames;
2978  pcre_uint16 *cn16ptr;  pcre_uint16 *cn16ptr;
2979  pcre_uint16 *gn16ptr;  pcre_uint16 *gn16ptr;
2980  #endif  #endif
# Line 2199  pcre_uint8 *gn8ptr; Line 2987  pcre_uint8 *gn8ptr;
2987  #endif  #endif
2988    
2989  /* Get buffers from malloc() so that valgrind will check their misuse when  /* Get buffers from malloc() so that valgrind will check their misuse when
2990  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-
2991  buffer (buffer16) is obtained only if needed. */  and 32-bit buffers (buffer16, buffer32) are obtained only if needed. */
2992    
2993  buffer = (pcre_uint8 *)malloc(buffer_size);  buffer = (pcre_uint8 *)malloc(buffer_size);
 dbuffer = (pcre_uint8 *)malloc(buffer_size);  
2994  pbuffer = (pcre_uint8 *)malloc(buffer_size);  pbuffer = (pcre_uint8 *)malloc(buffer_size);
2995    
2996  /* 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 2222  _setmode( _fileno( stdout ), _O_BINARY ) Line 3009  _setmode( _fileno( stdout ), _O_BINARY )
3009  /* Get the version number: both pcre_version() and pcre16_version() give the  /* Get the version number: both pcre_version() and pcre16_version() give the
3010  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. */
3011    
3012  #ifdef SUPPORT_PCRE8  #if defined SUPPORT_PCRE8
3013  version = pcre_version();  version = pcre_version();
3014  #else  #elif defined SUPPORT_PCRE16
3015  version = pcre16_version();  version = pcre16_version();
3016    #elif defined SUPPORT_PCRE32
3017    version = pcre32_version();
3018  #endif  #endif
3019    
3020  /* Scan options */  /* Scan options */
# Line 2233  version = pcre16_version(); Line 3022  version = pcre16_version();
3022  while (argc > 1 && argv[op][0] == '-')  while (argc > 1 && argv[op][0] == '-')
3023    {    {
3024    pcre_uint8 *endptr;    pcre_uint8 *endptr;
3025      char *arg = argv[op];
3026    
3027      if (strcmp(arg, "-m") == 0) showstore = 1;
3028      else if (strcmp(arg, "-s") == 0) force_study = 0;
3029    
3030    if (strcmp(argv[op], "-m") == 0) showstore = 1;    else if (strncmp(arg, "-s+", 3) == 0)
   else if (strcmp(argv[op], "-s") == 0) force_study = 0;  
   else if (strcmp(argv[op], "-s+") == 0)  
3031      {      {
3032        arg += 3;
3033        if (*arg == '+') { arg++; verify_jit = TRUE; }
3034      force_study = 1;      force_study = 1;
3035      force_study_options = PCRE_STUDY_JIT_COMPILE;      if (*arg == 0)
3036          force_study_options = jit_study_bits[6];
3037        else if (*arg >= '1' && *arg <= '7')
3038          force_study_options = jit_study_bits[*arg - '1'];
3039        else goto BAD_ARG;
3040        }
3041      else if (strcmp(arg, "-8") == 0)
3042        {
3043    #ifdef SUPPORT_PCRE8
3044        pcre_mode = PCRE8_MODE;
3045    #else
3046        printf("** This version of PCRE was built without 8-bit support\n");
3047        exit(1);
3048    #endif
3049      }      }
3050    else if (strcmp(argv[op], "-16") == 0)    else if (strcmp(arg, "-16") == 0)
3051      {      {
3052  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3053      use_pcre16 = 1;      pcre_mode = PCRE16_MODE;
3054  #else  #else
3055      printf("** This version of PCRE was built without 16-bit support\n");      printf("** This version of PCRE was built without 16-bit support\n");
3056      exit(1);      exit(1);
3057  #endif  #endif
3058      }      }
3059    else if (strcmp(argv[op], "-q") == 0) quiet = 1;    else if (strcmp(arg, "-32") == 0 || strcmp(arg, "-32+") == 0)
3060    else if (strcmp(argv[op], "-b") == 0) debug = 1;      {
3061    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;  #ifdef SUPPORT_PCRE32
3062    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;      pcre_mode = PCRE32_MODE;
3063    else if (strcmp(argv[op], "-M") == 0) default_find_match_limit = TRUE;      mask_utf32 = (strcmp(arg, "-32+") == 0);
3064    #else
3065        printf("** This version of PCRE was built without 32-bit support\n");
3066        exit(1);
3067    #endif
3068        }
3069      else if (strcmp(arg, "-q") == 0) quiet = 1;
3070      else if (strcmp(arg, "-b") == 0) debug = 1;
3071      else if (strcmp(arg, "-i") == 0) showinfo = 1;
3072      else if (strcmp(arg, "-d") == 0) showinfo = debug = 1;
3073      else if (strcmp(arg, "-M") == 0) default_find_match_limit = TRUE;
3074  #if !defined NODFA  #if !defined NODFA
3075    else if (strcmp(argv[op], "-dfa") == 0) all_use_dfa = 1;    else if (strcmp(arg, "-dfa") == 0) all_use_dfa = 1;
3076  #endif  #endif
3077    else if (strcmp(argv[op], "-o") == 0 && argc > 2 &&    else if (strcmp(arg, "-o") == 0 && argc > 2 &&
3078        ((size_offsets = get_value((pcre_uint8 *)argv[op+1], &endptr)),        ((size_offsets = get_value((pcre_uint8 *)argv[op+1], &endptr)),
3079          *endptr == 0))          *endptr == 0))
3080      {      {
3081      op++;      op++;
3082      argc--;      argc--;
3083      }      }
3084    else if (strcmp(argv[op], "-t") == 0 || strcmp(argv[op], "-tm") == 0)    else if (strcmp(arg, "-t") == 0 || strcmp(arg, "-tm") == 0)
3085      {      {
3086      int both = argv[op][2] == 0;      int both = arg[2] == 0;
3087      int temp;      int temp;
3088      if (argc > 2 && (temp = get_value((pcre_uint8 *)argv[op+1], &endptr),      if (argc > 2 && (temp = get_value((pcre_uint8 *)argv[op+1], &endptr),
3089                       *endptr == 0))                       *endptr == 0))
# Line 2279  while (argc > 1 && argv[op][0] == '-') Line 3095  while (argc > 1 && argv[op][0] == '-')
3095      else timeitm = LOOPREPEAT;      else timeitm = LOOPREPEAT;
3096      if (both) timeit = timeitm;      if (both) timeit = timeitm;
3097      }      }
3098    else if (strcmp(argv[op], "-S") == 0 && argc > 2 &&    else if (strcmp(arg, "-S") == 0 && argc > 2 &&
3099        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),
3100          *endptr == 0))          *endptr == 0))
3101      {      {
3102  #if defined(_WIN32) || defined(WIN32) || defined(__minix)  #if defined(_WIN32) || defined(WIN32) || defined(__minix) || defined(NATIVE_ZOS)
3103      printf("PCRE: -S not supported on this OS\n");      printf("PCRE: -S not supported on this OS\n");
3104      exit(1);      exit(1);
3105  #else  #else
# Line 2302  while (argc > 1 && argv[op][0] == '-') Line 3118  while (argc > 1 && argv[op][0] == '-')
3118  #endif  #endif
3119      }      }
3120  #if !defined NOPOSIX  #if !defined NOPOSIX
3121    else if (strcmp(argv[op], "-p") == 0) posix = 1;    else if (strcmp(arg, "-p") == 0) posix = 1;
3122  #endif  #endif
3123    else if (strcmp(argv[op], "-C") == 0)    else if (strcmp(arg, "-C") == 0)
3124      {      {
3125      int rc;      int rc;
3126      unsigned long int lrc;      unsigned long int lrc;
# Line 2316  while (argc > 1 && argv[op][0] == '-') Line 3132  while (argc > 1 && argv[op][0] == '-')
3132          (void)PCRE_CONFIG(PCRE_CONFIG_LINK_SIZE, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_LINK_SIZE, &rc);
3133          printf("%d\n", rc);          printf("%d\n", rc);
3134          yield = rc;          yield = rc;
         goto EXIT;  
3135          }          }
3136        if (strcmp(argv[op + 1], "pcre8") == 0)        else if (strcmp(argv[op + 1], "pcre8") == 0)
3137          {          {
3138  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
3139          printf("1\n");          printf("1\n");
# Line 2327  while (argc > 1 && argv[op][0] == '-') Line 3142  while (argc > 1 && argv[op][0] == '-')
3142          printf("0\n");          printf("0\n");
3143          yield = 0;          yield = 0;
3144  #endif  #endif
         goto EXIT;  
3145          }          }
3146        if (strcmp(argv[op + 1], "pcre16") == 0)        else if (strcmp(argv[op + 1], "pcre16") == 0)
3147          {          {
3148  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3149          printf("1\n");          printf("1\n");
# Line 2338  while (argc > 1 && argv[op][0] == '-') Line 3152  while (argc > 1 && argv[op][0] == '-')
3152          printf("0\n");          printf("0\n");
3153          yield = 0;          yield = 0;
3154  #endif  #endif
3155            }
3156          else if (strcmp(argv[op + 1], "pcre32") == 0)
3157            {
3158    #ifdef SUPPORT_PCRE32
3159            printf("1\n");
3160            yield = 1;
3161    #else
3162            printf("0\n");
3163            yield = 0;
3164    #endif
3165          goto EXIT;          goto EXIT;
3166          }          }
3167        if (strcmp(argv[op + 1], "utf") == 0)        if (strcmp(argv[op + 1], "utf") == 0)
3168          {          {
3169  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
3170          (void)pcre_config(PCRE_CONFIG_UTF8, &rc);          if (pcre_mode == PCRE8_MODE)
3171          printf("%d\n", rc);            (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
3172          yield = rc;  #endif
3173  #else  #ifdef SUPPORT_PCRE16
3174          (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);          if (pcre_mode == PCRE16_MODE)
3175              (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
3176    #endif
3177    #ifdef SUPPORT_PCRE32
3178            if (pcre_mode == PCRE32_MODE)
3179              (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
3180    #endif
3181          printf("%d\n", rc);          printf("%d\n", rc);
3182          yield = rc;          yield = rc;
 #endif  
3183          goto EXIT;          goto EXIT;
3184          }          }
3185        if (strcmp(argv[op + 1], "ucp") == 0)        else if (strcmp(argv[op + 1], "ucp") == 0)
3186          {          {
3187          (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
3188          printf("%d\n", rc);          printf("%d\n", rc);
3189          yield = rc;          yield = rc;
         goto EXIT;  
3190          }          }
3191        if (strcmp(argv[op + 1], "jit") == 0)        else if (strcmp(argv[op + 1], "jit") == 0)
3192          {          {
3193          (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);
3194          printf("%d\n", rc);          printf("%d\n", rc);
3195          yield = rc;          yield = rc;
         goto EXIT;  
3196          }          }
3197        if (strcmp(argv[op + 1], "newline") == 0)        else if (strcmp(argv[op + 1], "newline") == 0)
3198          {          {
3199          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3200          /* Note that these values are always the ASCII values, even          print_newline_config(rc, TRUE);
3201          in EBCDIC environments. CR is 13 and NL is 10. */          }
3202          printf("%s\n", (rc == 13)? "CR" :        else if (strcmp(argv[op + 1], "ebcdic") == 0)
3203            (rc == 10)? "LF" : (rc == (13<<8 | 10))? "CRLF" :          {
3204            (rc == -2)? "ANYCRLF" :  #ifdef EBCDIC
3205            (rc == -1)? "ANY" : "???");          printf("1\n");
3206          goto EXIT;          yield = 1;
3207    #else
3208            printf("0\n");
3209    #endif
3210            }
3211          else if (strcmp(argv[op + 1], "ebcdic-nl") == 0)
3212            {
3213    #ifdef EBCDIC
3214            printf("0x%02x\n", CHAR_LF);
3215    #else
3216            printf("0\n");
3217    #endif
3218            }
3219          else
3220            {
3221            printf("Unknown -C option: %s\n", argv[op + 1]);
3222          }          }
       printf("Unknown -C option: %s\n", argv[op + 1]);  
3223        goto EXIT;        goto EXIT;
3224        }        }
3225    
3226        /* No argument for -C: output all configuration information. */
3227    
3228      printf("PCRE version %s\n", version);      printf("PCRE version %s\n", version);
3229      printf("Compiled with\n");      printf("Compiled with\n");
3230    
3231    #ifdef EBCDIC
3232        printf("  EBCDIC code support: LF is 0x%02x\n", CHAR_LF);
3233    #endif
3234    
3235  /* 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
3236  are set, either both UTFs are supported or both are not supported. */  are set, either both UTFs are supported or both are not supported. */
3237    
3238  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE8
3239      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");  
3240      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
3241      printf("  %sUTF-8 support\n", rc? "" : "No ");        printf ("  %sUTF-8 support\n", rc ? "" : "No ");
3242  #else  #endif
3243      printf("  16-bit support only\n");  #ifdef SUPPORT_PCRE16
3244        printf("  16-bit support\n");
3245      (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);      (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
3246      printf("  %sUTF-16 support\n", rc? "" : "No ");      printf ("  %sUTF-16 support\n", rc ? "" : "No ");
3247    #endif
3248    #ifdef SUPPORT_PCRE32
3249        printf("  32-bit support\n");
3250        (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
3251        printf ("  %sUTF-32 support\n", rc ? "" : "No ");
3252  #endif  #endif
3253    
3254      (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
# Line 2417  are set, either both UTFs are supported Line 3263  are set, either both UTFs are supported
3263      else      else
3264        printf("  No just-in-time compiler support\n");        printf("  No just-in-time compiler support\n");
3265      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3266      /* Note that these values are always the ASCII values, even      print_newline_config(rc, FALSE);
     in EBCDIC environments. CR is 13 and NL is 10. */  
     printf("  Newline sequence is %s\n", (rc == 13)? "CR" :  
       (rc == 10)? "LF" : (rc == (13<<8 | 10))? "CRLF" :  
       (rc == -2)? "ANYCRLF" :  
       (rc == -1)? "ANY" : "???");  
3267      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);
3268      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :
3269                                       "all Unicode newlines");                                       "all Unicode newlines");
# Line 2444  are set, either both UTFs are supported Line 3285  are set, either both UTFs are supported
3285      printf("\n");      printf("\n");
3286      goto EXIT;      goto EXIT;
3287      }      }
3288    else if (strcmp(argv[op], "-help") == 0 ||    else if (strcmp(arg, "-help") == 0 ||
3289             strcmp(argv[op], "--help") == 0)             strcmp(arg, "--help") == 0)
3290      {      {
3291      usage();      usage();
3292      goto EXIT;      goto EXIT;
3293      }      }
3294    else    else
3295      {      {
3296      printf("** Unknown or malformed option %s\n", argv[op]);      BAD_ARG:
3297        printf("** Unknown or malformed option %s\n", arg);
3298      usage();      usage();
3299      yield = 1;      yield = 1;
3300      goto EXIT;      goto EXIT;
# Line 2513  pcre16_stack_malloc = stack_malloc; Line 3355  pcre16_stack_malloc = stack_malloc;
3355  pcre16_stack_free = stack_free;  pcre16_stack_free = stack_free;
3356  #endif  #endif
3357    
3358    #ifdef SUPPORT_PCRE32
3359    pcre32_malloc = new_malloc;
3360    pcre32_free = new_free;
3361    pcre32_stack_malloc = stack_malloc;
3362    pcre32_stack_free = stack_free;
3363    #endif
3364    
3365  /* Heading line unless quiet, then prompt for first regex if stdin */  /* Heading line unless quiet, then prompt for first regex if stdin */
3366    
3367  if (!quiet) fprintf(outfile, "PCRE version %s\n\n", version);  if (!quiet) fprintf(outfile, "PCRE version %s\n\n", version);
# Line 2550  while (!done) Line 3399  while (!done)
3399    int do_flip = 0;    int do_flip = 0;
3400    int erroroffset, len, delimiter, poffset;    int erroroffset, len, delimiter, poffset;
3401    
3402    #if !defined NODFA
3403      int dfa_matched = 0;
3404    #endif
3405    
3406    use_utf = 0;    use_utf = 0;
3407    debug_lengths = 1;    debug_lengths = 1;
3408    
# Line 2597  while (!done) Line 3450  while (!done)
3450        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];
3451    
3452      re = (pcre *)new_malloc(true_size);      re = (pcre *)new_malloc(true_size);
3453        if (re == NULL)
3454          {
3455          printf("** Failed to get %d bytes of memory for pcre object\n",
3456            (int)true_size);
3457          yield = 1;
3458          goto EXIT;
3459          }
3460      regex_gotten_store = first_gotten_store;      regex_gotten_store = first_gotten_store;
3461    
3462      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;
3463    
3464      magic = ((REAL_PCRE *)re)->magic_number;      magic = REAL_PCRE_MAGIC(re);
3465      if (magic != MAGIC_NUMBER)      if (magic != MAGIC_NUMBER)
3466        {        {
3467        if (swap_uint32(magic) == MAGIC_NUMBER)        if (swap_uint32(magic) == MAGIC_NUMBER)
# Line 2611  while (!done) Line 3471  while (!done)
3471        else        else
3472          {          {
3473          fprintf(outfile, "Data in %s is not a compiled PCRE regex\n", p);          fprintf(outfile, "Data in %s is not a compiled PCRE regex\n", p);
3474            new_free(re);
3475          fclose(f);          fclose(f);
3476          continue;          continue;
3477          }          }
# Line 2640  while (!done) Line 3501  while (!done)
3501            {            {
3502            PCRE_FREE_STUDY(extra);            PCRE_FREE_STUDY(extra);
3503            }            }
3504          if (re != NULL) new_free(re);          new_free(re);
3505          fclose(f);          fclose(f);
3506          continue;          continue;
3507          }          }
# Line 2656  while (!done) Line 3517  while (!done)
3517        PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, NULL);        PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, NULL);
3518        if (rc == PCRE_ERROR_BADMODE)        if (rc == PCRE_ERROR_BADMODE)
3519          {          {
3520            pcre_uint16 flags_in_host_byte_order;
3521            if (REAL_PCRE_MAGIC(re) == MAGIC_NUMBER)
3522              flags_in_host_byte_order = REAL_PCRE_FLAGS(re);
3523            else
3524              flags_in_host_byte_order = swap_uint16(REAL_PCRE_FLAGS(re));
3525          /* Simulate the result of the function call below. */          /* Simulate the result of the function call below. */
3526          fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,          fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
3527            use_pcre16? "16" : "", PCRE_INFO_OPTIONS);            pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "",
3528          fprintf(outfile, "Running in %s-bit mode but pattern was compiled in "            PCRE_INFO_OPTIONS);
3529            "%s-bit mode\n", use_pcre16? "16":"8", use_pcre16? "8":"16");          fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
3530              "%d-bit mode\n", 8 * CHAR_SIZE, 8 * (flags_in_host_byte_order & PCRE_MODE_MASK));
3531            new_free(re);
3532            fclose(f);
3533          continue;          continue;
3534          }          }
3535        }        }
3536    
3537      /* Need to know if UTF-8 for printing data strings. */      /* Need to know if UTF-8 for printing data strings. */
3538    
3539      if (new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options) < 0) continue;      if (new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options) < 0)
3540          {
3541          new_free(re);
3542          fclose(f);
3543          continue;
3544          }
3545      use_utf = (get_options & PCRE_UTF8) != 0;      use_utf = (get_options & PCRE_UTF8) != 0;
3546    
3547      fclose(f);      fclose(f);
# Line 2726  while (!done) Line 3600  while (!done)
3600    /* Look for options after final delimiter */    /* Look for options after final delimiter */
3601    
3602    options = 0;    options = 0;
3603    study_options = 0;    study_options = force_study_options;
3604    log_store = showstore;  /* default from command line */    log_store = showstore;  /* default from command line */
3605    
3606    while (*pp != 0)    while (*pp != 0)
# Line 2763  while (!done) Line 3637  while (!done)
3637  #endif  #endif
3638    
3639        case 'S':        case 'S':
3640        if (do_study == 0)        do_study = 1;
3641          for (;;)
3642          {          {
3643          do_study = 1;          switch (*pp++)
         if (*pp == '+')  
3644            {            {
3645            study_options |= PCRE_STUDY_JIT_COMPILE;            case 'S':
3646            pp++;            do_study = 0;
3647              no_force_study = 1;
3648              break;
3649    
3650              case '!':
3651              study_options |= PCRE_STUDY_EXTRA_NEEDED;
3652              break;
3653    
3654              case '+':
3655              if (*pp == '+')
3656                {
3657                verify_jit = TRUE;
3658                pp++;
3659                }
3660              if (*pp >= '1' && *pp <= '7')
3661                study_options |= jit_study_bits[*pp++ - '1'];
3662              else
3663                study_options |= jit_study_bits[6];
3664              break;
3665    
3666              case '-':
3667              study_options &= ~PCRE_STUDY_ALLJIT;
3668              break;
3669    
3670              default:
3671              pp--;
3672              goto ENDLOOP;
3673            }            }
3674          }          }
3675        else        ENDLOOP:
         {  
         do_study = 0;  
         no_force_study = 1;  
         }  
3676        break;        break;
3677    
3678        case 'U': options |= PCRE_UNGREEDY; break;        case 'U': options |= PCRE_UNGREEDY; break;
# Line 2895  while (!done) Line 3791  while (!done)
3791  #endif  /* !defined NOPOSIX */  #endif  /* !defined NOPOSIX */
3792    
3793      {      {
3794      /* In 16-bit mode, convert the input. */      /* In 16- or 32-bit mode, convert the input. */
3795    
3796  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3797      if (use_pcre16)      if (pcre_mode == PCRE16_MODE)
3798        {        {
3799        switch(to16(FALSE, p, options & PCRE_UTF8, (int)strlen((char *)p)))        switch(to16(FALSE, p, options & PCRE_UTF8, (int)strlen((char *)p)))
3800          {          {
# Line 2924  while (!done) Line 3820  while (!done)
3820        }        }
3821  #endif  #endif
3822    
3823    #ifdef SUPPORT_PCRE32
3824        if (pcre_mode == PCRE32_MODE)
3825          {
3826          switch(to32(FALSE, p, options & PCRE_UTF32, (int)strlen((char *)p)))
3827            {
3828            case -1:
3829            fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "
3830              "converted to UTF-32\n");
3831            goto SKIP_DATA;
3832    
3833            case -2:
3834            fprintf(outfile, "**Failed: character value greater than 0x10ffff "
3835              "cannot be converted to UTF-32\n");
3836            goto SKIP_DATA;
3837    
3838            case -3:
3839            fprintf(outfile, "**Failed: character value is ill-formed UTF-32\n");
3840            goto SKIP_DATA;
3841    
3842            default:
3843            break;
3844            }
3845          p = (pcre_uint8 *)buffer32;
3846          }
3847    #endif
3848    
3849      /* Compile many times when timing */      /* Compile many times when timing */
3850    
3851      if (timeit > 0)      if (timeit > 0)
# Line 2981  while (!done) Line 3903  while (!done)
3903      /* Extract the size for possible writing before possibly flipping it,      /* Extract the size for possible writing before possibly flipping it,
3904      and remember the store that was got. */      and remember the store that was got. */
3905    
3906      true_size = ((REAL_PCRE *)re)->size;      true_size = REAL_PCRE_SIZE(re);
3907      regex_gotten_store = first_gotten_store;      regex_gotten_store = first_gotten_store;
3908    
3909      /* Output code size information if requested */      /* Output code size information if requested */
3910    
3911      if (log_store)      if (log_store)
3912          {
3913          int name_count, name_entry_size, real_pcre_size;
3914    
3915          new_info(re, NULL, PCRE_INFO_NAMECOUNT, &name_count);
3916          new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
3917          real_pcre_size = 0;
3918    #ifdef SUPPORT_PCRE8
3919          if (REAL_PCRE_FLAGS(re) & PCRE_MODE8)
3920            real_pcre_size = sizeof(real_pcre);
3921    #endif
3922    #ifdef SUPPORT_PCRE16
3923          if (REAL_PCRE_FLAGS(re) & PCRE_MODE16)
3924            real_pcre_size = sizeof(real_pcre16);
3925    #endif
3926    #ifdef SUPPORT_PCRE32
3927          if (REAL_PCRE_FLAGS(re) & PCRE_MODE32)
3928            real_pcre_size = sizeof(real_pcre32);
3929    #endif
3930        fprintf(outfile, "Memory allocation (code space): %d\n",        fprintf(outfile, "Memory allocation (code space): %d\n",
3931          (int)(first_gotten_store -          (int)(first_gotten_store - real_pcre_size - name_count * name_entry_size));
3932                sizeof(REAL_PCRE) -        }
               ((REAL_PCRE *)re)->name_count * ((REAL_PCRE *)re)->name_entry_size));  
3933    
3934      /* 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
3935      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 3006  while (!done) Line 3945  while (!done)
3945          clock_t start_time = clock();          clock_t start_time = clock();
3946          for (i = 0; i < timeit; i++)          for (i = 0; i < timeit; i++)
3947            {            {
3948            PCRE_STUDY(extra, re, study_options | force_study_options, &error);            PCRE_STUDY(extra, re, study_options, &error);
3949            }            }
3950          time_taken = clock() - start_time;          time_taken = clock() - start_time;
3951          if (extra != NULL)          if (extra != NULL)
# Line 3017  while (!done) Line 3956  while (!done)
3956            (((double)time_taken * 1000.0) / (double)timeit) /            (((double)time_taken * 1000.0) / (double)timeit) /
3957              (double)CLOCKS_PER_SEC);              (double)CLOCKS_PER_SEC);
3958          }          }
3959        PCRE_STUDY(extra, re, study_options | force_study_options, &error);        PCRE_STUDY(extra, re, study_options, &error);
3960        if (error != NULL)        if (error != NULL)
3961          fprintf(outfile, "Failed to study: %s\n", error);          fprintf(outfile, "Failed to study: %s\n", error);
3962        else if (extra != NULL)        else if (extra != NULL)
# Line 3061  while (!done) Line 4000  while (!done)
4000      if (do_showinfo)      if (do_showinfo)
4001        {        {
4002        unsigned long int all_options;        unsigned long int all_options;
4003        int count, backrefmax, first_char, need_char, okpartial, jchanged,        pcre_uint32 first_char, need_char;
4004          hascrorlf;        int count, backrefmax, first_char_set, need_char_set, okpartial, jchanged,
4005            hascrorlf, maxlookbehind;
4006        int nameentrysize, namecount;        int nameentrysize, namecount;
4007        const pcre_uint8 *nametable;        const pcre_uint8 *nametable;
4008    
4009        if (new_info(re, NULL, PCRE_INFO_SIZE, &size) +        if (new_info(re, NULL, PCRE_INFO_SIZE, &size) +
4010            new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) +            new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) +
4011            new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax) +            new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax) +
4012            new_info(re, NULL, PCRE_INFO_FIRSTBYTE, &first_char) +            new_info(re, NULL, PCRE_INFO_FIRSTCHARACTER, &first_char) +
4013            new_info(re, NULL, PCRE_INFO_LASTLITERAL, &need_char) +            new_info(re, NULL, PCRE_INFO_FIRSTCHARACTERFLAGS, &first_char_set) +
4014              new_info(re, NULL, PCRE_INFO_REQUIREDCHAR, &need_char) +
4015              new_info(re, NULL, PCRE_INFO_REQUIREDCHARFLAGS, &need_char_set) +
4016            new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize) +            new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize) +
4017            new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount) +            new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount) +
4018            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +
4019            new_info(re, NULL, PCRE_INFO_OKPARTIAL, &okpartial) +            new_info(re, NULL, PCRE_INFO_OKPARTIAL, &okpartial) +
4020            new_info(re, NULL, PCRE_INFO_JCHANGED, &jchanged) +            new_info(re, NULL, PCRE_INFO_JCHANGED, &jchanged) +
4021            new_info(re, NULL, PCRE_INFO_HASCRORLF, &hascrorlf)            new_info(re, NULL, PCRE_INFO_HASCRORLF, &hascrorlf) +
4022              new_info(re, NULL, PCRE_INFO_MAXLOOKBEHIND, &maxlookbehind)
4023            != 0)            != 0)
4024          goto SKIP_DATA;          goto SKIP_DATA;
4025    
# Line 3093  while (!done) Line 4036  while (!done)
4036          fprintf(outfile, "Named capturing subpatterns:\n");          fprintf(outfile, "Named capturing subpatterns:\n");
4037          while (namecount-- > 0)          while (namecount-- > 0)
4038            {            {
4039  #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  
4040            int length = (int)STRLEN(nametable + imm2_size);            int length = (int)STRLEN(nametable + imm2_size);
4041            fprintf(outfile, "  ");            fprintf(outfile, "  ");
4042            PCHARSV(nametable, imm2_size, length, outfile);            PCHARSV(nametable, imm2_size, length, outfile);
4043            while (length++ < nameentrysize - imm2_size) putc(' ', outfile);            while (length++ < nameentrysize - imm2_size) putc(' ', outfile);
4044  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE32
4045            fprintf(outfile, "%3d\n", use_pcre16?            if (pcre_mode == PCRE32_MODE)
4046               (int)(((PCRE_SPTR16)nametable)[0])              fprintf(outfile, "%3d\n", (int)(((PCRE_SPTR32)nametable)[0]));
4047              :((int)nametable[0] << 8) | (int)nametable[1]);  #endif
4048            nametable += nameentrysize * (use_pcre16 ? 2 : 1);  #ifdef SUPPORT_PCRE16
4049  #else            if (pcre_mode == PCRE16_MODE)
4050            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;  
4051  #endif  #endif
4052    #ifdef SUPPORT_PCRE8
4053              if (pcre_mode == PCRE8_MODE)
4054                fprintf(outfile, "%3d\n", ((int)nametable[0] << 8) | (int)nametable[1]);
4055  #endif  #endif
4056              nametable += nameentrysize * CHAR_SIZE;
4057            }            }
4058          }          }
4059    
4060        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");
4061        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");
4062    
4063        all_options = ((REAL_PCRE *)re)->options;        all_options = REAL_PCRE_OPTIONS(re);
4064        if (do_flip) all_options = swap_uint32(all_options);        if (do_flip) all_options = swap_uint32(all_options);
4065    
4066        if (get_options == 0) fprintf(outfile, "No options\n");        if (get_options == 0) fprintf(outfile, "No options\n");
# Line 3172  while (!done) Line 4111  while (!done)
4111          break;          break;
4112          }          }
4113    
4114        if (first_char == -1)        if (first_char_set == 2)
4115          {          {
4116          fprintf(outfile, "First char at start or follows newline\n");          fprintf(outfile, "First char at start or follows newline\n");
4117          }          }
4118        else if (first_char < 0)        else if (first_char_set == 1)
         {  
         fprintf(outfile, "No first char\n");  
         }  
       else  
4119          {          {
4120          const char *caseless =          const char *caseless =
4121            ((((REAL_PCRE *)re)->flags & PCRE_FCH_CASELESS) == 0)?            ((REAL_PCRE_FLAGS(re) & PCRE_FCH_CASELESS) == 0)?
4122            "" : " (caseless)";            "" : " (caseless)";
4123    
4124          if (PRINTOK(first_char))          if (PRINTOK(first_char))
# Line 3195  while (!done) Line 4130  while (!done)
4130            fprintf(outfile, "%s\n", caseless);            fprintf(outfile, "%s\n", caseless);
4131            }            }
4132          }          }
4133          else
4134            {
4135            fprintf(outfile, "No first char\n");
4136            }
4137    
4138        if (need_char < 0)        if (need_char_set == 0)
4139          {          {
4140          fprintf(outfile, "No need char\n");          fprintf(outfile, "No need char\n");
4141          }          }
4142        else        else
4143          {          {
4144          const char *caseless =          const char *caseless =
4145            ((((REAL_PCRE *)re)->flags & PCRE_RCH_CASELESS) == 0)?            ((REAL_PCRE_FLAGS(re) & PCRE_RCH_CASELESS) == 0)?
4146            "" : " (caseless)";            "" : " (caseless)";
4147    
4148          if (PRINTOK(need_char))          if (PRINTOK(need_char))
# Line 3216  while (!done) Line 4155  while (!done)
4155            }            }
4156          }          }
4157    
4158          if (maxlookbehind > 0)
4159            fprintf(outfile, "Max lookbehind = %d\n", maxlookbehind);
4160    
4161        /* 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
4162        value, but it varies, depending on the computer architecture, and        value, but it varies, depending on the computer architecture, and
4163        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 3273  while (!done) Line 4215  while (!done)
4215    
4216          /* Show this only if the JIT was set by /S, not by -s. */          /* Show this only if the JIT was set by /S, not by -s. */
4217    
4218          if ((study_options & PCRE_STUDY_JIT_COMPILE) != 0)          if ((study_options & PCRE_STUDY_ALLJIT) != 0 &&
4219                (force_study_options & PCRE_STUDY_ALLJIT) == 0)
4220            {            {
4221            int jit;            int jit;
4222            if (new_info(re, extra, PCRE_INFO_JIT, &jit) == 0)            if (new_info(re, extra, PCRE_INFO_JIT, &jit) == 0)
# Line 3360  while (!done) Line 4303  while (!done)
4303    
4304    for (;;)    for (;;)
4305      {      {
4306      pcre_uint8 *q;  #ifdef SUPPORT_PCRE8
4307        pcre_uint8 *q8;
4308    #endif
4309    #ifdef SUPPORT_PCRE16
4310        pcre_uint16 *q16;
4311    #endif
4312    #ifdef SUPPORT_PCRE32
4313        pcre_uint32 *q32;
4314    #endif
4315      pcre_uint8 *bptr;      pcre_uint8 *bptr;
4316      int *use_offsets = offsets;      int *use_offsets = offsets;
4317      int use_size_offsets = size_offsets;      int use_size_offsets = size_offsets;
4318      int callout_data = 0;      int callout_data = 0;
4319      int callout_data_set = 0;      int callout_data_set = 0;
4320      int count, c;      int count;
4321        pcre_uint32 c;
4322      int copystrings = 0;      int copystrings = 0;
4323      int find_match_limit = default_find_match_limit;      int find_match_limit = default_find_match_limit;
4324      int getstrings = 0;      int getstrings = 0;
# Line 3380  while (!done) Line 4332  while (!done)
4332      *copynames = 0;      *copynames = 0;
4333      *getnames = 0;      *getnames = 0;
4334    
4335    #ifdef SUPPORT_PCRE32
4336        cn32ptr = copynames;
4337        gn32ptr = getnames;
4338    #endif
4339  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
4340      cn16ptr = copynames;      cn16ptr = copynames16;
4341      gn16ptr = getnames;      gn16ptr = getnames16;
4342  #endif  #endif
4343  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
4344      cn8ptr = copynames8;      cn8ptr = copynames8;
# Line 3427  while (!done) Line 4383  while (!done)
4383      p = buffer;      p = buffer;
4384      while (isspace(*p)) p++;      while (isspace(*p)) p++;
4385    
4386      bptr = q = dbuffer;  #ifndef NOUTF
4387        /* Check that the data is well-formed UTF-8 if we're in UTF mode. To create
4388           invalid input to pcre_exec, you must use \x?? or \x{} sequences. */
4389        if (use_utf)
4390          {
4391          pcre_uint8 *q;
4392          pcre_uint32 cc;
4393          int n = 1;
4394    
4395          for (q = p; n > 0 && *q; q += n) n = utf82ord(q, &cc);
4396          if (n <= 0)
4397            {
4398            fprintf(outfile, "**Failed: invalid UTF-8 string cannot be used as input in UTF mode\n");
4399            goto NEXT_DATA;
4400            }
4401          }
4402    #endif
4403    
4404    #ifdef SUPPORT_VALGRIND
4405        /* Mark the dbuffer as addressable but undefined again. */
4406        if (dbuffer != NULL)
4407          {
4408          VALGRIND_MAKE_MEM_UNDEFINED(dbuffer, dbuffer_size * CHAR_SIZE);
4409          }
4410    #endif
4411    
4412        /* Allocate a buffer to hold the data line. len+1 is an upper bound on
4413           the number of pcre_uchar units that will be needed. */
4414        if (dbuffer == NULL || (size_t)len >= dbuffer_size)
4415          {
4416          dbuffer_size *= 2;
4417          dbuffer = (pcre_uint8 *)realloc(dbuffer, dbuffer_size * CHAR_SIZE);
4418          if (dbuffer == NULL)
4419            {
4420            fprintf(stderr, "pcretest: malloc(%d) failed\n", (int)dbuffer_size);
4421            exit(1);
4422            }
4423          }
4424    
4425    #ifdef SUPPORT_PCRE8
4426        q8 = (pcre_uint8 *) dbuffer;
4427    #endif
4428    #ifdef SUPPORT_PCRE16
4429        q16 = (pcre_uint16 *) dbuffer;
4430    #endif
4431    #ifdef SUPPORT_PCRE32
4432        q32 = (pcre_uint32 *) dbuffer;
4433    #endif
4434    
4435      while ((c = *p++) != 0)      while ((c = *p++) != 0)
4436        {        {
4437        int i = 0;        int i = 0;
# Line 3436  while (!done) Line 4440  while (!done)
4440        /* 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.
4441        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,
4442        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
4443        16-bit mode. */        16-bit or 32-bit mode. */
4444    
4445        if (c != '\\')        if (c != '\\')
4446          {          {
4447          if (use_utf)  #ifndef NOUTF
4448            {          if (use_utf && HASUTF8EXTRALEN(c)) { GETUTF8INC(c, p); }
4449            *q++ = c;  #endif
           continue;  
           }  
4450          }          }
4451    
4452        /* Handle backslash escapes */        /* Handle backslash escapes */
# Line 3497  while (!done) Line 4499  while (!done)
4499          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
4500          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.
4501          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
4502          UTF-8 when running in 16-bit mode. */          UTF-8 when running in 16/32-bit mode. */
4503    
4504          c = 0;          c = 0;
4505          while (i++ < 2 && isxdigit(*p))          while (i++ < 2 && isxdigit(*p))
# Line 3505  while (!done) Line 4507  while (!done)
4507            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);
4508            p++;            p++;
4509            }            }
4510          if (use_utf)  #if !defined NOUTF && defined SUPPORT_PCRE8
4511            if (use_utf && (pcre_mode == PCRE8_MODE))
4512            {            {
4513            *q++ = c;            *q8++ = c;
4514            continue;            continue;
4515            }            }
4516    #endif
4517          break;          break;
4518    
4519          case 0:   /* \ followed by EOF allows for an empty line */          case 0:   /* \ followed by EOF allows for an empty line */
# Line 3542  while (!done) Line 4546  while (!done)
4546            }            }
4547          else if (isalnum(*p))          else if (isalnum(*p))
4548            {            {
4549            READ_CAPTURE_NAME(p, &cn8ptr, &cn16ptr, re);            READ_CAPTURE_NAME(p, &cn8ptr, &cn16ptr, &cn32ptr, re);
4550            }            }
4551          else if (*p == '+')          else if (*p == '+')
4552            {            {
# Line 3605  while (!done) Line 4609  while (!done)
4609            }            }
4610          else if (isalnum(*p))          else if (isalnum(*p))
4611            {            {
4612            READ_CAPTURE_NAME(p, &gn8ptr, &gn16ptr, re);            READ_CAPTURE_NAME(p, &gn8ptr, &gn16ptr, &gn32ptr, re);
4613            }            }
4614          continue;          continue;
4615    
# Line 3653  while (!done) Line 4657  while (!done)
4657            }            }
4658          use_size_offsets = n;          use_size_offsets = n;
4659          if (n == 0) use_offsets = NULL;   /* Ensures it can't write to it */          if (n == 0) use_offsets = NULL;   /* Ensures it can't write to it */
4660              else use_offsets = offsets + size_offsets_max - n;  /* To catch overruns */
4661          continue;          continue;
4662    
4663          case 'P':          case 'P':
# Line 3714  while (!done) Line 4719  while (!done)
4719          continue;          continue;
4720          }          }
4721    
4722        /* 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.
4723        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
4724        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
4725        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. */
4726        mode must have come from \x{...} or octal constructs because values from  
4727        \x.. get this far only in non-UTF mode. */  #ifdef SUPPORT_PCRE8
4728          if (pcre_mode == PCRE8_MODE)
4729  #if !defined NOUTF || defined SUPPORT_PCRE16          {
4730        if (use_pcre16 || use_utf)  #ifndef NOUTF
4731          {          if (use_utf)
4732          pcre_uint8 buff8[8];            {
4733          int ii, utn;            if (c > 0x7fffffff)
4734          utn = ord2utf8(c, buff8);              {
4735          for (ii = 0; ii < utn; ii++) *q++ = buff8[ii];              fprintf(outfile, "** Character \\x{%x} is greater than 0x7fffffff "
4736                  "and so cannot be converted to UTF-8\n", c);
4737                goto NEXT_DATA;
4738                }
4739              q8 += ord2utf8(c, q8);
4740              }
4741            else
4742    #endif
4743              {
4744              if (c > 0xffu)
4745                {
4746                fprintf(outfile, "** Character \\x{%x} is greater than 255 "
4747                  "and UTF-8 mode is not enabled.\n", c);
4748                fprintf(outfile, "** Truncation will probably give the wrong "
4749                  "result.\n");
4750                }
4751              *q8++ = c;
4752              }
4753          }          }
       else  
4754  #endif  #endif
4755    #ifdef SUPPORT_PCRE16
4756          if (pcre_mode == PCRE16_MODE)
4757          {          {
4758          if (c > 255)  #ifndef NOUTF
4759            if (use_utf)
4760            {            {
4761            fprintf(outfile, "** Character \\x{%x} is greater than 255 "            if (c > 0x10ffffu)
4762              "and UTF-8 mode is not enabled.\n", c);              {
4763            fprintf(outfile, "** Truncation will probably give the wrong "              fprintf(outfile, "** Failed: character \\x{%x} is greater than "
4764              "result.\n");                "0x10ffff and so cannot be converted to UTF-16\n", c);
4765                goto NEXT_DATA;
4766                }
4767              else if (c >= 0x10000u)
4768                {
4769                c-= 0x10000u;
4770                *q16++ = 0xD800 | (c >> 10);
4771                *q16++ = 0xDC00 | (c & 0x3ff);
4772                }
4773              else
4774                *q16++ = c;
4775              }
4776            else
4777    #endif
4778              {
4779              if (c > 0xffffu)
4780                {
4781                fprintf(outfile, "** Character \\x{%x} is greater than 0xffff "
4782                  "and UTF-16 mode is not enabled.\n", c);
4783                fprintf(outfile, "** Truncation will probably give the wrong "
4784                  "result.\n");
4785                }
4786    
4787              *q16++ = c;
4788            }            }
         *q++ = c;  
4789          }          }
4790    #endif
4791    #ifdef SUPPORT_PCRE32
4792          if (pcre_mode == PCRE32_MODE)
4793            {
4794            *q32++ = c;
4795            }
4796    #endif
4797    
4798        }        }
4799    
4800      /* Reached end of subject string */      /* Reached end of subject string */
4801    
4802      *q = 0;  #ifdef SUPPORT_PCRE8
4803      len = (int)(q - dbuffer);      if (pcre_mode == PCRE8_MODE)
4804        {
4805          *q8 = 0;
4806          len = (int)(q8 - (pcre_uint8 *)dbuffer);
4807        }
4808    #endif
4809    #ifdef SUPPORT_PCRE16
4810        if (pcre_mode == PCRE16_MODE)
4811        {
4812          *q16 = 0;
4813          len = (int)(q16 - (pcre_uint16 *)dbuffer);
4814        }
4815    #endif
4816    #ifdef SUPPORT_PCRE32
4817        if (pcre_mode == PCRE32_MODE)
4818        {
4819          *q32 = 0;
4820          len = (int)(q32 - (pcre_uint32 *)dbuffer);
4821        }
4822    #endif
4823    
4824    #if defined SUPPORT_UTF && defined SUPPORT_PCRE32
4825        /* If we're requsted to test UTF-32 masking of high bits, change the data
4826        string to have high bits set, unless the string is invalid UTF-32.
4827        Since the JIT doesn't support this yet, only do it when not JITing. */
4828        if (use_utf && mask_utf32 && (study_options & PCRE_STUDY_ALLJIT) == 0 &&
4829            valid_utf32((pcre_uint32 *)dbuffer, len))
4830          {
4831          for (q32 = (pcre_uint32 *)dbuffer; *q32; q32++)
4832            *q32 |= ~(pcre_uint32)UTF32_MASK;
4833    
4834          /* Need to pass NO_UTF32_CHECK so the high bits are allowed */
4835          options |= PCRE_NO_UTF32_CHECK;
4836          }
4837    #endif
4838    
4839        /* If we're compiling with explicit valgrind support, Mark the data from after
4840        its end to the end of the buffer as unaddressable, so that a read over the end
4841        of the buffer will be seen by valgrind, even if it doesn't cause a crash.
4842        If we're not building with valgrind support, at least move the data to the end
4843        of the buffer so that it might at least cause a crash.
4844        If we are using the POSIX interface, we must include the terminating zero. */
4845    
4846      /* 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. */  
4847    
4848  #if !defined NOPOSIX  #if !defined NOPOSIX
4849      if (posix || do_posix)      if (posix || do_posix)
4850        {        {
4851        memmove(bptr + buffer_size - len - 1, bptr, len + 1);  #ifdef SUPPORT_VALGRIND
4852        bptr += buffer_size - len - 1;        VALGRIND_MAKE_MEM_NOACCESS(dbuffer + len + 1, dbuffer_size - (len + 1));
4853    #else
4854          memmove(bptr + dbuffer_size - len - 1, bptr, len + 1);
4855          bptr += dbuffer_size - len - 1;
4856    #endif
4857        }        }
4858      else      else
4859  #endif  #endif
4860        {        {
4861        memmove(bptr + buffer_size - len, bptr, len);  #ifdef SUPPORT_VALGRIND
4862        bptr += buffer_size - len;        VALGRIND_MAKE_MEM_NOACCESS(dbuffer + len * CHAR_SIZE, (dbuffer_size - len) * CHAR_SIZE);
4863    #else
4864          bptr = memmove(bptr + (dbuffer_size - len) * CHAR_SIZE, bptr, len * CHAR_SIZE);
4865    #endif
4866        }        }
4867    
4868      if ((all_use_dfa || use_dfa) && find_match_limit)      if ((all_use_dfa || use_dfa) && find_match_limit)
# Line 3793  while (!done) Line 4893  while (!done)
4893          (void)regerror(rc, &preg, (char *)buffer, buffer_size);          (void)regerror(rc, &preg, (char *)buffer, buffer_size);
4894          fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);          fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);
4895          }          }
4896        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)  
4897          {          {
4898          fprintf(outfile, "Matched with REG_NOSUB\n");          fprintf(outfile, "Matched with REG_NOSUB\n");
4899          }          }
# Line 3827  while (!done) Line 4926  while (!done)
4926    
4927      /* Handle matching via the native interface - repeats for /g and /G */      /* Handle matching via the native interface - repeats for /g and /G */
4928    
4929  #ifdef SUPPORT_PCRE16      /* Ensure that there is a JIT callback if we want to verify that JIT was
4930      if (use_pcre16)      actually used. If jit_stack == NULL, no stack has yet been assigned. */
       {  
       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;  
4931    
4932          default:      if (verify_jit && jit_stack == NULL && extra != NULL)
4933          break;         { PCRE_ASSIGN_JIT_STACK(extra, jit_callback, jit_stack); }
         }  
       bptr = (pcre_uint8 *)buffer16;  
       }  
 #endif  
4934    
4935      for (;; gmatched++)    /* Loop for /g or /G */      for (;; gmatched++)    /* Loop for /g or /G */
4936        {        {
4937        markptr = NULL;        markptr = NULL;
4938          jit_was_used = FALSE;
4939    
4940        if (timeitm > 0)        if (timeitm > 0)
4941          {          {
# Line 3868  while (!done) Line 4946  while (!done)
4946  #if !defined NODFA  #if !defined NODFA
4947          if (all_use_dfa || use_dfa)          if (all_use_dfa || use_dfa)
4948            {            {
4949            int workspace[1000];            if ((options & PCRE_DFA_RESTART) != 0)
4950                {
4951                fprintf(outfile, "Timing DFA restarts is not supported\n");
4952                break;
4953                }
4954              if (dfa_workspace == NULL)
4955                dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
4956            for (i = 0; i < timeitm; i++)            for (i = 0; i < timeitm; i++)
4957              {              {
4958              PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,              PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
4959                (options | g_notempty), use_offsets, use_size_offsets, workspace,                (options | g_notempty), use_offsets, use_size_offsets,
4960                (sizeof(workspace)/sizeof(int)));                dfa_workspace, DFA_WS_DIMENSION);
4961              }              }
4962            }            }
4963          else          else
# Line 3899  while (!done) Line 4983  while (!done)
4983    
4984        if (find_match_limit)        if (find_match_limit)
4985          {          {
4986          if (extra == NULL)          if (extra != NULL) { PCRE_FREE_STUDY(extra); }
4987            {          extra = (pcre_extra *)malloc(sizeof(pcre_extra));
4988            extra = (pcre_extra *)malloc(sizeof(pcre_extra));          extra->flags = 0;
           extra->flags = 0;  
           }  
         else extra->flags &= ~PCRE_EXTRA_EXECUTABLE_JIT;  
4989    
4990          (void)check_match_limit(re, extra, bptr, len, start_offset,          (void)check_match_limit(re, extra, bptr, len, start_offset,
4991            options|g_notempty, use_offsets, use_size_offsets,            options|g_notempty, use_offsets, use_size_offsets,
# Line 3939  while (!done) Line 5020  while (!done)
5020  #if !defined NODFA  #if !defined NODFA
5021        else if (all_use_dfa || use_dfa)        else if (all_use_dfa || use_dfa)
5022          {          {
5023          int workspace[1000];          if (dfa_workspace == NULL)
5024              dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
5025            if (dfa_matched++ == 0)
5026              dfa_workspace[0] = -1;  /* To catch bad restart */
5027          PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,          PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
5028            (options | g_notempty), use_offsets, use_size_offsets, workspace,            (options | g_notempty), use_offsets, use_size_offsets, dfa_workspace,
5029            (sizeof(workspace)/sizeof(int)));            DFA_WS_DIMENSION);
5030          if (count == 0)          if (count == 0)
5031            {            {
5032            fprintf(outfile, "Matched, but too many subsidiary matches\n");            fprintf(outfile, "Matched, but too many subsidiary matches\n");
# Line 4019  while (!done) Line 5103  while (!done)
5103              fprintf(outfile, "%2d: ", i/2);              fprintf(outfile, "%2d: ", i/2);
5104              PCHARSV(bptr, use_offsets[i],              PCHARSV(bptr, use_offsets[i],
5105                use_offsets[i+1] - use_offsets[i], outfile);                use_offsets[i+1] - use_offsets[i], outfile);
5106                if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
5107              fprintf(outfile, "\n");              fprintf(outfile, "\n");
5108              if (do_showcaprest || (i == 0 && do_showrest))              if (do_showcaprest || (i == 0 && do_showrest))
5109                {                {
# Line 4062  while (!done) Line 5147  while (!done)
5147            int rc;            int rc;
5148            char copybuffer[256];            char copybuffer[256];
5149    
5150            if (use_pcre16)  #ifdef SUPPORT_PCRE32
5151              if (pcre_mode == PCRE32_MODE)
5152                {
5153                if (*(pcre_uint32 *)cnptr == 0) break;
5154                }
5155    #endif
5156    #ifdef SUPPORT_PCRE16
5157              if (pcre_mode == PCRE16_MODE)
5158              {              {
5159              if (*(pcre_uint16 *)cnptr == 0) break;              if (*(pcre_uint16 *)cnptr == 0) break;
5160              }              }
5161            else  #endif
5162    #ifdef SUPPORT_PCRE8
5163              if (pcre_mode == PCRE8_MODE)
5164              {              {
5165              if (*(pcre_uint8 *)cnptr == 0) break;              if (*(pcre_uint8 *)cnptr == 0) break;
5166              }              }
5167    #endif
5168    
5169            PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,            PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,
5170              cnptr, copybuffer, sizeof(copybuffer));              cnptr, copybuffer, sizeof(copybuffer));
# Line 4117  while (!done) Line 5212  while (!done)
5212            int rc;            int rc;
5213            const char *substring;            const char *substring;
5214    
5215            if (use_pcre16)  #ifdef SUPPORT_PCRE32
5216              if (pcre_mode == PCRE32_MODE)
5217                {
5218                if (*(pcre_uint32 *)gnptr == 0) break;
5219                }
5220    #endif
5221    #ifdef SUPPORT_PCRE16
5222              if (pcre_mode == PCRE16_MODE)
5223              {              {
5224              if (*(pcre_uint16 *)gnptr == 0) break;              if (*(pcre_uint16 *)gnptr == 0) break;
5225              }              }
5226            else  #endif
5227    #ifdef SUPPORT_PCRE8
5228              if (pcre_mode == PCRE8_MODE)
5229              {              {
5230              if (*(pcre_uint8 *)gnptr == 0) break;              if (*(pcre_uint8 *)gnptr == 0) break;
5231              }              }
5232    #endif
5233    
5234            PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,            PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,
5235              gnptr, &substring);              gnptr, &substring);
# Line 4185  while (!done) Line 5290  while (!done)
5290            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],
5291              outfile);              outfile);
5292            }            }
5293            if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
5294          fprintf(outfile, "\n");          fprintf(outfile, "\n");
5295          break;  /* Out of the /g loop */          break;  /* Out of the /g loop */
5296          }          }
# Line 4210  while (!done) Line 5316  while (!done)
5316          if (g_notempty != 0)          if (g_notempty != 0)
5317            {            {
5318            int onechar = 1;            int onechar = 1;
5319            unsigned int obits = ((REAL_PCRE *)re)->options;            unsigned int obits = REAL_PCRE_OPTIONS(re);
5320            use_offsets[0] = start_offset;            use_offsets[0] = start_offset;
5321            if ((obits & PCRE_NEWLINE_BITS) == 0)            if ((obits & PCRE_NEWLINE_BITS) == 0)
5322              {              {
# Line 4228  while (!done) Line 5334  while (!done)
5334                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||
5335                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)
5336                &&                &&
5337                start_offset < len - 1 &&                start_offset < len - 1 && (
5338  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE8
5339                (use_pcre16?                (pcre_mode == PCRE8_MODE &&
5340                     ((PCRE_SPTR16)bptr)[start_offset] == '\r'                 bptr[start_offset] == '\r' &&
5341                  && ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n'                 bptr[start_offset + 1] == '\n') ||
5342                :  #endif
5343                     bptr[start_offset] == '\r'  #ifdef SUPPORT_PCRE16
5344                  && bptr[start_offset + 1] == '\n')                (pcre_mode == PCRE16_MODE &&
5345  #elif defined SUPPORT_PCRE16                 ((PCRE_SPTR16)bptr)[start_offset] == '\r' &&
5346                   ((PCRE_SPTR16)bptr)[start_offset] == '\r'                 ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n') ||
5347                && ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n'  #endif
5348  #else  #ifdef SUPPORT_PCRE32
5349                   bptr[start_offset] == '\r'                (pcre_mode == PCRE32_MODE &&
5350                && bptr[start_offset + 1] == '\n'                 ((PCRE_SPTR32)bptr)[start_offset] == '\r' &&
5351                   ((PCRE_SPTR32)bptr)[start_offset + 1] == '\n') ||
5352  #endif  #endif
5353                )                0))
5354              onechar++;              onechar++;
5355            else if (use_utf)            else if (use_utf)
5356              {              {
# Line 4264  while (!done) Line 5371  while (!done)
5371                {                {
5372                if (markptr == NULL)                if (markptr == NULL)
5373                  {                  {
5374                  fprintf(outfile, "No match\n");                  fprintf(outfile, "No match");
5375                  }                  }
5376                else                else
5377                  {                  {
5378                  fprintf(outfile, "No match, mark = ");                  fprintf(outfile, "No match, mark = ");
5379                  PCHARSV(markptr, 0, -1, outfile);                  PCHARSV(markptr, 0, -1, outfile);
                 putc('\n', outfile);  
5380                  }                  }
5381                  if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
5382                  putc('\n', outfile);
5383                }                }
5384              break;              break;
5385    
5386              case PCRE_ERROR_BADUTF8:              case PCRE_ERROR_BADUTF8:
5387              case PCRE_ERROR_SHORTUTF8:              case PCRE_ERROR_SHORTUTF8:
5388              fprintf(outfile, "Error %d (%s UTF-%s string)", count,              fprintf(outfile, "Error %d (%s UTF-%d string)", count,
5389                (count == PCRE_ERROR_BADUTF8)? "bad" : "short",                (count == PCRE_ERROR_BADUTF8)? "bad" : "short",
5390                use_pcre16? "16" : "8");                8 * CHAR_SIZE);
5391              if (use_size_offsets >= 2)              if (use_size_offsets >= 2)
5392                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],
5393                  use_offsets[1]);                  use_offsets[1]);
# Line 4287  while (!done) Line 5395  while (!done)
5395              break;              break;
5396    
5397              case PCRE_ERROR_BADUTF8_OFFSET:              case PCRE_ERROR_BADUTF8_OFFSET:
5398              fprintf(outfile, "Error %d (bad UTF-%s offset)\n", count,              fprintf(outfile, "Error %d (bad UTF-%d offset)\n", count,
5399                use_pcre16? "16" : "8");                8 * CHAR_SIZE);
5400              break;              break;
5401    
5402              default:              default:
5403              if (count < 0 &&              if (count < 0 &&
5404                  (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))                  (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))
5405                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);
5406              else              else
# Line 4378  free(offsets); Line 5486  free(offsets);
5486  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
5487  if (buffer16 != NULL) free(buffer16);  if (buffer16 != NULL) free(buffer16);
5488  #endif  #endif
5489    #ifdef SUPPORT_PCRE32
5490    if (buffer32 != NULL) free(buffer32);
5491    #endif
5492    
5493    #if !defined NODFA
5494    if (dfa_workspace != NULL)
5495      free(dfa_workspace);
5496    #endif
5497    
5498  return yield;  return yield;
5499  }  }

Legend:
Removed from v.908  
changed lines
  Added in v.1190

  ViewVC Help
Powered by ViewVC 1.1.5