/[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 1248 by ph10, Wed Feb 13 17:36:38 2013 UTC
# Line 36  POSSIBILITY OF SUCH DAMAGE. Line 36  POSSIBILITY OF SUCH DAMAGE.
36  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
37  */  */
38    
39  /* This program now supports the testing of both the 8-bit and 16-bit PCRE  /* This program now supports the testing of all of the 8-bit, 16-bit, and
40  libraries in a single program. This is different from the modules such as  32-bit PCRE libraries in a single program. This is different from the modules
41  pcre_compile.c in the library itself, which are compiled separately for each  such as pcre_compile.c in the library itself, which are compiled separately for
42  mode. If both modes are enabled, for example, pcre_compile.c is compiled twice  each mode. If two modes are enabled, for example, pcre_compile.c is compiled
43  (the second time with COMPILE_PCRE16 defined). By contrast, pcretest.c is  twice. By contrast, pcretest.c is compiled only once. Therefore, it must not
44  compiled only once. Therefore, it must not make use of any of the macros from  make use of any of the macros from pcre_internal.h that depend on
45  pcre_internal.h that depend on COMPILE_PCRE8 or COMPILE_PCRE16. It does,  COMPILE_PCRE8, COMPILE_PCRE16, or COMPILE_PCRE32. It does, however, make use of
46  however, make use of SUPPORT_PCRE8 and SUPPORT_PCRE16 to ensure that it calls  SUPPORT_PCRE8, SUPPORT_PCRE16, and SUPPORT_PCRE32 to ensure that it calls only
47  only supported library functions. */  supported library functions. */
   
48    
49  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
50  #include "config.h"  #include "config.h"
# Line 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 275  argument, the casting might be incorrect Line 289  argument, the casting might be incorrect
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    
296  /* -----------------------------------------------------------*/  /* -----------------------------------------------------------*/
# 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  /* ----- Both modes are supported; a runtime test is needed, except for  #define PCRE_ASSIGN_JIT_STACK32(extra, callback, userdata) \
404      pcre32_assign_jit_stack((pcre32_extra *)extra, \
405        (pcre32_jit_callback)callback, userdata)
406    
407    #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  #if (defined (SUPPORT_PCRE8) + defined (SUPPORT_PCRE16) + \
486         defined (SUPPORT_PCRE32)) >= 2
487    
488  #define CHAR_SIZE (use_pcre16? 2:1)  #define CHAR_SIZE (1 << pcre_mode)
489    
490    /* 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 NEVER
1794    
1795    #ifdef SUPPORT_UTF
1796    static BOOL
1797    valid_utf32(pcre_uint32 *string, int length)
1798    {
1799    register pcre_uint32 *p;
1800    register pcre_uint32 c;
1801    
1802    for (p = string; length-- > 0; p++)
1803      {
1804      c = *p;
1805    
1806      if (c > 0x10ffffu)
1807        return FALSE;
1808    
1809      /* A surrogate */
1810      if ((c & 0xfffff800u) == 0xd800u)
1811        return FALSE;
1812    
1813      /* Non-character */
1814      if ((c & 0xfffeu) == 0xfffeu || (c >= 0xfdd0u && c <= 0xfdefu))
1815        return FALSE;
1816      }
1817    
1818    return TRUE;
1819    }
1820    #endif /* SUPPORT_UTF */
1821    
1822    #endif /* NEVER */
1823    
1824    
1825    #endif
1826    
1827  /*************************************************  /*************************************************
1828  *        Read or extend an input line            *  *        Read or extend an input line            *
# Line 1276  for (;;) Line 1860  for (;;)
1860      {      {
1861      int dlen;      int dlen;
1862    
1863      /* 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
1864      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
1865      we must put it back again, to be compatible with fgets(). */      newline, so we must put it back again, to be compatible with fgets(). */
1866    
1867  #ifdef SUPPORT_LIBREADLINE  #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
1868      if (isatty(fileno(f)))      if (isatty(fileno(f)))
1869        {        {
1870        size_t len;        size_t len;
# Line 1314  for (;;) Line 1898  for (;;)
1898      {      {
1899      int new_buffer_size = 2*buffer_size;      int new_buffer_size = 2*buffer_size;
1900      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);  
1901      pcre_uint8 *new_pbuffer = (pcre_uint8 *)malloc(new_buffer_size);      pcre_uint8 *new_pbuffer = (pcre_uint8 *)malloc(new_buffer_size);
1902    
1903      if (new_buffer == NULL || new_dbuffer == NULL || new_pbuffer == NULL)      if (new_buffer == NULL || new_pbuffer == NULL)
1904        {        {
1905        fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);        fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);
1906        exit(1);        exit(1);
# Line 1332  for (;;) Line 1915  for (;;)
1915      here = new_buffer + (here - buffer);      here = new_buffer + (here - buffer);
1916    
1917      free(buffer);      free(buffer);
     free(dbuffer);  
1918      free(pbuffer);      free(pbuffer);
1919    
1920      buffer = new_buffer;      buffer = new_buffer;
     dbuffer = new_dbuffer;  
1921      pbuffer = new_pbuffer;      pbuffer = new_pbuffer;
1922      }      }
1923    }    }
# Line 1379  return(result); Line 1960  return(result);
1960    
1961  /* Print a single character either literally, or as a hex escape. */  /* Print a single character either literally, or as a hex escape. */
1962    
1963  static int pchar(int c, FILE *f)  static int pchar(pcre_uint32 c, FILE *f)
1964  {  {
1965    int n = 0;
1966  if (PRINTOK(c))  if (PRINTOK(c))
1967    {    {
1968    if (f != NULL) fprintf(f, "%c", c);    if (f != NULL) fprintf(f, "%c", c);
# Line 1401  if (c < 0x100) Line 1983  if (c < 0x100)
1983      }      }
1984    }    }
1985    
1986  if (f != NULL) fprintf(f, "\\x{%02x}", c);  if (f != NULL) n = fprintf(f, "\\x{%02x}", c);
1987  return (c <= 0x000000ff)? 6 :  return n >= 0 ? n : 0;
        (c <= 0x00000fff)? 7 :  
        (c <= 0x0000ffff)? 8 :  
        (c <= 0x000fffff)? 9 : 10;  
