/[pcre]/code/branches/pcre16/pcretest.c
ViewVC logotype

Diff of /code/branches/pcre16/pcretest.c

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

revision 807 by ph10, Wed Dec 14 16:49:20 2011 UTC revision 808 by ph10, Sun Dec 18 11:11:48 2011 UTC
# Line 4  Line 4 
4    
5  /* This program was hacked up as a tester for PCRE. I really should have  /* This program was hacked up as a tester for PCRE. I really should have
6  written it more tidily in the first place. Will I ever learn? It has grown and  written it more tidily in the first place. Will I ever learn? It has grown and
7  been extended and consequently is now rather, er, *very* untidy in places.  been extended and consequently is now rather, er, *very* untidy in places. The
8    addition of 16-bit support has made it even worse. :-(
9    
10  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
11  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 107  appropriately for an application, not fo Line 108  appropriately for an application, not fo
108  #include "pcre.h"  #include "pcre.h"
109  #include "pcre_internal.h"  #include "pcre_internal.h"
110    
111  /* The pcre_printint() function, which prints the internal form of a compiled  /* The pcre_printint() function, which prints the internal form of a compiled
112  regex, is held in a separate file so that (a) it can be compiled in either  regex, is held in a separate file so that (a) it can be compiled in either
113  8-bit or 16-bit mode, and (b) it can be #included directly in pcre_compile.c  8-bit or 16-bit mode, and (b) it can be #included directly in pcre_compile.c
114  when that is compiled in debug mode. */  when that is compiled in debug mode. */
115    
116  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
# Line 149  that differ in their output from isprint Line 150  that differ in their output from isprint
150  #define PRINTABLE(c) ((c) >= 32 && (c) < 127)  #define PRINTABLE(c) ((c) >= 32 && (c) < 127)
151  #endif  #endif
152    
153  #define PRINTHEX(c) (locale_set? isprint(c) : PRINTABLE(c))  #define PRINTOK(c) (locale_set? isprint(c) : PRINTABLE(c))
154    
155  /* It is possible to compile this test program without including support for  /* It is possible to compile this test program without including support for
156  testing the POSIX interface, though this is not available via the standard  testing the POSIX interface, though this is not available via the standard
# Line 159  Makefile. */ Line 160  Makefile. */
160  #include "pcreposix.h"  #include "pcreposix.h"
161  #endif  #endif
162    
163  /* It is also possible, for the benefit of the version currently imported into  /* It is also possible, originally for the benefit of a version that was
164  Exim, to build pcretest without support for UTF8 (define NOUTF8), without the  imported into Exim, to build pcretest without support for UTF8 (define NOUTF8),
165  interface to the DFA matcher (NODFA), and without the doublecheck of the old  without the interface to the DFA matcher (NODFA), and without the doublecheck
166  "info" function (define NOINFOCHECK). In fact, we automatically cut out the  of the old "info" function (define NOINFOCHECK). In fact, we automatically cut
167  UTF8 support if PCRE is built without it. */  out the UTF8 support if PCRE is built without it. */
168    
169  #ifndef SUPPORT_UTF8  #ifndef SUPPORT_UTF8
170  #ifndef NOUTF8  #ifndef NOUTF8
# Line 171  UTF8 support if PCRE is built without it Line 172  UTF8 support if PCRE is built without it
172  #endif  #endif
173  #endif  #endif
174    
175    /* To make the code a bit tidier for 8-bit and 16-bit support, we define macros
176    for all the pcre[16]_xxx functions (except pcre16_fullinfo, which is called
177    only from one place and is handled differently). I couldn't dream up any way of
178    using a single macro to do this in a generic way, because of the many different
179    argument requirements. We know that at least one of SUPPORT_PCRE8 and
180    SUPPORT_PCRE16 must be set. First define macros for each individual mode; then
181    use these in the definitions of generic macros. */
182    
183    #ifdef SUPPORT_PCRE8
184    #define PCHARS8(lv, p, len, f) \
185      lv = pchars((pcre_uint8 *)p, len, f)
186    
187    #define PCHARSV8(p, len, f) \
188      (void)pchars((pcre_uint8 *)p, len, f)
189    
190    #define PCRE_COMPILE8(re, pat, options, error, erroffset, tables) \
191      re = pcre_compile((char *)pat, options, error, erroffset, tables)
192    
193    #define PCRE_EXEC8(count, re, extra, bptr, len, start_offset, options, \
194        offsets, size_offsets) \
195      count = pcre_exec(re, extra, (char *)bptr, len, start_offset, options, \
196        offsets, size_offsets)
197    
198    #define PCRE_STUDY8(extra, re, options, error) \
199      extra = pcre_study(re, options, error)
200    #endif
201    
202    
203    #ifdef SUPPORT_PCRE16
204    #define PCHARS16(lv, p, len, f) \
205      lv = pchars16((PCRE_SPTR16)p, len, f)
206    
207    #define PCHARSV16(p, len, f) \
208      (void)pchars16((PCRE_SPTR16)p, len, f)
209    
210    #define PCRE_COMPILE16(re, pat, options, error, erroffset, tables) \
211      re = pcre16_compile((PCRE_SPTR16)pat, options, error, erroffset, tables)
212    
213    #define PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \
214        offsets, size_offsets) \
215      count = pcre16_exec(re, extra, (PCRE_SPTR16)bptr, len, start_offset, \
216        options, offsets, size_offsets)
217    
218    #define PCRE_STUDY16(extra, re, options, error) \
219      extra = pcre16_study(re, options, error)
220    #endif
221    
222    
223    /* ----- Both modes are supported; a runtime test is needed ----- */
224    
225    #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16
226    
227    #define PCHARS(lv, p, len, f) \
228      if (use_pcre16) \
229        PCHARS16(lv, p, len, f); \
230      else \
231        PCHARS8(lv, p, len, f)
232    
233    #define PCHARSV(p, len, f) \
234      if (use_pcre16) \
235        PCHARSV16(p, len, f); \
236      else \
237        PCHARSV8(p, len, f)
238    
239    #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
240      if (use_pcre16) \
241        PCRE_COMPILE16(re, pat, options, error, erroffset, tables); \
242      else \
243        PCRE_COMPILE8(re, pat, options, error, erroffset, tables)
244    
245    #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
246        offsets, size_offsets) \
247      if (use_pcre16) \
248        PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \
249          offsets, size_offsets); \
250      else \
251        PCRE_EXEC8(count, re, extra, bptr, len, start_offset, options, \
252          offsets, size_offsets)
253    
254    #define PCRE_STUDY(extra, re, options, error) \
255      if (use_pcre16) \
256        PCRE_STUDY16(extra, re, options, error); \
257      else \
258        PCRE_STUDY8(extra, re, options, error)
259    
260    /* ----- Only 8-bit mode is supported ----- */
261    
262    #elif defined SUPPORT_PCRE8
263    #define PCHARS       PCHARS8
264    #define PCHARSV      PCHARSV8
265    #define PCRE_COMPILE PCRE_COMPILE8
266    #define PCRE_EXEC    PCRE_EXEC8
267    #define PCRE_STUDY   PCRE_STUDY8
268    
269    /* ----- Only 16-bit mode is supported ----- */
270    
271    #else
272    #define PCHARS       PCHARS16
273    #define PCHARSV      PCHARSV16
274    #define PCRE_COMPILE PCRE_COMPILE16
275    #define PCRE_EXEC    PCRE_EXEC16
276    #define PCRE_STUDY   PCRE_STUDY16
277    #endif
278    
279    /* ----- End of mode-specific function call macros ----- */
280    
281    
282  /* Other parameters */  /* Other parameters */
283    
# Line 203  static size_t gotten_store; Line 310  static size_t gotten_store;
310  static size_t first_gotten_store = 0;  static size_t first_gotten_store = 0;
311  static const unsigned char *last_callout_mark = NULL;  static const unsigned char *last_callout_mark = NULL;
312    
 static int (*fullinfo)(const pcre *, const pcre_extra *, int, void *);  
   
