/[pcre]/code/trunk/pcretest.c
ViewVC logotype

Diff of /code/trunk/pcretest.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 908 by ph10, Mon Jan 30 12:19:29 2012 UTC revision 1079 by chpe, Tue Oct 16 15:55:04 2012 UTC
# Line 46  pcre_internal.h that depend on COMPILE_P Line 46  pcre_internal.h that depend on COMPILE_P
46  however, make use of SUPPORT_PCRE8 and SUPPORT_PCRE16 to ensure that it calls  however, make use of SUPPORT_PCRE8 and SUPPORT_PCRE16 to ensure that it calls
47  only supported library functions. */  only supported library functions. */
48    
   
49  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
50  #include "config.h"  #include "config.h"
51  #endif  #endif
# Line 59  only supported library functions. */ Line 58  only supported library functions. */
58  #include <locale.h>  #include <locale.h>
59  #include <errno.h>  #include <errno.h>
60    
61  #ifdef SUPPORT_LIBREADLINE  /* Both libreadline and libedit are optionally supported. The user-supplied
62    original patch uses readline/readline.h for libedit, but in at least one system
63    it is installed as editline/readline.h, so the configuration code now looks for
64    that first, falling back to readline/readline.h. */
65    
66    #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
67  #ifdef HAVE_UNISTD_H  #ifdef HAVE_UNISTD_H
68  #include <unistd.h>  #include <unistd.h>
69  #endif  #endif
70    #if defined(SUPPORT_LIBREADLINE)
71  #include <readline/readline.h>  #include <readline/readline.h>
72  #include <readline/history.h>  #include <readline/history.h>
73    #else
74    #if defined(HAVE_EDITLINE_READLINE_H)
75    #include <editline/readline.h>
76    #else
77    #include <readline/readline.h>
78    #endif
79    #endif
80  #endif  #endif
   
