/[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 1142 by ph10, Fri Oct 19 15:45:43 2012 UTC
# Line 36  POSSIBILITY OF SUCH DAMAGE. Line 36  POSSIBILITY OF SUCH DAMAGE.
36  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
37  */  */
38    
39  /* This program now supports the testing of both the 8-bit and 16-bit PCRE  /* This program now supports the testing of all of the 8-bit, 16-bit, and
40  libraries in a single program. This is different from the modules such as  32-bit PCRE libraries in a single program. This is different from the modules
41  pcre_compile.c in the library itself, which are compiled separately for each  such as pcre_compile.c in the library itself, which are compiled separately for
42  mode. If both modes are enabled, for example, pcre_compile.c is compiled twice  each mode. If two modes are enabled, for example, pcre_compile.c is compiled
43  (the second time with COMPILE_PCRE16 defined). By contrast, pcretest.c is  twice. By contrast, pcretest.c is compiled only once. Therefore, it must not
44  compiled only once. Therefore, it must not make use of any of the macros from  make use of any of the macros from pcre_internal.h that depend on
45  pcre_internal.h that depend on COMPILE_PCRE8 or COMPILE_PCRE16. It does,  COMPILE_PCRE8, COMPILE_PCRE16, or COMPILE_PCRE32. It does, however, make use of
46  however, make use of SUPPORT_PCRE8 and SUPPORT_PCRE16 to ensure that it calls  SUPPORT_PCRE8, SUPPORT_PCRE16, and SUPPORT_PCRE32 to ensure that it calls only
47  only supported library functions. */  supported library functions. */
   
48    
49  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
50  #include "config.h"  #include "config.h"
# Line 59  only supported library functions. */ Line 58  only supported library functions. */
58  #include <locale.h>  #include <locale.h>
59  #include <errno.h>  #include <errno.h>
60    
61  #ifdef SUPPORT_LIBREADLINE  /* Both libreadline and libedit are optionally supported. The user-supplied
62    original patch uses readline/readline.h for libedit, but in at least one system
63    it is installed as editline/readline.h, so the configuration code now looks for
64    that first, falling back to readline/readline.h. */
65    
66    #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
67  #ifdef HAVE_UNISTD_H  #ifdef HAVE_UNISTD_H
68  #include <unistd.h>  #include <unistd.h>
69  #endif  #endif
70    #if defined(SUPPORT_LIBREADLINE)
71  #include <readline/readline.h>  #include <readline/readline.h>
72  #include <readline/history.h>  #include <readline/history.h>
73    #else
74    #if defined(HAVE_EDITLINE_READLINE_H)
75    #include <editline/readline.h>
76    #else
77    #include <readline/readline.h>
78    #endif
79    #endif
80  #endif  #endif
   
81    
82  /* A number of things vary for Windows builds. Originally, pcretest opened its  /* A number of things vary for Windows builds. Originally, pcretest opened its
83  input and output without "b"; then I was told that "b" was needed in some  input and output without "b"; then I was told that "b" was needed in some
# Line 101  input mode under Windows. */ Line 112  input mode under Windows. */
112  #else  #else
113  #include <sys/time.h>          /* These two includes are needed */  #include <sys/time.h>          /* These two includes are needed */
114  #include <sys/resource.h>      /* for setrlimit(). */  #include <sys/resource.h>      /* for setrlimit(). */
115    #if defined NATIVE_ZOS         /* z/OS uses non-binary I/O */
116    #define INPUT_MODE   "r"
117    #define OUTPUT_MODE  "w"
118    #else
119  #define INPUT_MODE   "rb"  #define INPUT_MODE   "rb"
120  #define OUTPUT_MODE  "wb"  #define OUTPUT_MODE  "wb"
121  #endif  #endif
122    #endif
123    
124  #define PRIV(name) name  #define PRIV(name) name
125    
# Line 117  here before pcre_internal.h so that the Line 133  here before pcre_internal.h so that the
133  appropriately for an application, not for building PCRE. */  appropriately for an application, not for building PCRE. */
134    
135  #include "pcre.h"  #include "pcre.h"
   
 #if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8  
 /* Configure internal macros to 16 bit mode. */  
 #define COMPILE_PCRE16  
 #endif  
   
136  #include "pcre_internal.h"  #include "pcre_internal.h"
137    
138  /* The pcre_printint() function, which prints the internal form of a compiled  /* The pcre_printint() function, which prints the internal form of a compiled
139  regex, is held in a separate file so that (a) it can be compiled in either  regex, is held in a separate file so that (a) it can be compiled in either
140  8-bit or 16-bit mode, and (b) it can be #included directly in pcre_compile.c  8-, 16- or 32-bit mode, and (b) it can be #included directly in pcre_compile.c
141  when that is compiled in debug mode. */  when that is compiled in debug mode. */
142    
143  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
# Line 136  void pcre_printint(pcre *external_re, FI Line 146  void pcre_printint(pcre *external_re, FI
146  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
147  void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths);  void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths);
148  #endif  #endif
149    #ifdef SUPPORT_PCRE32
150    void pcre32_printint(pcre *external_re, FILE *f, BOOL print_lengths);
151    #endif
152    
153  /* We need access to some of the data tables that PCRE uses. So as not to have  /* We need access to some of the data tables that PCRE uses. So as not to have
154  to keep two copies, we include the source file here, changing the names of the  to keep two copies, we include the source files here, changing the names of the
155  external symbols to prevent clashes. */  external symbols to prevent clashes. */
156    
157  #define PCRE_INCLUDED  #define PCRE_INCLUDED
158    
159  #include "pcre_tables.c"  #include "pcre_tables.c"
160    #include "pcre_ucd.c"
161    
162  /* The definition of the macro PRINTABLE, which determines whether to print an  /* The definition of the macro PRINTABLE, which determines whether to print an
163  output character as-is or as a hex value when showing compiled patterns, is  output character as-is or as a hex value when showing compiled patterns, is
# Line 159  that differ in their output from isprint Line 173  that differ in their output from isprint
173    
174  #define PRINTOK(c) (locale_set? isprint(c) : PRINTABLE(c))  #define PRINTOK(c) (locale_set? isprint(c) : PRINTABLE(c))
175    
176  /* Posix support is disabled in 16 bit only mode. */  /* Posix support is disabled in 16 or 32 bit only mode. */
177  #if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8 && !defined NOPOSIX  #if !defined SUPPORT_PCRE8 && !defined NOPOSIX
178  #define NOPOSIX  #define NOPOSIX
179  #endif  #endif
180    
# Line 183  automatically cut out the UTF support if Line 197  automatically cut out the UTF support if
197  #endif  #endif
198  #endif  #endif
199    
200  /* To make the code a bit tidier for 8-bit and 16-bit support, we define macros  /* To make the code a bit tidier for 8/16/32-bit support, we define macros
201  for all the pcre[16]_xxx functions (except pcre16_fullinfo, which is called  for all the pcre[16]_xxx functions (except pcre16_fullinfo, which is called
202  only from one place and is handled differently). I couldn't dream up any way of  only from one place and is handled differently). I couldn't dream up any way of
203  using a single macro to do this in a generic way, because of the many different  using a single macro to do this in a generic way, because of the many different
# Line 205  argument, the casting might be incorrect Line 219  argument, the casting might be incorrect
219  #define PCHARSV8(p, offset, len, f) \  #define PCHARSV8(p, offset, len, f) \
220    (void)pchars((pcre_uint8 *)(p) + offset, len, f)    (void)pchars((pcre_uint8 *)(p) + offset, len, f)
221    
222  #define READ_CAPTURE_NAME8(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME8(p, cn8, cn16, cn32, re) \
223    p = read_capture_name8(p, cn8, re)    p = read_capture_name8(p, cn8, re)
224    
225  #define STRLEN8(p) ((int)strlen((char *)p))  #define STRLEN8(p) ((int)strlen((char *)p))
# Line 274  argument, the casting might be incorrect Line 288  argument, the casting might be incorrect
288    
289  #define PCRE_JIT_STACK_FREE8(stack) \  #define PCRE_JIT_STACK_FREE8(stack) \
290    pcre_jit_stack_free(stack)    pcre_jit_stack_free(stack)
291    
292    #define pcre8_maketables pcre_maketables
293    
294  #endif /* SUPPORT_PCRE8 */  #endif /* SUPPORT_PCRE8 */
295    
# Line 287  argument, the casting might be incorrect Line 303  argument, the casting might be incorrect
303  #define PCHARSV16(p, offset, len, f) \  #define PCHARSV16(p, offset, len, f) \
304    (void)pchars16((PCRE_SPTR16)(p) + offset, len, f)    (void)pchars16((PCRE_SPTR16)(p) + offset, len, f)
305    
306  #define READ_CAPTURE_NAME16(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME16(p, cn8, cn16, cn32, re) \
307    p = read_capture_name16(p, cn16, re)    p = read_capture_name16(p, cn16, re)
308    
309  #define STRLEN16(p) ((int)strlen16((PCRE_SPTR16)p))  #define STRLEN16(p) ((int)strlen16((PCRE_SPTR16)p))
# Line 366  argument, the casting might be incorrect Line 382  argument, the casting might be incorrect
382    
383  #endif /* SUPPORT_PCRE16 */  #endif /* SUPPORT_PCRE16 */
384    
385    /* -----------------------------------------------------------*/
386    
387    #ifdef SUPPORT_PCRE32
388    
389    #define PCHARS32(lv, p, offset, len, f) \
390      lv = pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
391    
392    #define PCHARSV32(p, offset, len, f)                \
393      (void)pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
394    
395    #define READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re) \
396      p = read_capture_name32(p, cn32, re)
397    
398    #define STRLEN32(p) ((int)strlen32((PCRE_SPTR32)p))
399    
400    #define SET_PCRE_CALLOUT32(callout) \
401      pcre32_callout = (int (*)(pcre32_callout_block *))callout
402    
403    #define PCRE_ASSIGN_JIT_STACK32(extra, callback, userdata) \
404      pcre32_assign_jit_stack((pcre32_extra *)extra, \
405        (pcre32_jit_callback)callback, userdata)
406    
407    #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  /* ----- Both modes are supported; a runtime test is needed, except for  #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  };  };
1134    
1135    
# Line 1057  return sys_errlist[n]; Line 1481  return sys_errlist[n];
1481  #endif /* HAVE_STRERROR */  #endif /* HAVE_STRERROR */
1482    
1483    
1484    
1485    /*************************************************
1486    *       Print newline configuration              *
1487    *************************************************/
1488    
1489    /*
1490    Arguments:
1491      rc         the return code from PCRE_CONFIG_NEWLINE
1492      isc        TRUE if called from "-C newline"
1493    Returns:     nothing
1494    */
1495    
1496    static void
1497    print_newline_config(int rc, BOOL isc)
1498    {
1499    const char *s = NULL;
1500    if (!isc) printf("  Newline sequence is ");
1501    switch(rc)
1502      {
1503      case CHAR_CR: s = "CR"; break;
1504      case CHAR_LF: s = "LF"; break;
1505      case (CHAR_CR<<8 | CHAR_LF): s = "CRLF"; break;
1506      case -1: s = "ANY"; break;
1507      case -2: s = "ANYCRLF"; break;
1508    
1509      default:
1510      printf("a non-standard value: 0x%04x\n", rc);
1511      return;
1512      }
1513    
1514    printf("%s\n", s);
1515    }
1516    
1517    
1518    
1519  /*************************************************  /*************************************************
1520  *         JIT memory callback                    *  *         JIT memory callback                    *
1521  *************************************************/  *************************************************/
1522    
1523  static pcre_jit_stack* jit_callback(void *arg)  static pcre_jit_stack* jit_callback(void *arg)
1524  {  {
1525    jit_was_used = TRUE;
1526  return (pcre_jit_stack *)arg;  return (pcre_jit_stack *)arg;
1527  }  }
1528    
1529    
1530  #if !defined NOUTF || defined SUPPORT_PCRE16  #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32
1531  /*************************************************  /*************************************************
1532  *            Convert UTF-8 string to value       *  *            Convert UTF-8 string to value       *
1533  *************************************************/  *************************************************/
# Line 1084  Returns:      >  0 => the number of byte Line 1544  Returns:      >  0 => the number of byte
1544  */  */
1545    
1546  static int  static int
1547  utf82ord(pcre_uint8 *utf8bytes, int *vptr)  utf82ord(pcre_uint8 *utf8bytes, pcre_uint32 *vptr)
1548  {  {
1549  int c = *utf8bytes++;  pcre_uint32 c = *utf8bytes++;
1550  int d = c;  pcre_uint32 d = c;
1551  int i, j, s;  int i, j, s;
1552    
1553  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 1575  for (j = 0; j < i; j++)
1575  /* Check that encoding was the correct unique one */  /* Check that encoding was the correct unique one */
1576    
1577  for (j = 0; j < utf8_table1_size; j++)  for (j = 0; j < utf8_table1_size; j++)
1578    if (d <= utf8_table1[j]) break;    if (d <= (pcre_uint32)utf8_table1[j]) break;
1579  if (j != i) return -(i+1);  if (j != i) return -(i+1);
1580    
1581  /* Valid value */  /* Valid value */
# Line 1127  return i+1; Line 1587  return i+1;
1587    
1588    
1589    
1590  #if !defined NOUTF || defined SUPPORT_PCRE16  #if defined SUPPORT_PCRE8 && !defined NOUTF
1591  /*************************************************  /*************************************************
1592  *       Convert character value to UTF-8         *  *       Convert character value to UTF-8         *
1593  *************************************************/  *************************************************/
# Line 1143  Returns:     number of characters placed Line 1603  Returns:     number of characters placed
1603  */  */
1604    
1605  static int  static int
1606  ord2utf8(int cvalue, pcre_uint8 *utf8bytes)  ord2utf8(pcre_uint32 cvalue, pcre_uint8 *utf8bytes)
1607  {  {
1608  register int i, j;  register int i, j;
1609    if (cvalue > 0x7fffffffu)
1610      return -1;
1611  for (i = 0; i < utf8_table1_size; i++)  for (i = 0; i < utf8_table1_size; i++)
1612    if (cvalue <= utf8_table1[i]) break;    if (cvalue <= (pcre_uint32)utf8_table1[i]) break;
1613  utf8bytes += i;  utf8bytes += i;
1614  for (j = i; j > 0; j--)  for (j = i; j > 0; j--)
1615   {   {
# Line 1216  if (!utf && !data) Line 1678  if (!utf && !data)
1678    
1679  else  else
1680    {    {
1681    int c = 0;    pcre_uint32 c = 0;
1682    while (len > 0)    while (len > 0)
1683      {      {
1684      int chlen = utf82ord(p, &c);      int chlen = utf82ord(p, &c);
# Line 1239  return pp - buffer16; Line 1701  return pp - buffer16;
1701  }  }
1702  #endif  #endif
1703    
1704    #ifdef SUPPORT_PCRE32
1705    /*************************************************
1706    *         Convert a string to 32-bit             *
1707    *************************************************/
1708    
1709    /* In non-UTF mode, the space needed for a 32-bit string is exactly four times the
1710    8-bit size. For a UTF-8 string, the size needed for UTF-32 is no more than four
1711    times, because up to 0xffff uses no more than 3 bytes in UTF-8 but possibly 4
1712    in UTF-32. Higher values use 4 bytes in UTF-8 and up to 4 bytes in UTF-32. The
1713    result is always left in buffer32.
1714    
1715    Note that this function does not object to surrogate values. This is
1716    deliberate; it makes it possible to construct UTF-32 strings that are invalid,
1717    for the purpose of testing that they are correctly faulted.
1718    
1719    Patterns to be converted are either plain ASCII or UTF-8; data lines are always
1720    in UTF-8 so that values greater than 255 can be handled.
1721    
1722    Arguments:
1723      data       TRUE if converting a data line; FALSE for a regex
1724      p          points to a byte string
1725      utf        true if UTF-8 (to be converted to UTF-32)
1726      len        number of bytes in the string (excluding trailing zero)
1727    
1728    Returns:     number of 32-bit data items used (excluding trailing zero)
1729                 OR -1 if a UTF-8 string is malformed
1730                 OR -2 if a value > 0x10ffff is encountered
1731                 OR -3 if an ill-formed value is encountered (i.e. a surrogate)
1732    */
1733    
1734    static int
1735    to32(int data, pcre_uint8 *p, int utf, int len)
1736    {
1737    pcre_uint32 *pp;
1738    
1739    if (buffer32_size < 4*len + 4)
1740      {
1741      if (buffer32 != NULL) free(buffer32);
1742      buffer32_size = 4*len + 4;
1743      buffer32 = (pcre_uint32 *)malloc(buffer32_size);
1744      if (buffer32 == NULL)
1745        {
1746        fprintf(stderr, "pcretest: malloc(%d) failed for buffer32\n", buffer32_size);
1747        exit(1);
1748        }
1749      }
1750    
1751    pp = buffer32;
1752    
1753    if (!utf && !data)
1754      {
1755      while (len-- > 0) *pp++ = *p++;
1756      }
1757    
1758    else
1759      {
1760      pcre_uint32 c = 0;
1761      while (len > 0)
1762        {
1763        int chlen = utf82ord(p, &c);
1764        if (chlen <= 0) return -1;
1765        if (utf)
1766          {
1767          if (c > 0x10ffff) return -2;
1768          if (!data && (c & 0xfffff800u) == 0xd800u) return -3;
1769          }
1770    
1771        p += chlen;
1772        len -= chlen;
1773        *pp++ = c;
1774        }
1775      }
1776    
1777    *pp = 0;
1778    return pp - buffer32;
1779    }
1780    
1781    /* Check that a 32-bit character string is valid UTF-32.
1782    
1783    Arguments:
1784      string       points to the string
1785      length       length of string, or -1 if the string is zero-terminated
1786    
1787    Returns:       TRUE  if the string is a valid UTF-32 string
1788                   FALSE otherwise
1789    */
1790    
1791    #ifdef SUPPORT_UTF
1792    static BOOL
1793    valid_utf32(pcre_uint32 *string, int length)
1794    {
1795    register pcre_uint32 *p;
1796    register pcre_uint32 c;
1797    
1798    for (p = string; length-- > 0; p++)
1799      {
1800      c = *p;
1801    
1802      if (c > 0x10ffffu)
1803        return FALSE;
1804    
1805      /* A surrogate */
1806      if ((c & 0xfffff800u) == 0xd800u)
1807        return FALSE;
1808    
1809      /* Non-character */
1810      if ((c & 0xfffeu) == 0xfffeu || (c >= 0xfdd0u && c <= 0xfdefu))
1811        return FALSE;
1812      }
1813    
1814    return TRUE;
1815    }
1816    #endif /* SUPPORT_UTF */
1817    
1818    #endif
1819    
1820  /*************************************************  /*************************************************
1821  *        Read or extend an input line            *  *        Read or extend an input line            *
# Line 1276  for (;;) Line 1853  for (;;)
1853      {      {
1854      int dlen;      int dlen;
1855    
1856      /* 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
1857      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
1858      we must put it back again, to be compatible with fgets(). */      newline, so we must put it back again, to be compatible with fgets(). */
1859    
1860  #ifdef SUPPORT_LIBREADLINE  #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
1861      if (isatty(fileno(f)))      if (isatty(fileno(f)))
1862        {        {
1863        size_t len;        size_t len;
# Line 1314  for (;;) Line 1891  for (;;)
1891      {      {
1892      int new_buffer_size = 2*buffer_size;      int new_buffer_size = 2*buffer_size;
1893      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);  
1894      pcre_uint8 *new_pbuffer = (pcre_uint8 *)malloc(new_buffer_size);      pcre_uint8 *new_pbuffer = (pcre_uint8 *)malloc(new_buffer_size);
1895    
1896      if (new_buffer == NULL || new_dbuffer == NULL || new_pbuffer == NULL)      if (new_buffer == NULL || new_pbuffer == NULL)
1897        {        {
1898        fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);        fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);
1899        exit(1);        exit(1);
# Line 1332  for (;;) Line 1908  for (;;)
1908      here = new_buffer + (here - buffer);      here = new_buffer + (here - buffer);
1909    
1910      free(buffer);      free(buffer);
     free(dbuffer);  
1911      free(pbuffer);      free(pbuffer);
1912    
1913      buffer = new_buffer;      buffer = new_buffer;
     dbuffer = new_dbuffer;  
1914      pbuffer = new_pbuffer;      pbuffer = new_pbuffer;
1915      }      }
1916    }    }
# Line 1379  return(result); Line 1953  return(result);
1953    
1954  /* Print a single character either literally, or as a hex escape. */  /* Print a single character either literally, or as a hex escape. */
1955    
1956  static int pchar(int c, FILE *f)  static int pchar(pcre_uint32 c, FILE *f)
1957  {  {
1958    int n = 0;
1959  if (PRINTOK(c))  if (PRINTOK(c))
1960    {    {
1961    if (f != NULL) fprintf(f, "%c", c);    if (f != NULL) fprintf(f, "%c", c);
# Line 1401  if (c < 0x100) Line 1976  if (c < 0x100)
1976      }      }
1977    }    }
1978    
1979  if (f != NULL) fprintf(f, "\\x{%02x}", c);  if (f != NULL) n = fprintf(f, "\\x{%02x}", c);
1980  return (c <= 0x000000ff)? 6 :  return n >= 0 ? n : 0;
        (c <= 0x00000fff)? 7 :  
        (c <= 0x0000ffff)? 8 :  
        (c <= 0x000fffff)? 9 : 10;  
1981  }  }
1982    
1983    
# Line 1420  If handed a NULL file, just counts chars Line 1992  If handed a NULL file, just counts chars
1992    
1993  static int pchars(pcre_uint8 *p, int length, FILE *f)  static int pchars(pcre_uint8 *p, int length, FILE *f)
1994  {  {
1995  int c = 0;  pcre_uint32 c = 0;
1996  int yield = 0;  int yield = 0;
1997    
1998  if (length < 0)  if (length < 0)
# Line 1465  return len; Line 2037  return len;
2037  #endif  /* SUPPORT_PCRE16 */  #endif  /* SUPPORT_PCRE16 */
2038    
2039    
2040    
2041    #ifdef SUPPORT_PCRE32
2042    /*************************************************
2043    *    Find length of 0-terminated 32-bit string   *
2044    *************************************************/
2045    
2046    static int strlen32(PCRE_SPTR32 p)
2047    {
2048    int len = 0;
2049    while (*p++ != 0) len++;
2050    return len;
2051    }
2052    #endif  /* SUPPORT_PCRE32 */
2053    
2054    
2055    
2056  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2057  /*************************************************  /*************************************************
2058  *           Print 16-bit character string        *  *           Print 16-bit character string        *
# Line 1482  if (length < 0) Line 2070  if (length < 0)
2070    
2071  while (length-- > 0)  while (length-- > 0)
2072    {    {
2073    int c = *p++ & 0xffff;    pcre_uint32 c = *p++ & 0xffff;
2074  #if !defined NOUTF  #if !defined NOUTF
2075    if (use_utf && c >= 0xD800 && c < 0xDC00 && length > 0)    if (use_utf && c >= 0xD800 && c < 0xDC00 && length > 0)
2076      {      {
# Line 1504  return yield; Line 2092  return yield;
2092    
2093    
2094    
2095    #ifdef SUPPORT_PCRE32
2096    /*************************************************
2097    *           Print 32-bit character string        *
2098    *************************************************/
2099    
2100    /* Must handle UTF-32 strings in utf mode. Yields number of characters printed.
2101    If handed a NULL file, just counts chars without printing. */
2102    
2103    #define UTF32_MASK (0x1fffffu)
2104    
2105    static int pchars32(PCRE_SPTR32 p, int length, BOOL utf, FILE *f)
2106    {
2107    int yield = 0;
2108    
2109    if (length < 0)
2110      length = strlen32(p);
2111    
2112    while (length-- > 0)
2113      {
2114      pcre_uint32 c = *p++;
2115      if (utf) c &= UTF32_MASK;
2116      yield += pchar(c, f);
2117      }
2118    
2119    return yield;
2120    }
2121    #endif  /* SUPPORT_PCRE32 */
2122    
2123    
2124    
2125  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
2126  /*************************************************  /*************************************************
2127  *     Read a capture name (8-bit) and check it   *  *     Read a capture name (8-bit) and check it   *
# Line 1557  return p; Line 2175  return p;
2175    
2176    
2177    
2178    #ifdef SUPPORT_PCRE32
2179    /*************************************************
2180    *     Read a capture name (32-bit) and check it  *
2181    *************************************************/
2182    
2183    /* Note that the text being read is 8-bit. */
2184    
2185    static pcre_uint8 *
2186    read_capture_name32(pcre_uint8 *p, pcre_uint32 **pp, pcre *re)
2187    {
2188    pcre_uint32 *npp = *pp;
2189    while (isalnum(*p)) *npp++ = *p++;
2190    *npp++ = 0;
2191    *npp = 0;
2192    if (pcre32_get_stringnumber((pcre32 *)re, (PCRE_SPTR32)(*pp)) < 0)
2193      {
2194      fprintf(outfile, "no parentheses with name \"");
2195      PCHARSV(*pp, 0, -1, outfile);
2196      fprintf(outfile, "\"\n");
2197      }
2198    *pp = npp;
2199    return p;
2200    }
2201    #endif  /* SUPPORT_PCRE32 */
2202    
2203    
2204    
2205  /*************************************************  /*************************************************
2206  *              Callout function                  *  *              Callout function                  *
2207  *************************************************/  *************************************************/
# Line 1714  free(block); Line 2359  free(block);
2359  *************************************************/  *************************************************/
2360    
2361  /* Get one piece of information from the pcre_fullinfo() function. When only  /* Get one piece of information from the pcre_fullinfo() function. When only
2362  one of 8-bit or 16-bit is supported, use_pcre16 should always have the correct  one of 8-, 16- or 32-bit is supported, pcre_mode should always have the correct
2363  value, but the code is defensive.  value, but the code is defensive.
2364    
2365  Arguments:  Arguments:
# Line 1731  new_info(pcre *re, pcre_extra *study, in Line 2376  new_info(pcre *re, pcre_extra *study, in
2376  {  {
2377  int rc;  int rc;
2378    
2379  if (use_pcre16)  if (pcre_mode == PCRE32_MODE)
2380    #ifdef SUPPORT_PCRE32
2381      rc = pcre32_fullinfo((pcre32 *)re, (pcre32_extra *)study, option, ptr);
2382    #else
2383      rc = PCRE_ERROR_BADMODE;
2384    #endif
2385    else if (pcre_mode == PCRE16_MODE)
2386  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2387    rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);    rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);
2388  #else  #else
# Line 1747  else Line 2398  else
2398  if (rc < 0)  if (rc < 0)
2399    {    {
2400    fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,    fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
2401      use_pcre16? "16" : "", option);      pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "", option);
2402    if (rc == PCRE_ERROR_BADMODE)    if (rc == PCRE_ERROR_BADMODE)
2403      fprintf(outfile, "Running in %s-bit mode but pattern was compiled in "      fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
2404        "%s-bit mode\n", use_pcre16? "16":"8", use_pcre16? "8":"16");        "%d-bit mode\n", 8 * CHAR_SIZE,
2405          8 * (REAL_PCRE_FLAGS(re) & PCRE_MODE_MASK));
2406    }    }
2407    
2408  return rc;  return rc;
# Line 1799  bytes in the pattern itself. This is to Line 2451  bytes in the pattern itself. This is to
2451  ability to reload byte-flipped patterns, e.g. those compiled on a different  ability to reload byte-flipped patterns, e.g. those compiled on a different
2452  architecture. */  architecture. */
2453    
2454    #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
2455  static void  static void
2456  regexflip(pcre *ere, pcre_extra *extra)  regexflip8_or_16(pcre *ere, pcre_extra *extra)
2457  {  {
2458  REAL_PCRE *re = (REAL_PCRE *)ere;  real_pcre8_or_16 *re = (real_pcre8_or_16 *)ere;
2459  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2460  int op;  int op;
2461  pcre_uint16 *ptr = (pcre_uint16 *)re + re->name_table_offset;  pcre_uint16 *ptr = (pcre_uint16 *)re + re->name_table_offset;
# Line 1839  if (extra != NULL) Line 2492  if (extra != NULL)
2492  in the name table, if present, and then in the pattern itself. */  in the name table, if present, and then in the pattern itself. */
2493    
2494  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2495  if (!use_pcre16) return;  if (pcre_mode != PCRE16_MODE) return;
2496    
2497  while(TRUE)  while(TRUE)
2498    {    {
# Line 1977  while(TRUE) Line 2630  while(TRUE)
2630  /* Control should never reach here in 16 bit mode. */  /* Control should never reach here in 16 bit mode. */
2631  #endif /* SUPPORT_PCRE16 */  #endif /* SUPPORT_PCRE16 */
2632  }  }
2633    #endif /* SUPPORT_PCRE[8|16] */
2634    
2635    
2636    
2637    #if defined SUPPORT_PCRE32
2638    static void
2639    regexflip_32(pcre *ere, pcre_extra *extra)
2640    {
2641    real_pcre32 *re = (real_pcre32 *)ere;
2642    int op;
2643    pcre_uint32 *ptr = (pcre_uint32 *)re + re->name_table_offset;
2644    int length = re->name_count * re->name_entry_size;
2645    
2646    /* Always flip the bytes in the main data block and study blocks. */
2647    
2648    re->magic_number = REVERSED_MAGIC_NUMBER;
2649    re->size = swap_uint32(re->size);
2650    re->options = swap_uint32(re->options);
2651    re->flags = swap_uint16(re->flags);
2652    re->top_bracket = swap_uint16(re->top_bracket);
2653    re->top_backref = swap_uint16(re->top_backref);
2654    re->first_char = swap_uint32(re->first_char);
2655    re->req_char = swap_uint32(re->req_char);
2656    re->name_table_offset = swap_uint16(re->name_table_offset);
2657    re->name_entry_size = swap_uint16(re->name_entry_size);
2658    re->name_count = swap_uint16(re->name_count);
2659    
2660    if (extra != NULL)
2661      {
2662      pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
2663      rsd->size = swap_uint32(rsd->size);
2664      rsd->flags = swap_uint32(rsd->flags);
2665      rsd->minlength = swap_uint32(rsd->minlength);
2666      }
2667    
2668    /* In 32-bit mode we must swap bytes in the name table, if present, and then in
2669    the pattern itself. */
2670    
2671    while(TRUE)
2672      {
2673      /* Swap previous characters. */
2674      while (length-- > 0)
2675        {
2676        *ptr = swap_uint32(*ptr);
2677        ptr++;
2678        }
2679    
2680      /* Get next opcode. */
2681    
2682      length = 0;
2683      op = *ptr;
2684      *ptr++ = swap_uint32(op);
2685    
2686      switch (op)
2687        {
2688        case OP_END:
2689        return;
2690    
2691        default:
2692        length = OP_lengths32[op] - 1;
2693        break;
2694    
2695        case OP_CLASS:
2696        case OP_NCLASS:
2697        /* Skip the character bit map. */
2698        ptr += 32/sizeof(pcre_uint32);
2699        length = 0;
2700        break;
2701    
2702        case OP_XCLASS:
2703        /* LINK_SIZE can only be 1 in 32-bit mode. */
2704        length = (int)((unsigned int)(ptr[0]) - (1 + LINK_SIZE + 1));
2705    
2706        /* Reverse the size of the XCLASS instance. */
2707        *ptr = swap_uint32(*ptr);
2708        ptr++;
2709    
2710        op = *ptr;
2711        *ptr = swap_uint32(op);
2712        ptr++;
2713        if ((op & XCL_MAP) != 0)
2714          {
2715          /* Skip the character bit map. */
2716          ptr += 32/sizeof(pcre_uint32);
2717          length -= 32/sizeof(pcre_uint32);
2718          }
2719        break;
2720        }
2721      }
2722    /* Control should never reach here in 32 bit mode. */
2723    }
2724    
2725    #endif /* SUPPORT_PCRE32 */
2726    
2727    
2728    
2729    static void
2730    regexflip(pcre *ere, pcre_extra *extra)
2731    {
2732    #if defined SUPPORT_PCRE32
2733      if (REAL_PCRE_FLAGS(ere) & PCRE_MODE32)
2734        regexflip_32(ere, extra);
2735    #endif
2736    #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
2737      if (REAL_PCRE_FLAGS(ere) & (PCRE_MODE8 | PCRE_MODE16))
2738        regexflip8_or_16(ere, extra);
2739    #endif
2740    }
2741    
2742    
2743    
# Line 2096  usage(void) Line 2857  usage(void)
2857  {  {
2858  printf("Usage:     pcretest [options] [<input file> [<output file>]]\n\n");  printf("Usage:     pcretest [options] [<input file> [<output file>]]\n\n");
2859  printf("Input and output default to stdin and stdout.\n");  printf("Input and output default to stdin and stdout.\n");
2860  #ifdef SUPPORT_LIBREADLINE  #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
2861  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");
2862  #else  #else
2863  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 2866  printf("\nOptions:\n");
2866  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2867  printf("  -16      use the 16-bit library\n");  printf("  -16      use the 16-bit library\n");
2868  #endif  #endif
2869    #ifdef SUPPORT_PCRE32
2870    printf("  -32      use the 32-bit library\n");
2871    #endif
2872  printf("  -b       show compiled code\n");  printf("  -b       show compiled code\n");
2873  printf("  -C       show PCRE compile-time options and exit\n");  printf("  -C       show PCRE compile-time options and exit\n");
2874  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 2876  printf("           and exit with its val
2876  printf("     linksize     internal link size [2, 3, 4]\n");  printf("     linksize     internal link size [2, 3, 4]\n");
2877  printf("     pcre8        8 bit library support enabled [0, 1]\n");  printf("     pcre8        8 bit library support enabled [0, 1]\n");
2878  printf("     pcre16       16 bit library support enabled [0, 1]\n");  printf("     pcre16       16 bit library support enabled [0, 1]\n");
2879    printf("     pcre32       32 bit library support enabled [0, 1]\n");
2880  printf("     utf          Unicode Transformation Format supported [0, 1]\n");  printf("     utf          Unicode Transformation Format supported [0, 1]\n");
2881  printf("     ucp          Unicode Properties supported [0, 1]\n");  printf("     ucp          Unicode Properties supported [0, 1]\n");
2882  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 2897  printf("  -q       quiet: do not output
2897  printf("  -S <n>   set stack size to <n> megabytes\n");  printf("  -S <n>   set stack size to <n> megabytes\n");
2898  printf("  -s       force each pattern to be studied at basic level\n"  printf("  -s       force each pattern to be studied at basic level\n"
2899         "  -s+      force each pattern to be studied, using JIT if available\n"         "  -s+      force each pattern to be studied, using JIT if available\n"
2900           "  -s++     ditto, verifying when JIT was actually used\n"
2901           "  -s+n     force each pattern to be studied, using JIT if available,\n"
2902           "             where 1 <= n <= 7 selects JIT options\n"
2903           "  -s++n    ditto, verifying when JIT was actually used\n"
2904         "  -t       time compilation and execution\n");         "  -t       time compilation and execution\n");
2905  printf("  -t <n>   time compilation and execution, repeating <n> times\n");  printf("  -t <n>   time compilation and execution, repeating <n> times\n");
2906  printf("  -tm      time execution (matching) only\n");  printf("  -tm      time execution (matching) only\n");
# Line 2166  int quiet = 0; Line 2935  int quiet = 0;
2935  int size_offsets = 45;  int size_offsets = 45;
2936  int size_offsets_max;  int size_offsets_max;
2937  int *offsets = NULL;  int *offsets = NULL;
 #if !defined NOPOSIX  
 int posix = 0;  
 #endif  
2938  int debug = 0;  int debug = 0;
2939  int done = 0;  int done = 0;
2940  int all_use_dfa = 0;  int all_use_dfa = 0;
2941    int verify_jit = 0;
2942  int yield = 0;  int yield = 0;
2943    #ifdef SUPPORT_PCRE32
2944    int mask_utf32 = 0;
2945    #endif
2946  int stack_size;  int stack_size;
2947    pcre_uint8 *dbuffer = NULL;
2948    size_t dbuffer_size = 1u << 14;
2949    
2950    #if !defined NOPOSIX
2951    int posix = 0;
2952    #endif
2953    #if !defined NODFA
2954    int *dfa_workspace = NULL;
2955    #endif
2956    
2957  pcre_jit_stack *jit_stack = NULL;  pcre_jit_stack *jit_stack = NULL;
2958    
2959  /* These vectors store, end-to-end, a list of zero-terminated captured  /* These vectors store, end-to-end, a list of zero-terminated captured
2960  substring names, each list itself being terminated by an empty name. Assume  substring names, each list itself being terminated by an empty name. Assume
2961  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
2962  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
2963  for the actual memory, to ensure alignment. */  for the actual memory, to ensure alignment. */
2964    
2965  pcre_uint16 copynames[1024];  pcre_uint32 copynames[1024];
2966  pcre_uint16 getnames[1024];  pcre_uint32 getnames[1024];
2967    
2968    #ifdef SUPPORT_PCRE32
2969    pcre_uint32 *cn32ptr;
2970    pcre_uint32 *gn32ptr;
2971    #endif
2972    
2973  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2974    pcre_uint16 *copynames16 = (pcre_uint16 *)copynames;
2975    pcre_uint16 *getnames16 = (pcre_uint16 *)getnames;
2976  pcre_uint16 *cn16ptr;  pcre_uint16 *cn16ptr;
2977  pcre_uint16 *gn16ptr;  pcre_uint16 *gn16ptr;
2978  #endif  #endif
# Line 2199  pcre_uint8 *gn8ptr; Line 2985  pcre_uint8 *gn8ptr;
2985  #endif  #endif
2986    
2987  /* Get buffers from malloc() so that valgrind will check their misuse when  /* Get buffers from malloc() so that valgrind will check their misuse when
2988  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-
2989  buffer (buffer16) is obtained only if needed. */  and 32-bit buffers (buffer16, buffer32) are obtained only if needed. */
2990    
2991  buffer = (pcre_uint8 *)malloc(buffer_size);  buffer = (pcre_uint8 *)malloc(buffer_size);
 dbuffer = (pcre_uint8 *)malloc(buffer_size);  
2992  pbuffer = (pcre_uint8 *)malloc(buffer_size);  pbuffer = (pcre_uint8 *)malloc(buffer_size);
2993    
2994  /* 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 3007  _setmode( _fileno( stdout ), _O_BINARY )
3007  /* Get the version number: both pcre_version() and pcre16_version() give the  /* Get the version number: both pcre_version() and pcre16_version() give the
3008  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. */
3009    
3010  #ifdef SUPPORT_PCRE8  #if defined SUPPORT_PCRE8
3011  version = pcre_version();  version = pcre_version();
3012  #else  #elif defined SUPPORT_PCRE16
3013  version = pcre16_version();  version = pcre16_version();
3014    #elif defined SUPPORT_PCRE32
3015    version = pcre32_version();
3016  #endif  #endif
3017    
3018  /* Scan options */  /* Scan options */
# Line 2233  version = pcre16_version(); Line 3020  version = pcre16_version();
3020  while (argc > 1 && argv[op][0] == '-')  while (argc > 1 && argv[op][0] == '-')
3021    {    {
3022    pcre_uint8 *endptr;    pcre_uint8 *endptr;
3023      char *arg = argv[op];
3024    
3025      if (strcmp(arg, "-m") == 0) showstore = 1;
3026      else if (strcmp(arg, "-s") == 0) force_study = 0;
3027    
3028    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)  
3029      {      {
3030        arg += 3;
3031        if (*arg == '+') { arg++; verify_jit = TRUE; }
3032      force_study = 1;      force_study = 1;
3033      force_study_options = PCRE_STUDY_JIT_COMPILE;      if (*arg == 0)
3034          force_study_options = jit_study_bits[6];
3035        else if (*arg >= '1' && *arg <= '7')
3036          force_study_options = jit_study_bits[*arg - '1'];
3037        else goto BAD_ARG;
3038        }
3039      else if (strcmp(arg, "-8") == 0)
3040        {
3041    #ifdef SUPPORT_PCRE8
3042        pcre_mode = PCRE8_MODE;
3043    #else
3044        printf("** This version of PCRE was built without 8-bit support\n");
3045        exit(1);
3046    #endif
3047      }      }
3048    else if (strcmp(argv[op], "-16") == 0)    else if (strcmp(arg, "-16") == 0)
3049      {      {
3050  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3051      use_pcre16 = 1;      pcre_mode = PCRE16_MODE;
3052  #else  #else
3053      printf("** This version of PCRE was built without 16-bit support\n");      printf("** This version of PCRE was built without 16-bit support\n");
3054      exit(1);      exit(1);
3055  #endif  #endif
3056      }      }
3057    else if (strcmp(argv[op], "-q") == 0) quiet = 1;    else if (strcmp(arg, "-32") == 0 || strcmp(arg, "-32+") == 0)
3058    else if (strcmp(argv[op], "-b") == 0) debug = 1;      {
3059    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;  #ifdef SUPPORT_PCRE32
3060    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;      pcre_mode = PCRE32_MODE;
3061    else if (strcmp(argv[op], "-M") == 0) default_find_match_limit = TRUE;      mask_utf32 = (strcmp(arg, "-32+") == 0);
3062    #else
3063        printf("** This version of PCRE was built without 32-bit support\n");
3064        exit(1);
3065    #endif
3066        }
3067      else if (strcmp(arg, "-q") == 0) quiet = 1;
3068      else if (strcmp(arg, "-b") == 0) debug = 1;
3069      else if (strcmp(arg, "-i") == 0) showinfo = 1;
3070      else if (strcmp(arg, "-d") == 0) showinfo = debug = 1;
3071      else if (strcmp(arg, "-M") == 0) default_find_match_limit = TRUE;
3072  #if !defined NODFA  #if !defined NODFA
3073    else if (strcmp(argv[op], "-dfa") == 0) all_use_dfa = 1;    else if (strcmp(arg, "-dfa") == 0) all_use_dfa = 1;
3074  #endif  #endif
3075    else if (strcmp(argv[op], "-o") == 0 && argc > 2 &&    else if (strcmp(arg, "-o") == 0 && argc > 2 &&
3076        ((size_offsets = get_value((pcre_uint8 *)argv[op+1], &endptr)),        ((size_offsets = get_value((pcre_uint8 *)argv[op+1], &endptr)),
3077          *endptr == 0))          *endptr == 0))
3078      {      {
3079      op++;      op++;
3080      argc--;      argc--;
3081      }      }
3082    else if (strcmp(argv[op], "-t") == 0 || strcmp(argv[op], "-tm") == 0)    else if (strcmp(arg, "-t") == 0 || strcmp(arg, "-tm") == 0)
3083      {      {
3084      int both = argv[op][2] == 0;      int both = arg[2] == 0;
3085      int temp;      int temp;
3086      if (argc > 2 && (temp = get_value((pcre_uint8 *)argv[op+1], &endptr),      if (argc > 2 && (temp = get_value((pcre_uint8 *)argv[op+1], &endptr),
3087                       *endptr == 0))                       *endptr == 0))
# Line 2279  while (argc > 1 && argv[op][0] == '-') Line 3093  while (argc > 1 && argv[op][0] == '-')
3093      else timeitm = LOOPREPEAT;      else timeitm = LOOPREPEAT;
3094      if (both) timeit = timeitm;      if (both) timeit = timeitm;
3095      }      }
3096    else if (strcmp(argv[op], "-S") == 0 && argc > 2 &&    else if (strcmp(arg, "-S") == 0 && argc > 2 &&
3097        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),
3098          *endptr == 0))          *endptr == 0))
3099      {      {
3100  #if defined(_WIN32) || defined(WIN32) || defined(__minix)  #if defined(_WIN32) || defined(WIN32) || defined(__minix) || defined(NATIVE_ZOS)
3101      printf("PCRE: -S not supported on this OS\n");      printf("PCRE: -S not supported on this OS\n");
3102      exit(1);      exit(1);
3103  #else  #else
# Line 2302  while (argc > 1 && argv[op][0] == '-') Line 3116  while (argc > 1 && argv[op][0] == '-')
3116  #endif  #endif
3117      }      }
3118  #if !defined NOPOSIX  #if !defined NOPOSIX
3119    else if (strcmp(argv[op], "-p") == 0) posix = 1;    else if (strcmp(arg, "-p") == 0) posix = 1;
3120  #endif  #endif
3121    else if (strcmp(argv[op], "-C") == 0)    else if (strcmp(arg, "-C") == 0)
3122      {      {
3123      int rc;      int rc;
3124      unsigned long int lrc;      unsigned long int lrc;
# Line 2316  while (argc > 1 && argv[op][0] == '-') Line 3130  while (argc > 1 && argv[op][0] == '-')
3130          (void)PCRE_CONFIG(PCRE_CONFIG_LINK_SIZE, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_LINK_SIZE, &rc);
3131          printf("%d\n", rc);          printf("%d\n", rc);
3132          yield = rc;          yield = rc;
         goto EXIT;  
3133          }          }
3134        if (strcmp(argv[op + 1], "pcre8") == 0)        else if (strcmp(argv[op + 1], "pcre8") == 0)
3135          {          {
3136  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
3137          printf("1\n");          printf("1\n");
# Line 2327  while (argc > 1 && argv[op][0] == '-') Line 3140  while (argc > 1 && argv[op][0] == '-')
3140          printf("0\n");          printf("0\n");
3141          yield = 0;          yield = 0;
3142  #endif  #endif
         goto EXIT;  
3143          }          }
3144        if (strcmp(argv[op + 1], "pcre16") == 0)        else if (strcmp(argv[op + 1], "pcre16") == 0)
3145            {
3146    #ifdef SUPPORT_PCRE16
3147            printf("1\n");
3148            yield = 1;
3149    #else
3150            printf("0\n");
3151            yield = 0;
3152    #endif
3153            }
3154          else if (strcmp(argv[op + 1], "pcre32") == 0)
3155          {          {
3156  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE32
3157          printf("1\n");          printf("1\n");
3158          yield = 1;          yield = 1;
3159  #else  #else
# Line 2343  while (argc > 1 && argv[op][0] == '-') Line 3165  while (argc > 1 && argv[op][0] == '-')
3165        if (strcmp(argv[op + 1], "utf") == 0)        if (strcmp(argv[op + 1], "utf") == 0)
3166          {          {
3167  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
3168          (void)pcre_config(PCRE_CONFIG_UTF8, &rc);          if (pcre_mode == PCRE8_MODE)
3169          printf("%d\n", rc);            (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
3170          yield = rc;  #endif
3171  #else  #ifdef SUPPORT_PCRE16
3172          (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);          if (pcre_mode == PCRE16_MODE)
3173              (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
3174    #endif
3175    #ifdef SUPPORT_PCRE32
3176            if (pcre_mode == PCRE32_MODE)
3177              (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
3178    #endif
3179          printf("%d\n", rc);          printf("%d\n", rc);
3180          yield = rc;          yield = rc;
 #endif  
3181          goto EXIT;          goto EXIT;
3182          }          }
3183        if (strcmp(argv[op + 1], "ucp") == 0)        else if (strcmp(argv[op + 1], "ucp") == 0)
3184          {          {
3185          (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
3186          printf("%d\n", rc);          printf("%d\n", rc);
3187          yield = rc;          yield = rc;
         goto EXIT;  
3188          }          }
3189        if (strcmp(argv[op + 1], "jit") == 0)        else if (strcmp(argv[op + 1], "jit") == 0)
3190          {          {
3191          (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);
3192          printf("%d\n", rc);          printf("%d\n", rc);
3193          yield = rc;          yield = rc;
         goto EXIT;  
3194          }          }
3195        if (strcmp(argv[op + 1], "newline") == 0)        else if (strcmp(argv[op + 1], "newline") == 0)
3196          {          {
3197          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3198          /* Note that these values are always the ASCII values, even          print_newline_config(rc, TRUE);
3199          in EBCDIC environments. CR is 13 and NL is 10. */          }
3200          printf("%s\n", (rc == 13)? "CR" :        else if (strcmp(argv[op + 1], "ebcdic") == 0)
3201            (rc == 10)? "LF" : (rc == (13<<8 | 10))? "CRLF" :          {
3202            (rc == -2)? "ANYCRLF" :  #ifdef EBCDIC
3203            (rc == -1)? "ANY" : "???");          printf("1\n");
3204          goto EXIT;          yield = 1;
3205    #else
3206            printf("0\n");
3207    #endif
3208            }
3209          else if (strcmp(argv[op + 1], "ebcdic-nl") == 0)
3210            {
3211    #ifdef EBCDIC
3212            printf("0x%02x\n", CHAR_LF);
3213    #else
3214            printf("0\n");
3215    #endif
3216            }
3217          else
3218            {
3219            printf("Unknown -C option: %s\n", argv[op + 1]);
3220          }          }
       printf("Unknown -C option: %s\n", argv[op + 1]);  
3221        goto EXIT;        goto EXIT;
3222        }        }
3223    
3224        /* No argument for -C: output all configuration information. */
3225    
3226      printf("PCRE version %s\n", version);      printf("PCRE version %s\n", version);
3227      printf("Compiled with\n");      printf("Compiled with\n");
3228    
3229    #ifdef EBCDIC
3230        printf("  EBCDIC code support: LF is 0x%02x\n", CHAR_LF);
3231    #endif
3232    
3233  /* 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
3234  are set, either both UTFs are supported or both are not supported. */  are set, either both UTFs are supported or both are not supported. */
3235    
3236  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE8
3237      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");  
3238      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
3239      printf("  %sUTF-8 support\n", rc? "" : "No ");        printf ("  %sUTF-8 support\n", rc ? "" : "No ");
3240  #else  #endif
3241      printf("  16-bit support only\n");  #ifdef SUPPORT_PCRE16
3242        printf("  16-bit support\n");
3243      (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);      (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
3244      printf("  %sUTF-16 support\n", rc? "" : "No ");      printf ("  %sUTF-16 support\n", rc ? "" : "No ");
3245    #endif
3246    #ifdef SUPPORT_PCRE32
3247        printf("  32-bit support\n");
3248        (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
3249        printf ("  %sUTF-32 support\n", rc ? "" : "No ");
3250  #endif  #endif
3251    
3252      (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 3261  are set, either both UTFs are supported
3261      else      else
3262        printf("  No just-in-time compiler support\n");        printf("  No just-in-time compiler support\n");
3263      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3264      /* 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" : "???");  
3265      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);
3266      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :
3267                                       "all Unicode newlines");                                       "all Unicode newlines");
# Line 2444  are set, either both UTFs are supported Line 3283  are set, either both UTFs are supported
3283      printf("\n");      printf("\n");
3284      goto EXIT;      goto EXIT;
3285      }      }
3286    else if (strcmp(argv[op], "-help") == 0 ||    else if (strcmp(arg, "-help") == 0 ||
3287             strcmp(argv[op], "--help") == 0)             strcmp(arg, "--help") == 0)
3288      {      {
3289      usage();      usage();
3290      goto EXIT;      goto EXIT;
3291      }      }
3292    else    else
3293      {      {
3294      printf("** Unknown or malformed option %s\n", argv[op]);      BAD_ARG:
3295        printf("** Unknown or malformed option %s\n", arg);
3296      usage();      usage();
3297      yield = 1;      yield = 1;
3298      goto EXIT;      goto EXIT;
# Line 2513  pcre16_stack_malloc = stack_malloc; Line 3353  pcre16_stack_malloc = stack_malloc;
3353  pcre16_stack_free = stack_free;  pcre16_stack_free = stack_free;
3354  #endif  #endif
3355    
3356    #ifdef SUPPORT_PCRE32
3357    pcre32_malloc = new_malloc;
3358    pcre32_free = new_free;
3359    pcre32_stack_malloc = stack_malloc;
3360    pcre32_stack_free = stack_free;
3361    #endif
3362    
3363  /* Heading line unless quiet, then prompt for first regex if stdin */  /* Heading line unless quiet, then prompt for first regex if stdin */
3364    
3365  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 3397  while (!done)
3397    int do_flip = 0;    int do_flip = 0;
3398    int erroroffset, len, delimiter, poffset;    int erroroffset, len, delimiter, poffset;
3399    
3400    #if !defined NODFA
3401      int dfa_matched = 0;
3402    #endif
3403    
3404    use_utf = 0;    use_utf = 0;
3405    debug_lengths = 1;    debug_lengths = 1;
3406    
# Line 2597  while (!done) Line 3448  while (!done)
3448        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];
3449    
3450      re = (pcre *)new_malloc(true_size);      re = (pcre *)new_malloc(true_size);
3451        if (re == NULL)
3452          {
3453          printf("** Failed to get %d bytes of memory for pcre object\n",
3454            (int)true_size);
3455          yield = 1;
3456          goto EXIT;
3457          }
3458      regex_gotten_store = first_gotten_store;      regex_gotten_store = first_gotten_store;
3459    
3460      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;
3461    
3462      magic = ((REAL_PCRE *)re)->magic_number;      magic = REAL_PCRE_MAGIC(re);
3463      if (magic != MAGIC_NUMBER)      if (magic != MAGIC_NUMBER)
3464        {        {
3465        if (swap_uint32(magic) == MAGIC_NUMBER)        if (swap_uint32(magic) == MAGIC_NUMBER)
# Line 2611  while (!done) Line 3469  while (!done)
3469        else        else
3470          {          {
3471          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);
3472            new_free(re);
3473          fclose(f);          fclose(f);
3474          continue;          continue;
3475          }          }
# Line 2640  while (!done) Line 3499  while (!done)
3499            {            {
3500            PCRE_FREE_STUDY(extra);            PCRE_FREE_STUDY(extra);
3501            }            }
3502          if (re != NULL) new_free(re);          new_free(re);
3503          fclose(f);          fclose(f);
3504          continue;          continue;
3505          }          }
# Line 2658  while (!done) Line 3517  while (!done)
3517          {          {
3518          /* Simulate the result of the function call below. */          /* Simulate the result of the function call below. */
3519          fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,          fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
3520            use_pcre16? "16" : "", PCRE_INFO_OPTIONS);            pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "",
3521          fprintf(outfile, "Running in %s-bit mode but pattern was compiled in "            PCRE_INFO_OPTIONS);
3522            "%s-bit mode\n", use_pcre16? "16":"8", use_pcre16? "8":"16");          fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
3523              "%d-bit mode\n", 8 * CHAR_SIZE,
3524              8 * (REAL_PCRE_FLAGS(re) & PCRE_MODE_MASK));
3525            new_free(re);
3526            fclose(f);
3527          continue;          continue;
3528          }          }
3529        }        }
3530    
3531      /* Need to know if UTF-8 for printing data strings. */      /* Need to know if UTF-8 for printing data strings. */
3532    
3533      if (new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options) < 0) continue;      if (new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options) < 0)
3534          {
3535          new_free(re);
3536          fclose(f);
3537          continue;
3538          }
3539      use_utf = (get_options & PCRE_UTF8) != 0;      use_utf = (get_options & PCRE_UTF8) != 0;
3540    
3541      fclose(f);      fclose(f);
# Line 2726  while (!done) Line 3594  while (!done)
3594    /* Look for options after final delimiter */    /* Look for options after final delimiter */
3595    
3596    options = 0;    options = 0;
3597    study_options = 0;    study_options = force_study_options;
3598    log_store = showstore;  /* default from command line */    log_store = showstore;  /* default from command line */
3599    
3600    while (*pp != 0)    while (*pp != 0)
# Line 2763  while (!done) Line 3631  while (!done)
3631  #endif  #endif
3632    
3633        case 'S':        case 'S':
3634        if (do_study == 0)        do_study = 1;
3635          for (;;)
3636          {          {
3637          do_study = 1;          switch (*pp++)
         if (*pp == '+')  
3638            {            {
3639            study_options |= PCRE_STUDY_JIT_COMPILE;            case 'S':
3640            pp++;            do_study = 0;
3641              no_force_study = 1;
3642              break;
3643    
3644              case '!':
3645              study_options |= PCRE_STUDY_EXTRA_NEEDED;
3646              break;
3647    
3648              case '+':
3649              if (*pp == '+')
3650                {
3651                verify_jit = TRUE;
3652                pp++;
3653                }
3654              if (*pp >= '1' && *pp <= '7')
3655                study_options |= jit_study_bits[*pp++ - '1'];
3656              else
3657                study_options |= jit_study_bits[6];
3658              break;
3659    
3660              case '-':
3661              study_options &= ~PCRE_STUDY_ALLJIT;
3662              break;
3663    
3664              default:
3665              pp--;
3666              goto ENDLOOP;
3667            }            }
3668          }          }
3669        else        ENDLOOP:
         {  
         do_study = 0;  
         no_force_study = 1;  
         }  
3670        break;        break;
3671    
3672        case 'U': options |= PCRE_UNGREEDY; break;        case 'U': options |= PCRE_UNGREEDY; break;
# Line 2895  while (!done) Line 3785  while (!done)
3785  #endif  /* !defined NOPOSIX */  #endif  /* !defined NOPOSIX */
3786    
3787      {      {
3788      /* In 16-bit mode, convert the input. */      /* In 16- or 32-bit mode, convert the input. */
3789    
3790  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3791      if (use_pcre16)      if (pcre_mode == PCRE16_MODE)
3792        {        {
3793        switch(to16(FALSE, p, options & PCRE_UTF8, (int)strlen((char *)p)))        switch(to16(FALSE, p, options & PCRE_UTF8, (int)strlen((char *)p)))
3794          {          {
# Line 2924  while (!done) Line 3814  while (!done)
3814        }        }
3815  #endif  #endif
3816    
3817    #ifdef SUPPORT_PCRE32
3818        if (pcre_mode == PCRE32_MODE)
3819          {
3820          switch(to32(FALSE, p, options & PCRE_UTF32, (int)strlen((char *)p)))
3821            {
3822            case -1:
3823            fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "
3824              "converted to UTF-32\n");
3825            goto SKIP_DATA;
3826    
3827            case -2:
3828            fprintf(outfile, "**Failed: character value greater than 0x10ffff "
3829              "cannot be converted to UTF-32\n");
3830            goto SKIP_DATA;
3831    
3832            case -3:
3833            fprintf(outfile, "**Failed: character value is ill-formed UTF-32\n");
3834            goto SKIP_DATA;
3835    
3836            default:
3837            break;
3838            }
3839          p = (pcre_uint8 *)buffer32;
3840          }
3841    #endif
3842    
3843      /* Compile many times when timing */      /* Compile many times when timing */
3844    
3845      if (timeit > 0)      if (timeit > 0)
# Line 2981  while (!done) Line 3897  while (!done)
3897      /* Extract the size for possible writing before possibly flipping it,      /* Extract the size for possible writing before possibly flipping it,
3898      and remember the store that was got. */      and remember the store that was got. */
3899    
3900      true_size = ((REAL_PCRE *)re)->size;      true_size = REAL_PCRE_SIZE(re);
3901      regex_gotten_store = first_gotten_store;      regex_gotten_store = first_gotten_store;
3902    
3903      /* Output code size information if requested */      /* Output code size information if requested */
3904    
3905      if (log_store)      if (log_store)
3906          {
3907          int name_count, name_entry_size, real_pcre_size;
3908    
3909          new_info(re, NULL, PCRE_INFO_NAMECOUNT, &name_count);
3910          new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
3911          real_pcre_size = 0;
3912    #ifdef SUPPORT_PCRE8
3913          if (REAL_PCRE_FLAGS(re) & PCRE_MODE8)
3914            real_pcre_size = sizeof(real_pcre);
3915    #endif
3916    #ifdef SUPPORT_PCRE16
3917          if (REAL_PCRE_FLAGS(re) & PCRE_MODE16)
3918            real_pcre_size = sizeof(real_pcre16);
3919    #endif
3920    #ifdef SUPPORT_PCRE32
3921          if (REAL_PCRE_FLAGS(re) & PCRE_MODE32)
3922            real_pcre_size = sizeof(real_pcre32);
3923    #endif
3924        fprintf(outfile, "Memory allocation (code space): %d\n",        fprintf(outfile, "Memory allocation (code space): %d\n",
3925          (int)(first_gotten_store -          (int)(first_gotten_store - real_pcre_size - name_count * name_entry_size));
3926                sizeof(REAL_PCRE) -        }
               ((REAL_PCRE *)re)->name_count * ((REAL_PCRE *)re)->name_entry_size));  
3927    
3928      /* 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
3929      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 3939  while (!done)
3939          clock_t start_time = clock();          clock_t start_time = clock();
3940          for (i = 0; i < timeit; i++)          for (i = 0; i < timeit; i++)
3941            {            {
3942            PCRE_STUDY(extra, re, study_options | force_study_options, &error);            PCRE_STUDY(extra, re, study_options, &error);
3943            }            }
3944          time_taken = clock() - start_time;          time_taken = clock() - start_time;
3945          if (extra != NULL)          if (extra != NULL)
# Line 3017  while (!done) Line 3950  while (!done)
3950            (((double)time_taken * 1000.0) / (double)timeit) /            (((double)time_taken * 1000.0) / (double)timeit) /
3951              (double)CLOCKS_PER_SEC);              (double)CLOCKS_PER_SEC);
3952          }          }
3953        PCRE_STUDY(extra, re, study_options | force_study_options, &error);        PCRE_STUDY(extra, re, study_options, &error);
3954        if (error != NULL)        if (error != NULL)
3955          fprintf(outfile, "Failed to study: %s\n", error);          fprintf(outfile, "Failed to study: %s\n", error);
3956        else if (extra != NULL)        else if (extra != NULL)
# Line 3061  while (!done) Line 3994  while (!done)
3994      if (do_showinfo)      if (do_showinfo)
3995        {        {
3996        unsigned long int all_options;        unsigned long int all_options;
3997        int count, backrefmax, first_char, need_char, okpartial, jchanged,        pcre_uint32 first_char, need_char;
3998          hascrorlf;        int count, backrefmax, first_char_set, need_char_set, okpartial, jchanged,
3999            hascrorlf, maxlookbehind;
4000        int nameentrysize, namecount;        int nameentrysize, namecount;
4001        const pcre_uint8 *nametable;        const pcre_uint8 *nametable;
4002    
4003        if (new_info(re, NULL, PCRE_INFO_SIZE, &size) +        if (new_info(re, NULL, PCRE_INFO_SIZE, &size) +
4004            new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) +            new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) +
4005            new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax) +            new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax) +
4006            new_info(re, NULL, PCRE_INFO_FIRSTBYTE, &first_char) +            new_info(re, NULL, PCRE_INFO_FIRSTCHARACTER, &first_char) +
4007            new_info(re, NULL, PCRE_INFO_LASTLITERAL, &need_char) +            new_info(re, NULL, PCRE_INFO_FIRSTCHARACTERFLAGS, &first_char_set) +
4008              new_info(re, NULL, PCRE_INFO_REQUIREDCHAR, &need_char) +
4009              new_info(re, NULL, PCRE_INFO_REQUIREDCHARFLAGS, &need_char_set) +
4010            new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize) +            new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize) +
4011            new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount) +            new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount) +
4012            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +
4013            new_info(re, NULL, PCRE_INFO_OKPARTIAL, &okpartial) +            new_info(re, NULL, PCRE_INFO_OKPARTIAL, &okpartial) +
4014            new_info(re, NULL, PCRE_INFO_JCHANGED, &jchanged) +            new_info(re, NULL, PCRE_INFO_JCHANGED, &jchanged) +
4015            new_info(re, NULL, PCRE_INFO_HASCRORLF, &hascrorlf)            new_info(re, NULL, PCRE_INFO_HASCRORLF, &hascrorlf) +
4016              new_info(re, NULL, PCRE_INFO_MAXLOOKBEHIND, &maxlookbehind)
4017            != 0)            != 0)
4018          goto SKIP_DATA;          goto SKIP_DATA;
4019    
# Line 3093  while (!done) Line 4030  while (!done)
4030          fprintf(outfile, "Named capturing subpatterns:\n");          fprintf(outfile, "Named capturing subpatterns:\n");
4031          while (namecount-- > 0)          while (namecount-- > 0)
4032            {            {
4033  #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  
4034            int length = (int)STRLEN(nametable + imm2_size);            int length = (int)STRLEN(nametable + imm2_size);
4035            fprintf(outfile, "  ");            fprintf(outfile, "  ");
4036            PCHARSV(nametable, imm2_size, length, outfile);            PCHARSV(nametable, imm2_size, length, outfile);
4037            while (length++ < nameentrysize - imm2_size) putc(' ', outfile);            while (length++ < nameentrysize - imm2_size) putc(' ', outfile);
4038  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE32
4039            fprintf(outfile, "%3d\n", use_pcre16?            if (pcre_mode == PCRE32_MODE)
4040               (int)(((PCRE_SPTR16)nametable)[0])              fprintf(outfile, "%3d\n", (int)(((PCRE_SPTR32)nametable)[0]));
4041              :((int)nametable[0] << 8) | (int)nametable[1]);  #endif
4042            nametable += nameentrysize * (use_pcre16 ? 2 : 1);  #ifdef SUPPORT_PCRE16
4043  #else            if (pcre_mode == PCRE16_MODE)
4044            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;  
4045  #endif  #endif
4046    #ifdef SUPPORT_PCRE8
4047              if (pcre_mode == PCRE8_MODE)
4048                fprintf(outfile, "%3d\n", ((int)nametable[0] << 8) | (int)nametable[1]);
4049  #endif  #endif
4050              nametable += nameentrysize * CHAR_SIZE;
4051            }            }
4052          }          }
4053    
4054        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");
4055        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");
4056    
4057        all_options = ((REAL_PCRE *)re)->options;        all_options = REAL_PCRE_OPTIONS(re);
4058        if (do_flip) all_options = swap_uint32(all_options);        if (do_flip) all_options = swap_uint32(all_options);
4059    
4060        if (get_options == 0) fprintf(outfile, "No options\n");        if (get_options == 0) fprintf(outfile, "No options\n");
# Line 3172  while (!done) Line 4105  while (!done)
4105          break;          break;
4106          }          }
4107    
4108        if (first_char == -1)        if (first_char_set == 2)
4109          {          {
4110          fprintf(outfile, "First char at start or follows newline\n");          fprintf(outfile, "First char at start or follows newline\n");
4111          }          }
4112        else if (first_char < 0)        else if (first_char_set == 1)
         {  
         fprintf(outfile, "No first char\n");  
         }  
       else  
4113          {          {
4114          const char *caseless =          const char *caseless =
4115            ((((REAL_PCRE *)re)->flags & PCRE_FCH_CASELESS) == 0)?            ((REAL_PCRE_FLAGS(re) & PCRE_FCH_CASELESS) == 0)?
4116            "" : " (caseless)";            "" : " (caseless)";
4117    
4118          if (PRINTOK(first_char))          if (PRINTOK(first_char))
# Line 3195  while (!done) Line 4124  while (!done)
4124            fprintf(outfile, "%s\n", caseless);            fprintf(outfile, "%s\n", caseless);
4125            }            }
4126          }          }
4127          else
4128            {
4129            fprintf(outfile, "No first char\n");
4130            }
4131    
4132        if (need_char < 0)        if (need_char_set == 0)
4133          {          {
4134          fprintf(outfile, "No need char\n");          fprintf(outfile, "No need char\n");
4135          }          }
4136        else        else
4137          {          {
4138          const char *caseless =          const char *caseless =
4139            ((((REAL_PCRE *)re)->flags & PCRE_RCH_CASELESS) == 0)?            ((REAL_PCRE_FLAGS(re) & PCRE_RCH_CASELESS) == 0)?
4140            "" : " (caseless)";            "" : " (caseless)";
4141    
4142          if (PRINTOK(need_char))          if (PRINTOK(need_char))
# Line 3216  while (!done) Line 4149  while (!done)
4149            }            }
4150          }          }
4151    
4152          if (maxlookbehind > 0)
4153            fprintf(outfile, "Max lookbehind = %d\n", maxlookbehind);
4154    
4155        /* 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
4156        value, but it varies, depending on the computer architecture, and        value, but it varies, depending on the computer architecture, and
4157        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 4209  while (!done)
4209    
4210          /* 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. */
4211    
4212          if ((study_options & PCRE_STUDY_JIT_COMPILE) != 0)          if ((study_options & PCRE_STUDY_ALLJIT) != 0 &&
4213                (force_study_options & PCRE_STUDY_ALLJIT) == 0)
4214            {            {
4215            int jit;            int jit;
4216            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 4297  while (!done)
4297    
4298    for (;;)    for (;;)
4299      {      {
4300      pcre_uint8 *q;  #ifdef SUPPORT_PCRE8
4301        pcre_uint8 *q8;
4302    #endif
4303    #ifdef SUPPORT_PCRE16
4304        pcre_uint16 *q16;
4305    #endif
4306    #ifdef SUPPORT_PCRE32
4307        pcre_uint32 *q32;
4308    #endif
4309      pcre_uint8 *bptr;      pcre_uint8 *bptr;
4310      int *use_offsets = offsets;      int *use_offsets = offsets;
4311      int use_size_offsets = size_offsets;      int use_size_offsets = size_offsets;
4312      int callout_data = 0;      int callout_data = 0;
4313      int callout_data_set = 0;      int callout_data_set = 0;
4314      int count, c;      int count;
4315        pcre_uint32 c;
4316      int copystrings = 0;      int copystrings = 0;
4317      int find_match_limit = default_find_match_limit;      int find_match_limit = default_find_match_limit;
4318      int getstrings = 0;      int getstrings = 0;
# Line 3380  while (!done) Line 4326  while (!done)
4326      *copynames = 0;      *copynames = 0;
4327      *getnames = 0;      *getnames = 0;
4328    
4329    #ifdef SUPPORT_PCRE32
4330        cn32ptr = copynames;
4331        gn32ptr = getnames;
4332    #endif
4333  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
4334      cn16ptr = copynames;      cn16ptr = copynames16;
4335      gn16ptr = getnames;      gn16ptr = getnames16;
4336  #endif  #endif
4337  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
4338      cn8ptr = copynames8;      cn8ptr = copynames8;
# Line 3427  while (!done) Line 4377  while (!done)
4377      p = buffer;      p = buffer;
4378      while (isspace(*p)) p++;      while (isspace(*p)) p++;
4379    
4380      bptr = q = dbuffer;  #ifndef NOUTF
4381        /* Check that the data is well-formed UTF-8 if we're in UTF mode. To create
4382           invalid input to pcre_exec, you must use \x?? or \x{} sequences. */
4383        if (use_utf)
4384          {
4385          pcre_uint8 *q;
4386          pcre_uint32 cc;
4387          int n = 1;
4388    
4389          for (q = p; n > 0 && *q; q += n) n = utf82ord(q, &cc);
4390          if (n <= 0)
4391            {
4392            fprintf(outfile, "**Failed: invalid UTF-8 string cannot be used as input in UTF mode\n");
4393            goto NEXT_DATA;
4394            }
4395          }
4396    #endif
4397    
4398        /* Allocate a buffer to hold the data line. len+1 is an upper bound on
4399           the number of pcre_uchar units that will be needed. */
4400        if (dbuffer == NULL || (size_t)len >= dbuffer_size)
4401          {
4402          dbuffer_size *= 2;
4403          dbuffer = (pcre_uint8 *)realloc(dbuffer, dbuffer_size * CHAR_SIZE);
4404          if (dbuffer == NULL)
4405            {
4406            fprintf(stderr, "pcretest: malloc(%d) failed\n", dbuffer_size);
4407            exit(1);
4408            }
4409          }
4410    
4411    #ifdef SUPPORT_PCRE8
4412        q8 = (pcre_uint8 *) dbuffer;
4413    #endif
4414    #ifdef SUPPORT_PCRE16
4415        q16 = (pcre_uint16 *) dbuffer;
4416    #endif
4417    #ifdef SUPPORT_PCRE32
4418        q32 = (pcre_uint32 *) dbuffer;
4419    #endif
4420    
4421      while ((c = *p++) != 0)      while ((c = *p++) != 0)
4422        {        {
4423        int i = 0;        int i = 0;
# Line 3436  while (!done) Line 4426  while (!done)
4426        /* 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.
4427        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,
4428        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
4429        16-bit mode. */        16-bit or 32-bit mode. */
4430    
4431        if (c != '\\')        if (c != '\\')
4432          {          {
4433          if (use_utf)  #ifndef NOUTF
4434            {          if (use_utf && HASUTF8EXTRALEN(c)) { GETUTF8INC(c, p); }
4435            *q++ = c;  #endif
           continue;  
           }  
4436          }          }
4437    
4438        /* Handle backslash escapes */        /* Handle backslash escapes */
# Line 3497  while (!done) Line 4485  while (!done)
4485          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
4486          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.
4487          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
4488          UTF-8 when running in 16-bit mode. */          UTF-8 when running in 16/32-bit mode. */
4489    
4490          c = 0;          c = 0;
4491          while (i++ < 2 && isxdigit(*p))          while (i++ < 2 && isxdigit(*p))
# Line 3505  while (!done) Line 4493  while (!done)
4493            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);
4494            p++;            p++;
4495            }            }
4496          if (use_utf)  #if !defined NOUTF && defined SUPPORT_PCRE8
4497            if (use_utf && (pcre_mode == PCRE8_MODE))
4498            {            {
4499            *q++ = c;            *q8++ = c;
4500            continue;            continue;
4501            }            }
4502    #endif
4503          break;          break;
4504    
4505          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 4532  while (!done)
4532            }            }
4533          else if (isalnum(*p))          else if (isalnum(*p))
4534            {            {
4535            READ_CAPTURE_NAME(p, &cn8ptr, &cn16ptr, re);            READ_CAPTURE_NAME(p, &cn8ptr, &cn16ptr, &cn32ptr, re);
4536            }            }
4537          else if (*p == '+')          else if (*p == '+')
4538            {            {
# Line 3605  while (!done) Line 4595  while (!done)
4595            }            }
4596          else if (isalnum(*p))          else if (isalnum(*p))
4597            {            {
4598            READ_CAPTURE_NAME(p, &gn8ptr, &gn16ptr, re);            READ_CAPTURE_NAME(p, &gn8ptr, &gn16ptr, &gn32ptr, re);
4599            }            }
4600          continue;          continue;
4601    
# Line 3653  while (!done) Line 4643  while (!done)
4643            }            }
4644          use_size_offsets = n;          use_size_offsets = n;
4645          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 */
4646              else use_offsets = offsets + size_offsets_max - n;  /* To catch overruns */
4647          continue;          continue;
4648    
4649          case 'P':          case 'P':
# Line 3714  while (!done) Line 4705  while (!done)
4705          continue;          continue;
4706          }          }
4707    
4708        /* 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.
4709        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
4710        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
4711        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. */
4712        mode must have come from \x{...} or octal constructs because values from  
4713        \x.. get this far only in non-UTF mode. */  #ifdef SUPPORT_PCRE8
4714          if (pcre_mode == PCRE8_MODE)
4715  #if !defined NOUTF || defined SUPPORT_PCRE16          {
4716        if (use_pcre16 || use_utf)  #ifndef NOUTF
4717          {          if (use_utf)
4718          pcre_uint8 buff8[8];            {
4719          int ii, utn;            q8 += ord2utf8(c, q8);
4720          utn = ord2utf8(c, buff8);            }
4721          for (ii = 0; ii < utn; ii++) *q++ = buff8[ii];          else
4722    #endif
4723              {
4724              if (c > 0xffu)
4725                {
4726                fprintf(outfile, "** Character \\x{%x} is greater than 255 "
4727                  "and UTF-8 mode is not enabled.\n", c);
4728                fprintf(outfile, "** Truncation will probably give the wrong "
4729                  "result.\n");
4730                }
4731              *q8++ = c;
4732              }
4733          }          }
       else  
4734  #endif  #endif
4735    #ifdef SUPPORT_PCRE16
4736          if (pcre_mode == PCRE16_MODE)
4737          {          {
4738          if (c > 255)  #ifndef NOUTF
4739            if (use_utf)
4740              {
4741              if (c > 0x10ffffu)
4742                {
4743                fprintf(outfile, "**Failed: character value greater than 0x10ffff "
4744                  "cannot be converted to UTF-16\n");
4745                goto NEXT_DATA;
4746                }
4747              else if (c >= 0x10000u)
4748                {
4749                c-= 0x10000u;
4750                *q16++ = 0xD800 | (c >> 10);
4751                *q16++ = 0xDC00 | (c & 0x3ff);
4752                }
4753              else
4754                *q16++ = c;
4755              }
4756            else
4757    #endif
4758            {            {
4759            fprintf(outfile, "** Character \\x{%x} is greater than 255 "            if (c > 0xffffu)
4760              "and UTF-8 mode is not enabled.\n", c);              {
4761            fprintf(outfile, "** Truncation will probably give the wrong "              fprintf(outfile, "** Character value is greater than 0xffff "
4762              "result.\n");                "and UTF-16 mode is not enabled.\n");
4763                fprintf(outfile, "** Truncation will probably give the wrong "
4764                  "result.\n");
4765                }
4766    
4767              *q16++ = c;
4768            }            }
         *q++ = c;  
4769          }          }
4770    #endif
4771    #ifdef SUPPORT_PCRE32
4772          if (pcre_mode == PCRE32_MODE)
4773            {
4774            *q32++ = c;
4775            }
4776    #endif
4777    
4778        }        }
4779    
4780      /* Reached end of subject string */      /* Reached end of subject string */
4781    
4782      *q = 0;  #ifdef SUPPORT_PCRE8
4783      len = (int)(q - dbuffer);      if (pcre_mode == PCRE8_MODE)
4784        {
4785          *q8 = 0;
4786          len = (int)(q8 - (pcre_uint8 *)dbuffer);
4787        }
4788    #endif
4789    #ifdef SUPPORT_PCRE16
4790        if (pcre_mode == PCRE16_MODE)
4791        {
4792          *q16 = 0;
4793          len = (int)(q16 - (pcre_uint16 *)dbuffer);
4794        }
4795    #endif
4796    #ifdef SUPPORT_PCRE32
4797        if (pcre_mode == PCRE32_MODE)
4798        {
4799          *q32 = 0;
4800          len = (int)(q32 - (pcre_uint32 *)dbuffer);
4801        }
4802    #endif
4803    
4804    #if defined SUPPORT_UTF && defined SUPPORT_PCRE32
4805        /* If we're requsted to test UTF-32 masking of high bits, change the data
4806        string to have high bits set, unless the string is invalid UTF-32.
4807        Since the JIT doesn't support this yet, only do it when not JITing. */
4808        if (use_utf && mask_utf32 && (study_options & PCRE_STUDY_ALLJIT) == 0 &&
4809            valid_utf32((pcre_uint32 *)dbuffer, len))
4810          {
4811          for (q32 = (pcre_uint32 *)dbuffer; *q32; q32++)
4812            *q32 |= ~(pcre_uint32)UTF32_MASK;
4813    
4814          /* Need to pass NO_UTF32_CHECK so the high bits are allowed */
4815          options |= PCRE_NO_UTF32_CHECK;
4816          }
4817    #endif
4818    
4819      /* Move the data to the end of the buffer so that a read over the end of      /* Move the data to the end of the buffer so that a read over the end of
4820      the buffer will be seen by valgrind, even if it doesn't cause a crash. If      the buffer will be seen by valgrind, even if it doesn't cause a crash. If
4821      we are using the POSIX interface, we must include the terminating zero. */      we are using the POSIX interface, we must include the terminating zero. */
4822    
4823        bptr = dbuffer;
4824    
4825  #if !defined NOPOSIX  #if !defined NOPOSIX
4826      if (posix || do_posix)      if (posix || do_posix)
4827        {        {
4828        memmove(bptr + buffer_size - len - 1, bptr, len + 1);        memmove(bptr + dbuffer_size - len - 1, bptr, len + 1);
4829        bptr += buffer_size - len - 1;        bptr += dbuffer_size - len - 1;
4830        }        }
4831      else      else
4832  #endif  #endif
4833        {        {
4834        memmove(bptr + buffer_size - len, bptr, len);        bptr = memmove(bptr + (dbuffer_size - len) * CHAR_SIZE, bptr, len * CHAR_SIZE);
       bptr += buffer_size - len;  
4835        }        }
4836    
4837      if ((all_use_dfa || use_dfa) && find_match_limit)      if ((all_use_dfa || use_dfa) && find_match_limit)
# Line 3793  while (!done) Line 4862  while (!done)
4862          (void)regerror(rc, &preg, (char *)buffer, buffer_size);          (void)regerror(rc, &preg, (char *)buffer, buffer_size);
4863          fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);          fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);
4864          }          }
4865        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)  
4866          {          {
4867          fprintf(outfile, "Matched with REG_NOSUB\n");          fprintf(outfile, "Matched with REG_NOSUB\n");
4868          }          }
# Line 3827  while (!done) Line 4895  while (!done)
4895    
4896      /* Handle matching via the native interface - repeats for /g and /G */      /* Handle matching via the native interface - repeats for /g and /G */
4897    
4898  #ifdef SUPPORT_PCRE16      /* Ensure that there is a JIT callback if we want to verify that JIT was
4899      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;  
4900    
4901          default:      if (verify_jit && jit_stack == NULL && extra != NULL)
4902          break;         { PCRE_ASSIGN_JIT_STACK(extra, jit_callback, jit_stack); }
         }  
       bptr = (pcre_uint8 *)buffer16;  
       }  
 #endif  
