/[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 839 by zherczeg, Fri Dec 30 13:22:28 2011 UTC revision 914 by zherczeg, Mon Feb 13 06:04:50 2012 UTC
# Line 105  input mode under Windows. */ Line 105  input mode under Windows. */
105  #define OUTPUT_MODE  "wb"  #define OUTPUT_MODE  "wb"
106  #endif  #endif
107    
108    #define PRIV(name) name
109    
110  /* We have to include pcre_internal.h because we need the internal info for  /* We have to include pcre_internal.h because we need the internal info for
111  displaying the results of pcre_study() and we also need to know about the  displaying the results of pcre_study() and we also need to know about the
# Line 141  to keep two copies, we include the sourc Line 142  to keep two copies, we include the sourc
142  external symbols to prevent clashes. */  external symbols to prevent clashes. */
143    
144  #define PCRE_INCLUDED  #define PCRE_INCLUDED
 #undef PRIV  
 #define PRIV(name) name  
145    
146  #include "pcre_tables.c"  #include "pcre_tables.c"
147    
# Line 209  argument, the casting might be incorrect Line 208  argument, the casting might be incorrect
208  #define READ_CAPTURE_NAME8(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME8(p, cn8, cn16, re) \
209    p = read_capture_name8(p, cn8, re)    p = read_capture_name8(p, cn8, re)
210    
211    #define STRLEN8(p) ((int)strlen((char *)p))
212    
213  #define SET_PCRE_CALLOUT8(callout) \  #define SET_PCRE_CALLOUT8(callout) \
214    pcre_callout = callout    pcre_callout = callout
215    
216  #define STRLEN8(p) ((int)strlen((char *)p))  #define PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata) \
217       pcre_assign_jit_stack(extra, callback, userdata)
218    
219  #define PCRE_COMPILE8(re, pat, options, error, erroffset, tables) \  #define PCRE_COMPILE8(re, pat, options, error, erroffset, tables) \
220    re = pcre_compile((char *)pat, options, error, erroffset, tables)    re = pcre_compile((char *)pat, options, error, erroffset, tables)
# Line 268  argument, the casting might be incorrect Line 269  argument, the casting might be incorrect
269  #define PCRE_STUDY8(extra, re, options, error) \  #define PCRE_STUDY8(extra, re, options, error) \
270    extra = pcre_study(re, options, error)    extra = pcre_study(re, options, error)
271    
272    #define PCRE_JIT_STACK_ALLOC8(startsize, maxsize) \
273      pcre_jit_stack_alloc(startsize, maxsize)
274    
275    #define PCRE_JIT_STACK_FREE8(stack) \
276      pcre_jit_stack_free(stack)
277    
278  #endif /* SUPPORT_PCRE8 */  #endif /* SUPPORT_PCRE8 */
279    
280  /* -----------------------------------------------------------*/  /* -----------------------------------------------------------*/
# Line 286  argument, the casting might be incorrect Line 293  argument, the casting might be incorrect
293  #define STRLEN16(p) ((int)strlen16((PCRE_SPTR16)p))  #define STRLEN16(p) ((int)strlen16((PCRE_SPTR16)p))
294    
295  #define SET_PCRE_CALLOUT16(callout) \  #define SET_PCRE_CALLOUT16(callout) \
296    pcre16_callout = callout    pcre16_callout = (int (*)(pcre16_callout_block *))callout
297    
298    #define PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata) \
299      pcre16_assign_jit_stack((pcre16_extra *)extra, \
300        (pcre16_jit_callback)callback, userdata)
301    
302  #define PCRE_COMPILE16(re, pat, options, error, erroffset, tables) \  #define PCRE_COMPILE16(re, pat, options, error, erroffset, tables) \
303    re = pcre16_compile((PCRE_SPTR16)pat, options, error, erroffset, tables)    re = (pcre *)pcre16_compile((PCRE_SPTR16)pat, options, error, erroffset, \
304        tables)
305    
306  #define PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \  #define PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
307      namesptr, cbuffer, size) \      namesptr, cbuffer, size) \
308    rc = pcre16_copy_named_substring(re, (PCRE_SPTR16)bptr, offsets, count, \    rc = pcre16_copy_named_substring((pcre16 *)re, (PCRE_SPTR16)bptr, offsets, \
309      (PCRE_SPTR16)namesptr, (PCRE_SCHAR16 *)cbuffer, size/2)      count, (PCRE_SPTR16)namesptr, (PCRE_UCHAR16 *)cbuffer, size/2)
310    
311  #define PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size) \  #define PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size) \
312    rc = pcre16_copy_substring((PCRE_SPTR16)bptr, offsets, count, i, \    rc = pcre16_copy_substring((PCRE_SPTR16)bptr, offsets, count, i, \
313      (PCRE_SCHAR16 *)cbuffer, size/2)      (PCRE_UCHAR16 *)cbuffer, size/2)
314    
315  #define PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \
316      offsets, size_offsets, workspace, size_workspace) \      offsets, size_offsets, workspace, size_workspace) \
317    count = pcre16_dfa_exec(re, extra, (PCRE_SPTR16)bptr, len, start_offset, \    count = pcre16_dfa_exec((pcre16 *)re, (pcre16_extra *)extra, \
318      options, offsets, size_offsets, workspace, size_workspace)      (PCRE_SPTR16)bptr, len, start_offset, options, offsets, size_offsets, \
319        workspace, size_workspace)
320    
321  #define PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \
322      offsets, size_offsets) \      offsets, size_offsets) \
323    count = pcre16_exec(re, extra, (PCRE_SPTR16)bptr, len, start_offset, \    count = pcre16_exec((pcre16 *)re, (pcre16_extra *)extra, (PCRE_SPTR16)bptr, \
324      options, offsets, size_offsets)      len, start_offset, options, offsets, size_offsets)
325    
326  #define PCRE_FREE_STUDY16(extra) \  #define PCRE_FREE_STUDY16(extra) \
327    pcre16_free_study(extra)    pcre16_free_study((pcre16_extra *)extra)
328    
329  #define PCRE_FREE_SUBSTRING16(substring) \  #define PCRE_FREE_SUBSTRING16(substring) \
330    pcre16_free_substring((PCRE_SPTR16)substring)    pcre16_free_substring((PCRE_SPTR16)substring)
# Line 322  argument, the casting might be incorrect Line 334  argument, the casting might be incorrect
334    
335  #define PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \  #define PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
336      getnamesptr, subsptr) \      getnamesptr, subsptr) \
337    rc = pcre16_get_named_substring(re, (PCRE_SPTR16)bptr, offsets, count, \    rc = pcre16_get_named_substring((pcre16 *)re, (PCRE_SPTR16)bptr, offsets, \
338      (PCRE_SPTR16)getnamesptr, (PCRE_SPTR16 *)(void*)subsptr)      count, (PCRE_SPTR16)getnamesptr, (PCRE_SPTR16 *)(void*)subsptr)
339    
340  #define PCRE_GET_STRINGNUMBER16(n, rc, ptr) \  #define PCRE_GET_STRINGNUMBER16(n, rc, ptr) \
341    n = pcre16_get_stringnumber(re, (PCRE_SPTR16)ptr)    n = pcre16_get_stringnumber(re, (PCRE_SPTR16)ptr)
# Line 337  argument, the casting might be incorrect Line 349  argument, the casting might be incorrect
349      (PCRE_SPTR16 **)(void*)listptr)      (PCRE_SPTR16 **)(void*)listptr)
350    
351  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables) \  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables) \
352    rc = pcre16_pattern_to_host_byte_order(re, extra, tables)    rc = pcre16_pattern_to_host_byte_order((pcre16 *)re, (pcre16_extra *)extra, \
353        tables)
354    
355  #define PCRE_PRINTINT16(re, outfile, debug_lengths) \  #define PCRE_PRINTINT16(re, outfile, debug_lengths) \
356    pcre16_printint(re, outfile, debug_lengths)    pcre16_printint(re, outfile, debug_lengths)
357    
358  #define PCRE_STUDY16(extra, re, options, error) \  #define PCRE_STUDY16(extra, re, options, error) \
359    extra = pcre16_study(re, options, error)    extra = (pcre_extra *)pcre16_study((pcre16 *)re, options, error)
360    
361    #define PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \
362      (pcre_jit_stack *)pcre16_jit_stack_alloc(startsize, maxsize)
363    
364    #define PCRE_JIT_STACK_FREE16(stack) \
365      pcre16_jit_stack_free((pcre16_jit_stack *)stack)
366    
367  #endif /* SUPPORT_PCRE16 */  #endif /* SUPPORT_PCRE16 */
368    
# Line 382  version is called. ----- */ Line 401  version is called. ----- */
401    
402  #define STRLEN(p) (use_pcre16? STRLEN16(p) : STRLEN8(p))  #define STRLEN(p) (use_pcre16? STRLEN16(p) : STRLEN8(p))
403    
404  #define PCRE_ASSIGN_JIT_STACK pcre_assign_jit_stack  #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
405      if (use_pcre16) \
406        PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata); \
407      else \
408        PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata)
409    
410  #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \  #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
411    if (use_pcre16) \    if (use_pcre16) \
# Line 470  version is called. ----- */ Line 493  version is called. ----- */
493    else \    else \
494      PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)      PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)
495    
496  #define PCRE_JIT_STACK_ALLOC pcre_jit_stack_alloc  #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
497  #define PCRE_JIT_STACK_FREE pcre_jit_stack_free    (use_pcre16 ? \
498         PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \
499        :PCRE_JIT_STACK_ALLOC8(startsize, maxsize))
500    
501    #define PCRE_JIT_STACK_FREE(stack) \
502      if (use_pcre16) \
503        PCRE_JIT_STACK_FREE16(stack); \
504      else \
505        PCRE_JIT_STACK_FREE8(stack)
506    
507  #define PCRE_MAKETABLES \  #define PCRE_MAKETABLES \
508    (use_pcre16? pcre16_maketables() : pcre_maketables())    (use_pcre16? pcre16_maketables() : pcre_maketables())
# Line 503  version is called. ----- */ Line 534  version is called. ----- */
534  #define READ_CAPTURE_NAME         READ_CAPTURE_NAME8  #define READ_CAPTURE_NAME         READ_CAPTURE_NAME8
535  #define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT8  #define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT8
536  #define STRLEN                    STRLEN8  #define STRLEN                    STRLEN8
537  #define PCRE_ASSIGN_JIT_STACK     pcre_assign_jit_stack  #define PCRE_ASSIGN_JIT_STACK     PCRE_ASSIGN_JIT_STACK8
538  #define PCRE_COMPILE              PCRE_COMPILE8  #define PCRE_COMPILE              PCRE_COMPILE8
539  #define PCRE_CONFIG               pcre_config  #define PCRE_CONFIG               pcre_config
540  #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING8  #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING8
# Line 517  version is called. ----- */ Line 548  version is called. ----- */
548  #define PCRE_GET_STRINGNUMBER     PCRE_GET_STRINGNUMBER8  #define PCRE_GET_STRINGNUMBER     PCRE_GET_STRINGNUMBER8
549  #define PCRE_GET_SUBSTRING        PCRE_GET_SUBSTRING8  #define PCRE_GET_SUBSTRING        PCRE_GET_SUBSTRING8
550  #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST8  #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST8
551  #define PCRE_JIT_STACK_ALLOC      pcre_jit_stack_alloc  #define PCRE_JIT_STACK_ALLOC      PCRE_JIT_STACK_ALLOC8
552  #define PCRE_JIT_STACK_FREE       pcre_jit_stack_free  #define PCRE_JIT_STACK_FREE       PCRE_JIT_STACK_FREE8
553  #define PCRE_MAKETABLES           pcre_maketables()  #define PCRE_MAKETABLES           pcre_maketables()
554  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER8  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER8
555  #define PCRE_PRINTINT             PCRE_PRINTINT8  #define PCRE_PRINTINT             PCRE_PRINTINT8
# Line 533  version is called. ----- */ Line 564  version is called. ----- */
564  #define READ_CAPTURE_NAME         READ_CAPTURE_NAME16  #define READ_CAPTURE_NAME         READ_CAPTURE_NAME16
565  #define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT16  #define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT16
566  #define STRLEN                    STRLEN16  #define STRLEN                    STRLEN16
567  #define PCRE_ASSIGN_JIT_STACK     pcre16_assign_jit_stack  #define PCRE_ASSIGN_JIT_STACK     PCRE_ASSIGN_JIT_STACK16
568  #define PCRE_COMPILE              PCRE_COMPILE16  #define PCRE_COMPILE              PCRE_COMPILE16
569  #define PCRE_CONFIG               pcre16_config  #define PCRE_CONFIG               pcre16_config
570  #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING16  #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING16
# Line 547  version is called. ----- */ Line 578  version is called. ----- */
578  #define PCRE_GET_STRINGNUMBER     PCRE_GET_STRINGNUMBER16  #define PCRE_GET_STRINGNUMBER     PCRE_GET_STRINGNUMBER16
579  #define PCRE_GET_SUBSTRING        PCRE_GET_SUBSTRING16  #define PCRE_GET_SUBSTRING        PCRE_GET_SUBSTRING16
580  #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST16  #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST16
581  #define PCRE_JIT_STACK_ALLOC      pcre16_jit_stack_alloc  #define PCRE_JIT_STACK_ALLOC      PCRE_JIT_STACK_ALLOC16
582  #define PCRE_JIT_STACK_FREE       pcre16_jit_stack_free  #define PCRE_JIT_STACK_FREE       PCRE_JIT_STACK_FREE16
583  #define PCRE_MAKETABLES           pcre16_maketables()  #define PCRE_MAKETABLES           pcre16_maketables()
584  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER16  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER16
585  #define PCRE_PRINTINT             PCRE_PRINTINT16  #define PCRE_PRINTINT             PCRE_PRINTINT16
# Line 1126  for (j = i; j > 0; j--) Line 1157  for (j = i; j > 0; j--)
1157  *utf8bytes = utf8_table2[i] | cvalue;  *utf8bytes = utf8_table2[i] | cvalue;
1158  return i + 1;  return i + 1;
1159  }  }
1160  #endif /* NOUTF || SUPPORT_PCRE16 */  #endif
   
