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

Diff of /code/trunk/pcretest.c

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

revision 908 by ph10, Mon Jan 30 12:19:29 2012 UTC revision 1030 by ph10, Sat Sep 8 15:58:38 2012 UTC
# Line 46  pcre_internal.h that depend on COMPILE_P Line 46  pcre_internal.h that depend on COMPILE_P
46  however, make use of SUPPORT_PCRE8 and SUPPORT_PCRE16 to ensure that it calls  however, make use of SUPPORT_PCRE8 and SUPPORT_PCRE16 to ensure that it calls
47  only supported library functions. */  only supported library functions. */
48    
   
49  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
50  #include "config.h"  #include "config.h"
51  #endif  #endif
# Line 59  only supported library functions. */ Line 58  only supported library functions. */
58  #include <locale.h>  #include <locale.h>
59  #include <errno.h>  #include <errno.h>
60    
61  #ifdef SUPPORT_LIBREADLINE  /* Both libreadline and libedit are optionally supported. The user-supplied
62    original patch uses readline/readline.h for libedit, but in at least one system
63    it is installed as editline/readline.h, so the configuration code now looks for
64    that first, falling back to readline/readline.h. */
65    
66    #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
67  #ifdef HAVE_UNISTD_H  #ifdef HAVE_UNISTD_H
68  #include <unistd.h>  #include <unistd.h>
69  #endif  #endif
70    #if defined(SUPPORT_LIBREADLINE)
71  #include <readline/readline.h>  #include <readline/readline.h>
72  #include <readline/history.h>  #include <readline/history.h>
73    #else
74    #if defined(HAVE_EDITLINE_READLINE_H)
75    #include <editline/readline.h>
76    #else
77    #include <readline/readline.h>
78    #endif
79    #endif
80  #endif  #endif
   
