/[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 1122 by ph10, Wed Oct 17 17:31:19 2012 UTC
# Line 46  pcre_internal.h that depend on COMPILE_P Line 46  pcre_internal.h that depend on COMPILE_P
46  however, make use of SUPPORT_PCRE8 and SUPPORT_PCRE16 to ensure that it calls  however, make use of SUPPORT_PCRE8 and SUPPORT_PCRE16 to ensure that it calls
47  only supported library functions. */  only supported library functions. */
48    
   
49  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
50  #include "config.h"  #include "config.h"
51  #endif  #endif
# 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 118  appropriately for an application, not fo Line 134  appropriately for an application, not fo
134    
135  #include "pcre.h"  #include "pcre.h"
136    
137  #if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8  #if defined SUPPORT_PCRE32 && !defined SUPPORT_PCRE8 && !defined SUPPORT_PCRE16
138    /* Configure internal macros to 32 bit mode. */
139    #define COMPILE_PCRE32
140    #endif
141    #if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8 && !defined SUPPORT_PCRE32
142  /* Configure internal macros to 16 bit mode. */  /* Configure internal macros to 16 bit mode. */
143  #define COMPILE_PCRE16  #define COMPILE_PCRE16
144  #endif  #endif
145    #if defined SUPPORT_PCRE8 && !defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE32
146    /* Configure internal macros to 16 bit mode. */
147    #define COMPILE_PCRE8
148    #endif
149    
150  #include "pcre_internal.h"  #include "pcre_internal.h"
151    
152  /* The pcre_printint() function, which prints the internal form of a compiled  /* The pcre_printint() function, which prints the internal form of a compiled
153  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
154  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
155  when that is compiled in debug mode. */  when that is compiled in debug mode. */
156    
157  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
# Line 136  void pcre_printint(pcre *external_re, FI Line 160  void pcre_printint(pcre *external_re, FI
160  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
161  void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths);  void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths);
162  #endif  #endif
163    #ifdef SUPPORT_PCRE32
164    void pcre32_printint(pcre *external_re, FILE *f, BOOL print_lengths);
165    #endif
166    
167  /* 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
168  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
169  external symbols to prevent clashes. */  external symbols to prevent clashes. */
170    
171  #define PCRE_INCLUDED  #define PCRE_INCLUDED
172    
173  #include "pcre_tables.c"  #include "pcre_tables.c"
174    #include "pcre_ucd.c"
175    
176  /* The definition of the macro PRINTABLE, which determines whether to print an  /* The definition of the macro PRINTABLE, which determines whether to print an
177  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 187  that differ in their output from isprint
187    
188  #define PRINTOK(c) (locale_set? isprint(c) : PRINTABLE(c))  #define PRINTOK(c) (locale_set? isprint(c) : PRINTABLE(c))
189    
190  /* Posix support is disabled in 16 bit only mode. */  /* Posix support is disabled in 16 or 32 bit only mode. */
191  #if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8 && !defined NOPOSIX  #if !defined SUPPORT_PCRE8 && !defined NOPOSIX
192  #define NOPOSIX  #define NOPOSIX
193  #endif  #endif
194    
# Line 183  automatically cut out the UTF support if Line 211  automatically cut out the UTF support if
211  #endif  #endif
212  #endif  #endif
213    
214  /* 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
215  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
216  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
217  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 233  argument, the casting might be incorrect
233  #define PCHARSV8(p, offset, len, f) \  #define PCHARSV8(p, offset, len, f) \
234    (void)pchars((pcre_uint8 *)(p) + offset, len, f)    (void)pchars((pcre_uint8 *)(p) + offset, len, f)
235    
236  #define READ_CAPTURE_NAME8(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME8(p, cn8, cn16, cn32, re) \
237    p = read_capture_name8(p, cn8, re)    p = read_capture_name8(p, cn8, re)
238    
239  #define STRLEN8(p) ((int)strlen((char *)p))  #define STRLEN8(p) ((int)strlen((char *)p))
# Line 287  argument, the casting might be incorrect Line 315  argument, the casting might be incorrect
315  #define PCHARSV16(p, offset, len, f) \  #define PCHARSV16(p, offset, len, f) \
316    (void)pchars16((PCRE_SPTR16)(p) + offset, len, f)    (void)pchars16((PCRE_SPTR16)(p) + offset, len, f)
317    
318  #define READ_CAPTURE_NAME16(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME16(p, cn8, cn16, cn32, re) \
319    p = read_capture_name16(p, cn16, re)    p = read_capture_name16(p, cn16, re)
320    
321  #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 394  argument, the casting might be incorrect
394    
395  #endif /* SUPPORT_PCRE16 */  #endif /* SUPPORT_PCRE16 */
396    
397    /* -----------------------------------------------------------*/
398    
399    #ifdef SUPPORT_PCRE32
400    
401    #define PCHARS32(lv, p, offset, len, f) \
402      lv = pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
403    
404    #define PCHARSV32(p, offset, len, f)                \
405      (void)pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
406    
407    #define READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re) \
408      p = read_capture_name32(p, cn32, re)
409    
410    #define STRLEN32(p) ((int)strlen32((PCRE_SPTR32)p))
411    
412    #define SET_PCRE_CALLOUT32(callout) \
413      pcre32_callout = (int (*)(pcre32_callout_block *))callout
414    
415    #define PCRE_ASSIGN_JIT_STACK32(extra, callback, userdata) \
416      pcre32_assign_jit_stack((pcre32_extra *)extra, \
417        (pcre32_jit_callback)callback, userdata)
418    
419    #define PCRE_COMPILE32(re, pat, options, error, erroffset, tables) \
420      re = (pcre *)pcre32_compile((PCRE_SPTR32)pat, options, error, erroffset, \
421        tables)
422    
423    #define PCRE_COPY_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
424        namesptr, cbuffer, size) \
425      rc = pcre32_copy_named_substring((pcre32 *)re, (PCRE_SPTR32)bptr, offsets, \
426        count, (PCRE_SPTR32)namesptr, (PCRE_UCHAR32 *)cbuffer, size/2)
427    
428  /* ----- Both modes are supported; a runtime test is needed, except for  #define PCRE_COPY_SUBSTRING32(rc, bptr, offsets, count, i, cbuffer, size) \
429      rc = pcre32_copy_substring((PCRE_SPTR32)bptr, offsets, count, i, \
430        (PCRE_UCHAR32 *)cbuffer, size/2)
431    
432    #define PCRE_DFA_EXEC32(count, re, extra, bptr, len, start_offset, options, \
433        offsets, size_offsets, workspace, size_workspace) \
434      count = pcre32_dfa_exec((pcre32 *)re, (pcre32_extra *)extra, \
435        (PCRE_SPTR32)bptr, len, start_offset, options, offsets, size_offsets, \
436        workspace, size_workspace)
437    
438    #define PCRE_EXEC32(count, re, extra, bptr, len, start_offset, options, \
439        offsets, size_offsets) \
440      count = pcre32_exec((pcre32 *)re, (pcre32_extra *)extra, (PCRE_SPTR32)bptr, \
441        len, start_offset, options, offsets, size_offsets)
442    
443    #define PCRE_FREE_STUDY32(extra) \
444      pcre32_free_study((pcre32_extra *)extra)
445    
446    #define PCRE_FREE_SUBSTRING32(substring) \
447      pcre32_free_substring((PCRE_SPTR32)substring)
448    
449    #define PCRE_FREE_SUBSTRING_LIST32(listptr) \
450      pcre32_free_substring_list((PCRE_SPTR32 *)listptr)
451    
452    #define PCRE_GET_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
453        getnamesptr, subsptr) \
454      rc = pcre32_get_named_substring((pcre32 *)re, (PCRE_SPTR32)bptr, offsets, \
455        count, (PCRE_SPTR32)getnamesptr, (PCRE_SPTR32 *)(void*)subsptr)
456    
457    #define PCRE_GET_STRINGNUMBER32(n, rc, ptr) \
458      n = pcre32_get_stringnumber(re, (PCRE_SPTR32)ptr)
459    
460    #define PCRE_GET_SUBSTRING32(rc, bptr, offsets, count, i, subsptr) \
461      rc = pcre32_get_substring((PCRE_SPTR32)bptr, offsets, count, i, \
462        (PCRE_SPTR32 *)(void*)subsptr)
463    
464    #define PCRE_GET_SUBSTRING_LIST32(rc, bptr, offsets, count, listptr) \
465      rc = pcre32_get_substring_list((PCRE_SPTR32)bptr, offsets, count, \
466        (PCRE_SPTR32 **)(void*)listptr)
467    
468    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER32(rc, re, extra, tables) \
469      rc = pcre32_pattern_to_host_byte_order((pcre32 *)re, (pcre32_extra *)extra, \
470        tables)
471    
472    #define PCRE_PRINTINT32(re, outfile, debug_lengths) \
473      pcre32_printint(re, outfile, debug_lengths)
474    
475    #define PCRE_STUDY32(extra, re, options, error) \
476      extra = (pcre_extra *)pcre32_study((pcre32 *)re, options, error)
477    
478    #define PCRE_JIT_STACK_ALLOC32(startsize, maxsize) \
479      (pcre_jit_stack *)pcre32_jit_stack_alloc(startsize, maxsize)
480    
481    #define PCRE_JIT_STACK_FREE32(stack) \
482      pcre32_jit_stack_free((pcre32_jit_stack *)stack)
483    
484    #endif /* SUPPORT_PCRE32 */
485    
486    
487    /* ----- More than one mode is supported; a runtime test is needed, except for
488  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
489  version is called. ----- */  version is called. ----- */
490    
491  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  enum {
492      PCRE8_MODE,
493      PCRE16_MODE,
494      PCRE32_MODE
495    };
496    
497    #if (defined (SUPPORT_PCRE8) + defined (SUPPORT_PCRE16) + \
498         defined (SUPPORT_PCRE32)) >= 2
499    
500    #define CHAR_SIZE (1 << pcre_mode)
501    
502    /* There doesn't seem to be an easy way of writing these macros that can cope
503    with the 3 pairs of bit sizes plus all three bit sizes. So just handle all the
504    cases separately. */
505    
506    /* ----- All three modes supported ----- */
507    
508    #if defined(SUPPORT_PCRE8) && defined(SUPPORT_PCRE16) && defined(SUPPORT_PCRE32)
509    
510    #define PCHARS(lv, p, offset, len, f) \
511      if (pcre_mode == PCRE32_MODE) \
512        PCHARS32(lv, p, offset, len, f); \
513      else if (pcre_mode == PCRE16_MODE) \
514        PCHARS16(lv, p, offset, len, f); \
515      else \
516        PCHARS8(lv, p, offset, len, f)
517    
518    #define PCHARSV(p, offset, len, f) \
519      if (pcre_mode == PCRE32_MODE) \
520        PCHARSV32(p, offset, len, f); \
521      else if (pcre_mode == PCRE16_MODE) \
522        PCHARSV16(p, offset, len, f); \
523      else \
524        PCHARSV8(p, offset, len, f)
525    
526    #define READ_CAPTURE_NAME(p, cn8, cn16, cn32, re) \
527      if (pcre_mode == PCRE32_MODE) \
528        READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re); \
529      else if (pcre_mode == PCRE16_MODE) \
530        READ_CAPTURE_NAME16(p, cn8, cn16, cn32, re); \
531      else \
532        READ_CAPTURE_NAME8(p, cn8, cn16, cn32, re)
533    
534    #define SET_PCRE_CALLOUT(callout) \
535      if (pcre_mode == PCRE32_MODE) \
536        SET_PCRE_CALLOUT32(callout); \
537      else if (pcre_mode == PCRE16_MODE) \
538        SET_PCRE_CALLOUT16(callout); \
539      else \
540        SET_PCRE_CALLOUT8(callout)
541    
542    #define STRLEN(p) (pcre_mode == PCRE32_MODE ? STRLEN32(p) : pcre_mode == PCRE16_MODE ? STRLEN16(p) : STRLEN8(p))
543    
544    #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
545      if (pcre_mode == PCRE32_MODE) \
546        PCRE_ASSIGN_JIT_STACK32(extra, callback, userdata); \
547      else if (pcre_mode == PCRE16_MODE) \
548        PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata); \
549      else \
550        PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata)
551    
552    #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
553      if (pcre_mode == PCRE32_MODE) \
554        PCRE_COMPILE32(re, pat, options, error, erroffset, tables); \
555      else if (pcre_mode == PCRE16_MODE) \
556        PCRE_COMPILE16(re, pat, options, error, erroffset, tables); \
557      else \
558        PCRE_COMPILE8(re, pat, options, error, erroffset, tables)
559    
560    #define PCRE_CONFIG pcre_config
561    
562    #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
563        namesptr, cbuffer, size) \
564      if (pcre_mode == PCRE32_MODE) \
565        PCRE_COPY_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
566          namesptr, cbuffer, size); \
567      else if (pcre_mode == PCRE16_MODE) \
568        PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
569          namesptr, cbuffer, size); \
570      else \
571        PCRE_COPY_NAMED_SUBSTRING8(rc, re, bptr, offsets, count, \
572          namesptr, cbuffer, size)
573    
574    #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \
575      if (pcre_mode == PCRE32_MODE) \
576        PCRE_COPY_SUBSTRING32(rc, bptr, offsets, count, i, cbuffer, size); \
577      else if (pcre_mode == PCRE16_MODE) \
578        PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size); \
579      else \
580        PCRE_COPY_SUBSTRING8(rc, bptr, offsets, count, i, cbuffer, size)
581    
582    #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \
583        offsets, size_offsets, workspace, size_workspace) \
584      if (pcre_mode == PCRE32_MODE) \
585        PCRE_DFA_EXEC32(count, re, extra, bptr, len, start_offset, options, \
586          offsets, size_offsets, workspace, size_workspace); \
587      else if (pcre_mode == PCRE16_MODE) \
588        PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \
589          offsets, size_offsets, workspace, size_workspace); \
590      else \
591        PCRE_DFA_EXEC8(count, re, extra, bptr, len, start_offset, options, \
592          offsets, size_offsets, workspace, size_workspace)
593    
594    #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
595        offsets, size_offsets) \
596      if (pcre_mode == PCRE32_MODE) \
597        PCRE_EXEC32(count, re, extra, bptr, len, start_offset, options, \
598          offsets, size_offsets); \
599      else if (pcre_mode == PCRE16_MODE) \
600        PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \
601          offsets, size_offsets); \
602      else \
603        PCRE_EXEC8(count, re, extra, bptr, len, start_offset, options, \
604          offsets, size_offsets)
605    
606    #define PCRE_FREE_STUDY(extra) \
607      if (pcre_mode == PCRE32_MODE) \
608        PCRE_FREE_STUDY32(extra); \
609      else if (pcre_mode == PCRE16_MODE) \
610        PCRE_FREE_STUDY16(extra); \
611      else \
612        PCRE_FREE_STUDY8(extra)
613    
614    #define PCRE_FREE_SUBSTRING(substring) \
615      if (pcre_mode == PCRE32_MODE) \
616        PCRE_FREE_SUBSTRING32(substring); \
617      else if (pcre_mode == PCRE16_MODE) \
618        PCRE_FREE_SUBSTRING16(substring); \
619      else \
620        PCRE_FREE_SUBSTRING8(substring)
621    
622    #define PCRE_FREE_SUBSTRING_LIST(listptr) \
623      if (pcre_mode == PCRE32_MODE) \
624        PCRE_FREE_SUBSTRING_LIST32(listptr); \
625      else if (pcre_mode == PCRE16_MODE) \
626        PCRE_FREE_SUBSTRING_LIST16(listptr); \
627      else \
628        PCRE_FREE_SUBSTRING_LIST8(listptr)
629    
630    #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
631        getnamesptr, subsptr) \
632      if (pcre_mode == PCRE32_MODE) \
633        PCRE_GET_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
634          getnamesptr, subsptr); \
635      else if (pcre_mode == PCRE16_MODE) \
636        PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
637          getnamesptr, subsptr); \
638      else \
639        PCRE_GET_NAMED_SUBSTRING8(rc, re, bptr, offsets, count, \
640          getnamesptr, subsptr)
641    
642    #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \
643      if (pcre_mode == PCRE32_MODE) \
644        PCRE_GET_STRINGNUMBER32(n, rc, ptr); \
645      else if (pcre_mode == PCRE16_MODE) \
646        PCRE_GET_STRINGNUMBER16(n, rc, ptr); \
647      else \
648        PCRE_GET_STRINGNUMBER8(n, rc, ptr)
649    
650    #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \
651      if (pcre_mode == PCRE32_MODE) \
652        PCRE_GET_SUBSTRING32(rc, bptr, use_offsets, count, i, subsptr); \
653      else if (pcre_mode == PCRE16_MODE) \
654        PCRE_GET_SUBSTRING16(rc, bptr, use_offsets, count, i, subsptr); \
655      else \
656        PCRE_GET_SUBSTRING8(rc, bptr, use_offsets, count, i, subsptr)
657    
658    #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \
659      if (pcre_mode == PCRE32_MODE) \
660        PCRE_GET_SUBSTRING_LIST32(rc, bptr, offsets, count, listptr); \
661      else if (pcre_mode == PCRE16_MODE) \
662        PCRE_GET_SUBSTRING_LIST16(rc, bptr, offsets, count, listptr); \
663      else \
664        PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)
665    
666    #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
667      (pcre_mode == PCRE32_MODE ? \
668         PCRE_JIT_STACK_ALLOC32(startsize, maxsize) \
669        : pcre_mode == PCRE16_MODE ? \
670          PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \
671          : PCRE_JIT_STACK_ALLOC8(startsize, maxsize))
672    
673    #define PCRE_JIT_STACK_FREE(stack) \
674      if (pcre_mode == PCRE32_MODE) \
675        PCRE_JIT_STACK_FREE32(stack); \
676      else if (pcre_mode == PCRE16_MODE) \
677        PCRE_JIT_STACK_FREE16(stack); \
678      else \
679        PCRE_JIT_STACK_FREE8(stack)
680    
681    #define PCRE_MAKETABLES \
682      (pcre_mode == PCRE32_MODE ? pcre32_maketables() : pcre_mode == PCRE16_MODE ? pcre16_maketables() : pcre_maketables())
683    
684    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \
685      if (pcre_mode == PCRE32_MODE) \
686        PCRE_PATTERN_TO_HOST_BYTE_ORDER32(rc, re, extra, tables); \
687      else if (pcre_mode == PCRE16_MODE) \
688        PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables); \
689      else \
690        PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables)
691    
692    #define PCRE_PRINTINT(re, outfile, debug_lengths) \
693      if (pcre_mode == PCRE32_MODE) \
694        PCRE_PRINTINT32(re, outfile, debug_lengths); \
695      else if (pcre_mode == PCRE16_MODE) \
696        PCRE_PRINTINT16(re, outfile, debug_lengths); \
697      else \
698        PCRE_PRINTINT8(re, outfile, debug_lengths)
699    
700    #define PCRE_STUDY(extra, re, options, error) \
701      if (pcre_mode == PCRE32_MODE) \
702        PCRE_STUDY32(extra, re, options, error); \
703      else if (pcre_mode == PCRE16_MODE) \
704        PCRE_STUDY16(extra, re, options, error); \
705      else \
706        PCRE_STUDY8(extra, re, options, error)
707    
708    
709    /* ----- 32-bit and 16-bit but not 8-bit supported ----- */
710    
711    #elif defined(SUPPORT_PCRE32) && defined(SUPPORT_PCRE16)
712    #define PCHARS(lv, p, offset, len, f) \
713      if (pcre_mode == PCRE32_MODE) \
714        PCHARS32(lv, p, offset, len, f); \
715      else \
716        PCHARS16(lv, p, offset, len, f)
717    
718    #define PCHARSV(p, offset, len, f) \
719      if (pcre_mode == PCRE32_MODE) \
720        PCHARSV32(p, offset, len, f); \
721      else \
722        PCHARSV16(p, offset, len, f)
723    
724    #define READ_CAPTURE_NAME(p, cn8, cn16, cn32, re) \
725      if (pcre_mode == PCRE32_MODE) \
726        READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re); \
727      else \
728        READ_CAPTURE_NAME16(p, cn8, cn16, cn32, re)
729    
730    #define SET_PCRE_CALLOUT(callout) \
731      if (pcre_mode == PCRE32_MODE) \
732        SET_PCRE_CALLOUT32(callout); \
733      else \
734        SET_PCRE_CALLOUT16(callout)
735    
736    #define STRLEN(p) (pcre_mode == PCRE32_MODE ? STRLEN32(p) : STRLEN16(p)
737    
738    #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
739      if (pcre_mode == PCRE32_MODE) \
740        PCRE_ASSIGN_JIT_STACK32(extra, callback, userdata); \
741      else \
742        PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata)
743    
744    #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
745      if (pcre_mode == PCRE32_MODE) \
746        PCRE_COMPILE32(re, pat, options, error, erroffset, tables); \
747      else \
748        PCRE_COMPILE16(re, pat, options, error, erroffset, tables)
749    
750    #define PCRE_CONFIG pcre_config
751    
752    #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
753        namesptr, cbuffer, size) \
754      if (pcre_mode == PCRE32_MODE) \
755        PCRE_COPY_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
756          namesptr, cbuffer, size); \
757      else \
758        PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
759          namesptr, cbuffer, size)
760    
761    #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \
762      if (pcre_mode == PCRE32_MODE) \
763        PCRE_COPY_SUBSTRING32(rc, bptr, offsets, count, i, cbuffer, size); \
764      else \
765        PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size)
766    
767  #define CHAR_SIZE (use_pcre16? 2:1)  #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \
768        offsets, size_offsets, workspace, size_workspace) \
769      if (pcre_mode == PCRE32_MODE) \
770        PCRE_DFA_EXEC32(count, re, extra, bptr, len, start_offset, options, \
771          offsets, size_offsets, workspace, size_workspace); \
772      else \
773        PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \
774          offsets, size_offsets, workspace, size_workspace)
775    
776    #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
777        offsets, size_offsets) \
778      if (pcre_mode == PCRE32_MODE) \
779        PCRE_EXEC32(count, re, extra, bptr, len, start_offset, options, \
780          offsets, size_offsets); \
781      else \
782        PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \
783          offsets, size_offsets)
784    
785    #define PCRE_FREE_STUDY(extra) \
786      if (pcre_mode == PCRE32_MODE) \
787        PCRE_FREE_STUDY32(extra); \
788      else \
789        PCRE_FREE_STUDY16(extra)
790    
791    #define PCRE_FREE_SUBSTRING(substring) \
792      if (pcre_mode == PCRE32_MODE) \
793        PCRE_FREE_SUBSTRING32(substring); \
794      else \
795        PCRE_FREE_SUBSTRING16(substring)
796    
797    #define PCRE_FREE_SUBSTRING_LIST(listptr) \
798      if (pcre_mode == PCRE32_MODE) \
799        PCRE_FREE_SUBSTRING_LIST32(listptr); \
800      else \
801        PCRE_FREE_SUBSTRING_LIST16(listptr)
802    
803    #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
804        getnamesptr, subsptr) \
805      if (pcre_mode == PCRE32_MODE) \
806        PCRE_GET_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
807          getnamesptr, subsptr); \
808      else \
809        PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
810          getnamesptr, subsptr)
811    
812    #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \
813      if (pcre_mode == PCRE32_MODE) \
814        PCRE_GET_STRINGNUMBER32(n, rc, ptr); \
815      else \
816        PCRE_GET_STRINGNUMBER16(n, rc, ptr)
817    
818    #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \
819      if (pcre_mode == PCRE32_MODE) \
820        PCRE_GET_SUBSTRING32(rc, bptr, use_offsets, count, i, subsptr); \
821      else \
822        PCRE_GET_SUBSTRING16(rc, bptr, use_offsets, count, i, subsptr)
823    
824    #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \
825      if (pcre_mode == PCRE32_MODE) \
826        PCRE_GET_SUBSTRING_LIST32(rc, bptr, offsets, count, listptr); \
827      else \
828        PCRE_GET_SUBSTRING_LIST16(rc, bptr, offsets, count, listptr)
829    
830    #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
831      (pcre_mode == PCRE32_MODE ? \
832         PCRE_JIT_STACK_ALLOC32(startsize, maxsize) \
833        : PCRE_JIT_STACK_ALLOC16(startsize, maxsize)
834    
835    #define PCRE_JIT_STACK_FREE(stack) \
836      if (pcre_mode == PCRE32_MODE) \
837        PCRE_JIT_STACK_FREE32(stack); \
838      else \
839        PCRE_JIT_STACK_FREE16(stack)
840    
841    #define PCRE_MAKETABLES \
842      (pcre_mode == PCRE32_MODE ? pcre32_maketables() : pcre16_maketables())
843    
844    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \
845      if (pcre_mode == PCRE32_MODE) \
846        PCRE_PATTERN_TO_HOST_BYTE_ORDER32(rc, re, extra, tables); \
847      else \
848        PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables)
849    
850    #define PCRE_PRINTINT(re, outfile, debug_lengths) \
851      if (pcre_mode == PCRE32_MODE) \
852        PCRE_PRINTINT32(re, outfile, debug_lengths); \
853      else \
854        PCRE_PRINTINT16(re, outfile, debug_lengths)
855    
856    #define PCRE_STUDY(extra, re, options, error) \
857      if (pcre_mode == PCRE32_MODE) \
858        PCRE_STUDY32(extra, re, options, error); \
859      else \
860        PCRE_STUDY16(extra, re, options, error)
861    
862    
863    /* ----- 32-bit and 8-bit but not 16-bit supported ----- */
864    
865    #elif defined(SUPPORT_PCRE32) && defined(SUPPORT_PCRE8)
866    
867  #define PCHARS(lv, p, offset, len, f) \  #define PCHARS(lv, p, offset, len, f) \
868    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
869        PCHARS32(lv, p, offset, len, f); \
870      else \
871        PCHARS8(lv, p, offset, len, f)
872    
873    #define PCHARSV(p, offset, len, f) \
874      if (pcre_mode == PCRE32_MODE) \
875        PCHARSV32(p, offset, len, f); \
876      else \
877        PCHARSV8(p, offset, len, f)
878    
879    #define READ_CAPTURE_NAME(p, cn8, cn16, cn32, re) \
880      if (pcre_mode == PCRE32_MODE) \
881        READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re); \
882      else \
883        READ_CAPTURE_NAME8(p, cn8, cn16, cn32, re)
884    
885    #define SET_PCRE_CALLOUT(callout) \
886      if (pcre_mode == PCRE32_MODE) \
887        SET_PCRE_CALLOUT32(callout); \
888      else \
889        SET_PCRE_CALLOUT8(callout)
890    
891    #define STRLEN(p) (pcre_mode == PCRE32_MODE ? STRLEN32(p) : STRLEN8(p))
892    
893    #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
894      if (pcre_mode == PCRE32_MODE) \
895        PCRE_ASSIGN_JIT_STACK32(extra, callback, userdata); \
896      else \
897        PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata)
898    
899    #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
900      if (pcre_mode == PCRE32_MODE) \
901        PCRE_COMPILE32(re, pat, options, error, erroffset, tables); \
902      else \
903        PCRE_COMPILE8(re, pat, options, error, erroffset, tables)
904    
905    #define PCRE_CONFIG pcre_config
906    
907    #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
908        namesptr, cbuffer, size) \
909      if (pcre_mode == PCRE32_MODE) \
910        PCRE_COPY_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
911          namesptr, cbuffer, size); \
912      else \
913        PCRE_COPY_NAMED_SUBSTRING8(rc, re, bptr, offsets, count, \
914          namesptr, cbuffer, size)
915    
916    #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \
917      if (pcre_mode == PCRE32_MODE) \
918        PCRE_COPY_SUBSTRING32(rc, bptr, offsets, count, i, cbuffer, size); \
919      else \
920        PCRE_COPY_SUBSTRING8(rc, bptr, offsets, count, i, cbuffer, size)
921    
922    #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \
923        offsets, size_offsets, workspace, size_workspace) \
924      if (pcre_mode == PCRE32_MODE) \
925        PCRE_DFA_EXEC32(count, re, extra, bptr, len, start_offset, options, \
926          offsets, size_offsets, workspace, size_workspace); \
927      else \
928        PCRE_DFA_EXEC8(count, re, extra, bptr, len, start_offset, options, \
929          offsets, size_offsets, workspace, size_workspace)
930    
931    #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
932        offsets, size_offsets) \
933      if (pcre_mode == PCRE32_MODE) \
934        PCRE_EXEC32(count, re, extra, bptr, len, start_offset, options, \
935          offsets, size_offsets); \
936      else \
937        PCRE_EXEC8(count, re, extra, bptr, len, start_offset, options, \
938          offsets, size_offsets)
939    
940    #define PCRE_FREE_STUDY(extra) \
941      if (pcre_mode == PCRE32_MODE) \
942        PCRE_FREE_STUDY32(extra); \
943      else \
944        PCRE_FREE_STUDY8(extra)
945    
946    #define PCRE_FREE_SUBSTRING(substring) \
947      if (pcre_mode == PCRE32_MODE) \
948        PCRE_FREE_SUBSTRING32(substring); \
949      else \
950        PCRE_FREE_SUBSTRING8(substring)
951    
952    #define PCRE_FREE_SUBSTRING_LIST(listptr) \
953      if (pcre_mode == PCRE32_MODE) \
954        PCRE_FREE_SUBSTRING_LIST32(listptr); \
955      else \
956        PCRE_FREE_SUBSTRING_LIST8(listptr)
957    
958    #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
959        getnamesptr, subsptr) \
960      if (pcre_mode == PCRE32_MODE) \
961        PCRE_GET_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
962          getnamesptr, subsptr); \
963      else \
964        PCRE_GET_NAMED_SUBSTRING8(rc, re, bptr, offsets, count, \
965          getnamesptr, subsptr)
966    
967    #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \
968      if (pcre_mode == PCRE32_MODE) \
969        PCRE_GET_STRINGNUMBER32(n, rc, ptr); \
970      else \
971        PCRE_GET_STRINGNUMBER8(n, rc, ptr)
972    
973    #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \
974      if (pcre_mode == PCRE32_MODE) \
975        PCRE_GET_SUBSTRING32(rc, bptr, use_offsets, count, i, subsptr); \
976      else \
977        PCRE_GET_SUBSTRING8(rc, bptr, use_offsets, count, i, subsptr)
978    
979    #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \
980      if (pcre_mode == PCRE32_MODE) \
981        PCRE_GET_SUBSTRING_LIST32(rc, bptr, offsets, count, listptr); \
982      else \
983        PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)
984    
985    #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
986      (pcre_mode == PCRE32_MODE ? \
987         PCRE_JIT_STACK_ALLOC32(startsize, maxsize) \
988          : PCRE_JIT_STACK_ALLOC8(startsize, maxsize))
989    
990    #define PCRE_JIT_STACK_FREE(stack) \
991      if (pcre_mode == PCRE32_MODE) \
992        PCRE_JIT_STACK_FREE32(stack); \
993      else \
994        PCRE_JIT_STACK_FREE8(stack)
995    
996    #define PCRE_MAKETABLES \
997      (pcre_mode == PCRE32_MODE ? pcre32_maketables() : pcre_maketables())
998    
999    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \
1000      if (pcre_mode == PCRE32_MODE) \
1001        PCRE_PATTERN_TO_HOST_BYTE_ORDER32(rc, re, extra, tables); \
1002      else \
1003        PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables)
1004    
1005    #define PCRE_PRINTINT(re, outfile, debug_lengths) \
1006      if (pcre_mode == PCRE32_MODE) \
1007        PCRE_PRINTINT32(re, outfile, debug_lengths); \
1008      else \
1009        PCRE_PRINTINT8(re, outfile, debug_lengths)
1010    
1011    #define PCRE_STUDY(extra, re, options, error) \
1012      if (pcre_mode == PCRE32_MODE) \
1013        PCRE_STUDY32(extra, re, options, error); \
1014      else \
1015        PCRE_STUDY8(extra, re, options, error)
1016    
1017    
1018    /* ----- 16-bit and 8-bit but not 32-bit supported ----- */
1019    
1020    #else
1021    #define PCHARS(lv, p, offset, len, f) \
1022      if (pcre_mode == PCRE16_MODE) \
1023      PCHARS16(lv, p, offset, len, f); \      PCHARS16(lv, p, offset, len, f); \
1024    else \    else \
1025      PCHARS8(lv, p, offset, len, f)      PCHARS8(lv, p, offset, len, f)
1026    
1027  #define PCHARSV(p, offset, len, f) \  #define PCHARSV(p, offset, len, f) \
1028    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1029      PCHARSV16(p, offset, len, f); \      PCHARSV16(p, offset, len, f); \
1030    else \    else \
1031      PCHARSV8(p, offset, len, f)      PCHARSV8(p, offset, len, f)
1032    
1033  #define READ_CAPTURE_NAME(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME(p, cn8, cn16, cn32, re) \
1034    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1035      READ_CAPTURE_NAME16(p, cn8, cn16, re); \      READ_CAPTURE_NAME16(p, cn8, cn16, cn32, re); \
1036    else \    else \
1037      READ_CAPTURE_NAME8(p, cn8, cn16, re)      READ_CAPTURE_NAME8(p, cn8, cn16, cn32, re)
1038    
1039  #define SET_PCRE_CALLOUT(callout) \  #define SET_PCRE_CALLOUT(callout) \
1040    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1041      SET_PCRE_CALLOUT16(callout); \      SET_PCRE_CALLOUT16(callout); \
1042    else \    else \
1043      SET_PCRE_CALLOUT8(callout)      SET_PCRE_CALLOUT8(callout)
1044    
1045  #define STRLEN(p) (use_pcre16? STRLEN16(p) : STRLEN8(p))  #define STRLEN(p) (pcre_mode == PCRE16_MODE ? STRLEN16(p) : STRLEN8(p))
1046    
1047  #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \  #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
1048    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1049      PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata); \      PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata); \
1050    else \    else \
1051      PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata)      PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata)
1052    
1053  #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \  #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
1054    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1055      PCRE_COMPILE16(re, pat, options, error, erroffset, tables); \      PCRE_COMPILE16(re, pat, options, error, erroffset, tables); \
1056    else \    else \
1057      PCRE_COMPILE8(re, pat, options, error, erroffset, tables)      PCRE_COMPILE8(re, pat, options, error, erroffset, tables)
# Line 417  version is called. ----- */ Line 1060  version is called. ----- */
1060    
1061  #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \  #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
1062      namesptr, cbuffer, size) \      namesptr, cbuffer, size) \
1063    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1064      PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \      PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
1065        namesptr, cbuffer, size); \        namesptr, cbuffer, size); \
1066    else \    else \
# Line 425  version is called. ----- */ Line 1068  version is called. ----- */
1068        namesptr, cbuffer, size)        namesptr, cbuffer, size)
1069    
1070  #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \  #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \
1071    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1072      PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size); \      PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size); \
1073    else \    else \
1074      PCRE_COPY_SUBSTRING8(rc, bptr, offsets, count, i, cbuffer, size)      PCRE_COPY_SUBSTRING8(rc, bptr, offsets, count, i, cbuffer, size)
1075    
1076  #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \
1077      offsets, size_offsets, workspace, size_workspace) \      offsets, size_offsets, workspace, size_workspace) \
1078    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1079      PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \      PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \
1080        offsets, size_offsets, workspace, size_workspace); \        offsets, size_offsets, workspace, size_workspace); \
1081    else \    else \
# Line 441  version is called. ----- */ Line 1084  version is called. ----- */
1084    
1085  #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
1086      offsets, size_offsets) \      offsets, size_offsets) \
1087    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1088      PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \      PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \
1089        offsets, size_offsets); \        offsets, size_offsets); \
1090    else \    else \
# Line 449  version is called. ----- */ Line 1092  version is called. ----- */
1092        offsets, size_offsets)        offsets, size_offsets)
1093    
1094  #define PCRE_FREE_STUDY(extra) \  #define PCRE_FREE_STUDY(extra) \
1095    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1096      PCRE_FREE_STUDY16(extra); \      PCRE_FREE_STUDY16(extra); \
1097    else \    else \
1098      PCRE_FREE_STUDY8(extra)      PCRE_FREE_STUDY8(extra)
1099    
1100  #define PCRE_FREE_SUBSTRING(substring) \  #define PCRE_FREE_SUBSTRING(substring) \
1101    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1102      PCRE_FREE_SUBSTRING16(substring); \      PCRE_FREE_SUBSTRING16(substring); \
1103    else \    else \
1104      PCRE_FREE_SUBSTRING8(substring)      PCRE_FREE_SUBSTRING8(substring)
1105    
1106  #define PCRE_FREE_SUBSTRING_LIST(listptr) \  #define PCRE_FREE_SUBSTRING_LIST(listptr) \
1107    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1108      PCRE_FREE_SUBSTRING_LIST16(listptr); \      PCRE_FREE_SUBSTRING_LIST16(listptr); \
1109    else \    else \
1110      PCRE_FREE_SUBSTRING_LIST8(listptr)      PCRE_FREE_SUBSTRING_LIST8(listptr)
1111    
1112  #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \  #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
1113      getnamesptr, subsptr) \      getnamesptr, subsptr) \
1114    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1115      PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \      PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
1116        getnamesptr, subsptr); \        getnamesptr, subsptr); \
1117    else \    else \
# Line 476  version is called. ----- */ Line 1119  version is called. ----- */
1119        getnamesptr, subsptr)        getnamesptr, subsptr)
1120    
1121  #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \  #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \
1122    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1123      PCRE_GET_STRINGNUMBER16(n, rc, ptr); \      PCRE_GET_STRINGNUMBER16(n, rc, ptr); \
1124    else \    else \
1125      PCRE_GET_STRINGNUMBER8(n, rc, ptr)      PCRE_GET_STRINGNUMBER8(n, rc, ptr)
1126    
1127  #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \  #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \
1128    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1129      PCRE_GET_SUBSTRING16(rc, bptr, use_offsets, count, i, subsptr); \      PCRE_GET_SUBSTRING16(rc, bptr, use_offsets, count, i, subsptr); \
1130    else \    else \
1131      PCRE_GET_SUBSTRING8(rc, bptr, use_offsets, count, i, subsptr)      PCRE_GET_SUBSTRING8(rc, bptr, use_offsets, count, i, subsptr)
1132    
1133  #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \  #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \
1134    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1135      PCRE_GET_SUBSTRING_LIST16(rc, bptr, offsets, count, listptr); \      PCRE_GET_SUBSTRING_LIST16(rc, bptr, offsets, count, listptr); \
1136    else \    else \
1137      PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)      PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)
1138    
1139  #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \  #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
1140    (use_pcre16 ? \    (pcre_mode == PCRE16_MODE ? \
1141       PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \        PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \
1142      :PCRE_JIT_STACK_ALLOC8(startsize, maxsize))        : PCRE_JIT_STACK_ALLOC8(startsize, maxsize))
1143    
1144  #define PCRE_JIT_STACK_FREE(stack) \  #define PCRE_JIT_STACK_FREE(stack) \
1145    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1146      PCRE_JIT_STACK_FREE16(stack); \      PCRE_JIT_STACK_FREE16(stack); \
1147    else \    else \
1148      PCRE_JIT_STACK_FREE8(stack)      PCRE_JIT_STACK_FREE8(stack)
1149    
1150  #define PCRE_MAKETABLES \  #define PCRE_MAKETABLES \
1151    (use_pcre16? pcre16_maketables() : pcre_maketables())    (pcre_mode == PCRE16_MODE ? pcre16_maketables() : pcre_maketables())
1152    
1153  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \
1154    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1155      PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables); \      PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables); \
1156    else \    else \
1157      PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables)      PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables)
1158    
1159  #define PCRE_PRINTINT(re, outfile, debug_lengths) \  #define PCRE_PRINTINT(re, outfile, debug_lengths) \
1160    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1161      PCRE_PRINTINT16(re, outfile, debug_lengths); \      PCRE_PRINTINT16(re, outfile, debug_lengths); \
1162    else \    else \
1163      PCRE_PRINTINT8(re, outfile, debug_lengths)      PCRE_PRINTINT8(re, outfile, debug_lengths)
1164    
1165  #define PCRE_STUDY(extra, re, options, error) \  #define PCRE_STUDY(extra, re, options, error) \
1166    if (use_pcre16) \    if (pcre_mode == PCRE16_MODE) \
1167      PCRE_STUDY16(extra, re, options, error); \      PCRE_STUDY16(extra, re, options, error); \
1168    else \    else \
1169      PCRE_STUDY8(extra, re, options, error)      PCRE_STUDY8(extra, re, options, error)
1170    
1171    #endif
1172    
1173    /* ----- End of cases where more than one mode is supported ----- */
1174    
1175    
1176  /* ----- Only 8-bit mode is supported ----- */  /* ----- Only 8-bit mode is supported ----- */
1177    
1178  #elif defined SUPPORT_PCRE8  #elif defined SUPPORT_PCRE8
# Line 557  version is called. ----- */ Line 1205  version is called. ----- */
1205    
1206  /* ----- Only 16-bit mode is supported ----- */  /* ----- Only 16-bit mode is supported ----- */
1207    
1208  #else  #elif defined SUPPORT_PCRE16
1209  #define CHAR_SIZE                 2  #define CHAR_SIZE                 2
1210  #define PCHARS                    PCHARS16  #define PCHARS                    PCHARS16
1211  #define PCHARSV                   PCHARSV16  #define PCHARSV                   PCHARSV16
# Line 584  version is called. ----- */ Line 1232  version is called. ----- */
1232  #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
1233  #define PCRE_PRINTINT             PCRE_PRINTINT16  #define PCRE_PRINTINT             PCRE_PRINTINT16
1234  #define PCRE_STUDY                PCRE_STUDY16  #define PCRE_STUDY                PCRE_STUDY16
1235    
1236    /* ----- Only 32-bit mode is supported ----- */
1237    
1238    #elif defined SUPPORT_PCRE32
1239    #define CHAR_SIZE                 4
1240    #define PCHARS                    PCHARS32
1241    #define PCHARSV                   PCHARSV32
1242    #define READ_CAPTURE_NAME         READ_CAPTURE_NAME32
1243    #define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT32
1244    #define STRLEN                    STRLEN32
1245    #define PCRE_ASSIGN_JIT_STACK     PCRE_ASSIGN_JIT_STACK32
1246    #define PCRE_COMPILE              PCRE_COMPILE32
1247    #define PCRE_CONFIG               pcre32_config
1248    #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING32
1249    #define PCRE_COPY_SUBSTRING       PCRE_COPY_SUBSTRING32
1250    #define PCRE_DFA_EXEC             PCRE_DFA_EXEC32
1251    #define PCRE_EXEC                 PCRE_EXEC32
1252    #define PCRE_FREE_STUDY           PCRE_FREE_STUDY32
1253    #define PCRE_FREE_SUBSTRING       PCRE_FREE_SUBSTRING32
1254    #define PCRE_FREE_SUBSTRING_LIST  PCRE_FREE_SUBSTRING_LIST32
1255    #define PCRE_GET_NAMED_SUBSTRING  PCRE_GET_NAMED_SUBSTRING32
1256    #define PCRE_GET_STRINGNUMBER     PCRE_GET_STRINGNUMBER32
1257    #define PCRE_GET_SUBSTRING        PCRE_GET_SUBSTRING32
1258    #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST32
1259    #define PCRE_JIT_STACK_ALLOC      PCRE_JIT_STACK_ALLOC32
1260    #define PCRE_JIT_STACK_FREE       PCRE_JIT_STACK_FREE32
1261    #define PCRE_MAKETABLES           pcre32_maketables()
1262    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER32
1263    #define PCRE_PRINTINT             PCRE_PRINTINT32
1264    #define PCRE_STUDY                PCRE_STUDY32
1265    
1266  #endif  #endif
1267    
1268  /* ----- End of mode-specific function call macros ----- */  /* ----- End of mode-specific function call macros ----- */
# Line 599  version is called. ----- */ Line 1278  version is called. ----- */
1278  #endif  #endif
1279  #endif  #endif
1280    
1281    #if !defined NODFA
1282    #define DFA_WS_DIMENSION 1000
1283    #endif
1284    
1285  /* This is the default loop count for timing. */  /* This is the default loop count for timing. */
1286    
1287  #define LOOPREPEAT 500000  #define LOOPREPEAT 500000
# Line 613  static int callout_fail_count; Line 1296  static int callout_fail_count;
1296  static int callout_fail_id;  static int callout_fail_id;
1297  static int debug_lengths;  static int debug_lengths;
1298  static int first_callout;  static int first_callout;
1299    static int jit_was_used;
1300  static int locale_set = 0;  static int locale_set = 0;
1301  static int show_malloc;  static int show_malloc;
1302  static int use_utf;  static int use_utf;
# Line 624  static const unsigned char *last_callout Line 1308  static const unsigned char *last_callout
1308    
1309  static int buffer_size = 50000;  static int buffer_size = 50000;
1310  static pcre_uint8 *buffer = NULL;  static pcre_uint8 *buffer = NULL;
 static pcre_uint8 *dbuffer = NULL;  
