/[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 1142 by ph10, Fri Oct 19 15:45:43 2012 UTC
# Line 36  POSSIBILITY OF SUCH DAMAGE. Line 36  POSSIBILITY OF SUCH DAMAGE.
36  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
37  */  */
38    
39  /* This program now supports the testing of both the 8-bit and 16-bit PCRE  /* This program now supports the testing of all of the 8-bit, 16-bit, and
40  libraries in a single program. This is different from the modules such as  32-bit PCRE libraries in a single program. This is different from the modules
41  pcre_compile.c in the library itself, which are compiled separately for each  such as pcre_compile.c in the library itself, which are compiled separately for
42  mode. If both modes are enabled, for example, pcre_compile.c is compiled twice  each mode. If two modes are enabled, for example, pcre_compile.c is compiled
43  (the second time with COMPILE_PCRE16 defined). By contrast, pcretest.c is  twice. By contrast, pcretest.c is compiled only once. Therefore, it must not
44  compiled only once. Therefore, it must not make use of any of the macros from  make use of any of the macros from pcre_internal.h that depend on
45  pcre_internal.h that depend on COMPILE_PCRE8 or COMPILE_PCRE16. It does,  COMPILE_PCRE8, COMPILE_PCRE16, or COMPILE_PCRE32. It does, however, make use of
46  however, make use of SUPPORT_PCRE8 and SUPPORT_PCRE16 to ensure that it calls  SUPPORT_PCRE8, SUPPORT_PCRE16, and SUPPORT_PCRE32 to ensure that it calls only
47  only supported library functions. */  supported library functions. */
48    
49  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
50  #include "config.h"  #include "config.h"
# Line 133  here before pcre_internal.h so that the Line 133  here before pcre_internal.h so that the
133  appropriately for an application, not for building PCRE. */  appropriately for an application, not for building PCRE. */
134    
135  #include "pcre.h"  #include "pcre.h"
   
 #if defined SUPPORT_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  
   
136  #include "pcre_internal.h"  #include "pcre_internal.h"
137    
138  /* The pcre_printint() function, which prints the internal form of a compiled  /* The pcre_printint() function, which prints the internal form of a compiled
# Line 302  argument, the casting might be incorrect Line 288  argument, the casting might be incorrect
288    
289  #define PCRE_JIT_STACK_FREE8(stack) \  #define PCRE_JIT_STACK_FREE8(stack) \
290    pcre_jit_stack_free(stack)    pcre_jit_stack_free(stack)
291    
292    #define pcre8_maketables pcre_maketables
293    
294  #endif /* SUPPORT_PCRE8 */  #endif /* SUPPORT_PCRE8 */
295    
# Line 399  argument, the casting might be incorrect Line 387  argument, the casting might be incorrect
387  #ifdef SUPPORT_PCRE32  #ifdef SUPPORT_PCRE32
388    
389  #define PCHARS32(lv, p, offset, len, f) \  #define PCHARS32(lv, p, offset, len, f) \
390    lv = pchars32((PCRE_SPTR32)(p) + offset, len, f)    lv = pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
391    
392  #define PCHARSV32(p, offset, len, f) \  #define PCHARSV32(p, offset, len, f)                \
393    (void)pchars32((PCRE_SPTR32)(p) + offset, len, f)    (void)pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
394    
395  #define READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re) \  #define READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re) \
396    p = read_capture_name32(p, cn32, re)    p = read_capture_name32(p, cn32, re)
# Line 484  argument, the casting might be incorrect Line 472  argument, the casting might be incorrect
472  #endif /* SUPPORT_PCRE32 */  #endif /* SUPPORT_PCRE32 */
473    
474    
475  /* ----- Both modes are supported; a runtime test is needed, except for  /* ----- More than one mode is supported; a runtime test is needed, except for
476  pcre_config(), and the JIT stack functions, when it doesn't matter which  pcre_config(), and the JIT stack functions, when it doesn't matter which
477  version is called. ----- */  available version is called. ----- */
478    
479  enum {  enum {
480    PCRE8_MODE,    PCRE8_MODE,
# Line 494  enum { Line 482  enum {
482    PCRE32_MODE    PCRE32_MODE
483  };  };
484    
485  #if (defined (SUPPORT_PCRE8) + defined (SUPPORT_PCRE16) + defined (SUPPORT_PCRE32)) >= 2  #if (defined (SUPPORT_PCRE8) + defined (SUPPORT_PCRE16) + \
486         defined (SUPPORT_PCRE32)) >= 2
487    
488  #define CHAR_SIZE (1 << pcre_mode)  #define CHAR_SIZE (1 << pcre_mode)
489    
490    /* There doesn't seem to be an easy way of writing these macros that can cope
491    with the 3 pairs of bit sizes plus all three bit sizes. So just handle all the
492    cases separately. */
493    
494    /* ----- All three modes supported ----- */
495    
496    #if defined(SUPPORT_PCRE8) && defined(SUPPORT_PCRE16) && defined(SUPPORT_PCRE32)
497    
498  #define PCHARS(lv, p, offset, len, f) \  #define PCHARS(lv, p, offset, len, f) \
499    if (pcre_mode == PCRE32_MODE) \    if (pcre_mode == PCRE32_MODE) \
500      PCHARS32(lv, p, offset, len, f); \      PCHARS32(lv, p, offset, len, f); \
# Line 696  enum { Line 693  enum {
693    else \    else \
694      PCRE_STUDY8(extra, re, options, error)      PCRE_STUDY8(extra, re, options, error)
695    
696    
697    /* ----- Two out of three modes are supported ----- */
698    
699    #else
700    
701    /* We can use some macro trickery to make a single set of definitions work in
702    the three different cases. */
703    
704    /* ----- 32-bit and 16-bit but not 8-bit supported ----- */
705    
706    #if defined(SUPPORT_PCRE32) && defined(SUPPORT_PCRE16)
707    #define BITONE 32
708    #define BITTWO 16
709    
710    /* ----- 32-bit and 8-bit but not 16-bit supported ----- */
711    
712    #elif defined(SUPPORT_PCRE32) && defined(SUPPORT_PCRE8)
713    #define BITONE 32
714    #define BITTWO 8
715    
716    /* ----- 16-bit and 8-bit but not 32-bit supported ----- */
717    
718    #else
719    #define BITONE 16
720    #define BITTWO 8
721    #endif
722    
723    #define glue(a,b) a##b
724    #define G(a,b) glue(a,b)
725    
726    
727    /* ----- Common macros for two-mode cases ----- */
728    
729    #define PCHARS(lv, p, offset, len, f) \
730      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
731        G(PCHARS,BITONE)(lv, p, offset, len, f); \
732      else \
733        G(PCHARS,BITTWO)(lv, p, offset, len, f)
734    
735    #define PCHARSV(p, offset, len, f) \
736      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
737        G(PCHARSV,BITONE)(p, offset, len, f); \
738      else \
739        G(PCHARSV,BITTWO)(p, offset, len, f)
740    
741    #define READ_CAPTURE_NAME(p, cn8, cn16, cn32, re) \
742      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
743        G(READ_CAPTURE_NAME,BITONE)(p, cn8, cn16, cn32, re); \
744      else \
745        G(READ_CAPTURE_NAME,BITTWO)(p, cn8, cn16, cn32, re)
746    
747    #define SET_PCRE_CALLOUT(callout) \
748      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
749        G(SET_PCRE_CALLOUT,BITONE)(callout); \
750      else \
751        G(SET_PCRE_CALLOUT,BITTWO)(callout)
752    
753    #define STRLEN(p) ((pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
754      G(STRLEN,BITONE)(p) : G(STRLEN,BITTWO)(p))
755    
756    #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
757      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
758        G(PCRE_ASSIGN_JIT_STACK,BITONE)(extra, callback, userdata); \
759      else \
760        G(PCRE_ASSIGN_JIT_STACK,BITTWO)(extra, callback, userdata)
761    
762    #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
763      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
764        G(PCRE_COMPILE,BITONE)(re, pat, options, error, erroffset, tables); \
765      else \
766        G(PCRE_COMPILE,BITTWO)(re, pat, options, error, erroffset, tables)
767    
768    #define PCRE_CONFIG G(G(pcre,BITONE),_config)
769    
770    #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
771        namesptr, cbuffer, size) \
772      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
773        G(PCRE_COPY_NAMED_SUBSTRING,BITONE)(rc, re, bptr, offsets, count, \
774          namesptr, cbuffer, size); \
775      else \
776        G(PCRE_COPY_NAMED_SUBSTRING,BITTWO)(rc, re, bptr, offsets, count, \
777          namesptr, cbuffer, size)
778    
779    #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \
780      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
781        G(PCRE_COPY_SUBSTRING,BITONE)(rc, bptr, offsets, count, i, cbuffer, size); \
782      else \
783        G(PCRE_COPY_SUBSTRING,BITTWO)(rc, bptr, offsets, count, i, cbuffer, size)
784    
785    #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \
786        offsets, size_offsets, workspace, size_workspace) \
787      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
788        G(PCRE_DFA_EXEC,BITONE)(count, re, extra, bptr, len, start_offset, options, \
789          offsets, size_offsets, workspace, size_workspace); \
790      else \
791        G(PCRE_DFA_EXEC,BITTWO)(count, re, extra, bptr, len, start_offset, options, \
792          offsets, size_offsets, workspace, size_workspace)
793    
794    #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
795        offsets, size_offsets) \
796      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
797        G(PCRE_EXEC,BITONE)(count, re, extra, bptr, len, start_offset, options, \
798          offsets, size_offsets); \
799      else \
800        G(PCRE_EXEC,BITTWO)(count, re, extra, bptr, len, start_offset, options, \
801          offsets, size_offsets)
802    
803    #define PCRE_FREE_STUDY(extra) \
804      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
805        G(PCRE_FREE_STUDY,BITONE)(extra); \
806      else \
807        G(PCRE_FREE_STUDY,BITTWO)(extra)
808    
809    #define PCRE_FREE_SUBSTRING(substring) \
810      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
811        G(PCRE_FREE_SUBSTRING,BITONE)(substring); \
812      else \
813        G(PCRE_FREE_SUBSTRING,BITTWO)(substring)
814    
815    #define PCRE_FREE_SUBSTRING_LIST(listptr) \
816      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
817        G(PCRE_FREE_SUBSTRING_LIST,BITONE)(listptr); \
818      else \
819        G(PCRE_FREE_SUBSTRING_LIST,BITTWO)(listptr)
820    
821    #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
822        getnamesptr, subsptr) \
823      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
824        G(PCRE_GET_NAMED_SUBSTRING,BITONE)(rc, re, bptr, offsets, count, \
825          getnamesptr, subsptr); \
826      else \
827        G(PCRE_GET_NAMED_SUBSTRING,BITTWO)(rc, re, bptr, offsets, count, \
828          getnamesptr, subsptr)
829    
830    #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \
831      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
832        G(PCRE_GET_STRINGNUMBER,BITONE)(n, rc, ptr); \
833      else \
834        G(PCRE_GET_STRINGNUMBER,BITTWO)(n, rc, ptr)
835    
836    #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \
837      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
838        G(PCRE_GET_SUBSTRING,BITONE)(rc, bptr, use_offsets, count, i, subsptr); \
839      else \
840        G(PCRE_GET_SUBSTRING,BITTWO)(rc, bptr, use_offsets, count, i, subsptr)
841    
842    #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \
843      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
844        G(PCRE_GET_SUBSTRING_LIST,BITONE)(rc, bptr, offsets, count, listptr); \
845      else \
846        G(PCRE_GET_SUBSTRING_LIST,BITTWO)(rc, bptr, offsets, count, listptr)
847    
848    #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
849      (pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
850         G(PCRE_JIT_STACK_ALLOC,BITONE)(startsize, maxsize) \
851        : G(PCRE_JIT_STACK_ALLOC,BITTWO)(startsize, maxsize)
852    
853    #define PCRE_JIT_STACK_FREE(stack) \
854      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
855        G(PCRE_JIT_STACK_FREE,BITONE)(stack); \
856      else \
857        G(PCRE_JIT_STACK_FREE,BITTWO)(stack)
858    
859    #define PCRE_MAKETABLES \
860      (pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
861        G(G(pcre,BITONE),_maketables)() : G(G(pcre,BITTWO),_maketables)()
862    
863    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \
864      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
865        G(PCRE_PATTERN_TO_HOST_BYTE_ORDER,BITONE)(rc, re, extra, tables); \
866      else \
867        G(PCRE_PATTERN_TO_HOST_BYTE_ORDER,BITTWO)(rc, re, extra, tables)
868    
869    #define PCRE_PRINTINT(re, outfile, debug_lengths) \
870      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
871        G(PCRE_PRINTINT,BITONE)(re, outfile, debug_lengths); \
872      else \
873        G(PCRE_PRINTINT,BITTWO)(re, outfile, debug_lengths)
874    
875    #define PCRE_STUDY(extra, re, options, error) \
876      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
877        G(PCRE_STUDY,BITONE)(extra, re, options, error); \
878      else \
879        G(PCRE_STUDY,BITTWO)(extra, re, options, error)
880    
881    #endif  /* Two out of three modes */
882    
883    /* ----- End of cases where more than one mode is supported ----- */
884    
885    
886  /* ----- Only 8-bit mode is supported ----- */  /* ----- Only 8-bit mode is supported ----- */
887    
888  #elif defined SUPPORT_PCRE8  #elif defined SUPPORT_PCRE8
# Line 831  static const unsigned char *last_callout Line 1018  static const unsigned char *last_callout
1018    
1019  static int buffer_size = 50000;  static int buffer_size = 50000;
1020  static pcre_uint8 *buffer = NULL;  static pcre_uint8 *buffer = NULL;
 static pcre_uint8 *dbuffer = NULL;  
1021  static pcre_uint8 *pbuffer = NULL;  static pcre_uint8 *pbuffer = NULL;
1022    
1023  /* Another buffer is needed translation to 16/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. */  
1024    
1025  #ifdef COMPILE_PCRE16  #ifdef COMPILE_PCRE16
1026  #error COMPILE_PCRE16 must not be set when compiling pcretest.c  #error COMPILE_PCRE16 must not be set when compiling pcretest.c
# Line 853  COMPILE_PCRE[16|32] is *not* set. */ Line 1030  COMPILE_PCRE[16|32] is *not* set. */
1030  #error COMPILE_PCRE32 must not be set when compiling pcretest.c  #error COMPILE_PCRE32 must not be set when compiling pcretest.c
1031  #endif  #endif
1032    
1033    /* We need buffers for building 16/32-bit strings, and the tables of operator
1034    lengths that are used for 16/32-bit compiling, in order to swap bytes in a
1035    pattern for saving/reloading testing. Luckily, the data for these tables is
1036    defined as a macro. However, we must ensure that LINK_SIZE and IMM2_SIZE (which
1037    are used in the tables) are adjusted appropriately for the 16/32-bit world.
1038    LINK_SIZE is also used later in this program. */
1039    
1040    #ifdef SUPPORT_PCRE16
1041    #undef IMM2_SIZE
1042    #define IMM2_SIZE 1
1043    
1044  #if LINK_SIZE == 2  #if LINK_SIZE == 2
1045  #undef LINK_SIZE  #undef LINK_SIZE
1046  #define LINK_SIZE 1  #define LINK_SIZE 1
# Line 863  COMPILE_PCRE[16|32] is *not* set. */ Line 1051  COMPILE_PCRE[16|32] is *not* set. */
1051  #error LINK_SIZE must be either 2, 3, or 4  #error LINK_SIZE must be either 2, 3, or 4
1052  #endif  #endif
1053    
 #undef IMM2_SIZE  
 #define IMM2_SIZE 1  
   
 #endif /* SUPPORT_PCRE8 && (SUPPORT_PCRE16 || SUPPORT_PCRE32) */  
   
 #ifdef SUPPORT_PCRE16  
1054  static int buffer16_size = 0;  static int buffer16_size = 0;
1055  static pcre_uint16 *buffer16 = NULL;  static pcre_uint16 *buffer16 = NULL;
1056  static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };  static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };
1057  #endif  /* SUPPORT_PCRE16 */  #endif  /* SUPPORT_PCRE16 */
1058    
1059  #ifdef SUPPORT_PCRE32  #ifdef SUPPORT_PCRE32
1060    #undef IMM2_SIZE
1061    #define IMM2_SIZE 1
1062    #undef LINK_SIZE
1063    #define LINK_SIZE 1
1064    
1065  static int buffer32_size = 0;  static int buffer32_size = 0;
1066  static pcre_uint32 *buffer32 = NULL;  static pcre_uint32 *buffer32 = NULL;
1067  static const pcre_uint32 OP_lengths32[] = { OP_LENGTHS };  static const pcre_uint32 OP_lengths32[] = { OP_LENGTHS };
1068  #endif  /* SUPPORT_PCRE32 */  #endif  /* SUPPORT_PCRE32 */
1069    
1070  /* 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
1071  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
1072  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. */
1073    
1074  #if defined SUPPORT_PCRE8  #if defined SUPPORT_PCRE8
1075  static int pcre_mode = PCRE8_MODE;  static int pcre_mode = PCRE8_MODE;
# Line 1299  return sys_errlist[n]; Line 1486  return sys_errlist[n];
1486  *       Print newline configuration              *  *       Print newline configuration              *
1487  *************************************************/  *************************************************/
1488    
1489  /*  /*
1490  Arguments:  Arguments:
1491    rc         the return code from PCRE_CONFIG_NEWLINE    rc         the return code from PCRE_CONFIG_NEWLINE
1492    isc        TRUE if called from "-C newline"    isc        TRUE if called from "-C newline"
1493  Returns:     nothing  Returns:     nothing
1494  */  */
1495    
# Line 1318  switch(rc) Line 1505  switch(rc)
1505    case (CHAR_CR<<8 | CHAR_LF): s = "CRLF"; break;    case (CHAR_CR<<8 | CHAR_LF): s = "CRLF"; break;
1506    case -1: s = "ANY"; break;    case -1: s = "ANY"; break;
1507    case -2: s = "ANYCRLF"; break;    case -2: s = "ANYCRLF"; break;
1508    
1509    default:    default:
1510    printf("a non-standard value: 0x%04x\n", rc);    printf("a non-standard value: 0x%04x\n", rc);
1511    return;    return;
1512    }    }
1513    
1514  printf("%s\n", s);  printf("%s\n", s);
1515  }  }
# Line 1388  for (j = 0; j < i; j++) Line 1575  for (j = 0; j < i; j++)
1575  /* Check that encoding was the correct unique one */  /* Check that encoding was the correct unique one */
1576    
1577  for (j = 0; j < utf8_table1_size; j++)  for (j = 0; j < utf8_table1_size; j++)
1578    if (d <= utf8_table1[j]) break;    if (d <= (pcre_uint32)utf8_table1[j]) break;
1579  if (j != i) return -(i+1);  if (j != i) return -(i+1);
1580    
1581  /* Valid value */  /* Valid value */
# Line 1400  return i+1; Line 1587  return i+1;
1587    
1588    
1589    
1590  #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32  #if defined SUPPORT_PCRE8 && !defined NOUTF
1591  /*************************************************  /*************************************************
1592  *       Convert character value to UTF-8         *  *       Convert character value to UTF-8         *
1593  *************************************************/  *************************************************/
# Line 1422  register int i, j; Line 1609  register int i, j;
1609  if (cvalue > 0x7fffffffu)  if (cvalue > 0x7fffffffu)
1610    return -1;    return -1;
1611  for (i = 0; i < utf8_table1_size; i++)  for (i = 0; i < utf8_table1_size; i++)
1612    if (cvalue <= utf8_table1[i]) break;    if (cvalue <= (pcre_uint32)utf8_table1[i]) break;
1613  utf8bytes += i;  utf8bytes += i;
1614  for (j = i; j > 0; j--)  for (j = i; j > 0; j--)
1615   {   {
# Line 1590  else Line 1777  else
1777  *pp = 0;  *pp = 0;
1778  return pp - buffer32;  return pp - buffer32;
1779  }  }
1780    
1781    /* Check that a 32-bit character string is valid UTF-32.
1782    
1783    Arguments:
1784      string       points to the string
1785      length       length of string, or -1 if the string is zero-terminated
1786    
1787    Returns:       TRUE  if the string is a valid UTF-32 string
1788                   FALSE otherwise
1789    */
1790    
1791    #ifdef SUPPORT_UTF
1792    static BOOL
1793    valid_utf32(pcre_uint32 *string, int length)
1794    {
1795    register pcre_uint32 *p;
1796    register pcre_uint32 c;
1797    
1798    for (p = string; length-- > 0; p++)
1799      {
1800      c = *p;
1801    
1802      if (c > 0x10ffffu)
1803        return FALSE;
1804    
1805      /* A surrogate */
1806      if ((c & 0xfffff800u) == 0xd800u)
1807        return FALSE;
1808    
1809      /* Non-character */
1810      if ((c & 0xfffeu) == 0xfffeu || (c >= 0xfdd0u && c <= 0xfdefu))
1811        return FALSE;
1812      }
1813    
1814    return TRUE;
1815    }
1816    #endif /* SUPPORT_UTF */
1817    
1818  #endif  #endif
1819    
1820  /*************************************************  /*************************************************
# Line 1666  for (;;) Line 1891  for (;;)
1891      {      {
1892      int new_buffer_size = 2*buffer_size;      int new_buffer_size = 2*buffer_size;
1893      pcre_uint8 *new_buffer = (pcre_uint8 *)malloc(new_buffer_size);      pcre_uint8 *new_buffer = (pcre_uint8 *)malloc(new_buffer_size);
     pcre_uint8 *new_dbuffer = (pcre_uint8 *)malloc(new_buffer_size);  
1894      pcre_uint8 *new_pbuffer = (pcre_uint8 *)malloc(new_buffer_size);      pcre_uint8 *new_pbuffer = (pcre_uint8 *)malloc(new_buffer_size);
1895    
1896      if (new_buffer == NULL || new_dbuffer == NULL || new_pbuffer == NULL)      if (new_buffer == NULL || new_pbuffer == NULL)
1897        {        {
1898        fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);        fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);
1899        exit(1);        exit(1);
# Line 1684  for (;;) Line 1908  for (;;)
1908      here = new_buffer + (here - buffer);      here = new_buffer + (here - buffer);
1909    
1910      free(buffer);      free(buffer);
     free(dbuffer);  
1911      free(pbuffer);      free(pbuffer);
1912    
1913      buffer = new_buffer;      buffer = new_buffer;
     dbuffer = new_dbuffer;  
1914      pbuffer = new_pbuffer;      pbuffer = new_pbuffer;
1915      }      }
1916    }    }
# Line 1733  return(result); Line 1955  return(result);
1955    
1956  static int pchar(pcre_uint32 c, FILE *f)  static int pchar(pcre_uint32 c, FILE *f)
1957  {  {
1958  int n;  int n = 0;
1959  if (PRINTOK(c))  if (PRINTOK(c))
1960    {    {
1961    if (f != NULL) fprintf(f, "%c", c);    if (f != NULL) fprintf(f, "%c", c);
# Line 1878  return yield; Line 2100  return yield;
2100  /* 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.
2101  If handed a NULL file, just counts chars without printing. */  If handed a NULL file, just counts chars without printing. */
2102    
2103  static int pchars32(PCRE_SPTR32 p, int length, FILE *f)  #define UTF32_MASK (0x1fffffu)
2104    
2105    static int pchars32(PCRE_SPTR32 p, int length, BOOL utf, FILE *f)
2106  {  {
2107  int yield = 0;  int yield = 0;
2108    
# Line 1888  if (length < 0) Line 2112  if (length < 0)
2112  while (length-- > 0)  while (length-- > 0)
2113    {    {
2114    pcre_uint32 c = *p++;    pcre_uint32 c = *p++;
2115      if (utf) c &= UTF32_MASK;
2116    yield += pchar(c, f);    yield += pchar(c, f);
2117    }    }
2118    
# Line 2417  real_pcre32 *re = (real_pcre32 *)ere; Line 2642  real_pcre32 *re = (real_pcre32 *)ere;
2642  int op;  int op;
2643  pcre_uint32 *ptr = (pcre_uint32 *)re + re->name_table_offset;  pcre_uint32 *ptr = (pcre_uint32 *)re + re->name_table_offset;
2644  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 */  
2645    
2646  /* Always flip the bytes in the main data block and study blocks. */  /* Always flip the bytes in the main data block and study blocks. */
2647    
# Line 2443  if (extra != NULL) Line 2665  if (extra != NULL)
2665    rsd->minlength = swap_uint32(rsd->minlength);    rsd->minlength = swap_uint32(rsd->minlength);
2666    }    }
2667    
2668  /* 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
2669  in the name table, if present, and then in the pattern itself. */  the pattern itself. */
2670    
2671  while(TRUE)  while(TRUE)
2672    {    {
# Line 2718  int done = 0; Line 2940  int done = 0;
2940  int all_use_dfa = 0;  int all_use_dfa = 0;
2941  int verify_jit = 0;  int verify_jit = 0;
2942  int yield = 0;  int yield = 0;
2943    #ifdef SUPPORT_PCRE32
2944    int mask_utf32 = 0;
2945    #endif
2946  int stack_size;  int stack_size;
2947    pcre_uint8 *dbuffer = NULL;
2948    size_t dbuffer_size = 1u << 14;
2949    
2950  #if !defined NOPOSIX  #if !defined NOPOSIX
2951  int posix = 0;  int posix = 0;
# Line 2758  pcre_uint8 *gn8ptr; Line 2985  pcre_uint8 *gn8ptr;
2985  #endif  #endif
2986    
2987  /* Get buffers from malloc() so that valgrind will check their misuse when  /* Get buffers from malloc() so that valgrind will check their misuse when
2988  debugging. They grow automatically when very long lines are read. The 16-  debugging. They grow automatically when very long lines are read. The 16-
2989  and 32-bit buffers (buffer16, buffer32) are obtained only if needed. */  and 32-bit buffers (buffer16, buffer32) are obtained only if needed. */
2990    
2991  buffer = (pcre_uint8 *)malloc(buffer_size);  buffer = (pcre_uint8 *)malloc(buffer_size);
 dbuffer = (pcre_uint8 *)malloc(buffer_size);  
2992  pbuffer = (pcre_uint8 *)malloc(buffer_size);  pbuffer = (pcre_uint8 *)malloc(buffer_size);
2993    
2994  /* The outfile variable is static so that new_malloc can use it. */  /* The outfile variable is static so that new_malloc can use it. */
# Line 2810  while (argc > 1 && argv[op][0] == '-') Line 3036  while (argc > 1 && argv[op][0] == '-')
3036        force_study_options = jit_study_bits[*arg - '1'];        force_study_options = jit_study_bits[*arg - '1'];
3037      else goto BAD_ARG;      else goto BAD_ARG;
3038      }      }
3039      else if (strcmp(arg, "-8") == 0)
3040        {
3041    #ifdef SUPPORT_PCRE8
3042        pcre_mode = PCRE8_MODE;
3043    #else
3044        printf("** This version of PCRE was built without 8-bit support\n");
3045        exit(1);
3046    #endif
3047        }
3048    else if (strcmp(arg, "-16") == 0)    else if (strcmp(arg, "-16") == 0)
3049      {      {
3050  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
# Line 2819  while (argc > 1 && argv[op][0] == '-') Line 3054  while (argc > 1 && argv[op][0] == '-')
3054      exit(1);      exit(1);
3055  #endif  #endif
3056      }      }
3057    else if (strcmp(arg, "-32") == 0)    else if (strcmp(arg, "-32") == 0 || strcmp(arg, "-32+") == 0)
3058      {      {
3059  #ifdef SUPPORT_PCRE32  #ifdef SUPPORT_PCRE32
3060      pcre_mode = PCRE32_MODE;      pcre_mode = PCRE32_MODE;
3061        mask_utf32 = (strcmp(arg, "-32+") == 0);
3062  #else  #else
3063      printf("** This version of PCRE was built without 32-bit support\n");      printf("** This version of PCRE was built without 32-bit support\n");
3064      exit(1);      exit(1);
# Line 2959  while (argc > 1 && argv[op][0] == '-') Line 3195  while (argc > 1 && argv[op][0] == '-')
3195        else if (strcmp(argv[op + 1], "newline") == 0)        else if (strcmp(argv[op + 1], "newline") == 0)
3196          {          {
3197          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3198          print_newline_config(rc, TRUE);          print_newline_config(rc, TRUE);
3199          }          }
3200        else if (strcmp(argv[op + 1], "ebcdic") == 0)        else if (strcmp(argv[op + 1], "ebcdic") == 0)
3201          {          {
3202  #ifdef EBCDIC  #ifdef EBCDIC
3203          printf("1\n");          printf("1\n");
3204          yield = 1;          yield = 1;
3205  #else  #else
3206          printf("0\n");          printf("0\n");
3207  #endif  #endif
3208          }          }
3209        else if (strcmp(argv[op + 1], "ebcdic-nl") == 0)        else if (strcmp(argv[op + 1], "ebcdic-nl") == 0)
3210          {          {
3211  #ifdef EBCDIC  #ifdef EBCDIC
3212          printf("0x%02x\n", CHAR_LF);          printf("0x%02x\n", CHAR_LF);
3213  #else  #else
3214          printf("0\n");          printf("0\n");
3215  #endif  #endif
3216          }          }
3217        else        else
3218          {          {
3219          printf("Unknown -C option: %s\n", argv[op + 1]);          printf("Unknown -C option: %s\n", argv[op + 1]);
3220          }          }
3221        goto EXIT;        goto EXIT;
3222        }        }
3223    
3224      /* No argument for -C: output all configuration information. */      /* No argument for -C: output all configuration information. */
3225    
3226      printf("PCRE version %s\n", version);      printf("PCRE version %s\n", version);
3227      printf("Compiled with\n");      printf("Compiled with\n");
3228    
3229  #ifdef EBCDIC  #ifdef EBCDIC
3230      printf("  EBCDIC code support: LF is 0x%02x\n", CHAR_LF);      printf("  EBCDIC code support: LF is 0x%02x\n", CHAR_LF);
3231  #endif  #endif
3232    
3233  /* At least one of SUPPORT_PCRE8 and SUPPORT_PCRE16 will be set. If both  /* At least one of SUPPORT_PCRE8 and SUPPORT_PCRE16 will be set. If both
3234  are set, either both UTFs are supported or both are not supported. */  are set, either both UTFs are supported or both are not supported. */
# Line 3025  are set, either both UTFs are supported Line 3261  are set, either both UTFs are supported
3261      else      else
3262        printf("  No just-in-time compiler support\n");        printf("  No just-in-time compiler support\n");
3263      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3264      print_newline_config(rc, FALSE);      print_newline_config(rc, FALSE);
3265      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);
3266      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :
3267                                       "all Unicode newlines");                                       "all Unicode newlines");
# Line 3672  while (!done) Line 3908  while (!done)
3908    
3909        new_info(re, NULL, PCRE_INFO_NAMECOUNT, &name_count);        new_info(re, NULL, PCRE_INFO_NAMECOUNT, &name_count);
3910        new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);        new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
3911          real_pcre_size = 0;
3912  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
3913        if (REAL_PCRE_FLAGS(re) & PCRE_MODE8)        if (REAL_PCRE_FLAGS(re) & PCRE_MODE8)
3914          real_pcre_size = sizeof(real_pcre);          real_pcre_size = sizeof(real_pcre);
# Line 3766  while (!done) Line 4003  while (!done)
4003        if (new_info(re, NULL, PCRE_INFO_SIZE, &size) +        if (new_info(re, NULL, PCRE_INFO_SIZE, &size) +
4004            new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) +            new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) +
4005            new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax) +            new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax) +
4006            new_info(re, NULL, PCRE_INFO_FIRSTLITERAL, &first_char) +            new_info(re, NULL, PCRE_INFO_FIRSTCHARACTER, &first_char) +
4007            new_info(re, NULL, PCRE_INFO_FIRSTLITERALSET, &first_char_set) +            new_info(re, NULL, PCRE_INFO_FIRSTCHARACTERFLAGS, &first_char_set) +
4008            new_info(re, NULL, PCRE_INFO_LASTLITERAL2, &need_char) +            new_info(re, NULL, PCRE_INFO_REQUIREDCHAR, &need_char) +
4009            new_info(re, NULL, PCRE_INFO_LASTLITERAL2SET, &need_char_set) +            new_info(re, NULL, PCRE_INFO_REQUIREDCHARFLAGS, &need_char_set) +
4010            new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize) +            new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize) +
4011            new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount) +            new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount) +
4012            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +
# Line 4060  while (!done) Line 4297  while (!done)
4297    
4298    for (;;)    for (;;)
4299      {      {
4300      pcre_uint8 *q;  #ifdef SUPPORT_PCRE8
4301        pcre_uint8 *q8;
4302    #endif
4303    #ifdef SUPPORT_PCRE16
4304        pcre_uint16 *q16;
4305    #endif
4306    #ifdef SUPPORT_PCRE32
4307        pcre_uint32 *q32;
4308    #endif
4309      pcre_uint8 *bptr;      pcre_uint8 *bptr;
4310      int *use_offsets = offsets;      int *use_offsets = offsets;
4311      int use_size_offsets = size_offsets;      int use_size_offsets = size_offsets;
# Line 4132  while (!done) Line 4377  while (!done)
4377      p = buffer;      p = buffer;
4378      while (isspace(*p)) p++;      while (isspace(*p)) p++;
4379    
4380      bptr = q = dbuffer;  #ifndef NOUTF
4381        /* Check that the data is well-formed UTF-8 if we're in UTF mode. To create
4382           invalid input to pcre_exec, you must use \x?? or \x{} sequences. */
4383        if (use_utf)
4384          {
4385          pcre_uint8 *q;
4386          pcre_uint32 cc;
4387          int n = 1;
4388    
4389          for (q = p; n > 0 && *q; q += n) n = utf82ord(q, &cc);
4390          if (n <= 0)
4391            {
4392            fprintf(outfile, "**Failed: invalid UTF-8 string cannot be used as input in UTF mode\n");
4393            goto NEXT_DATA;
4394            }
4395          }
4396    #endif
4397    
4398        /* Allocate a buffer to hold the data line. len+1 is an upper bound on
4399           the number of pcre_uchar units that will be needed. */
4400        if (dbuffer == NULL || (size_t)len >= dbuffer_size)
4401          {
4402          dbuffer_size *= 2;
4403          dbuffer = (pcre_uint8 *)realloc(dbuffer, dbuffer_size * CHAR_SIZE);
4404          if (dbuffer == NULL)
4405            {
4406            fprintf(stderr, "pcretest: malloc(%d) failed\n", dbuffer_size);
4407            exit(1);
4408            }
4409          }
4410    
4411    #ifdef SUPPORT_PCRE8
4412        q8 = (pcre_uint8 *) dbuffer;
4413    #endif
4414    #ifdef SUPPORT_PCRE16
4415        q16 = (pcre_uint16 *) dbuffer;
4416    #endif
4417    #ifdef SUPPORT_PCRE32
4418        q32 = (pcre_uint32 *) dbuffer;
4419    #endif
4420    
4421      while ((c = *p++) != 0)      while ((c = *p++) != 0)
4422        {        {
4423        int i = 0;        int i = 0;
# Line 4145  while (!done) Line 4430  while (!done)
4430    
4431        if (c != '\\')        if (c != '\\')
4432          {          {
4433          if (use_utf)  #ifndef NOUTF
4434            {          if (use_utf && HASUTF8EXTRALEN(c)) { GETUTF8INC(c, p); }
4435            *q++ = c;  #endif
           continue;  
           }  
4436          }          }
4437    
4438        /* Handle backslash escapes */        /* Handle backslash escapes */
# Line 4210  while (!done) Line 4493  while (!done)
4493            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);
4494            p++;            p++;
4495            }            }
4496          if (use_utf)  #if !defined NOUTF && defined SUPPORT_PCRE8
4497            if (use_utf && (pcre_mode == PCRE8_MODE))
4498            {            {
4499            *q++ = c;            *q8++ = c;
4500            continue;            continue;
4501            }            }
4502    #endif
4503          break;          break;
4504    
4505          case 0:   /* \ followed by EOF allows for an empty line */          case 0:   /* \ followed by EOF allows for an empty line */
# Line 4420  while (!done) Line 4705  while (!done)
4705          continue;          continue;
4706          }          }
4707    
4708        /* We now have a character value in c that may be greater than 255. In        /* We now have a character value in c that may be greater than 255.
4709        16-bit 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
4710        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  
4711        because values from \x.. get this far only in non-UTF mode. */        because values from \x.. get this far only in non-UTF mode. */
4712    
4713  #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32  #ifdef SUPPORT_PCRE8
4714        if (pcre_mode != PCRE8_MODE || use_utf)        if (pcre_mode == PCRE8_MODE)
4715          {          {
4716          pcre_uint8 buff8[8];  #ifndef NOUTF
4717          int ii, utn;          if (use_utf)
4718          utn = ord2utf8(c, buff8);            {
4719          for (ii = 0; ii < utn; ii++) *q++ = buff8[ii];            q8 += ord2utf8(c, q8);
4720              }
4721            else
4722    #endif
4723              {
4724              if (c > 0xffu)
4725                {
4726                fprintf(outfile, "** Character \\x{%x} is greater than 255 "
4727                  "and UTF-8 mode is not enabled.\n", c);
4728                fprintf(outfile, "** Truncation will probably give the wrong "
4729                  "result.\n");
4730                }
4731              *q8++ = c;
4732              }
4733          }          }
       else  