4903    
4904      for (;; gmatched++)    /* Loop for /g or /G */      for (;; gmatched++)    /* Loop for /g or /G */
4905        {        {
4906        markptr = NULL;        markptr = NULL;
4907          jit_was_used = FALSE;
4908    
4909        if (timeitm > 0)        if (timeitm > 0)
4910          {          {
# Line 3868  while (!done) Line 4915  while (!done)
4915  #if !defined NODFA  #if !defined NODFA
4916          if (all_use_dfa || use_dfa)          if (all_use_dfa || use_dfa)
4917            {            {
4918            int workspace[1000];            if ((options & PCRE_DFA_RESTART) != 0)
4919                {
4920                fprintf(outfile, "Timing DFA restarts is not supported\n");
4921                break;
4922                }
4923              if (dfa_workspace == NULL)
4924                dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
4925            for (i = 0; i < timeitm; i++)            for (i = 0; i < timeitm; i++)
4926              {              {
4927              PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,              PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
4928                (options | g_notempty), use_offsets, use_size_offsets, workspace,                (options | g_notempty), use_offsets, use_size_offsets,
4929                (sizeof(workspace)/sizeof(int)));                dfa_workspace, DFA_WS_DIMENSION);
4930              }              }
4931            }            }
4932          else          else
# Line 3899  while (!done) Line 4952  while (!done)
4952    
4953        if (find_match_limit)        if (find_match_limit)
4954          {          {
4955          if (extra == NULL)          if (extra != NULL) { PCRE_FREE_STUDY(extra); }
4956            {          extra = (pcre_extra *)malloc(sizeof(pcre_extra));
4957            extra = (pcre_extra *)malloc(sizeof(pcre_extra));          extra->flags = 0;
           extra->flags = 0;  
           }  
         else extra->flags &= ~PCRE_EXTRA_EXECUTABLE_JIT;  
4958    
4959          (void)check_match_limit(re, extra, bptr, len, start_offset,          (void)check_match_limit(re, extra, bptr, len, start_offset,
4960            options|g_notempty, use_offsets, use_size_offsets,            options|g_notempty, use_offsets, use_size_offsets,
# Line 3939  while (!done) Line 4989  while (!done)
4989  #if !defined NODFA  #if !defined NODFA
4990        else if (all_use_dfa || use_dfa)        else if (all_use_dfa || use_dfa)
4991          {          {
4992          int workspace[1000];          if (dfa_workspace == NULL)
4993              dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
4994            if (dfa_matched++ == 0)
4995              dfa_workspace[0] = -1;  /* To catch bad restart */
4996          PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,          PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
4997            (options | g_notempty), use_offsets, use_size_offsets, workspace,            (options | g_notempty), use_offsets, use_size_offsets, dfa_workspace,
4998            (sizeof(workspace)/sizeof(int)));            DFA_WS_DIMENSION);
4999          if (count == 0)          if (count == 0)
5000            {            {
5001            fprintf(outfile, "Matched, but too many subsidiary matches\n");            fprintf(outfile, "Matched, but too many subsidiary matches\n");
# Line 4019  while (!done) Line 5072  while (!done)
5072              fprintf(outfile, "%2d: ", i/2);              fprintf(outfile, "%2d: ", i/2);
5073              PCHARSV(bptr, use_offsets[i],              PCHARSV(bptr, use_offsets[i],
5074                use_offsets[i+1] - use_offsets[i], outfile);                use_offsets[i+1] - use_offsets[i], outfile);
5075                if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
5076              fprintf(outfile, "\n");              fprintf(outfile, "\n");
5077              if (do_showcaprest || (i == 0 && do_showrest))              if (do_showcaprest || (i == 0 && do_showrest))
5078                {                {
# Line 4062  while (!done) Line 5116  while (!done)
5116            int rc;            int rc;
5117            char copybuffer[256];            char copybuffer[256];
5118    
5119            if (use_pcre16)  #ifdef SUPPORT_PCRE32
5120              if (pcre_mode == PCRE32_MODE)
5121                {
5122                if (*(pcre_uint32 *)cnptr == 0) break;
5123                }
5124    #endif
5125    #ifdef SUPPORT_PCRE16
5126              if (pcre_mode == PCRE16_MODE)
5127              {              {
5128              if (*(pcre_uint16 *)cnptr == 0) break;              if (*(pcre_uint16 *)cnptr == 0) break;
5129              }              }
5130            else  #endif
5131    #ifdef SUPPORT_PCRE8
5132              if (pcre_mode == PCRE8_MODE)
5133              {              {
5134              if (*(pcre_uint8 *)cnptr == 0) break;              if (*(pcre_uint8 *)cnptr == 0) break;
5135              }              }
5136    #endif
5137    
5138            PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,            PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,
5139              cnptr, copybuffer, sizeof(copybuffer));              cnptr, copybuffer, sizeof(copybuffer));
# Line 4117  while (!done) Line 5181  while (!done)
5181            int rc;            int rc;
5182            const char *substring;            const char *substring;
5183    
5184            if (use_pcre16)  #ifdef SUPPORT_PCRE32
5185              if (pcre_mode == PCRE32_MODE)
5186                {
5187                if (*(pcre_uint32 *)gnptr == 0) break;
5188                }
5189    #endif
5190    #ifdef SUPPORT_PCRE16
5191              if (pcre_mode == PCRE16_MODE)
5192              {              {
5193              if (*(pcre_uint16 *)gnptr == 0) break;              if (*(pcre_uint16 *)gnptr == 0) break;
5194              }              }
5195            else  #endif
5196    #ifdef SUPPORT_PCRE8
5197              if (pcre_mode == PCRE8_MODE)
5198              {              {
5199              if (*(pcre_uint8 *)gnptr == 0) break;              if (*(pcre_uint8 *)gnptr == 0) break;
5200              }              }
5201    #endif
5202    
5203            PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,            PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,
5204              gnptr, &substring);              gnptr, &substring);
# Line 4185  while (!done) Line 5259  while (!done)
5259            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],
5260              outfile);              outfile);
5261            }            }
5262            if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
5263          fprintf(outfile, "\n");          fprintf(outfile, "\n");
5264          break;  /* Out of the /g loop */          break;  /* Out of the /g loop */
5265          }          }
# Line 4210  while (!done) Line 5285  while (!done)
5285          if (g_notempty != 0)          if (g_notempty != 0)
5286            {            {
5287            int onechar = 1;            int onechar = 1;
5288            unsigned int obits = ((REAL_PCRE *)re)->options;            unsigned int obits = REAL_PCRE_OPTIONS(re);
5289            use_offsets[0] = start_offset;            use_offsets[0] = start_offset;
5290            if ((obits & PCRE_NEWLINE_BITS) == 0)            if ((obits & PCRE_NEWLINE_BITS) == 0)
5291              {              {
# Line 4228  while (!done) Line 5303  while (!done)
5303                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||
5304                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)
5305                &&                &&
5306                start_offset < len - 1 &&                start_offset < len - 1 && (
5307  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE8
5308                (use_pcre16?                (pcre_mode == PCRE8_MODE &&
5309                     ((PCRE_SPTR16)bptr)[start_offset] == '\r'                 bptr[start_offset] == '\r' &&
5310                  && ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n'                 bptr[start_offset + 1] == '\n') ||
5311                :  #endif
5312                     bptr[start_offset] == '\r'  #ifdef SUPPORT_PCRE16
5313                  && bptr[start_offset + 1] == '\n')                (pcre_mode == PCRE16_MODE &&
5314  #elif defined SUPPORT_PCRE16                 ((PCRE_SPTR16)bptr)[start_offset] == '\r' &&
5315                   ((PCRE_SPTR16)bptr)[start_offset] == '\r'                 ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n') ||
5316                && ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n'  #endif
5317  #else  #ifdef SUPPORT_PCRE32
5318                   bptr[start_offset] == '\r'                (pcre_mode == PCRE32_MODE &&
5319                && bptr[start_offset + 1] == '\n'                 ((PCRE_SPTR32)bptr)[start_offset] == '\r' &&
5320                   ((PCRE_SPTR32)bptr)[start_offset + 1] == '\n') ||
5321  #endif  #endif
5322                )                0))
5323              onechar++;              onechar++;
5324            else if (use_utf)            else if (use_utf)
5325              {              {
# Line 4264  while (!done) Line 5340  while (!done)
5340                {                {
5341                if (markptr == NULL)                if (markptr == NULL)
5342                  {                  {
5343                  fprintf(outfile, "No match\n");                  fprintf(outfile, "No match");
5344                  }                  }
5345                else                else
5346                  {                  {
5347                  fprintf(outfile, "No match, mark = ");                  fprintf(outfile, "No match, mark = ");
5348                  PCHARSV(markptr, 0, -1, outfile);                  PCHARSV(markptr, 0, -1, outfile);
                 putc('\n', outfile);  
5349                  }                  }
5350                  if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
5351                  putc('\n', outfile);
5352                }                }
5353              break;              break;
5354    
5355              case PCRE_ERROR_BADUTF8:              case PCRE_ERROR_BADUTF8:
5356              case PCRE_ERROR_SHORTUTF8:              case PCRE_ERROR_SHORTUTF8:
5357              fprintf(outfile, "Error %d (%s UTF-%s string)", count,              fprintf(outfile, "Error %d (%s UTF-%d string)", count,
5358                (count == PCRE_ERROR_BADUTF8)? "bad" : "short",                (count == PCRE_ERROR_BADUTF8)? "bad" : "short",
5359                use_pcre16? "16" : "8");                8 * CHAR_SIZE);
5360              if (use_size_offsets >= 2)              if (use_size_offsets >= 2)
5361                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],
5362                  use_offsets[1]);                  use_offsets[1]);
# Line 4287  while (!done) Line 5364  while (!done)
5364              break;              break;
5365    
5366              case PCRE_ERROR_BADUTF8_OFFSET:              case PCRE_ERROR_BADUTF8_OFFSET:
5367              fprintf(outfile, "Error %d (bad UTF-%s offset)\n", count,              fprintf(outfile, "Error %d (bad UTF-%d offset)\n", count,
5368                use_pcre16? "16" : "8");                8 * CHAR_SIZE);
5369              break;              break;
5370    
5371              default:              default:
5372              if (count < 0 &&              if (count < 0 &&
5373                  (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))                  (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))
5374                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);
5375              else              else
# Line 4378  free(offsets); Line 5455  free(offsets);
5455  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
5456  if (buffer16 != NULL) free(buffer16);  if (buffer16 != NULL) free(buffer16);
5457  #endif  #endif
5458    #ifdef SUPPORT_PCRE32
5459    if (buffer32 != NULL) free(buffer32);
5460    #endif
5461    
5462    #if !defined NODFA
5463    if (dfa_workspace != NULL)
5464      free(dfa_workspace);
5465    #endif
5466    
5467  return yield;  return yield;
5468  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.5