/[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 1087 by chpe, Tue Oct 16 15:55:38 2012 UTC revision 1254 by ph10, Fri Feb 22 12:46:26 2013 UTC
# Line 36  POSSIBILITY OF SUCH DAMAGE. Line 36  POSSIBILITY OF SUCH DAMAGE.
36  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
37  */  */
38    
39  /* This program now supports the testing of both the 8-bit and 16-bit PCRE  /* This program now supports the testing of all of the 8-bit, 16-bit, and
40  libraries in a single program. This is different from the modules such as  32-bit PCRE libraries in a single program. This is different from the modules
41  pcre_compile.c in the library itself, which are compiled separately for each  such as pcre_compile.c in the library itself, which are compiled separately for
42  mode. If both modes are enabled, for example, pcre_compile.c is compiled twice  each mode. If two modes are enabled, for example, pcre_compile.c is compiled
43  (the second time with COMPILE_PCRE16 defined). By contrast, pcretest.c is  twice. By contrast, pcretest.c is compiled only once. Therefore, it must not
44  compiled only once. Therefore, it must not make use of any of the macros from  make use of any of the macros from pcre_internal.h that depend on
45  pcre_internal.h that depend on COMPILE_PCRE8 or COMPILE_PCRE16. It does,  COMPILE_PCRE8, COMPILE_PCRE16, or COMPILE_PCRE32. It does, however, make use of
46  however, make use of SUPPORT_PCRE8 and SUPPORT_PCRE16 to ensure that it calls  SUPPORT_PCRE8, SUPPORT_PCRE16, and SUPPORT_PCRE32 to ensure that it calls only
47  only supported library functions. */  supported library functions. */
48    
49  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
50  #include "config.h"  #include "config.h"
# Line 121  input mode under Windows. */ Line 121  input mode under Windows. */
121  #endif  #endif
122  #endif  #endif
123    
124    #ifdef __VMS
125    #include <ssdef.h>
126    void vms_setsymbol( char *, char *, int );
127    #endif
128    
129    
130  #define PRIV(name) name  #define PRIV(name) name
131    
132  /* We have to include pcre_internal.h because we need the internal info for  /* We have to include pcre_internal.h because we need the internal info for
# Line 133  here before pcre_internal.h so that the Line 139  here before pcre_internal.h so that the
139  appropriately for an application, not for building PCRE. */  appropriately for an application, not for building PCRE. */
140    
141  #include "pcre.h"  #include "pcre.h"
   
 #if defined SUPPORT_PCRE32 && !defined SUPPORT_PCRE8 && !defined SUPPORT_PCRE16  
 /* Configure internal macros to 32 bit mode. */  
 #define COMPILE_PCRE32  
 #endif  
 #if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8 && !defined SUPPORT_PCRE32  
 /* Configure internal macros to 16 bit mode. */  
 #define COMPILE_PCRE16  
 #endif  
 #if defined SUPPORT_PCRE8 && !defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE32  
 /* Configure internal macros to 16 bit mode. */  
 #define COMPILE_PCRE8  
 #endif  
   
142  #include "pcre_internal.h"  #include "pcre_internal.h"
143    
144  /* The pcre_printint() function, which prints the internal form of a compiled  /* The pcre_printint() function, which prints the internal form of a compiled
# Line 303  argument, the casting might be incorrect Line 295  argument, the casting might be incorrect
295  #define PCRE_JIT_STACK_FREE8(stack) \  #define PCRE_JIT_STACK_FREE8(stack) \
296    pcre_jit_stack_free(stack)    pcre_jit_stack_free(stack)
297    
298    #define pcre8_maketables pcre_maketables
299    
300  #endif /* SUPPORT_PCRE8 */  #endif /* SUPPORT_PCRE8 */
301    
302  /* -----------------------------------------------------------*/  /* -----------------------------------------------------------*/
# Line 399  argument, the casting might be incorrect Line 393  argument, the casting might be incorrect
393  #ifdef SUPPORT_PCRE32  #ifdef SUPPORT_PCRE32
394    
395  #define PCHARS32(lv, p, offset, len, f) \  #define PCHARS32(lv, p, offset, len, f) \
396    lv = pchars32((PCRE_SPTR32)(p) + offset, len, f)    lv = pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
397    
398  #define PCHARSV32(p, offset, len, f) \  #define PCHARSV32(p, offset, len, f)                \
399    (void)pchars32((PCRE_SPTR32)(p) + offset, len, f)    (void)pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
400    
401  #define READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re) \  #define READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re) \
402    p = read_capture_name32(p, cn32, re)    p = read_capture_name32(p, cn32, re)
# Line 484  argument, the casting might be incorrect Line 478  argument, the casting might be incorrect
478  #endif /* SUPPORT_PCRE32 */  #endif /* SUPPORT_PCRE32 */
479    
480    
481  /* ----- Both modes are supported; a runtime test is needed, except for  /* ----- More than one mode is supported; a runtime test is needed, except for
482  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
483  version is called. ----- */  available version is called. ----- */
484    
485  enum {  enum {
486    PCRE8_MODE,    PCRE8_MODE,
# Line 494  enum { Line 488  enum {
488    PCRE32_MODE    PCRE32_MODE
489  };  };
490    
491  #if (defined (SUPPORT_PCRE8) + defined (SUPPORT_PCRE16) + defined (SUPPORT_PCRE32)) >= 2  #if (defined (SUPPORT_PCRE8) + defined (SUPPORT_PCRE16) + \
492         defined (SUPPORT_PCRE32)) >= 2
493    
494  #define CHAR_SIZE (1 << pcre_mode)  #define CHAR_SIZE (1 << pcre_mode)
495    
496    /* There doesn't seem to be an easy way of writing these macros that can cope
497    with the 3 pairs of bit sizes plus all three bit sizes. So just handle all the
498    cases separately. */
499    
500    /* ----- All three modes supported ----- */
501    
502    #if defined(SUPPORT_PCRE8) && defined(SUPPORT_PCRE16) && defined(SUPPORT_PCRE32)
503    
504  #define PCHARS(lv, p, offset, len, f) \  #define PCHARS(lv, p, offset, len, f) \
505    if (pcre_mode == PCRE32_MODE) \    if (pcre_mode == PCRE32_MODE) \
506      PCHARS32(lv, p, offset, len, f); \      PCHARS32(lv, p, offset, len, f); \
# Line 696  enum { Line 699  enum {
699    else \    else \
700      PCRE_STUDY8(extra, re, options, error)      PCRE_STUDY8(extra, re, options, error)
701    
702    
703    /* ----- Two out of three modes are supported ----- */
704    
705    #else
706    
707    /* We can use some macro trickery to make a single set of definitions work in
708    the three different cases. */
709    
710    /* ----- 32-bit and 16-bit but not 8-bit supported ----- */
711    
712    #if defined(SUPPORT_PCRE32) && defined(SUPPORT_PCRE16)
713    #define BITONE 32
714    #define BITTWO 16
715    
716    /* ----- 32-bit and 8-bit but not 16-bit supported ----- */
717    
718    #elif defined(SUPPORT_PCRE32) && defined(SUPPORT_PCRE8)
719    #define BITONE 32
720    #define BITTWO 8
721    
722    /* ----- 16-bit and 8-bit but not 32-bit supported ----- */
723    
724    #else
725    #define BITONE 16
726    #define BITTWO 8
727    #endif
728    
729    #define glue(a,b) a##b
730    #define G(a,b) glue(a,b)
731    
732    
733    /* ----- Common macros for two-mode cases ----- */
734    
735    #define PCHARS(lv, p, offset, len, f) \
736      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
737        G(PCHARS,BITONE)(lv, p, offset, len, f); \
738      else \
739        G(PCHARS,BITTWO)(lv, p, offset, len, f)
740    
741    #define PCHARSV(p, offset, len, f) \
742      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
743        G(PCHARSV,BITONE)(p, offset, len, f); \
744      else \
745        G(PCHARSV,BITTWO)(p, offset, len, f)
746    
747    #define READ_CAPTURE_NAME(p, cn8, cn16, cn32, re) \
748      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
749        G(READ_CAPTURE_NAME,BITONE)(p, cn8, cn16, cn32, re); \
750      else \
751        G(READ_CAPTURE_NAME,BITTWO)(p, cn8, cn16, cn32, re)
752    
753    #define SET_PCRE_CALLOUT(callout) \
754      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
755        G(SET_PCRE_CALLOUT,BITONE)(callout); \
756      else \
757        G(SET_PCRE_CALLOUT,BITTWO)(callout)
758    
759    #define STRLEN(p) ((pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
760      G(STRLEN,BITONE)(p) : G(STRLEN,BITTWO)(p))
761    
762    #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
763      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
764        G(PCRE_ASSIGN_JIT_STACK,BITONE)(extra, callback, userdata); \
765      else \
766        G(PCRE_ASSIGN_JIT_STACK,BITTWO)(extra, callback, userdata)
767    
768    #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
769      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
770        G(PCRE_COMPILE,BITONE)(re, pat, options, error, erroffset, tables); \
771      else \
772        G(PCRE_COMPILE,BITTWO)(re, pat, options, error, erroffset, tables)
773    
774    #define PCRE_CONFIG G(G(pcre,BITONE),_config)
775    
776    #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
777        namesptr, cbuffer, size) \
778      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
779        G(PCRE_COPY_NAMED_SUBSTRING,BITONE)(rc, re, bptr, offsets, count, \
780          namesptr, cbuffer, size); \
781      else \
782        G(PCRE_COPY_NAMED_SUBSTRING,BITTWO)(rc, re, bptr, offsets, count, \
783          namesptr, cbuffer, size)
784    
785    #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \
786      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
787        G(PCRE_COPY_SUBSTRING,BITONE)(rc, bptr, offsets, count, i, cbuffer, size); \
788      else \
789        G(PCRE_COPY_SUBSTRING,BITTWO)(rc, bptr, offsets, count, i, cbuffer, size)
790    
791    #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \
792        offsets, size_offsets, workspace, size_workspace) \
793      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
794        G(PCRE_DFA_EXEC,BITONE)(count, re, extra, bptr, len, start_offset, options, \
795          offsets, size_offsets, workspace, size_workspace); \
796      else \
797        G(PCRE_DFA_EXEC,BITTWO)(count, re, extra, bptr, len, start_offset, options, \
798          offsets, size_offsets, workspace, size_workspace)
799    
800    #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
801        offsets, size_offsets) \
802      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
803        G(PCRE_EXEC,BITONE)(count, re, extra, bptr, len, start_offset, options, \
804          offsets, size_offsets); \
805      else \
806        G(PCRE_EXEC,BITTWO)(count, re, extra, bptr, len, start_offset, options, \
807          offsets, size_offsets)
808    
809    #define PCRE_FREE_STUDY(extra) \
810      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
811        G(PCRE_FREE_STUDY,BITONE)(extra); \
812      else \
813        G(PCRE_FREE_STUDY,BITTWO)(extra)
814    
815    #define PCRE_FREE_SUBSTRING(substring) \
816      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
817        G(PCRE_FREE_SUBSTRING,BITONE)(substring); \
818      else \
819        G(PCRE_FREE_SUBSTRING,BITTWO)(substring)
820    
821    #define PCRE_FREE_SUBSTRING_LIST(listptr) \
822      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
823        G(PCRE_FREE_SUBSTRING_LIST,BITONE)(listptr); \
824      else \
825        G(PCRE_FREE_SUBSTRING_LIST,BITTWO)(listptr)
826    
827    #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
828        getnamesptr, subsptr) \
829      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
830        G(PCRE_GET_NAMED_SUBSTRING,BITONE)(rc, re, bptr, offsets, count, \
831          getnamesptr, subsptr); \
832      else \
833        G(PCRE_GET_NAMED_SUBSTRING,BITTWO)(rc, re, bptr, offsets, count, \
834          getnamesptr, subsptr)
835    
836    #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \
837      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
838        G(PCRE_GET_STRINGNUMBER,BITONE)(n, rc, ptr); \
839      else \
840        G(PCRE_GET_STRINGNUMBER,BITTWO)(n, rc, ptr)
841    
842    #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \
843      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
844        G(PCRE_GET_SUBSTRING,BITONE)(rc, bptr, use_offsets, count, i, subsptr); \
845      else \
846        G(PCRE_GET_SUBSTRING,BITTWO)(rc, bptr, use_offsets, count, i, subsptr)
847    
848    #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \
849      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
850        G(PCRE_GET_SUBSTRING_LIST,BITONE)(rc, bptr, offsets, count, listptr); \
851      else \
852        G(PCRE_GET_SUBSTRING_LIST,BITTWO)(rc, bptr, offsets, count, listptr)
853    
854    #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
855      (pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
856         G(PCRE_JIT_STACK_ALLOC,BITONE)(startsize, maxsize) \
857        : G(PCRE_JIT_STACK_ALLOC,BITTWO)(startsize, maxsize)
858    
859    #define PCRE_JIT_STACK_FREE(stack) \
860      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
861        G(PCRE_JIT_STACK_FREE,BITONE)(stack); \
862      else \
863        G(PCRE_JIT_STACK_FREE,BITTWO)(stack)
864    
865    #define PCRE_MAKETABLES \
866      (pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
867        G(G(pcre,BITONE),_maketables)() : G(G(pcre,BITTWO),_maketables)()
868    
869    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \
870      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
871        G(PCRE_PATTERN_TO_HOST_BYTE_ORDER,BITONE)(rc, re, extra, tables); \
872      else \
873        G(PCRE_PATTERN_TO_HOST_BYTE_ORDER,BITTWO)(rc, re, extra, tables)
874    
875    #define PCRE_PRINTINT(re, outfile, debug_lengths) \
876      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
877        G(PCRE_PRINTINT,BITONE)(re, outfile, debug_lengths); \
878      else \
879        G(PCRE_PRINTINT,BITTWO)(re, outfile, debug_lengths)
880    
881    #define PCRE_STUDY(extra, re, options, error) \
882      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
883        G(PCRE_STUDY,BITONE)(extra, re, options, error); \
884      else \
885        G(PCRE_STUDY,BITTWO)(extra, re, options, error)
886    
887    #endif  /* Two out of three modes */
888    
889    /* ----- End of cases where more than one mode is supported ----- */
890    
891    
892  /* ----- Only 8-bit mode is supported ----- */  /* ----- Only 8-bit mode is supported ----- */
893    
894  #elif defined SUPPORT_PCRE8  #elif defined SUPPORT_PCRE8
# Line 831  static const unsigned char *last_callout Line 1024  static const unsigned char *last_callout
1024    
1025  static int buffer_size = 50000;  static int buffer_size = 50000;
1026  static pcre_uint8 *buffer = NULL;  static pcre_uint8 *buffer = NULL;
 static pcre_uint8 *dbuffer = NULL;  
1027  static pcre_uint8 *pbuffer = NULL;  static pcre_uint8 *pbuffer = NULL;
1028    
1029  /* Another buffer is needed translation to 16/32-bit character strings. It will  /* Just as a safety check, make sure that COMPILE_PCRE[16|32] are *not* set. */
 obtained and extended as required. */  
   
 #if defined SUPPORT_PCRE8 && (defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32)  
   
 /* We need the table of operator lengths that is used for 16/32-bit compiling, in  
 order to swap bytes in a pattern for saving/reloading testing. Luckily, the  
 data is defined as a macro. However, we must ensure that LINK_SIZE is adjusted  
 appropriately for the 16/32-bit world. Just as a safety check, make sure that  
 COMPILE_PCRE[16|32] is *not* set. */  
1030    
1031  #ifdef COMPILE_PCRE16  #ifdef COMPILE_PCRE16
1032  #error COMPILE_PCRE16 must not be set when compiling pcretest.c  #error COMPILE_PCRE16 must not be set when compiling pcretest.c
# Line 853  COMPILE_PCRE[16|32] is *not* set. */ Line 1036  COMPILE_PCRE[16|32] is *not* set. */
1036  #error COMPILE_PCRE32 must not be set when compiling pcretest.c  #error COMPILE_PCRE32 must not be set when compiling pcretest.c
1037  #endif  #endif
1038    
1039    /* We need buffers for building 16/32-bit strings, and the tables of operator
1040    lengths that are used for 16/32-bit compiling, in order to swap bytes in a
1041    pattern for saving/reloading testing. Luckily, the data for these tables is
1042    defined as a macro. However, we must ensure that LINK_SIZE and IMM2_SIZE (which
1043    are used in the tables) are adjusted appropriately for the 16/32-bit world.
1044    LINK_SIZE is also used later in this program. */
1045    
1046    #ifdef SUPPORT_PCRE16
1047    #undef IMM2_SIZE
1048    #define IMM2_SIZE 1
1049    
1050  #if LINK_SIZE == 2  #if LINK_SIZE == 2
1051  #undef LINK_SIZE  #undef LINK_SIZE
1052  #define LINK_SIZE 1  #define LINK_SIZE 1
# Line 863  COMPILE_PCRE[16|32] is *not* set. */ Line 1057  COMPILE_PCRE[16|32] is *not* set. */
1057  #error LINK_SIZE must be either 2, 3, or 4  #error LINK_SIZE must be either 2, 3, or 4
1058  #endif  #endif
1059    
 #undef IMM2_SIZE  
 #define IMM2_SIZE 1  
   
 #endif /* SUPPORT_PCRE8 && (SUPPORT_PCRE16 || SUPPORT_PCRE32) */  
   
 #ifdef SUPPORT_PCRE16  
1060  static int buffer16_size = 0;  static int buffer16_size = 0;
1061  static pcre_uint16 *buffer16 = NULL;  static pcre_uint16 *buffer16 = NULL;
1062  static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };  static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };
1063  #endif  /* SUPPORT_PCRE16 */  #endif  /* SUPPORT_PCRE16 */
1064    
1065  #ifdef SUPPORT_PCRE32  #ifdef SUPPORT_PCRE32
1066    #undef IMM2_SIZE
1067    #define IMM2_SIZE 1
1068    #undef LINK_SIZE
1069    #define LINK_SIZE 1
1070    
1071  static int buffer32_size = 0;  static int buffer32_size = 0;
1072  static pcre_uint32 *buffer32 = NULL;  static pcre_uint32 *buffer32 = NULL;
1073  static const pcre_uint32 OP_lengths32[] = { OP_LENGTHS };  static const pcre_uint32 OP_lengths32[] = { OP_LENGTHS };
1074  #endif  /* SUPPORT_PCRE32 */  #endif  /* SUPPORT_PCRE32 */
1075    
1076  /* If we have 8-bit support, default to it; if there is also  /* If we have 8-bit support, default to it; if there is also 16-or 32-bit
1077  16-or 32-bit support, it can be changed by an option. If there is no 8-bit support,  support, it can be changed by an option. If there is no 8-bit support, there
1078  there must be 16-or 32-bit support, so default it to 1. */  must be 16-or 32-bit support, so default it to 1. */
1079    
1080  #if defined SUPPORT_PCRE8  #if defined SUPPORT_PCRE8
1081  static int pcre_mode = PCRE8_MODE;  static int pcre_mode = PCRE8_MODE;
# Line 942  static const char *errtexts[] = { Line 1135  static const char *errtexts[] = {
1135    "JIT stack limit reached",    "JIT stack limit reached",
1136    "pattern compiled in wrong mode: 8-bit/16-bit error",    "pattern compiled in wrong mode: 8-bit/16-bit error",
1137    "pattern compiled with other endianness",    "pattern compiled with other endianness",
1138    "invalid data in workspace for DFA restart"    "invalid data in workspace for DFA restart",
1139      "bad JIT option",
1140      "bad length"
1141  };  };
1142    
1143    
# Line 1299  return sys_errlist[n]; Line 1494  return sys_errlist[n];
1494  *       Print newline configuration              *  *       Print newline configuration              *
1495  *************************************************/  *************************************************/
1496    
1497  /*  /*
1498  Arguments:  Arguments:
1499    rc         the return code from PCRE_CONFIG_NEWLINE    rc         the return code from PCRE_CONFIG_NEWLINE
1500    isc        TRUE if called from "-C newline"    isc        TRUE if called from "-C newline"
1501  Returns:     nothing  Returns:     nothing
1502  */  */
1503    
# Line 1318  switch(rc) Line 1513  switch(rc)
1513    case (CHAR_CR<<8 | CHAR_LF): s = "CRLF"; break;    case (CHAR_CR<<8 | CHAR_LF): s = "CRLF"; break;
1514    case -1: s = "ANY"; break;    case -1: s = "ANY"; break;
1515    case -2: s = "ANYCRLF"; break;    case -2: s = "ANYCRLF"; break;
1516    
1517    default:    default:
1518    printf("a non-standard value: 0x%04x\n", rc);    printf("a non-standard value: 0x%04x\n", rc);
1519    return;    return;
1520    }    }
1521    
1522  printf("%s\n", s);  printf("%s\n", s);
1523  }  }
# Line 1388  for (j = 0; j < i; j++) Line 1583  for (j = 0; j < i; j++)
1583  /* Check that encoding was the correct unique one */  /* Check that encoding was the correct unique one */
1584    
1585  for (j = 0; j < utf8_table1_size; j++)  for (j = 0; j < utf8_table1_size; j++)
1586    if (d <= utf8_table1[j]) break;    if (d <= (pcre_uint32)utf8_table1[j]) break;
1587  if (j != i) return -(i+1);  if (j != i) return -(i+1);
1588    
1589  /* Valid value */  /* Valid value */
# Line 1400  return i+1; Line 1595  return i+1;
1595    
1596    
1597    
1598  #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32  #if defined SUPPORT_PCRE8 && !defined NOUTF
1599  /*************************************************  /*************************************************
1600  *       Convert character value to UTF-8         *  *       Convert character value to UTF-8         *
1601  *************************************************/  *************************************************/
# Line 1422  register int i, j; Line 1617  register int i, j;
1617  if (cvalue > 0x7fffffffu)  if (cvalue > 0x7fffffffu)
1618    return -1;    return -1;
1619  for (i = 0; i < utf8_table1_size; i++)  for (i = 0; i < utf8_table1_size; i++)
1620    if (cvalue <= utf8_table1[i]) break;    if (cvalue <= (pcre_uint32)utf8_table1[i]) break;
1621  utf8bytes += i;  utf8bytes += i;
1622  for (j = i; j > 0; j--)  for (j = i; j > 0; j--)
1623   {   {
# Line 1590  else Line 1785  else
1785  *pp = 0;  *pp = 0;
1786  return pp - buffer32;  return pp - buffer32;
1787  }  }
1788    
1789    /* Check that a 32-bit character string is valid UTF-32.
1790    
1791    Arguments:
1792      string       points to the string
1793      length       length of string, or -1 if the string is zero-terminated
1794    
1795    Returns:       TRUE  if the string is a valid UTF-32 string
1796                   FALSE otherwise
1797    */
1798    
1799    #ifdef NEVER
1800    
1801    #ifdef SUPPORT_UTF
1802    static BOOL
1803    valid_utf32(pcre_uint32 *string, int length)
1804    {
1805    register pcre_uint32 *p;
1806    register pcre_uint32 c;
1807    
1808    for (p = string; length-- > 0; p++)
1809      {
1810      c = *p;
1811    
1812      if (c > 0x10ffffu)
1813        return FALSE;
1814    
1815      /* A surrogate */
1816      if ((c & 0xfffff800u) == 0xd800u)
1817        return FALSE;
1818    
1819      /* Non-character */
1820      if ((c & 0xfffeu) == 0xfffeu || (c >= 0xfdd0u && c <= 0xfdefu))
1821        return FALSE;
1822      }
1823    
1824    return TRUE;
1825    }
1826    #endif /* SUPPORT_UTF */
1827    
1828    #endif /* NEVER */
1829    
1830    
1831  #endif  #endif
1832    
1833  /*************************************************  /*************************************************
# Line 1666  for (;;) Line 1904  for (;;)
1904      {      {
1905      int new_buffer_size = 2*buffer_size;      int new_buffer_size = 2*buffer_size;
1906      pcre_uint8 *new_buffer = (pcre_uint8 *)malloc(new_buffer_size);      pcre_uint8 *new_buffer = (pcre_uint8 *)malloc(new_buffer_size);
     pcre_uint8 *new_dbuffer = (pcre_uint8 *)malloc(new_buffer_size);  
1907      pcre_uint8 *new_pbuffer = (pcre_uint8 *)malloc(new_buffer_size);      pcre_uint8 *new_pbuffer = (pcre_uint8 *)malloc(new_buffer_size);
1908    
1909      if (new_buffer == NULL || new_dbuffer == NULL || new_pbuffer == NULL)      if (new_buffer == NULL || new_pbuffer == NULL)
1910        {        {
1911        fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);        fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);
1912        exit(1);        exit(1);
# Line 1684  for (;;) Line 1921  for (;;)
1921      here = new_buffer + (here - buffer);      here = new_buffer + (here - buffer);
1922    
1923      free(buffer);      free(buffer);
     free(dbuffer);  
1924      free(pbuffer);      free(pbuffer);
1925    
1926      buffer = new_buffer;      buffer = new_buffer;
     dbuffer = new_dbuffer;  
1927      pbuffer = new_pbuffer;      pbuffer = new_pbuffer;
1928      }      }
1929    }    }
# Line 1733  return(result); Line 1968  return(result);
1968    
1969  static int pchar(pcre_uint32 c, FILE *f)  static int pchar(pcre_uint32 c, FILE *f)
1970  {  {
1971  int n;  int n = 0;
1972  if (PRINTOK(c))  if (PRINTOK(c))
1973    {    {
1974    if (f != NULL) fprintf(f, "%c", c);    if (f != NULL) fprintf(f, "%c", c);
# Line 1878  return yield; Line 2113  return yield;
2113  /* Must handle UTF-32 strings in utf mode. Yields number of characters printed.  /* Must handle UTF-32 strings in utf mode. Yields number of characters printed.
2114  If handed a NULL file, just counts chars without printing. */  If handed a NULL file, just counts chars without printing. */
2115    
2116  static int pchars32(PCRE_SPTR32 p, int length, FILE *f)  static int pchars32(PCRE_SPTR32 p, int length, BOOL utf, FILE *f)
2117  {  {
2118  int yield = 0;  int yield = 0;
2119    
2120    (void)(utf);  /* Avoid compiler warning */
2121    
2122  if (length < 0)  if (length < 0)
2123    length = strlen32(p);    length = strlen32(p);
2124    
# Line 2417  real_pcre32 *re = (real_pcre32 *)ere; Line 2654  real_pcre32 *re = (real_pcre32 *)ere;
2654  int op;  int op;
2655  pcre_uint32 *ptr = (pcre_uint32 *)re + re->name_table_offset;  pcre_uint32 *ptr = (pcre_uint32 *)re + re->name_table_offset;
2656  int length = re->name_count * re->name_entry_size;  int length = re->name_count * re->name_entry_size;
 #ifdef SUPPORT_UTF  
 BOOL utf = (re->options & PCRE_UTF32) != 0;  
 #endif /* SUPPORT_UTF */  
2657    
2658  /* Always flip the bytes in the main data block and study blocks. */  /* Always flip the bytes in the main data block and study blocks. */
2659    
# Line 2443  if (extra != NULL) Line 2677  if (extra != NULL)
2677    rsd->minlength = swap_uint32(rsd->minlength);    rsd->minlength = swap_uint32(rsd->minlength);
2678    }    }
2679    
2680  /* In 32-bit mode we must swap bytes  /* In 32-bit mode we must swap bytes in the name table, if present, and then in
2681  in the name table, if present, and then in the pattern itself. */  the pattern itself. */
2682    
2683  while(TRUE)  while(TRUE)
2684    {    {
# Line 2719  int all_use_dfa = 0; Line 2953  int all_use_dfa = 0;
2953  int verify_jit = 0;  int verify_jit = 0;
2954  int yield = 0;  int yield = 0;
2955  int stack_size;  int stack_size;
2956    pcre_uint8 *dbuffer = NULL;
2957    size_t dbuffer_size = 1u << 14;
2958    
2959  #if !defined NOPOSIX  #if !defined NOPOSIX
2960  int posix = 0;  int posix = 0;
# Line 2758  pcre_uint8 *gn8ptr; Line 2994  pcre_uint8 *gn8ptr;
2994  #endif  #endif
2995    
2996  /* Get buffers from malloc() so that valgrind will check their misuse when  /* Get buffers from malloc() so that valgrind will check their misuse when
2997  debugging. They grow automatically when very long lines are read. The 16-  debugging. They grow automatically when very long lines are read. The 16-
2998  and 32-bit buffers (buffer16, buffer32) are obtained only if needed. */  and 32-bit buffers (buffer16, buffer32) are obtained only if needed. */
2999    
3000  buffer = (pcre_uint8 *)malloc(buffer_size);  buffer = (pcre_uint8 *)malloc(buffer_size);
 dbuffer = (pcre_uint8 *)malloc(buffer_size);  
3001  pbuffer = (pcre_uint8 *)malloc(buffer_size);  pbuffer = (pcre_uint8 *)malloc(buffer_size);
3002    
3003  /* The outfile variable is static so that new_malloc can use it. */  /* The outfile variable is static so that new_malloc can use it. */
# Line 2810  while (argc > 1 && argv[op][0] == '-') Line 3045  while (argc > 1 && argv[op][0] == '-')
3045        force_study_options = jit_study_bits[*arg - '1'];        force_study_options = jit_study_bits[*arg - '1'];
3046      else goto BAD_ARG;      else goto BAD_ARG;
3047      }      }
3048      else if (strcmp(arg, "-8") == 0)
3049        {
3050    #ifdef SUPPORT_PCRE8
3051        pcre_mode = PCRE8_MODE;
3052    #else
3053        printf("** This version of PCRE was built without 8-bit support\n");
3054        exit(1);
3055    #endif
3056        }
3057    else if (strcmp(arg, "-16") == 0)    else if (strcmp(arg, "-16") == 0)
3058      {      {
3059  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
# Line 2861  while (argc > 1 && argv[op][0] == '-') Line 3105  while (argc > 1 && argv[op][0] == '-')
3105        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),
3106          *endptr == 0))          *endptr == 0))
3107      {      {
3108  #if defined(_WIN32) || defined(WIN32) || defined(__minix) || defined(NATIVE_ZOS)  #if defined(_WIN32) || defined(WIN32) || defined(__minix) || defined(NATIVE_ZOS) || defined(__VMS)
3109      printf("PCRE: -S not supported on this OS\n");      printf("PCRE: -S not supported on this OS\n");
3110      exit(1);      exit(1);
3111  #else  #else
# Line 2894  while (argc > 1 && argv[op][0] == '-') Line 3138  while (argc > 1 && argv[op][0] == '-')
3138          (void)PCRE_CONFIG(PCRE_CONFIG_LINK_SIZE, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_LINK_SIZE, &rc);
3139          printf("%d\n", rc);          printf("%d\n", rc);
3140          yield = rc;          yield = rc;
3141    
3142    #ifdef __VMS
3143            vms_setsymbol("LINKSIZE",0,yield );
3144    #endif
3145          }          }
3146        else if (strcmp(argv[op + 1], "pcre8") == 0)        else if (strcmp(argv[op + 1], "pcre8") == 0)
3147          {          {
# Line 2904  while (argc > 1 && argv[op][0] == '-') Line 3152  while (argc > 1 && argv[op][0] == '-')
3152          printf("0\n");          printf("0\n");
3153          yield = 0;          yield = 0;
3154  #endif  #endif
3155    #ifdef __VMS
3156            vms_setsymbol("PCRE8",0,yield );
3157    #endif
3158          }          }
3159        else if (strcmp(argv[op + 1], "pcre16") == 0)        else if (strcmp(argv[op + 1], "pcre16") == 0)
3160          {          {
# Line 2914  while (argc > 1 && argv[op][0] == '-') Line 3165  while (argc > 1 && argv[op][0] == '-')
3165          printf("0\n");          printf("0\n");
3166          yield = 0;          yield = 0;
3167  #endif  #endif
3168    #ifdef __VMS
3169            vms_setsymbol("PCRE16",0,yield );
3170    #endif
3171          }          }
3172        else if (strcmp(argv[op + 1], "pcre32") == 0)        else if (strcmp(argv[op + 1], "pcre32") == 0)
3173          {          {
# Line 2924  while (argc > 1 && argv[op][0] == '-') Line 3178  while (argc > 1 && argv[op][0] == '-')
3178          printf("0\n");          printf("0\n");
3179          yield = 0;          yield = 0;
3180  #endif  #endif
3181          goto EXIT;  #ifdef __VMS
3182            vms_setsymbol("PCRE32",0,yield );
3183    #endif
3184          }          }
3185        if (strcmp(argv[op + 1], "utf") == 0)        else if (strcmp(argv[op + 1], "utf") == 0)
3186          {          {
3187  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
3188          if (pcre_mode == PCRE8_MODE)          if (pcre_mode == PCRE8_MODE)
# Line 2942  while (argc > 1 && argv[op][0] == '-') Line 3198  while (argc > 1 && argv[op][0] == '-')
3198  #endif  #endif
3199          printf("%d\n", rc);          printf("%d\n", rc);
3200          yield = rc;          yield = rc;
3201          goto EXIT;  #ifdef __VMS
3202            vms_setsymbol("UTF",0,yield );
3203    #endif
3204          }          }
3205        else if (strcmp(argv[op + 1], "ucp") == 0)        else if (strcmp(argv[op + 1], "ucp") == 0)
3206          {          {
# Line 2959  while (argc > 1 && argv[op][0] == '-') Line 3217  while (argc > 1 && argv[op][0] == '-')
3217        else if (strcmp(argv[op + 1], "newline") == 0)        else if (strcmp(argv[op + 1], "newline") == 0)
3218          {          {
3219          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3220          print_newline_config(rc, TRUE);          print_newline_config(rc, TRUE);
3221          }          }
3222        else if (strcmp(argv[op + 1], "ebcdic") == 0)        else if (strcmp(argv[op + 1], "ebcdic") == 0)
3223          {          {
3224  #ifdef EBCDIC  #ifdef EBCDIC
3225          printf("1\n");          printf("1\n");
3226          yield = 1;          yield = 1;
3227  #else  #else
3228          printf("0\n");          printf("0\n");
3229  #endif  #endif
3230          }          }
3231        else if (strcmp(argv[op + 1], "ebcdic-nl") == 0)        else if (strcmp(argv[op + 1], "ebcdic-nl") == 0)
3232          {          {
3233  #ifdef EBCDIC  #ifdef EBCDIC
3234          printf("0x%02x\n", CHAR_LF);          printf("0x%02x\n", CHAR_LF);
3235  #else  #else
3236          printf("0\n");          printf("0\n");
3237  #endif  #endif
3238          }          }
3239        else        else
3240          {          {
3241          printf("Unknown -C option: %s\n", argv[op + 1]);          printf("Unknown -C option: %s\n", argv[op + 1]);
3242          }          }
3243        goto EXIT;        goto EXIT;
3244        }        }
3245    
3246      /* No argument for -C: output all configuration information. */      /* No argument for -C: output all configuration information. */
3247    
3248      printf("PCRE version %s\n", version);      printf("PCRE version %s\n", version);
3249      printf("Compiled with\n");      printf("Compiled with\n");
3250    
3251  #ifdef EBCDIC  #ifdef EBCDIC
3252      printf("  EBCDIC code support: LF is 0x%02x\n", CHAR_LF);      printf("  EBCDIC code support: LF is 0x%02x\n", CHAR_LF);
3253  #endif  #endif
3254    
3255  /* 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
3256  are set, either both UTFs are supported or both are not supported. */  are set, either both UTFs are supported or both are not supported. */
# Line 3025  are set, either both UTFs are supported Line 3283  are set, either both UTFs are supported
3283      else      else
3284        printf("  No just-in-time compiler support\n");        printf("  No just-in-time compiler support\n");
3285      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3286      print_newline_config(rc, FALSE);      print_newline_config(rc, FALSE);
3287      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);
3288      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :
3289                                       "all Unicode newlines");                                       "all Unicode newlines");
# Line 3279  while (!done) Line 3537  while (!done)
3537        PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, NULL);        PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, NULL);
3538        if (rc == PCRE_ERROR_BADMODE)        if (rc == PCRE_ERROR_BADMODE)
3539          {          {
3540            pcre_uint16 flags_in_host_byte_order;
3541            if (REAL_PCRE_MAGIC(re) == MAGIC_NUMBER)
3542              flags_in_host_byte_order = REAL_PCRE_FLAGS(re);
3543            else
3544              flags_in_host_byte_order = swap_uint16(REAL_PCRE_FLAGS(re));
3545          /* Simulate the result of the function call below. */          /* Simulate the result of the function call below. */
3546          fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,          fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
3547            pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "",            pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "",
3548            PCRE_INFO_OPTIONS);            PCRE_INFO_OPTIONS);
3549          fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "          fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
3550            "%d-bit mode\n", 8 * CHAR_SIZE,            "%d-bit mode\n", 8 * CHAR_SIZE, 8 * (flags_in_host_byte_order & PCRE_MODE_MASK));
           8 * (REAL_PCRE_FLAGS(re) & PCRE_MODE_MASK));  