4734  #endif  #endif
4735    #ifdef SUPPORT_PCRE16
4736          if (pcre_mode == PCRE16_MODE)
4737          {          {
4738          if (c > 255)  #ifndef NOUTF
4739            if (use_utf)
4740            {            {
4741            fprintf(outfile, "** Character \\x{%x} is greater than 255 "            if (c > 0x10ffffu)
4742              "and UTF-8 mode is not enabled.\n", c);              {
4743            fprintf(outfile, "** Truncation will probably give the wrong "              fprintf(outfile, "**Failed: character value greater than 0x10ffff "
4744              "result.\n");                "cannot be converted to UTF-16\n");
4745                goto NEXT_DATA;
4746                }
4747              else if (c >= 0x10000u)
4748                {
4749                c-= 0x10000u;
4750                *q16++ = 0xD800 | (c >> 10);
4751                *q16++ = 0xDC00 | (c & 0x3ff);
4752                }
4753              else
4754                *q16++ = c;
4755            }            }
4756          *q++ = c;          else
4757    #endif
4758              {
4759              if (c > 0xffffu)
4760                {
4761                fprintf(outfile, "** Character value is greater than 0xffff "
4762                  "and UTF-16 mode is not enabled.\n");
4763                fprintf(outfile, "** Truncation will probably give the wrong "
4764                  "result.\n");
4765                }
4766    
4767              *q16++ = c;
4768              }
4769            }
4770    #endif
4771    #ifdef SUPPORT_PCRE32
4772          if (pcre_mode == PCRE32_MODE)
4773            {
4774            *q32++ = c;
4775          }          }
4776    #endif
4777    
4778        }        }
4779    
4780      /* Reached end of subject string */      /* Reached end of subject string */
4781    
4782      *q = 0;  #ifdef SUPPORT_PCRE8
4783      len = (int)(q - dbuffer);      if (pcre_mode == PCRE8_MODE)
4784        {
4785          *q8 = 0;
4786          len = (int)(q8 - (pcre_uint8 *)dbuffer);
4787        }
4788    #endif
4789    #ifdef SUPPORT_PCRE16
4790        if (pcre_mode == PCRE16_MODE)
4791        {
4792          *q16 = 0;
4793          len = (int)(q16 - (pcre_uint16 *)dbuffer);
4794        }
4795    #endif
4796    #ifdef SUPPORT_PCRE32
4797        if (pcre_mode == PCRE32_MODE)
4798        {
4799          *q32 = 0;
4800          len = (int)(q32 - (pcre_uint32 *)dbuffer);
4801        }
4802    #endif
4803    
4804    #if defined SUPPORT_UTF && defined SUPPORT_PCRE32
4805        /* If we're requsted to test UTF-32 masking of high bits, change the data
4806        string to have high bits set, unless the string is invalid UTF-32.
4807        Since the JIT doesn't support this yet, only do it when not JITing. */
4808        if (use_utf && mask_utf32 && (study_options & PCRE_STUDY_ALLJIT) == 0 &&
4809            valid_utf32((pcre_uint32 *)dbuffer, len))
4810          {
4811          for (q32 = (pcre_uint32 *)dbuffer; *q32; q32++)
4812            *q32 |= ~(pcre_uint32)UTF32_MASK;
4813    
4814          /* Need to pass NO_UTF32_CHECK so the high bits are allowed */
4815          options |= PCRE_NO_UTF32_CHECK;
4816          }
4817    #endif
4818    
4819      /* Move the data to the end of the buffer so that a read over the end of      /* Move the data to the end of the buffer so that a read over the end of
4820      the buffer will be seen by valgrind, even if it doesn't cause a crash. If      the buffer will be seen by valgrind, even if it doesn't cause a crash. If
4821      we are using the POSIX interface, we must include the terminating zero. */      we are using the POSIX interface, we must include the terminating zero. */
4822    
4823        bptr = dbuffer;
4824    
4825  #if !defined NOPOSIX  #if !defined NOPOSIX
4826      if (posix || do_posix)      if (posix || do_posix)
4827        {        {
4828        memmove(bptr + buffer_size - len - 1, bptr, len + 1);        memmove(bptr + dbuffer_size - len - 1, bptr, len + 1);
4829        bptr += buffer_size - len - 1;        bptr += dbuffer_size - len - 1;
4830        }        }
4831      else      else
4832  #endif  #endif
4833        {        {
4834        memmove(bptr + buffer_size - len, bptr, len);        bptr = memmove(bptr + (dbuffer_size - len) * CHAR_SIZE, bptr, len * CHAR_SIZE);
       bptr += buffer_size - len;  
4835        }        }
4836    
4837      if ((all_use_dfa || use_dfa) && find_match_limit)      if ((all_use_dfa || use_dfa) && find_match_limit)
# Line 4532  while (!done) Line 4895  while (!done)
4895    
4896      /* Handle matching via the native interface - repeats for /g and /G */      /* Handle matching via the native interface - repeats for /g and /G */
4897    
 #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  
   