1988  }  }
1989    
1990    
# Line 1420  If handed a NULL file, just counts chars Line 1999  If handed a NULL file, just counts chars
1999    
2000  static int pchars(pcre_uint8 *p, int length, FILE *f)  static int pchars(pcre_uint8 *p, int length, FILE *f)
2001  {  {
2002  int c = 0;  pcre_uint32 c = 0;
2003  int yield = 0;  int yield = 0;
2004    
2005  if (length < 0)  if (length < 0)
# Line 1465  return len; Line 2044  return len;
2044  #endif  /* SUPPORT_PCRE16 */  #endif  /* SUPPORT_PCRE16 */
2045    
2046    
2047    
2048    #ifdef SUPPORT_PCRE32
2049    /*************************************************
2050    *    Find length of 0-terminated 32-bit string   *
2051    *************************************************/
2052    
2053    static int strlen32(PCRE_SPTR32 p)
2054    {
2055    int len = 0;
2056    while (*p++ != 0) len++;
2057    return len;
2058    }
2059    #endif  /* SUPPORT_PCRE32 */
2060    
2061    
2062    
2063  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2064  /*************************************************  /*************************************************
2065  *           Print 16-bit character string        *  *           Print 16-bit character string        *
# Line 1482  if (length < 0) Line 2077  if (length < 0)
2077    
2078  while (length-- > 0)  while (length-- > 0)
2079    {    {
2080    int c = *p++ & 0xffff;    pcre_uint32 c = *p++ & 0xffff;
2081  #if !defined NOUTF  #if !defined NOUTF
2082    if (use_utf && c >= 0xD800 && c < 0xDC00 && length > 0)    if (use_utf && c >= 0xD800 && c < 0xDC00 && length > 0)
2083      {      {
# Line 1504  return yield; Line 2099  return yield;
2099    
2100    
2101    
2102    #ifdef SUPPORT_PCRE32
2103    /*************************************************
2104    *           Print 32-bit character string        *
2105    *************************************************/
2106    
2107    /* Must handle UTF-32 strings in utf mode. Yields number of characters printed.
2108    If handed a NULL file, just counts chars without printing. */
2109    
2110    static int pchars32(PCRE_SPTR32 p, int length, BOOL utf, FILE *f)
2111    {
2112    int yield = 0;
2113    
2114    (void)(utf);  /* Avoid compiler warning */
2115    
2116    if (length < 0)
2117      length = strlen32(p);
2118    
2119    while (length-- > 0)
2120      {
2121      pcre_uint32 c = *p++;
2122      yield += pchar(c, f);
2123      }
2124    
2125    return yield;
2126    }
2127    #endif  /* SUPPORT_PCRE32 */
2128    
2129    
2130    
2131  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
2132  /*************************************************  /*************************************************
2133  *     Read a capture name (8-bit) and check it   *  *     Read a capture name (8-bit) and check it   *
# Line 1557  return p; Line 2181  return p;
2181    
2182    
2183    
2184    #ifdef SUPPORT_PCRE32
2185    /*************************************************
2186    *     Read a capture name (32-bit) and check it  *
2187    *************************************************/
2188    
2189    /* Note that the text being read is 8-bit. */
2190    
2191    static pcre_uint8 *
2192    read_capture_name32(pcre_uint8 *p, pcre_uint32 **pp, pcre *re)
2193    {
2194    pcre_uint32 *npp = *pp;
2195    while (isalnum(*p)) *npp++ = *p++;
2196    *npp++ = 0;
2197    *npp = 0;
2198    if (pcre32_get_stringnumber((pcre32 *)re, (PCRE_SPTR32)(*pp)) < 0)
2199      {
2200      fprintf(outfile, "no parentheses with name \"");
2201      PCHARSV(*pp, 0, -1, outfile);
2202      fprintf(outfile, "\"\n");
2203      }
2204    *pp = npp;
2205    return p;
2206    }
2207    #endif  /* SUPPORT_PCRE32 */
2208    
2209    
2210    
2211  /*************************************************  /*************************************************
2212  *              Callout function                  *  *              Callout function                  *
2213  *************************************************/  *************************************************/
# Line 1714  free(block); Line 2365  free(block);
2365  *************************************************/  *************************************************/
2366    
2367  /* Get one piece of information from the pcre_fullinfo() function. When only  /* Get one piece of information from the pcre_fullinfo() function. When only
2368  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
2369  value, but the code is defensive.  value, but the code is defensive.
2370    
2371  Arguments:  Arguments:
# Line 1731  new_info(pcre *re, pcre_extra *study, in Line 2382  new_info(pcre *re, pcre_extra *study, in
2382  {  {
2383  int rc;  int rc;
2384    
2385  if (use_pcre16)  if (pcre_mode == PCRE32_MODE)
2386    #ifdef SUPPORT_PCRE32
2387      rc = pcre32_fullinfo((pcre32 *)re, (pcre32_extra *)study, option, ptr);
2388    #else
2389      rc = PCRE_ERROR_BADMODE;
2390    #endif
2391    else if (pcre_mode == PCRE16_MODE)
2392  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2393    rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);    rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);
2394  #else  #else
# Line 1747  else Line 2404  else
2404  if (rc < 0)  if (rc < 0)
2405    {    {
2406    fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,    fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
2407      use_pcre16? "16" : "", option);      pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "", option);
2408    if (rc == PCRE_ERROR_BADMODE)    if (rc == PCRE_ERROR_BADMODE)
2409      fprintf(outfile, "Running in %s-bit mode but pattern was compiled in "      fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
2410        "%s-bit mode\n", use_pcre16? "16":"8", use_pcre16? "8":"16");        "%d-bit mode\n", 8 * CHAR_SIZE,
2411          8 * (REAL_PCRE_FLAGS(re) & PCRE_MODE_MASK));
2412    }    }
2413    
2414  return rc;  return rc;
# Line 1799  bytes in the pattern itself. This is to Line 2457  bytes in the pattern itself. This is to
2457  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
2458  architecture. */  architecture. */
2459    
2460    #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
2461  static void  static void
2462  regexflip(pcre *ere, pcre_extra *extra)  regexflip8_or_16(pcre *ere, pcre_extra *extra)
2463  {  {
2464  REAL_PCRE *re = (REAL_PCRE *)ere;  real_pcre8_or_16 *re = (real_pcre8_or_16 *)ere;
2465  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2466  int op;  int op;
2467  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 2498  if (extra != NULL)
2498  in the name table, if present, and then in the pattern itself. */  in the name table, if present, and then in the pattern itself. */
2499    
2500  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2501  if (!use_pcre16) return;  if (pcre_mode != PCRE16_MODE) return;
2502    
2503  while(TRUE)  while(TRUE)
2504    {    {
# Line 1977  while(TRUE) Line 2636  while(TRUE)
2636  /* Control should never reach here in 16 bit mode. */  /* Control should never reach here in 16 bit mode. */
2637  #endif /* SUPPORT_PCRE16 */  #endif /* SUPPORT_PCRE16 */
2638  }  }
2639    #endif /* SUPPORT_PCRE[8|16] */
2640    
2641    
2642    
2643    #if defined SUPPORT_PCRE32
2644    static void
2645    regexflip_32(pcre *ere, pcre_extra *extra)
2646    {
2647    real_pcre32 *re = (real_pcre32 *)ere;
2648    int op;
2649    pcre_uint32 *ptr = (pcre_uint32 *)re + re->name_table_offset;
2650    int length = re->name_count * re->name_entry_size;
2651    
2652    /* Always flip the bytes in the main data block and study blocks. */
2653    
2654    re->magic_number = REVERSED_MAGIC_NUMBER;
2655    re->size = swap_uint32(re->size);
2656    re->options = swap_uint32(re->options);
2657    re->flags = swap_uint16(re->flags);
2658    re->top_bracket = swap_uint16(re->top_bracket);
2659    re->top_backref = swap_uint16(re->top_backref);
2660    re->first_char = swap_uint32(re->first_char);
2661    re->req_char = swap_uint32(re->req_char);
2662    re->name_table_offset = swap_uint16(re->name_table_offset);
2663    re->name_entry_size = swap_uint16(re->name_entry_size);
2664    re->name_count = swap_uint16(re->name_count);
2665    
2666    if (extra != NULL)
2667      {
2668      pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
2669      rsd->size = swap_uint32(rsd->size);
2670      rsd->flags = swap_uint32(rsd->flags);
2671      rsd->minlength = swap_uint32(rsd->minlength);
2672      }
2673    
2674    /* In 32-bit mode we must swap bytes in the name table, if present, and then in
2675    the pattern itself. */
2676    
2677    while(TRUE)
2678      {
2679      /* Swap previous characters. */
2680      while (length-- > 0)
2681        {
2682        *ptr = swap_uint32(*ptr);
2683        ptr++;
2684        }
2685    
2686      /* Get next opcode. */
2687    
2688      length = 0;
2689      op = *ptr;
2690      *ptr++ = swap_uint32(op);
2691    
2692      switch (op)
2693        {
2694        case OP_END:
2695        return;
2696    
2697        default:
2698        length = OP_lengths32[op] - 1;
2699        break;
2700    
2701        case OP_CLASS:
2702        case OP_NCLASS:
2703        /* Skip the character bit map. */
2704        ptr += 32/sizeof(pcre_uint32);
2705        length = 0;
2706        break;
2707    
2708        case OP_XCLASS:
2709        /* LINK_SIZE can only be 1 in 32-bit mode. */
2710        length = (int)((unsigned int)(ptr[0]) - (1 + LINK_SIZE + 1));
2711    
2712        /* Reverse the size of the XCLASS instance. */
2713        *ptr = swap_uint32(*ptr);
2714        ptr++;
2715    
2716        op = *ptr;
2717        *ptr = swap_uint32(op);
2718        ptr++;
2719        if ((op & XCL_MAP) != 0)
2720          {
2721          /* Skip the character bit map. */
2722          ptr += 32/sizeof(pcre_uint32);
2723          length -= 32/sizeof(pcre_uint32);
2724          }
2725        break;
2726        }
2727      }
2728    /* Control should never reach here in 32 bit mode. */
2729    }
2730    
2731    #endif /* SUPPORT_PCRE32 */
2732    
2733    
2734    
2735    static void
2736    regexflip(pcre *ere, pcre_extra *extra)
2737    {
2738    #if defined SUPPORT_PCRE32
2739      if (REAL_PCRE_FLAGS(ere) & PCRE_MODE32)
2740        regexflip_32(ere, extra);
2741    #endif
2742    #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
2743      if (REAL_PCRE_FLAGS(ere) & (PCRE_MODE8 | PCRE_MODE16))
2744        regexflip8_or_16(ere, extra);
2745    #endif
2746    }
2747    
2748    
2749    
# Line 2096  usage(void) Line 2863  usage(void)
2863  {  {
2864  printf("Usage:     pcretest [options] [<input file> [<output file>]]\n\n");  printf("Usage:     pcretest [options] [<input file> [<output file>]]\n\n");
2865  printf("Input and output default to stdin and stdout.\n");  printf("Input and output default to stdin and stdout.\n");
2866  #ifdef SUPPORT_LIBREADLINE  #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
2867  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");
2868  #else  #else
2869  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 2872  printf("\nOptions:\n");
2872  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2873  printf("  -16      use the 16-bit library\n");  printf("  -16      use the 16-bit library\n");
2874  #endif  #endif
2875    #ifdef SUPPORT_PCRE32
2876    printf("  -32      use the 32-bit library\n");
2877    #endif
2878  printf("  -b       show compiled code\n");  printf("  -b       show compiled code\n");
2879  printf("  -C       show PCRE compile-time options and exit\n");  printf("  -C       show PCRE compile-time options and exit\n");
2880  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 2882  printf("           and exit with its val
2882  printf("     linksize     internal link size [2, 3, 4]\n");  printf("     linksize     internal link size [2, 3, 4]\n");
2883  printf("     pcre8        8 bit library support enabled [0, 1]\n");  printf("     pcre8        8 bit library support enabled [0, 1]\n");
2884  printf("     pcre16       16 bit library support enabled [0, 1]\n");  printf("     pcre16       16 bit library support enabled [0, 1]\n");
2885    printf("     pcre32       32 bit library support enabled [0, 1]\n");
2886  printf("     utf          Unicode Transformation Format supported [0, 1]\n");  printf("     utf          Unicode Transformation Format supported [0, 1]\n");
2887  printf("     ucp          Unicode Properties supported [0, 1]\n");  printf("     ucp          Unicode Properties supported [0, 1]\n");
2888  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 2903  printf("  -q       quiet: do not output
2903  printf("  -S <n>   set stack size to <n> megabytes\n");  printf("  -S <n>   set stack size to <n> megabytes\n");
2904  printf("  -s       force each pattern to be studied at basic level\n"  printf("  -s       force each pattern to be studied at basic level\n"
2905         "  -s+      force each pattern to be studied, using JIT if available\n"         "  -s+      force each pattern to be studied, using JIT if available\n"
2906           "  -s++     ditto, verifying when JIT was actually used\n"
2907           "  -s+n     force each pattern to be studied, using JIT if available,\n"
2908           "             where 1 <= n <= 7 selects JIT options\n"
2909           "  -s++n    ditto, verifying when JIT was actually used\n"
2910         "  -t       time compilation and execution\n");         "  -t       time compilation and execution\n");
2911  printf("  -t <n>   time compilation and execution, repeating <n> times\n");  printf("  -t <n>   time compilation and execution, repeating <n> times\n");
2912  printf("  -tm      time execution (matching) only\n");  printf("  -tm      time execution (matching) only\n");
# Line 2166  int quiet = 0; Line 2941  int quiet = 0;
2941  int size_offsets = 45;  int size_offsets = 45;
2942  int size_offsets_max;  int size_offsets_max;
2943  int *offsets = NULL;  int *offsets = NULL;
 #if !defined NOPOSIX  
 int posix = 0;  
 #endif  
2944  int debug = 0;  int debug = 0;
2945  int done = 0;  int done = 0;
2946  int all_use_dfa = 0;  int all_use_dfa = 0;
2947    int verify_jit = 0;
2948  int yield = 0;  int yield = 0;
2949  int stack_size;  int stack_size;
2950    pcre_uint8 *dbuffer = NULL;
2951    size_t dbuffer_size = 1u << 14;
2952    
2953    #if !defined NOPOSIX
2954    int posix = 0;
2955    #endif
2956    #if !defined NODFA
2957    int *dfa_workspace = NULL;
2958    #endif
2959    
2960  pcre_jit_stack *jit_stack = NULL;  pcre_jit_stack *jit_stack = NULL;
2961    
2962  /* These vectors store, end-to-end, a list of zero-terminated captured  /* These vectors store, end-to-end, a list of zero-terminated captured
2963  substring names, each list itself being terminated by an empty name. Assume  substring names, each list itself being terminated by an empty name. Assume
2964  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
2965  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
2966  for the actual memory, to ensure alignment. */  for the actual memory, to ensure alignment. */
2967    
2968  pcre_uint16 copynames[1024];  pcre_uint32 copynames[1024];
2969  pcre_uint16 getnames[1024];  pcre_uint32 getnames[1024];
2970    
2971    #ifdef SUPPORT_PCRE32
2972    pcre_uint32 *cn32ptr;
2973    pcre_uint32 *gn32ptr;
2974    #endif
2975    
2976  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2977    pcre_uint16 *copynames16 = (pcre_uint16 *)copynames;
2978    pcre_uint16 *getnames16 = (pcre_uint16 *)getnames;
2979  pcre_uint16 *cn16ptr;  pcre_uint16 *cn16ptr;
2980  pcre_uint16 *gn16ptr;  pcre_uint16 *gn16ptr;
2981  #endif  #endif
# Line 2199  pcre_uint8 *gn8ptr; Line 2988  pcre_uint8 *gn8ptr;
2988  #endif  #endif
2989    
2990  /* Get buffers from malloc() so that valgrind will check their misuse when  /* Get buffers from malloc() so that valgrind will check their misuse when
2991  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-
2992  buffer (buffer16) is obtained only if needed. */  and 32-bit buffers (buffer16, buffer32) are obtained only if needed. */
2993    
2994  buffer = (pcre_uint8 *)malloc(buffer_size);  buffer = (pcre_uint8 *)malloc(buffer_size);
 dbuffer = (pcre_uint8 *)malloc(buffer_size);  
2995  pbuffer = (pcre_uint8 *)malloc(buffer_size);  pbuffer = (pcre_uint8 *)malloc(buffer_size);
2996    
2997  /* 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 3010  _setmode( _fileno( stdout ), _O_BINARY )
3010  /* Get the version number: both pcre_version() and pcre16_version() give the  /* Get the version number: both pcre_version() and pcre16_version() give the
3011  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. */
3012    
3013  #ifdef SUPPORT_PCRE8  #if defined SUPPORT_PCRE8
3014  version = pcre_version();  version = pcre_version();
3015  #else  #elif defined SUPPORT_PCRE16
3016  version = pcre16_version();  version = pcre16_version();
3017    #elif defined SUPPORT_PCRE32
3018    version = pcre32_version();
3019  #endif  #endif
3020    
3021  /* Scan options */  /* Scan options */
# Line 2233  version = pcre16_version(); Line 3023  version = pcre16_version();
3023  while (argc > 1 && argv[op][0] == '-')  while (argc > 1 && argv[op][0] == '-')
3024    {    {
3025    pcre_uint8 *endptr;    pcre_uint8 *endptr;
3026      char *arg = argv[op];
3027    
3028      if (strcmp(arg, "-m") == 0) showstore = 1;
3029      else if (strcmp(arg, "-s") == 0) force_study = 0;
3030    
3031    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)  
3032      {      {
3033        arg += 3;
3034        if (*arg == '+') { arg++; verify_jit = TRUE; }
3035      force_study = 1;      force_study = 1;
3036      force_study_options = PCRE_STUDY_JIT_COMPILE;      if (*arg == 0)
3037          force_study_options = jit_study_bits[6];
3038        else if (*arg >= '1' && *arg <= '7')
3039          force_study_options = jit_study_bits[*arg - '1'];
3040        else goto BAD_ARG;
3041        }
3042      else if (strcmp(arg, "-8") == 0)
3043        {
3044    #ifdef SUPPORT_PCRE8
3045        pcre_mode = PCRE8_MODE;
3046    #else
3047        printf("** This version of PCRE was built without 8-bit support\n");
3048        exit(1);
3049    #endif
3050      }      }
3051    else if (strcmp(argv[op], "-16") == 0)    else if (strcmp(arg, "-16") == 0)
3052      {      {
3053  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3054      use_pcre16 = 1;      pcre_mode = PCRE16_MODE;
3055  #else  #else
3056      printf("** This version of PCRE was built without 16-bit support\n");      printf("** This version of PCRE was built without 16-bit support\n");
3057      exit(1);      exit(1);
3058  #endif  #endif
3059      }      }
3060    else if (strcmp(argv[op], "-q") == 0) quiet = 1;    else if (strcmp(arg, "-32") == 0)
3061    else if (strcmp(argv[op], "-b") == 0) debug = 1;      {
3062    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;  #ifdef SUPPORT_PCRE32
3063    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;      pcre_mode = PCRE32_MODE;
3064    else if (strcmp(argv[op], "-M") == 0) default_find_match_limit = TRUE;  #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 2329  while (argc > 1 && argv[op][0] == '-') Line 3144  while (argc > 1 && argv[op][0] == '-')
3144  #endif  #endif
3145          goto EXIT;          goto EXIT;
3146          }          }
3147        if (strcmp(argv[op + 1], "pcre16") == 0)        else if (strcmp(argv[op + 1], "pcre16") == 0)
3148          {          {
3149  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3150          printf("1\n");          printf("1\n");
# Line 2340  while (argc > 1 && argv[op][0] == '-') Line 3155  while (argc > 1 && argv[op][0] == '-')
3155  #endif  #endif
3156          goto EXIT;          goto EXIT;
3157          }          }
3158          else if (strcmp(argv[op + 1], "pcre32") == 0)
3159            {
3160    #ifdef SUPPORT_PCRE32
3161            printf("1\n");
3162            yield = 1;
3163    #else
3164            printf("0\n");
3165            yield = 0;
3166    #endif
3167            goto EXIT;
3168            }
3169        if (strcmp(argv[op + 1], "utf") == 0)        if (strcmp(argv[op + 1], "utf") == 0)
3170          {          {
3171  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
3172          (void)pcre_config(PCRE_CONFIG_UTF8, &rc);          if (pcre_mode == PCRE8_MODE)
3173          printf("%d\n", rc);            (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
3174          yield = rc;  #endif
3175  #else  #ifdef SUPPORT_PCRE16
3176          (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);          if (pcre_mode == PCRE16_MODE)
3177              (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
3178    #endif
3179    #ifdef SUPPORT_PCRE32
3180            if (pcre_mode == PCRE32_MODE)
3181              (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
3182    #endif
3183          printf("%d\n", rc);          printf("%d\n", rc);
3184          yield = rc;          yield = rc;
 #endif  
3185          goto EXIT;          goto EXIT;
3186          }          }
3187        if (strcmp(argv[op + 1], "ucp") == 0)        else if (strcmp(argv[op + 1], "ucp") == 0)
3188          {          {
3189          (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
3190          printf("%d\n", rc);          printf("%d\n", rc);
3191          yield = rc;          yield = rc;
         goto EXIT;  
3192          }          }
3193        if (strcmp(argv[op + 1], "jit") == 0)        else if (strcmp(argv[op + 1], "jit") == 0)
3194          {          {
3195          (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);
3196          printf("%d\n", rc);          printf("%d\n", rc);
3197          yield = rc;          yield = rc;
         goto EXIT;  
3198          }          }
3199        if (strcmp(argv[op + 1], "newline") == 0)        else if (strcmp(argv[op + 1], "newline") == 0)
3200          {          {
3201          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3202          /* Note that these values are always the ASCII values, even          print_newline_config(rc, TRUE);
3203          in EBCDIC environments. CR is 13 and NL is 10. */          }
3204          printf("%s\n", (rc == 13)? "CR" :        else if (strcmp(argv[op + 1], "ebcdic") == 0)
3205            (rc == 10)? "LF" : (rc == (13<<8 | 10))? "CRLF" :          {
3206            (rc == -2)? "ANYCRLF" :  #ifdef EBCDIC
3207            (rc == -1)? "ANY" : "???");          printf("1\n");
3208          goto EXIT;          yield = 1;
3209    #else
3210            printf("0\n");
3211    #endif
3212            }
3213          else if (strcmp(argv[op + 1], "ebcdic-nl") == 0)
3214            {
3215    #ifdef EBCDIC
3216            printf("0x%02x\n", CHAR_LF);
3217    #else
3218            printf("0\n");
3219    #endif
3220            }
3221          else
3222            {
3223            printf("Unknown -C option: %s\n", argv[op + 1]);
3224          }          }
       printf("Unknown -C option: %s\n", argv[op + 1]);  
3225        goto EXIT;        goto EXIT;
3226        }        }
3227    
3228        /* No argument for -C: output all configuration information. */
3229    
3230      printf("PCRE version %s\n", version);      printf("PCRE version %s\n", version);
3231      printf("Compiled with\n");      printf("Compiled with\n");
3232    
3233    #ifdef EBCDIC
3234        printf("  EBCDIC code support: LF is 0x%02x\n", CHAR_LF);
3235    #endif
3236    
3237  /* 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
3238  are set, either both UTFs are supported or both are not supported. */  are set, either both UTFs are supported or both are not supported. */
3239    
3240  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE8
3241      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");  
3242      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
3243      printf("  %sUTF-8 support\n", rc? "" : "No ");        printf ("  %sUTF-8 support\n", rc ? "" : "No ");
3244  #else  #endif
3245      printf("  16-bit support only\n");  #ifdef SUPPORT_PCRE16
3246        printf("  16-bit support\n");
3247      (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);      (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
3248      printf("  %sUTF-16 support\n", rc? "" : "No ");      printf ("  %sUTF-16 support\n", rc ? "" : "No ");
3249    #endif
3250    #ifdef SUPPORT_PCRE32
3251        printf("  32-bit support\n");
3252        (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
3253        printf ("  %sUTF-32 support\n", rc ? "" : "No ");
3254  #endif  #endif
3255    
3256      (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 3265  are set, either both UTFs are supported
3265      else      else
3266        printf("  No just-in-time compiler support\n");        printf("  No just-in-time compiler support\n");
3267      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3268      /* 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" : "???");  
3269      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);
3270      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :
3271                                       "all Unicode newlines");                                       "all Unicode newlines");
# Line 2444  are set, either both UTFs are supported Line 3287  are set, either both UTFs are supported
3287      printf("\n");      printf("\n");
3288      goto EXIT;      goto EXIT;
3289      }      }
3290    else if (strcmp(argv[op], "-help") == 0 ||    else if (strcmp(arg, "-help") == 0 ||
3291             strcmp(argv[op], "--help") == 0)             strcmp(arg, "--help") == 0)
3292      {      {
3293      usage();      usage();
3294      goto EXIT;      goto EXIT;
3295      }      }
3296    else    else
3297      {      {
3298      printf("** Unknown or malformed option %s\n", argv[op]);      BAD_ARG:
3299        printf("** Unknown or malformed option %s\n", arg);
3300      usage();      usage();
3301      yield = 1;      yield = 1;
3302      goto EXIT;      goto EXIT;
# Line 2513  pcre16_stack_malloc = stack_malloc; Line 3357  pcre16_stack_malloc = stack_malloc;
3357  pcre16_stack_free = stack_free;  pcre16_stack_free = stack_free;
3358  #endif  #endif
3359    
3360    #ifdef SUPPORT_PCRE32
3361    pcre32_malloc = new_malloc;
3362    pcre32_free = new_free;
3363    pcre32_stack_malloc = stack_malloc;
3364    pcre32_stack_free = stack_free;
3365    #endif
3366    
3367  /* Heading line unless quiet, then prompt for first regex if stdin */  /* Heading line unless quiet, then prompt for first regex if stdin */
3368    
3369  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 3401  while (!done)
3401    int do_flip = 0;    int do_flip = 0;
3402    int erroroffset, len, delimiter, poffset;    int erroroffset, len, delimiter, poffset;
3403    
3404    #if !defined NODFA
3405      int dfa_matched = 0;
3406    #endif
3407    
3408    use_utf = 0;    use_utf = 0;
3409    debug_lengths = 1;    debug_lengths = 1;
3410    
# Line 2597  while (!done) Line 3452  while (!done)
3452        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];
3453    
3454      re = (pcre *)new_malloc(true_size);      re = (pcre *)new_malloc(true_size);
3455        if (re == NULL)
3456          {
3457          printf("** Failed to get %d bytes of memory for pcre object\n",
3458            (int)true_size);
3459          yield = 1;
3460          goto EXIT;
3461          }
3462      regex_gotten_store = first_gotten_store;      regex_gotten_store = first_gotten_store;
3463    
3464      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;
3465    
3466      magic = ((REAL_PCRE *)re)->magic_number;      magic = REAL_PCRE_MAGIC(re);
3467      if (magic != MAGIC_NUMBER)      if (magic != MAGIC_NUMBER)
3468        {        {
3469        if (swap_uint32(magic) == MAGIC_NUMBER)        if (swap_uint32(magic) == MAGIC_NUMBER)
# Line 2611  while (!done) Line 3473  while (!done)
3473        else        else
3474          {          {
3475          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);
3476            new_free(re);
3477          fclose(f);          fclose(f);
3478          continue;          continue;
3479          }          }
# Line 2640  while (!done) Line 3503  while (!done)
3503            {            {
3504            PCRE_FREE_STUDY(extra);            PCRE_FREE_STUDY(extra);
3505            }            }
3506          if (re != NULL) new_free(re);          new_free(re);
3507          fclose(f);          fclose(f);
3508          continue;          continue;
3509          }          }
# Line 2656  while (!done) Line 3519  while (!done)
3519        PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, NULL);        PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, NULL);
3520        if (rc == PCRE_ERROR_BADMODE)        if (rc == PCRE_ERROR_BADMODE)
3521          {          {
3522            pcre_uint16 flags_in_host_byte_order;
3523            if (REAL_PCRE_MAGIC(re) == MAGIC_NUMBER)
3524              flags_in_host_byte_order = REAL_PCRE_FLAGS(re);
3525            else
3526              flags_in_host_byte_order = swap_uint16(REAL_PCRE_FLAGS(re));
3527          /* Simulate the result of the function call below. */          /* Simulate the result of the function call below. */
3528          fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,          fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
3529            use_pcre16? "16" : "", PCRE_INFO_OPTIONS);            pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "",
3530          fprintf(outfile, "Running in %s-bit mode but pattern was compiled in "            PCRE_INFO_OPTIONS);
3531            "%s-bit mode\n", use_pcre16? "16":"8", use_pcre16? "8":"16");          fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
3532              "%d-bit mode\n", 8 * CHAR_SIZE, 8 * (flags_in_host_byte_order & PCRE_MODE_MASK));
3533            new_free(re);
3534            fclose(f);
3535          continue;          continue;
3536          }          }
3537        }        }
3538    
3539      /* Need to know if UTF-8 for printing data strings. */      /* Need to know if UTF-8 for printing data strings. */
3540    
3541      if (new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options) < 0) continue;      if (new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options) < 0)
3542          {
3543          new_free(re);
3544          fclose(f);
3545          continue;
3546          }
3547      use_utf = (get_options & PCRE_UTF8) != 0;      use_utf = (get_options & PCRE_UTF8) != 0;
3548    
3549      fclose(f);      fclose(f);
# Line 2726  while (!done) Line 3602  while (!done)
3602    /* Look for options after final delimiter */    /* Look for options after final delimiter */
3603    
3604    options = 0;    options = 0;
3605    study_options = 0;    study_options = force_study_options;
3606    log_store = showstore;  /* default from command line */    log_store = showstore;  /* default from command line */
3607    
3608    while (*pp != 0)    while (*pp != 0)
# Line 2763  while (!done) Line 3639  while (!done)
3639  #endif  #endif
3640    
3641        case 'S':        case 'S':
3642        if (do_study == 0)        do_study = 1;
3643          for (;;)
3644          {          {
3645          do_study = 1;          switch (*pp++)
         if (*pp == '+')  
3646            {            {
3647            study_options |= PCRE_STUDY_JIT_COMPILE;            case 'S':
3648            pp++;            do_study = 0;
3649              no_force_study = 1;
3650              break;
3651    
3652              case '!':
3653              study_options |= PCRE_STUDY_EXTRA_NEEDED;
3654              break;
3655    
3656              case '+':
3657              if (*pp == '+')
3658                {
3659                verify_jit = TRUE;
3660                pp++;
3661                }
3662              if (*pp >= '1' && *pp <= '7')
3663                study_options |= jit_study_bits[*pp++ - '1'];
3664              else
3665                study_options |= jit_study_bits[6];
3666              break;
3667    
3668              case '-':
3669              study_options &= ~PCRE_STUDY_ALLJIT;
3670              break;
3671    
3672              default:
3673              pp--;
3674              goto ENDLOOP;
3675            }            }
3676          }          }
3677        else        ENDLOOP:
         {  
         do_study = 0;  
         no_force_study = 1;  
         }  
3678        break;        break;
3679    
3680        case 'U': options |= PCRE_UNGREEDY; break;        case 'U': options |= PCRE_UNGREEDY; break;
# Line 2895  while (!done) Line 3793  while (!done)
3793  #endif  /* !defined NOPOSIX */  #endif  /* !defined NOPOSIX */
3794    
3795      {      {
3796      /* In 16-bit mode, convert the input. */      /* In 16- or 32-bit mode, convert the input. */
3797    
3798  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3799      if (use_pcre16)      if (pcre_mode == PCRE16_MODE)
3800        {        {
3801        switch(to16(FALSE, p, options & PCRE_UTF8, (int)strlen((char *)p)))        switch(to16(FALSE, p, options & PCRE_UTF8, (int)strlen((char *)p)))
3802          {          {
# Line 2924  while (!done) Line 3822  while (!done)
3822        }        }
3823  #endif  #endif
3824    
3825    #ifdef SUPPORT_PCRE32
3826        if (pcre_mode == PCRE32_MODE)
3827          {
3828          switch(to32(FALSE, p, options & PCRE_UTF32, (int)strlen((char *)p)))
3829            {
3830            case -1:
3831            fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "
3832              "converted to UTF-32\n");
3833            goto SKIP_DATA;
3834    
3835            case -2:
3836            fprintf(outfile, "**Failed: character value greater than 0x10ffff "
3837              "cannot be converted to UTF-32\n");
3838            goto SKIP_DATA;
3839    
3840            case -3:
3841            fprintf(outfile, "**Failed: character value is ill-formed UTF-32\n");
3842            goto SKIP_DATA;
3843    
3844            default:
3845            break;
3846            }
3847          p = (pcre_uint8 *)buffer32;
3848          }
3849    #endif
3850    
3851      /* Compile many times when timing */      /* Compile many times when timing */
3852    
3853      if (timeit > 0)      if (timeit > 0)
# Line 2981  while (!done) Line 3905  while (!done)
3905      /* Extract the size for possible writing before possibly flipping it,      /* Extract the size for possible writing before possibly flipping it,
3906      and remember the store that was got. */      and remember the store that was got. */
3907    
3908      true_size = ((REAL_PCRE *)re)->size;      true_size = REAL_PCRE_SIZE(re);
3909      regex_gotten_store = first_gotten_store;      regex_gotten_store = first_gotten_store;
3910    
3911      /* Output code size information if requested */      /* Output code size information if requested */
3912    
3913      if (log_store)      if (log_store)
3914          {
3915          int name_count, name_entry_size, real_pcre_size;
3916    
3917          new_info(re, NULL, PCRE_INFO_NAMECOUNT, &name_count);
3918          new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
3919          real_pcre_size = 0;
3920    #ifdef SUPPORT_PCRE8
3921          if (REAL_PCRE_FLAGS(re) & PCRE_MODE8)
3922            real_pcre_size = sizeof(real_pcre);
3923    #endif
3924    #ifdef SUPPORT_PCRE16
3925          if (REAL_PCRE_FLAGS(re) & PCRE_MODE16)
3926            real_pcre_size = sizeof(real_pcre16);
3927    #endif
3928    #ifdef SUPPORT_PCRE32
3929          if (REAL_PCRE_FLAGS(re) & PCRE_MODE32)
3930            real_pcre_size = sizeof(real_pcre32);
3931    #endif
3932        fprintf(outfile, "Memory allocation (code space): %d\n",        fprintf(outfile, "Memory allocation (code space): %d\n",
3933          (int)(first_gotten_store -          (int)(first_gotten_store - real_pcre_size - name_count * name_entry_size));
3934                sizeof(REAL_PCRE) -        }
               ((REAL_PCRE *)re)->name_count * ((REAL_PCRE *)re)->name_entry_size));  
3935    
3936      /* 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
3937      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 3947  while (!done)
3947          clock_t start_time = clock();          clock_t start_time = clock();
3948          for (i = 0; i < timeit; i++)          for (i = 0; i < timeit; i++)
3949            {            {
3950            PCRE_STUDY(extra, re, study_options | force_study_options, &error);            PCRE_STUDY(extra, re, study_options, &error);
3951            }            }
3952          time_taken = clock() - start_time;          time_taken = clock() - start_time;
3953          if (extra != NULL)          if (extra != NULL)
# Line 3017  while (!done) Line 3958  while (!done)
3958            (((double)time_taken * 1000.0) / (double)timeit) /            (((double)time_taken * 1000.0) / (double)timeit) /
3959              (double)CLOCKS_PER_SEC);              (double)CLOCKS_PER_SEC);
3960          }          }
3961        PCRE_STUDY(extra, re, study_options | force_study_options, &error);        PCRE_STUDY(extra, re, study_options, &error);
3962        if (error != NULL)        if (error != NULL)
3963          fprintf(outfile, "Failed to study: %s\n", error);          fprintf(outfile, "Failed to study: %s\n", error);
3964        else if (extra != NULL)        else if (extra != NULL)
# Line 3061  while (!done) Line 4002  while (!done)
4002      if (do_showinfo)      if (do_showinfo)
4003        {        {
4004        unsigned long int all_options;        unsigned long int all_options;
4005        int count, backrefmax, first_char, need_char, okpartial, jchanged,        pcre_uint32 first_char, need_char;
4006          hascrorlf;        int count, backrefmax, first_char_set, need_char_set, okpartial, jchanged,
4007            hascrorlf, maxlookbehind;
4008        int nameentrysize, namecount;        int nameentrysize, namecount;
4009        const pcre_uint8 *nametable;        const pcre_uint8 *nametable;
4010    
4011        if (new_info(re, NULL, PCRE_INFO_SIZE, &size) +        if (new_info(re, NULL, PCRE_INFO_SIZE, &size) +
4012            new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) +            new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) +
4013            new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax) +            new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax) +
4014            new_info(re, NULL, PCRE_INFO_FIRSTBYTE, &first_char) +            new_info(re, NULL, PCRE_INFO_FIRSTCHARACTER, &first_char) +
4015            new_info(re, NULL, PCRE_INFO_LASTLITERAL, &need_char) +            new_info(re, NULL, PCRE_INFO_FIRSTCHARACTERFLAGS, &first_char_set) +
4016              new_info(re, NULL, PCRE_INFO_REQUIREDCHAR, &need_char) +
4017              new_info(re, NULL, PCRE_INFO_REQUIREDCHARFLAGS, &need_char_set) +
4018            new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize) +            new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize) +
4019            new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount) +            new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount) +
4020            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +
4021            new_info(re, NULL, PCRE_INFO_OKPARTIAL, &okpartial) +            new_info(re, NULL, PCRE_INFO_OKPARTIAL, &okpartial) +
4022            new_info(re, NULL, PCRE_INFO_JCHANGED, &jchanged) +            new_info(re, NULL, PCRE_INFO_JCHANGED, &jchanged) +
4023            new_info(re, NULL, PCRE_INFO_HASCRORLF, &hascrorlf)            new_info(re, NULL, PCRE_INFO_HASCRORLF, &hascrorlf) +
4024              new_info(re, NULL, PCRE_INFO_MAXLOOKBEHIND, &maxlookbehind)
4025            != 0)            != 0)
4026          goto SKIP_DATA;          goto SKIP_DATA;
4027    
# Line 3093  while (!done) Line 4038  while (!done)
4038          fprintf(outfile, "Named capturing subpatterns:\n");          fprintf(outfile, "Named capturing subpatterns:\n");
4039          while (namecount-- > 0)          while (namecount-- > 0)
4040            {            {
4041  #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  
4042            int length = (int)STRLEN(nametable + imm2_size);            int length = (int)STRLEN(nametable + imm2_size);
4043            fprintf(outfile, "  ");            fprintf(outfile, "  ");
4044            PCHARSV(nametable, imm2_size, length, outfile);            PCHARSV(nametable, imm2_size, length, outfile);
4045            while (length++ < nameentrysize - imm2_size) putc(' ', outfile);            while (length++ < nameentrysize - imm2_size) putc(' ', outfile);
4046  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE32
4047            fprintf(outfile, "%3d\n", use_pcre16?            if (pcre_mode == PCRE32_MODE)
4048               (int)(((PCRE_SPTR16)nametable)[0])              fprintf(outfile, "%3d\n", (int)(((PCRE_SPTR32)nametable)[0]));
4049              :((int)nametable[0] << 8) | (int)nametable[1]);  #endif
4050            nametable += nameentrysize * (use_pcre16 ? 2 : 1);  #ifdef SUPPORT_PCRE16
4051  #else            if (pcre_mode == PCRE16_MODE)
4052            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;  
4053  #endif  #endif
4054    #ifdef SUPPORT_PCRE8
4055              if (pcre_mode == PCRE8_MODE)
4056                fprintf(outfile, "%3d\n", ((int)nametable[0] << 8) | (int)nametable[1]);
4057  #endif  #endif
4058              nametable += nameentrysize * CHAR_SIZE;
4059            }            }
4060          }          }
4061    
4062        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");
4063        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");
4064    
4065        all_options = ((REAL_PCRE *)re)->options;        all_options = REAL_PCRE_OPTIONS(re);
4066        if (do_flip) all_options = swap_uint32(all_options);        if (do_flip) all_options = swap_uint32(all_options);
4067    
4068        if (get_options == 0) fprintf(outfile, "No options\n");        if (get_options == 0) fprintf(outfile, "No options\n");
# Line 3172  while (!done) Line 4113  while (!done)
4113          break;          break;
4114          }          }
4115    
4116        if (first_char == -1)        if (first_char_set == 2)
4117          {          {
4118          fprintf(outfile, "First char at start or follows newline\n");          fprintf(outfile, "First char at start or follows newline\n");
4119          }          }
4120        else if (first_char < 0)        else if (first_char_set == 1)
         {  
         fprintf(outfile, "No first char\n");  
         }  
       else  
4121          {          {
4122          const char *caseless =          const char *caseless =
4123            ((((REAL_PCRE *)re)->flags & PCRE_FCH_CASELESS) == 0)?            ((REAL_PCRE_FLAGS(re) & PCRE_FCH_CASELESS) == 0)?
4124            "" : " (caseless)";            "" : " (caseless)";
4125    
4126          if (PRINTOK(first_char))          if (PRINTOK(first_char))
# Line 3195  while (!done) Line 4132  while (!done)
4132            fprintf(outfile, "%s\n", caseless);            fprintf(outfile, "%s\n", caseless);
4133            }            }
4134          }          }
4135          else
4136            {
4137            fprintf(outfile, "No first char\n");
4138            }
4139    
4140        if (need_char < 0)        if (need_char_set == 0)
4141          {          {
4142          fprintf(outfile, "No need char\n");          fprintf(outfile, "No need char\n");
4143          }          }
4144        else        else
4145          {          {
4146          const char *caseless =          const char *caseless =
4147            ((((REAL_PCRE *)re)->flags & PCRE_RCH_CASELESS) == 0)?            ((REAL_PCRE_FLAGS(re) & PCRE_RCH_CASELESS) == 0)?
4148            "" : " (caseless)";            "" : " (caseless)";
4149    
4150          if (PRINTOK(need_char))          if (PRINTOK(need_char))
# Line 3216  while (!done) Line 4157  while (!done)
4157            }            }
4158          }          }
4159    
4160          if (maxlookbehind > 0)
4161            fprintf(outfile, "Max lookbehind = %d\n", maxlookbehind);
4162    
4163        /* 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
4164        value, but it varies, depending on the computer architecture, and        value, but it varies, depending on the computer architecture, and
4165        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 4217  while (!done)
4217    
4218          /* 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. */
4219    
4220          if ((study_options & PCRE_STUDY_JIT_COMPILE) != 0)          if ((study_options & PCRE_STUDY_ALLJIT) != 0 &&
4221                (force_study_options & PCRE_STUDY_ALLJIT) == 0)
4222            {            {
4223            int jit;            int jit;
4224            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 4305  while (!done)
4305    
4306    for (;;)    for (;;)
4307      {      {
4308      pcre_uint8 *q;  #ifdef SUPPORT_PCRE8
4309        pcre_uint8 *q8;
4310    #endif
4311    #ifdef SUPPORT_PCRE16
4312        pcre_uint16 *q16;
4313    #endif
4314    #ifdef SUPPORT_PCRE32
4315        pcre_uint32 *q32;
4316    #endif
4317      pcre_uint8 *bptr;      pcre_uint8 *bptr;
4318      int *use_offsets = offsets;      int *use_offsets = offsets;
4319      int use_size_offsets = size_offsets;      int use_size_offsets = size_offsets;
4320      int callout_data = 0;      int callout_data = 0;
4321      int callout_data_set = 0;      int callout_data_set = 0;
4322      int count, c;      int count;
4323        pcre_uint32 c;
4324      int copystrings = 0;      int copystrings = 0;
4325      int find_match_limit = default_find_match_limit;      int find_match_limit = default_find_match_limit;
4326      int getstrings = 0;      int getstrings = 0;
# Line 3380  while (!done) Line 4334  while (!done)
4334      *copynames = 0;      *copynames = 0;
4335      *getnames = 0;      *getnames = 0;
4336    
4337    #ifdef SUPPORT_PCRE32
4338        cn32ptr = copynames;
4339        gn32ptr = getnames;
4340    #endif
4341  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
4342      cn16ptr = copynames;      cn16ptr = copynames16;
4343      gn16ptr = getnames;      gn16ptr = getnames16;
4344  #endif  #endif
4345  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
4346      cn8ptr = copynames8;      cn8ptr = copynames8;
# Line 3427  while (!done) Line 4385  while (!done)
4385      p = buffer;      p = buffer;
4386      while (isspace(*p)) p++;      while (isspace(*p)) p++;
4387    
4388      bptr = q = dbuffer;  #ifndef NOUTF
4389        /* Check that the data is well-formed UTF-8 if we're in UTF mode. To create
4390           invalid input to pcre_exec, you must use \x?? or \x{} sequences. */
4391        if (use_utf)
4392          {
4393          pcre_uint8 *q;
4394          pcre_uint32 cc;
4395          int n = 1;
4396    
4397          for (q = p; n > 0 && *q; q += n) n = utf82ord(q, &cc);
4398          if (n <= 0)
4399            {
4400            fprintf(outfile, "**Failed: invalid UTF-8 string cannot be used as input in UTF mode\n");
4401            goto NEXT_DATA;
4402            }
4403          }
4404    #endif
4405    
4406    #ifdef SUPPORT_VALGRIND
4407        /* Mark the dbuffer as addressable but undefined again. */
4408        if (dbuffer != NULL)
4409          {
4410          VALGRIND_MAKE_MEM_UNDEFINED(dbuffer, dbuffer_size * CHAR_SIZE);
4411          }
4412    #endif
4413    
4414        /* Allocate a buffer to hold the data line. len+1 is an upper bound on
4415           the number of pcre_uchar units that will be needed. */
4416        if (dbuffer == NULL || (size_t)len >= dbuffer_size)
4417          {
4418          dbuffer_size *= 2;
4419          dbuffer = (pcre_uint8 *)realloc(dbuffer, dbuffer_size * CHAR_SIZE);
4420          if (dbuffer == NULL)
4421            {
4422            fprintf(stderr, "pcretest: malloc(%d) failed\n", (int)dbuffer_size);
4423            exit(1);
4424            }
4425          }
4426    
4427    #ifdef SUPPORT_PCRE8
4428        q8 = (pcre_uint8 *) dbuffer;
4429    #endif
4430    #ifdef SUPPORT_PCRE16
4431        q16 = (pcre_uint16 *) dbuffer;
4432    #endif
4433    #ifdef SUPPORT_PCRE32
4434        q32 = (pcre_uint32 *) dbuffer;
4435    #endif
4436    
4437      while ((c = *p++) != 0)      while ((c = *p++) != 0)
4438        {        {
4439        int i = 0;        int i = 0;
# Line 3436  while (!done) Line 4442  while (!done)
4442        /* 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.
4443        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,
4444        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
4445        16-bit mode. */        16-bit or 32-bit mode. */
4446    
4447        if (c != '\\')        if (c != '\\')
4448          {          {
4449          if (use_utf)  #ifndef NOUTF
4450            {          if (use_utf && HASUTF8EXTRALEN(c)) { GETUTF8INC(c, p); }
4451            *q++ = c;  #endif
           continue;  
           }  
4452          }          }
4453    
4454        /* Handle backslash escapes */        /* Handle backslash escapes */
# Line 3497  while (!done) Line 4501  while (!done)
4501          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
4502          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.
4503          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
4504          UTF-8 when running in 16-bit mode. */          UTF-8 when running in 16/32-bit mode. */
4505    
4506          c = 0;          c = 0;
4507          while (i++ < 2 && isxdigit(*p))          while (i++ < 2 && isxdigit(*p))
# Line 3505  while (!done) Line 4509  while (!done)
4509            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);
4510            p++;            p++;
4511            }            }
4512          if (use_utf)  #if !defined NOUTF && defined SUPPORT_PCRE8
4513            if (use_utf && (pcre_mode == PCRE8_MODE))
4514            {            {
4515            *q++ = c;            *q8++ = c;
4516            continue;            continue;
4517            }            }
4518    #endif
4519          break;          break;
4520    
4521          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 4548  while (!done)
4548            }            }
4549          else if (isalnum(*p))          else if (isalnum(*p))
4550            {            {
4551            READ_CAPTURE_NAME(p, &cn8ptr, &cn16ptr, re);            READ_CAPTURE_NAME(p, &cn8ptr, &cn16ptr, &cn32ptr, re);
4552            }            }
4553          else if (*p == '+')          else if (*p == '+')
4554            {            {
# Line 3605  while (!done) Line 4611  while (!done)
4611            }            }
4612          else if (isalnum(*p))          else if (isalnum(*p))
4613            {            {
4614            READ_CAPTURE_NAME(p, &gn8ptr, &gn16ptr, re);            READ_CAPTURE_NAME(p, &gn8ptr, &gn16ptr, &gn32ptr, re);
4615            }            }
4616          continue;          continue;
4617    
# Line 3653  while (!done) Line 4659  while (!done)
4659            }            }
4660          use_size_offsets = n;          use_size_offsets = n;
4661          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 */
4662              else use_offsets = offsets + size_offsets_max - n;  /* To catch overruns */
4663          continue;          continue;
4664    
4665          case 'P':          case 'P':
# Line 3714  while (!done) Line 4721  while (!done)
4721          continue;          continue;
4722          }          }
4723    
4724        /* 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.
4725        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
4726        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
4727        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. */
4728        mode must have come from \x{...} or octal constructs because values from  
4729        \x.. get this far only in non-UTF mode. */  #ifdef SUPPORT_PCRE8
4730          if (pcre_mode == PCRE8_MODE)
4731  #if !defined NOUTF || defined SUPPORT_PCRE16          {
4732        if (use_pcre16 || use_utf)  #ifndef NOUTF
4733          {          if (use_utf)
4734          pcre_uint8 buff8[8];            {
4735          int ii, utn;            if (c > 0x7fffffff)
4736          utn = ord2utf8(c, buff8);              {
4737          for (ii = 0; ii < utn; ii++) *q++ = buff8[ii];              fprintf(outfile, "** Character \\x{%x} is greater than 0x7fffffff "
4738                  "and so cannot be converted to UTF-8\n", c);
4739                goto NEXT_DATA;
4740                }
4741              q8 += ord2utf8(c, q8);
4742              }
4743            else
4744    #endif
4745              {
4746              if (c > 0xffu)
4747                {
4748                fprintf(outfile, "** Character \\x{%x} is greater than 255 "
4749                  "and UTF-8 mode is not enabled.\n", c);
4750                fprintf(outfile, "** Truncation will probably give the wrong "
4751                  "result.\n");
4752                }
4753              *q8++ = c;
4754              }
4755          }          }
       else  
4756  #endif  #endif
4757    #ifdef SUPPORT_PCRE16
4758          if (pcre_mode == PCRE16_MODE)
4759          {          {
4760          if (c > 255)  #ifndef NOUTF
4761            if (use_utf)
4762              {
4763              if (c > 0x10ffffu)
4764                {
4765                fprintf(outfile, "** Failed: character \\x{%x} is greater than "
4766                  "0x10ffff and so cannot be converted to UTF-16\n", c);
4767                goto NEXT_DATA;
4768                }
4769              else if (c >= 0x10000u)
4770                {
4771                c-= 0x10000u;
4772                *q16++ = 0xD800 | (c >> 10);
4773                *q16++ = 0xDC00 | (c & 0x3ff);
4774                }
4775              else
4776                *q16++ = c;
4777              }
4778            else
4779    #endif
4780            {            {
4781            fprintf(outfile, "** Character \\x{%x} is greater than 255 "            if (c > 0xffffu)
4782              "and UTF-8 mode is not enabled.\n", c);              {
4783            fprintf(outfile, "** Truncation will probably give the wrong "              fprintf(outfile, "** Character \\x{%x} is greater than 0xffff "
4784              "result.\n");                "and UTF-16 mode is not enabled.\n", c);
4785                fprintf(outfile, "** Truncation will probably give the wrong "
4786                  "result.\n");
4787                }
4788    
4789              *q16++ = c;
4790            }            }
         *q++ = c;  
4791          }          }
4792    #endif
4793    #ifdef SUPPORT_PCRE32
4794          if (pcre_mode == PCRE32_MODE)
4795            {
4796            *q32++ = c;
4797            }
4798    #endif
4799    
4800        }        }
4801    
4802      /* Reached end of subject string */      /* Reached end of subject string */
4803    
4804      *q = 0;  #ifdef SUPPORT_PCRE8
4805      len = (int)(q - dbuffer);      if (pcre_mode == PCRE8_MODE)
4806        {
4807          *q8 = 0;
4808          len = (int)(q8 - (pcre_uint8 *)dbuffer);
4809        }
4810    #endif
4811    #ifdef SUPPORT_PCRE16
4812        if (pcre_mode == PCRE16_MODE)
4813        {
4814          *q16 = 0;
4815          len = (int)(q16 - (pcre_uint16 *)dbuffer);
4816        }
4817    #endif
4818    #ifdef SUPPORT_PCRE32
4819        if (pcre_mode == PCRE32_MODE)
4820        {
4821          *q32 = 0;
4822          len = (int)(q32 - (pcre_uint32 *)dbuffer);
4823        }
4824    #endif
4825    
4826        /* If we're compiling with explicit valgrind support, Mark the data from after
4827        its end to the end of the buffer as unaddressable, so that a read over the end
4828        of the buffer will be seen by valgrind, even if it doesn't cause a crash.
4829        If we're not building with valgrind support, at least move the data to the end
4830        of the buffer so that it might at least cause a crash.
4831        If we are using the POSIX interface, we must include the terminating zero. */
4832    
4833      /* 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. */  
4834    
4835  #if !defined NOPOSIX  #if !defined NOPOSIX
4836      if (posix || do_posix)      if (posix || do_posix)
4837        {        {
4838        memmove(bptr + buffer_size - len - 1, bptr, len + 1);  #ifdef SUPPORT_VALGRIND
4839        bptr += buffer_size - len - 1;        VALGRIND_MAKE_MEM_NOACCESS(dbuffer + len + 1, dbuffer_size - (len + 1));
4840    #else
4841          memmove(bptr + dbuffer_size - len - 1, bptr, len + 1);
4842          bptr += dbuffer_size - len - 1;
4843    #endif
4844        }        }
4845      else      else
4846  #endif  #endif
4847        {        {
4848        memmove(bptr + buffer_size - len, bptr, len);  #ifdef SUPPORT_VALGRIND
4849        bptr += buffer_size - len;        VALGRIND_MAKE_MEM_NOACCESS(dbuffer + len * CHAR_SIZE, (dbuffer_size - len) * CHAR_SIZE);
4850    #else
4851          bptr = memmove(bptr + (dbuffer_size - len) * CHAR_SIZE, bptr, len * CHAR_SIZE);
4852    #endif
4853        }        }
4854    
4855      if ((all_use_dfa || use_dfa) && find_match_limit)      if ((all_use_dfa || use_dfa) && find_match_limit)
# Line 3793  while (!done) Line 4880  while (!done)
4880          (void)regerror(rc, &preg, (char *)buffer, buffer_size);          (void)regerror(rc, &preg, (char *)buffer, buffer_size);
4881          fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);          fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);
4882          }          }
4883        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)  
4884          {          {
4885          fprintf(outfile, "Matched with REG_NOSUB\n");          fprintf(outfile, "Matched with REG_NOSUB\n");
4886          }          }
# Line 3827  while (!done) Line 4913  while (!done)
4913    
4914      /* Handle matching via the native interface - repeats for /g and /G */      /* Handle matching via the native interface - repeats for /g and /G */
4915    
4916  #ifdef SUPPORT_PCRE16      /* Ensure that there is a JIT callback if we want to verify that JIT was
4917      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;  
4918    
4919          default:      if (verify_jit && jit_stack == NULL && extra != NULL)
4920          break;         { PCRE_ASSIGN_JIT_STACK(extra, jit_callback, jit_stack); }
         }  
       bptr = (pcre_uint8 *)buffer16;  
       }  
 #endif  