1311  static pcre_uint8 *pbuffer = NULL;  static pcre_uint8 *pbuffer = NULL;
1312    
1313  /* Another buffer is needed translation to 16-bit character strings. It will  /* Another buffer is needed translation to 16/32-bit character strings. It will
1314  obtained and extended as required. */  obtained and extended as required. */
1315    
1316  #ifdef SUPPORT_PCRE16  #if defined SUPPORT_PCRE8 && (defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32)
 static int buffer16_size = 0;  
 static pcre_uint16 *buffer16 = NULL;  
   
 #ifdef SUPPORT_PCRE8  
1317    
1318  /* We need the table of operator lengths that is used for 16-bit compiling, in  /* We need the table of operator lengths that is used for 16/32-bit compiling, in
1319  order to swap bytes in a pattern for saving/reloading testing. Luckily, the  order to swap bytes in a pattern for saving/reloading testing. Luckily, the
1320  data is defined as a macro. However, we must ensure that LINK_SIZE is adjusted  data is defined as a macro. However, we must ensure that LINK_SIZE is adjusted
1321  appropriately for the 16-bit world. Just as a safety check, make sure that  appropriately for the 16/32-bit world. Just as a safety check, make sure that
1322  COMPILE_PCRE16 is *not* set. */  COMPILE_PCRE[16|32] is *not* set. */
1323    
1324  #ifdef COMPILE_PCRE16  #ifdef COMPILE_PCRE16
1325  #error COMPILE_PCRE16 must not be set when compiling pcretest.c  #error COMPILE_PCRE16 must not be set when compiling pcretest.c
1326  #endif  #endif
1327    
1328    #ifdef COMPILE_PCRE32
1329    #error COMPILE_PCRE32 must not be set when compiling pcretest.c
1330    #endif
1331    
1332  #if LINK_SIZE == 2  #if LINK_SIZE == 2
1333  #undef LINK_SIZE  #undef LINK_SIZE
1334  #define LINK_SIZE 1  #define LINK_SIZE 1
# Line 659  COMPILE_PCRE16 is *not* set. */ Line 1342  COMPILE_PCRE16 is *not* set. */
1342  #undef IMM2_SIZE  #undef IMM2_SIZE
1343  #define IMM2_SIZE 1  #define IMM2_SIZE 1
1344    
1345  #endif /* SUPPORT_PCRE8 */  #endif /* SUPPORT_PCRE8 && (SUPPORT_PCRE16 || SUPPORT_PCRE32) */
1346    
1347    #ifdef SUPPORT_PCRE16
1348    static int buffer16_size = 0;
1349    static pcre_uint16 *buffer16 = NULL;
1350  static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };  static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };
1351  #endif  /* SUPPORT_PCRE16 */  #endif  /* SUPPORT_PCRE16 */
1352    
1353  /* If we have 8-bit support, default use_pcre16 to false; if there is also  #ifdef SUPPORT_PCRE32
1354  16-bit support, it can be changed by an option. If there is no 8-bit support,  static int buffer32_size = 0;
1355  there must be 16-bit support, so default it to 1. */  static pcre_uint32 *buffer32 = NULL;
1356    static const pcre_uint32 OP_lengths32[] = { OP_LENGTHS };
1357    #endif  /* SUPPORT_PCRE32 */
1358    
1359    /* If we have 8-bit support, default to it; if there is also
1360    16-or 32-bit support, it can be changed by an option. If there is no 8-bit support,
1361    there must be 16-or 32-bit support, so default it to 1. */
1362    
1363  #ifdef SUPPORT_PCRE8  #if defined SUPPORT_PCRE8
1364  static int use_pcre16 = 0;  static int pcre_mode = PCRE8_MODE;
1365  #else  #elif defined SUPPORT_PCRE16
1366  static int use_pcre16 = 1;  static int pcre_mode = PCRE16_MODE;
1367    #elif defined SUPPORT_PCRE32
1368    static int pcre_mode = PCRE32_MODE;
1369  #endif  #endif
1370    
1371    /* JIT study options for -s+n and /S+n where '1' <= n <= '7'. */
1372    
1373    static int jit_study_bits[] =
1374      {
1375      PCRE_STUDY_JIT_COMPILE,
1376      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE,
1377      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE,
1378      PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
1379      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
1380      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE + PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
1381      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE +
1382        PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE
1383    };
1384    
1385    #define PCRE_STUDY_ALLJIT (PCRE_STUDY_JIT_COMPILE | \
1386      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE | PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE)
1387    
1388  /* Textual explanations for runtime error codes */  /* Textual explanations for runtime error codes */
1389    
1390  static const char *errtexts[] = {  static const char *errtexts[] = {
# Line 705  static const char *errtexts[] = { Line 1416  static const char *errtexts[] = {
1416    NULL,  /* SHORTUTF8/16 is handled specially */    NULL,  /* SHORTUTF8/16 is handled specially */
1417    "nested recursion at the same subject position",    "nested recursion at the same subject position",
1418    "JIT stack limit reached",    "JIT stack limit reached",
1419    "pattern compiled in wrong mode: 8-bit/16-bit error"    "pattern compiled in wrong mode: 8-bit/16-bit error",
1420      "pattern compiled with other endianness",
1421      "invalid data in workspace for DFA restart"
1422  };  };
1423    
1424    
# Line 1051  extern char *sys_errlist[]; Line 1764  extern char *sys_errlist[];
1764  char *  char *
1765  strerror(int n)  strerror(int n)
1766  {  {
1767  if (n < 0 || n >= sys_nerr) return "unknown error number";  if (n < 0 || n >= sys_nerr) return "unknown error number";
1768  return sys_errlist[n];  return sys_errlist[n];
1769    }
1770    #endif /* HAVE_STRERROR */
1771    
1772    
1773    
1774    /*************************************************
1775    *       Print newline configuration              *
1776    *************************************************/
1777    
1778    /*
1779    Arguments:
1780      rc         the return code from PCRE_CONFIG_NEWLINE
1781      isc        TRUE if called from "-C newline"
1782    Returns:     nothing
1783    */
1784    
1785    static void
1786    print_newline_config(int rc, BOOL isc)
1787    {
1788    const char *s = NULL;
1789    if (!isc) printf("  Newline sequence is ");
1790    switch(rc)
1791      {
1792      case CHAR_CR: s = "CR"; break;
1793      case CHAR_LF: s = "LF"; break;
1794      case (CHAR_CR<<8 | CHAR_LF): s = "CRLF"; break;
1795      case -1: s = "ANY"; break;
1796      case -2: s = "ANYCRLF"; break;
1797    
1798      default:
1799      printf("a non-standard value: 0x%04x\n", rc);
1800      return;
1801      }
1802    
1803    printf("%s\n", s);
1804  }  }
1805  #endif /* HAVE_STRERROR */  
1806    
1807    
1808  /*************************************************  /*************************************************
# Line 1063  return sys_errlist[n]; Line 1811  return sys_errlist[n];
1811    
1812  static pcre_jit_stack* jit_callback(void *arg)  static pcre_jit_stack* jit_callback(void *arg)
1813  {  {
1814    jit_was_used = TRUE;
1815  return (pcre_jit_stack *)arg;  return (pcre_jit_stack *)arg;
1816  }  }
1817    
1818    
1819  #if !defined NOUTF || defined SUPPORT_PCRE16  #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32
1820  /*************************************************  /*************************************************
1821  *            Convert UTF-8 string to value       *  *            Convert UTF-8 string to value       *
1822  *************************************************/  *************************************************/
# Line 1084  Returns:      >  0 => the number of byte Line 1833  Returns:      >  0 => the number of byte
1833  */  */
1834    
1835  static int  static int
1836  utf82ord(pcre_uint8 *utf8bytes, int *vptr)  utf82ord(pcre_uint8 *utf8bytes, pcre_uint32 *vptr)
1837  {  {
1838  int c = *utf8bytes++;  pcre_uint32 c = *utf8bytes++;
1839  int d = c;  pcre_uint32 d = c;
1840  int i, j, s;  int i, j, s;
1841    
1842  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 1864  for (j = 0; j < i; j++)
1864  /* Check that encoding was the correct unique one */  /* Check that encoding was the correct unique one */
1865    
1866  for (j = 0; j < utf8_table1_size; j++)  for (j = 0; j < utf8_table1_size; j++)
1867    if (d <= utf8_table1[j]) break;    if (d <= (pcre_uint32)utf8_table1[j]) break;
1868  if (j != i) return -(i+1);  if (j != i) return -(i+1);
1869    
1870  /* Valid value */  /* Valid value */
# Line 1127  return i+1; Line 1876  return i+1;
1876    
1877    
1878    
1879  #if !defined NOUTF || defined SUPPORT_PCRE16  #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32
1880  /*************************************************  /*************************************************
1881  *       Convert character value to UTF-8         *  *       Convert character value to UTF-8         *
1882  *************************************************/  *************************************************/
# Line 1143  Returns:     number of characters placed Line 1892  Returns:     number of characters placed
1892  */  */
1893    
1894  static int  static int
1895  ord2utf8(int cvalue, pcre_uint8 *utf8bytes)  ord2utf8(pcre_uint32 cvalue, pcre_uint8 *utf8bytes)
1896  {  {
1897  register int i, j;  register int i, j;
1898    if (cvalue > 0x7fffffffu)
1899      return -1;
1900  for (i = 0; i < utf8_table1_size; i++)  for (i = 0; i < utf8_table1_size; i++)
1901    if (cvalue <= utf8_table1[i]) break;    if (cvalue <= (pcre_uint32)utf8_table1[i]) break;
1902  utf8bytes += i;  utf8bytes += i;
1903  for (j = i; j > 0; j--)  for (j = i; j > 0; j--)
1904   {   {
# Line 1216  if (!utf && !data) Line 1967  if (!utf && !data)
1967    
1968  else  else
1969    {    {
1970    int c = 0;    pcre_uint32 c = 0;
1971    while (len > 0)    while (len > 0)
1972      {      {
1973      int chlen = utf82ord(p, &c);      int chlen = utf82ord(p, &c);
# Line 1239  return pp - buffer16; Line 1990  return pp - buffer16;
1990  }  }
1991  #endif  #endif
1992    
1993    #ifdef SUPPORT_PCRE32
1994    /*************************************************
1995    *         Convert a string to 32-bit             *
1996    *************************************************/
1997    
1998    /* In non-UTF mode, the space needed for a 32-bit string is exactly four times the
1999    8-bit size. For a UTF-8 string, the size needed for UTF-32 is no more than four
2000    times, because up to 0xffff uses no more than 3 bytes in UTF-8 but possibly 4
2001    in UTF-32. Higher values use 4 bytes in UTF-8 and up to 4 bytes in UTF-32. The
2002    result is always left in buffer32.
2003    
2004    Note that this function does not object to surrogate values. This is
2005    deliberate; it makes it possible to construct UTF-32 strings that are invalid,
2006    for the purpose of testing that they are correctly faulted.
2007    
2008    Patterns to be converted are either plain ASCII or UTF-8; data lines are always
2009    in UTF-8 so that values greater than 255 can be handled.
2010    
2011    Arguments:
2012      data       TRUE if converting a data line; FALSE for a regex
2013      p          points to a byte string
2014      utf        true if UTF-8 (to be converted to UTF-32)
2015      len        number of bytes in the string (excluding trailing zero)
2016    
2017    Returns:     number of 32-bit data items used (excluding trailing zero)
2018                 OR -1 if a UTF-8 string is malformed
2019                 OR -2 if a value > 0x10ffff is encountered
2020                 OR -3 if an ill-formed value is encountered (i.e. a surrogate)
2021    */
2022    
2023    static int
2024    to32(int data, pcre_uint8 *p, int utf, int len)
2025    {
2026    pcre_uint32 *pp;
2027    
2028    if (buffer32_size < 4*len + 4)
2029      {
2030      if (buffer32 != NULL) free(buffer32);
2031      buffer32_size = 4*len + 4;
2032      buffer32 = (pcre_uint32 *)malloc(buffer32_size);
2033      if (buffer32 == NULL)
2034        {
2035        fprintf(stderr, "pcretest: malloc(%d) failed for buffer32\n", buffer32_size);
2036        exit(1);
2037        }
2038      }
2039    
2040    pp = buffer32;
2041    
2042    if (!utf && !data)
2043      {
2044      while (len-- > 0) *pp++ = *p++;
2045      }
2046    
2047    else
2048      {
2049      pcre_uint32 c = 0;
2050      while (len > 0)
2051        {
2052        int chlen = utf82ord(p, &c);
2053        if (chlen <= 0) return -1;
2054        if (utf)
2055          {
2056          if (c > 0x10ffff) return -2;
2057          if (!data && (c & 0xfffff800u) == 0xd800u) return -3;
2058          }
2059    
2060        p += chlen;
2061        len -= chlen;
2062        *pp++ = c;
2063        }
2064      }
2065    
2066    *pp = 0;
2067    return pp - buffer32;
2068    }
2069    
2070    /* Check that a 32-bit character string is valid UTF-32.
2071    
2072    Arguments:
2073      string       points to the string
2074      length       length of string, or -1 if the string is zero-terminated
2075    
2076    Returns:       TRUE  if the string is a valid UTF-32 string
2077                   FALSE otherwise
2078    */
2079    
2080    #ifdef SUPPORT_UTF
2081    static BOOL
2082    valid_utf32(pcre_uint32 *string, int length)
2083    {
2084    register pcre_uint32 *p;
2085    register pcre_uint32 c;
2086    
2087    for (p = string; length-- > 0; p++)
2088      {
2089      c = *p;
2090    
2091      if (c > 0x10ffffu)
2092        return FALSE;
2093    
2094      /* A surrogate */
2095      if ((c & 0xfffff800u) == 0xd800u)
2096        return FALSE;
2097    
2098      /* Non-character */
2099      if ((c & 0xfffeu) == 0xfffeu ||
2100          c >= 0xfdd0u && c <= 0xfdefu)
2101        return FALSE;
2102      }
2103    
2104    return TRUE;
2105    }
2106    #endif /* SUPPORT_UTF */
2107    
2108    #endif
2109    
2110  /*************************************************  /*************************************************
2111  *        Read or extend an input line            *  *        Read or extend an input line            *
# Line 1276  for (;;) Line 2143  for (;;)
2143      {      {
2144      int dlen;      int dlen;
2145    
2146      /* 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
2147      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
2148      we must put it back again, to be compatible with fgets(). */      newline, so we must put it back again, to be compatible with fgets(). */
2149    
2150  #ifdef SUPPORT_LIBREADLINE  #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
2151      if (isatty(fileno(f)))      if (isatty(fileno(f)))
2152        {        {
2153        size_t len;        size_t len;
# Line 1314  for (;;) Line 2181  for (;;)
2181      {      {
2182      int new_buffer_size = 2*buffer_size;      int new_buffer_size = 2*buffer_size;
2183      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);  
2184      pcre_uint8 *new_pbuffer = (pcre_uint8 *)malloc(new_buffer_size);      pcre_uint8 *new_pbuffer = (pcre_uint8 *)malloc(new_buffer_size);
2185    
2186      if (new_buffer == NULL || new_dbuffer == NULL || new_pbuffer == NULL)      if (new_buffer == NULL || new_pbuffer == NULL)
2187        {        {
2188        fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);        fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);
2189        exit(1);        exit(1);
# Line 1332  for (;;) Line 2198  for (;;)
2198      here = new_buffer + (here - buffer);      here = new_buffer + (here - buffer);
2199    
2200      free(buffer);      free(buffer);
     free(dbuffer);  
2201      free(pbuffer);      free(pbuffer);
2202    
2203      buffer = new_buffer;      buffer = new_buffer;
     dbuffer = new_dbuffer;  
2204      pbuffer = new_pbuffer;      pbuffer = new_pbuffer;
2205      }      }
2206    }    }
# Line 1379  return(result); Line 2243  return(result);
2243    
2244  /* Print a single character either literally, or as a hex escape. */  /* Print a single character either literally, or as a hex escape. */
2245    
2246  static int pchar(int c, FILE *f)  static int pchar(pcre_uint32 c, FILE *f)
2247  {  {
2248    int n;
2249  if (PRINTOK(c))  if (PRINTOK(c))
2250    {    {
2251    if (f != NULL) fprintf(f, "%c", c);    if (f != NULL) fprintf(f, "%c", c);
# Line 1401  if (c < 0x100) Line 2266  if (c < 0x100)
2266      }      }
2267    }    }
2268    
2269  if (f != NULL) fprintf(f, "\\x{%02x}", c);  if (f != NULL) n = fprintf(f, "\\x{%02x}", c);
2270  return (c <= 0x000000ff)? 6 :  return n >= 0 ? n : 0;
        (c <= 0x00000fff)? 7 :  
        (c <= 0x0000ffff)? 8 :  
        (c <= 0x000fffff)? 9 : 10;  
2271  }  }
2272    
2273    
# Line 1420  If handed a NULL file, just counts chars Line 2282  If handed a NULL file, just counts chars
2282    
2283  static int pchars(pcre_uint8 *p, int length, FILE *f)  static int pchars(pcre_uint8 *p, int length, FILE *f)
2284  {  {
2285  int c = 0;  pcre_uint32 c = 0;
2286  int yield = 0;  int yield = 0;
2287    
2288  if (length < 0)  if (length < 0)
# Line 1465  return len; Line 2327  return len;
2327  #endif  /* SUPPORT_PCRE16 */  #endif  /* SUPPORT_PCRE16 */
2328    
2329    
2330    
2331    #ifdef SUPPORT_PCRE32
2332    /*************************************************
2333    *    Find length of 0-terminated 32-bit string   *
2334    *************************************************/
2335    
2336    static int strlen32(PCRE_SPTR32 p)
2337    {
2338    int len = 0;
2339    while (*p++ != 0) len++;
2340    return len;
2341    }
2342    #endif  /* SUPPORT_PCRE32 */
2343    
2344    
2345    
2346  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2347  /*************************************************  /*************************************************
2348  *           Print 16-bit character string        *  *           Print 16-bit character string        *
# Line 1482  if (length < 0) Line 2360  if (length < 0)
2360    
2361  while (length-- > 0)  while (length-- > 0)
2362    {    {
2363    int c = *p++ & 0xffff;    pcre_uint32 c = *p++ & 0xffff;
2364  #if !defined NOUTF  #if !defined NOUTF
2365    if (use_utf && c >= 0xD800 && c < 0xDC00 && length > 0)    if (use_utf && c >= 0xD800 && c < 0xDC00 && length > 0)
2366      {      {
# Line 1504  return yield; Line 2382  return yield;
2382    
2383    
2384    
2385    #ifdef SUPPORT_PCRE32
2386    /*************************************************
2387    *           Print 32-bit character string        *
2388    *************************************************/
2389    
2390    /* Must handle UTF-32 strings in utf mode. Yields number of characters printed.
2391    If handed a NULL file, just counts chars without printing. */
2392    
2393    #define UTF32_MASK (0x1fffffu)
2394    
2395    static int pchars32(PCRE_SPTR32 p, int length, BOOL utf, FILE *f)
2396    {
2397    int yield = 0;
2398    
2399    if (length < 0)
2400      length = strlen32(p);
2401    
2402    while (length-- > 0)
2403      {
2404      pcre_uint32 c = *p++;
2405      if (utf) c &= UTF32_MASK;
2406      yield += pchar(c, f);
2407      }
2408    
2409    return yield;
2410    }
2411    #endif  /* SUPPORT_PCRE32 */
2412    
2413    
2414    
2415  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
2416  /*************************************************  /*************************************************
2417  *     Read a capture name (8-bit) and check it   *  *     Read a capture name (8-bit) and check it   *
# Line 1557  return p; Line 2465  return p;
2465    
2466    
2467    
2468    #ifdef SUPPORT_PCRE32
2469    /*************************************************
2470    *     Read a capture name (32-bit) and check it  *
2471    *************************************************/
2472    
2473    /* Note that the text being read is 8-bit. */
2474    
2475    static pcre_uint8 *
2476    read_capture_name32(pcre_uint8 *p, pcre_uint32 **pp, pcre *re)
2477    {
2478    pcre_uint32 *npp = *pp;
2479    while (isalnum(*p)) *npp++ = *p++;
2480    *npp++ = 0;
2481    *npp = 0;
2482    if (pcre32_get_stringnumber((pcre32 *)re, (PCRE_SPTR32)(*pp)) < 0)
2483      {
2484      fprintf(outfile, "no parentheses with name \"");
2485      PCHARSV(*pp, 0, -1, outfile);
2486      fprintf(outfile, "\"\n");
2487      }
2488    *pp = npp;
2489    return p;
2490    }
2491    #endif  /* SUPPORT_PCRE32 */
2492    
2493    
2494    
2495  /*************************************************  /*************************************************
2496  *              Callout function                  *  *              Callout function                  *
2497  *************************************************/  *************************************************/
# Line 1714  free(block); Line 2649  free(block);
2649  *************************************************/  *************************************************/
2650    
2651  /* Get one piece of information from the pcre_fullinfo() function. When only  /* Get one piece of information from the pcre_fullinfo() function. When only
2652  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
2653  value, but the code is defensive.  value, but the code is defensive.
2654    
2655  Arguments:  Arguments:
# Line 1731  new_info(pcre *re, pcre_extra *study, in Line 2666  new_info(pcre *re, pcre_extra *study, in
2666  {  {
2667  int rc;  int rc;
2668    
2669  if (use_pcre16)  if (pcre_mode == PCRE32_MODE)
2670    #ifdef SUPPORT_PCRE32
2671      rc = pcre32_fullinfo((pcre32 *)re, (pcre32_extra *)study, option, ptr);
2672    #else
2673      rc = PCRE_ERROR_BADMODE;
2674    #endif
2675    else if (pcre_mode == PCRE16_MODE)
2676  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2677    rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);    rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);
2678  #else  #else
# Line 1747  else Line 2688  else
2688  if (rc < 0)  if (rc < 0)
2689    {    {
2690    fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,    fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
2691      use_pcre16? "16" : "", option);      pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "", option);
2692    if (rc == PCRE_ERROR_BADMODE)    if (rc == PCRE_ERROR_BADMODE)
2693      fprintf(outfile, "Running in %s-bit mode but pattern was compiled in "      fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
2694        "%s-bit mode\n", use_pcre16? "16":"8", use_pcre16? "8":"16");        "%d-bit mode\n", 8 * CHAR_SIZE,
2695          8 * (REAL_PCRE_FLAGS(re) & PCRE_MODE_MASK));
2696    }    }
2697    
2698  return rc;  return rc;
# Line 1799  bytes in the pattern itself. This is to Line 2741  bytes in the pattern itself. This is to
2741  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
2742  architecture. */  architecture. */
2743    
2744    #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
2745  static void  static void
2746  regexflip(pcre *ere, pcre_extra *extra)  regexflip8_or_16(pcre *ere, pcre_extra *extra)
2747  {  {
2748  REAL_PCRE *re = (REAL_PCRE *)ere;  real_pcre8_or_16 *re = (real_pcre8_or_16 *)ere;
2749  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2750  int op;  int op;
2751  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 2782  if (extra != NULL)
2782  in the name table, if present, and then in the pattern itself. */  in the name table, if present, and then in the pattern itself. */
2783    
2784  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2785  if (!use_pcre16) return;  if (pcre_mode != PCRE16_MODE) return;
2786    
2787  while(TRUE)  while(TRUE)
2788    {    {
# Line 1977  while(TRUE) Line 2920  while(TRUE)
2920  /* Control should never reach here in 16 bit mode. */  /* Control should never reach here in 16 bit mode. */
2921  #endif /* SUPPORT_PCRE16 */  #endif /* SUPPORT_PCRE16 */
2922  }  }
2923    #endif /* SUPPORT_PCRE[8|16] */
2924    
2925    
2926    
2927    #if defined SUPPORT_PCRE32
2928    static void
2929    regexflip_32(pcre *ere, pcre_extra *extra)
2930    {
2931    real_pcre32 *re = (real_pcre32 *)ere;
2932    int op;
2933    pcre_uint32 *ptr = (pcre_uint32 *)re + re->name_table_offset;
2934    int length = re->name_count * re->name_entry_size;
2935    #ifdef SUPPORT_UTF
2936    BOOL utf = (re->options & PCRE_UTF32) != 0;
2937    #endif /* SUPPORT_UTF */
2938    
2939    /* Always flip the bytes in the main data block and study blocks. */
2940    
2941    re->magic_number = REVERSED_MAGIC_NUMBER;
2942    re->size = swap_uint32(re->size);
2943    re->options = swap_uint32(re->options);
2944    re->flags = swap_uint16(re->flags);
2945    re->top_bracket = swap_uint16(re->top_bracket);
2946    re->top_backref = swap_uint16(re->top_backref);
2947    re->first_char = swap_uint32(re->first_char);
2948    re->req_char = swap_uint32(re->req_char);
2949    re->name_table_offset = swap_uint16(re->name_table_offset);
2950    re->name_entry_size = swap_uint16(re->name_entry_size);
2951    re->name_count = swap_uint16(re->name_count);
2952    
2953    if (extra != NULL)
2954      {
2955      pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
2956      rsd->size = swap_uint32(rsd->size);
2957      rsd->flags = swap_uint32(rsd->flags);
2958      rsd->minlength = swap_uint32(rsd->minlength);
2959      }
2960    
2961    /* In 32-bit mode we must swap bytes
2962    in the name table, if present, and then in the pattern itself. */
2963    
2964    while(TRUE)
2965      {
2966      /* Swap previous characters. */
2967      while (length-- > 0)
2968        {
2969        *ptr = swap_uint32(*ptr);
2970        ptr++;
2971        }
2972    
2973      /* Get next opcode. */
2974    
2975      length = 0;
2976      op = *ptr;
2977      *ptr++ = swap_uint32(op);
2978    
2979      switch (op)
2980        {
2981        case OP_END:
2982        return;
2983    
2984        default:
2985        length = OP_lengths32[op] - 1;
2986        break;
2987    
2988        case OP_CLASS:
2989        case OP_NCLASS:
2990        /* Skip the character bit map. */
2991        ptr += 32/sizeof(pcre_uint32);
2992        length = 0;
2993        break;
2994    
2995        case OP_XCLASS:
2996        /* LINK_SIZE can only be 1 in 32-bit mode. */
2997        length = (int)((unsigned int)(ptr[0]) - (1 + LINK_SIZE + 1));
2998    
2999        /* Reverse the size of the XCLASS instance. */
3000        *ptr = swap_uint32(*ptr);
3001        ptr++;
3002    
3003        op = *ptr;
3004        *ptr = swap_uint32(op);
3005        ptr++;
3006        if ((op & XCL_MAP) != 0)
3007          {
3008          /* Skip the character bit map. */
3009          ptr += 32/sizeof(pcre_uint32);
3010          length -= 32/sizeof(pcre_uint32);
3011          }
3012        break;
3013        }
3014      }
3015    /* Control should never reach here in 32 bit mode. */
3016    }
3017    
3018    #endif /* SUPPORT_PCRE32 */
3019    
3020    
3021    
3022    static void
3023    regexflip(pcre *ere, pcre_extra *extra)
3024    {
3025    #if defined SUPPORT_PCRE32
3026      if (REAL_PCRE_FLAGS(ere) & PCRE_MODE32)
3027        regexflip_32(ere, extra);
3028    #endif
3029    #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
3030      if (REAL_PCRE_FLAGS(ere) & (PCRE_MODE8 | PCRE_MODE16))
3031        regexflip8_or_16(ere, extra);
3032    #endif
3033    }
3034    
3035    
3036    
# Line 2096  usage(void) Line 3150  usage(void)
3150  {  {
3151  printf("Usage:     pcretest [options] [<input file> [<output file>]]\n\n");  printf("Usage:     pcretest [options] [<input file> [<output file>]]\n\n");
3152  printf("Input and output default to stdin and stdout.\n");  printf("Input and output default to stdin and stdout.\n");
3153  #ifdef SUPPORT_LIBREADLINE  #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
3154  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");
3155  #else  #else
3156  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 3159  printf("\nOptions:\n");
3159  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3160  printf("  -16      use the 16-bit library\n");  printf("  -16      use the 16-bit library\n");
3161  #endif  #endif
3162    #ifdef SUPPORT_PCRE32
3163    printf("  -32      use the 32-bit library\n");
3164    #endif
3165  printf("  -b       show compiled code\n");  printf("  -b       show compiled code\n");
3166  printf("  -C       show PCRE compile-time options and exit\n");  printf("  -C       show PCRE compile-time options and exit\n");
3167  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 3169  printf("           and exit with its val
3169  printf("     linksize     internal link size [2, 3, 4]\n");  printf("     linksize     internal link size [2, 3, 4]\n");
3170  printf("     pcre8        8 bit library support enabled [0, 1]\n");  printf("     pcre8        8 bit library support enabled [0, 1]\n");
3171  printf("     pcre16       16 bit library support enabled [0, 1]\n");  printf("     pcre16       16 bit library support enabled [0, 1]\n");
3172    printf("     pcre32       32 bit library support enabled [0, 1]\n");
3173  printf("     utf          Unicode Transformation Format supported [0, 1]\n");  printf("     utf          Unicode Transformation Format supported [0, 1]\n");
3174  printf("     ucp          Unicode Properties supported [0, 1]\n");  printf("     ucp          Unicode Properties supported [0, 1]\n");
3175  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 3190  printf("  -q       quiet: do not output
3190  printf("  -S <n>   set stack size to <n> megabytes\n");  printf("  -S <n>   set stack size to <n> megabytes\n");
3191  printf("  -s       force each pattern to be studied at basic level\n"  printf("  -s       force each pattern to be studied at basic level\n"
3192         "  -s+      force each pattern to be studied, using JIT if available\n"         "  -s+      force each pattern to be studied, using JIT if available\n"
3193           "  -s++     ditto, verifying when JIT was actually used\n"
3194           "  -s+n     force each pattern to be studied, using JIT if available,\n"
3195           "             where 1 <= n <= 7 selects JIT options\n"
3196           "  -s++n    ditto, verifying when JIT was actually used\n"
3197         "  -t       time compilation and execution\n");         "  -t       time compilation and execution\n");
3198  printf("  -t <n>   time compilation and execution, repeating <n> times\n");  printf("  -t <n>   time compilation and execution, repeating <n> times\n");
3199  printf("  -tm      time execution (matching) only\n");  printf("  -tm      time execution (matching) only\n");
# Line 2166  int quiet = 0; Line 3228  int quiet = 0;
3228  int size_offsets = 45;  int size_offsets = 45;
3229  int size_offsets_max;  int size_offsets_max;
3230  int *offsets = NULL;  int *offsets = NULL;
 #if !defined NOPOSIX  
 int posix = 0;  
 #endif  
3231  int debug = 0;  int debug = 0;
3232  int done = 0;  int done = 0;
3233  int all_use_dfa = 0;  int all_use_dfa = 0;
3234    int verify_jit = 0;
3235  int yield = 0;  int yield = 0;
3236    #ifdef SUPPORT_PCRE32
3237    int mask_utf32 = 0;
3238    #endif
3239  int stack_size;  int stack_size;
3240    pcre_uint8 *dbuffer = NULL;
3241    size_t dbuffer_size = 1u << 14;
3242    
3243    #if !defined NOPOSIX
3244    int posix = 0;
3245    #endif
3246    #if !defined NODFA
3247    int *dfa_workspace = NULL;
3248    #endif
3249    
3250  pcre_jit_stack *jit_stack = NULL;  pcre_jit_stack *jit_stack = NULL;
3251    
3252  /* These vectors store, end-to-end, a list of zero-terminated captured  /* These vectors store, end-to-end, a list of zero-terminated captured
3253  substring names, each list itself being terminated by an empty name. Assume  substring names, each list itself being terminated by an empty name. Assume
3254  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
3255  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
3256  for the actual memory, to ensure alignment. */  for the actual memory, to ensure alignment. */
3257    
3258  pcre_uint16 copynames[1024];  pcre_uint32 copynames[1024];
3259  pcre_uint16 getnames[1024];  pcre_uint32 getnames[1024];
3260    
3261    #ifdef SUPPORT_PCRE32
3262    pcre_uint32 *cn32ptr;
3263    pcre_uint32 *gn32ptr;
3264    #endif
3265    
3266  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3267    pcre_uint16 *copynames16 = (pcre_uint16 *)copynames;
3268    pcre_uint16 *getnames16 = (pcre_uint16 *)getnames;
3269  pcre_uint16 *cn16ptr;  pcre_uint16 *cn16ptr;
3270  pcre_uint16 *gn16ptr;  pcre_uint16 *gn16ptr;
3271  #endif  #endif
# Line 2199  pcre_uint8 *gn8ptr; Line 3278  pcre_uint8 *gn8ptr;
3278  #endif  #endif
3279    
3280  /* Get buffers from malloc() so that valgrind will check their misuse when  /* Get buffers from malloc() so that valgrind will check their misuse when
3281  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-
3282  buffer (buffer16) is obtained only if needed. */  and 32-bit buffers (buffer16, buffer32) are obtained only if needed. */
3283    
3284  buffer = (pcre_uint8 *)malloc(buffer_size);  buffer = (pcre_uint8 *)malloc(buffer_size);
 dbuffer = (pcre_uint8 *)malloc(buffer_size);  
3285  pbuffer = (pcre_uint8 *)malloc(buffer_size);  pbuffer = (pcre_uint8 *)malloc(buffer_size);
3286    
3287  /* 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 3300  _setmode( _fileno( stdout ), _O_BINARY )
3300  /* Get the version number: both pcre_version() and pcre16_version() give the  /* Get the version number: both pcre_version() and pcre16_version() give the
3301  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. */
3302    
3303  #ifdef SUPPORT_PCRE8  #if defined SUPPORT_PCRE8
3304  version = pcre_version();  version = pcre_version();
3305  #else  #elif defined SUPPORT_PCRE16
3306  version = pcre16_version();  version = pcre16_version();
3307    #elif defined SUPPORT_PCRE32
3308    version = pcre32_version();
3309  #endif  #endif
3310    
3311  /* Scan options */  /* Scan options */
# Line 2233  version = pcre16_version(); Line 3313  version = pcre16_version();
3313  while (argc > 1 && argv[op][0] == '-')  while (argc > 1 && argv[op][0] == '-')
3314    {    {
3315    pcre_uint8 *endptr;    pcre_uint8 *endptr;
3316      char *arg = argv[op];
3317    
3318    if (strcmp(argv[op], "-m") == 0) showstore = 1;    if (strcmp(arg, "-m") == 0) showstore = 1;
3319    else if (strcmp(argv[op], "-s") == 0) force_study = 0;    else if (strcmp(arg, "-s") == 0) force_study = 0;
3320    else if (strcmp(argv[op], "-s+") == 0)  
3321      else if (strncmp(arg, "-s+", 3) == 0)
3322      {      {
3323        arg += 3;
3324        if (*arg == '+') { arg++; verify_jit = TRUE; }
3325      force_study = 1;      force_study = 1;
3326      force_study_options = PCRE_STUDY_JIT_COMPILE;      if (*arg == 0)
3327          force_study_options = jit_study_bits[6];
3328        else if (*arg >= '1' && *arg <= '7')
3329          force_study_options = jit_study_bits[*arg - '1'];
3330        else goto BAD_ARG;
3331        }
3332      else if (strcmp(arg, "-8") == 0)
3333        {
3334    #ifdef SUPPORT_PCRE8
3335        pcre_mode = PCRE8_MODE;
3336    #else
3337        printf("** This version of PCRE was built without 8-bit support\n");
3338        exit(1);
3339    #endif
3340      }      }
3341    else if (strcmp(argv[op], "-16") == 0)    else if (strcmp(arg, "-16") == 0)
3342      {      {
3343  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3344      use_pcre16 = 1;      pcre_mode = PCRE16_MODE;
3345  #else  #else
3346      printf("** This version of PCRE was built without 16-bit support\n");      printf("** This version of PCRE was built without 16-bit support\n");
3347      exit(1);      exit(1);
3348  #endif  #endif
3349      }      }
3350    else if (strcmp(argv[op], "-q") == 0) quiet = 1;    else if (strcmp(arg, "-32") == 0 || strcmp(arg, "-32+") == 0)
3351    else if (strcmp(argv[op], "-b") == 0) debug = 1;      {
3352    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;  #ifdef SUPPORT_PCRE32
3353    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;      pcre_mode = PCRE32_MODE;
3354    else if (strcmp(argv[op], "-M") == 0) default_find_match_limit = TRUE;      mask_utf32 = (strcmp(arg, "-32+") == 0);
3355    #else
3356        printf("** This version of PCRE was built without 32-bit support\n");
3357        exit(1);
3358    #endif
3359        }
3360      else if (strcmp(arg, "-q") == 0) quiet = 1;
3361      else if (strcmp(arg, "-b") == 0) debug = 1;
3362      else if (strcmp(arg, "-i") == 0) showinfo = 1;
3363      else if (strcmp(arg, "-d") == 0) showinfo = debug = 1;
3364      else if (strcmp(arg, "-M") == 0) default_find_match_limit = TRUE;
3365  #if !defined NODFA  #if !defined NODFA
3366    else if (strcmp(argv[op], "-dfa") == 0) all_use_dfa = 1;    else if (strcmp(arg, "-dfa") == 0) all_use_dfa = 1;
3367  #endif  #endif
3368    else if (strcmp(argv[op], "-o") == 0 && argc > 2 &&    else if (strcmp(arg, "-o") == 0 && argc > 2 &&
3369        ((size_offsets = get_value((pcre_uint8 *)argv[op+1], &endptr)),        ((size_offsets = get_value((pcre_uint8 *)argv[op+1], &endptr)),
3370          *endptr == 0))          *endptr == 0))
3371      {      {
3372      op++;      op++;
3373      argc--;      argc--;
3374      }      }
3375    else if (strcmp(argv[op], "-t") == 0 || strcmp(argv[op], "-tm") == 0)    else if (strcmp(arg, "-t") == 0 || strcmp(arg, "-tm") == 0)
3376      {      {
3377      int both = argv[op][2] == 0;      int both = arg[2] == 0;
3378      int temp;      int temp;
3379      if (argc > 2 && (temp = get_value((pcre_uint8 *)argv[op+1], &endptr),      if (argc > 2 && (temp = get_value((pcre_uint8 *)argv[op+1], &endptr),
3380                       *endptr == 0))                       *endptr == 0))
# Line 2279  while (argc > 1 && argv[op][0] == '-') Line 3386  while (argc > 1 && argv[op][0] == '-')
3386      else timeitm = LOOPREPEAT;      else timeitm = LOOPREPEAT;
3387      if (both) timeit = timeitm;      if (both) timeit = timeitm;
3388      }      }
3389    else if (strcmp(argv[op], "-S") == 0 && argc > 2 &&    else if (strcmp(arg, "-S") == 0 && argc > 2 &&
3390        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),
3391          *endptr == 0))          *endptr == 0))
3392      {      {
3393  #if defined(_WIN32) || defined(WIN32) || defined(__minix)  #if defined(_WIN32) || defined(WIN32) || defined(__minix) || defined(NATIVE_ZOS)
3394      printf("PCRE: -S not supported on this OS\n");      printf("PCRE: -S not supported on this OS\n");
3395      exit(1);      exit(1);
3396  #else  #else
# Line 2302  while (argc > 1 && argv[op][0] == '-') Line 3409  while (argc > 1 && argv[op][0] == '-')
3409  #endif  #endif
3410      }      }
3411  #if !defined NOPOSIX  #if !defined NOPOSIX
3412    else if (strcmp(argv[op], "-p") == 0) posix = 1;    else if (strcmp(arg, "-p") == 0) posix = 1;
3413  #endif  #endif
3414    else if (strcmp(argv[op], "-C") == 0)    else if (strcmp(arg, "-C") == 0)
3415      {      {
3416      int rc;      int rc;
3417      unsigned long int lrc;      unsigned long int lrc;
# Line 2316  while (argc > 1 && argv[op][0] == '-') Line 3423  while (argc > 1 && argv[op][0] == '-')
3423          (void)PCRE_CONFIG(PCRE_CONFIG_LINK_SIZE, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_LINK_SIZE, &rc);
3424          printf("%d\n", rc);          printf("%d\n", rc);
3425          yield = rc;          yield = rc;
         goto EXIT;  
3426          }          }
3427        if (strcmp(argv[op + 1], "pcre8") == 0)        else if (strcmp(argv[op + 1], "pcre8") == 0)
3428          {          {
3429  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
3430          printf("1\n");          printf("1\n");
# Line 2327  while (argc > 1 && argv[op][0] == '-') Line 3433  while (argc > 1 && argv[op][0] == '-')
3433          printf("0\n");          printf("0\n");
3434          yield = 0;          yield = 0;
3435  #endif  #endif
         goto EXIT;  
3436          }          }
3437        if (strcmp(argv[op + 1], "pcre16") == 0)        else if (strcmp(argv[op + 1], "pcre16") == 0)
3438          {          {
3439  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3440          printf("1\n");          printf("1\n");
# Line 2338  while (argc > 1 && argv[op][0] == '-') Line 3443  while (argc > 1 && argv[op][0] == '-')
3443          printf("0\n");          printf("0\n");
3444          yield = 0;          yield = 0;
3445  #endif  #endif
3446            }
3447          else if (strcmp(argv[op + 1], "pcre32") == 0)
3448            {
3449    #ifdef SUPPORT_PCRE32
3450            printf("1\n");
3451            yield = 1;
3452    #else
3453            printf("0\n");
3454            yield = 0;
3455    #endif
3456          goto EXIT;          goto EXIT;
3457          }          }
3458        if (strcmp(argv[op + 1], "utf") == 0)        if (strcmp(argv[op + 1], "utf") == 0)
3459          {          {
3460  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
3461          (void)pcre_config(PCRE_CONFIG_UTF8, &rc);          if (pcre_mode == PCRE8_MODE)
3462          printf("%d\n", rc);            (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
3463          yield = rc;  #endif
3464  #else  #ifdef SUPPORT_PCRE16
3465          (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);          if (pcre_mode == PCRE16_MODE)
3466              (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
3467    #endif
3468    #ifdef SUPPORT_PCRE32
3469            if (pcre_mode == PCRE32_MODE)
3470              (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
3471    #endif
3472          printf("%d\n", rc);          printf("%d\n", rc);
3473          yield = rc;          yield = rc;
 #endif  
3474          goto EXIT;          goto EXIT;
3475          }          }
3476        if (strcmp(argv[op + 1], "ucp") == 0)        else if (strcmp(argv[op + 1], "ucp") == 0)
3477          {          {
3478          (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
3479          printf("%d\n", rc);          printf("%d\n", rc);
3480          yield = rc;          yield = rc;
         goto EXIT;  
3481          }          }
3482        if (strcmp(argv[op + 1], "jit") == 0)        else if (strcmp(argv[op + 1], "jit") == 0)
3483          {          {
3484          (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);
3485          printf("%d\n", rc);          printf("%d\n", rc);
3486          yield = rc;          yield = rc;
         goto EXIT;  
3487          }          }
3488        if (strcmp(argv[op + 1], "newline") == 0)        else if (strcmp(argv[op + 1], "newline") == 0)
3489          {          {
3490          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3491          /* Note that these values are always the ASCII values, even          print_newline_config(rc, TRUE);
3492          in EBCDIC environments. CR is 13 and NL is 10. */          }
3493          printf("%s\n", (rc == 13)? "CR" :        else if (strcmp(argv[op + 1], "ebcdic") == 0)
3494            (rc == 10)? "LF" : (rc == (13<<8 | 10))? "CRLF" :          {
3495            (rc == -2)? "ANYCRLF" :  #ifdef EBCDIC
3496            (rc == -1)? "ANY" : "???");          printf("1\n");
3497          goto EXIT;          yield = 1;
3498    #else
3499            printf("0\n");
3500    #endif
3501            }
3502          else if (strcmp(argv[op + 1], "ebcdic-nl") == 0)
3503            {
3504    #ifdef EBCDIC
3505            printf("0x%02x\n", CHAR_LF);
3506    #else
3507            printf("0\n");
3508    #endif
3509            }
3510          else
3511            {
3512            printf("Unknown -C option: %s\n", argv[op + 1]);
3513          }          }
       printf("Unknown -C option: %s\n", argv[op + 1]);  
3514        goto EXIT;        goto EXIT;
3515        }        }
3516    
3517        /* No argument for -C: output all configuration information. */
3518    
3519      printf("PCRE version %s\n", version);      printf("PCRE version %s\n", version);
3520      printf("Compiled with\n");      printf("Compiled with\n");
3521    
3522    #ifdef EBCDIC
3523        printf("  EBCDIC code support: LF is 0x%02x\n", CHAR_LF);
3524    #endif
3525    
3526  /* 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
3527  are set, either both UTFs are supported or both are not supported. */  are set, either both UTFs are supported or both are not supported. */
3528    
3529  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE8
3530      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");  
3531      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
3532      printf("  %sUTF-8 support\n", rc? "" : "No ");        printf ("  %sUTF-8 support\n", rc ? "" : "No ");
3533  #else  #endif
3534      printf("  16-bit support only\n");  #ifdef SUPPORT_PCRE16
3535        printf("  16-bit support\n");
3536      (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);      (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
3537      printf("  %sUTF-16 support\n", rc? "" : "No ");      printf ("  %sUTF-16 support\n", rc ? "" : "No ");
3538    #endif
3539    #ifdef SUPPORT_PCRE32
3540        printf("  32-bit support\n");
3541        (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
3542        printf ("  %sUTF-32 support\n", rc ? "" : "No ");
3543  #endif  #endif
3544    
3545      (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 3554  are set, either both UTFs are supported
3554      else      else
3555        printf("  No just-in-time compiler support\n");        printf("  No just-in-time compiler support\n");
3556      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3557      /* 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" : "???");  
3558      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);
3559      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :
3560                                       "all Unicode newlines");                                       "all Unicode newlines");
# Line 2444  are set, either both UTFs are supported Line 3576  are set, either both UTFs are supported
3576      printf("\n");      printf("\n");
3577      goto EXIT;      goto EXIT;
3578      }      }
3579    else if (strcmp(argv[op], "-help") == 0 ||    else if (strcmp(arg, "-help") == 0 ||
3580             strcmp(argv[op], "--help") == 0)             strcmp(arg, "--help") == 0)
3581      {      {
3582      usage();      usage();
3583      goto EXIT;      goto EXIT;
3584      }      }
3585    else    else
3586      {      {
3587      printf("** Unknown or malformed option %s\n", argv[op]);      BAD_ARG:
3588        printf("** Unknown or malformed option %s\n", arg);
3589      usage();      usage();
3590      yield = 1;      yield = 1;
3591      goto EXIT;      goto EXIT;
# Line 2513  pcre16_stack_malloc = stack_malloc; Line 3646  pcre16_stack_malloc = stack_malloc;
3646  pcre16_stack_free = stack_free;  pcre16_stack_free = stack_free;
3647  #endif  #endif
3648    
3649    #ifdef SUPPORT_PCRE32
3650    pcre32_malloc = new_malloc;
3651    pcre32_free = new_free;
3652    pcre32_stack_malloc = stack_malloc;
3653    pcre32_stack_free = stack_free;
3654    #endif
3655    
3656  /* Heading line unless quiet, then prompt for first regex if stdin */  /* Heading line unless quiet, then prompt for first regex if stdin */
3657    
3658  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 3690  while (!done)
3690    int do_flip = 0;    int do_flip = 0;
3691    int erroroffset, len, delimiter, poffset;    int erroroffset, len, delimiter, poffset;
3692    
3693    #if !defined NODFA
3694      int dfa_matched = 0;
3695    #endif
3696    
3697    use_utf = 0;    use_utf = 0;
3698    debug_lengths = 1;    debug_lengths = 1;
3699    
# Line 2597  while (!done) Line 3741  while (!done)
3741        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];
3742    
3743      re = (pcre *)new_malloc(true_size);      re = (pcre *)new_malloc(true_size);
3744        if (re == NULL)
3745          {
3746          printf("** Failed to get %d bytes of memory for pcre object\n",
3747            (int)true_size);
3748          yield = 1;
3749          goto EXIT;
3750          }
3751      regex_gotten_store = first_gotten_store;      regex_gotten_store = first_gotten_store;
3752    
3753      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;
3754    
3755      magic = ((REAL_PCRE *)re)->magic_number;      magic = REAL_PCRE_MAGIC(re);
3756      if (magic != MAGIC_NUMBER)      if (magic != MAGIC_NUMBER)
3757        {        {
3758        if (swap_uint32(magic) == MAGIC_NUMBER)        if (swap_uint32(magic) == MAGIC_NUMBER)
# Line 2611  while (!done) Line 3762  while (!done)
3762        else        else
3763          {          {
3764          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);
3765            new_free(re);
3766          fclose(f);          fclose(f);
3767          continue;          continue;
3768          }          }
# Line 2640  while (!done) Line 3792  while (!done)
3792            {            {
3793            PCRE_FREE_STUDY(extra);            PCRE_FREE_STUDY(extra);
3794            }            }
3795          if (re != NULL) new_free(re);          new_free(re);
3796          fclose(f);          fclose(f);
3797          continue;          continue;
3798          }          }
# Line 2658  while (!done) Line 3810  while (!done)
3810          {          {
3811          /* Simulate the result of the function call below. */          /* Simulate the result of the function call below. */
3812          fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,          fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
3813            use_pcre16? "16" : "", PCRE_INFO_OPTIONS);            pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "",
3814          fprintf(outfile, "Running in %s-bit mode but pattern was compiled in "            PCRE_INFO_OPTIONS);
3815            "%s-bit mode\n", use_pcre16? "16":"8", use_pcre16? "8":"16");          fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
3816              "%d-bit mode\n", 8 * CHAR_SIZE,
3817              8 * (REAL_PCRE_FLAGS(re) & PCRE_MODE_MASK));
3818            new_free(re);
3819            fclose(f);
3820          continue;          continue;
3821          }          }
3822        }        }
3823    
3824      /* Need to know if UTF-8 for printing data strings. */      /* Need to know if UTF-8 for printing data strings. */
3825    
3826      if (new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options) < 0) continue;      if (new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options) < 0)
3827          {
3828          new_free(re);
3829          fclose(f);
3830          continue;
3831          }
3832      use_utf = (get_options & PCRE_UTF8) != 0;      use_utf = (get_options & PCRE_UTF8) != 0;
3833    
3834      fclose(f);      fclose(f);
# Line 2726  while (!done) Line 3887  while (!done)
3887    /* Look for options after final delimiter */    /* Look for options after final delimiter */
3888    
3889    options = 0;    options = 0;
3890    study_options = 0;    study_options = force_study_options;
3891    log_store = showstore;  /* default from command line */    log_store = showstore;  /* default from command line */
3892    
3893    while (*pp != 0)    while (*pp != 0)
# Line 2763  while (!done) Line 3924  while (!done)
3924  #endif  #endif
3925    
3926        case 'S':        case 'S':
3927        if (do_study == 0)        do_study = 1;
3928          for (;;)
3929          {          {
3930          do_study = 1;          switch (*pp++)
         if (*pp == '+')  
3931            {            {
3932            study_options |= PCRE_STUDY_JIT_COMPILE;            case 'S':
3933            pp++;            do_study = 0;
3934              no_force_study = 1;
3935              break;
3936    
3937              case '!':
3938              study_options |= PCRE_STUDY_EXTRA_NEEDED;
3939              break;
3940    
3941              case '+':
3942              if (*pp == '+')
3943                {
3944                verify_jit = TRUE;
3945                pp++;
3946                }
3947              if (*pp >= '1' && *pp <= '7')
3948                study_options |= jit_study_bits[*pp++ - '1'];
3949              else
3950                study_options |= jit_study_bits[6];
3951              break;
3952    
3953              case '-':
3954              study_options &= ~PCRE_STUDY_ALLJIT;
3955              break;
3956    
3957              default:
3958              pp--;
3959              goto ENDLOOP;
3960            }            }
3961          }          }
3962        else        ENDLOOP:
         {  
         do_study = 0;  
         no_force_study = 1;  
         }  
3963        break;        break;
3964    
3965        case 'U': options |= PCRE_UNGREEDY; break;        case 'U': options |= PCRE_UNGREEDY; break;
# Line 2895  while (!done) Line 4078  while (!done)
4078  #endif  /* !defined NOPOSIX */  #endif  /* !defined NOPOSIX */
4079    
4080      {      {
4081      /* In 16-bit mode, convert the input. */      /* In 16- or 32-bit mode, convert the input. */
4082    
4083  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
4084      if (use_pcre16)      if (pcre_mode == PCRE16_MODE)
4085        {        {
4086        switch(to16(FALSE, p, options & PCRE_UTF8, (int)strlen((char *)p)))        switch(to16(FALSE, p, options & PCRE_UTF8, (int)strlen((char *)p)))
4087          {          {
# Line 2924  while (!done) Line 4107  while (!done)
4107        }        }
4108  #endif  #endif
4109    
4110    #ifdef SUPPORT_PCRE32
4111        if (pcre_mode == PCRE32_MODE)
4112          {
4113          switch(to32(FALSE, p, options & PCRE_UTF32, (int)strlen((char *)p)))
4114            {
4115            case -1:
4116            fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "
4117              "converted to UTF-32\n");
4118            goto SKIP_DATA;
4119    
4120            case -2:
4121            fprintf(outfile, "**Failed: character value greater than 0x10ffff "
4122              "cannot be converted to UTF-32\n");
4123            goto SKIP_DATA;
4124    
4125            case -3:
4126            fprintf(outfile, "**Failed: character value is ill-formed UTF-32\n");
4127            goto SKIP_DATA;
4128    
4129            default:
4130            break;
4131            }
4132          p = (pcre_uint8 *)buffer32;
4133          }
4134    #endif
4135    
4136      /* Compile many times when timing */      /* Compile many times when timing */
4137    
4138      if (timeit > 0)      if (timeit > 0)
# Line 2981  while (!done) Line 4190  while (!done)
4190      /* Extract the size for possible writing before possibly flipping it,      /* Extract the size for possible writing before possibly flipping it,
4191      and remember the store that was got. */      and remember the store that was got. */
4192    
4193      true_size = ((REAL_PCRE *)re)->size;      true_size = REAL_PCRE_SIZE(re);
4194      regex_gotten_store = first_gotten_store;      regex_gotten_store = first_gotten_store;
4195    
4196      /* Output code size information if requested */      /* Output code size information if requested */
4197    
4198      if (log_store)      if (log_store)
4199          {
4200          int name_count, name_entry_size, real_pcre_size;
4201    
4202          new_info(re, NULL, PCRE_INFO_NAMECOUNT, &name_count);
4203          new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
4204    #ifdef SUPPORT_PCRE8
4205          if (REAL_PCRE_FLAGS(re) & PCRE_MODE8)
4206            real_pcre_size = sizeof(real_pcre);
4207    #endif
4208    #ifdef SUPPORT_PCRE16
4209          if (REAL_PCRE_FLAGS(re) & PCRE_MODE16)
4210            real_pcre_size = sizeof(real_pcre16);
4211    #endif
4212    #ifdef SUPPORT_PCRE32
4213          if (REAL_PCRE_FLAGS(re) & PCRE_MODE32)
4214            real_pcre_size = sizeof(real_pcre32);
4215    #endif
4216        fprintf(outfile, "Memory allocation (code space): %d\n",        fprintf(outfile, "Memory allocation (code space): %d\n",
4217          (int)(first_gotten_store -          (int)(first_gotten_store - real_pcre_size - name_count * name_entry_size));
4218                sizeof(REAL_PCRE) -        }
               ((REAL_PCRE *)re)->name_count * ((REAL_PCRE *)re)->name_entry_size));  
4219    
4220      /* 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
4221      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 4231  while (!done)
4231          clock_t start_time = clock();          clock_t start_time = clock();
4232          for (i = 0; i < timeit; i++)          for (i = 0; i < timeit; i++)
4233            {            {
4234            PCRE_STUDY(extra, re, study_options | force_study_options, &error);            PCRE_STUDY(extra, re, study_options, &error);
4235            }            }
4236          time_taken = clock() - start_time;          time_taken = clock() - start_time;
4237          if (extra != NULL)          if (extra != NULL)
# Line 3017  while (!done) Line 4242  while (!done)
4242            (((double)time_taken * 1000.0) / (double)timeit) /            (((double)time_taken * 1000.0) / (double)timeit) /
4243              (double)CLOCKS_PER_SEC);              (double)CLOCKS_PER_SEC);
4244          }          }
4245        PCRE_STUDY(extra, re, study_options | force_study_options, &error);        PCRE_STUDY(extra, re, study_options, &error);
4246        if (error != NULL)        if (error != NULL)
4247          fprintf(outfile, "Failed to study: %s\n", error);          fprintf(outfile, "Failed to study: %s\n", error);
4248        else if (extra != NULL)        else if (extra != NULL)
# Line 3061  while (!done) Line 4286  while (!done)
4286      if (do_showinfo)      if (do_showinfo)
4287        {        {
4288        unsigned long int all_options;        unsigned long int all_options;
4289        int count, backrefmax, first_char, need_char, okpartial, jchanged,        pcre_uint32 first_char, need_char;
4290          hascrorlf;        int count, backrefmax, first_char_set, need_char_set, okpartial, jchanged,
4291            hascrorlf, maxlookbehind;
4292        int nameentrysize, namecount;        int nameentrysize, namecount;
4293        const pcre_uint8 *nametable;        const pcre_uint8 *nametable;
4294    
4295        if (new_info(re, NULL, PCRE_INFO_SIZE, &size) +        if (new_info(re, NULL, PCRE_INFO_SIZE, &size) +
4296            new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) +            new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) +
4297            new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax) +            new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax) +
4298            new_info(re, NULL, PCRE_INFO_FIRSTBYTE, &first_char) +            new_info(re, NULL, PCRE_INFO_FIRSTCHARACTER, &first_char) +
4299            new_info(re, NULL, PCRE_INFO_LASTLITERAL, &need_char) +            new_info(re, NULL, PCRE_INFO_FIRSTCHARACTERFLAGS, &first_char_set) +
4300              new_info(re, NULL, PCRE_INFO_REQUIREDCHAR, &need_char) +
4301              new_info(re, NULL, PCRE_INFO_REQUIREDCHARFLAGS, &need_char_set) +
4302            new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize) +            new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize) +
4303            new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount) +            new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount) +
4304            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +
4305            new_info(re, NULL, PCRE_INFO_OKPARTIAL, &okpartial) +            new_info(re, NULL, PCRE_INFO_OKPARTIAL, &okpartial) +
4306            new_info(re, NULL, PCRE_INFO_JCHANGED, &jchanged) +            new_info(re, NULL, PCRE_INFO_JCHANGED, &jchanged) +
4307            new_info(re, NULL, PCRE_INFO_HASCRORLF, &hascrorlf)            new_info(re, NULL, PCRE_INFO_HASCRORLF, &hascrorlf) +
4308              new_info(re, NULL, PCRE_INFO_MAXLOOKBEHIND, &maxlookbehind)
4309            != 0)            != 0)
4310          goto SKIP_DATA;          goto SKIP_DATA;
4311    
# Line 3093  while (!done) Line 4322  while (!done)
4322          fprintf(outfile, "Named capturing subpatterns:\n");          fprintf(outfile, "Named capturing subpatterns:\n");
4323          while (namecount-- > 0)          while (namecount-- > 0)
4324            {            {
4325  #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  
4326            int length = (int)STRLEN(nametable + imm2_size);            int length = (int)STRLEN(nametable + imm2_size);
4327            fprintf(outfile, "  ");            fprintf(outfile, "  ");
4328            PCHARSV(nametable, imm2_size, length, outfile);            PCHARSV(nametable, imm2_size, length, outfile);
4329            while (length++ < nameentrysize - imm2_size) putc(' ', outfile);            while (length++ < nameentrysize - imm2_size) putc(' ', outfile);
4330  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE32
4331            fprintf(outfile, "%3d\n", use_pcre16?            if (pcre_mode == PCRE32_MODE)
4332               (int)(((PCRE_SPTR16)nametable)[0])              fprintf(outfile, "%3d\n", (int)(((PCRE_SPTR32)nametable)[0]));
4333              :((int)nametable[0] << 8) | (int)nametable[1]);  #endif
4334            nametable += nameentrysize * (use_pcre16 ? 2 : 1);  #ifdef SUPPORT_PCRE16
4335  #else            if (pcre_mode == PCRE16_MODE)
4336            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;  
4337  #endif  #endif
4338    #ifdef SUPPORT_PCRE8
4339              if (pcre_mode == PCRE8_MODE)
4340                fprintf(outfile, "%3d\n", ((int)nametable[0] << 8) | (int)nametable[1]);
4341  #endif  #endif
4342              nametable += nameentrysize * CHAR_SIZE;
4343            }            }
4344          }          }
4345    
4346        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");
4347        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");
4348    
4349        all_options = ((REAL_PCRE *)re)->options;        all_options = REAL_PCRE_OPTIONS(re);
4350        if (do_flip) all_options = swap_uint32(all_options);        if (do_flip) all_options = swap_uint32(all_options);
4351    
4352        if (get_options == 0) fprintf(outfile, "No options\n");        if (get_options == 0) fprintf(outfile, "No options\n");
# Line 3172  while (!done) Line 4397  while (!done)
4397          break;          break;
4398          }          }
4399    
4400        if (first_char == -1)        if (first_char_set == 2)
4401          {          {
4402          fprintf(outfile, "First char at start or follows newline\n");          fprintf(outfile, "First char at start or follows newline\n");
4403          }          }
4404        else if (first_char < 0)        else if (first_char_set == 1)
         {  
         fprintf(outfile, "No first char\n");  
         }  
       else  
4405          {          {
4406          const char *caseless =          const char *caseless =
4407            ((((REAL_PCRE *)re)->flags & PCRE_FCH_CASELESS) == 0)?            ((REAL_PCRE_FLAGS(re) & PCRE_FCH_CASELESS) == 0)?
4408            "" : " (caseless)";            "" : " (caseless)";
4409    
4410          if (PRINTOK(first_char))          if (PRINTOK(first_char))
# Line 3195  while (!done) Line 4416  while (!done)
4416            fprintf(outfile, "%s\n", caseless);            fprintf(outfile, "%s\n", caseless);
4417            }            }
4418          }          }
4419          else
4420            {
4421            fprintf(outfile, "No first char\n");
4422            }
4423    
4424        if (need_char < 0)        if (need_char_set == 0)
4425          {          {
4426          fprintf(outfile, "No need char\n");          fprintf(outfile, "No need char\n");
4427          }          }
4428        else        else
4429          {          {
4430          const char *caseless =          const char *caseless =
4431            ((((REAL_PCRE *)re)->flags & PCRE_RCH_CASELESS) == 0)?            ((REAL_PCRE_FLAGS(re) & PCRE_RCH_CASELESS) == 0)?
4432            "" : " (caseless)";            "" : " (caseless)";
4433    
4434          if (PRINTOK(need_char))          if (PRINTOK(need_char))
# Line 3216  while (!done) Line 4441  while (!done)
4441            }            }
4442          }          }
4443    
4444          if (maxlookbehind > 0)
4445            fprintf(outfile, "Max lookbehind = %d\n", maxlookbehind);
4446    
4447        /* 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
4448        value, but it varies, depending on the computer architecture, and        value, but it varies, depending on the computer architecture, and
4449        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 4501  while (!done)
4501    
4502          /* 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. */
4503    
4504          if ((study_options & PCRE_STUDY_JIT_COMPILE) != 0)          if ((study_options & PCRE_STUDY_ALLJIT) != 0 &&
4505                (force_study_options & PCRE_STUDY_ALLJIT) == 0)
4506            {            {
4507            int jit;            int jit;
4508            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 4589  while (!done)
4589    
4590    for (;;)    for (;;)
4591      {      {
4592      pcre_uint8 *q;  #ifdef SUPPORT_PCRE8
4593        pcre_uint8 *q8;
4594    #endif
4595    #ifdef SUPPORT_PCRE16
4596        pcre_uint16 *q16;
4597    #endif
4598    #ifdef SUPPORT_PCRE32
4599        pcre_uint32 *q32;
4600    #endif
4601      pcre_uint8 *bptr;      pcre_uint8 *bptr;
4602      int *use_offsets = offsets;      int *use_offsets = offsets;
4603      int use_size_offsets = size_offsets;      int use_size_offsets = size_offsets;
4604      int callout_data = 0;      int callout_data = 0;
4605      int callout_data_set = 0;      int callout_data_set = 0;
4606      int count, c;      int count;
4607        pcre_uint32 c;
4608      int copystrings = 0;      int copystrings = 0;
4609      int find_match_limit = default_find_match_limit;      int find_match_limit = default_find_match_limit;
4610      int getstrings = 0;      int getstrings = 0;
# Line 3380  while (!done) Line 4618  while (!done)
4618      *copynames = 0;      *copynames = 0;
4619      *getnames = 0;      *getnames = 0;
4620    
4621    #ifdef SUPPORT_PCRE32
4622        cn32ptr = copynames;
4623        gn32ptr = getnames;
4624    #endif
4625  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
4626      cn16ptr = copynames;      cn16ptr = copynames16;
4627      gn16ptr = getnames;      gn16ptr = getnames16;
4628  #endif  #endif
4629  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
4630      cn8ptr = copynames8;      cn8ptr = copynames8;
# Line 3427  while (!done) Line 4669  while (!done)
4669      p = buffer;      p = buffer;
4670      while (isspace(*p)) p++;      while (isspace(*p)) p++;
4671    
4672      bptr = q = dbuffer;  #ifndef NOUTF
4673        /* Check that the data is well-formed UTF-8 if we're in UTF mode. To create
4674           invalid input to pcre_exec, you must use \x?? or \x{} sequences. */
4675        if (use_utf)
4676          {
4677          pcre_uint8 *q;
4678          pcre_uint32 cc;
4679          int n = 1;
4680    
4681          for (q = p; n > 0 && *q; q += n) n = utf82ord(q, &cc);
4682          if (n <= 0)
4683            {
4684            fprintf(outfile, "**Failed: invalid UTF-8 string cannot be used as input in UTF mode\n");
4685            goto NEXT_DATA;
4686            }
4687          }
4688    #endif
4689    
4690        /* Allocate a buffer to hold the data line. len+1 is an upper bound on
4691           the number of pcre_uchar units that will be needed. */
4692        if (dbuffer == NULL || (size_t)len >= dbuffer_size)
4693          {
4694          dbuffer_size *= 2;
4695          dbuffer = (pcre_uint8 *)realloc(dbuffer, dbuffer_size * CHAR_SIZE);
4696          if (dbuffer == NULL)
4697            {
4698            fprintf(stderr, "pcretest: malloc(%d) failed\n", dbuffer_size);
4699            exit(1);
4700            }
4701          }
4702    
4703    #ifdef SUPPORT_PCRE8
4704        q8 = (pcre_uint8 *) dbuffer;
4705    #endif
4706    #ifdef SUPPORT_PCRE16
4707        q16 = (pcre_uint16 *) dbuffer;
4708    #endif
4709    #ifdef SUPPORT_PCRE32
4710        q32 = (pcre_uint32 *) dbuffer;
4711    #endif
4712    
4713      while ((c = *p++) != 0)      while ((c = *p++) != 0)
4714        {        {
4715        int i = 0;        int i = 0;
# Line 3436  while (!done) Line 4718  while (!done)
4718        /* 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.
4719        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,
4720        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
4721        16-bit mode. */        16-bit or 32-bit mode. */
4722    
4723        if (c != '\\')        if (c != '\\')
4724          {          {
4725          if (use_utf)  #ifndef NOUTF
4726            {          if (use_utf && HASUTF8EXTRALEN(c)) { GETUTF8INC(c, p); }
4727            *q++ = c;  #endif
           continue;  
           }  
4728          }          }
4729    
4730        /* Handle backslash escapes */        /* Handle backslash escapes */
# Line 3497  while (!done) Line 4777  while (!done)
4777          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
4778          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.
4779          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
4780          UTF-8 when running in 16-bit mode. */          UTF-8 when running in 16/32-bit mode. */
4781    
4782          c = 0;          c = 0;
4783          while (i++ < 2 && isxdigit(*p))          while (i++ < 2 && isxdigit(*p))
# Line 3505  while (!done) Line 4785  while (!done)
4785            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);
4786            p++;            p++;
4787            }            }
4788          if (use_utf)  #if !defined NOUTF && defined SUPPORT_PCRE8
4789            if (use_utf && (pcre_mode == PCRE8_MODE))
4790            {            {
4791            *q++ = c;            *q8++ = c;
4792            continue;            continue;
4793            }            }
4794    #endif
4795          break;          break;
4796    
4797          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 4824  while (!done)
4824            }            }
4825          else if (isalnum(*p))          else if (isalnum(*p))
4826            {            {
4827            READ_CAPTURE_NAME(p, &cn8ptr, &cn16ptr, re);            READ_CAPTURE_NAME(p, &cn8ptr, &cn16ptr, &cn32ptr, re);
4828            }            }
4829          else if (*p == '+')          else if (*p == '+')
4830            {            {
# Line 3605  while (!done) Line 4887  while (!done)
4887            }            }
4888          else if (isalnum(*p))          else if (isalnum(*p))
4889            {            {
4890            READ_CAPTURE_NAME(p, &gn8ptr, &gn16ptr, re);            READ_CAPTURE_NAME(p, &gn8ptr, &gn16ptr, &gn32ptr, re);
4891            }            }
4892          continue;          continue;
4893    
# Line 3653  while (!done) Line 4935  while (!done)
4935            }            }
4936          use_size_offsets = n;          use_size_offsets = n;
4937          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 */
4938              else use_offsets = offsets + size_offsets_max - n;  /* To catch overruns */
4939          continue;          continue;
4940    
4941          case 'P':          case 'P':
# Line 3715  while (!done) Line 4998  while (!done)
4998          }          }
4999    
5000        /* 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. In
5001        16-bit mode, we always convert characters to UTF-8 so that values greater        16-bit or 32-bit mode, we always convert characters to UTF-8 so that
5002        than 255 can be passed to non-UTF 16-bit strings. In 8-bit mode we        values greater than 255 can be passed to non-UTF 16- or 32-bit strings.
5003        convert to UTF-8 if we are in UTF mode. Values greater than 127 in UTF        In 8-bit       mode we convert to UTF-8 if we are in UTF mode. Values greater
5004        mode must have come from \x{...} or octal constructs because values from        than 127       in UTF mode must have come from \x{...} or octal constructs
5005        \x.. get this far only in non-UTF mode. */        because values from \x.. get this far only in non-UTF mode. */
5006    
5007  #if !defined NOUTF || defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE8
5008        if (use_pcre16 || use_utf)        if (pcre_mode == PCRE8_MODE)
5009          {          {
5010          pcre_uint8 buff8[8];  #ifndef NOUTF
5011          int ii, utn;          if (use_utf)
5012          utn = ord2utf8(c, buff8);            {
5013          for (ii = 0; ii < utn; ii++) *q++ = buff8[ii];            q8 += ord2utf8(c, q8);
5014              }
5015            else
5016    #endif
5017              {
5018              if (c > 0xffu)
5019                {
5020                fprintf(outfile, "** Character \\x{%x} is greater than 255 "
5021                  "and UTF-8 mode is not enabled.\n", c);
5022                fprintf(outfile, "** Truncation will probably give the wrong "
5023                  "result.\n");
5024                }
5025    
5026              *q8++ = c;
5027              }
5028          }          }
       else  
5029  #endif  #endif
5030    #ifdef SUPPORT_PCRE16
5031          if (pcre_mode == PCRE16_MODE)
5032          {          {
5033          if (c > 255)  #ifndef NOUTF
5034            if (use_utf)
5035              {
5036              if (c > 0x10ffffu)
5037                {
5038                fprintf(outfile, "**Failed: character value greater than 0x10ffff "
5039                  "cannot be converted to UTF-16\n");
5040                goto NEXT_DATA;
5041                }
5042              else if (c >= 0x10000u)
5043                {
5044                c-= 0x10000u;
5045                *q16++ = 0xD800 | (c >> 10);
5046                *q16++ = 0xDC00 | (c & 0x3ff);
5047                }
5048              else
5049                *q16++ = c;
5050              }
5051            else
5052    #endif
5053            {            {
5054            fprintf(outfile, "** Character \\x{%x} is greater than 255 "            if (c > 0xffffu)
5055              "and UTF-8 mode is not enabled.\n", c);              {
5056            fprintf(outfile, "** Truncation will probably give the wrong "              fprintf(outfile, "** Character value is greater than 0xffff "
5057              "result.\n");                "and UTF-16 mode is not enabled.\n");
5058                fprintf(outfile, "** Truncation will probably give the wrong "
5059                  "result.\n");
5060                }
5061    
5062              *q16++ = c;
5063            }            }
         *q++ = c;  
5064          }          }
5065    #endif
5066    #ifdef SUPPORT_PCRE32
5067          if (pcre_mode == PCRE32_MODE)
5068            {
5069            *q32++ = c;
5070            }
5071    #endif
5072    
5073        }        }
5074    
5075      /* Reached end of subject string */      /* Reached end of subject string */
5076    
5077      *q = 0;  #ifdef SUPPORT_PCRE8
5078      len = (int)(q - dbuffer);      if (pcre_mode == PCRE8_MODE)
5079        {
5080          *q8 = 0;
5081          len = (int)(q8 - (pcre_uint8 *)dbuffer);
5082        }
5083    #endif
5084    #ifdef SUPPORT_PCRE16
5085        if (pcre_mode == PCRE16_MODE)
5086        {
5087          *q16 = 0;
5088          len = (int)(q16 - (pcre_uint16 *)dbuffer);
5089        }
5090    #endif
5091    #ifdef SUPPORT_PCRE32
5092        if (pcre_mode == PCRE32_MODE)
5093        {
5094          *q32 = 0;
5095          len = (int)(q32 - (pcre_uint32 *)dbuffer);
5096        }
5097    #endif
5098    
5099    #if defined SUPPORT_UTF && defined SUPPORT_PCRE32
5100        /* If we're requsted to test UTF-32 masking of high bits, change the data
5101        string to have high bits set, unless the string is invalid UTF-32.
5102        Since the JIT doesn't support this yet, only do it when not JITing. */
5103        if (use_utf && mask_utf32 && (study_options & PCRE_STUDY_ALLJIT) == 0 &&
5104            valid_utf32((pcre_uint32 *)dbuffer, len))
5105          {
5106          for (q32 = (pcre_uint32 *)dbuffer; *q32; q32++)
5107            *q32 |= ~(pcre_uint32)UTF32_MASK;
5108    
5109          /* Need to pass NO_UTF32_CHECK so the high bits are allowed */
5110          options |= PCRE_NO_UTF32_CHECK;
5111          }
5112    #endif
5113    
5114      /* 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
5115      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
5116      we are using the POSIX interface, we must include the terminating zero. */      we are using the POSIX interface, we must include the terminating zero. */
5117    
5118        bptr = dbuffer;
5119    
5120  #if !defined NOPOSIX  #if !defined NOPOSIX
5121      if (posix || do_posix)      if (posix || do_posix)
5122        {        {
5123        memmove(bptr + buffer_size - len - 1, bptr, len + 1);        memmove(bptr + dbuffer_size - len - 1, bptr, len + 1);
5124        bptr += buffer_size - len - 1;        bptr += dbuffer_size - len - 1;
5125        }        }
5126      else      else
5127  #endif  #endif
5128        {        {
5129        memmove(bptr + buffer_size - len, bptr, len);        bptr = memmove(bptr + (dbuffer_size - len) * CHAR_SIZE, bptr, len * CHAR_SIZE);
       bptr += buffer_size - len;  
5130        }        }
5131    
5132      if ((all_use_dfa || use_dfa) && find_match_limit)      if ((all_use_dfa || use_dfa) && find_match_limit)
# Line 3793  while (!done) Line 5157  while (!done)
5157          (void)regerror(rc, &preg, (char *)buffer, buffer_size);          (void)regerror(rc, &preg, (char *)buffer, buffer_size);
5158          fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);          fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);
5159          }          }
5160        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)  
5161          {          {
5162          fprintf(outfile, "Matched with REG_NOSUB\n");          fprintf(outfile, "Matched with REG_NOSUB\n");
5163          }          }
# Line 3827  while (!done) Line 5190  while (!done)
5190    
5191      /* Handle matching via the native interface - repeats for /g and /G */      /* Handle matching via the native interface - repeats for /g and /G */
5192    
5193  #ifdef SUPPORT_PCRE16      /* Ensure that there is a JIT callback if we want to verify that JIT was
5194      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;  
5195    
5196          default:      if (verify_jit && jit_stack == NULL && extra != NULL)
5197          break;         { PCRE_ASSIGN_JIT_STACK(extra, jit_callback, jit_stack); }
         }  
       bptr = (pcre_uint8 *)buffer16;  
       }  
 #endif  