3551          new_free(re);          new_free(re);
3552          fclose(f);          fclose(f);
3553          continue;          continue;
# Line 3672  while (!done) Line 3934  while (!done)
3934    
3935        new_info(re, NULL, PCRE_INFO_NAMECOUNT, &name_count);        new_info(re, NULL, PCRE_INFO_NAMECOUNT, &name_count);
3936        new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);        new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
3937          real_pcre_size = 0;
3938  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
3939        if (REAL_PCRE_FLAGS(re) & PCRE_MODE8)        if (REAL_PCRE_FLAGS(re) & PCRE_MODE8)
3940          real_pcre_size = sizeof(real_pcre);          real_pcre_size = sizeof(real_pcre);
# Line 3766  while (!done) Line 4029  while (!done)
4029        if (new_info(re, NULL, PCRE_INFO_SIZE, &size) +        if (new_info(re, NULL, PCRE_INFO_SIZE, &size) +
4030            new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) +            new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) +
4031            new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax) +            new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax) +
4032            new_info(re, NULL, PCRE_INFO_FIRSTLITERAL, &first_char) +            new_info(re, NULL, PCRE_INFO_FIRSTCHARACTER, &first_char) +
4033            new_info(re, NULL, PCRE_INFO_FIRSTLITERALSET, &first_char_set) +            new_info(re, NULL, PCRE_INFO_FIRSTCHARACTERFLAGS, &first_char_set) +
4034            new_info(re, NULL, PCRE_INFO_LASTLITERAL2, &need_char) +            new_info(re, NULL, PCRE_INFO_REQUIREDCHAR, &need_char) +
4035            new_info(re, NULL, PCRE_INFO_LASTLITERAL2SET, &need_char_set) +            new_info(re, NULL, PCRE_INFO_REQUIREDCHARFLAGS, &need_char_set) +
4036            new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize) +            new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize) +
4037            new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount) +            new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount) +
4038            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +
# Line 4060  while (!done) Line 4323  while (!done)
4323    
4324    for (;;)    for (;;)
4325      {      {
4326      pcre_uint8 *q;  #ifdef SUPPORT_PCRE8
4327        pcre_uint8 *q8;
4328    #endif
4329    #ifdef SUPPORT_PCRE16
4330        pcre_uint16 *q16;
4331    #endif
4332    #ifdef SUPPORT_PCRE32
4333        pcre_uint32 *q32;
4334    #endif
4335      pcre_uint8 *bptr;      pcre_uint8 *bptr;
4336      int *use_offsets = offsets;      int *use_offsets = offsets;
4337      int use_size_offsets = size_offsets;      int use_size_offsets = size_offsets;
# Line 4132  while (!done) Line 4403  while (!done)
4403      p = buffer;      p = buffer;
4404      while (isspace(*p)) p++;      while (isspace(*p)) p++;
4405    
4406      bptr = q = dbuffer;  #ifndef NOUTF
4407        /* Check that the data is well-formed UTF-8 if we're in UTF mode. To create
4408           invalid input to pcre_exec, you must use \x?? or \x{} sequences. */
4409        if (use_utf)
4410          {
4411          pcre_uint8 *q;
4412          pcre_uint32 cc;
4413          int n = 1;
4414    
4415          for (q = p; n > 0 && *q; q += n) n = utf82ord(q, &cc);
4416          if (n <= 0)
4417            {
4418            fprintf(outfile, "**Failed: invalid UTF-8 string cannot be used as input in UTF mode\n");
4419            goto NEXT_DATA;
4420            }
4421          }
4422    #endif
4423    
4424    #ifdef SUPPORT_VALGRIND
4425        /* Mark the dbuffer as addressable but undefined again. */
4426        if (dbuffer != NULL)
4427          {
4428          VALGRIND_MAKE_MEM_UNDEFINED(dbuffer, dbuffer_size * CHAR_SIZE);
4429          }
4430    #endif
4431    
4432        /* Allocate a buffer to hold the data line. len+1 is an upper bound on
4433           the number of pcre_uchar units that will be needed. */
4434        if (dbuffer == NULL || (size_t)len >= dbuffer_size)
4435          {
4436          dbuffer_size *= 2;
4437          dbuffer = (pcre_uint8 *)realloc(dbuffer, dbuffer_size * CHAR_SIZE);
4438          if (dbuffer == NULL)
4439            {
4440            fprintf(stderr, "pcretest: malloc(%d) failed\n", (int)dbuffer_size);
4441            exit(1);
4442            }
4443          }
4444    
4445    #ifdef SUPPORT_PCRE8
4446        q8 = (pcre_uint8 *) dbuffer;
4447    #endif
4448    #ifdef SUPPORT_PCRE16
4449        q16 = (pcre_uint16 *) dbuffer;
4450    #endif
4451    #ifdef SUPPORT_PCRE32
4452        q32 = (pcre_uint32 *) dbuffer;
4453    #endif
4454    
4455      while ((c = *p++) != 0)      while ((c = *p++) != 0)
4456        {        {
4457        int i = 0;        int i = 0;
# Line 4145  while (!done) Line 4464  while (!done)
4464    
4465        if (c != '\\')        if (c != '\\')
4466          {          {
4467          if (use_utf)  #ifndef NOUTF
4468            {          if (use_utf && HASUTF8EXTRALEN(c)) { GETUTF8INC(c, p); }
4469            *q++ = c;  #endif
           continue;  
           }  
4470          }          }
4471    
4472        /* Handle backslash escapes */        /* Handle backslash escapes */
# Line 4210  while (!done) Line 4527  while (!done)
4527            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);
4528            p++;            p++;
4529            }            }
4530          if (use_utf)  #if !defined NOUTF && defined SUPPORT_PCRE8
4531            if (use_utf && (pcre_mode == PCRE8_MODE))
4532            {            {
4533            *q++ = c;            *q8++ = c;
4534            continue;            continue;
4535            }            }
4536    #endif
4537          break;          break;
4538    
4539          case 0:   /* \ followed by EOF allows for an empty line */          case 0:   /* \ followed by EOF allows for an empty line */
# Line 4420  while (!done) Line 4739  while (!done)
4739          continue;          continue;
4740          }          }
4741    
4742        /* We now have a character value in c that may be greater than 255. In        /* We now have a character value in c that may be greater than 255.
4743        16-bit or 32-bit mode, we always convert characters to UTF-8 so that        In 8-bit mode we convert to UTF-8 if we are in UTF mode. Values greater
4744        values greater than 255 can be passed to non-UTF 16- or 32-bit strings.        than 127 in UTF mode must have come from \x{...} or octal constructs
       In 8-bit       mode we convert to UTF-8 if we are in UTF mode. Values greater  
       than 127       in UTF mode must have come from \x{...} or octal constructs  
4745        because values from \x.. get this far only in non-UTF mode. */        because values from \x.. get this far only in non-UTF mode. */
4746    
4747  #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32  #ifdef SUPPORT_PCRE8
4748        if (pcre_mode != PCRE8_MODE || use_utf)        if (pcre_mode == PCRE8_MODE)
4749          {          {
4750          pcre_uint8 buff8[8];  #ifndef NOUTF
4751          int ii, utn;          if (use_utf)
4752          utn = ord2utf8(c, buff8);            {
4753          for (ii = 0; ii < utn; ii++) *q++ = buff8[ii];            if (c > 0x7fffffff)
4754                {
4755                fprintf(outfile, "** Character \\x{%x} is greater than 0x7fffffff "
4756                  "and so cannot be converted to UTF-8\n", c);
4757                goto NEXT_DATA;
4758                }
4759              q8 += ord2utf8(c, q8);
4760              }
4761            else
4762    #endif
4763              {
4764              if (c > 0xffu)
4765                {
4766                fprintf(outfile, "** Character \\x{%x} is greater than 255 "
4767                  "and UTF-8 mode is not enabled.\n", c);
4768                fprintf(outfile, "** Truncation will probably give the wrong "
4769                  "result.\n");
4770                }
4771              *q8++ = c;
4772              }
4773          }          }
       else  
