/[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 860 by zherczeg, Mon Jan 9 20:12:58 2012 UTC revision 1087 by chpe, Tue Oct 16 15:55:38 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
125    
126  /* We have to include pcre_internal.h because we need the internal info for  /* We have to include pcre_internal.h because we need the internal info for
127  displaying the results of pcre_study() and we also need to know about the  displaying the results of pcre_study() and we also need to know about the
# Line 117  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 135  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
 #undef PRIV  
 #define PRIV(name) name  
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 160  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 184  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 206  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 288  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 367  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, f)
403    
404    #define PCHARSV32(p, offset, len, f) \
405      (void)pchars32((PCRE_SPTR32)(p) + offset, len, 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    #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  /* ----- Both modes are supported; a runtime test is needed, except for  /* ----- Both modes are 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) + defined (SUPPORT_PCRE32)) >= 2
498    
499  #define CHAR_SIZE (use_pcre16? 2:1)  #define CHAR_SIZE (1 << pcre_mode)
500    
501  #define PCHARS(lv, p, offset, len, f) \  #define PCHARS(lv, p, offset, len, f) \
502    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
503        PCHARS32(lv, p, offset, len, f); \
504      else if (pcre_mode == PCRE16_MODE) \
505      PCHARS16(lv, p, offset, len, f); \      PCHARS16(lv, p, offset, len, f); \
506    else \    else \
507      PCHARS8(lv, p, offset, len, f)      PCHARS8(lv, p, offset, len, f)
508    
509  #define PCHARSV(p, offset, len, f) \  #define PCHARSV(p, offset, len, f) \
510    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
511        PCHARSV32(p, offset, len, f); \
512      else if (pcre_mode == PCRE16_MODE) \
513      PCHARSV16(p, offset, len, f); \      PCHARSV16(p, offset, len, f); \
514    else \    else \
515      PCHARSV8(p, offset, len, f)      PCHARSV8(p, offset, len, f)
516    
517  #define READ_CAPTURE_NAME(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME(p, cn8, cn16, cn32, re) \
518    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
519      READ_CAPTURE_NAME16(p, cn8, cn16, re); \      READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re); \
520      else if (pcre_mode == PCRE16_MODE) \
521        READ_CAPTURE_NAME16(p, cn8, cn16, cn32, re); \
522    else \    else \
523      READ_CAPTURE_NAME8(p, cn8, cn16, re)      READ_CAPTURE_NAME8(p, cn8, cn16, cn32, re)
524    
525  #define SET_PCRE_CALLOUT(callout) \  #define SET_PCRE_CALLOUT(callout) \
526    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
527        SET_PCRE_CALLOUT32(callout); \
528      else if (pcre_mode == PCRE16_MODE) \
529      SET_PCRE_CALLOUT16(callout); \      SET_PCRE_CALLOUT16(callout); \
530    else \    else \
531      SET_PCRE_CALLOUT8(callout)      SET_PCRE_CALLOUT8(callout)
532    
533  #define STRLEN(p) (use_pcre16? STRLEN16(p) : STRLEN8(p))  #define STRLEN(p) (pcre_mode == PCRE32_MODE ? STRLEN32(p) : pcre_mode == PCRE16_MODE ? STRLEN16(p) : STRLEN8(p))
534    
535  #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \  #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
536    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
537        PCRE_ASSIGN_JIT_STACK32(extra, callback, userdata); \
538      else if (pcre_mode == PCRE16_MODE) \
539      PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata); \      PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata); \
540    else \    else \
541      PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata)      PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata)
542    
543  #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \  #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
544    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
545        PCRE_COMPILE32(re, pat, options, error, erroffset, tables); \
546      else if (pcre_mode == PCRE16_MODE) \
547      PCRE_COMPILE16(re, pat, options, error, erroffset, tables); \      PCRE_COMPILE16(re, pat, options, error, erroffset, tables); \
548    else \    else \
549      PCRE_COMPILE8(re, pat, options, error, erroffset, tables)      PCRE_COMPILE8(re, pat, options, error, erroffset, tables)
# Line 418  version is called. ----- */ Line 552  version is called. ----- */
552    
553  #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \  #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
554      namesptr, cbuffer, size) \      namesptr, cbuffer, size) \
555    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
556        PCRE_COPY_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
557          namesptr, cbuffer, size); \
558      else if (pcre_mode == PCRE16_MODE) \
559      PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \      PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
560        namesptr, cbuffer, size); \        namesptr, cbuffer, size); \
561    else \    else \
# Line 426  version is called. ----- */ Line 563  version is called. ----- */
563        namesptr, cbuffer, size)        namesptr, cbuffer, size)
564    
565  #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \  #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \
566    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
567        PCRE_COPY_SUBSTRING32(rc, bptr, offsets, count, i, cbuffer, size); \
568      else if (pcre_mode == PCRE16_MODE) \
569      PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size); \      PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size); \
570    else \    else \
571      PCRE_COPY_SUBSTRING8(rc, bptr, offsets, count, i, cbuffer, size)      PCRE_COPY_SUBSTRING8(rc, bptr, offsets, count, i, cbuffer, size)
572    
573  #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \
574      offsets, size_offsets, workspace, size_workspace) \      offsets, size_offsets, workspace, size_workspace) \
575    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
576        PCRE_DFA_EXEC32(count, re, extra, bptr, len, start_offset, options, \
577          offsets, size_offsets, workspace, size_workspace); \
578      else if (pcre_mode == PCRE16_MODE) \
579      PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \      PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \
580        offsets, size_offsets, workspace, size_workspace); \        offsets, size_offsets, workspace, size_workspace); \
581    else \    else \
# Line 442  version is called. ----- */ Line 584  version is called. ----- */
584    
585  #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
586      offsets, size_offsets) \      offsets, size_offsets) \
587    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
588        PCRE_EXEC32(count, re, extra, bptr, len, start_offset, options, \
589          offsets, size_offsets); \
590      else if (pcre_mode == PCRE16_MODE) \
591      PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \      PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \
592        offsets, size_offsets); \        offsets, size_offsets); \
593    else \    else \
# Line 450  version is called. ----- */ Line 595  version is called. ----- */
595        offsets, size_offsets)        offsets, size_offsets)
596    
597  #define PCRE_FREE_STUDY(extra) \  #define PCRE_FREE_STUDY(extra) \
598    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
599        PCRE_FREE_STUDY32(extra); \
600      else if (pcre_mode == PCRE16_MODE) \
601      PCRE_FREE_STUDY16(extra); \      PCRE_FREE_STUDY16(extra); \
602    else \    else \
603      PCRE_FREE_STUDY8(extra)      PCRE_FREE_STUDY8(extra)
604    
605  #define PCRE_FREE_SUBSTRING(substring) \  #define PCRE_FREE_SUBSTRING(substring) \
606    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
607        PCRE_FREE_SUBSTRING32(substring); \
608      else if (pcre_mode == PCRE16_MODE) \
609      PCRE_FREE_SUBSTRING16(substring); \      PCRE_FREE_SUBSTRING16(substring); \
610    else \    else \
611      PCRE_FREE_SUBSTRING8(substring)      PCRE_FREE_SUBSTRING8(substring)
612    
613  #define PCRE_FREE_SUBSTRING_LIST(listptr) \  #define PCRE_FREE_SUBSTRING_LIST(listptr) \
614    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
615        PCRE_FREE_SUBSTRING_LIST32(listptr); \
616      else if (pcre_mode == PCRE16_MODE) \
617      PCRE_FREE_SUBSTRING_LIST16(listptr); \      PCRE_FREE_SUBSTRING_LIST16(listptr); \
618    else \    else \
619      PCRE_FREE_SUBSTRING_LIST8(listptr)      PCRE_FREE_SUBSTRING_LIST8(listptr)
620    
621  #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \  #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
622      getnamesptr, subsptr) \      getnamesptr, subsptr) \
623    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
624        PCRE_GET_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
625          getnamesptr, subsptr); \
626      else if (pcre_mode == PCRE16_MODE) \
627      PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \      PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
628        getnamesptr, subsptr); \        getnamesptr, subsptr); \
629    else \    else \
# Line 477  version is called. ----- */ Line 631  version is called. ----- */
631        getnamesptr, subsptr)        getnamesptr, subsptr)
632    
633  #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \  #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \
634    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
635        PCRE_GET_STRINGNUMBER32(n, rc, ptr); \
636      else if (pcre_mode == PCRE16_MODE) \
637      PCRE_GET_STRINGNUMBER16(n, rc, ptr); \      PCRE_GET_STRINGNUMBER16(n, rc, ptr); \
638    else \    else \
639      PCRE_GET_STRINGNUMBER8(n, rc, ptr)      PCRE_GET_STRINGNUMBER8(n, rc, ptr)
640    
641  #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \  #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \
642    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
643        PCRE_GET_SUBSTRING32(rc, bptr, use_offsets, count, i, subsptr); \
644      else if (pcre_mode == PCRE16_MODE) \
645      PCRE_GET_SUBSTRING16(rc, bptr, use_offsets, count, i, subsptr); \      PCRE_GET_SUBSTRING16(rc, bptr, use_offsets, count, i, subsptr); \
646    else \    else \
647      PCRE_GET_SUBSTRING8(rc, bptr, use_offsets, count, i, subsptr)      PCRE_GET_SUBSTRING8(rc, bptr, use_offsets, count, i, subsptr)
648    
649  #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \  #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \
650    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
651        PCRE_GET_SUBSTRING_LIST32(rc, bptr, offsets, count, listptr); \
652      else if (pcre_mode == PCRE16_MODE) \
653      PCRE_GET_SUBSTRING_LIST16(rc, bptr, offsets, count, listptr); \      PCRE_GET_SUBSTRING_LIST16(rc, bptr, offsets, count, listptr); \
654    else \    else \
655      PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)      PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)
656    
657  #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \  #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
658    (use_pcre16 ? \    (pcre_mode == PCRE32_MODE ? \
659       PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \       PCRE_JIT_STACK_ALLOC32(startsize, maxsize) \
660      :PCRE_JIT_STACK_ALLOC8(startsize, maxsize))      : pcre_mode == PCRE16_MODE ? \
661          PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \
662          : PCRE_JIT_STACK_ALLOC8(startsize, maxsize))
663    
664  #define PCRE_JIT_STACK_FREE(stack) \  #define PCRE_JIT_STACK_FREE(stack) \
665    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
666        PCRE_JIT_STACK_FREE32(stack); \
667      else if (pcre_mode == PCRE16_MODE) \
668      PCRE_JIT_STACK_FREE16(stack); \      PCRE_JIT_STACK_FREE16(stack); \
669    else \    else \
670      PCRE_JIT_STACK_FREE8(stack)      PCRE_JIT_STACK_FREE8(stack)
671    
672  #define PCRE_MAKETABLES \  #define PCRE_MAKETABLES \
673    (use_pcre16? pcre16_maketables() : pcre_maketables())    (pcre_mode == PCRE32_MODE ? pcre32_maketables() : pcre_mode == PCRE16_MODE ? pcre16_maketables() : pcre_maketables())
674    
675  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \
676    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
677        PCRE_PATTERN_TO_HOST_BYTE_ORDER32(rc, re, extra, tables); \
678      else if (pcre_mode == PCRE16_MODE) \
679      PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables); \      PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables); \
680    else \    else \
681      PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables)      PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables)
682    
683  #define PCRE_PRINTINT(re, outfile, debug_lengths) \  #define PCRE_PRINTINT(re, outfile, debug_lengths) \
684    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
685        PCRE_PRINTINT32(re, outfile, debug_lengths); \
686      else if (pcre_mode == PCRE16_MODE) \
687      PCRE_PRINTINT16(re, outfile, debug_lengths); \      PCRE_PRINTINT16(re, outfile, debug_lengths); \
688    else \    else \
689      PCRE_PRINTINT8(re, outfile, debug_lengths)      PCRE_PRINTINT8(re, outfile, debug_lengths)
690    
691  #define PCRE_STUDY(extra, re, options, error) \  #define PCRE_STUDY(extra, re, options, error) \
692    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
693        PCRE_STUDY32(extra, re, options, error); \
694      else if (pcre_mode == PCRE16_MODE) \
695      PCRE_STUDY16(extra, re, options, error); \      PCRE_STUDY16(extra, re, options, error); \
696    else \    else \
697      PCRE_STUDY8(extra, re, options, error)      PCRE_STUDY8(extra, re, options, error)
# Line 558  version is called. ----- */ Line 728  version is called. ----- */
728    
729  /* ----- Only 16-bit mode is supported ----- */  /* ----- Only 16-bit mode is supported ----- */
730    
731  #else  #elif defined SUPPORT_PCRE16
732  #define CHAR_SIZE                 2  #define CHAR_SIZE                 2
733  #define PCHARS                    PCHARS16  #define PCHARS                    PCHARS16
734  #define PCHARSV                   PCHARSV16  #define PCHARSV                   PCHARSV16
# Line 585  version is called. ----- */ Line 755  version is called. ----- */
755  #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
756  #define PCRE_PRINTINT             PCRE_PRINTINT16  #define PCRE_PRINTINT             PCRE_PRINTINT16
757  #define PCRE_STUDY                PCRE_STUDY16  #define PCRE_STUDY                PCRE_STUDY16
758    
759    /* ----- Only 32-bit mode is supported ----- */
760    
761    #elif defined SUPPORT_PCRE32
762    #define CHAR_SIZE                 4
763    #define PCHARS                    PCHARS32
764    #define PCHARSV                   PCHARSV32
765    #define READ_CAPTURE_NAME         READ_CAPTURE_NAME32
766    #define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT32
767    #define STRLEN                    STRLEN32
768    #define PCRE_ASSIGN_JIT_STACK     PCRE_ASSIGN_JIT_STACK32
769    #define PCRE_COMPILE              PCRE_COMPILE32
770    #define PCRE_CONFIG               pcre32_config
771    #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING32
772    #define PCRE_COPY_SUBSTRING       PCRE_COPY_SUBSTRING32
773    #define PCRE_DFA_EXEC             PCRE_DFA_EXEC32
774    #define PCRE_EXEC                 PCRE_EXEC32
775    #define PCRE_FREE_STUDY           PCRE_FREE_STUDY32
776    #define PCRE_FREE_SUBSTRING       PCRE_FREE_SUBSTRING32
777    #define PCRE_FREE_SUBSTRING_LIST  PCRE_FREE_SUBSTRING_LIST32
778    #define PCRE_GET_NAMED_SUBSTRING  PCRE_GET_NAMED_SUBSTRING32
779    #define PCRE_GET_STRINGNUMBER     PCRE_GET_STRINGNUMBER32
780    #define PCRE_GET_SUBSTRING        PCRE_GET_SUBSTRING32
781    #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST32
782    #define PCRE_JIT_STACK_ALLOC      PCRE_JIT_STACK_ALLOC32
783    #define PCRE_JIT_STACK_FREE       PCRE_JIT_STACK_FREE32
784    #define PCRE_MAKETABLES           pcre32_maketables()
785    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER32
786    #define PCRE_PRINTINT             PCRE_PRINTINT32
787    #define PCRE_STUDY                PCRE_STUDY32
788    
789  #endif  #endif
790    
791  /* ----- End of mode-specific function call macros ----- */  /* ----- End of mode-specific function call macros ----- */
# Line 600  version is called. ----- */ Line 801  version is called. ----- */
801  #endif  #endif
802  #endif  #endif
803    
804    #if !defined NODFA
805    #define DFA_WS_DIMENSION 1000
806    #endif
807    
808  /* This is the default loop count for timing. */  /* This is the default loop count for timing. */
809    
810  #define LOOPREPEAT 500000  #define LOOPREPEAT 500000
# Line 614  static int callout_fail_count; Line 819  static int callout_fail_count;
819  static int callout_fail_id;  static int callout_fail_id;
820  static int debug_lengths;  static int debug_lengths;
821  static int first_callout;  static int first_callout;
822    static int jit_was_used;
823  static int locale_set = 0;  static int locale_set = 0;
824  static int show_malloc;  static int show_malloc;
825  static int use_utf;  static int use_utf;
# Line 628  static pcre_uint8 *buffer = NULL; Line 834  static pcre_uint8 *buffer = NULL;
834  static pcre_uint8 *dbuffer = NULL;  static pcre_uint8 *dbuffer = NULL;
835  static pcre_uint8 *pbuffer = NULL;  static pcre_uint8 *pbuffer = NULL;
836    
837  /* 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
838  obtained and extended as required. */  obtained and extended as required. */
839    
840  #ifdef SUPPORT_PCRE16  #if defined SUPPORT_PCRE8 && (defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32)
 static int buffer16_size = 0;  
 static pcre_uint16 *buffer16 = NULL;  