4921    
4922      for (;; gmatched++)    /* Loop for /g or /G */      for (;; gmatched++)    /* Loop for /g or /G */
4923        {        {
4924        markptr = NULL;        markptr = NULL;
4925          jit_was_used = FALSE;
4926    
4927        if (timeitm > 0)        if (timeitm > 0)
4928          {          {
# Line 3868  while (!done) Line 4933  while (!done)
4933  #if !defined NODFA  #if !defined NODFA
4934          if (all_use_dfa || use_dfa)          if (all_use_dfa || use_dfa)
4935            {            {
4936            int workspace[1000];            if ((options & PCRE_DFA_RESTART) != 0)
4937                {
4938                fprintf(outfile, "Timing DFA restarts is not supported\n");
4939                break;
4940                }
4941              if (dfa_workspace == NULL)
4942                dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
4943            for (i = 0; i < timeitm; i++)            for (i = 0; i < timeitm; i++)
4944              {              {
4945              PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,              PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
4946                (options | g_notempty), use_offsets, use_size_offsets, workspace,                (options | g_notempty), use_offsets, use_size_offsets,
4947                (sizeof(workspace)/sizeof(int)));                dfa_workspace, DFA_WS_DIMENSION);
4948              }              }
4949            }            }
4950          else          else
# Line 3899  while (!done) Line 4970  while (!done)
4970    
4971        if (find_match_limit)        if (find_match_limit)
4972          {          {
4973          if (extra == NULL)          if (extra != NULL) { PCRE_FREE_STUDY(extra); }
4974            {          extra = (pcre_extra *)malloc(sizeof(pcre_extra));
4975            extra = (pcre_extra *)malloc(sizeof(pcre_extra));          extra->flags = 0;
           extra->flags = 0;  
           }  
         else extra->flags &= ~PCRE_EXTRA_EXECUTABLE_JIT;  
4976    
4977          (void)check_match_limit(re, extra, bptr, len, start_offset,          (void)check_match_limit(re, extra, bptr, len, start_offset,
4978            options|g_notempty, use_offsets, use_size_offsets,            options|g_notempty, use_offsets, use_size_offsets,
# Line 3939  while (!done) Line 5007  while (!done)
5007  #if !defined NODFA  #if !defined NODFA
5008        else if (all_use_dfa || use_dfa)        else if (all_use_dfa || use_dfa)
5009          {          {
5010          int workspace[1000];          if (dfa_workspace == NULL)
5011              dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
5012            if (dfa_matched++ == 0)
5013              dfa_workspace[0] = -1;  /* To catch bad restart */
5014          PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,          PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
5015            (options | g_notempty), use_offsets, use_size_offsets, workspace,            (options | g_notempty), use_offsets, use_size_offsets, dfa_workspace,
5016            (sizeof(workspace)/sizeof(int)));            DFA_WS_DIMENSION);
5017          if (count == 0)          if (count == 0)
5018            {            {
5019            fprintf(outfile, "Matched, but too many subsidiary matches\n");            fprintf(outfile, "Matched, but too many subsidiary matches\n");
# Line 3958  while (!done) Line 5029  while (!done)
5029          if (count == 0)          if (count == 0)
5030            {            {
5031            fprintf(outfile, "Matched, but too many substrings\n");            fprintf(outfile, "Matched, but too many substrings\n");
5032            count = use_size_offsets/3;            /* 2 is a special case; match can be returned */
5033              count = (use_size_offsets == 2)? 1 : use_size_offsets/3;
5034            }            }
5035          }          }
5036    
# Line 3972  while (!done) Line 5044  while (!done)
5044  #if !defined NODFA  #if !defined NODFA
5045          if (all_use_dfa || use_dfa) maxcount = use_size_offsets/2; else          if (all_use_dfa || use_dfa) maxcount = use_size_offsets/2; else
5046  #endif  #endif
5047            maxcount = use_size_offsets/3;            /* 2 is a special case; match can be returned */
5048              maxcount = (use_size_offsets == 2)? 1 : use_size_offsets/3;
5049    
5050          /* This is a check against a lunatic return value. */          /* This is a check against a lunatic return value. */
5051    
# Line 4019  while (!done) Line 5092  while (!done)
5092              fprintf(outfile, "%2d: ", i/2);              fprintf(outfile, "%2d: ", i/2);
5093              PCHARSV(bptr, use_offsets[i],              PCHARSV(bptr, use_offsets[i],
5094                use_offsets[i+1] - use_offsets[i], outfile);                use_offsets[i+1] - use_offsets[i], outfile);
5095                if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
5096              fprintf(outfile, "\n");              fprintf(outfile, "\n");
5097              if (do_showcaprest || (i == 0 && do_showrest))              if (do_showcaprest || (i == 0 && do_showrest))
5098                {                {
# Line 4062  while (!done) Line 5136  while (!done)
5136            int rc;            int rc;
5137            char copybuffer[256];            char copybuffer[256];
5138    
5139            if (use_pcre16)  #ifdef SUPPORT_PCRE32
5140              if (pcre_mode == PCRE32_MODE)
5141                {
5142                if (*(pcre_uint32 *)cnptr == 0) break;
5143                }
5144    #endif
5145    #ifdef SUPPORT_PCRE16
5146              if (pcre_mode == PCRE16_MODE)
5147              {              {
5148              if (*(pcre_uint16 *)cnptr == 0) break;              if (*(pcre_uint16 *)cnptr == 0) break;
5149              }              }
5150            else  #endif
5151    #ifdef SUPPORT_PCRE8
5152              if (pcre_mode == PCRE8_MODE)
5153              {              {
5154              if (*(pcre_uint8 *)cnptr == 0) break;              if (*(pcre_uint8 *)cnptr == 0) break;
5155              }              }
5156    #endif
5157    
5158            PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,            PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,
5159              cnptr, copybuffer, sizeof(copybuffer));              cnptr, copybuffer, sizeof(copybuffer));
# Line 4117  while (!done) Line 5201  while (!done)
5201            int rc;            int rc;
5202            const char *substring;            const char *substring;
5203    
5204            if (use_pcre16)  #ifdef SUPPORT_PCRE32
5205              if (pcre_mode == PCRE32_MODE)
5206                {
5207                if (*(pcre_uint32 *)gnptr == 0) break;
5208                }
5209    #endif
5210    #ifdef SUPPORT_PCRE16
5211              if (pcre_mode == PCRE16_MODE)
5212              {              {
5213              if (*(pcre_uint16 *)gnptr == 0) break;              if (*(pcre_uint16 *)gnptr == 0) break;
5214              }              }
5215            else  #endif
5216    #ifdef SUPPORT_PCRE8
5217              if (pcre_mode == PCRE8_MODE)
5218              {              {
5219              if (*(pcre_uint8 *)gnptr == 0) break;              if (*(pcre_uint8 *)gnptr == 0) break;
5220              }              }
5221    #endif
5222    
5223            PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,            PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,
5224              gnptr, &substring);              gnptr, &substring);
# Line 4185  while (!done) Line 5279  while (!done)
5279            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],
5280              outfile);              outfile);
5281            }            }
5282            if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
5283          fprintf(outfile, "\n");          fprintf(outfile, "\n");
5284          break;  /* Out of the /g loop */          break;  /* Out of the /g loop */
5285          }          }
# Line 4210  while (!done) Line 5305  while (!done)
5305          if (g_notempty != 0)          if (g_notempty != 0)
5306            {            {
5307            int onechar = 1;            int onechar = 1;
5308            unsigned int obits = ((REAL_PCRE *)re)->options;            unsigned int obits = REAL_PCRE_OPTIONS(re);
5309            use_offsets[0] = start_offset;            use_offsets[0] = start_offset;
5310            if ((obits & PCRE_NEWLINE_BITS) == 0)            if ((obits & PCRE_NEWLINE_BITS) == 0)
5311              {              {
# Line 4228  while (!done) Line 5323  while (!done)
5323                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||
5324                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)
5325                &&                &&
5326                start_offset < len - 1 &&                start_offset < len - 1 && (
5327  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE8
5328                (use_pcre16?                (pcre_mode == PCRE8_MODE &&
5329                     ((PCRE_SPTR16)bptr)[start_offset] == '\r'                 bptr[start_offset] == '\r' &&
5330                  && ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n'                 bptr[start_offset + 1] == '\n') ||
5331                :  #endif
5332                     bptr[start_offset] == '\r'  #ifdef SUPPORT_PCRE16
5333                  && bptr[start_offset + 1] == '\n')                (pcre_mode == PCRE16_MODE &&
5334  #elif defined SUPPORT_PCRE16                 ((PCRE_SPTR16)bptr)[start_offset] == '\r' &&
5335                   ((PCRE_SPTR16)bptr)[start_offset] == '\r'                 ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n') ||
5336                && ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n'  #endif
5337  #else  #ifdef SUPPORT_PCRE32
5338                   bptr[start_offset] == '\r'                (pcre_mode == PCRE32_MODE &&
5339                && bptr[start_offset + 1] == '\n'                 ((PCRE_SPTR32)bptr)[start_offset] == '\r' &&
5340                   ((PCRE_SPTR32)bptr)[start_offset + 1] == '\n') ||
5341  #endif  #endif
5342                )                0))
5343              onechar++;              onechar++;
5344            else if (use_utf)            else if (use_utf)
5345              {              {
# Line 4264  while (!done) Line 5360  while (!done)
5360                {                {
5361                if (markptr == NULL)                if (markptr == NULL)
5362                  {                  {
5363                  fprintf(outfile, "No match\n");                  fprintf(outfile, "No match");
5364                  }                  }
5365                else                else
5366                  {                  {
5367                  fprintf(outfile, "No match, mark = ");                  fprintf(outfile, "No match, mark = ");
5368                  PCHARSV(markptr, 0, -1, outfile);                  PCHARSV(markptr, 0, -1, outfile);
                 putc('\n', outfile);  
5369                  }                  }
5370                  if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
5371                  putc('\n', outfile);
5372                }                }
5373              break;              break;
5374    
5375              case PCRE_ERROR_BADUTF8:              case PCRE_ERROR_BADUTF8:
5376              case PCRE_ERROR_SHORTUTF8:              case PCRE_ERROR_SHORTUTF8:
5377              fprintf(outfile, "Error %d (%s UTF-%s string)", count,              fprintf(outfile, "Error %d (%s UTF-%d string)", count,
5378                (count == PCRE_ERROR_BADUTF8)? "bad" : "short",                (count == PCRE_ERROR_BADUTF8)? "bad" : "short",
5379                use_pcre16? "16" : "8");                8 * CHAR_SIZE);
5380              if (use_size_offsets >= 2)              if (use_size_offsets >= 2)
5381                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],
5382                  use_offsets[1]);                  use_offsets[1]);
# Line 4287  while (!done) Line 5384  while (!done)
5384              break;              break;
5385    
5386              case PCRE_ERROR_BADUTF8_OFFSET:              case PCRE_ERROR_BADUTF8_OFFSET:
5387              fprintf(outfile, "Error %d (bad UTF-%s offset)\n", count,              fprintf(outfile, "Error %d (bad UTF-%d offset)\n", count,
5388                use_pcre16? "16" : "8");                8 * CHAR_SIZE);
5389              break;              break;
5390    
5391              default:              default:
5392              if (count < 0 &&              if (count < 0 &&
5393                  (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))                  (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))
5394                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);
5395              else              else
# Line 4378  free(offsets); Line 5475  free(offsets);
5475  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
5476  if (buffer16 != NULL) free(buffer16);  if (buffer16 != NULL) free(buffer16);
5477  #endif  #endif
5478    #ifdef SUPPORT_PCRE32
5479    if (buffer32 != NULL) free(buffer32);
5480    #endif
5481    
5482    #if !defined NODFA
5483    if (dfa_workspace != NULL)
5484      free(dfa_workspace);
5485    #endif
5486    
5487  return yield;  return yield;
5488  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.5