1161    
1162    
1163  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
# Line 1145  Note that this function does not object Line 1175  Note that this function does not object
1175  deliberate; it makes it possible to construct UTF-16 strings that are invalid,  deliberate; it makes it possible to construct UTF-16 strings that are invalid,
1176  for the purpose of testing that they are correctly faulted.  for the purpose of testing that they are correctly faulted.
1177    
1178  Patterns to be converted are either plain ASCII or UTF-8; data lines are always  Patterns to be converted are either plain ASCII or UTF-8; data lines are always
1179  in UTF-8 so that values greater than 255 can be handled.  in UTF-8 so that values greater than 255 can be handled.
1180    
1181  Arguments:  Arguments:
# Line 1157  Arguments: Line 1187  Arguments:
1187  Returns:     number of 16-bit data items used (excluding trailing zero)  Returns:     number of 16-bit data items used (excluding trailing zero)
1188               OR -1 if a UTF-8 string is malformed               OR -1 if a UTF-8 string is malformed
1189               OR -2 if a value > 0x10ffff is encountered               OR -2 if a value > 0x10ffff is encountered
1190               OR -3 if a value > 0xffff is encountered when not in UTF mode               OR -3 if a value > 0xffff is encountered when not in UTF mode
1191  */  */
1192    
1193  static int  static int
# Line 1240  pcre_uint8 *here = start; Line 1270  pcre_uint8 *here = start;
1270    
1271  for (;;)  for (;;)
1272    {    {
1273    int rlen = (int)(buffer_size - (here - buffer));    size_t rlen = (size_t)(buffer_size - (here - buffer));
1274    
1275    if (rlen > 1000)    if (rlen > 1000)
1276      {      {
# Line 1514  pcre_uint16 *npp = *pp; Line 1544  pcre_uint16 *npp = *pp;
1544  while (isalnum(*p)) *npp++ = *p++;  while (isalnum(*p)) *npp++ = *p++;
1545  *npp++ = 0;  *npp++ = 0;
1546  *npp = 0;  *npp = 0;
1547  if (pcre16_get_stringnumber(re, (PCRE_SPTR16)(*pp)) < 0)  if (pcre16_get_stringnumber((pcre16 *)re, (PCRE_SPTR16)(*pp)) < 0)
1548    {    {
1549    fprintf(outfile, "no parentheses with name \"");    fprintf(outfile, "no parentheses with name \"");
1550    PCHARSV(*pp, 0, -1, outfile);    PCHARSV(*pp, 0, -1, outfile);
# Line 1703  int rc; Line 1733  int rc;
1733    
1734  if (use_pcre16)  if (use_pcre16)
1735  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
1736    rc = pcre16_fullinfo(re, study, option, ptr);    rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);
1737  #else  #else
1738    rc = PCRE_ERROR_BADMODE;    rc = PCRE_ERROR_BADMODE;
1739  #endif  #endif
# Line 1772  architecture. */ Line 1802  architecture. */
1802  static void  static void
1803  regexflip(pcre *ere, pcre_extra *extra)  regexflip(pcre *ere, pcre_extra *extra)
1804  {  {
1805  real_pcre *re = (real_pcre *)ere;  REAL_PCRE *re = (REAL_PCRE *)ere;
1806  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
1807  int op;  int op;
1808  pcre_uint16 *ptr = (pcre_uint16 *)re + re->name_table_offset;  pcre_uint16 *ptr = (pcre_uint16 *)re + re->name_table_offset;
# Line 2073  printf("This version of pcretest is not Line 2103  printf("This version of pcretest is not
2103  #endif  #endif
2104  printf("\nOptions:\n");  printf("\nOptions:\n");
2105  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2106  printf("  -16      use 16-bit interface\n");  printf("  -16      use the 16-bit library\n");
2107  #endif  #endif
2108  printf("  -b       show compiled code (bytecode)\n");  printf("  -b       show compiled code\n");
2109  printf("  -C       show PCRE compile-time options and exit\n");  printf("  -C       show PCRE compile-time options and exit\n");
2110  printf("  -C arg   show a specific compile-time option\n");  printf("  -C arg   show a specific compile-time option\n");
2111  printf("           and exit with its value. The arg can be:\n");  printf("           and exit with its value. The arg can be:\n");
# Line 2151  pcre_jit_stack *jit_stack = NULL; Line 2181  pcre_jit_stack *jit_stack = NULL;
2181  substring names, each list itself being terminated by an empty name. Assume  substring names, each list itself being terminated by an empty name. Assume
2182  that 1024 is plenty long enough for the few names we'll be testing. It is  that 1024 is plenty long enough for the few names we'll be testing. It is
2183  easiest to keep separate 8-bit and 16-bit versions, using the 16-bit version  easiest to keep separate 8-bit and 16-bit versions, using the 16-bit version
2184  for the actual memory, to ensure alignment. By defining these variables always  for the actual memory, to ensure alignment. */
 (whether or not 8-bit or 16-bit is supported), we avoid too much mess with  
 #ifdefs in the code. */  
2185    
2186  pcre_uint16 copynames[1024];  pcre_uint16 copynames[1024];
2187  pcre_uint16 getnames[1024];  pcre_uint16 getnames[1024];
2188    
2189    #ifdef SUPPORT_PCRE16
2190  pcre_uint16 *cn16ptr;  pcre_uint16 *cn16ptr;
2191  pcre_uint16 *gn16ptr;  pcre_uint16 *gn16ptr;
2192    #endif
2193    
2194    #ifdef SUPPORT_PCRE8
2195  pcre_uint8 *copynames8 = (pcre_uint8 *)copynames;  pcre_uint8 *copynames8 = (pcre_uint8 *)copynames;
2196  pcre_uint8 *getnames8 = (pcre_uint8 *)getnames;  pcre_uint8 *getnames8 = (pcre_uint8 *)getnames;
2197  pcre_uint8 *cn8ptr;  pcre_uint8 *cn8ptr;
2198  pcre_uint8 *gn8ptr;  pcre_uint8 *gn8ptr;
2199    #endif
2200    
2201  /* Get buffers from malloc() so that valgrind will check their misuse when  /* Get buffers from malloc() so that valgrind will check their misuse when
2202  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
# Line 2207  while (argc > 1 && argv[op][0] == '-') Line 2239  while (argc > 1 && argv[op][0] == '-')
2239    else if (strcmp(argv[op], "-s+") == 0)    else if (strcmp(argv[op], "-s+") == 0)
2240      {      {
2241      force_study = 1;      force_study = 1;
2242      force_study_options = PCRE_STUDY_JIT_COMPILE;      force_study_options = PCRE_STUDY_JIT_COMPILE
2243                            | PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE
2244                            | PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE;
2245      }      }
2246    else if (strcmp(argv[op], "-16") == 0)    else if (strcmp(argv[op], "-16") == 0)
2247      {      {
# Line 2336  while (argc > 1 && argv[op][0] == '-') Line 2370  while (argc > 1 && argv[op][0] == '-')
2370          goto EXIT;          goto EXIT;
2371          }          }
2372        if (strcmp(argv[op + 1], "newline") == 0)        if (strcmp(argv[op + 1], "newline") == 0)
2373          {          {
2374          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
2375          /* Note that these values are always the ASCII values, even          /* Note that these values are always the ASCII values, even
2376          in EBCDIC environments. CR is 13 and NL is 10. */          in EBCDIC environments. CR is 13 and NL is 10. */
# Line 2345  while (argc > 1 && argv[op][0] == '-') Line 2379  while (argc > 1 && argv[op][0] == '-')
2379            (rc == -2)? "ANYCRLF" :            (rc == -2)? "ANYCRLF" :
2380            (rc == -1)? "ANY" : "???");            (rc == -1)? "ANY" : "???");
2381          goto EXIT;          goto EXIT;
2382          }          }
2383        printf("Unknown -C option: %s\n", argv[op + 1]);        printf("Unknown -C option: %s\n", argv[op + 1]);
2384        goto EXIT;        goto EXIT;
2385        }        }
# Line 2377  are set, either both UTFs are supported Line 2411  are set, either both UTFs are supported
2411      printf("  %sUnicode properties support\n", rc? "" : "No ");      printf("  %sUnicode properties support\n", rc? "" : "No ");
2412      (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);
2413      if (rc)      if (rc)
2414        printf("  Just-in-time compiler support\n");        {
2415          const char *arch;
2416          (void)PCRE_CONFIG(PCRE_CONFIG_JITTARGET, (void *)(&arch));
2417          printf("  Just-in-time compiler support: %s\n", arch);
2418          }
2419      else      else
2420        printf("  No just-in-time compiler support\n");        printf("  No just-in-time compiler support\n");
2421      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
# Line 2399  are set, either both UTFs are supported Line 2437  are set, either both UTFs are supported
2437      (void)PCRE_CONFIG(PCRE_CONFIG_MATCH_LIMIT_RECURSION, &lrc);      (void)PCRE_CONFIG(PCRE_CONFIG_MATCH_LIMIT_RECURSION, &lrc);
2438      printf("  Default recursion depth limit = %ld\n", lrc);      printf("  Default recursion depth limit = %ld\n", lrc);
2439      (void)PCRE_CONFIG(PCRE_CONFIG_STACKRECURSE, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_STACKRECURSE, &rc);
2440      printf("  Match recursion uses %s\n", rc? "stack" : "heap");      printf("  Match recursion uses %s", rc? "stack" : "heap");
2441        if (showstore)
2442          {
2443          PCRE_EXEC(stack_size, NULL, NULL, NULL, -999, -999, 0, NULL, 0);
2444          printf(": %sframe size = %d bytes", rc? "approximate " : "", -stack_size);
2445          }
2446        printf("\n");
2447      goto EXIT;      goto EXIT;
2448      }      }
2449    else if (strcmp(argv[op], "-help") == 0 ||    else if (strcmp(argv[op], "-help") == 0 ||
# Line 2492  while (!done) Line 2536  while (!done)
2536    pcre_uint8 *p, *pp, *ppp;    pcre_uint8 *p, *pp, *ppp;
2537    pcre_uint8 *to_file = NULL;    pcre_uint8 *to_file = NULL;
2538    const pcre_uint8 *tables = NULL;    const pcre_uint8 *tables = NULL;
2539      unsigned long int get_options;
2540    unsigned long int true_size, true_study_size = 0;    unsigned long int true_size, true_study_size = 0;
2541    size_t size, regex_gotten_store;    size_t size, regex_gotten_store;
2542    int do_allcaps = 0;    int do_allcaps = 0;
# Line 2522  while (!done) Line 2567  while (!done)
2567    
2568    if (*p == '<' && strchr((char *)(p+1), '<') == NULL)    if (*p == '<' && strchr((char *)(p+1), '<') == NULL)
2569      {      {
2570      unsigned long int magic, get_options;      pcre_uint32 magic;
2571      pcre_uint8 sbuf[8];      pcre_uint8 sbuf[8];
2572      FILE *f;      FILE *f;
2573    
# Line 2553  while (!done) Line 2598  while (!done)
2598      true_study_size =      true_study_size =
2599        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];
2600    
2601      re = (real_pcre *)new_malloc(true_size);      re = (pcre *)new_malloc(true_size);
2602      regex_gotten_store = first_gotten_store;      regex_gotten_store = first_gotten_store;
2603    
2604      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;
2605    
2606      magic = ((real_pcre *)re)->magic_number;      magic = ((REAL_PCRE *)re)->magic_number;
2607      if (magic != MAGIC_NUMBER)      if (magic != MAGIC_NUMBER)
2608        {        {
2609        if (swap_uint32(magic) == MAGIC_NUMBER)        if (swap_uint32(magic) == MAGIC_NUMBER)
# Line 2725  while (!done) Line 2770  while (!done)
2770          do_study = 1;          do_study = 1;
2771          if (*pp == '+')          if (*pp == '+')
2772            {            {
2773            study_options |= PCRE_STUDY_JIT_COMPILE;            study_options |= PCRE_STUDY_JIT_COMPILE
2774                            | PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE
2775                            | PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE;
2776            pp++;            pp++;
2777            }            }
2778          }          }
# Line 2852  while (!done) Line 2899  while (!done)
2899  #endif  /* !defined NOPOSIX */  #endif  /* !defined NOPOSIX */
2900    
2901      {      {
     unsigned long int get_options;  
   
2902      /* In 16-bit mode, convert the input. */      /* In 16-bit mode, convert the input. */
2903    
2904  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
# Line 2870  while (!done) Line 2915  while (!done)
2915          fprintf(outfile, "**Failed: character value greater than 0x10ffff "          fprintf(outfile, "**Failed: character value greater than 0x10ffff "
2916            "cannot be converted to UTF-16\n");            "cannot be converted to UTF-16\n");
2917          goto SKIP_DATA;          goto SKIP_DATA;
2918    
2919          case -3: /* "Impossible error" when to16 is called arg1 FALSE */          case -3: /* "Impossible error" when to16 is called arg1 FALSE */
2920          fprintf(outfile, "**Failed: character value greater than 0xffff "          fprintf(outfile, "**Failed: character value greater than 0xffff "
2921            "cannot be converted to 16-bit in non-UTF mode\n");            "cannot be converted to 16-bit in non-UTF mode\n");
2922          goto SKIP_DATA;          goto SKIP_DATA;
2923    
2924          default:          default:
2925          break;          break;
# Line 2940  while (!done) Line 2985  while (!done)
2985      /* Extract the size for possible writing before possibly flipping it,      /* Extract the size for possible writing before possibly flipping it,
2986      and remember the store that was got. */      and remember the store that was got. */
2987    
2988      true_size = ((real_pcre *)re)->size;      true_size = ((REAL_PCRE *)re)->size;
2989      regex_gotten_store = first_gotten_store;      regex_gotten_store = first_gotten_store;
2990    
2991      /* Output code size information if requested */      /* Output code size information if requested */
# Line 2948  while (!done) Line 2993  while (!done)
2993      if (log_store)      if (log_store)
2994        fprintf(outfile, "Memory allocation (code space): %d\n",        fprintf(outfile, "Memory allocation (code space): %d\n",
2995          (int)(first_gotten_store -          (int)(first_gotten_store -
2996                sizeof(real_pcre) -                sizeof(REAL_PCRE) -
2997                ((real_pcre *)re)->name_count * ((real_pcre *)re)->name_entry_size));                ((REAL_PCRE *)re)->name_count * ((REAL_PCRE *)re)->name_entry_size));
2998    
2999      /* If -s or /S was present, study the regex to generate additional info to      /* If -s or /S was present, study the regex to generate additional info to
3000      help with the matching, unless the pattern has the SS option, which      help with the matching, unless the pattern has the SS option, which
# Line 3080  while (!done) Line 3125  while (!done)
3125        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");
3126        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");
3127    
3128        all_options = ((real_pcre *)re)->options;        all_options = ((REAL_PCRE *)re)->options;
3129        if (do_flip) all_options = swap_uint32(all_options);        if (do_flip) all_options = swap_uint32(all_options);
3130    
3131        if (get_options == 0) fprintf(outfile, "No options\n");        if (get_options == 0) fprintf(outfile, "No options\n");
# Line 3142  while (!done) Line 3187  while (!done)
3187        else        else
3188          {          {
3189          const char *caseless =          const char *caseless =
3190            ((((real_pcre *)re)->flags & PCRE_FCH_CASELESS) == 0)?            ((((REAL_PCRE *)re)->flags & PCRE_FCH_CASELESS) == 0)?
3191            "" : " (caseless)";            "" : " (caseless)";
3192    
3193          if (PRINTOK(first_char))          if (PRINTOK(first_char))
# Line 3162  while (!done) Line 3207  while (!done)
3207        else        else
3208          {          {
3209          const char *caseless =          const char *caseless =
3210            ((((real_pcre *)re)->flags & PCRE_RCH_CASELESS) == 0)?            ((((REAL_PCRE *)re)->flags & PCRE_RCH_CASELESS) == 0)?
3211            "" : " (caseless)";            "" : " (caseless)";
3212    
3213          if (PRINTOK(need_char))          if (PRINTOK(need_char))
# Line 3339  while (!done) Line 3384  while (!done)
3384      *copynames = 0;      *copynames = 0;
3385      *getnames = 0;      *getnames = 0;
3386    
3387    #ifdef SUPPORT_PCRE16
3388      cn16ptr = copynames;      cn16ptr = copynames;
3389      gn16ptr = getnames;      gn16ptr = getnames;
3390    #endif
3391    #ifdef SUPPORT_PCRE8
3392      cn8ptr = copynames8;      cn8ptr = copynames8;
3393      gn8ptr = getnames8;      gn8ptr = getnames8;
3394    #endif
3395    
3396      SET_PCRE_CALLOUT(callout);      SET_PCRE_CALLOUT(callout);
3397      first_callout = 1;      first_callout = 1;
# Line 3387  while (!done) Line 3436  while (!done)
3436        {        {
3437        int i = 0;        int i = 0;
3438        int n = 0;        int n = 0;
3439    
3440        /* In UTF mode, input can be UTF-8, so just copy all non-backslash bytes.        /* In UTF mode, input can be UTF-8, so just copy all non-backslash bytes.
3441        In non-UTF mode, allow the value of the byte to fall through to later,        In non-UTF mode, allow the value of the byte to fall through to later,
3442        where values greater than 127 are turned into UTF-8 when running in        where values greater than 127 are turned into UTF-8 when running in
3443        16-bit mode. */        16-bit mode. */
3444    
3445        if (c != '\\')        if (c != '\\')
3446          {          {
3447          if (use_utf)          if (use_utf)
3448            {            {
3449            *q++ = c;            *q++ = c;
3450            continue;            continue;
3451            }            }
3452          }          }
3453    
3454        /* Handle backslash escapes */        /* Handle backslash escapes */
3455    
3456        else switch ((c = *p++))        else switch ((c = *p++))
3457          {          {
3458          case 'a': c =    7; break;          case 'a': c =    7; break;
# Line 3434  while (!done) Line 3483  while (!done)
3483            least one MacOS environment. */            least one MacOS environment. */
3484    
3485            for (pt++; isxdigit(*pt); pt++)            for (pt++; isxdigit(*pt); pt++)
3486              c = c * 16 + tolower(*pt) - ((isdigit(*pt))? '0' : 'a' - 10);              {
3487                if (++i == 9)
3488                  fprintf(outfile, "** Too many hex digits in \\x{...} item; "
3489                                   "using only the first eight.\n");
3490                else c = c * 16 + tolower(*pt) - ((isdigit(*pt))? '0' : 'a' - 10);
3491                }
3492            if (*pt == '}')            if (*pt == '}')
3493              {              {
3494              p = pt + 1;              p = pt + 1;
# Line 3443  while (!done) Line 3497  while (!done)
3497            /* Not correct form for \x{...}; fall through */            /* Not correct form for \x{...}; fall through */
3498            }            }
3499    
3500          /* \x without {} always defines just one byte in 8-bit mode. This          /* \x without {} always defines just one byte in 8-bit mode. This
3501          allows UTF-8 characters to be constructed byte by byte, and also allows          allows UTF-8 characters to be constructed byte by byte, and also allows
3502          invalid UTF-8 sequences to be made. Just copy the byte in UTF mode.          invalid UTF-8 sequences to be made. Just copy the byte in UTF mode.
3503          Otherwise, pass it down to later code so that it can be turned into          Otherwise, pass it down to later code so that it can be turned into
3504          UTF-8 when running in 16-bit mode. */          UTF-8 when running in 16-bit mode. */
3505    
3506          c = 0;          c = 0;
# Line 3456  while (!done) Line 3510  while (!done)
3510            p++;            p++;
3511            }            }
3512          if (use_utf)          if (use_utf)
3513            {            {
3514            *q++ = c;            *q++ = c;
3515            continue;            continue;
3516            }            }
3517          break;          break;
3518    
3519          case 0:   /* \ followed by EOF allows for an empty line */          case 0:   /* \ followed by EOF allows for an empty line */
# Line 3565  while (!done) Line 3619  while (!done)
3619              && (extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0              && (extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0
3620              && extra->executable_jit != NULL)              && extra->executable_jit != NULL)
3621            {            {
3622            if (jit_stack != NULL) PCRE_JIT_STACK_FREE(jit_stack);            if (jit_stack != NULL) { PCRE_JIT_STACK_FREE(jit_stack); }
3623            jit_stack = PCRE_JIT_STACK_ALLOC(1, n * 1024);            jit_stack = PCRE_JIT_STACK_ALLOC(1, n * 1024);
3624            PCRE_ASSIGN_JIT_STACK(extra, jit_callback, jit_stack);            PCRE_ASSIGN_JIT_STACK(extra, jit_callback, jit_stack);
3625            }            }
# Line 3664  while (!done) Line 3718  while (!done)
3718          continue;          continue;
3719          }          }
3720    
3721        /* We now have a character value in c that may be greater than 255. In        /* We now have a character value in c that may be greater than 255. In
3722        16-bit mode, we always convert characters to UTF-8 so that values greater        16-bit mode, we always convert characters to UTF-8 so that values greater
3723        than 255 can be passed to non-UTF 16-bit strings. In 8-bit mode we        than 255 can be passed to non-UTF 16-bit strings. In 8-bit mode we
3724        convert to UTF-8 if we are in UTF mode. Values greater than 127 in UTF        convert to UTF-8 if we are in UTF mode. Values greater than 127 in UTF
3725        mode must have come from \x{...} or octal constructs because values from        mode must have come from \x{...} or octal constructs because values from
3726        \x.. get this far only in non-UTF mode. */        \x.. get this far only in non-UTF mode. */
3727    
3728    #if !defined NOUTF || defined SUPPORT_PCRE16
3729        if (use_pcre16 || use_utf)        if (use_pcre16 || use_utf)
3730          {          {
3731          pcre_uint8 buff8[8];          pcre_uint8 buff8[8];
# Line 3679  while (!done) Line 3734  while (!done)
3734          for (ii = 0; ii < utn; ii++) *q++ = buff8[ii];          for (ii = 0; ii < utn; ii++) *q++ = buff8[ii];
3735          }          }
3736        else        else
3737    #endif
3738          {          {
3739          if (c > 255)          if (c > 255)
3740            {            {
# Line 3690  while (!done) Line 3746  while (!done)
3746          *q++ = c;          *q++ = c;
3747          }          }
3748        }        }
3749    
3750      /* Reached end of subject string */      /* Reached end of subject string */
3751    
3752      *q = 0;      *q = 0;
3753      len = (int)(q - dbuffer);      len = (int)(q - dbuffer);
3754    
# Line 3778  while (!done) Line 3834  while (!done)
3834  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3835      if (use_pcre16)      if (use_pcre16)
3836        {        {
3837        len = to16(TRUE, bptr, (((real_pcre *)re)->options) & PCRE_UTF8, len);        len = to16(TRUE, bptr, (((REAL_PCRE *)re)->options) & PCRE_UTF8, len);
3838        switch(len)        switch(len)
3839          {          {
3840          case -1:          case -1:
# Line 3794  while (!done) Line 3850  while (!done)
3850          case -3:          case -3:
3851          fprintf(outfile, "**Failed: character value greater than 0xffff "          fprintf(outfile, "**Failed: character value greater than 0xffff "
3852            "cannot be converted to 16-bit in non-UTF mode\n");            "cannot be converted to 16-bit in non-UTF mode\n");
3853          goto NEXT_DATA;          goto NEXT_DATA;
3854    
3855          default:          default:
3856          break;          break;
# Line 4158  while (!done) Line 4214  while (!done)
4214          if (g_notempty != 0)          if (g_notempty != 0)
4215            {            {
4216            int onechar = 1;            int onechar = 1;
4217            unsigned int obits = ((real_pcre *)re)->options;            unsigned int obits = ((REAL_PCRE *)re)->options;
4218            use_offsets[0] = start_offset;            use_offsets[0] = start_offset;
4219            if ((obits & PCRE_NEWLINE_BITS) == 0)            if ((obits & PCRE_NEWLINE_BITS) == 0)
4220              {              {
# Line 4240  while (!done) Line 4296  while (!done)
4296              break;              break;
4297    
4298              default:              default:
4299              if (count < 0 && (-count) < sizeof(errtexts)/sizeof(const char *))              if (count < 0 &&
4300                    (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))
4301                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);
4302              else              else
4303                fprintf(outfile, "Error %d (Unexpected value)\n", count);                fprintf(outfile, "Error %d (Unexpected value)\n", count);

Legend:
Removed from v.839  
changed lines
  Added in v.914

  ViewVC Help
Powered by ViewVC 1.1.5