4774  #endif  #endif
4775    #ifdef SUPPORT_PCRE16
4776          if (pcre_mode == PCRE16_MODE)
4777          {          {
4778          if (c > 255)  #ifndef NOUTF
4779            if (use_utf)
4780            {            {
4781            fprintf(outfile, "** Character \\x{%x} is greater than 255 "            if (c > 0x10ffffu)
4782              "and UTF-8 mode is not enabled.\n", c);              {
4783            fprintf(outfile, "** Truncation will probably give the wrong "              fprintf(outfile, "** Failed: character \\x{%x} is greater than "
4784              "result.\n");                "0x10ffff and so cannot be converted to UTF-16\n", c);
4785                goto NEXT_DATA;
4786                }
4787              else if (c >= 0x10000u)
4788                {
4789                c-= 0x10000u;
4790                *q16++ = 0xD800 | (c >> 10);
4791                *q16++ = 0xDC00 | (c & 0x3ff);
4792                }
4793              else
4794                *q16++ = c;
4795            }            }
4796          *q++ = c;          else
4797    #endif
4798              {
4799              if (c > 0xffffu)
4800                {
4801                fprintf(outfile, "** Character \\x{%x} is greater than 0xffff "
4802                  "and UTF-16 mode is not enabled.\n", c);
4803                fprintf(outfile, "** Truncation will probably give the wrong "
4804                  "result.\n");
4805                }
4806    
4807              *q16++ = c;
4808              }
4809            }
4810    #endif
4811    #ifdef SUPPORT_PCRE32
4812          if (pcre_mode == PCRE32_MODE)
4813            {
4814            *q32++ = c;
4815          }          }
4816    #endif
4817    
4818        }        }
4819    
4820      /* Reached end of subject string */      /* Reached end of subject string */
4821    
4822      *q = 0;  #ifdef SUPPORT_PCRE8
4823      len = (int)(q - dbuffer);      if (pcre_mode == PCRE8_MODE)
4824        {
4825          *q8 = 0;
4826          len = (int)(q8 - (pcre_uint8 *)dbuffer);
4827        }
4828    #endif
4829    #ifdef SUPPORT_PCRE16
4830        if (pcre_mode == PCRE16_MODE)
4831        {
4832          *q16 = 0;
4833          len = (int)(q16 - (pcre_uint16 *)dbuffer);
4834        }
4835    #endif
4836    #ifdef SUPPORT_PCRE32
4837        if (pcre_mode == PCRE32_MODE)
4838        {
4839          *q32 = 0;
4840          len = (int)(q32 - (pcre_uint32 *)dbuffer);
4841        }
4842    #endif
4843    
4844      /* Move the data to the end of the buffer so that a read over the end of      /* If we're compiling with explicit valgrind support, Mark the data from after
4845      the buffer will be seen by valgrind, even if it doesn't cause a crash. If      its end to the end of the buffer as unaddressable, so that a read over the end
4846      we are using the POSIX interface, we must include the terminating zero. */      of the buffer will be seen by valgrind, even if it doesn't cause a crash.
4847        If we're not building with valgrind support, at least move the data to the end
4848        of the buffer so that it might at least cause a crash.
4849        If we are using the POSIX interface, we must include the terminating zero. */
4850    
4851        bptr = dbuffer;
4852    
4853  #if !defined NOPOSIX  #if !defined NOPOSIX
4854      if (posix || do_posix)      if (posix || do_posix)
4855        {        {
4856        memmove(bptr + buffer_size - len - 1, bptr, len + 1);  #ifdef SUPPORT_VALGRIND
4857        bptr += buffer_size - len - 1;        VALGRIND_MAKE_MEM_NOACCESS(dbuffer + len + 1, dbuffer_size - (len + 1));
4858    #else
4859          memmove(bptr + dbuffer_size - len - 1, bptr, len + 1);
4860          bptr += dbuffer_size - len - 1;
4861    #endif
4862        }        }
4863      else      else
4864  #endif  #endif
4865        {        {
4866        memmove(bptr + buffer_size - len, bptr, len);  #ifdef SUPPORT_VALGRIND
4867        bptr += buffer_size - len;        VALGRIND_MAKE_MEM_NOACCESS(dbuffer + len * CHAR_SIZE, (dbuffer_size - len) * CHAR_SIZE);
4868    #else
4869          bptr = memmove(bptr + (dbuffer_size - len) * CHAR_SIZE, bptr, len * CHAR_SIZE);
4870    #endif
4871        }        }
4872    
4873      if ((all_use_dfa || use_dfa) && find_match_limit)      if ((all_use_dfa || use_dfa) && find_match_limit)
# Line 4532  while (!done) Line 4931  while (!done)
4931    
4932      /* Handle matching via the native interface - repeats for /g and /G */      /* Handle matching via the native interface - repeats for /g and /G */
4933    
 #ifdef SUPPORT_PCRE16  
     if (pcre_mode == PCRE16_MODE)  
       {  
       len = to16(TRUE, bptr, REAL_PCRE_OPTIONS(re) & PCRE_UTF8, len);  
       switch(len)  
         {  
         case -1:  
         fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "  
           "converted to UTF-16\n");  
         goto NEXT_DATA;  
   
         case -2:  
         fprintf(outfile, "**Failed: character value greater than 0x10ffff "  
           "cannot be converted to UTF-16\n");  
         goto NEXT_DATA;  
   
         case -3:  
         fprintf(outfile, "**Failed: character value greater than 0xffff "  
           "cannot be converted to 16-bit in non-UTF mode\n");  
         goto NEXT_DATA;  
   
         default:  
         break;  
         }  
       bptr = (pcre_uint8 *)buffer16;  
       }  
 #endif  
   
 #ifdef SUPPORT_PCRE32  
     if (pcre_mode == PCRE32_MODE)  
       {  
       len = to32(TRUE, bptr, REAL_PCRE_OPTIONS(re) & PCRE_UTF32, len);  
       switch(len)  
         {  
         case -1:  
         fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "  
           "converted to UTF-32\n");  
         goto NEXT_DATA;  
   
         case -2:  
         fprintf(outfile, "**Failed: character value greater than 0x10ffff "  
           "cannot be converted to UTF-32\n");  
         goto NEXT_DATA;  
   
         case -3:  
         fprintf(outfile, "**Failed: character value is ill-formed UTF-32\n");  
         goto NEXT_DATA;  
   
         default:  
         break;  
         }  
       bptr = (pcre_uint8 *)buffer32;  
       }  
 #endif  
   