313  /* The buffers grow automatically if very long input lines are encountered. */  /* The buffers grow automatically if very long input lines are encountered. */
314    
315  static int buffer_size = 50000;  static int buffer_size = 50000;
# Line 217  static int buffer16_size = 0; Line 322  static int buffer16_size = 0;
322  static pcre_uint16 *buffer16 = NULL;  static pcre_uint16 *buffer16 = NULL;
323  #endif  #endif
324    
325    /* If we have 8-bit support, default use_pcre16 to false; if there is also
326    16-bit support, it can be changed by an option. If there is no 8-bit support,
327    there must be 16-bit support, so default it to 1. */
328    
329    #ifdef SUPPORT_PCRE8
330    static int use_pcre16 = 0;
331    #else
332    static int use_pcre16 = 1;
333    #endif
334    
335  /* Textual explanations for runtime error codes */  /* Textual explanations for runtime error codes */
336    
337  static const char *errtexts[] = {  static const char *errtexts[] = {
# Line 248  static const char *errtexts[] = { Line 363  static const char *errtexts[] = {
363    NULL,  /* SHORTUTF8 is handled specially */    NULL,  /* SHORTUTF8 is handled specially */
364    "nested recursion at the same subject position",    "nested recursion at the same subject position",
365    "JIT stack limit reached",    "JIT stack limit reached",
366    "pattern compiled in wrong mode (8-bit/16-bit error)"    "pattern compiled in wrong mode (8-bit/16-bit error)"
367  };  };
368    
369    
# Line 264  the L (locale) option also adjusts the t Line 379  the L (locale) option also adjusts the t
379  /* This is the set of tables distributed as default with PCRE. It recognizes  /* This is the set of tables distributed as default with PCRE. It recognizes
380  only ASCII characters. */  only ASCII characters. */
381    
382  static const unsigned char tables0[] = {  static const pcre_uint8 tables0[] = {
383    
384  /* This table is a lower casing table. */  /* This table is a lower casing table. */
385    
# Line 437  graph, print, punct, and cntrl. Other cl Line 552  graph, print, punct, and cntrl. Other cl
552  be at least an approximation of ISO 8859. In particular, there are characters  be at least an approximation of ISO 8859. In particular, there are characters
553  greater than 128 that are marked as spaces, letters, etc. */  greater than 128 that are marked as spaces, letters, etc. */
554    
555  static const unsigned char tables1[] = {  static const pcre_uint8 tables1[] = {
556  0,1,2,3,4,5,6,7,  0,1,2,3,4,5,6,7,
557  8,9,10,11,12,13,14,15,  8,9,10,11,12,13,14,15,
558  16,17,18,19,20,21,22,23,  16,17,18,19,20,21,22,23,
# Line 610  return (pcre_jit_stack *)arg; Line 725  return (pcre_jit_stack *)arg;
725  }  }
726    
727    
728    /*************************************************
729    *            Convert UTF-8 string to value       *
730    *************************************************/
731    
732    /* This function takes one or more bytes that represents a UTF-8 character,
733    and returns the value of the character.
734    
735    Argument:
736      utf8bytes   a pointer to the byte vector
737      vptr        a pointer to an int to receive the value
738    
739    Returns:      >  0 => the number of bytes consumed
740                  -6 to 0 => malformed UTF-8 character at offset = (-return)
741    */
742    
743    #if !defined NOUTF8
744    
745    static int
746    utf82ord(pcre_uint8 *utf8bytes, int *vptr)
747    {
748    int c = *utf8bytes++;
749    int d = c;
750    int i, j, s;
751    
752    for (i = -1; i < 6; i++)               /* i is number of additional bytes */
753      {
754      if ((d & 0x80) == 0) break;
755      d <<= 1;
756      }
757    
758    if (i == -1) { *vptr = c; return 1; }  /* ascii character */
759    if (i == 0 || i == 6) return 0;        /* invalid UTF-8 */
760    
761    /* i now has a value in the range 1-5 */
762    
763    s = 6*i;
764    d = (c & utf8_table3[i]) << s;
765    
766    for (j = 0; j < i; j++)
767      {
768      c = *utf8bytes++;
769      if ((c & 0xc0) != 0x80) return -(j+1);
770      s -= 6;
771      d |= (c & 0x3f) << s;
772      }
773    
774    /* Check that encoding was the correct unique one */
775    
776    for (j = 0; j < utf8_table1_size; j++)
777      if (d <= utf8_table1[j]) break;
778    if (j != i) return -(i+1);
779    
780    /* Valid value */
781    
782    *vptr = d;
783    return i+1;
784    }
785    
786    #endif
787    
788    
789    
790    /*************************************************
791    *       Convert character value to UTF-8         *
792    *************************************************/
793    
794    /* This function takes an integer value in the range 0 - 0x7fffffff
795    and encodes it as a UTF-8 character in 0 to 6 bytes.
796    
797    Arguments:
798      cvalue     the character value
799      utf8bytes  pointer to buffer for result - at least 6 bytes long
800    
801    Returns:     number of characters placed in the buffer
802    */
803    
804    #if !defined NOUTF8
805    
806    static int
807    ord2utf8(int cvalue, pcre_uint8 *utf8bytes)
808    {
809    register int i, j;
810    for (i = 0; i < utf8_table1_size; i++)
811      if (cvalue <= utf8_table1[i]) break;
812    utf8bytes += i;
813    for (j = i; j > 0; j--)
814     {
815     *utf8bytes-- = 0x80 | (cvalue & 0x3f);
816     cvalue >>= 6;
817     }
818    *utf8bytes = utf8_table2[i] | cvalue;
819    return i + 1;
820    }
821    
822    #endif
823    
824    
825    
826  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
827  /*************************************************  /*************************************************
828  *         Convert a string to 16-bit             *  *         Convert a string to 16-bit             *
829  *************************************************/  *************************************************/
830    
831  /* The result is always left in buffer16. */  /* In non-UTF mode, the space needed for a 16-bit string is exactly double the
832    8-bit size. For a UTF-8 string, the size needed for UTF-16 is no more than
833    double, because up to 0xffff uses no more than 3 bytes in UTF-8 but possibly 4
834    in UTF-16. Higher values use 4 bytes in UTF-8 and up to 4 bytes in UTF-16. The
835    result is always left in buffer16. */
836    
837  static int  static int
838  to16(unsigned char *p, int utf)  to16(pcre_uint8 *p, int utf, int len)
839  {  {
840  pcre_uint16 *pp;  pcre_uint16 *pp;
 int len = (int)strlen((char *)p) + 1;  
841    
842  if (buffer16_size < 2*len)  if (buffer16_size < 2*len + 2)
843    {    {
844    if (buffer16 != NULL) free(buffer16);    if (buffer16 != NULL) free(buffer16);
845    buffer16_size = 2*len;    buffer16_size = 2*len + 2;
846    buffer16 = (pcre_uint16 *)malloc(buffer16_size);    buffer16 = (pcre_uint16 *)malloc(buffer16_size);
847    if (buffer16 == NULL)    if (buffer16 == NULL)
848      {      {
849      fprintf(stderr, "pcretest: malloc(%d) failed for buffer16\n", buffer16_size);      fprintf(stderr, "pcretest: malloc(%d) failed for buffer16\n", buffer16_size);
850      exit(1);      exit(1);
851      }      }
852    }    }
853    
854  pp = buffer16;  pp = buffer16;
855    
856  if (!utf)  if (!utf)
857    {    {
858    while (*p != 0) *pp++ = *p++;    while (len-- > 0) *pp++ = *p++;
   *pp++ = 0;  
859    }    }
860    
861  else  else
862    {    {
863  fprintf(stderr, "pcretest: no support yet for UTF-16\n");    int c;
864  exit(1);    while (len > 0)
865    }      {
866        int chlen = utf82ord(p, &c);
867        p += chlen;
868        len -= chlen;
869        if (c < 0x10000) *pp++ = c; else
870          {
871          c -= 0x10000;
872          *pp++ = 0xD800 | (c >> 10);
873          *pp++ = 0xDC00 | (c & 0x3ff);
874          }
875        }
876      }
877    
878    *pp = 0;
879  return pp - buffer16;  return pp - buffer16;
880  }  }
881  #endif  #endif
882    
883    
# Line 727  for (;;) Line 954  for (;;)
954    else    else
955      {      {
956      int new_buffer_size = 2*buffer_size;      int new_buffer_size = 2*buffer_size;
957      pcre_uint8 *new_buffer = (unsigned char *)malloc(new_buffer_size);      pcre_uint8 *new_buffer = (pcre_uint8 *)malloc(new_buffer_size);
958      pcre_uint8 *new_dbuffer = (unsigned char *)malloc(new_buffer_size);      pcre_uint8 *new_dbuffer = (pcre_uint8 *)malloc(new_buffer_size);
959      pcre_uint8 *new_pbuffer = (unsigned char *)malloc(new_buffer_size);      pcre_uint8 *new_pbuffer = (pcre_uint8 *)malloc(new_buffer_size);
960    
961      if (new_buffer == NULL || new_dbuffer == NULL || new_pbuffer == NULL)      if (new_buffer == NULL || new_dbuffer == NULL || new_pbuffer == NULL)
962        {        {
# Line 760  return NULL;  /* Control never gets here Line 987  return NULL;  /* Control never gets here
987    
988    
989    
   
   
   
   
990  /*************************************************  /*************************************************
991  *          Read number from string               *  *          Read number from string               *
992  *************************************************/  *************************************************/
# Line 780  Returns:        the unsigned long Line 1003  Returns:        the unsigned long
1003  */  */
1004    
1005  static int  static int
1006  get_value(unsigned char *str, unsigned char **endptr)  get_value(pcre_uint8 *str, pcre_uint8 **endptr)
1007  {  {
1008  int result = 0;  int result = 0;
1009  while(*str != 0 && isspace(*str)) str++;  while(*str != 0 && isspace(*str)) str++;
# Line 791  return(result); Line 1014  return(result);
1014    
1015    
1016    
1017    #ifdef SUPPORT_PCRE8
 /*************************************************  
 *            Convert UTF-8 string to value       *  
 *************************************************/  
   
 /* This function takes one or more bytes that represents a UTF-8 character,  
 and returns the value of the character.  
   
 Argument:  
   utf8bytes   a pointer to the byte vector  
   vptr        a pointer to an int to receive the value  
   
 Returns:      >  0 => the number of bytes consumed  
               -6 to 0 => malformed UTF-8 character at offset = (-return)  
 */  
   
 #if !defined NOUTF8  
   
 static int  
 utf82ord(unsigned char *utf8bytes, int *vptr)  
 {  
 int c = *utf8bytes++;  
 int d = c;  
 int i, j, s;  
   
 for (i = -1; i < 6; i++)               /* i is number of additional bytes */  
   {  
   if ((d & 0x80) == 0) break;  
   d <<= 1;  
   }  
   
 if (i == -1) { *vptr = c; return 1; }  /* ascii character */  
 if (i == 0 || i == 6) return 0;        /* invalid UTF-8 */  
   
 /* i now has a value in the range 1-5 */  
   
 s = 6*i;  
 d = (c & utf8_table3[i]) << s;  
   
 for (j = 0; j < i; j++)  
   {  
   c = *utf8bytes++;  
   if ((c & 0xc0) != 0x80) return -(j+1);  
   s -= 6;  
   d |= (c & 0x3f) << s;  
   }  
   
 /* Check that encoding was the correct unique one */  
   
 for (j = 0; j < utf8_table1_size; j++)  
   if (d <= utf8_table1[j]) break;  
 if (j != i) return -(i+1);  
   
 /* Valid value */  
   
 *vptr = d;  
 return i+1;  
 }  
   
 #endif  
   
   
   
 /*************************************************  
 *       Convert character value to UTF-8         *  
 *************************************************/  
   
 /* This function takes an integer value in the range 0 - 0x7fffffff  
 and encodes it as a UTF-8 character in 0 to 6 bytes.  
   
 Arguments:  
   cvalue     the character value  
   utf8bytes  pointer to buffer for result - at least 6 bytes long  
   
 Returns:     number of characters placed in the buffer  
 */  
   
 #if !defined NOUTF8  
   
 static int  
 ord2utf8(int cvalue, pcre_uint8 *utf8bytes)  
 {  
 register int i, j;  
 for (i = 0; i < utf8_table1_size; i++)  
   if (cvalue <= utf8_table1[i]) break;  
 utf8bytes += i;  
 for (j = i; j > 0; j--)  
  {  
  *utf8bytes-- = 0x80 | (cvalue & 0x3f);  
  cvalue >>= 6;  
  }  
 *utf8bytes = utf8_table2[i] | cvalue;  
 return i + 1;  
 }  
   
 #endif  
   
   
   
1018  /*************************************************  /*************************************************
1019  *             Print character string             *  *         Print 8-bit character string           *
1020  *************************************************/  *************************************************/
1021    
1022  /* Character string printing function. Must handle UTF-8 strings in utf8  /* Must handle UTF-8 strings in utf8 mode. Yields number of characters printed.
1023  mode. Yields number of characters printed. If handed a NULL file, just counts  If handed a NULL file, just counts chars without printing. */
 chars without printing. */  
1024    
1025  static int pchars(unsigned char *p, int length, FILE *f)  static int pchars(pcre_uint8 *p, int length, FILE *f)
1026  {  {
1027  int c = 0;  int c = 0;
1028  int yield = 0;  int yield = 0;
# Line 914  while (length-- > 0) Line 1038  while (length-- > 0)
1038        {        {
1039        length -= rc - 1;        length -= rc - 1;
1040        p += rc;        p += rc;
1041        if (PRINTHEX(c))        if (PRINTOK(c))
1042          {          {
1043          if (f != NULL) fprintf(f, "%c", c);          if (f != NULL) fprintf(f, "%c", c);
1044          yield++;          yield++;
# Line 936  while (length-- > 0) Line 1060  while (length-- > 0)
1060     /* Not UTF-8, or malformed UTF-8  */     /* Not UTF-8, or malformed UTF-8  */
1061    
1062    c = *p++;    c = *p++;
1063    if (PRINTHEX(c))    if (PRINTOK(c))
1064      {      {
1065      if (f != NULL) fprintf(f, "%c", c);      if (f != NULL) fprintf(f, "%c", c);
1066      yield++;      yield++;
# Line 950  while (length-- > 0) Line 1074  while (length-- > 0)
1074    
1075  return yield;  return yield;
1076  }  }
1077    #endif
1078    
1079    
1080    
1081    #ifdef SUPPORT_PCRE16
1082    /*************************************************
1083    *           Print 16-bit character string        *
1084    *************************************************/
1085    
1086    /* Must handle UTF-16 strings in utf mode. Yields number of characters printed.
1087    If handed a NULL file, just counts chars without printing. */
1088    
1089    static int pchars16(PCRE_SPTR16 p, int length, FILE *f)
1090    {
1091    int yield = 0;
1092    
1093    while (length-- > 0)
1094      {
1095      int c = *p++ & 0xffff;
1096    
1097    #if !defined NOUTF8
1098      if (use_utf8 && c >= 0xD800 && c < 0xDC00 && length > 0)
1099        {
1100        int d = *p & 0xffff;
1101        if (d >= 0xDC00 && d < 0xDFFF)
1102          {
1103          c = ((c & 0x3ff) << 10) + (d & 0x3ff) + 0x10000;
1104          length--;
1105          p++;
1106          }
1107        }
1108    #endif
1109    
1110      if (PRINTOK(c))
1111        {
1112        if (f != NULL) fprintf(f, "%c", c);
1113        yield++;
1114        }
1115      else
1116        {
1117        yield += 4;
1118        if (c < 0x100)
1119          {
1120          if (f != NULL) fprintf(f, "\\x%02x", c);
1121          }
1122        else
1123          {
1124          if (f != NULL) fprintf(f, "\\x{%02x}", c);
1125          yield += (c <= 0x000000ff)? 2 :
1126                   (c <= 0x00000fff)? 3 :
1127                   (c <= 0x0000ffff)? 4 :
1128                   (c <= 0x000fffff)? 5 : 6;
1129          }
1130        }
1131      }
1132    
1133    return yield;
1134    }
1135    #endif
1136    
1137    
1138    
# Line 978  if (callout_extra) Line 1161  if (callout_extra)
1161      else      else
1162        {        {
1163        fprintf(f, "%2d: ", i/2);        fprintf(f, "%2d: ", i/2);
1164        (void)pchars((unsigned char *)cb->subject + cb->offset_vector[i],        PCHARSV(cb->subject + cb->offset_vector[i],
1165          cb->offset_vector[i+1] - cb->offset_vector[i], f);          cb->offset_vector[i+1] - cb->offset_vector[i], f);
1166        fprintf(f, "\n");        fprintf(f, "\n");
1167        }        }
# Line 991  printed lengths of the substrings. */ Line 1174  printed lengths of the substrings. */
1174    
1175  if (f != NULL) fprintf(f, "--->");  if (f != NULL) fprintf(f, "--->");
1176    
1177  pre_start = pchars((unsigned char *)cb->subject, cb->start_match, f);  PCHARS(pre_start, cb->subject, cb->start_match, f);
1178  post_start = pchars((unsigned char *)(cb->subject + cb->start_match),  PCHARS(post_start, cb->subject + cb->start_match,
1179    cb->current_position - cb->start_match, f);    cb->current_position - cb->start_match, f);
1180    
1181  subject_length = pchars((unsigned char *)cb->subject, cb->subject_length, NULL);  PCHARS(subject_length, cb->subject, cb->subject_length, NULL);
1182    
1183  (void)pchars((unsigned char *)(cb->subject + cb->current_position),  PCHARSV(cb->subject + cb->current_position,
1184    cb->subject_length - cb->current_position, f);    cb->subject_length - cb->current_position, f);
1185    
1186  if (f != NULL) fprintf(f, "\n");  if (f != NULL) fprintf(f, "\n");
# Line 1103  free(block); Line 1286  free(block);
1286  *          Call pcre_fullinfo()                  *  *          Call pcre_fullinfo()                  *
1287  *************************************************/  *************************************************/
1288    
1289  /* Get one piece of information from the pcre_fullinfo() function */  /* Get one piece of information from the pcre_fullinfo() function. When only
1290    one of 8-bit or 16-bit is supported, use_pcre16 should always have the correct
1291    value, but the code is defensive. */
1292    
1293  static void new_info(pcre *re, pcre_extra *study, int option, void *ptr)  static void new_info(pcre *re, pcre_extra *study, int option, void *ptr)
1294  {  {
1295  int rc;  int rc;
1296  if ((rc = (fullinfo)(re, study, option, ptr)) < 0)  
1297    fprintf(outfile, "Error %d from pcre_fullinfo(%d)\n", rc, option);  if (use_pcre16)
1298    #ifdef SUPPORT_PCRE16
1299      rc = pcre16_fullinfo(re, study, option, ptr);
1300    #else
1301      rc = PCRE_ERROR_BADMODE;
1302    #endif
1303    else
1304    #ifdef SUPPORT_PCRE8
1305      rc = pcre_fullinfo(re, study, option, ptr);
1306    #else
1307      rc = PCRE_ERROR_BADMODE;
1308    #endif
1309    
1310    if (rc < 0) fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
1311      use_pcre16? "16" : "", option);
1312  }  }
1313    
1314    
# Line 1151  for (;;) Line 1350  for (;;)
1350    {    {
1351    *limit = mid;    *limit = mid;
1352    
1353    count = pcre_exec(re, extra, (char *)bptr, len, start_offset, options,    PCRE_EXEC(count, re, extra, bptr, len, start_offset, options,
1354      use_offsets, use_size_offsets);      use_offsets, use_size_offsets);
1355    
1356    if (count == errnumber)    if (count == errnumber)
# Line 1313  int posix = 0; Line 1512  int posix = 0;
1512  int debug = 0;  int debug = 0;
1513  int done = 0;  int done = 0;
1514  int all_use_dfa = 0;  int all_use_dfa = 0;
 int use_pcre16 = 0;  
1515  int yield = 0;  int yield = 0;
1516  int stack_size;  int stack_size;
1517    
# Line 1329  pcre_uchar *copynamesptr; Line 1527  pcre_uchar *copynamesptr;
1527  pcre_uchar *getnamesptr;  pcre_uchar *getnamesptr;
1528    
1529  /* Get buffers from malloc() so that valgrind will check their misuse when  /* Get buffers from malloc() so that valgrind will check their misuse when
1530  debugging. They grow automatically when very long lines are read. The 16-bit  debugging. They grow automatically when very long lines are read. The 16-bit
1531  buffer (buffer16) is obtained only if needed. */  buffer (buffer16) is obtained only if needed. */
1532    
1533  buffer = (pcre_uint8 *)malloc(buffer_size);  buffer = (pcre_uint8 *)malloc(buffer_size);
# Line 1353  _setmode( _fileno( stdout ), _O_BINARY ) Line 1551  _setmode( _fileno( stdout ), _O_BINARY )
1551    
1552  while (argc > 1 && argv[op][0] == '-')  while (argc > 1 && argv[op][0] == '-')
1553    {    {
1554    unsigned char *endptr;    pcre_uint8 *endptr;
1555    
1556    if (strcmp(argv[op], "-16") == 0) use_pcre16 = 1;    if (strcmp(argv[op], "-m") == 0) showstore = 1;
   else if (strcmp(argv[op], "-m") == 0) showstore = 1;  
1557    else if (strcmp(argv[op], "-s") == 0) force_study = 0;    else if (strcmp(argv[op], "-s") == 0) force_study = 0;
1558    else if (strcmp(argv[op], "-s+") == 0)    else if (strcmp(argv[op], "-s+") == 0)
1559      {      {
1560      force_study = 1;      force_study = 1;
1561      force_study_options = PCRE_STUDY_JIT_COMPILE;      force_study_options = PCRE_STUDY_JIT_COMPILE;
1562      }      }
1563    #ifdef SUPPORT_PCRE16
1564      else if (strcmp(argv[op], "-16") == 0) use_pcre16 = 1;
1565    #endif
1566    
1567    else if (strcmp(argv[op], "-q") == 0) quiet = 1;    else if (strcmp(argv[op], "-q") == 0) quiet = 1;
1568    else if (strcmp(argv[op], "-b") == 0) debug = 1;    else if (strcmp(argv[op], "-b") == 0) debug = 1;
1569    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;
# Line 1372  while (argc > 1 && argv[op][0] == '-') Line 1573  while (argc > 1 && argv[op][0] == '-')
1573    else if (strcmp(argv[op], "-dfa") == 0) all_use_dfa = 1;    else if (strcmp(argv[op], "-dfa") == 0) all_use_dfa = 1;
1574  #endif  #endif
1575    else if (strcmp(argv[op], "-o") == 0 && argc > 2 &&    else if (strcmp(argv[op], "-o") == 0 && argc > 2 &&
1576        ((size_offsets = get_value((unsigned char *)argv[op+1], &endptr)),        ((size_offsets = get_value((pcre_uint8 *)argv[op+1], &endptr)),
1577          *endptr == 0))          *endptr == 0))
1578      {      {
1579      op++;      op++;
# Line 1382  while (argc > 1 && argv[op][0] == '-') Line 1583  while (argc > 1 && argv[op][0] == '-')
1583      {      {
1584      int both = argv[op][2] == 0;      int both = argv[op][2] == 0;
1585      int temp;      int temp;
1586      if (argc > 2 && (temp = get_value((unsigned char *)argv[op+1], &endptr),      if (argc > 2 && (temp = get_value((pcre_uint8 *)argv[op+1], &endptr),
1587                       *endptr == 0))                       *endptr == 0))
1588        {        {
1589        timeitm = temp;        timeitm = temp;
# Line 1393  while (argc > 1 && argv[op][0] == '-') Line 1594  while (argc > 1 && argv[op][0] == '-')
1594      if (both) timeit = timeitm;      if (both) timeit = timeitm;
1595      }      }
1596    else if (strcmp(argv[op], "-S") == 0 && argc > 2 &&    else if (strcmp(argv[op], "-S") == 0 && argc > 2 &&
1597        ((stack_size = get_value((unsigned char *)argv[op+1], &endptr)),        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),
1598          *endptr == 0))          *endptr == 0))
1599      {      {
1600  #if defined(_WIN32) || defined(WIN32) || defined(__minix)  #if defined(_WIN32) || defined(WIN32) || defined(__minix)
# Line 1423  while (argc > 1 && argv[op][0] == '-') Line 1624  while (argc > 1 && argv[op][0] == '-')
1624      unsigned long int lrc;      unsigned long int lrc;
1625      printf("PCRE version %s\n", pcre_version());      printf("PCRE version %s\n", pcre_version());
1626      printf("Compiled with\n");      printf("Compiled with\n");
1627    
1628  /* At least one of SUPPORT_PCRE8 and SUPPORT_PCRE16 will be set. */  /* At least one of SUPPORT_PCRE8 and SUPPORT_PCRE16 will be set. If both
1629    are set, either both UTFs are supported or both are not supported. */
1630    
1631  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16
1632      printf("  8-bit and 16-bit support\n");      printf("  8-bit and 16-bit support\n");
1633      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
1634      printf("  %sUTF-8 support\n", rc? "" : "No ");      if (rc)
1635      (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);        printf("  UTF-8 and UTF-16 support\n");
1636      printf("  %sUTF-16 support\n", rc? "" : "No ");      else
1637          printf("  No UTF-8 or UTF-16 support\n");
1638  #elif defined SUPPORT_PCRE8  #elif defined SUPPORT_PCRE8
1639      printf("  8-bit support only\n");      printf("  8-bit support only\n");
1640      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
1641      printf("  %sUTF-8 support\n", rc? "" : "No ");      printf("  %sUTF-8 support\n", rc? "" : "No ");
1642  #else  #else
1643      printf("  16-bit support only\n");      printf("  16-bit support only\n");
1644      (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);      (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
1645      printf("  %sUTF-16 support\n", rc? "" : "No ");      printf("  %sUTF-16 support\n", rc? "" : "No ");
1646  #endif  #endif
1647    
1648      (void)pcre_config(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);      (void)pcre_config(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
1649      printf("  %sUnicode properties support\n", rc? "" : "No ");      printf("  %sUnicode properties support\n", rc? "" : "No ");
1650      (void)pcre_config(PCRE_CONFIG_JIT, &rc);      (void)pcre_config(PCRE_CONFIG_JIT, &rc);
# Line 1488  while (argc > 1 && argv[op][0] == '-') Line 1691  while (argc > 1 && argv[op][0] == '-')
1691    argc--;    argc--;
1692    }    }
1693    
 /* Select which fullinfo function to use. */  
   
 fullinfo = use_pcre16? pcre16_fullinfo : pcre_fullinfo;  
   
1694  /* Get the store for the offsets vector, and remember what it was */  /* Get the store for the offsets vector, and remember what it was */
1695    
1696  size_offsets_max = size_offsets;  size_offsets_max = size_offsets;
# Line 1561  while (!done) Line 1760  while (!done)
1760  #endif  #endif
1761    
1762    const char *error;    const char *error;
1763    unsigned char *markptr;    pcre_uint8 *markptr;
1764    unsigned char *p, *pp, *ppp;    pcre_uint8 *p, *pp, *ppp;
1765    unsigned char *to_file = NULL;    pcre_uint8 *to_file = NULL;
1766    const unsigned char *tables = NULL;    const pcre_uint8 *tables = NULL;
1767    unsigned long int true_size, true_study_size = 0;    unsigned long int true_size, true_study_size = 0;
1768    size_t size, regex_gotten_store;    size_t size, regex_gotten_store;
1769    int do_allcaps = 0;    int do_allcaps = 0;
# Line 1898  while (!done) Line 2097  while (!done)
2097    
2098      {      {
2099      unsigned long int get_options;      unsigned long int get_options;
2100    
2101      /* In 16-bit mode, convert the input. The space needed for a non-UTF string      /* In 16-bit mode, convert the input. */
2102      is exactly double the 8-bit size. For a UTF-8 string, the size needed for  
     UTF-16 is no more than double, because up to 0xffff uses no more than 3  
     bytes in UTF-8 but possibly 4 in UTF-16. Higher values use 4 bytes in UTF-8  
     and up to 4 bytes in UTF-16. */  
   
2103  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2104      if (use_pcre16) (void)to16(p, options & PCRE_UTF8);      if (use_pcre16)
2105          {
2106          (void)to16(p, options & PCRE_UTF8, (int)strlen((char *)p));
2107          p = (pcre_uint8 *)buffer16;
2108          }
2109  #endif  #endif
2110    
2111      /* Compile many times when timing */      /* Compile many times when timing */
# Line 1918  while (!done) Line 2117  while (!done)
2117        clock_t start_time = clock();        clock_t start_time = clock();
2118        for (i = 0; i < timeit; i++)        for (i = 0; i < timeit; i++)
2119          {          {
2120  #ifdef SUPPORT_PCRE16          PCRE_COMPILE(re, p, options, &error, &erroroffset, tables);
         if (use_pcre16)  
           re = pcre16_compile((PCRE_SPTR16)buffer16, options, &error, &erroroffset, tables);  
         else  
 #endif  
           re = pcre_compile((char *)p, options, &error, &erroroffset, tables);  
2121          if (re != NULL) free(re);          if (re != NULL) free(re);
2122          }          }
2123        time_taken = clock() - start_time;        time_taken = clock() - start_time;
# Line 1933  while (!done) Line 2127  while (!done)
2127        }        }
2128    
2129      first_gotten_store = 0;      first_gotten_store = 0;
2130        PCRE_COMPILE(re, p, options, &error, &erroroffset, tables);
 #ifdef SUPPORT_PCRE16  
     if (use_pcre16)  
       re = pcre16_compile((PCRE_SPTR16)buffer16, options, &error, &erroroffset, tables);  
     else  
 #endif  
       re = pcre_compile((char *)p, options, &error, &erroroffset, tables);  
2131    
2132      /* Compilation failed; go back for another re, skipping to blank line      /* Compilation failed; go back for another re, skipping to blank line
2133      if non-interactive. */      if non-interactive. */
# Line 2001  while (!done) Line 2189  while (!done)
2189          clock_t start_time = clock();          clock_t start_time = clock();
2190          for (i = 0; i < timeit; i++)          for (i = 0; i < timeit; i++)
2191            {            {
2192            if (use_pcre16)            PCRE_STUDY(extra, re, study_options | force_study_options, &error);
2193              extra = pcre16_study(re, study_options | force_study_options, &error);            }
           else  
             extra = pcre_study(re, study_options | force_study_options, &error);  
           }  
2194          time_taken = clock() - start_time;          time_taken = clock() - start_time;
2195          if (extra != NULL) pcre_free_study(extra);          if (extra != NULL) pcre_free_study(extra);
2196          fprintf(outfile, "  Study time %.4f milliseconds\n",          fprintf(outfile, "  Study time %.4f milliseconds\n",
2197            (((double)time_taken * 1000.0) / (double)timeit) /            (((double)time_taken * 1000.0) / (double)timeit) /
2198              (double)CLOCKS_PER_SEC);              (double)CLOCKS_PER_SEC);
2199          }          }
2200        if (use_pcre16)        PCRE_STUDY(extra, re, study_options | force_study_options, &error);
         extra = pcre16_study(re, study_options | force_study_options, &error);  
       else  
         extra = pcre_study(re, study_options | force_study_options, &error);  
2201        if (error != NULL)        if (error != NULL)
2202          fprintf(outfile, "Failed to study: %s\n", error);          fprintf(outfile, "Failed to study: %s\n", error);
2203        else if (extra != NULL)        else if (extra != NULL)
# Line 2090  while (!done) Line 2272  while (!done)
2272        fprintf(outfile, "------------------------------------------------------------------\n");        fprintf(outfile, "------------------------------------------------------------------\n");
2273        if (use_pcre16)        if (use_pcre16)
2274          pcre16_printint(re, outfile, debug_lengths);          pcre16_printint(re, outfile, debug_lengths);
2275        else        else
2276          pcre_printint(re, outfile, debug_lengths);          pcre_printint(re, outfile, debug_lengths);
2277        }        }
2278    
# Line 2121  while (!done) Line 2303  while (!done)
2303    
2304        /* The old, obsolete function pcre_info() works only in 8-bit mode. Check        /* The old, obsolete function pcre_info() works only in 8-bit mode. Check
2305        that it gives the same results as the new function. */        that it gives the same results as the new function. */
2306    
2307  #if !defined NOINFOCHECK  #if !defined NOINFOCHECK
2308        if (!use_pcre16)        if (!use_pcre16)
2309          {          {
2310          old_count = pcre_info(re, &old_options, &old_first_char);          old_count = pcre_info(re, &old_options, &old_first_char);
2311          if (count < 0) fprintf(outfile,          if (count < 0) fprintf(outfile,
2312            "Error %d from pcre_info()\n", count);            "Error %d from pcre_info()\n", count);
# Line 2133  while (!done) Line 2315  while (!done)
2315            if (old_count != count) fprintf(outfile,            if (old_count != count) fprintf(outfile,
2316              "Count disagreement: pcre_fullinfo=%d pcre_info=%d\n", count,              "Count disagreement: pcre_fullinfo=%d pcre_info=%d\n", count,
2317                old_count);                old_count);
2318    
2319            if (old_first_char != first_char) fprintf(outfile,            if (old_first_char != first_char) fprintf(outfile,
2320              "First char disagreement: pcre_fullinfo=%d pcre_info=%d\n",              "First char disagreement: pcre_fullinfo=%d pcre_info=%d\n",
2321                first_char, old_first_char);                first_char, old_first_char);
2322    
2323            if (old_options != (int)get_options) fprintf(outfile,            if (old_options != (int)get_options) fprintf(outfile,
2324              "Options disagreement: pcre_fullinfo=%ld pcre_info=%d\n",              "Options disagreement: pcre_fullinfo=%ld pcre_info=%d\n",
2325                get_options, old_options);                get_options, old_options);
2326            }            }
2327          }          }
2328  #endif  #endif
2329    
2330        if (size != regex_gotten_store) fprintf(outfile,        if (size != regex_gotten_store) fprintf(outfile,
# Line 2233  while (!done) Line 2415  while (!done)
2415            ((((real_pcre *)re)->flags & PCRE_FCH_CASELESS) == 0)?            ((((real_pcre *)re)->flags & PCRE_FCH_CASELESS) == 0)?
2416            "" : " (caseless)";            "" : " (caseless)";
2417    
2418          if (PRINTHEX(first_char))          if (PRINTOK(first_char))
2419            fprintf(outfile, "First char = \'%c\'%s\n", first_char, caseless);            fprintf(outfile, "First char = \'%c\'%s\n", first_char, caseless);
2420          else          else
2421            fprintf(outfile, "First char = %d%s\n", first_char, caseless);            fprintf(outfile, "First char = %d%s\n", first_char, caseless);
# Line 2249  while (!done) Line 2431  while (!done)
2431            ((((real_pcre *)re)->flags & PCRE_RCH_CASELESS) == 0)?            ((((real_pcre *)re)->flags & PCRE_RCH_CASELESS) == 0)?
2432            "" : " (caseless)";            "" : " (caseless)";
2433    
2434          if (PRINTHEX(need_char))          if (PRINTOK(need_char))
2435            fprintf(outfile, "Need char = \'%c\'%s\n", need_char, caseless);            fprintf(outfile, "Need char = \'%c\'%s\n", need_char, caseless);
2436          else          else
2437            fprintf(outfile, "Need char = %d%s\n", need_char, caseless);            fprintf(outfile, "Need char = %d%s\n", need_char, caseless);
# Line 2292  while (!done) Line 2474  while (!done)
2474                    fprintf(outfile, "\n  ");                    fprintf(outfile, "\n  ");
2475                    c = 2;                    c = 2;
2476                    }                    }
2477                  if (PRINTHEX(i) && i != ' ')                  if (PRINTOK(i) && i != ' ')
2478                    {                    {
2479                    fprintf(outfile, "%c ", i);                    fprintf(outfile, "%c ", i);
2480                    c += 2;                    c += 2;
# Line 2479  while (!done) Line 2661  while (!done)
2661  #if !defined NOUTF8  #if !defined NOUTF8
2662          if (use_utf8 && c > 255)          if (use_utf8 && c > 255)
2663            {            {
2664            unsigned char buff8[8];            pcre_uint8 buff8[8];
2665            int ii, utn;            int ii, utn;
2666            utn = ord2utf8(c, buff8);            utn = ord2utf8(c, buff8);
2667            for (ii = 0; ii < utn - 1; ii++) *q++ = buff8[ii];            for (ii = 0; ii < utn - 1; ii++) *q++ = buff8[ii];
# Line 2495  while (!done) Line 2677  while (!done)
2677  #if !defined NOUTF8  #if !defined NOUTF8
2678          if (*p == '{')          if (*p == '{')
2679            {            {
2680            unsigned char *pt = p;            pcre_uint8 *pt = p;
2681            c = 0;            c = 0;
2682    
2683            /* We used to have "while (isxdigit(*(++pt)))" here, but it fails            /* We used to have "while (isxdigit(*(++pt)))" here, but it fails
# Line 2507  while (!done) Line 2689  while (!done)
2689              c = c * 16 + tolower(*pt) - ((isdigit(*pt))? '0' : 'a' - 10);              c = c * 16 + tolower(*pt) - ((isdigit(*pt))? '0' : 'a' - 10);
2690            if (*pt == '}')            if (*pt == '}')
2691              {              {
2692              unsigned char buff8[8];              pcre_uint8 buff8[8];
2693              int ii, utn;              int ii, utn;
2694              if (use_utf8)              if (use_utf8)
2695                {                {
# Line 2817  while (!done) Line 2999  while (!done)
2999            if (pmatch[i].rm_so >= 0)            if (pmatch[i].rm_so >= 0)
3000              {              {
3001              fprintf(outfile, "%2d: ", (int)i);              fprintf(outfile, "%2d: ", (int)i);
3002              (void)pchars(dbuffer + pmatch[i].rm_so,              PCHARSV(dbuffer + pmatch[i].rm_so,
3003                pmatch[i].rm_eo - pmatch[i].rm_so, outfile);                pmatch[i].rm_eo - pmatch[i].rm_so, outfile);
3004              fprintf(outfile, "\n");              fprintf(outfile, "\n");
3005              if (do_showcaprest || (i == 0 && do_showrest))              if (do_showcaprest || (i == 0 && do_showrest))
3006                {                {
3007                fprintf(outfile, "%2d+ ", (int)i);                fprintf(outfile, "%2d+ ", (int)i);
3008                (void)pchars(dbuffer + pmatch[i].rm_eo, len - pmatch[i].rm_eo,                PCHARSV(dbuffer + pmatch[i].rm_eo, len - pmatch[i].rm_eo,
3009                  outfile);                  outfile);
3010                fprintf(outfile, "\n");                fprintf(outfile, "\n");
3011                }                }
# Line 2831  while (!done) Line 3013  while (!done)
3013            }            }
3014          }          }
3015        free(pmatch);        free(pmatch);
3016          goto NEXT_DATA;
3017        }        }
3018    
3019    #endif  /* !defined NOPOSIX */
3020    
3021      /* Handle matching via the native interface - repeats for /g and /G */      /* Handle matching via the native interface - repeats for /g and /G */
3022    
3023      else  #ifdef SUPPORT_PCRE16
3024  #endif  /* !defined NOPOSIX */      if (use_pcre16)
3025          {
3026          len = to16(bptr, (((real_pcre *)re)->options) & PCRE_UTF8, len);
3027          bptr = (pcre_uint8 *)buffer16;
3028          }
3029    #endif
3030    
3031      for (;; gmatched++)    /* Loop for /g or /G */      for (;; gmatched++)    /* Loop for /g or /G */
3032        {        {
# Line 2847  while (!done) Line 3037  while (!done)
3037          register int i;          register int i;
3038          clock_t time_taken;          clock_t time_taken;
3039          clock_t start_time = clock();          clock_t start_time = clock();
   
 #ifdef SUPPORT_PCRE16  
         if (use_pcre16) len = to16(bptr, options & PCRE_UTF8);  
 #endif  
   
3040    
3041  #if !defined NODFA  #if !defined NODFA
3042          if (all_use_dfa || use_dfa)          if (all_use_dfa || use_dfa)
# Line 2866  while (!done) Line 3051  while (!done)
3051  #endif  #endif
3052    
3053          for (i = 0; i < timeitm; i++)          for (i = 0; i < timeitm; i++)
3054            count = pcre_exec(re, extra, (char *)bptr, len,            {
3055              PCRE_EXEC(count, re, extra, bptr, len,
3056              start_offset, options | g_notempty, use_offsets, use_size_offsets);              start_offset, options | g_notempty, use_offsets, use_size_offsets);
3057              }
3058          time_taken = clock() - start_time;          time_taken = clock() - start_time;
3059          fprintf(outfile, "Execute time %.4f milliseconds\n",          fprintf(outfile, "Execute time %.4f milliseconds\n",
3060            (((double)time_taken * 1000.0) / (double)timeitm) /            (((double)time_taken * 1000.0) / (double)timeitm) /
# Line 2913  while (!done) Line 3099  while (!done)
3099            }            }
3100          extra->flags |= PCRE_EXTRA_CALLOUT_DATA;          extra->flags |= PCRE_EXTRA_CALLOUT_DATA;
3101          extra->callout_data = &callout_data;          extra->callout_data = &callout_data;
3102          count = pcre_exec(re, extra, (char *)bptr, len, start_offset,          PCRE_EXEC(count, re, extra, bptr, len, start_offset,
3103            options | g_notempty, use_offsets, use_size_offsets);            options | g_notempty, use_offsets, use_size_offsets);
3104          extra->flags &= ~PCRE_EXTRA_CALLOUT_DATA;          extra->flags &= ~PCRE_EXTRA_CALLOUT_DATA;
3105          }          }
# Line 2938  while (!done) Line 3124  while (!done)
3124    
3125        else        else
3126          {          {
3127          if (use_pcre16)          PCRE_EXEC(count, re, extra, bptr, len, start_offset,
3128            count = pcre16_exec(re, extra, (PCRE_SPTR16)buffer16, len,            options | g_notempty, use_offsets, use_size_offsets);
             start_offset, options | g_notempty, use_offsets, use_size_offsets);  
         else  
           count = pcre_exec(re, extra, (char *)bptr, len,  
             start_offset, options | g_notempty, use_offsets, use_size_offsets);  
3129          if (count == 0)          if (count == 0)
3130            {            {
3131            fprintf(outfile, "Matched, but too many substrings\n");            fprintf(outfile, "Matched, but too many substrings\n");
# Line 3004  while (!done) Line 3186  while (!done)
3186            else            else
3187              {              {
3188              fprintf(outfile, "%2d: ", i/2);              fprintf(outfile, "%2d: ", i/2);
3189              (void)pchars(bptr + use_offsets[i],              PCHARSV(bptr + use_offsets[i],
3190                use_offsets[i+1] - use_offsets[i], outfile);                use_offsets[i+1] - use_offsets[i], outfile);
3191              fprintf(outfile, "\n");              fprintf(outfile, "\n");
3192              if (do_showcaprest || (i == 0 && do_showrest))              if (do_showcaprest || (i == 0 && do_showrest))
3193                {                {
3194                fprintf(outfile, "%2d+ ", i/2);                fprintf(outfile, "%2d+ ", i/2);
3195                (void)pchars(bptr + use_offsets[i+1], len - use_offsets[i+1],                PCHARSV(bptr + use_offsets[i+1], len - use_offsets[i+1],
3196                  outfile);                  outfile);
3197                fprintf(outfile, "\n");                fprintf(outfile, "\n");
3198                }                }
# Line 3106  while (!done) Line 3288  while (!done)
3288          if (use_size_offsets > 1)          if (use_size_offsets > 1)
3289            {            {
3290            fprintf(outfile, ": ");            fprintf(outfile, ": ");
3291            pchars(bptr + use_offsets[0], use_offsets[1] - use_offsets[0],            PCHARSV(bptr + use_offsets[0], use_offsets[1] - use_offsets[0],
3292              outfile);              outfile);
3293            }            }
3294          fprintf(outfile, "\n");          fprintf(outfile, "\n");

Legend:
Removed from v.807  
changed lines
  Added in v.808

  ViewVC Help
Powered by ViewVC 1.1.5