841    
842  #ifdef SUPPORT_PCRE8  /* We need the table of operator lengths that is used for 16/32-bit compiling, in
   
 /* We need the table of operator lengths that is used for 16-bit compiling, in  
843  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
844  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
845  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
846  COMPILE_PCRE16 is *not* set. */  COMPILE_PCRE[16|32] is *not* set. */
847    
848  #ifdef COMPILE_PCRE16  #ifdef COMPILE_PCRE16
849  #error COMPILE_PCRE16 must not be set when compiling pcretest.c  #error COMPILE_PCRE16 must not be set when compiling pcretest.c
850  #endif  #endif
851    
852    #ifdef COMPILE_PCRE32
853    #error COMPILE_PCRE32 must not be set when compiling pcretest.c
854    #endif
855    
856  #if LINK_SIZE == 2  #if LINK_SIZE == 2
857  #undef LINK_SIZE  #undef LINK_SIZE
858  #define LINK_SIZE 1  #define LINK_SIZE 1
# Line 660  COMPILE_PCRE16 is *not* set. */ Line 866  COMPILE_PCRE16 is *not* set. */
866  #undef IMM2_SIZE  #undef IMM2_SIZE
867  #define IMM2_SIZE 1  #define IMM2_SIZE 1
868    
869  #endif /* SUPPORT_PCRE8 */  #endif /* SUPPORT_PCRE8 && (SUPPORT_PCRE16 || SUPPORT_PCRE32) */
870    
871    #ifdef SUPPORT_PCRE16
872    static int buffer16_size = 0;
873    static pcre_uint16 *buffer16 = NULL;
874  static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };  static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };
875  #endif  /* SUPPORT_PCRE16 */  #endif  /* SUPPORT_PCRE16 */
876    
877  /* If we have 8-bit support, default use_pcre16 to false; if there is also  #ifdef SUPPORT_PCRE32
878  16-bit support, it can be changed by an option. If there is no 8-bit support,  static int buffer32_size = 0;
879  there must be 16-bit support, so default it to 1. */  static pcre_uint32 *buffer32 = NULL;
880    static const pcre_uint32 OP_lengths32[] = { OP_LENGTHS };
881    #endif  /* SUPPORT_PCRE32 */
882    
883    /* If we have 8-bit support, default to it; if there is also
884    16-or 32-bit support, it can be changed by an option. If there is no 8-bit support,
885    there must be 16-or 32-bit support, so default it to 1. */
886    
887  #ifdef SUPPORT_PCRE8  #if defined SUPPORT_PCRE8
888  static int use_pcre16 = 0;  static int pcre_mode = PCRE8_MODE;
889  #else  #elif defined SUPPORT_PCRE16
890  static int use_pcre16 = 1;  static int pcre_mode = PCRE16_MODE;
891    #elif defined SUPPORT_PCRE32
892    static int pcre_mode = PCRE32_MODE;
893  #endif  #endif
894    
895    /* JIT study options for -s+n and /S+n where '1' <= n <= '7'. */
896    
897    static int jit_study_bits[] =
898      {
899      PCRE_STUDY_JIT_COMPILE,
900      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE,
901      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE,
902      PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
903      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
904      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE + PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
905      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE +
906        PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE
907    };
908    
909    #define PCRE_STUDY_ALLJIT (PCRE_STUDY_JIT_COMPILE | \
910      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE | PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE)
911    
912  /* Textual explanations for runtime error codes */  /* Textual explanations for runtime error codes */
913    
914  static const char *errtexts[] = {  static const char *errtexts[] = {
# Line 706  static const char *errtexts[] = { Line 940  static const char *errtexts[] = {
940    NULL,  /* SHORTUTF8/16 is handled specially */    NULL,  /* SHORTUTF8/16 is handled specially */
941    "nested recursion at the same subject position",    "nested recursion at the same subject position",
942    "JIT stack limit reached",    "JIT stack limit reached",
943    "pattern compiled in wrong mode: 8-bit/16-bit error"    "pattern compiled in wrong mode: 8-bit/16-bit error",
944      "pattern compiled with other endianness",
945      "invalid data in workspace for DFA restart"
946  };  };
947    
948    
# Line 1058  return sys_errlist[n]; Line 1294  return sys_errlist[n];
1294  #endif /* HAVE_STRERROR */  #endif /* HAVE_STRERROR */
1295    
1296    
1297    
1298    /*************************************************
1299    *       Print newline configuration              *
1300    *************************************************/
1301    
1302    /*
1303    Arguments:
1304      rc         the return code from PCRE_CONFIG_NEWLINE
1305      isc        TRUE if called from "-C newline"
1306    Returns:     nothing
1307    */
1308    
1309    static void
1310    print_newline_config(int rc, BOOL isc)
1311    {
1312    const char *s = NULL;
1313    if (!isc) printf("  Newline sequence is ");
1314    switch(rc)
1315      {
1316      case CHAR_CR: s = "CR"; break;
1317      case CHAR_LF: s = "LF"; break;
1318      case (CHAR_CR<<8 | CHAR_LF): s = "CRLF"; break;
1319      case -1: s = "ANY"; break;
1320      case -2: s = "ANYCRLF"; break;
1321    
1322      default:
1323      printf("a non-standard value: 0x%04x\n", rc);
1324      return;
1325      }
1326    
1327    printf("%s\n", s);
1328    }
1329    
1330    
1331    
1332  /*************************************************  /*************************************************
1333  *         JIT memory callback                    *  *         JIT memory callback                    *
1334  *************************************************/  *************************************************/
1335    
1336  static pcre_jit_stack* jit_callback(void *arg)  static pcre_jit_stack* jit_callback(void *arg)
1337  {  {
1338    jit_was_used = TRUE;
1339  return (pcre_jit_stack *)arg;  return (pcre_jit_stack *)arg;
1340  }  }
1341    
1342    
1343  #if !defined NOUTF || defined SUPPORT_PCRE16  #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32
1344  /*************************************************  /*************************************************
1345  *            Convert UTF-8 string to value       *  *            Convert UTF-8 string to value       *
1346  *************************************************/  *************************************************/
# Line 1085  Returns:      >  0 => the number of byte Line 1357  Returns:      >  0 => the number of byte
1357  */  */
1358    
1359  static int  static int
1360  utf82ord(pcre_uint8 *utf8bytes, int *vptr)  utf82ord(pcre_uint8 *utf8bytes, pcre_uint32 *vptr)
1361  {  {
1362  int c = *utf8bytes++;  pcre_uint32 c = *utf8bytes++;
1363  int d = c;  pcre_uint32 d = c;
1364  int i, j, s;  int i, j, s;
1365    
1366  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 1128  return i+1; Line 1400  return i+1;
1400    
1401    
1402    
1403  #if !defined NOUTF || defined SUPPORT_PCRE16  #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32
1404  /*************************************************  /*************************************************
1405  *       Convert character value to UTF-8         *  *       Convert character value to UTF-8         *
1406  *************************************************/  *************************************************/
# Line 1144  Returns:     number of characters placed Line 1416  Returns:     number of characters placed
1416  */  */
1417    
1418  static int  static int
1419  ord2utf8(int cvalue, pcre_uint8 *utf8bytes)  ord2utf8(pcre_uint32 cvalue, pcre_uint8 *utf8bytes)
1420  {  {
1421  register int i, j;  register int i, j;
1422    if (cvalue > 0x7fffffffu)
1423      return -1;
1424  for (i = 0; i < utf8_table1_size; i++)  for (i = 0; i < utf8_table1_size; i++)
1425    if (cvalue <= utf8_table1[i]) break;    if (cvalue <= utf8_table1[i]) break;
1426  utf8bytes += i;  utf8bytes += i;
# Line 1217  if (!utf && !data) Line 1491  if (!utf && !data)
1491    
1492  else  else
1493    {    {
1494    int c = 0;    pcre_uint32 c = 0;
1495    while (len > 0)    while (len > 0)
1496      {      {
1497      int chlen = utf82ord(p, &c);      int chlen = utf82ord(p, &c);
# Line 1240  return pp - buffer16; Line 1514  return pp - buffer16;
1514  }  }
1515  #endif  #endif
1516    
1517    #ifdef SUPPORT_PCRE32
1518    /*************************************************
1519    *         Convert a string to 32-bit             *
1520    *************************************************/
1521    
1522    /* In non-UTF mode, the space needed for a 32-bit string is exactly four times the
1523    8-bit size. For a UTF-8 string, the size needed for UTF-32 is no more than four
1524    times, because up to 0xffff uses no more than 3 bytes in UTF-8 but possibly 4
1525    in UTF-32. Higher values use 4 bytes in UTF-8 and up to 4 bytes in UTF-32. The
1526    result is always left in buffer32.
1527    
1528    Note that this function does not object to surrogate values. This is
1529    deliberate; it makes it possible to construct UTF-32 strings that are invalid,
1530    for the purpose of testing that they are correctly faulted.
1531    
1532    Patterns to be converted are either plain ASCII or UTF-8; data lines are always
1533    in UTF-8 so that values greater than 255 can be handled.
1534    
1535    Arguments:
1536      data       TRUE if converting a data line; FALSE for a regex
1537      p          points to a byte string
1538      utf        true if UTF-8 (to be converted to UTF-32)
1539      len        number of bytes in the string (excluding trailing zero)
1540    
1541    Returns:     number of 32-bit data items used (excluding trailing zero)
1542                 OR -1 if a UTF-8 string is malformed
1543                 OR -2 if a value > 0x10ffff is encountered
1544                 OR -3 if an ill-formed value is encountered (i.e. a surrogate)
1545    */
1546    
1547    static int
1548    to32(int data, pcre_uint8 *p, int utf, int len)
1549    {
1550    pcre_uint32 *pp;
1551    
1552    if (buffer32_size < 4*len + 4)
1553      {
1554      if (buffer32 != NULL) free(buffer32);
1555      buffer32_size = 4*len + 4;
1556      buffer32 = (pcre_uint32 *)malloc(buffer32_size);
1557      if (buffer32 == NULL)
1558        {
1559        fprintf(stderr, "pcretest: malloc(%d) failed for buffer32\n", buffer32_size);
1560        exit(1);
1561        }
1562      }
1563    
1564    pp = buffer32;
1565    
1566    if (!utf && !data)
1567      {
1568      while (len-- > 0) *pp++ = *p++;
1569      }
1570    
1571    else
1572      {
1573      pcre_uint32 c = 0;
1574      while (len > 0)
1575        {
1576        int chlen = utf82ord(p, &c);
1577        if (chlen <= 0) return -1;
1578        if (utf)
1579          {
1580          if (c > 0x10ffff) return -2;
1581          if (!data && (c & 0xfffff800u) == 0xd800u) return -3;
1582          }
1583    
1584        p += chlen;
1585        len -= chlen;
1586        *pp++ = c;
1587        }
1588      }
1589    
1590    *pp = 0;
1591    return pp - buffer32;
1592    }
1593    #endif
1594    
1595  /*************************************************  /*************************************************
1596  *        Read or extend an input line            *  *        Read or extend an input line            *
# Line 1271  pcre_uint8 *here = start; Line 1622  pcre_uint8 *here = start;
1622    
1623  for (;;)  for (;;)
1624    {    {
1625    int rlen = (int)(buffer_size - (here - buffer));    size_t rlen = (size_t)(buffer_size - (here - buffer));
1626    
1627    if (rlen > 1000)    if (rlen > 1000)
1628      {      {
1629      int dlen;      int dlen;
1630    
1631      /* 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
1632      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
1633      we must put it back again, to be compatible with fgets(). */      newline, so we must put it back again, to be compatible with fgets(). */
1634    
1635  #ifdef SUPPORT_LIBREADLINE  #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
1636      if (isatty(fileno(f)))      if (isatty(fileno(f)))
1637        {        {
1638        size_t len;        size_t len;
# Line 1380  return(result); Line 1731  return(result);
1731    
1732  /* Print a single character either literally, or as a hex escape. */  /* Print a single character either literally, or as a hex escape. */
1733    
1734  static int pchar(int c, FILE *f)  static int pchar(pcre_uint32 c, FILE *f)
1735  {  {
1736    int n;
1737  if (PRINTOK(c))  if (PRINTOK(c))
1738    {    {
1739    if (f != NULL) fprintf(f, "%c", c);    if (f != NULL) fprintf(f, "%c", c);
# Line 1402  if (c < 0x100) Line 1754  if (c < 0x100)
1754      }      }
1755    }    }
1756    
1757  if (f != NULL) fprintf(f, "\\x{%02x}", c);  if (f != NULL) n = fprintf(f, "\\x{%02x}", c);
1758  return (c <= 0x000000ff)? 6 :  return n >= 0 ? n : 0;
        (c <= 0x00000fff)? 7 :  
        (c <= 0x0000ffff)? 8 :  
        (c <= 0x000fffff)? 9 : 10;  
1759  }  }
1760    
1761    
# Line 1421  If handed a NULL file, just counts chars Line 1770  If handed a NULL file, just counts chars
1770    
1771  static int pchars(pcre_uint8 *p, int length, FILE *f)  static int pchars(pcre_uint8 *p, int length, FILE *f)
1772  {  {
1773  int c = 0;  pcre_uint32 c = 0;
1774  int yield = 0;  int yield = 0;
1775    
1776  if (length < 0)  if (length < 0)
# Line 1466  return len; Line 1815  return len;
1815  #endif  /* SUPPORT_PCRE16 */  #endif  /* SUPPORT_PCRE16 */
1816    
1817    
1818    
1819    #ifdef SUPPORT_PCRE32
1820    /*************************************************
1821    *    Find length of 0-terminated 32-bit string   *
1822    *************************************************/
1823    
1824    static int strlen32(PCRE_SPTR32 p)
1825    {
1826    int len = 0;
1827    while (*p++ != 0) len++;
1828    return len;
1829    }
1830    #endif  /* SUPPORT_PCRE32 */
1831    
1832    
1833    
1834  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
1835  /*************************************************  /*************************************************
1836  *           Print 16-bit character string        *  *           Print 16-bit character string        *
# Line 1483  if (length < 0) Line 1848  if (length < 0)
1848    
1849  while (length-- > 0)  while (length-- > 0)
1850    {    {
1851    int c = *p++ & 0xffff;    pcre_uint32 c = *p++ & 0xffff;
1852  #if !defined NOUTF  #if !defined NOUTF
1853    if (use_utf && c >= 0xD800 && c < 0xDC00 && length > 0)    if (use_utf && c >= 0xD800 && c < 0xDC00 && length > 0)
1854      {      {
# Line 1505  return yield; Line 1870  return yield;
1870    
1871    
1872    
1873    #ifdef SUPPORT_PCRE32
1874    /*************************************************
1875    *           Print 32-bit character string        *
1876    *************************************************/
1877    
1878    /* Must handle UTF-32 strings in utf mode. Yields number of characters printed.
1879    If handed a NULL file, just counts chars without printing. */
1880    
1881    static int pchars32(PCRE_SPTR32 p, int length, FILE *f)
1882    {
1883    int yield = 0;
1884    
1885    if (length < 0)
1886      length = strlen32(p);
1887    
1888    while (length-- > 0)
1889      {
1890      pcre_uint32 c = *p++;
1891      yield += pchar(c, f);
1892      }
1893    
1894    return yield;
1895    }
1896    #endif  /* SUPPORT_PCRE32 */
1897    
1898    
1899    
1900  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
1901  /*************************************************  /*************************************************
1902  *     Read a capture name (8-bit) and check it   *  *     Read a capture name (8-bit) and check it   *
# Line 1558  return p; Line 1950  return p;
1950    
1951    
1952    
1953    #ifdef SUPPORT_PCRE32
1954    /*************************************************
1955    *     Read a capture name (32-bit) and check it  *
1956    *************************************************/
1957    
1958    /* Note that the text being read is 8-bit. */
1959    
1960    static pcre_uint8 *
1961    read_capture_name32(pcre_uint8 *p, pcre_uint32 **pp, pcre *re)
1962    {
1963    pcre_uint32 *npp = *pp;
1964    while (isalnum(*p)) *npp++ = *p++;
1965    *npp++ = 0;
1966    *npp = 0;
1967    if (pcre32_get_stringnumber((pcre32 *)re, (PCRE_SPTR32)(*pp)) < 0)
1968      {
1969      fprintf(outfile, "no parentheses with name \"");
1970      PCHARSV(*pp, 0, -1, outfile);
1971      fprintf(outfile, "\"\n");
1972      }
1973    *pp = npp;
1974    return p;
1975    }
1976    #endif  /* SUPPORT_PCRE32 */
1977    
1978    
1979    
1980  /*************************************************  /*************************************************
1981  *              Callout function                  *  *              Callout function                  *
1982  *************************************************/  *************************************************/
# Line 1715  free(block); Line 2134  free(block);
2134  *************************************************/  *************************************************/
2135    
2136  /* Get one piece of information from the pcre_fullinfo() function. When only  /* Get one piece of information from the pcre_fullinfo() function. When only
2137  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
2138  value, but the code is defensive.  value, but the code is defensive.
2139    
2140  Arguments:  Arguments:
# Line 1732  new_info(pcre *re, pcre_extra *study, in Line 2151  new_info(pcre *re, pcre_extra *study, in
2151  {  {
2152  int rc;  int rc;
2153    
2154  if (use_pcre16)  if (pcre_mode == PCRE32_MODE)
2155    #ifdef SUPPORT_PCRE32
2156      rc = pcre32_fullinfo((pcre32 *)re, (pcre32_extra *)study, option, ptr);
2157    #else
2158      rc = PCRE_ERROR_BADMODE;
2159    #endif
2160    else if (pcre_mode == PCRE16_MODE)
2161  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2162    rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);    rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);
2163  #else  #else
# Line 1748  else Line 2173  else
2173  if (rc < 0)  if (rc < 0)
2174    {    {
2175    fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,    fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
2176      use_pcre16? "16" : "", option);      pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "", option);
2177    if (rc == PCRE_ERROR_BADMODE)    if (rc == PCRE_ERROR_BADMODE)
2178      fprintf(outfile, "Running in %s-bit mode but pattern was compiled in "      fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
2179        "%s-bit mode\n", use_pcre16? "16":"8", use_pcre16? "8":"16");        "%d-bit mode\n", 8 * CHAR_SIZE,
2180          8 * (REAL_PCRE_FLAGS(re) & PCRE_MODE_MASK));
2181    }    }
2182    
2183  return rc;  return rc;
# Line 1800  bytes in the pattern itself. This is to Line 2226  bytes in the pattern itself. This is to
2226  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
2227  architecture. */  architecture. */
2228    
2229    #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
2230  static void  static void
2231  regexflip(pcre *ere, pcre_extra *extra)  regexflip8_or_16(pcre *ere, pcre_extra *extra)
2232  {  {
2233  REAL_PCRE *re = (REAL_PCRE *)ere;  real_pcre8_or_16 *re = (real_pcre8_or_16 *)ere;
2234  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2235  int op;  int op;
2236  pcre_uint16 *ptr = (pcre_uint16 *)re + re->name_table_offset;  pcre_uint16 *ptr = (pcre_uint16 *)re + re->name_table_offset;
# Line 1840  if (extra != NULL) Line 2267  if (extra != NULL)
2267  in the name table, if present, and then in the pattern itself. */  in the name table, if present, and then in the pattern itself. */
2268    
2269  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2270  if (!use_pcre16) return;  if (pcre_mode != PCRE16_MODE) return;
2271    
2272  while(TRUE)  while(TRUE)
2273    {    {
# Line 1978  while(TRUE) Line 2405  while(TRUE)
2405  /* Control should never reach here in 16 bit mode. */  /* Control should never reach here in 16 bit mode. */
2406  #endif /* SUPPORT_PCRE16 */  #endif /* SUPPORT_PCRE16 */
2407  }  }
2408    #endif /* SUPPORT_PCRE[8|16] */
2409    
2410    
2411    
2412    #if defined SUPPORT_PCRE32
2413    static void
2414    regexflip_32(pcre *ere, pcre_extra *extra)
2415    {
2416    real_pcre32 *re = (real_pcre32 *)ere;
2417    int op;
2418    pcre_uint32 *ptr = (pcre_uint32 *)re + re->name_table_offset;
2419    int length = re->name_count * re->name_entry_size;
2420    #ifdef SUPPORT_UTF
2421    BOOL utf = (re->options & PCRE_UTF32) != 0;
2422    #endif /* SUPPORT_UTF */
2423    
2424    /* Always flip the bytes in the main data block and study blocks. */
2425    
2426    re->magic_number = REVERSED_MAGIC_NUMBER;
2427    re->size = swap_uint32(re->size);
2428    re->options = swap_uint32(re->options);
2429    re->flags = swap_uint16(re->flags);
2430    re->top_bracket = swap_uint16(re->top_bracket);
2431    re->top_backref = swap_uint16(re->top_backref);
2432    re->first_char = swap_uint32(re->first_char);
2433    re->req_char = swap_uint32(re->req_char);
2434    re->name_table_offset = swap_uint16(re->name_table_offset);
2435    re->name_entry_size = swap_uint16(re->name_entry_size);
2436    re->name_count = swap_uint16(re->name_count);
2437    
2438    if (extra != NULL)
2439      {
2440      pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
2441      rsd->size = swap_uint32(rsd->size);
2442      rsd->flags = swap_uint32(rsd->flags);
2443      rsd->minlength = swap_uint32(rsd->minlength);
2444      }
2445    
2446    /* In 32-bit mode we must swap bytes
2447    in the name table, if present, and then in the pattern itself. */
2448    
2449    while(TRUE)
2450      {
2451      /* Swap previous characters. */
2452      while (length-- > 0)
2453        {
2454        *ptr = swap_uint32(*ptr);
2455        ptr++;
2456        }
2457    
2458      /* Get next opcode. */
2459    
2460      length = 0;
2461      op = *ptr;
2462      *ptr++ = swap_uint32(op);
2463    
2464      switch (op)
2465        {
2466        case OP_END:
2467        return;
2468    
2469        default:
2470        length = OP_lengths32[op] - 1;
2471        break;
2472    
2473        case OP_CLASS:
2474        case OP_NCLASS:
2475        /* Skip the character bit map. */
2476        ptr += 32/sizeof(pcre_uint32);
2477        length = 0;
2478        break;
2479    
2480        case OP_XCLASS:
2481        /* LINK_SIZE can only be 1 in 32-bit mode. */
2482        length = (int)((unsigned int)(ptr[0]) - (1 + LINK_SIZE + 1));
2483    
2484        /* Reverse the size of the XCLASS instance. */
2485        *ptr = swap_uint32(*ptr);
2486        ptr++;
2487    
2488        op = *ptr;
2489        *ptr = swap_uint32(op);
2490        ptr++;
2491        if ((op & XCL_MAP) != 0)
2492          {
2493          /* Skip the character bit map. */
2494          ptr += 32/sizeof(pcre_uint32);
2495          length -= 32/sizeof(pcre_uint32);
2496          }
2497        break;
2498        }
2499      }
2500    /* Control should never reach here in 32 bit mode. */
2501    }
2502    
2503    #endif /* SUPPORT_PCRE32 */
2504    
2505    
2506    
2507    static void
2508    regexflip(pcre *ere, pcre_extra *extra)
2509    {
2510    #if defined SUPPORT_PCRE32
2511      if (REAL_PCRE_FLAGS(ere) & PCRE_MODE32)
2512        regexflip_32(ere, extra);
2513    #endif
2514    #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
2515      if (REAL_PCRE_FLAGS(ere) & (PCRE_MODE8 | PCRE_MODE16))
2516        regexflip8_or_16(ere, extra);
2517    #endif
2518    }
2519    
2520    
2521    
# Line 2097  usage(void) Line 2635  usage(void)
2635  {  {
2636  printf("Usage:     pcretest [options] [<input file> [<output file>]]\n\n");  printf("Usage:     pcretest [options] [<input file> [<output file>]]\n\n");
2637  printf("Input and output default to stdin and stdout.\n");  printf("Input and output default to stdin and stdout.\n");
2638  #ifdef SUPPORT_LIBREADLINE  #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
2639  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");
2640  #else  #else
2641  printf("This version of pcretest is not linked with readline().\n");  printf("This version of pcretest is not linked with readline().\n");
2642  #endif  #endif
2643  printf("\nOptions:\n");  printf("\nOptions:\n");
2644  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2645  printf("  -16      use 16-bit interface\n");  printf("  -16      use the 16-bit library\n");
2646    #endif
2647    #ifdef SUPPORT_PCRE32
2648    printf("  -32      use the 32-bit library\n");
2649  #endif  #endif
2650  printf("  -b       show compiled code (bytecode)\n");  printf("  -b       show compiled code\n");
2651  printf("  -C       show PCRE compile-time options and exit\n");  printf("  -C       show PCRE compile-time options and exit\n");
2652  printf("  -C arg   show a specific compile-time option\n");  printf("  -C arg   show a specific compile-time option\n");
2653  printf("           and exit with its value. The arg can be:\n");  printf("           and exit with its value. The arg can be:\n");
2654  printf("     linksize     internal link size [2, 3, 4]\n");  printf("     linksize     internal link size [2, 3, 4]\n");
2655  printf("     pcre8        8 bit library support enabled [0, 1]\n");  printf("     pcre8        8 bit library support enabled [0, 1]\n");
2656  printf("     pcre16       16 bit library support enabled [0, 1]\n");  printf("     pcre16       16 bit library support enabled [0, 1]\n");
2657    printf("     pcre32       32 bit library support enabled [0, 1]\n");
2658  printf("     utf          Unicode Transformation Format supported [0, 1]\n");  printf("     utf          Unicode Transformation Format supported [0, 1]\n");
2659  printf("     ucp          Unicode Properties supported [0, 1]\n");  printf("     ucp          Unicode Properties supported [0, 1]\n");
2660  printf("     jit          Just-in-time compiler supported [0, 1]\n");  printf("     jit          Just-in-time compiler supported [0, 1]\n");
# Line 2133  printf("  -q       quiet: do not output Line 2675  printf("  -q       quiet: do not output
2675  printf("  -S <n>   set stack size to <n> megabytes\n");  printf("  -S <n>   set stack size to <n> megabytes\n");
2676  printf("  -s       force each pattern to be studied at basic level\n"  printf("  -s       force each pattern to be studied at basic level\n"
2677         "  -s+      force each pattern to be studied, using JIT if available\n"         "  -s+      force each pattern to be studied, using JIT if available\n"
2678           "  -s++     ditto, verifying when JIT was actually used\n"
2679           "  -s+n     force each pattern to be studied, using JIT if available,\n"
2680           "             where 1 <= n <= 7 selects JIT options\n"
2681           "  -s++n    ditto, verifying when JIT was actually used\n"
2682         "  -t       time compilation and execution\n");         "  -t       time compilation and execution\n");
2683  printf("  -t <n>   time compilation and execution, repeating <n> times\n");  printf("  -t <n>   time compilation and execution, repeating <n> times\n");
2684  printf("  -tm      time execution (matching) only\n");  printf("  -tm      time execution (matching) only\n");
# Line 2167  int quiet = 0; Line 2713  int quiet = 0;
2713  int size_offsets = 45;  int size_offsets = 45;
2714  int size_offsets_max;  int size_offsets_max;
2715  int *offsets = NULL;  int *offsets = NULL;
 #if !defined NOPOSIX  
 int posix = 0;  
 #endif  
2716  int debug = 0;  int debug = 0;
2717  int done = 0;  int done = 0;
2718  int all_use_dfa = 0;  int all_use_dfa = 0;
2719    int verify_jit = 0;
2720  int yield = 0;  int yield = 0;
2721  int stack_size;  int stack_size;
2722    
2723    #if !defined NOPOSIX
2724    int posix = 0;
2725    #endif
2726    #if !defined NODFA
2727    int *dfa_workspace = NULL;
2728    #endif
2729    
2730  pcre_jit_stack *jit_stack = NULL;  pcre_jit_stack *jit_stack = NULL;
2731    
2732  /* These vectors store, end-to-end, a list of zero-terminated captured  /* These vectors store, end-to-end, a list of zero-terminated captured
2733  substring names, each list itself being terminated by an empty name. Assume  substring names, each list itself being terminated by an empty name. Assume
2734  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
2735  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
2736  for the actual memory, to ensure alignment. By defining these variables always  for the actual memory, to ensure alignment. */
2737  (whether or not 8-bit or 16-bit is supported), we avoid too much mess with  
2738  #ifdefs in the code. */  pcre_uint32 copynames[1024];
2739    pcre_uint32 getnames[1024];
2740    
2741  pcre_uint16 copynames[1024];  #ifdef SUPPORT_PCRE32
2742  pcre_uint16 getnames[1024];  pcre_uint32 *cn32ptr;
2743    pcre_uint32 *gn32ptr;
2744    #endif
2745    
2746    #ifdef SUPPORT_PCRE16
2747    pcre_uint16 *copynames16 = (pcre_uint16 *)copynames;
2748    pcre_uint16 *getnames16 = (pcre_uint16 *)getnames;
2749  pcre_uint16 *cn16ptr;  pcre_uint16 *cn16ptr;
2750  pcre_uint16 *gn16ptr;  pcre_uint16 *gn16ptr;
2751    #endif
2752    
2753    #ifdef SUPPORT_PCRE8
2754  pcre_uint8 *copynames8 = (pcre_uint8 *)copynames;  pcre_uint8 *copynames8 = (pcre_uint8 *)copynames;
2755  pcre_uint8 *getnames8 = (pcre_uint8 *)getnames;  pcre_uint8 *getnames8 = (pcre_uint8 *)getnames;
2756  pcre_uint8 *cn8ptr;  pcre_uint8 *cn8ptr;
2757  pcre_uint8 *gn8ptr;  pcre_uint8 *gn8ptr;
2758    #endif
2759    
2760  /* Get buffers from malloc() so that valgrind will check their misuse when  /* Get buffers from malloc() so that valgrind will check their misuse when
2761  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-
2762  buffer (buffer16) is obtained only if needed. */  and 32-bit buffers (buffer16, buffer32) are obtained only if needed. */
2763    
2764  buffer = (pcre_uint8 *)malloc(buffer_size);  buffer = (pcre_uint8 *)malloc(buffer_size);
2765  dbuffer = (pcre_uint8 *)malloc(buffer_size);  dbuffer = (pcre_uint8 *)malloc(buffer_size);
# Line 2221  _setmode( _fileno( stdout ), _O_BINARY ) Line 2781  _setmode( _fileno( stdout ), _O_BINARY )
2781  /* Get the version number: both pcre_version() and pcre16_version() give the  /* Get the version number: both pcre_version() and pcre16_version() give the
2782  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. */
2783    
2784  #ifdef SUPPORT_PCRE8  #if defined SUPPORT_PCRE8
2785  version = pcre_version();  version = pcre_version();
2786  #else  #elif defined SUPPORT_PCRE16
2787  version = pcre16_version();  version = pcre16_version();
2788    #elif defined SUPPORT_PCRE32
2789    version = pcre32_version();
2790  #endif  #endif
2791    
2792  /* Scan options */  /* Scan options */
# Line 2232  version = pcre16_version(); Line 2794  version = pcre16_version();
2794  while (argc > 1 && argv[op][0] == '-')  while (argc > 1 && argv[op][0] == '-')
2795    {    {
2796    pcre_uint8 *endptr;    pcre_uint8 *endptr;
2797      char *arg = argv[op];
2798    
2799      if (strcmp(arg, "-m") == 0) showstore = 1;
2800      else if (strcmp(arg, "-s") == 0) force_study = 0;
2801    
2802    if (strcmp(argv[op], "-m") == 0) showstore = 1;    else if (strncmp(arg, "-s+", 3) == 0)
   else if (strcmp(argv[op], "-s") == 0) force_study = 0;  
   else if (strcmp(argv[op], "-s+") == 0)  
2803      {      {
2804        arg += 3;
2805        if (*arg == '+') { arg++; verify_jit = TRUE; }
2806      force_study = 1;      force_study = 1;
2807      force_study_options = PCRE_STUDY_JIT_COMPILE;      if (*arg == 0)
2808          force_study_options = jit_study_bits[6];
2809        else if (*arg >= '1' && *arg <= '7')
2810          force_study_options = jit_study_bits[*arg - '1'];
2811        else goto BAD_ARG;
2812      }      }
2813    else if (strcmp(argv[op], "-16") == 0)    else if (strcmp(arg, "-16") == 0)
2814      {      {
2815  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2816      use_pcre16 = 1;      pcre_mode = PCRE16_MODE;
2817  #else  #else
2818      printf("** This version of PCRE was built without 16-bit support\n");      printf("** This version of PCRE was built without 16-bit support\n");
2819      exit(1);      exit(1);
2820  #endif  #endif
2821      }      }
2822    else if (strcmp(argv[op], "-q") == 0) quiet = 1;    else if (strcmp(arg, "-32") == 0)
2823    else if (strcmp(argv[op], "-b") == 0) debug = 1;      {
2824    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;  #ifdef SUPPORT_PCRE32
2825    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;      pcre_mode = PCRE32_MODE;
2826    else if (strcmp(argv[op], "-M") == 0) default_find_match_limit = TRUE;  #else
2827        printf("** This version of PCRE was built without 32-bit support\n");
2828        exit(1);
2829    #endif
2830        }
2831      else if (strcmp(arg, "-q") == 0) quiet = 1;
2832      else if (strcmp(arg, "-b") == 0) debug = 1;
2833      else if (strcmp(arg, "-i") == 0) showinfo = 1;
2834      else if (strcmp(arg, "-d") == 0) showinfo = debug = 1;
2835      else if (strcmp(arg, "-M") == 0) default_find_match_limit = TRUE;
2836  #if !defined NODFA  #if !defined NODFA
2837    else if (strcmp(argv[op], "-dfa") == 0) all_use_dfa = 1;    else if (strcmp(arg, "-dfa") == 0) all_use_dfa = 1;
2838  #endif  #endif
2839    else if (strcmp(argv[op], "-o") == 0 && argc > 2 &&    else if (strcmp(arg, "-o") == 0 && argc > 2 &&
2840        ((size_offsets = get_value((pcre_uint8 *)argv[op+1], &endptr)),        ((size_offsets = get_value((pcre_uint8 *)argv[op+1], &endptr)),
2841          *endptr == 0))          *endptr == 0))
2842      {      {
2843      op++;      op++;
2844      argc--;      argc--;
2845      }      }
2846    else if (strcmp(argv[op], "-t") == 0 || strcmp(argv[op], "-tm") == 0)    else if (strcmp(arg, "-t") == 0 || strcmp(arg, "-tm") == 0)
2847      {      {
2848      int both = argv[op][2] == 0;      int both = arg[2] == 0;
2849      int temp;      int temp;
2850      if (argc > 2 && (temp = get_value((pcre_uint8 *)argv[op+1], &endptr),      if (argc > 2 && (temp = get_value((pcre_uint8 *)argv[op+1], &endptr),
2851                       *endptr == 0))                       *endptr == 0))
# Line 2278  while (argc > 1 && argv[op][0] == '-') Line 2857  while (argc > 1 && argv[op][0] == '-')
2857      else timeitm = LOOPREPEAT;      else timeitm = LOOPREPEAT;
2858      if (both) timeit = timeitm;      if (both) timeit = timeitm;
2859      }      }
2860    else if (strcmp(argv[op], "-S") == 0 && argc > 2 &&    else if (strcmp(arg, "-S") == 0 && argc > 2 &&
2861        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),
2862          *endptr == 0))          *endptr == 0))
2863      {      {
2864  #if defined(_WIN32) || defined(WIN32) || defined(__minix)  #if defined(_WIN32) || defined(WIN32) || defined(__minix) || defined(NATIVE_ZOS)
2865      printf("PCRE: -S not supported on this OS\n");      printf("PCRE: -S not supported on this OS\n");
2866      exit(1);      exit(1);
2867  #else  #else
# Line 2301  while (argc > 1 && argv[op][0] == '-') Line 2880  while (argc > 1 && argv[op][0] == '-')
2880  #endif  #endif
2881      }      }
2882  #if !defined NOPOSIX  #if !defined NOPOSIX
2883    else if (strcmp(argv[op], "-p") == 0) posix = 1;    else if (strcmp(arg, "-p") == 0) posix = 1;
2884  #endif  #endif
2885    else if (strcmp(argv[op], "-C") == 0)    else if (strcmp(arg, "-C") == 0)
2886      {      {
2887      int rc;      int rc;
2888      unsigned long int lrc;      unsigned long int lrc;
# Line 2315  while (argc > 1 && argv[op][0] == '-') Line 2894  while (argc > 1 && argv[op][0] == '-')
2894          (void)PCRE_CONFIG(PCRE_CONFIG_LINK_SIZE, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_LINK_SIZE, &rc);
2895          printf("%d\n", rc);          printf("%d\n", rc);
2896          yield = rc;          yield = rc;
         goto EXIT;  
2897          }          }
2898        if (strcmp(argv[op + 1], "pcre8") == 0)        else if (strcmp(argv[op + 1], "pcre8") == 0)
2899          {          {
2900  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
2901          printf("1\n");          printf("1\n");
# Line 2326  while (argc > 1 && argv[op][0] == '-') Line 2904  while (argc > 1 && argv[op][0] == '-')
2904          printf("0\n");          printf("0\n");
2905          yield = 0;          yield = 0;
2906  #endif  #endif
         goto EXIT;  
2907          }          }
2908        if (strcmp(argv[op + 1], "pcre16") == 0)        else if (strcmp(argv[op + 1], "pcre16") == 0)
2909          {          {
2910  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2911          printf("1\n");          printf("1\n");
# Line 2337  while (argc > 1 && argv[op][0] == '-') Line 2914  while (argc > 1 && argv[op][0] == '-')
2914          printf("0\n");          printf("0\n");
2915          yield = 0;          yield = 0;
2916  #endif  #endif
2917            }
2918          else if (strcmp(argv[op + 1], "pcre32") == 0)
2919            {
2920    #ifdef SUPPORT_PCRE32
2921            printf("1\n");
2922            yield = 1;
2923    #else
2924            printf("0\n");
2925            yield = 0;
2926    #endif
2927          goto EXIT;          goto EXIT;
2928          }          }
2929        if (strcmp(argv[op + 1], "utf") == 0)        if (strcmp(argv[op + 1], "utf") == 0)
2930          {          {
2931  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
2932          (void)pcre_config(PCRE_CONFIG_UTF8, &rc);          if (pcre_mode == PCRE8_MODE)
2933          printf("%d\n", rc);            (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
2934          yield = rc;  #endif
2935  #else  #ifdef SUPPORT_PCRE16
2936          (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);          if (pcre_mode == PCRE16_MODE)
2937              (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
2938    #endif
2939    #ifdef SUPPORT_PCRE32
2940            if (pcre_mode == PCRE32_MODE)
2941              (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
2942    #endif
2943          printf("%d\n", rc);          printf("%d\n", rc);
2944          yield = rc;          yield = rc;
 #endif  
2945          goto EXIT;          goto EXIT;
2946          }          }
2947        if (strcmp(argv[op + 1], "ucp") == 0)        else if (strcmp(argv[op + 1], "ucp") == 0)
2948          {          {
2949          (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
2950          printf("%d\n", rc);          printf("%d\n", rc);
2951          yield = rc;          yield = rc;
         goto EXIT;  
2952          }          }
2953        if (strcmp(argv[op + 1], "jit") == 0)        else if (strcmp(argv[op + 1], "jit") == 0)
2954          {          {
2955          (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);
2956          printf("%d\n", rc);          printf("%d\n", rc);
2957          yield = rc;          yield = rc;
         goto EXIT;  
2958          }          }
2959        if (strcmp(argv[op + 1], "newline") == 0)        else if (strcmp(argv[op + 1], "newline") == 0)
2960          {          {
2961          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
2962          /* Note that these values are always the ASCII values, even          print_newline_config(rc, TRUE);
         in EBCDIC environments. CR is 13 and NL is 10. */  
         printf("%s\n", (rc == 13)? "CR" :  
           (rc == 10)? "LF" : (rc == (13<<8 | 10))? "CRLF" :  
           (rc == -2)? "ANYCRLF" :  
           (rc == -1)? "ANY" : "???");  
         goto EXIT;  
2963          }          }
2964        printf("Unknown -C option: %s\n", argv[op + 1]);        else if (strcmp(argv[op + 1], "ebcdic") == 0)
2965            {
2966    #ifdef EBCDIC
2967            printf("1\n");
2968            yield = 1;
2969    #else
2970            printf("0\n");
2971    #endif
2972            }
2973          else if (strcmp(argv[op + 1], "ebcdic-nl") == 0)
2974            {
2975    #ifdef EBCDIC
2976            printf("0x%02x\n", CHAR_LF);
2977    #else
2978            printf("0\n");
2979    #endif
2980            }
2981          else
2982            {
2983            printf("Unknown -C option: %s\n", argv[op + 1]);
2984            }
2985        goto EXIT;        goto EXIT;
2986        }        }
2987    
2988        /* No argument for -C: output all configuration information. */
2989    
2990      printf("PCRE version %s\n", version);      printf("PCRE version %s\n", version);
2991      printf("Compiled with\n");      printf("Compiled with\n");
2992    
2993    #ifdef EBCDIC
2994        printf("  EBCDIC code support: LF is 0x%02x\n", CHAR_LF);
2995    #endif
2996    
2997  /* 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
2998  are set, either both UTFs are supported or both are not supported. */  are set, either both UTFs are supported or both are not supported. */
2999    
3000  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE8
3001      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");  
3002      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
3003      printf("  %sUTF-8 support\n", rc? "" : "No ");        printf ("  %sUTF-8 support\n", rc ? "" : "No ");
3004  #else  #endif
3005      printf("  16-bit support only\n");  #ifdef SUPPORT_PCRE16
3006        printf("  16-bit support\n");
3007      (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);      (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
3008      printf("  %sUTF-16 support\n", rc? "" : "No ");      printf ("  %sUTF-16 support\n", rc ? "" : "No ");
3009    #endif
3010    #ifdef SUPPORT_PCRE32
3011        printf("  32-bit support\n");
3012        (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
3013        printf ("  %sUTF-32 support\n", rc ? "" : "No ");
3014  #endif  #endif
3015    
3016      (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
3017      printf("  %sUnicode properties support\n", rc? "" : "No ");      printf("  %sUnicode properties support\n", rc? "" : "No ");
3018      (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);
3019      if (rc)      if (rc)
3020        printf("  Just-in-time compiler support\n");        {
3021          const char *arch;
3022          (void)PCRE_CONFIG(PCRE_CONFIG_JITTARGET, (void *)(&arch));
3023          printf("  Just-in-time compiler support: %s\n", arch);
3024          }
3025      else      else
3026        printf("  No just-in-time compiler support\n");        printf("  No just-in-time compiler support\n");
3027      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3028      /* 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" : "???");  
3029      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);
3030      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :
3031                                       "all Unicode newlines");                                       "all Unicode newlines");
# Line 2430  are set, either both UTFs are supported Line 3038  are set, either both UTFs are supported
3038      (void)PCRE_CONFIG(PCRE_CONFIG_MATCH_LIMIT_RECURSION, &lrc);      (void)PCRE_CONFIG(PCRE_CONFIG_MATCH_LIMIT_RECURSION, &lrc);
3039      printf("  Default recursion depth limit = %ld\n", lrc);      printf("  Default recursion depth limit = %ld\n", lrc);
3040      (void)PCRE_CONFIG(PCRE_CONFIG_STACKRECURSE, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_STACKRECURSE, &rc);
3041      printf("  Match recursion uses %s\n", rc? "stack" : "heap");      printf("  Match recursion uses %s", rc? "stack" : "heap");
3042        if (showstore)
3043          {
3044          PCRE_EXEC(stack_size, NULL, NULL, NULL, -999, -999, 0, NULL, 0);
3045          printf(": %sframe size = %d bytes", rc? "approximate " : "", -stack_size);
3046          }
3047        printf("\n");
3048      goto EXIT;      goto EXIT;
3049      }      }
3050    else if (strcmp(argv[op], "-help") == 0 ||    else if (strcmp(arg, "-help") == 0 ||
3051             strcmp(argv[op], "--help") == 0)             strcmp(arg, "--help") == 0)
3052      {      {
3053      usage();      usage();
3054      goto EXIT;      goto EXIT;
3055      }      }
3056    else    else
3057      {      {
3058      printf("** Unknown or malformed option %s\n", argv[op]);      BAD_ARG:
3059        printf("** Unknown or malformed option %s\n", arg);
3060      usage();      usage();
3061      yield = 1;      yield = 1;
3062      goto EXIT;      goto EXIT;
# Line 2502  pcre16_stack_malloc = stack_malloc; Line 3117  pcre16_stack_malloc = stack_malloc;
3117  pcre16_stack_free = stack_free;  pcre16_stack_free = stack_free;
3118  #endif  #endif
3119    
3120    #ifdef SUPPORT_PCRE32
3121    pcre32_malloc = new_malloc;
3122    pcre32_free = new_free;
3123    pcre32_stack_malloc = stack_malloc;
3124    pcre32_stack_free = stack_free;
3125    #endif
3126    
3127  /* Heading line unless quiet, then prompt for first regex if stdin */  /* Heading line unless quiet, then prompt for first regex if stdin */
3128    
3129  if (!quiet) fprintf(outfile, "PCRE version %s\n\n", version);  if (!quiet) fprintf(outfile, "PCRE version %s\n\n", version);
# Line 2539  while (!done) Line 3161  while (!done)
3161    int do_flip = 0;    int do_flip = 0;
3162    int erroroffset, len, delimiter, poffset;    int erroroffset, len, delimiter, poffset;
3163    
3164    #if !defined NODFA
3165      int dfa_matched = 0;
3166    #endif
3167    
3168    use_utf = 0;    use_utf = 0;
3169    debug_lengths = 1;    debug_lengths = 1;
3170    
# Line 2586  while (!done) Line 3212  while (!done)
3212        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];
3213    
3214      re = (pcre *)new_malloc(true_size);      re = (pcre *)new_malloc(true_size);
3215        if (re == NULL)
3216          {
3217          printf("** Failed to get %d bytes of memory for pcre object\n",
3218            (int)true_size);
3219          yield = 1;
3220          goto EXIT;
3221          }
3222      regex_gotten_store = first_gotten_store;      regex_gotten_store = first_gotten_store;
3223    
3224      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;
3225    
3226      magic = ((REAL_PCRE *)re)->magic_number;      magic = REAL_PCRE_MAGIC(re);
3227      if (magic != MAGIC_NUMBER)      if (magic != MAGIC_NUMBER)
3228        {        {
3229        if (swap_uint32(magic) == MAGIC_NUMBER)        if (swap_uint32(magic) == MAGIC_NUMBER)
# Line 2600  while (!done) Line 3233  while (!done)
3233        else        else
3234          {          {
3235          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);
3236            new_free(re);
3237          fclose(f);          fclose(f);
3238          continue;          continue;
3239          }          }
# Line 2629  while (!done) Line 3263  while (!done)
3263            {            {
3264            PCRE_FREE_STUDY(extra);            PCRE_FREE_STUDY(extra);
3265            }            }
3266          if (re != NULL) new_free(re);          new_free(re);
3267          fclose(f);          fclose(f);
3268          continue;          continue;
3269          }          }
# Line 2647  while (!done) Line 3281  while (!done)
3281          {          {
3282          /* Simulate the result of the function call below. */          /* Simulate the result of the function call below. */
3283          fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,          fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
3284            use_pcre16? "16" : "", PCRE_INFO_OPTIONS);            pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "",
3285          fprintf(outfile, "Running in %s-bit mode but pattern was compiled in "            PCRE_INFO_OPTIONS);
3286            "%s-bit mode\n", use_pcre16? "16":"8", use_pcre16? "8":"16");          fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
3287              "%d-bit mode\n", 8 * CHAR_SIZE,
3288              8 * (REAL_PCRE_FLAGS(re) & PCRE_MODE_MASK));
3289            new_free(re);
3290            fclose(f);
3291          continue;          continue;
3292          }          }
3293        }        }
3294    
3295      /* Need to know if UTF-8 for printing data strings. */      /* Need to know if UTF-8 for printing data strings. */
3296    
3297      if (new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options) < 0) continue;      if (new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options) < 0)
3298          {
3299          new_free(re);
3300          fclose(f);
3301          continue;
3302          }
3303      use_utf = (get_options & PCRE_UTF8) != 0;      use_utf = (get_options & PCRE_UTF8) != 0;
3304    
3305      fclose(f);      fclose(f);
# Line 2715  while (!done) Line 3358  while (!done)
3358    /* Look for options after final delimiter */    /* Look for options after final delimiter */
3359    
3360    options = 0;    options = 0;
3361    study_options = 0;    study_options = force_study_options;
3362    log_store = showstore;  /* default from command line */    log_store = showstore;  /* default from command line */
3363    
3364    while (*pp != 0)    while (*pp != 0)
# Line 2752  while (!done) Line 3395  while (!done)
3395  #endif  #endif
3396    
3397        case 'S':        case 'S':
3398        if (do_study == 0)        do_study = 1;
3399          for (;;)
3400          {          {
3401          do_study = 1;          switch (*pp++)
         if (*pp == '+')  
3402            {            {
3403            study_options |= PCRE_STUDY_JIT_COMPILE;            case 'S':
3404            pp++;            do_study = 0;
3405              no_force_study = 1;
3406              break;
3407    
3408              case '!':
3409              study_options |= PCRE_STUDY_EXTRA_NEEDED;
3410              break;
3411    
3412              case '+':
3413              if (*pp == '+')
3414                {
3415                verify_jit = TRUE;
3416                pp++;
3417                }
3418              if (*pp >= '1' && *pp <= '7')
3419                study_options |= jit_study_bits[*pp++ - '1'];
3420              else
3421                study_options |= jit_study_bits[6];
3422              break;
3423    
3424              case '-':
3425              study_options &= ~PCRE_STUDY_ALLJIT;
3426              break;
3427    
3428              default:
3429              pp--;
3430              goto ENDLOOP;
3431            }            }
3432          }          }
3433        else        ENDLOOP:
         {  
         do_study = 0;  
         no_force_study = 1;  
         }  
3434        break;        break;
3435    
3436        case 'U': options |= PCRE_UNGREEDY; break;        case 'U': options |= PCRE_UNGREEDY; break;
# Line 2884  while (!done) Line 3549  while (!done)
3549  #endif  /* !defined NOPOSIX */  #endif  /* !defined NOPOSIX */
3550    
3551      {      {
3552      /* In 16-bit mode, convert the input. */      /* In 16- or 32-bit mode, convert the input. */
3553    
3554  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3555      if (use_pcre16)      if (pcre_mode == PCRE16_MODE)
3556        {        {
3557        switch(to16(FALSE, p, options & PCRE_UTF8, (int)strlen((char *)p)))        switch(to16(FALSE, p, options & PCRE_UTF8, (int)strlen((char *)p)))
3558          {          {
# Line 2913  while (!done) Line 3578  while (!done)
3578        }        }
3579  #endif  #endif
3580    
3581    #ifdef SUPPORT_PCRE32
3582        if (pcre_mode == PCRE32_MODE)
3583          {
3584          switch(to32(FALSE, p, options & PCRE_UTF32, (int)strlen((char *)p)))
3585            {
3586            case -1:
3587            fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "
3588              "converted to UTF-32\n");
3589            goto SKIP_DATA;
3590    
3591            case -2:
3592            fprintf(outfile, "**Failed: character value greater than 0x10ffff "
3593              "cannot be converted to UTF-32\n");
3594            goto SKIP_DATA;
3595    
3596            case -3:
3597            fprintf(outfile, "**Failed: character value is ill-formed UTF-32\n");
3598            goto SKIP_DATA;
3599    
3600            default:
3601            break;
3602            }
3603          p = (pcre_uint8 *)buffer32;
3604          }
3605    #endif
3606    
3607      /* Compile many times when timing */      /* Compile many times when timing */
3608    
3609      if (timeit > 0)      if (timeit > 0)
# Line 2970  while (!done) Line 3661  while (!done)
3661      /* Extract the size for possible writing before possibly flipping it,      /* Extract the size for possible writing before possibly flipping it,
3662      and remember the store that was got. */      and remember the store that was got. */
3663    
3664      true_size = ((REAL_PCRE *)re)->size;      true_size = REAL_PCRE_SIZE(re);
3665      regex_gotten_store = first_gotten_store;      regex_gotten_store = first_gotten_store;
3666    
3667      /* Output code size information if requested */      /* Output code size information if requested */
3668    
3669      if (log_store)      if (log_store)
3670          {
3671          int name_count, name_entry_size, real_pcre_size;
3672    
3673          new_info(re, NULL, PCRE_INFO_NAMECOUNT, &name_count);
3674          new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
3675    #ifdef SUPPORT_PCRE8
3676          if (REAL_PCRE_FLAGS(re) & PCRE_MODE8)
3677            real_pcre_size = sizeof(real_pcre);
3678    #endif
3679    #ifdef SUPPORT_PCRE16
3680          if (REAL_PCRE_FLAGS(re) & PCRE_MODE16)
3681            real_pcre_size = sizeof(real_pcre16);
3682    #endif
3683    #ifdef SUPPORT_PCRE32
3684          if (REAL_PCRE_FLAGS(re) & PCRE_MODE32)
3685            real_pcre_size = sizeof(real_pcre32);
3686    #endif
3687        fprintf(outfile, "Memory allocation (code space): %d\n",        fprintf(outfile, "Memory allocation (code space): %d\n",
3688          (int)(first_gotten_store -          (int)(first_gotten_store - real_pcre_size - name_count * name_entry_size));
3689                sizeof(REAL_PCRE) -        }
               ((REAL_PCRE *)re)->name_count * ((REAL_PCRE *)re)->name_entry_size));  
3690    
3691      /* 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
3692      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 2995  while (!done) Line 3702  while (!done)
3702          clock_t start_time = clock();          clock_t start_time = clock();
3703          for (i = 0; i < timeit; i++)          for (i = 0; i < timeit; i++)
3704            {            {
3705            PCRE_STUDY(extra, re, study_options | force_study_options, &error);            PCRE_STUDY(extra, re, study_options, &error);
3706            }            }
3707          time_taken = clock() - start_time;          time_taken = clock() - start_time;
3708          if (extra != NULL)          if (extra != NULL)
# Line 3006  while (!done) Line 3713  while (!done)
3713            (((double)time_taken * 1000.0) / (double)timeit) /            (((double)time_taken * 1000.0) / (double)timeit) /
3714              (double)CLOCKS_PER_SEC);              (double)CLOCKS_PER_SEC);
3715          }          }
3716        PCRE_STUDY(extra, re, study_options | force_study_options, &error);        PCRE_STUDY(extra, re, study_options, &error);
3717        if (error != NULL)        if (error != NULL)
3718          fprintf(outfile, "Failed to study: %s\n", error);          fprintf(outfile, "Failed to study: %s\n", error);
3719        else if (extra != NULL)        else if (extra != NULL)
# Line 3050  while (!done) Line 3757  while (!done)
3757      if (do_showinfo)      if (do_showinfo)
3758        {        {
3759        unsigned long int all_options;        unsigned long int all_options;
3760        int count, backrefmax, first_char, need_char, okpartial, jchanged,        pcre_uint32 first_char, need_char;
3761          hascrorlf;        int count, backrefmax, first_char_set, need_char_set, okpartial, jchanged,
3762            hascrorlf, maxlookbehind;
3763        int nameentrysize, namecount;        int nameentrysize, namecount;
3764        const pcre_uint8 *nametable;        const pcre_uint8 *nametable;
3765    
3766        if (new_info(re, NULL, PCRE_INFO_SIZE, &size) +        if (new_info(re, NULL, PCRE_INFO_SIZE, &size) +
3767            new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) +            new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) +
3768            new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax) +            new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax) +
3769            new_info(re, NULL, PCRE_INFO_FIRSTBYTE, &first_char) +            new_info(re, NULL, PCRE_INFO_FIRSTLITERAL, &first_char) +
3770            new_info(re, NULL, PCRE_INFO_LASTLITERAL, &need_char) +            new_info(re, NULL, PCRE_INFO_FIRSTLITERALSET, &first_char_set) +
3771              new_info(re, NULL, PCRE_INFO_LASTLITERAL2, &need_char) +
3772              new_info(re, NULL, PCRE_INFO_LASTLITERAL2SET, &need_char_set) +
3773            new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize) +            new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize) +
3774            new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount) +            new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount) +
3775            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +
3776            new_info(re, NULL, PCRE_INFO_OKPARTIAL, &okpartial) +            new_info(re, NULL, PCRE_INFO_OKPARTIAL, &okpartial) +
3777            new_info(re, NULL, PCRE_INFO_JCHANGED, &jchanged) +            new_info(re, NULL, PCRE_INFO_JCHANGED, &jchanged) +
3778            new_info(re, NULL, PCRE_INFO_HASCRORLF, &hascrorlf)            new_info(re, NULL, PCRE_INFO_HASCRORLF, &hascrorlf) +
3779              new_info(re, NULL, PCRE_INFO_MAXLOOKBEHIND, &maxlookbehind)
3780            != 0)            != 0)
3781          goto SKIP_DATA;          goto SKIP_DATA;
3782    
# Line 3082  while (!done) Line 3793  while (!done)
3793          fprintf(outfile, "Named capturing subpatterns:\n");          fprintf(outfile, "Named capturing subpatterns:\n");
3794          while (namecount-- > 0)          while (namecount-- > 0)
3795            {            {
3796  #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  
3797            int length = (int)STRLEN(nametable + imm2_size);            int length = (int)STRLEN(nametable + imm2_size);
3798            fprintf(outfile, "  ");            fprintf(outfile, "  ");
3799            PCHARSV(nametable, imm2_size, length, outfile);            PCHARSV(nametable, imm2_size, length, outfile);
3800            while (length++ < nameentrysize - imm2_size) putc(' ', outfile);            while (length++ < nameentrysize - imm2_size) putc(' ', outfile);
3801  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE32
3802            fprintf(outfile, "%3d\n", use_pcre16?            if (pcre_mode == PCRE32_MODE)
3803               (int)(((PCRE_SPTR16)nametable)[0])              fprintf(outfile, "%3d\n", (int)(((PCRE_SPTR32)nametable)[0]));
3804              :((int)nametable[0] << 8) | (int)nametable[1]);  #endif
3805            nametable += nameentrysize * (use_pcre16 ? 2 : 1);  #ifdef SUPPORT_PCRE16
3806  #else            if (pcre_mode == PCRE16_MODE)
3807            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;  
3808  #endif  #endif
3809    #ifdef SUPPORT_PCRE8
3810              if (pcre_mode == PCRE8_MODE)
3811                fprintf(outfile, "%3d\n", ((int)nametable[0] << 8) | (int)nametable[1]);
3812  #endif  #endif
3813              nametable += nameentrysize * CHAR_SIZE;
3814            }            }
3815          }          }
3816    
3817        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");
3818        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");
3819    
3820        all_options = ((REAL_PCRE *)re)->options;        all_options = REAL_PCRE_OPTIONS(re);
3821        if (do_flip) all_options = swap_uint32(all_options);        if (do_flip) all_options = swap_uint32(all_options);
3822    
3823        if (get_options == 0) fprintf(outfile, "No options\n");        if (get_options == 0) fprintf(outfile, "No options\n");
# Line 3161  while (!done) Line 3868  while (!done)
3868          break;          break;
3869          }          }
3870    
3871        if (first_char == -1)        if (first_char_set == 2)
3872          {          {
3873          fprintf(outfile, "First char at start or follows newline\n");          fprintf(outfile, "First char at start or follows newline\n");
3874          }          }
3875        else if (first_char < 0)        else if (first_char_set == 1)
         {  
         fprintf(outfile, "No first char\n");  
         }  
       else  
3876          {          {
3877          const char *caseless =          const char *caseless =
3878            ((((REAL_PCRE *)re)->flags & PCRE_FCH_CASELESS) == 0)?            ((REAL_PCRE_FLAGS(re) & PCRE_FCH_CASELESS) == 0)?
3879            "" : " (caseless)";            "" : " (caseless)";
3880    
3881          if (PRINTOK(first_char))          if (PRINTOK(first_char))
# Line 3184  while (!done) Line 3887  while (!done)
3887            fprintf(outfile, "%s\n", caseless);            fprintf(outfile, "%s\n", caseless);
3888            }            }
3889          }          }
3890          else
3891            {
3892            fprintf(outfile, "No first char\n");
3893            }
3894    
3895        if (need_char < 0)        if (need_char_set == 0)
3896          {          {
3897          fprintf(outfile, "No need char\n");          fprintf(outfile, "No need char\n");
3898          }          }
3899        else        else
3900          {          {
3901          const char *caseless =          const char *caseless =
3902            ((((REAL_PCRE *)re)->flags & PCRE_RCH_CASELESS) == 0)?            ((REAL_PCRE_FLAGS(re) & PCRE_RCH_CASELESS) == 0)?
3903            "" : " (caseless)";            "" : " (caseless)";
3904    
3905          if (PRINTOK(need_char))          if (PRINTOK(need_char))
# Line 3205  while (!done) Line 3912  while (!done)
3912            }            }
3913          }          }
3914    
3915          if (maxlookbehind > 0)
3916            fprintf(outfile, "Max lookbehind = %d\n", maxlookbehind);
3917    
3918        /* 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
3919        value, but it varies, depending on the computer architecture, and        value, but it varies, depending on the computer architecture, and
3920        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 3262  while (!done) Line 3972  while (!done)
3972    
3973          /* 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. */
3974    
3975          if ((study_options & PCRE_STUDY_JIT_COMPILE) != 0)          if ((study_options & PCRE_STUDY_ALLJIT) != 0 &&
3976                (force_study_options & PCRE_STUDY_ALLJIT) == 0)
3977            {            {
3978            int jit;            int jit;
3979            if (new_info(re, extra, PCRE_INFO_JIT, &jit) == 0)            if (new_info(re, extra, PCRE_INFO_JIT, &jit) == 0)
# Line 3355  while (!done) Line 4066  while (!done)
4066      int use_size_offsets = size_offsets;      int use_size_offsets = size_offsets;
4067      int callout_data = 0;      int callout_data = 0;
4068      int callout_data_set = 0;      int callout_data_set = 0;
4069      int count, c;      int count;
4070        pcre_uint32 c;
4071      int copystrings = 0;      int copystrings = 0;
4072      int find_match_limit = default_find_match_limit;      int find_match_limit = default_find_match_limit;
4073      int getstrings = 0;      int getstrings = 0;
# Line 3369  while (!done) Line 4081  while (!done)
4081      *copynames = 0;      *copynames = 0;
4082      *getnames = 0;      *getnames = 0;
4083    
4084      cn16ptr = copynames;  #ifdef SUPPORT_PCRE32
4085      gn16ptr = getnames;      cn32ptr = copynames;
4086        gn32ptr = getnames;
4087    #endif
4088    #ifdef SUPPORT_PCRE16
4089        cn16ptr = copynames16;
4090        gn16ptr = getnames16;
4091    #endif
4092    #ifdef SUPPORT_PCRE8
4093      cn8ptr = copynames8;      cn8ptr = copynames8;
4094      gn8ptr = getnames8;      gn8ptr = getnames8;
4095    #endif
4096    
4097      SET_PCRE_CALLOUT(callout);      SET_PCRE_CALLOUT(callout);
4098      first_callout = 1;      first_callout = 1;
# Line 3421  while (!done) Line 4141  while (!done)
4141        /* 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.
4142        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,
4143        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
4144        16-bit mode. */        16-bit or 32-bit mode. */
4145    
4146        if (c != '\\')        if (c != '\\')
4147          {          {
# Line 3464  while (!done) Line 4184  while (!done)
4184            least one MacOS environment. */            least one MacOS environment. */
4185    
4186            for (pt++; isxdigit(*pt); pt++)            for (pt++; isxdigit(*pt); pt++)
4187              c = c * 16 + tolower(*pt) - ((isdigit(*pt))? '0' : 'a' - 10);              {
4188                if (++i == 9)
4189                  fprintf(outfile, "** Too many hex digits in \\x{...} item; "
4190                                   "using only the first eight.\n");
4191                else c = c * 16 + tolower(*pt) - ((isdigit(*pt))? '0' : 'a' - 10);
4192                }
4193            if (*pt == '}')            if (*pt == '}')
4194              {              {
4195              p = pt + 1;              p = pt + 1;
# Line 3477  while (!done) Line 4202  while (!done)
4202          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
4203          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.
4204          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
4205          UTF-8 when running in 16-bit mode. */          UTF-8 when running in 16/32-bit mode. */
4206    
4207          c = 0;          c = 0;
4208          while (i++ < 2 && isxdigit(*p))          while (i++ < 2 && isxdigit(*p))
# Line 3522  while (!done) Line 4247  while (!done)
4247            }            }
4248          else if (isalnum(*p))          else if (isalnum(*p))
4249            {            {
4250            READ_CAPTURE_NAME(p, &cn8ptr, &cn16ptr, re);            READ_CAPTURE_NAME(p, &cn8ptr, &cn16ptr, &cn32ptr, re);
4251            }            }
4252          else if (*p == '+')          else if (*p == '+')
4253            {            {
# Line 3585  while (!done) Line 4310  while (!done)
4310            }            }
4311          else if (isalnum(*p))          else if (isalnum(*p))
4312            {            {
4313            READ_CAPTURE_NAME(p, &gn8ptr, &gn16ptr, re);            READ_CAPTURE_NAME(p, &gn8ptr, &gn16ptr, &gn32ptr, re);
4314            }            }
4315          continue;          continue;
4316    
# Line 3633  while (!done) Line 4358  while (!done)
4358            }            }
4359          use_size_offsets = n;          use_size_offsets = n;
4360          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 */
4361              else use_offsets = offsets + size_offsets_max - n;  /* To catch overruns */
4362          continue;          continue;
4363    
4364          case 'P':          case 'P':
# Line 3695  while (!done) Line 4421  while (!done)
4421          }          }
4422    
4423        /* 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
4424        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
4425        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.
4426        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
4427        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
4428        \x.. get this far only in non-UTF mode. */        because values from \x.. get this far only in non-UTF mode. */
4429    
4430  #if !defined NOUTF || defined SUPPORT_PCRE16  #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32
4431        if (use_pcre16 || use_utf)        if (pcre_mode != PCRE8_MODE || use_utf)
4432          {          {
4433          pcre_uint8 buff8[8];          pcre_uint8 buff8[8];
4434          int ii, utn;          int ii, utn;
# Line 3773  while (!done) Line 4499  while (!done)
4499          (void)regerror(rc, &preg, (char *)buffer, buffer_size);          (void)regerror(rc, &preg, (char *)buffer, buffer_size);
4500          fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);          fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);
4501          }          }
4502        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)  
4503          {          {
4504          fprintf(outfile, "Matched with REG_NOSUB\n");          fprintf(outfile, "Matched with REG_NOSUB\n");
4505          }          }
# Line 3808  while (!done) Line 4533  while (!done)
4533      /* Handle matching via the native interface - repeats for /g and /G */      /* Handle matching via the native interface - repeats for /g and /G */
4534    
4535  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
4536      if (use_pcre16)      if (pcre_mode == PCRE16_MODE)
4537        {        {
4538        len = to16(TRUE, bptr, (((REAL_PCRE *)re)->options) & PCRE_UTF8, len);        len = to16(TRUE, bptr, REAL_PCRE_OPTIONS(re) & PCRE_UTF8, len);
4539        switch(len)        switch(len)
4540          {          {
4541          case -1:          case -1:
# Line 3835  while (!done) Line 4560  while (!done)
4560        }        }
4561  #endif  #endif
4562    
4563    #ifdef SUPPORT_PCRE32
4564        if (pcre_mode == PCRE32_MODE)
4565          {
4566          len = to32(TRUE, bptr, REAL_PCRE_OPTIONS(re) & PCRE_UTF32, len);
4567          switch(len)
4568            {
4569            case -1:
4570            fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "
4571              "converted to UTF-32\n");
4572            goto NEXT_DATA;
4573    
4574            case -2:
4575            fprintf(outfile, "**Failed: character value greater than 0x10ffff "
4576              "cannot be converted to UTF-32\n");
4577            goto NEXT_DATA;
4578    
4579            case -3:
4580            fprintf(outfile, "**Failed: character value is ill-formed UTF-32\n");
4581            goto NEXT_DATA;
4582    
4583            default:
4584            break;
4585            }
4586          bptr = (pcre_uint8 *)buffer32;
4587          }
4588    #endif
4589    
4590        /* Ensure that there is a JIT callback if we want to verify that JIT was
4591        actually used. If jit_stack == NULL, no stack has yet been assigned. */
4592    
4593        if (verify_jit && jit_stack == NULL && extra != NULL)
4594           { PCRE_ASSIGN_JIT_STACK(extra, jit_callback, jit_stack); }
4595    
4596      for (;; gmatched++)    /* Loop for /g or /G */      for (;; gmatched++)    /* Loop for /g or /G */
4597        {        {
4598        markptr = NULL;        markptr = NULL;
4599          jit_was_used = FALSE;
4600    
4601        if (timeitm > 0)        if (timeitm > 0)
4602          {          {
# Line 3848  while (!done) Line 4607  while (!done)
4607  #if !defined NODFA  #if !defined NODFA
4608          if (all_use_dfa || use_dfa)          if (all_use_dfa || use_dfa)
4609            {            {
4610            int workspace[1000];            if ((options & PCRE_DFA_RESTART) != 0)
4611                {
4612                fprintf(outfile, "Timing DFA restarts is not supported\n");
4613                break;
4614                }
4615              if (dfa_workspace == NULL)
4616                dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
4617            for (i = 0; i < timeitm; i++)            for (i = 0; i < timeitm; i++)
4618              {              {
4619              PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,              PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
4620                (options | g_notempty), use_offsets, use_size_offsets, workspace,                (options | g_notempty), use_offsets, use_size_offsets,
4621                (sizeof(workspace)/sizeof(int)));                dfa_workspace, DFA_WS_DIMENSION);
4622              }              }
4623            }            }
4624          else          else
# Line 3879  while (!done) Line 4644  while (!done)
4644    
4645        if (find_match_limit)        if (find_match_limit)
4646          {          {
4647          if (extra == NULL)          if (extra != NULL) { PCRE_FREE_STUDY(extra); }
4648            {          extra = (pcre_extra *)malloc(sizeof(pcre_extra));
4649            extra = (pcre_extra *)malloc(sizeof(pcre_extra));          extra->flags = 0;
           extra->flags = 0;  
           }  
         else extra->flags &= ~PCRE_EXTRA_EXECUTABLE_JIT;  
4650    
4651          (void)check_match_limit(re, extra, bptr, len, start_offset,          (void)check_match_limit(re, extra, bptr, len, start_offset,
4652            options|g_notempty, use_offsets, use_size_offsets,            options|g_notempty, use_offsets, use_size_offsets,
# Line 3919  while (!done) Line 4681  while (!done)
4681  #if !defined NODFA  #if !defined NODFA
4682        else if (all_use_dfa || use_dfa)        else if (all_use_dfa || use_dfa)
4683          {          {
4684          int workspace[1000];          if (dfa_workspace == NULL)
4685              dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
4686            if (dfa_matched++ == 0)
4687              dfa_workspace[0] = -1;  /* To catch bad restart */
4688          PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,          PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
4689            (options | g_notempty), use_offsets, use_size_offsets, workspace,            (options | g_notempty), use_offsets, use_size_offsets, dfa_workspace,
4690            (sizeof(workspace)/sizeof(int)));            DFA_WS_DIMENSION);
4691          if (count == 0)          if (count == 0)
4692            {            {
4693            fprintf(outfile, "Matched, but too many subsidiary matches\n");            fprintf(outfile, "Matched, but too many subsidiary matches\n");
# Line 3999  while (!done) Line 4764  while (!done)
4764              fprintf(outfile, "%2d: ", i/2);              fprintf(outfile, "%2d: ", i/2);
4765              PCHARSV(bptr, use_offsets[i],              PCHARSV(bptr, use_offsets[i],
4766                use_offsets[i+1] - use_offsets[i], outfile);                use_offsets[i+1] - use_offsets[i], outfile);
4767                if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
4768              fprintf(outfile, "\n");              fprintf(outfile, "\n");
4769              if (do_showcaprest || (i == 0 && do_showrest))              if (do_showcaprest || (i == 0 && do_showrest))
4770                {                {
# Line 4042  while (!done) Line 4808  while (!done)
4808            int rc;            int rc;
4809            char copybuffer[256];            char copybuffer[256];
4810    
4811            if (use_pcre16)            if (pcre_mode == PCRE16_MODE)
4812              {              {
4813              if (*(pcre_uint16 *)cnptr == 0) break;              if (*(pcre_uint16 *)cnptr == 0) break;
4814              }              }
# Line 4097  while (!done) Line 4863  while (!done)
4863            int rc;            int rc;
4864            const char *substring;            const char *substring;
4865    
4866            if (use_pcre16)            if (pcre_mode == PCRE16_MODE)
4867              {              {
4868              if (*(pcre_uint16 *)gnptr == 0) break;              if (*(pcre_uint16 *)gnptr == 0) break;
4869              }              }
# Line 4165  while (!done) Line 4931  while (!done)
4931            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],
4932              outfile);              outfile);
4933            }            }
4934            if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
4935          fprintf(outfile, "\n");          fprintf(outfile, "\n");
4936          break;  /* Out of the /g loop */          break;  /* Out of the /g loop */
4937          }          }
# Line 4190  while (!done) Line 4957  while (!done)
4957          if (g_notempty != 0)          if (g_notempty != 0)
4958            {            {
4959            int onechar = 1;            int onechar = 1;
4960            unsigned int obits = ((REAL_PCRE *)re)->options;            unsigned int obits = REAL_PCRE_OPTIONS(re);
4961            use_offsets[0] = start_offset;            use_offsets[0] = start_offset;
4962            if ((obits & PCRE_NEWLINE_BITS) == 0)            if ((obits & PCRE_NEWLINE_BITS) == 0)
4963              {              {
# Line 4208  while (!done) Line 4975  while (!done)
4975                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||
4976                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)
4977                &&                &&
4978                start_offset < len - 1 &&                start_offset < len - 1 && (
4979  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE8
4980                (use_pcre16?                (pcre_mode == PCRE8_MODE &&
4981                     ((PCRE_SPTR16)bptr)[start_offset] == '\r'                 bptr[start_offset] == '\r' &&
4982                  && ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n'                 bptr[start_offset + 1] == '\n') ||
               :  
                    bptr[start_offset] == '\r'  
                 && bptr[start_offset + 1] == '\n')  
 #elif defined SUPPORT_PCRE16  
                  ((PCRE_SPTR16)bptr)[start_offset] == '\r'  
               && ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n'  
 #else  
                  bptr[start_offset] == '\r'  
               && bptr[start_offset + 1] == '\n'  
4983  #endif  #endif
4984                )  #ifdef SUPPORT_PCRE16
4985                  (pcre_mode == PCRE16_MODE &&
4986                   ((PCRE_SPTR16)bptr)[start_offset] == '\r' &&
4987                   ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n') ||
4988    #endif
4989    #ifdef SUPPORT_PCRE32
4990                  (pcre_mode == PCRE32_MODE &&
4991                   ((PCRE_SPTR32)bptr)[start_offset] == '\r' &&
4992                   ((PCRE_SPTR32)bptr)[start_offset + 1] == '\n') ||
4993    #endif
4994                  0))
4995              onechar++;              onechar++;
4996            else if (use_utf)            else if (use_utf)
4997              {              {
# Line 4244  while (!done) Line 5012  while (!done)
5012                {                {
5013                if (markptr == NULL)                if (markptr == NULL)
5014                  {                  {
5015                  fprintf(outfile, "No match\n");                  fprintf(outfile, "No match");
5016                  }                  }
5017                else                else
5018                  {                  {
5019                  fprintf(outfile, "No match, mark = ");                  fprintf(outfile, "No match, mark = ");
5020                  PCHARSV(markptr, 0, -1, outfile);                  PCHARSV(markptr, 0, -1, outfile);
                 putc('\n', outfile);  
5021                  }                  }
5022                  if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
5023                  putc('\n', outfile);
5024                }                }
5025              break;              break;
5026    
5027              case PCRE_ERROR_BADUTF8:              case PCRE_ERROR_BADUTF8:
5028              case PCRE_ERROR_SHORTUTF8:              case PCRE_ERROR_SHORTUTF8:
5029              fprintf(outfile, "Error %d (%s UTF-%s string)", count,              fprintf(outfile, "Error %d (%s UTF-%d string)", count,
5030                (count == PCRE_ERROR_BADUTF8)? "bad" : "short",                (count == PCRE_ERROR_BADUTF8)? "bad" : "short",
5031                use_pcre16? "16" : "8");                8 * CHAR_SIZE);
5032              if (use_size_offsets >= 2)              if (use_size_offsets >= 2)
5033                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],
5034                  use_offsets[1]);                  use_offsets[1]);
# Line 4267  while (!done) Line 5036  while (!done)
5036              break;              break;
5037    
5038              case PCRE_ERROR_BADUTF8_OFFSET:              case PCRE_ERROR_BADUTF8_OFFSET:
5039              fprintf(outfile, "Error %d (bad UTF-%s offset)\n", count,              fprintf(outfile, "Error %d (bad UTF-%d offset)\n", count,
5040                use_pcre16? "16" : "8");                8 * CHAR_SIZE);
5041              break;              break;
5042    
5043              default:              default:
5044              if (count < 0 && (-count) < sizeof(errtexts)/sizeof(const char *))              if (count < 0 &&
5045                    (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))
5046                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);
5047              else              else
5048                fprintf(outfile, "Error %d (Unexpected value)\n", count);                fprintf(outfile, "Error %d (Unexpected value)\n", count);
# Line 4357  free(offsets); Line 5127  free(offsets);
5127  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
5128  if (buffer16 != NULL) free(buffer16);  if (buffer16 != NULL) free(buffer16);
5129  #endif  #endif
5130    #ifdef SUPPORT_PCRE32
5131    if (buffer32 != NULL) free(buffer32);
5132    #endif
5133    
5134    #if !defined NODFA
5135    if (dfa_workspace != NULL)
5136      free(dfa_workspace);
5137    #endif
5138    
5139  return yield;  return yield;
5140  }  }

Legend:
Removed from v.860  
changed lines
  Added in v.1087

  ViewVC Help
Powered by ViewVC 1.1.5