81    
82  /* A number of things vary for Windows builds. Originally, pcretest opened its  /* A number of things vary for Windows builds. Originally, pcretest opened its
83  input and output without "b"; then I was told that "b" was needed in some  input and output without "b"; then I was told that "b" was needed in some
# Line 101  input mode under Windows. */ Line 112  input mode under Windows. */
112  #else  #else
113  #include <sys/time.h>          /* These two includes are needed */  #include <sys/time.h>          /* These two includes are needed */
114  #include <sys/resource.h>      /* for setrlimit(). */  #include <sys/resource.h>      /* for setrlimit(). */
115    #if defined NATIVE_ZOS         /* z/OS uses non-binary I/O */
116    #define INPUT_MODE   "r"
117    #define OUTPUT_MODE  "w"
118    #else
119  #define INPUT_MODE   "rb"  #define INPUT_MODE   "rb"
120  #define OUTPUT_MODE  "wb"  #define OUTPUT_MODE  "wb"
121  #endif  #endif
122    #endif
123    
124  #define PRIV(name) name  #define PRIV(name) name
125    
# Line 599  version is called. ----- */ Line 615  version is called. ----- */
615  #endif  #endif
616  #endif  #endif
617    
618    #if !defined NODFA
619    #define DFA_WS_DIMENSION 1000
620    #endif
621    
622  /* This is the default loop count for timing. */  /* This is the default loop count for timing. */
623    
624  #define LOOPREPEAT 500000  #define LOOPREPEAT 500000
# Line 613  static int callout_fail_count; Line 633  static int callout_fail_count;
633  static int callout_fail_id;  static int callout_fail_id;
634  static int debug_lengths;  static int debug_lengths;
635  static int first_callout;  static int first_callout;
636    static int jit_was_used;
637  static int locale_set = 0;  static int locale_set = 0;
638  static int show_malloc;  static int show_malloc;
639  static int use_utf;  static int use_utf;
# Line 674  static int use_pcre16 = 0; Line 695  static int use_pcre16 = 0;
695  static int use_pcre16 = 1;  static int use_pcre16 = 1;
696  #endif  #endif
697    
698    /* JIT study options for -s+n and /S+n where '1' <= n <= '7'. */
699    
700    static int jit_study_bits[] =
701      {
702      PCRE_STUDY_JIT_COMPILE,
703      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE,
704      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE,
705      PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
706      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
707      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE + PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
708      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE +
709        PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE
710    };
711    
712    #define PCRE_STUDY_ALLJIT (PCRE_STUDY_JIT_COMPILE | \
713      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE | PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE)
714    
715  /* Textual explanations for runtime error codes */  /* Textual explanations for runtime error codes */
716    
717  static const char *errtexts[] = {  static const char *errtexts[] = {
# Line 705  static const char *errtexts[] = { Line 743  static const char *errtexts[] = {
743    NULL,  /* SHORTUTF8/16 is handled specially */    NULL,  /* SHORTUTF8/16 is handled specially */
744    "nested recursion at the same subject position",    "nested recursion at the same subject position",
745    "JIT stack limit reached",    "JIT stack limit reached",
746    "pattern compiled in wrong mode: 8-bit/16-bit error"    "pattern compiled in wrong mode: 8-bit/16-bit error",
747      "pattern compiled with other endianness",
748      "invalid data in workspace for DFA restart"
749  };  };
750    
751    
# Line 1057  return sys_errlist[n]; Line 1097  return sys_errlist[n];
1097  #endif /* HAVE_STRERROR */  #endif /* HAVE_STRERROR */
1098    
1099    
1100    
1101    /*************************************************
1102    *       Print newline configuration              *
1103    *************************************************/
1104    
1105    /*
1106    Argument: the return code from PCRE_CONFIG_NEWLINE
1107    Returns:  nothing
1108    */
1109    
1110    static void
1111    print_newline_config(int rc)
1112    {
1113    const char *s = NULL;
1114    printf("  Newline sequence is ");
1115    switch(rc)
1116      {
1117      case CHAR_CR: s = "CR"; break;
1118      case CHAR_LF: s = "LF"; break;
1119      case (CHAR_CR<<8 | CHAR_LF): s = "CRLF"; break;
1120      case -1: s = "ANY"; break;
1121      case -2: s = "ANYCRLF"; break;
1122    
1123      default:
1124      printf("a non-standard value: 0x%04x\n", rc);
1125      return;
1126      }
1127    
1128    printf("%s\n", s);
1129    }
1130    
1131    
1132    
1133  /*************************************************  /*************************************************
1134  *         JIT memory callback                    *  *         JIT memory callback                    *
1135  *************************************************/  *************************************************/
1136    
1137  static pcre_jit_stack* jit_callback(void *arg)  static pcre_jit_stack* jit_callback(void *arg)
1138  {  {
1139    jit_was_used = TRUE;
1140  return (pcre_jit_stack *)arg;  return (pcre_jit_stack *)arg;
1141  }  }
1142    
# Line 1276  for (;;) Line 1350  for (;;)
1350      {      {
1351      int dlen;      int dlen;
1352    
1353      /* If libreadline support is required, use readline() to read a line if the      /* If libreadline or libedit support is required, use readline() to read a
1354      input is a terminal. Note that readline() removes the trailing newline, so      line if the input is a terminal. Note that readline() removes the trailing
1355      we must put it back again, to be compatible with fgets(). */      newline, so we must put it back again, to be compatible with fgets(). */
1356    
1357  #ifdef SUPPORT_LIBREADLINE  #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
1358      if (isatty(fileno(f)))      if (isatty(fileno(f)))
1359        {        {
1360        size_t len;        size_t len;
# Line 2096  usage(void) Line 2170  usage(void)
2170  {  {
2171  printf("Usage:     pcretest [options] [<input file> [<output file>]]\n\n");  printf("Usage:     pcretest [options] [<input file> [<output file>]]\n\n");
2172  printf("Input and output default to stdin and stdout.\n");  printf("Input and output default to stdin and stdout.\n");
2173  #ifdef SUPPORT_LIBREADLINE  #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
2174  printf("If input is a terminal, readline() is used to read from it.\n");  printf("If input is a terminal, readline() is used to read from it.\n");
2175  #else  #else
2176  printf("This version of pcretest is not linked with readline().\n");  printf("This version of pcretest is not linked with readline().\n");
# Line 2132  printf("  -q       quiet: do not output Line 2206  printf("  -q       quiet: do not output
2206  printf("  -S <n>   set stack size to <n> megabytes\n");  printf("  -S <n>   set stack size to <n> megabytes\n");
2207  printf("  -s       force each pattern to be studied at basic level\n"  printf("  -s       force each pattern to be studied at basic level\n"
2208         "  -s+      force each pattern to be studied, using JIT if available\n"         "  -s+      force each pattern to be studied, using JIT if available\n"
2209           "  -s++     ditto, verifying when JIT was actually used\n"
2210           "  -s+n     force each pattern to be studied, using JIT if available,\n"
2211           "             where 1 <= n <= 7 selects JIT options\n"
2212           "  -s++n    ditto, verifying when JIT was actually used\n"
2213         "  -t       time compilation and execution\n");         "  -t       time compilation and execution\n");
2214  printf("  -t <n>   time compilation and execution, repeating <n> times\n");  printf("  -t <n>   time compilation and execution, repeating <n> times\n");
2215  printf("  -tm      time execution (matching) only\n");  printf("  -tm      time execution (matching) only\n");
# Line 2166  int quiet = 0; Line 2244  int quiet = 0;
2244  int size_offsets = 45;  int size_offsets = 45;
2245  int size_offsets_max;  int size_offsets_max;
2246  int *offsets = NULL;  int *offsets = NULL;
 #if !defined NOPOSIX  
 int posix = 0;  
 #endif  
2247  int debug = 0;  int debug = 0;
2248  int done = 0;  int done = 0;
2249  int all_use_dfa = 0;  int all_use_dfa = 0;
2250    int verify_jit = 0;
2251  int yield = 0;  int yield = 0;
2252  int stack_size;  int stack_size;
2253    
2254    #if !defined NOPOSIX
2255    int posix = 0;
2256    #endif
2257    #if !defined NODFA
2258    int *dfa_workspace = NULL;
2259    #endif
2260    
2261  pcre_jit_stack *jit_stack = NULL;  pcre_jit_stack *jit_stack = NULL;
2262    
2263  /* These vectors store, end-to-end, a list of zero-terminated captured  /* These vectors store, end-to-end, a list of zero-terminated captured
# Line 2233  version = pcre16_version(); Line 2316  version = pcre16_version();
2316  while (argc > 1 && argv[op][0] == '-')  while (argc > 1 && argv[op][0] == '-')
2317    {    {
2318    pcre_uint8 *endptr;    pcre_uint8 *endptr;
2319      char *arg = argv[op];
2320    
2321    if (strcmp(argv[op], "-m") == 0) showstore = 1;    if (strcmp(arg, "-m") == 0) showstore = 1;
2322    else if (strcmp(argv[op], "-s") == 0) force_study = 0;    else if (strcmp(arg, "-s") == 0) force_study = 0;
2323    else if (strcmp(argv[op], "-s+") == 0)  
2324      else if (strncmp(arg, "-s+", 3) == 0)
2325      {      {
2326        arg += 3;
2327        if (*arg == '+') { arg++; verify_jit = TRUE; }
2328      force_study = 1;      force_study = 1;
2329      force_study_options = PCRE_STUDY_JIT_COMPILE;      if (*arg == 0)
2330          force_study_options = jit_study_bits[6];
2331        else if (*arg >= '1' && *arg <= '7')
2332          force_study_options = jit_study_bits[*arg - '1'];
2333        else goto BAD_ARG;
2334      }      }
2335    else if (strcmp(argv[op], "-16") == 0)    else if (strcmp(arg, "-16") == 0)
2336      {      {
2337  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2338      use_pcre16 = 1;      use_pcre16 = 1;
# Line 2250  while (argc > 1 && argv[op][0] == '-') Line 2341  while (argc > 1 && argv[op][0] == '-')
2341      exit(1);      exit(1);
2342  #endif  #endif
2343      }      }
2344    else if (strcmp(argv[op], "-q") == 0) quiet = 1;    else if (strcmp(arg, "-q") == 0) quiet = 1;
2345    else if (strcmp(argv[op], "-b") == 0) debug = 1;    else if (strcmp(arg, "-b") == 0) debug = 1;
2346    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;    else if (strcmp(arg, "-i") == 0) showinfo = 1;
2347    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;    else if (strcmp(arg, "-d") == 0) showinfo = debug = 1;
2348    else if (strcmp(argv[op], "-M") == 0) default_find_match_limit = TRUE;    else if (strcmp(arg, "-M") == 0) default_find_match_limit = TRUE;
2349  #if !defined NODFA  #if !defined NODFA
2350    else if (strcmp(argv[op], "-dfa") == 0) all_use_dfa = 1;    else if (strcmp(arg, "-dfa") == 0) all_use_dfa = 1;
2351  #endif  #endif
2352    else if (strcmp(argv[op], "-o") == 0 && argc > 2 &&    else if (strcmp(arg, "-o") == 0 && argc > 2 &&
2353        ((size_offsets = get_value((pcre_uint8 *)argv[op+1], &endptr)),        ((size_offsets = get_value((pcre_uint8 *)argv[op+1], &endptr)),
2354          *endptr == 0))          *endptr == 0))
2355      {      {
2356      op++;      op++;
2357      argc--;      argc--;
2358      }      }
2359    else if (strcmp(argv[op], "-t") == 0 || strcmp(argv[op], "-tm") == 0)    else if (strcmp(arg, "-t") == 0 || strcmp(arg, "-tm") == 0)
2360      {      {
2361      int both = argv[op][2] == 0;      int both = arg[2] == 0;
2362      int temp;      int temp;
2363      if (argc > 2 && (temp = get_value((pcre_uint8 *)argv[op+1], &endptr),      if (argc > 2 && (temp = get_value((pcre_uint8 *)argv[op+1], &endptr),
2364                       *endptr == 0))                       *endptr == 0))
# Line 2279  while (argc > 1 && argv[op][0] == '-') Line 2370  while (argc > 1 && argv[op][0] == '-')
2370      else timeitm = LOOPREPEAT;      else timeitm = LOOPREPEAT;
2371      if (both) timeit = timeitm;      if (both) timeit = timeitm;
2372      }      }
2373    else if (strcmp(argv[op], "-S") == 0 && argc > 2 &&    else if (strcmp(arg, "-S") == 0 && argc > 2 &&
2374        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),
2375          *endptr == 0))          *endptr == 0))
2376      {      {
2377  #if defined(_WIN32) || defined(WIN32) || defined(__minix)  #if defined(_WIN32) || defined(WIN32) || defined(__minix) || defined(NATIVE_ZOS)
2378      printf("PCRE: -S not supported on this OS\n");      printf("PCRE: -S not supported on this OS\n");
2379      exit(1);      exit(1);
2380  #else  #else
# Line 2302  while (argc > 1 && argv[op][0] == '-') Line 2393  while (argc > 1 && argv[op][0] == '-')
2393  #endif  #endif
2394      }      }
2395  #if !defined NOPOSIX  #if !defined NOPOSIX
2396    else if (strcmp(argv[op], "-p") == 0) posix = 1;    else if (strcmp(arg, "-p") == 0) posix = 1;
2397  #endif  #endif
2398    else if (strcmp(argv[op], "-C") == 0)    else if (strcmp(arg, "-C") == 0)
2399      {      {
2400      int rc;      int rc;
2401      unsigned long int lrc;      unsigned long int lrc;
# Line 2370  while (argc > 1 && argv[op][0] == '-') Line 2461  while (argc > 1 && argv[op][0] == '-')
2461        if (strcmp(argv[op + 1], "newline") == 0)        if (strcmp(argv[op + 1], "newline") == 0)
2462          {          {
2463          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);          (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
2464          /* Note that these values are always the ASCII values, even          print_newline_config(rc);
         in EBCDIC environments. CR is 13 and NL is 10. */  
         printf("%s\n", (rc == 13)? "CR" :  
           (rc == 10)? "LF" : (rc == (13<<8 | 10))? "CRLF" :  
           (rc == -2)? "ANYCRLF" :  
           (rc == -1)? "ANY" : "???");  
2465          goto EXIT;          goto EXIT;
2466          }          }
2467        printf("Unknown -C option: %s\n", argv[op + 1]);        printf("Unknown -C option: %s\n", argv[op + 1]);
# Line 2384  while (argc > 1 && argv[op][0] == '-') Line 2470  while (argc > 1 && argv[op][0] == '-')
2470    
2471      printf("PCRE version %s\n", version);      printf("PCRE version %s\n", version);
2472      printf("Compiled with\n");      printf("Compiled with\n");
2473    
2474    #ifdef EBCDIC
2475        printf("  EBCDIC code support: LF is 0x%02x\n", CHAR_LF);
2476    #endif
2477    
2478  /* 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
2479  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 2417  are set, either both UTFs are supported Line 2507  are set, either both UTFs are supported
2507      else      else
2508        printf("  No just-in-time compiler support\n");        printf("  No just-in-time compiler support\n");
2509      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
2510      /* Note that these values are always the ASCII values, even      print_newline_config(rc);
     in EBCDIC environments. CR is 13 and NL is 10. */  
     printf("  Newline sequence is %s\n", (rc == 13)? "CR" :  
       (rc == 10)? "LF" : (rc == (13<<8 | 10))? "CRLF" :  
       (rc == -2)? "ANYCRLF" :  
       (rc == -1)? "ANY" : "???");  
2511      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);
2512      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :
2513                                       "all Unicode newlines");                                       "all Unicode newlines");
# Line 2444  are set, either both UTFs are supported Line 2529  are set, either both UTFs are supported
2529      printf("\n");      printf("\n");
2530      goto EXIT;      goto EXIT;
2531      }      }
2532    else if (strcmp(argv[op], "-help") == 0 ||    else if (strcmp(arg, "-help") == 0 ||
2533             strcmp(argv[op], "--help") == 0)             strcmp(arg, "--help") == 0)
2534      {      {
2535      usage();      usage();
2536      goto EXIT;      goto EXIT;
2537      }      }
2538    else    else
2539      {      {
2540      printf("** Unknown or malformed option %s\n", argv[op]);      BAD_ARG:
2541        printf("** Unknown or malformed option %s\n", arg);
2542      usage();      usage();
2543      yield = 1;      yield = 1;
2544      goto EXIT;      goto EXIT;
# Line 2550  while (!done) Line 2636  while (!done)
2636    int do_flip = 0;    int do_flip = 0;
2637    int erroroffset, len, delimiter, poffset;    int erroroffset, len, delimiter, poffset;
2638    
2639    #if !defined NODFA
2640      int dfa_matched = 0;
2641    #endif
2642    
2643    use_utf = 0;    use_utf = 0;
2644    debug_lengths = 1;    debug_lengths = 1;
2645    
# Line 2597  while (!done) Line 2687  while (!done)
2687        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];
2688    
2689      re = (pcre *)new_malloc(true_size);      re = (pcre *)new_malloc(true_size);
2690        if (re == NULL)
2691          {
2692          printf("** Failed to get %d bytes of memory for pcre object\n",
2693            (int)true_size);
2694          yield = 1;
2695          goto EXIT;
2696          }
2697      regex_gotten_store = first_gotten_store;      regex_gotten_store = first_gotten_store;
2698    
2699      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;
# Line 2611  while (!done) Line 2708  while (!done)
2708        else        else
2709          {          {
2710          fprintf(outfile, "Data in %s is not a compiled PCRE regex\n", p);          fprintf(outfile, "Data in %s is not a compiled PCRE regex\n", p);
2711            new_free(re);
2712          fclose(f);          fclose(f);
2713          continue;          continue;
2714          }          }
# Line 2640  while (!done) Line 2738  while (!done)
2738            {            {
2739            PCRE_FREE_STUDY(extra);            PCRE_FREE_STUDY(extra);
2740            }            }
2741          if (re != NULL) new_free(re);          new_free(re);
2742          fclose(f);          fclose(f);
2743          continue;          continue;
2744          }          }
# Line 2661  while (!done) Line 2759  while (!done)
2759            use_pcre16? "16" : "", PCRE_INFO_OPTIONS);            use_pcre16? "16" : "", PCRE_INFO_OPTIONS);
2760          fprintf(outfile, "Running in %s-bit mode but pattern was compiled in "          fprintf(outfile, "Running in %s-bit mode but pattern was compiled in "
2761            "%s-bit mode\n", use_pcre16? "16":"8", use_pcre16? "8":"16");            "%s-bit mode\n", use_pcre16? "16":"8", use_pcre16? "8":"16");
2762            new_free(re);
2763            fclose(f);
2764          continue;          continue;
2765          }          }
2766        }        }
2767    
2768      /* Need to know if UTF-8 for printing data strings. */      /* Need to know if UTF-8 for printing data strings. */
2769    
2770      if (new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options) < 0) continue;      if (new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options) < 0)
2771          {
2772          new_free(re);
2773          fclose(f);
2774          continue;
2775          }
2776      use_utf = (get_options & PCRE_UTF8) != 0;      use_utf = (get_options & PCRE_UTF8) != 0;
2777    
2778      fclose(f);      fclose(f);
# Line 2726  while (!done) Line 2831  while (!done)
2831    /* Look for options after final delimiter */    /* Look for options after final delimiter */
2832    
2833    options = 0;    options = 0;
2834    study_options = 0;    study_options = force_study_options;
2835    log_store = showstore;  /* default from command line */    log_store = showstore;  /* default from command line */
2836    
2837    while (*pp != 0)    while (*pp != 0)
# Line 2763  while (!done) Line 2868  while (!done)
2868  #endif  #endif
2869    
2870        case 'S':        case 'S':
2871        if (do_study == 0)        do_study = 1;
2872          for (;;)
2873          {          {
2874          do_study = 1;          switch (*pp++)
         if (*pp == '+')  
2875            {            {
2876            study_options |= PCRE_STUDY_JIT_COMPILE;            case 'S':
2877            pp++;            do_study = 0;
2878              no_force_study = 1;
2879              break;
2880    
2881              case '!':
2882              study_options |= PCRE_STUDY_EXTRA_NEEDED;
2883              break;
2884    
2885              case '+':
2886              if (*pp == '+')
2887                {
2888                verify_jit = TRUE;
2889                pp++;
2890                }
2891              if (*pp >= '1' && *pp <= '7')
2892                study_options |= jit_study_bits[*pp++ - '1'];
2893              else
2894                study_options |= jit_study_bits[6];
2895              break;
2896    
2897              case '-':
2898              study_options &= ~PCRE_STUDY_ALLJIT;
2899              break;
2900    
2901              default:
2902              pp--;
2903              goto ENDLOOP;
2904            }            }
2905          }          }
2906        else        ENDLOOP:
         {  
         do_study = 0;  
         no_force_study = 1;  
         }  