81    
82  /* A number of things vary for Windows builds. Originally, pcretest opened its  /* A number of things vary for Windows builds. Originally, pcretest opened its
83  input and output without "b"; then I was told that "b" was needed in some  input and output without "b"; then I was told that "b" was needed in some
# Line 101  input mode under Windows. */ Line 112  input mode under Windows. */
112  #else  #else
113  #include <sys/time.h>          /* These two includes are needed */  #include <sys/time.h>          /* These two includes are needed */
114  #include <sys/resource.h>      /* for setrlimit(). */  #include <sys/resource.h>      /* for setrlimit(). */
115    #if defined NATIVE_ZOS         /* z/OS uses non-binary I/O */
116    #define INPUT_MODE   "r"
117    #define OUTPUT_MODE  "w"
118    #else
119  #define INPUT_MODE   "rb"  #define INPUT_MODE   "rb"
120  #define OUTPUT_MODE  "wb"  #define OUTPUT_MODE  "wb"
121  #endif  #endif
122    #endif
123    
124  #define PRIV(name) name  #define PRIV(name) name
125    
# Line 118  appropriately for an application, not fo Line 134  appropriately for an application, not fo
134    
135  #include "pcre.h"  #include "pcre.h"
136    
137  #if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8  #if defined SUPPORT_PCRE32 && !defined SUPPORT_PCRE8 && !defined SUPPORT_PCRE16
138    /* Configure internal macros to 32 bit mode. */
139    #define COMPILE_PCRE32
140    #endif
141    #if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8 && !defined SUPPORT_PCRE32
142  /* Configure internal macros to 16 bit mode. */  /* Configure internal macros to 16 bit mode. */
143  #define COMPILE_PCRE16  #define COMPILE_PCRE16
144  #endif  #endif
145    #if defined SUPPORT_PCRE8 && !defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE32
146    /* Configure internal macros to 16 bit mode. */
147    #define COMPILE_PCRE8
148    #endif
149    
150  #include "pcre_internal.h"  #include "pcre_internal.h"
151    
# Line 136  void pcre_printint(pcre *external_re, FI Line 160  void pcre_printint(pcre *external_re, FI
160  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
161  void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths);  void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths);
162  #endif  #endif
163    #ifdef SUPPORT_PCRE32
164    void pcre32_printint(pcre *external_re, FILE *f, BOOL print_lengths);
165    #endif
166    
167  /* We need access to some of the data tables that PCRE uses. So as not to have  /* We need access to some of the data tables that PCRE uses. So as not to have
168  to keep two copies, we include the source file here, changing the names of the  to keep two copies, we include the source files here, changing the names of the
169  external symbols to prevent clashes. */  external symbols to prevent clashes. */
170    
171  #define PCRE_INCLUDED  #define PCRE_INCLUDED
172    
173  #include "pcre_tables.c"  #include "pcre_tables.c"
174    #include "pcre_ucd.c"
175    
176  /* The definition of the macro PRINTABLE, which determines whether to print an  /* The definition of the macro PRINTABLE, which determines whether to print an
177  output character as-is or as a hex value when showing compiled patterns, is  output character as-is or as a hex value when showing compiled patterns, is
# Line 159  that differ in their output from isprint Line 187  that differ in their output from isprint
187    
188  #define PRINTOK(c) (locale_set? isprint(c) : PRINTABLE(c))  #define PRINTOK(c) (locale_set? isprint(c) : PRINTABLE(c))
189    
190  /* Posix support is disabled in 16 bit only mode. */  /* Posix support is disabled in 16 or 32 bit only mode. */
191  #if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8 && !defined NOPOSIX  #if !defined SUPPORT_PCRE8 && !defined NOPOSIX
192  #define NOPOSIX  #define NOPOSIX
193  #endif  #endif
194    
# Line 205  argument, the casting might be incorrect Line 233  argument, the casting might be incorrect
233  #define PCHARSV8(p, offset, len, f) \  #define PCHARSV8(p, offset, len, f) \
234    (void)pchars((pcre_uint8 *)(p) + offset, len, f)    (void)pchars((pcre_uint8 *)(p) + offset, len, f)
235    
236  #define READ_CAPTURE_NAME8(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME8(p, cn8, cn16, cn32, re) \
237    p = read_capture_name8(p, cn8, re)    p = read_capture_name8(p, cn8, re)
238    
239  #define STRLEN8(p) ((int)strlen((char *)p))  #define STRLEN8(p) ((int)strlen((char *)p))
# Line 287  argument, the casting might be incorrect Line 315  argument, the casting might be incorrect
315  #define PCHARSV16(p, offset, len, f) \  #define PCHARSV16(p, offset, len, f) \
316    (void)pchars16((PCRE_SPTR16)(p) + offset, len, f)    (void)pchars16((PCRE_SPTR16)(p) + offset, len, f)
317    
318  #define READ_CAPTURE_NAME16(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME16(p, cn8, cn16, cn32, re) \
319    p = read_capture_name16(p, cn16, re)    p = read_capture_name16(p, cn16, re)
320    
321  #define STRLEN16(p) ((int)strlen16((PCRE_SPTR16)p))  #define STRLEN16(p) ((int)strlen16((PCRE_SPTR16)p))
# Line 366  argument, the casting might be incorrect Line 394  argument, the casting might be incorrect
394    
395  #endif /* SUPPORT_PCRE16 */  #endif /* SUPPORT_PCRE16 */
396    
397    /* -----------------------------------------------------------*/
398    
399    #ifdef SUPPORT_PCRE32
400    
401    #define PCHARS32(lv, p, offset, len, f) \
402      lv = pchars32((PCRE_SPTR32)(p) + offset, len, 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 417  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 425  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 441  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 449  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 476  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 557  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 584  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 599  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 613  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 630  static pcre_uint8 *pbuffer = NULL; Line 837  static pcre_uint8 *pbuffer = NULL;
837  /* Another buffer is needed translation to 16-bit character strings. It will  /* Another buffer is needed translation to 16-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 659  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 705  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 1057  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 1127  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 1239  return pp - buffer16; Line 1512  return pp - buffer16;
1512  }  }
1513  #endif  #endif
1514    
1515    #ifdef SUPPORT_PCRE32
1516    /*************************************************
1517    *         Convert a string to 32-bit             *
1518    *************************************************/
1519    
1520    /* In non-UTF mode, the space needed for a 32-bit string is exactly four times the
1521    8-bit size. For a UTF-8 string, the size needed for UTF-32 is no more than four
1522    times, because up to 0xffff uses no more than 3 bytes in UTF-8 but possibly 4
1523    in UTF-32. Higher values use 4 bytes in UTF-8 and up to 4 bytes in UTF-32. The
1524    result is always left in buffer32.
1525    
1526    Note that this function does not object to surrogate values. This is
1527    deliberate; it makes it possible to construct UTF-32 strings that are invalid,
1528    for the purpose of testing that they are correctly faulted.
1529    
1530    Patterns to be converted are either plain ASCII or UTF-8; data lines are always
1531    in UTF-8 so that values greater than 255 can be handled.
1532    
1533    Arguments:
1534      data       TRUE if converting a data line; FALSE for a regex
1535      p          points to a byte string
1536      utf        true if UTF-8 (to be converted to UTF-32)
1537      len        number of bytes in the string (excluding trailing zero)
1538    
1539    Returns:     number of 32-bit data items used (excluding trailing zero)
1540                 OR -1 if a UTF-8 string is malformed
1541                 OR -2 if a value > 0x10ffff is encountered
1542                 OR -3 if an ill-formed value is encountered (i.e. a surrogate)
1543    */
1544    
1545    static int
1546    to32(int data, pcre_uint8 *p, int utf, int len)
1547    {
1548    pcre_uint32 *pp;
1549    
1550    if (buffer32_size < 4*len + 4)
1551      {
1552      if (buffer32 != NULL) free(buffer32);
1553      buffer32_size = 4*len + 4;
1554      buffer32 = (pcre_uint32 *)malloc(buffer32_size);
1555      if (buffer32 == NULL)
1556        {
1557        fprintf(stderr, "pcretest: malloc(%d) failed for buffer32\n", buffer32_size);
1558        exit(1);
1559        }
1560      }
1561    
1562    pp = buffer32;
1563    
1564    if (!utf && !data)
1565      {
1566      while (len-- > 0) *pp++ = *p++;
1567      }
1568    
1569    else
1570      {
1571      int c = 0;
1572      while (len > 0)
1573        {
1574        int chlen = utf82ord(p, &c);
1575        if (chlen <= 0) return -1;
1576        if (utf)
1577          {
1578          if (c > 0x10ffff) return -2;
1579          if (!data && (c & 0xfffff800u) == 0xd800u) return -3;
1580          }
1581    
1582        p += chlen;
1583        len -= chlen;
1584        *pp++ = c;
1585        }
1586      }
1587    
1588    *pp = 0;
1589    return pp - buffer32;
1590    }
1591    #endif
1592    
1593  /*************************************************  /*************************************************
1594  *        Read or extend an input line            *  *        Read or extend an input line            *
# Line 1276  for (;;) Line 1626  for (;;)
1626      {      {
1627      int dlen;      int dlen;
1628    
1629      /* 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
1630      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
1631      we must put it back again, to be compatible with fgets(). */      newline, so we must put it back again, to be compatible with fgets(). */
1632    
1633  #ifdef SUPPORT_LIBREADLINE  #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
1634      if (isatty(fileno(f)))      if (isatty(fileno(f)))
1635        {        {
1636        size_t len;        size_t len;
# Line 1379  return(result); Line 1729  return(result);
1729    
1730  /* Print a single character either literally, or as a hex escape. */  /* Print a single character either literally, or as a hex escape. */
1731    
1732  static int pchar(int c, FILE *f)  static int pchar(pcre_uint32 c, FILE *f)
1733  {  {
1734  if (PRINTOK(c))  if (PRINTOK(c))
1735    {    {
# Line 1465  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 1482  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 1504  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 1557  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 1714  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 1731  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 1747  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 1799  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 1839  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 1977  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 2096  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");
# Line 2105  printf("\nOptions:\n"); Line 2644  printf("\nOptions:\n");
2644  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2645  printf("  -16      use the 16-bit library\n");  printf("  -16      use the 16-bit library\n");
2646  #endif  #endif
2647    #ifdef SUPPORT_PCRE32
2648    printf("  -32      use the 32-bit library\n");
2649    #endif
2650  printf("  -b       show compiled code\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");
# Line 2112  printf("           and exit with its val Line 2654  printf("           and exit with its val
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 2132  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 2166  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. */  for the actual memory, to ensure alignment. */
2737    
2738  pcre_uint16 copynames[1024];  pcre_uint32 copynames[1024];
2739  pcre_uint16 getnames[1024];  pcre_uint32 getnames[1024];
2740    
2741    #ifdef SUPPORT_PCRE32
2742    pcre_uint32 *cn32ptr;
2743    pcre_uint32 *gn32ptr;
2744    #endif
2745    
2746  #ifdef SUPPORT_PCRE16  #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  #endif
# Line 2199  pcre_uint8 *gn8ptr; Line 2758  pcre_uint8 *gn8ptr;
2758  #endif  #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 2222  _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 2233  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 2279  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 2302  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 2316  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 2327  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 2338  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);
# Line 2417  are set, either both UTFs are supported Line 3025  are set, either both UTFs are supported
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 2444  are set, either both UTFs are supported Line 3047  are set, either both UTFs are supported
3047      printf("\n");      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 2513  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 2550  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 2597  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 2611  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 2640  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 2658  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 2726  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 2763  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 2895  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 2924  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 2981  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 3006  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 3017  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 3062  while (!done) Line 3758  while (!done)
3758        {        {
3759        unsigned long int all_options;        unsigned long int all_options;
3760        int count, backrefmax, first_char, need_char, okpartial, jchanged,        int count, backrefmax, first_char, need_char, okpartial, jchanged,
3761          hascrorlf;          hascrorlf, maxlookbehind;
3762        int nameentrysize, namecount;        int nameentrysize, namecount;
3763        const pcre_uint8 *nametable;        const pcre_uint8 *nametable;
3764    
# Line 3076  while (!done) Line 3772  while (!done)
3772            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +
3773            new_info(re, NULL, PCRE_INFO_OKPARTIAL, &okpartial) +            new_info(re, NULL, PCRE_INFO_OKPARTIAL, &okpartial) +
3774            new_info(re, NULL, PCRE_INFO_JCHANGED, &jchanged) +            new_info(re, NULL, PCRE_INFO_JCHANGED, &jchanged) +
3775            new_info(re, NULL, PCRE_INFO_HASCRORLF, &hascrorlf)            new_info(re, NULL, PCRE_INFO_HASCRORLF, &hascrorlf) +
3776              new_info(re, NULL, PCRE_INFO_MAXLOOKBEHIND, &maxlookbehind)
3777            != 0)            != 0)
3778          goto SKIP_DATA;          goto SKIP_DATA;
3779    
# Line 3093  while (!done) Line 3790  while (!done)
3790          fprintf(outfile, "Named capturing subpatterns:\n");          fprintf(outfile, "Named capturing subpatterns:\n");
3791          while (namecount-- > 0)          while (namecount-- > 0)
3792            {            {
3793  #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  
3794            int length = (int)STRLEN(nametable + imm2_size);            int length = (int)STRLEN(nametable + imm2_size);
3795            fprintf(outfile, "  ");            fprintf(outfile, "  ");
3796            PCHARSV(nametable, imm2_size, length, outfile);            PCHARSV(nametable, imm2_size, length, outfile);
3797            while (length++ < nameentrysize - imm2_size) putc(' ', outfile);            while (length++ < nameentrysize - imm2_size) putc(' ', outfile);
3798  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE32
3799            fprintf(outfile, "%3d\n", use_pcre16?            if (pcre_mode == PCRE32_MODE)
3800               (int)(((PCRE_SPTR16)nametable)[0])              fprintf(outfile, "%3d\n", (int)(((PCRE_SPTR32)nametable)[0]));
             :((int)nametable[0] << 8) | (int)nametable[1]);  
           nametable += nameentrysize * (use_pcre16 ? 2 : 1);  
 #else  
           fprintf(outfile, "%3d\n", GET2(nametable, 0));  
 #ifdef SUPPORT_PCRE8  
           nametable += nameentrysize;  
 #else  
           nametable += nameentrysize * 2;  
3801  #endif  #endif
3802    #ifdef SUPPORT_PCRE16
3803              if (pcre_mode == PCRE16_MODE)
3804                fprintf(outfile, "%3d\n", (int)(((PCRE_SPTR16)nametable)[0]));
3805  #endif  #endif
3806    #ifdef SUPPORT_PCRE8
3807              if (pcre_mode == PCRE8_MODE)
3808                fprintf(outfile, "%3d\n", ((int)nametable[0] << 8) | (int)nametable[1]);
3809    #endif
3810              nametable += nameentrysize * CHAR_SIZE;
3811            }            }
3812          }          }
3813    
3814        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");
3815        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");
3816    
3817        all_options = ((REAL_PCRE *)re)->options;        all_options = REAL_PCRE_OPTIONS(re);
3818        if (do_flip) all_options = swap_uint32(all_options);        if (do_flip) all_options = swap_uint32(all_options);
3819    
3820        if (get_options == 0) fprintf(outfile, "No options\n");        if (get_options == 0) fprintf(outfile, "No options\n");
# Line 3183  while (!done) Line 3876  while (!done)
3876        else        else
3877          {          {
3878          const char *caseless =          const char *caseless =
3879            ((((REAL_PCRE *)re)->flags & PCRE_FCH_CASELESS) == 0)?            ((REAL_PCRE_FLAGS(re) & PCRE_FCH_CASELESS) == 0)?
3880            "" : " (caseless)";            "" : " (caseless)";
3881    
3882          if (PRINTOK(first_char))          if (PRINTOK(first_char))
# Line 3203  while (!done) Line 3896  while (!done)
3896        else        else
3897          {          {
3898          const char *caseless =          const char *caseless =
3899            ((((REAL_PCRE *)re)->flags & PCRE_RCH_CASELESS) == 0)?            ((REAL_PCRE_FLAGS(re) & PCRE_RCH_CASELESS) == 0)?
3900            "" : " (caseless)";            "" : " (caseless)";
3901    
3902          if (PRINTOK(need_char))          if (PRINTOK(need_char))
# Line 3216  while (!done) Line 3909  while (!done)
3909            }            }
3910          }          }
3911    
3912          if (maxlookbehind > 0)
3913            fprintf(outfile, "Max lookbehind = %d\n", maxlookbehind);
3914    
3915        /* 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
3916        value, but it varies, depending on the computer architecture, and        value, but it varies, depending on the computer architecture, and
3917        so messes up the test suite. (And with the /F option, it might be        so messes up the test suite. (And with the /F option, it might be
# Line 3273  while (!done) Line 3969  while (!done)
3969    
3970          /* 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. */
3971    
3972          if ((study_options & PCRE_STUDY_JIT_COMPILE) != 0)          if ((study_options & PCRE_STUDY_ALLJIT) != 0 &&
3973                (force_study_options & PCRE_STUDY_ALLJIT) == 0)
3974            {            {
3975            int jit;            int jit;
3976            if (new_info(re, extra, PCRE_INFO_JIT, &jit) == 0)            if (new_info(re, extra, PCRE_INFO_JIT, &jit) == 0)
# Line 3380  while (!done) Line 4077  while (!done)
4077      *copynames = 0;      *copynames = 0;
4078      *getnames = 0;      *getnames = 0;
4079    
4080    #ifdef SUPPORT_PCRE32
4081        cn32ptr = copynames;
4082        gn32ptr = getnames;
4083    #endif
4084  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
4085      cn16ptr = copynames;      cn16ptr = copynames16;
4086      gn16ptr = getnames;      gn16ptr = getnames16;
4087  #endif  #endif
4088  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
4089      cn8ptr = copynames8;      cn8ptr = copynames8;
# Line 3497  while (!done) Line 4198  while (!done)
4198          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
4199          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.
4200          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
4201          UTF-8 when running in 16-bit mode. */          UTF-8 when running in 16/32-bit mode. */
4202    
4203          c = 0;          c = 0;
4204          while (i++ < 2 && isxdigit(*p))          while (i++ < 2 && isxdigit(*p))
# Line 3542  while (!done) Line 4243  while (!done)
4243            }            }
4244          else if (isalnum(*p))          else if (isalnum(*p))
4245            {            {
4246            READ_CAPTURE_NAME(p, &cn8ptr, &cn16ptr, re);            READ_CAPTURE_NAME(p, &cn8ptr, &cn16ptr, &cn32ptr, re);
4247            }            }
4248          else if (*p == '+')          else if (*p == '+')
4249            {            {
# Line 3605  while (!done) Line 4306  while (!done)
4306            }            }
4307          else if (isalnum(*p))          else if (isalnum(*p))
4308            {            {
4309            READ_CAPTURE_NAME(p, &gn8ptr, &gn16ptr, re);            READ_CAPTURE_NAME(p, &gn8ptr, &gn16ptr, &gn32ptr, re);
4310            }            }
4311          continue;          continue;
4312    
# Line 3653  while (!done) Line 4354  while (!done)
4354            }            }
4355          use_size_offsets = n;          use_size_offsets = n;
4356          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 */
4357              else use_offsets = offsets + size_offsets_max - n;  /* To catch overruns */
4358          continue;          continue;
4359    
4360          case 'P':          case 'P':
# Line 3721  while (!done) Line 4423  while (!done)
4423        mode must have come from \x{...} or octal constructs because values from        mode must have come from \x{...} or octal constructs because values from
4424        \x.. get this far only in non-UTF mode. */        \x.. get this far only in non-UTF mode. */
4425    
4426  #if !defined NOUTF || defined SUPPORT_PCRE16  #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32
4427        if (use_pcre16 || use_utf)        if (pcre_mode != PCRE8_MODE || use_utf)
4428          {          {
4429          pcre_uint8 buff8[8];          pcre_uint8 buff8[8];
4430          int ii, utn;          int ii, utn;
# Line 3793  while (!done) Line 4495  while (!done)
4495          (void)regerror(rc, &preg, (char *)buffer, buffer_size);          (void)regerror(rc, &preg, (char *)buffer, buffer_size);
4496          fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);          fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);
4497          }          }
4498        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)  
4499          {          {
4500          fprintf(outfile, "Matched with REG_NOSUB\n");          fprintf(outfile, "Matched with REG_NOSUB\n");
4501          }          }
# Line 3828  while (!done) Line 4529  while (!done)
4529      /* Handle matching via the native interface - repeats for /g and /G */      /* Handle matching via the native interface - repeats for /g and /G */
4530    
4531  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
4532      if (use_pcre16)      if (pcre_mode == PCRE16_MODE)
4533        {        {
4534        len = to16(TRUE, bptr, (((REAL_PCRE *)re)->options) & PCRE_UTF8, len);        len = to16(TRUE, bptr, REAL_PCRE_OPTIONS(re) & PCRE_UTF8, len);
4535        switch(len)        switch(len)
4536          {          {
4537          case -1:          case -1:
# Line 3855  while (!done) Line 4556  while (!done)
4556        }        }
4557  #endif  #endif
4558    
4559    #ifdef SUPPORT_PCRE32
4560        if (pcre_mode == PCRE32_MODE)
4561          {
4562          len = to32(TRUE, bptr, REAL_PCRE_OPTIONS(re) & PCRE_UTF32, len);
4563          switch(len)
4564            {
4565            case -1:
4566            fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "
4567              "converted to UTF-32\n");
4568            goto NEXT_DATA;
4569    
4570            case -2:
4571            fprintf(outfile, "**Failed: character value greater than 0x10ffff "
4572              "cannot be converted to UTF-32\n");
4573            goto NEXT_DATA;
4574    
4575            case -3:
4576            fprintf(outfile, "**Failed: character value is ill-formed UTF-32\n");
4577            goto NEXT_DATA;
4578    
4579            default:
4580            break;
4581            }
4582          bptr = (pcre_uint8 *)buffer32;
4583          }
4584    #endif
4585    
4586        /* Ensure that there is a JIT callback if we want to verify that JIT was
4587        actually used. If jit_stack == NULL, no stack has yet been assigned. */
4588    
4589        if (verify_jit && jit_stack == NULL && extra != NULL)
4590           { PCRE_ASSIGN_JIT_STACK(extra, jit_callback, jit_stack); }
4591    
4592      for (;; gmatched++)    /* Loop for /g or /G */      for (;; gmatched++)    /* Loop for /g or /G */
4593        {        {
4594        markptr = NULL;        markptr = NULL;
4595          jit_was_used = FALSE;
4596    
4597        if (timeitm > 0)        if (timeitm > 0)
4598          {          {
# Line 3868  while (!done) Line 4603  while (!done)
4603  #if !defined NODFA  #if !defined NODFA
4604          if (all_use_dfa || use_dfa)          if (all_use_dfa || use_dfa)
4605            {            {
4606            int workspace[1000];            if ((options & PCRE_DFA_RESTART) != 0)
4607                {
4608                fprintf(outfile, "Timing DFA restarts is not supported\n");
4609                break;
4610                }
4611              if (dfa_workspace == NULL)
4612                dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
4613            for (i = 0; i < timeitm; i++)            for (i = 0; i < timeitm; i++)
4614              {              {
4615              PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,              PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
4616                (options | g_notempty), use_offsets, use_size_offsets, workspace,                (options | g_notempty), use_offsets, use_size_offsets,
4617                (sizeof(workspace)/sizeof(int)));                dfa_workspace, DFA_WS_DIMENSION);
4618              }              }
4619            }            }
4620          else          else
# Line 3899  while (!done) Line 4640  while (!done)
4640    
4641        if (find_match_limit)        if (find_match_limit)
4642          {          {
4643          if (extra == NULL)          if (extra != NULL) { PCRE_FREE_STUDY(extra); }
4644            {          extra = (pcre_extra *)malloc(sizeof(pcre_extra));
4645            extra = (pcre_extra *)malloc(sizeof(pcre_extra));          extra->flags = 0;
           extra->flags = 0;  
           }  
         else extra->flags &= ~PCRE_EXTRA_EXECUTABLE_JIT;  
4646    
4647          (void)check_match_limit(re, extra, bptr, len, start_offset,          (void)check_match_limit(re, extra, bptr, len, start_offset,
4648            options|g_notempty, use_offsets, use_size_offsets,            options|g_notempty, use_offsets, use_size_offsets,
# Line 3939  while (!done) Line 4677  while (!done)
4677  #if !defined NODFA  #if !defined NODFA
4678        else if (all_use_dfa || use_dfa)        else if (all_use_dfa || use_dfa)
4679          {          {
4680          int workspace[1000];          if (dfa_workspace == NULL)
4681              dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
4682            if (dfa_matched++ == 0)
4683              dfa_workspace[0] = -1;  /* To catch bad restart */
4684          PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,          PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
4685            (options | g_notempty), use_offsets, use_size_offsets, workspace,            (options | g_notempty), use_offsets, use_size_offsets, dfa_workspace,
4686            (sizeof(workspace)/sizeof(int)));            DFA_WS_DIMENSION);
4687          if (count == 0)          if (count == 0)
4688            {            {
4689            fprintf(outfile, "Matched, but too many subsidiary matches\n");            fprintf(outfile, "Matched, but too many subsidiary matches\n");
# Line 4019  while (!done) Line 4760  while (!done)
4760              fprintf(outfile, "%2d: ", i/2);              fprintf(outfile, "%2d: ", i/2);
4761              PCHARSV(bptr, use_offsets[i],              PCHARSV(bptr, use_offsets[i],
4762                use_offsets[i+1] - use_offsets[i], outfile);                use_offsets[i+1] - use_offsets[i], outfile);
4763                if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
4764              fprintf(outfile, "\n");              fprintf(outfile, "\n");
4765              if (do_showcaprest || (i == 0 && do_showrest))              if (do_showcaprest || (i == 0 && do_showrest))
4766                {                {
# Line 4062  while (!done) Line 4804  while (!done)
4804            int rc;            int rc;
4805            char copybuffer[256];            char copybuffer[256];
4806    
4807            if (use_pcre16)            if (pcre_mode == PCRE16_MODE)
4808              {              {
4809              if (*(pcre_uint16 *)cnptr == 0) break;              if (*(pcre_uint16 *)cnptr == 0) break;
4810              }              }
# Line 4117  while (!done) Line 4859  while (!done)
4859            int rc;            int rc;
4860            const char *substring;            const char *substring;
4861    
4862            if (use_pcre16)            if (pcre_mode == PCRE16_MODE)
4863              {              {
4864              if (*(pcre_uint16 *)gnptr == 0) break;              if (*(pcre_uint16 *)gnptr == 0) break;
4865              }              }
# Line 4185  while (!done) Line 4927  while (!done)
4927            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],
4928              outfile);              outfile);
4929            }            }
4930            if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
4931          fprintf(outfile, "\n");          fprintf(outfile, "\n");
4932          break;  /* Out of the /g loop */          break;  /* Out of the /g loop */
4933          }          }
# Line 4210  while (!done) Line 4953  while (!done)
4953          if (g_notempty != 0)          if (g_notempty != 0)
4954            {            {
4955            int onechar = 1;            int onechar = 1;
4956            unsigned int obits = ((REAL_PCRE *)re)->options;            unsigned int obits = REAL_PCRE_OPTIONS(re);
4957            use_offsets[0] = start_offset;            use_offsets[0] = start_offset;
4958            if ((obits & PCRE_NEWLINE_BITS) == 0)            if ((obits & PCRE_NEWLINE_BITS) == 0)
4959              {              {
# Line 4228  while (!done) Line 4971  while (!done)
4971                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||
4972                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)
4973                &&                &&
4974                start_offset < len - 1 &&                start_offset < len - 1 && (
4975  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE8
4976                (use_pcre16?                (pcre_mode == PCRE8_MODE &&
4977                     ((PCRE_SPTR16)bptr)[start_offset] == '\r'                 bptr[start_offset] == '\r' &&
4978                  && ((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'  
4979  #endif  #endif
4980                )  #ifdef SUPPORT_PCRE16
4981                  (pcre_mode == PCRE16_MODE &&
4982                   ((PCRE_SPTR16)bptr)[start_offset] == '\r' &&
4983                   ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n') ||
4984    #endif
4985    #ifdef SUPPORT_PCRE32
4986                  (pcre_mode == PCRE32_MODE &&
4987                   ((PCRE_SPTR32)bptr)[start_offset] == '\r' &&
4988                   ((PCRE_SPTR32)bptr)[start_offset + 1] == '\n') ||
4989    #endif
4990                  0))
4991              onechar++;              onechar++;
4992            else if (use_utf)            else if (use_utf)
4993              {              {
# Line 4264  while (!done) Line 5008  while (!done)
5008                {                {
5009                if (markptr == NULL)                if (markptr == NULL)
5010                  {                  {
5011                  fprintf(outfile, "No match\n");                  fprintf(outfile, "No match");
5012                  }                  }
5013                else                else
5014                  {                  {
5015                  fprintf(outfile, "No match, mark = ");                  fprintf(outfile, "No match, mark = ");
5016                  PCHARSV(markptr, 0, -1, outfile);                  PCHARSV(markptr, 0, -1, outfile);
                 putc('\n', outfile);  
5017                  }                  }
5018                  if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
5019                  putc('\n', outfile);
5020                }                }
5021              break;              break;
5022    
5023              case PCRE_ERROR_BADUTF8:              case PCRE_ERROR_BADUTF8:
5024              case PCRE_ERROR_SHORTUTF8:              case PCRE_ERROR_SHORTUTF8:
5025              fprintf(outfile, "Error %d (%s UTF-%s string)", count,              fprintf(outfile, "Error %d (%s UTF-%d string)", count,
5026                (count == PCRE_ERROR_BADUTF8)? "bad" : "short",                (count == PCRE_ERROR_BADUTF8)? "bad" : "short",
5027                use_pcre16? "16" : "8");                8 * CHAR_SIZE);
5028              if (use_size_offsets >= 2)              if (use_size_offsets >= 2)
5029                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],
5030                  use_offsets[1]);                  use_offsets[1]);
# Line 4287  while (!done) Line 5032  while (!done)
5032              break;              break;
5033    
5034              case PCRE_ERROR_BADUTF8_OFFSET:              case PCRE_ERROR_BADUTF8_OFFSET:
5035              fprintf(outfile, "Error %d (bad UTF-%s offset)\n", count,              fprintf(outfile, "Error %d (bad UTF-%d offset)\n", count,
5036                use_pcre16? "16" : "8");                8 * CHAR_SIZE);
5037              break;              break;
5038    
5039              default:              default:
5040              if (count < 0 &&              if (count < 0 &&
5041                  (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))                  (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))
5042                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);
5043              else              else
# Line 4378  free(offsets); Line 5123  free(offsets);
5123  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
5124  if (buffer16 != NULL) free(buffer16);  if (buffer16 != NULL) free(buffer16);
5125  #endif  #endif
5126    #ifdef SUPPORT_PCRE32
5127    if (buffer32 != NULL) free(buffer32);
5128    #endif
5129    
5130    #if !defined NODFA
5131    if (dfa_workspace != NULL)
5132      free(dfa_workspace);
5133    #endif
5134    
5135  return yield;  return yield;
5136  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.5