4934      /* Ensure that there is a JIT callback if we want to verify that JIT was      /* Ensure that there is a JIT callback if we want to verify that JIT was
4935      actually used. If jit_stack == NULL, no stack has yet been assigned. */      actually used. If jit_stack == NULL, no stack has yet been assigned. */
4936    
# Line 4703  while (!done) Line 5047  while (!done)
5047          if (count == 0)          if (count == 0)
5048            {            {
5049            fprintf(outfile, "Matched, but too many substrings\n");            fprintf(outfile, "Matched, but too many substrings\n");
5050            count = use_size_offsets/3;            /* 2 is a special case; match can be returned */
5051              count = (use_size_offsets == 2)? 1 : use_size_offsets/3;
5052            }            }
5053          }          }
5054    
# Line 4717  while (!done) Line 5062  while (!done)
5062  #if !defined NODFA  #if !defined NODFA
5063          if (all_use_dfa || use_dfa) maxcount = use_size_offsets/2; else          if (all_use_dfa || use_dfa) maxcount = use_size_offsets/2; else
5064  #endif  #endif
5065            maxcount = use_size_offsets/3;            /* 2 is a special case; match can be returned */
5066              maxcount = (use_size_offsets == 2)? 1 : use_size_offsets/3;
5067    
5068          /* This is a check against a lunatic return value. */          /* This is a check against a lunatic return value. */
5069    
# Line 4808  while (!done) Line 5154  while (!done)
5154            int rc;            int rc;
5155            char copybuffer[256];            char copybuffer[256];
5156    
5157    #ifdef SUPPORT_PCRE32
5158              if (pcre_mode == PCRE32_MODE)
5159                {
5160                if (*(pcre_uint32 *)cnptr == 0) break;
5161                }
5162    #endif
5163    #ifdef SUPPORT_PCRE16
5164            if (pcre_mode == PCRE16_MODE)            if (pcre_mode == PCRE16_MODE)
5165              {              {
5166              if (*(pcre_uint16 *)cnptr == 0) break;              if (*(pcre_uint16 *)cnptr == 0) break;
5167              }              }
5168            else  #endif
5169    #ifdef SUPPORT_PCRE8
5170              if (pcre_mode == PCRE8_MODE)
5171              {              {
5172              if (*(pcre_uint8 *)cnptr == 0) break;              if (*(pcre_uint8 *)cnptr == 0) break;
5173              }              }
5174    #endif
5175    
5176            PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,            PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,
5177              cnptr, copybuffer, sizeof(copybuffer));              cnptr, copybuffer, sizeof(copybuffer));
# Line 4863  while (!done) Line 5219  while (!done)
5219            int rc;            int rc;
5220            const char *substring;            const char *substring;
5221    
5222    #ifdef SUPPORT_PCRE32
5223              if (pcre_mode == PCRE32_MODE)
5224                {
5225                if (*(pcre_uint32 *)gnptr == 0) break;
5226                }
5227    #endif
5228    #ifdef SUPPORT_PCRE16
5229            if (pcre_mode == PCRE16_MODE)            if (pcre_mode == PCRE16_MODE)
5230              {              {
5231              if (*(pcre_uint16 *)gnptr == 0) break;              if (*(pcre_uint16 *)gnptr == 0) break;
5232              }              }
5233            else  #endif
5234    #ifdef SUPPORT_PCRE8
5235              if (pcre_mode == PCRE8_MODE)
5236              {              {
5237              if (*(pcre_uint8 *)gnptr == 0) break;              if (*(pcre_uint8 *)gnptr == 0) break;
5238              }              }
5239    #endif
5240    
5241            PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,            PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,
5242              gnptr, &substring);              gnptr, &substring);
# Line 4915  while (!done) Line 5281  while (!done)
5281            }            }
5282          }          }
5283    
5284        /* There was a partial match */        /* There was a partial match. If the bumpalong point is not the same as
5285          the first inspected character, show the offset explicitly. */
5286    
5287        else if (count == PCRE_ERROR_PARTIAL)        else if (count == PCRE_ERROR_PARTIAL)
5288          {          {
5289          if (markptr == NULL) fprintf(outfile, "Partial match");          fprintf(outfile, "Partial match");
5290          else          if (use_size_offsets > 2 && use_offsets[0] != use_offsets[2])
5291              fprintf(outfile, " at offset %d", use_offsets[2]);
5292            if (markptr != NULL)
5293            {            {
5294            fprintf(outfile, "Partial match, mark=");            fprintf(outfile, ", mark=");
5295            PCHARSV(markptr, 0, -1, outfile);            PCHARSV(markptr, 0, -1, outfile);
5296            }            }
5297          if (use_size_offsets > 1)          if (use_size_offsets > 1)
# Line 5136  if (dfa_workspace != NULL) Line 5505  if (dfa_workspace != NULL)
5505    free(dfa_workspace);    free(dfa_workspace);
5506  #endif  #endif
5507    
5508    #if defined(__VMS)
5509      yield = SS$_NORMAL;  /* Return values via DCL symbols */
5510    #endif
5511    
5512  return yield;  return yield;
5513  }  }
5514    

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

  ViewVC Help
Powered by ViewVC 1.1.5