2907        break;        break;
2908    
2909        case 'U': options |= PCRE_UNGREEDY; break;        case 'U': options |= PCRE_UNGREEDY; break;
# Line 3006  while (!done) Line 3133  while (!done)
3133          clock_t start_time = clock();          clock_t start_time = clock();
3134          for (i = 0; i < timeit; i++)          for (i = 0; i < timeit; i++)
3135            {            {
3136            PCRE_STUDY(extra, re, study_options | force_study_options, &error);            PCRE_STUDY(extra, re, study_options, &error);
3137            }            }
3138          time_taken = clock() - start_time;          time_taken = clock() - start_time;
3139          if (extra != NULL)          if (extra != NULL)
# Line 3017  while (!done) Line 3144  while (!done)
3144            (((double)time_taken * 1000.0) / (double)timeit) /            (((double)time_taken * 1000.0) / (double)timeit) /
3145              (double)CLOCKS_PER_SEC);              (double)CLOCKS_PER_SEC);
3146          }          }
3147        PCRE_STUDY(extra, re, study_options | force_study_options, &error);        PCRE_STUDY(extra, re, study_options, &error);
3148        if (error != NULL)        if (error != NULL)
3149          fprintf(outfile, "Failed to study: %s\n", error);          fprintf(outfile, "Failed to study: %s\n", error);
3150        else if (extra != NULL)        else if (extra != NULL)
# Line 3062  while (!done) Line 3189  while (!done)
3189        {        {
3190        unsigned long int all_options;        unsigned long int all_options;
3191        int count, backrefmax, first_char, need_char, okpartial, jchanged,        int count, backrefmax, first_char, need_char, okpartial, jchanged,
3192          hascrorlf;          hascrorlf, maxlookbehind;
3193        int nameentrysize, namecount;        int nameentrysize, namecount;
3194        const pcre_uint8 *nametable;        const pcre_uint8 *nametable;
3195    
# Line 3076  while (!done) Line 3203  while (!done)
3203            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +
3204            new_info(re, NULL, PCRE_INFO_OKPARTIAL, &okpartial) +            new_info(re, NULL, PCRE_INFO_OKPARTIAL, &okpartial) +
3205            new_info(re, NULL, PCRE_INFO_JCHANGED, &jchanged) +            new_info(re, NULL, PCRE_INFO_JCHANGED, &jchanged) +
3206            new_info(re, NULL, PCRE_INFO_HASCRORLF, &hascrorlf)            new_info(re, NULL, PCRE_INFO_HASCRORLF, &hascrorlf) +
3207              new_info(re, NULL, PCRE_INFO_MAXLOOKBEHIND, &maxlookbehind)
3208            != 0)            != 0)
3209          goto SKIP_DATA;          goto SKIP_DATA;
3210    
# Line 3216  while (!done) Line 3344  while (!done)
3344            }            }
3345          }          }
3346    
3347          if (maxlookbehind > 0)
3348            fprintf(outfile, "Max lookbehind = %d\n", maxlookbehind);
3349    
3350        /* Don't output study size; at present it is in any case a fixed        /* Don't output study size; at present it is in any case a fixed
3351        value, but it varies, depending on the computer architecture, and        value, but it varies, depending on the computer architecture, and
3352        so messes up the test suite. (And with the /F option, it might be        so messes up the test suite. (And with the /F option, it might be
# Line 3273  while (!done) Line 3404  while (!done)
3404    
3405          /* Show this only if the JIT was set by /S, not by -s. */          /* Show this only if the JIT was set by /S, not by -s. */
3406    
3407          if ((study_options & PCRE_STUDY_JIT_COMPILE) != 0)          if ((study_options & PCRE_STUDY_ALLJIT) != 0 &&
3408                (force_study_options & PCRE_STUDY_ALLJIT) == 0)
3409            {            {
3410            int jit;            int jit;
3411            if (new_info(re, extra, PCRE_INFO_JIT, &jit) == 0)            if (new_info(re, extra, PCRE_INFO_JIT, &jit) == 0)
# Line 3653  while (!done) Line 3785  while (!done)
3785            }            }
3786          use_size_offsets = n;          use_size_offsets = n;
3787          if (n == 0) use_offsets = NULL;   /* Ensures it can't write to it */          if (n == 0) use_offsets = NULL;   /* Ensures it can't write to it */
3788              else use_offsets = offsets + size_offsets_max - n;  /* To catch overruns */
3789          continue;          continue;
3790    
3791          case 'P':          case 'P':
# Line 3855  while (!done) Line 3988  while (!done)
3988        }        }
3989  #endif  #endif
3990    
3991        /* Ensure that there is a JIT callback if we want to verify that JIT was
3992        actually used. If jit_stack == NULL, no stack has yet been assigned. */
3993    
3994        if (verify_jit && jit_stack == NULL && extra != NULL)
3995           { PCRE_ASSIGN_JIT_STACK(extra, jit_callback, jit_stack); }
3996    
3997      for (;; gmatched++)    /* Loop for /g or /G */      for (;; gmatched++)    /* Loop for /g or /G */
3998        {        {
3999        markptr = NULL;        markptr = NULL;
4000          jit_was_used = FALSE;
4001    
4002        if (timeitm > 0)        if (timeitm > 0)
4003          {          {
# Line 3868  while (!done) Line 4008  while (!done)
4008  #if !defined NODFA  #if !defined NODFA
4009          if (all_use_dfa || use_dfa)          if (all_use_dfa || use_dfa)
4010            {            {
4011            int workspace[1000];            if ((options & PCRE_DFA_RESTART) != 0)
4012                {
4013                fprintf(outfile, "Timing DFA restarts is not supported\n");
4014                break;
4015                }
4016              if (dfa_workspace == NULL)
4017                dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
4018            for (i = 0; i < timeitm; i++)            for (i = 0; i < timeitm; i++)
4019              {              {
4020              PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,              PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
4021                (options | g_notempty), use_offsets, use_size_offsets, workspace,                (options | g_notempty), use_offsets, use_size_offsets,
4022                (sizeof(workspace)/sizeof(int)));                dfa_workspace, DFA_WS_DIMENSION);
4023              }              }
4024            }            }
4025          else          else
# Line 3899  while (!done) Line 4045  while (!done)
4045    
4046        if (find_match_limit)        if (find_match_limit)
4047          {          {
4048          if (extra == NULL)          if (extra != NULL) { PCRE_FREE_STUDY(extra); }
4049            {          extra = (pcre_extra *)malloc(sizeof(pcre_extra));
4050            extra = (pcre_extra *)malloc(sizeof(pcre_extra));          extra->flags = 0;
           extra->flags = 0;  
           }  
         else extra->flags &= ~PCRE_EXTRA_EXECUTABLE_JIT;  
4051    
4052          (void)check_match_limit(re, extra, bptr, len, start_offset,          (void)check_match_limit(re, extra, bptr, len, start_offset,
4053            options|g_notempty, use_offsets, use_size_offsets,            options|g_notempty, use_offsets, use_size_offsets,
# Line 3939  while (!done) Line 4082  while (!done)
4082  #if !defined NODFA  #if !defined NODFA
4083        else if (all_use_dfa || use_dfa)        else if (all_use_dfa || use_dfa)
4084          {          {
4085          int workspace[1000];          if (dfa_workspace == NULL)
4086              dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
4087            if (dfa_matched++ == 0)
4088              dfa_workspace[0] = -1;  /* To catch bad restart */
4089          PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,          PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
4090            (options | g_notempty), use_offsets, use_size_offsets, workspace,            (options | g_notempty), use_offsets, use_size_offsets, dfa_workspace,
4091            (sizeof(workspace)/sizeof(int)));            DFA_WS_DIMENSION);
4092          if (count == 0)          if (count == 0)
4093            {            {
4094            fprintf(outfile, "Matched, but too many subsidiary matches\n");            fprintf(outfile, "Matched, but too many subsidiary matches\n");
# Line 4019  while (!done) Line 4165  while (!done)
4165              fprintf(outfile, "%2d: ", i/2);              fprintf(outfile, "%2d: ", i/2);
4166              PCHARSV(bptr, use_offsets[i],              PCHARSV(bptr, use_offsets[i],
4167                use_offsets[i+1] - use_offsets[i], outfile);                use_offsets[i+1] - use_offsets[i], outfile);
4168                if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
4169              fprintf(outfile, "\n");              fprintf(outfile, "\n");
4170              if (do_showcaprest || (i == 0 && do_showrest))              if (do_showcaprest || (i == 0 && do_showrest))
4171                {                {
# Line 4185  while (!done) Line 4332  while (!done)
4332            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],
4333              outfile);              outfile);
4334            }            }
4335            if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
4336          fprintf(outfile, "\n");          fprintf(outfile, "\n");
4337          break;  /* Out of the /g loop */          break;  /* Out of the /g loop */
4338          }          }
# Line 4264  while (!done) Line 4412  while (!done)
4412                {                {
4413                if (markptr == NULL)                if (markptr == NULL)
4414                  {                  {
4415                  fprintf(outfile, "No match\n");                  fprintf(outfile, "No match");
4416                  }                  }
4417                else                else
4418                  {                  {
4419                  fprintf(outfile, "No match, mark = ");                  fprintf(outfile, "No match, mark = ");
4420                  PCHARSV(markptr, 0, -1, outfile);                  PCHARSV(markptr, 0, -1, outfile);
                 putc('\n', outfile);  
4421                  }                  }
4422                  if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
4423                  putc('\n', outfile);
4424                }                }
4425              break;              break;
4426    
# Line 4292  while (!done) Line 4441  while (!done)
4441              break;              break;
4442    
4443              default:              default:
4444              if (count < 0 &&              if (count < 0 &&
4445                  (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))                  (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))
4446                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);
4447              else              else
# Line 4379  free(offsets); Line 4528  free(offsets);
4528  if (buffer16 != NULL) free(buffer16);  if (buffer16 != NULL) free(buffer16);
4529  #endif  #endif
4530    
4531    #if !defined NODFA
4532    if (dfa_workspace != NULL)
4533      free(dfa_workspace);
4534    #endif
4535    
4536  return yield;  return yield;
4537  }  }
4538    

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

  ViewVC Help
Powered by ViewVC 1.1.5