5198    
5199      for (;; gmatched++)    /* Loop for /g or /G */      for (;; gmatched++)    /* Loop for /g or /G */
5200        {        {
5201        markptr = NULL;        markptr = NULL;
5202          jit_was_used = FALSE;
5203    
5204        if (timeitm > 0)        if (timeitm > 0)
5205          {          {
# Line 3868  while (!done) Line 5210  while (!done)
5210  #if !defined NODFA  #if !defined NODFA
5211          if (all_use_dfa || use_dfa)          if (all_use_dfa || use_dfa)
5212            {            {
5213            int workspace[1000];            if ((options & PCRE_DFA_RESTART) != 0)
5214                {
5215                fprintf(outfile, "Timing DFA restarts is not supported\n");
5216                break;
5217                }
5218              if (dfa_workspace == NULL)
5219                dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
5220            for (i = 0; i < timeitm; i++)            for (i = 0; i < timeitm; i++)
5221              {              {
5222              PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,              PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
5223                (options | g_notempty), use_offsets, use_size_offsets, workspace,                (options | g_notempty), use_offsets, use_size_offsets,
5224                (sizeof(workspace)/sizeof(int)));                dfa_workspace, DFA_WS_DIMENSION);
5225              }              }
5226            }            }
5227          else          else
# Line 3899  while (!done) Line 5247  while (!done)
5247    
5248        if (find_match_limit)        if (find_match_limit)
5249          {          {
5250          if (extra == NULL)          if (extra != NULL) { PCRE_FREE_STUDY(extra); }
5251            {          extra = (pcre_extra *)malloc(sizeof(pcre_extra));
5252            extra = (pcre_extra *)malloc(sizeof(pcre_extra));          extra->flags = 0;
           extra->flags = 0;  
           }  
         else extra->flags &= ~PCRE_EXTRA_EXECUTABLE_JIT;  
5253    
5254          (void)check_match_limit(re, extra, bptr, len, start_offset,          (void)check_match_limit(re, extra, bptr, len, start_offset,
5255            options|g_notempty, use_offsets, use_size_offsets,            options|g_notempty, use_offsets, use_size_offsets,
# Line 3939  while (!done) Line 5284  while (!done)
5284  #if !defined NODFA  #if !defined NODFA
5285        else if (all_use_dfa || use_dfa)        else if (all_use_dfa || use_dfa)
5286          {          {
5287          int workspace[1000];          if (dfa_workspace == NULL)
5288              dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
5289            if (dfa_matched++ == 0)
5290              dfa_workspace[0] = -1;  /* To catch bad restart */
5291          PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,          PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
5292            (options | g_notempty), use_offsets, use_size_offsets, workspace,            (options | g_notempty), use_offsets, use_size_offsets, dfa_workspace,
5293            (sizeof(workspace)/sizeof(int)));            DFA_WS_DIMENSION);
5294          if (count == 0)          if (count == 0)
5295            {            {
5296            fprintf(outfile, "Matched, but too many subsidiary matches\n");            fprintf(outfile, "Matched, but too many subsidiary matches\n");
# Line 4019  while (!done) Line 5367  while (!done)
5367              fprintf(outfile, "%2d: ", i/2);              fprintf(outfile, "%2d: ", i/2);
5368              PCHARSV(bptr, use_offsets[i],              PCHARSV(bptr, use_offsets[i],
5369                use_offsets[i+1] - use_offsets[i], outfile);                use_offsets[i+1] - use_offsets[i], outfile);
5370                if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
5371              fprintf(outfile, "\n");              fprintf(outfile, "\n");
5372              if (do_showcaprest || (i == 0 && do_showrest))              if (do_showcaprest || (i == 0 && do_showrest))
5373                {                {
# Line 4062  while (!done) Line 5411  while (!done)
5411            int rc;            int rc;
5412            char copybuffer[256];            char copybuffer[256];
5413    
5414            if (use_pcre16)  #ifdef SUPPORT_PCRE32
5415              if (pcre_mode == PCRE32_MODE)
5416                {
5417                if (*(pcre_uint32 *)cnptr == 0) break;
5418                }
5419    #endif
5420    #ifdef SUPPORT_PCRE16
5421              if (pcre_mode == PCRE16_MODE)
5422              {              {
5423              if (*(pcre_uint16 *)cnptr == 0) break;              if (*(pcre_uint16 *)cnptr == 0) break;
5424              }              }
5425            else  #endif
5426    #ifdef SUPPORT_PCRE8
5427              if (pcre_mode == PCRE8_MODE)
5428              {              {
5429              if (*(pcre_uint8 *)cnptr == 0) break;              if (*(pcre_uint8 *)cnptr == 0) break;
5430              }              }
5431    #endif
5432    
5433            PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,            PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,
5434              cnptr, copybuffer, sizeof(copybuffer));              cnptr, copybuffer, sizeof(copybuffer));
# Line 4117  while (!done) Line 5476  while (!done)
5476            int rc;            int rc;
5477            const char *substring;            const char *substring;
5478    
5479            if (use_pcre16)  #ifdef SUPPORT_PCRE32
5480              if (pcre_mode == PCRE32_MODE)
5481                {
5482                if (*(pcre_uint32 *)gnptr == 0) break;
5483                }
5484    #endif
5485    #ifdef SUPPORT_PCRE16
5486              if (pcre_mode == PCRE16_MODE)
5487              {              {
5488              if (*(pcre_uint16 *)gnptr == 0) break;              if (*(pcre_uint16 *)gnptr == 0) break;
5489              }              }
5490            else  #endif
5491    #ifdef SUPPORT_PCRE8
5492              if (pcre_mode == PCRE8_MODE)
5493              {              {
5494              if (*(pcre_uint8 *)gnptr == 0) break;              if (*(pcre_uint8 *)gnptr == 0) break;
5495              }              }
5496    #endif
5497    
5498            PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,            PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,
5499              gnptr, &substring);              gnptr, &substring);
# Line 4185  while (!done) Line 5554  while (!done)
5554            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],
5555              outfile);              outfile);
5556            }            }
5557            if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
5558          fprintf(outfile, "\n");          fprintf(outfile, "\n");
5559          break;  /* Out of the /g loop */          break;  /* Out of the /g loop */
5560          }          }
# Line 4210  while (!done) Line 5580  while (!done)
5580          if (g_notempty != 0)          if (g_notempty != 0)
5581            {            {
5582            int onechar = 1;            int onechar = 1;
5583            unsigned int obits = ((REAL_PCRE *)re)->options;            unsigned int obits = REAL_PCRE_OPTIONS(re);
5584            use_offsets[0] = start_offset;            use_offsets[0] = start_offset;
5585            if ((obits & PCRE_NEWLINE_BITS) == 0)            if ((obits & PCRE_NEWLINE_BITS) == 0)
5586              {              {
# Line 4228  while (!done) Line 5598  while (!done)
5598                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||
5599                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)
5600                &&                &&
5601                start_offset < len - 1 &&                start_offset < len - 1 && (
5602  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE8
5603                (use_pcre16?                (pcre_mode == PCRE8_MODE &&
5604                     ((PCRE_SPTR16)bptr)[start_offset] == '\r'                 bptr[start_offset] == '\r' &&
5605                  && ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n'                 bptr[start_offset + 1] == '\n') ||
5606                :  #endif
5607                     bptr[start_offset] == '\r'  #ifdef SUPPORT_PCRE16
5608                  && bptr[start_offset + 1] == '\n')                (pcre_mode == PCRE16_MODE &&
5609  #elif defined SUPPORT_PCRE16                 ((PCRE_SPTR16)bptr)[start_offset] == '\r' &&
5610                   ((PCRE_SPTR16)bptr)[start_offset] == '\r'                 ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n') ||
5611                && ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n'  #endif
5612  #else  #ifdef SUPPORT_PCRE32
5613                   bptr[start_offset] == '\r'                (pcre_mode == PCRE32_MODE &&
5614                && bptr[start_offset + 1] == '\n'                 ((PCRE_SPTR32)bptr)[start_offset] == '\r' &&
5615                   ((PCRE_SPTR32)bptr)[start_offset + 1] == '\n') ||
5616  #endif  #endif
5617                )                0))
5618              onechar++;              onechar++;
5619            else if (use_utf)            else if (use_utf)
5620              {              {
# Line 4264  while (!done) Line 5635  while (!done)
5635                {                {
5636                if (markptr == NULL)                if (markptr == NULL)
5637                  {                  {
5638                  fprintf(outfile, "No match\n");                  fprintf(outfile, "No match");
5639                  }                  }
5640                else                else
5641                  {                  {
5642                  fprintf(outfile, "No match, mark = ");                  fprintf(outfile, "No match, mark = ");
5643                  PCHARSV(markptr, 0, -1, outfile);                  PCHARSV(markptr, 0, -1, outfile);
                 putc('\n', outfile);  
5644                  }                  }
5645                  if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
5646                  putc('\n', outfile);
5647                }                }
5648              break;              break;
5649    
5650              case PCRE_ERROR_BADUTF8:              case PCRE_ERROR_BADUTF8:
5651              case PCRE_ERROR_SHORTUTF8:              case PCRE_ERROR_SHORTUTF8:
5652              fprintf(outfile, "Error %d (%s UTF-%s string)", count,              fprintf(outfile, "Error %d (%s UTF-%d string)", count,
5653                (count == PCRE_ERROR_BADUTF8)? "bad" : "short",                (count == PCRE_ERROR_BADUTF8)? "bad" : "short",
5654                use_pcre16? "16" : "8");                8 * CHAR_SIZE);
5655              if (use_size_offsets >= 2)              if (use_size_offsets >= 2)
5656                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],
5657                  use_offsets[1]);                  use_offsets[1]);
# Line 4287  while (!done) Line 5659  while (!done)
5659              break;              break;
5660    
5661              case PCRE_ERROR_BADUTF8_OFFSET:              case PCRE_ERROR_BADUTF8_OFFSET:
5662              fprintf(outfile, "Error %d (bad UTF-%s offset)\n", count,              fprintf(outfile, "Error %d (bad UTF-%d offset)\n", count,
5663                use_pcre16? "16" : "8");                8 * CHAR_SIZE);
5664              break;              break;
5665    
5666              default:              default:
5667              if (count < 0 &&              if (count < 0 &&
5668                  (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))                  (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))
5669                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);
5670              else              else
# Line 4378  free(offsets); Line 5750  free(offsets);
5750  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
5751  if (buffer16 != NULL) free(buffer16);  if (buffer16 != NULL) free(buffer16);
5752  #endif  #endif
5753    #ifdef SUPPORT_PCRE32
5754    if (buffer32 != NULL) free(buffer32);
5755    #endif
5756    
5757    #if !defined NODFA
5758    if (dfa_workspace != NULL)
5759      free(dfa_workspace);
5760    #endif
5761    
5762  return yield;  return yield;
5763  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.5