4898      /* 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
4899      actually used. If jit_stack == NULL, no stack has yet been assigned. */      actually used. If jit_stack == NULL, no stack has yet been assigned. */
4900    
# Line 4808  while (!done) Line 5116  while (!done)
5116            int rc;            int rc;
5117            char copybuffer[256];            char copybuffer[256];
5118    
5119    #ifdef SUPPORT_PCRE32
5120              if (pcre_mode == PCRE32_MODE)
5121                {
5122                if (*(pcre_uint32 *)cnptr == 0) break;
5123                }
5124    #endif
5125    #ifdef SUPPORT_PCRE16
5126            if (pcre_mode == PCRE16_MODE)            if (pcre_mode == PCRE16_MODE)
5127              {              {
5128              if (*(pcre_uint16 *)cnptr == 0) break;              if (*(pcre_uint16 *)cnptr == 0) break;
5129              }              }
5130            else  #endif
5131    #ifdef SUPPORT_PCRE8
5132              if (pcre_mode == PCRE8_MODE)
5133              {              {
5134              if (*(pcre_uint8 *)cnptr == 0) break;              if (*(pcre_uint8 *)cnptr == 0) break;
5135              }              }
5136    #endif
5137    
5138            PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,            PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,
5139              cnptr, copybuffer, sizeof(copybuffer));              cnptr, copybuffer, sizeof(copybuffer));
# Line 4863  while (!done) Line 5181  while (!done)
5181            int rc;            int rc;
5182            const char *substring;            const char *substring;
5183    
5184    #ifdef SUPPORT_PCRE32
5185              if (pcre_mode == PCRE32_MODE)
5186                {
5187                if (*(pcre_uint32 *)gnptr == 0) break;
5188                }
5189    #endif
5190    #ifdef SUPPORT_PCRE16
5191            if (pcre_mode == PCRE16_MODE)            if (pcre_mode == PCRE16_MODE)
5192              {              {
5193              if (*(pcre_uint16 *)gnptr == 0) break;              if (*(pcre_uint16 *)gnptr == 0) break;
5194              }              }
5195            else  #endif
5196    #ifdef SUPPORT_PCRE8
5197              if (pcre_mode == PCRE8_MODE)
5198              {              {
5199              if (*(pcre_uint8 *)gnptr == 0) break;              if (*(pcre_uint8 *)gnptr == 0) break;
5200              }              }
5201    #endif
5202    
5203            PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,            PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,
5204              gnptr, &substring);              gnptr, &substring);

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

  ViewVC Help
Powered by ViewVC 1.1.5