/[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 929 by zherczeg, Fri Feb 24 11:07:47 2012 UTC
# Line 613  static int callout_fail_count; Line 613  static int callout_fail_count;
613  static int callout_fail_id;  static int callout_fail_id;
614  static int debug_lengths;  static int debug_lengths;
615  static int first_callout;  static int first_callout;
616    static int jit_was_used;
617  static int locale_set = 0;  static int locale_set = 0;
618  static int show_malloc;  static int show_malloc;
619  static int use_utf;  static int use_utf;
# Line 674  static int use_pcre16 = 0; Line 675  static int use_pcre16 = 0;
675  static int use_pcre16 = 1;  static int use_pcre16 = 1;
676  #endif  #endif
677    
678    /* JIT study options for -s+n and /S+n where '1' <= n <= '7'. */
679    
680    static int jit_study_bits[] =
681      {
682      PCRE_STUDY_JIT_COMPILE,
683      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE,
684      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE,
685      PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
686      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
687      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE + PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
688      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE +
689        PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE
690    };
691    
692  /* Textual explanations for runtime error codes */  /* Textual explanations for runtime error codes */
693    
694  static const char *errtexts[] = {  static const char *errtexts[] = {
# Line 1063  return sys_errlist[n]; Line 1078  return sys_errlist[n];
1078    
1079  static pcre_jit_stack* jit_callback(void *arg)  static pcre_jit_stack* jit_callback(void *arg)
1080  {  {
1081    jit_was_used = TRUE;
1082  return (pcre_jit_stack *)arg;  return (pcre_jit_stack *)arg;
1083  }  }
1084    
# Line 2132  printf("  -q       quiet: do not output Line 2148  printf("  -q       quiet: do not output
2148  printf("  -S <n>   set stack size to <n> megabytes\n");  printf("  -S <n>   set stack size to <n> megabytes\n");
2149  printf("  -s       force each pattern to be studied at basic level\n"  printf("  -s       force each pattern to be studied at basic level\n"
2150         "  -s+      force each pattern to be studied, using JIT if available\n"         "  -s+      force each pattern to be studied, using JIT if available\n"
2151           "  -s++     ditto, verifying when JIT was actually used\n"
2152           "  -s+n     force each pattern to be studied, using JIT if available,\n"
2153           "             where 1 <= n <= 7 selects JIT options\n"
2154           "  -s++n    ditto, verifying when JIT was actually used\n"
2155         "  -t       time compilation and execution\n");         "  -t       time compilation and execution\n");
2156  printf("  -t <n>   time compilation and execution, repeating <n> times\n");  printf("  -t <n>   time compilation and execution, repeating <n> times\n");
2157  printf("  -tm      time execution (matching) only\n");  printf("  -tm      time execution (matching) only\n");
# Line 2172  int posix = 0; Line 2192  int posix = 0;
2192  int debug = 0;  int debug = 0;
2193  int done = 0;  int done = 0;
2194  int all_use_dfa = 0;  int all_use_dfa = 0;
2195    int verify_jit = 0;
2196  int yield = 0;  int yield = 0;
2197  int stack_size;  int stack_size;
2198    
# Line 2233  version = pcre16_version(); Line 2254  version = pcre16_version();
2254  while (argc > 1 && argv[op][0] == '-')  while (argc > 1 && argv[op][0] == '-')
2255    {    {
2256    pcre_uint8 *endptr;    pcre_uint8 *endptr;
2257      char *arg = argv[op];
2258    
2259    if (strcmp(argv[op], "-m") == 0) showstore = 1;    if (strcmp(arg, "-m") == 0) showstore = 1;
2260    else if (strcmp(argv[op], "-s") == 0) force_study = 0;    else if (strcmp(arg, "-s") == 0) force_study = 0;
2261    else if (strcmp(argv[op], "-s+") == 0)  
2262      else if (strncmp(arg, "-s+", 3) == 0)
2263      {      {
2264        arg += 3;
2265        if (*arg == '+') { arg++; verify_jit = TRUE; }
2266      force_study = 1;      force_study = 1;
2267      force_study_options = PCRE_STUDY_JIT_COMPILE;      if (*arg == 0)
2268          force_study_options = jit_study_bits[6];
2269        else if (*arg >= '1' && *arg <= '7')
2270          force_study_options = jit_study_bits[*arg - '1'];
2271        else goto BAD_ARG;
2272      }      }
2273    else if (strcmp(argv[op], "-16") == 0)    else if (strcmp(arg, "-16") == 0)
2274      {      {
2275  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2276      use_pcre16 = 1;      use_pcre16 = 1;
# Line 2250  while (argc > 1 && argv[op][0] == '-') Line 2279  while (argc > 1 && argv[op][0] == '-')
2279      exit(1);      exit(1);
2280  #endif  #endif
2281      }      }
2282    else if (strcmp(argv[op], "-q") == 0) quiet = 1;    else if (strcmp(arg, "-q") == 0) quiet = 1;
2283    else if (strcmp(argv[op], "-b") == 0) debug = 1;    else if (strcmp(arg, "-b") == 0) debug = 1;
2284    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;    else if (strcmp(arg, "-i") == 0) showinfo = 1;
2285    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;    else if (strcmp(arg, "-d") == 0) showinfo = debug = 1;
2286    else if (strcmp(argv[op], "-M") == 0) default_find_match_limit = TRUE;    else if (strcmp(arg, "-M") == 0) default_find_match_limit = TRUE;
2287  #if !defined NODFA  #if !defined NODFA
2288    else if (strcmp(argv[op], "-dfa") == 0) all_use_dfa = 1;    else if (strcmp(arg, "-dfa") == 0) all_use_dfa = 1;
2289  #endif  #endif
2290    else if (strcmp(argv[op], "-o") == 0 && argc > 2 &&    else if (strcmp(arg, "-o") == 0 && argc > 2 &&
2291        ((size_offsets = get_value((pcre_uint8 *)argv[op+1], &endptr)),        ((size_offsets = get_value((pcre_uint8 *)argv[op+1], &endptr)),
2292          *endptr == 0))          *endptr == 0))
2293      {      {
2294      op++;      op++;
2295      argc--;      argc--;
2296      }      }
2297    else if (strcmp(argv[op], "-t") == 0 || strcmp(argv[op], "-tm") == 0)    else if (strcmp(arg, "-t") == 0 || strcmp(arg, "-tm") == 0)
2298      {      {
2299      int both = argv[op][2] == 0;      int both = arg[2] == 0;
2300      int temp;      int temp;
2301      if (argc > 2 && (temp = get_value((pcre_uint8 *)argv[op+1], &endptr),      if (argc > 2 && (temp = get_value((pcre_uint8 *)argv[op+1], &endptr),
2302                       *endptr == 0))                       *endptr == 0))
# Line 2279  while (argc > 1 && argv[op][0] == '-') Line 2308  while (argc > 1 && argv[op][0] == '-')
2308      else timeitm = LOOPREPEAT;      else timeitm = LOOPREPEAT;
2309      if (both) timeit = timeitm;      if (both) timeit = timeitm;
2310      }      }
2311    else if (strcmp(argv[op], "-S") == 0 && argc > 2 &&    else if (strcmp(arg, "-S") == 0 && argc > 2 &&
2312        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),
2313          *endptr == 0))          *endptr == 0))
2314      {      {
# Line 2302  while (argc > 1 && argv[op][0] == '-') Line 2331  while (argc > 1 && argv[op][0] == '-')
2331  #endif  #endif
2332      }      }
2333  #if !defined NOPOSIX  #if !defined NOPOSIX
2334    else if (strcmp(argv[op], "-p") == 0) posix = 1;    else if (strcmp(arg, "-p") == 0) posix = 1;
2335  #endif  #endif
2336    else if (strcmp(argv[op], "-C") == 0)    else if (strcmp(arg, "-C") == 0)
2337      {      {
2338      int rc;      int rc;
2339      unsigned long int lrc;      unsigned long int lrc;
# Line 2444  are set, either both UTFs are supported Line 2473  are set, either both UTFs are supported
2473      printf("\n");      printf("\n");
2474      goto EXIT;      goto EXIT;
2475      }      }
2476    else if (strcmp(argv[op], "-help") == 0 ||    else if (strcmp(arg, "-help") == 0 ||
2477             strcmp(argv[op], "--help") == 0)             strcmp(arg, "--help") == 0)
2478      {      {
2479      usage();      usage();
2480      goto EXIT;      goto EXIT;
2481      }      }
2482    else    else
2483      {      {
2484      printf("** Unknown or malformed option %s\n", argv[op]);      BAD_ARG:
2485        printf("** Unknown or malformed option %s\n", arg);
2486      usage();      usage();
2487      yield = 1;      yield = 1;
2488      goto EXIT;      goto EXIT;
# Line 2768  while (!done) Line 2798  while (!done)
2798          do_study = 1;          do_study = 1;
2799          if (*pp == '+')          if (*pp == '+')
2800            {            {
2801            study_options |= PCRE_STUDY_JIT_COMPILE;            if (*(++pp) == '+')
2802            pp++;              {
2803                verify_jit = TRUE;
2804                pp++;
2805                }
2806              if (*pp >= '1' && *pp <= '7')
2807                study_options |= jit_study_bits[*pp++ - '1'];
2808              else
2809                study_options |= jit_study_bits[6];
2810            }            }
2811          }          }
2812        else        else
# Line 3855  while (!done) Line 3892  while (!done)
3892        }        }
3893  #endif  #endif
3894    
3895        /* Ensure that there is a JIT callback if we want to verify that JIT was
3896        actually used. If jit_stack == NULL, no stack has yet been assigned. */
3897    
3898        if (verify_jit && jit_stack == NULL && extra != NULL)
3899           { PCRE_ASSIGN_JIT_STACK(extra, jit_callback, jit_stack); }
3900    
3901      for (;; gmatched++)    /* Loop for /g or /G */      for (;; gmatched++)    /* Loop for /g or /G */
3902        {        {
3903        markptr = NULL;        markptr = NULL;
3904          jit_was_used = FALSE;
3905    
3906        if (timeitm > 0)        if (timeitm > 0)
3907          {          {
# Line 3961  while (!done) Line 4005  while (!done)
4005            count = use_size_offsets/3;            count = use_size_offsets/3;
4006            }            }
4007          }          }
4008    
4009        /* Matched */        /* Matched */
4010    
4011        if (count >= 0)        if (count >= 0)
# Line 4019  while (!done) Line 4063  while (!done)
4063              fprintf(outfile, "%2d: ", i/2);              fprintf(outfile, "%2d: ", i/2);
4064              PCHARSV(bptr, use_offsets[i],              PCHARSV(bptr, use_offsets[i],
4065                use_offsets[i+1] - use_offsets[i], outfile);                use_offsets[i+1] - use_offsets[i], outfile);
4066                if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
4067              fprintf(outfile, "\n");              fprintf(outfile, "\n");
4068              if (do_showcaprest || (i == 0 && do_showrest))              if (do_showcaprest || (i == 0 && do_showrest))
4069                {                {
# Line 4185  while (!done) Line 4230  while (!done)
4230            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],
4231              outfile);              outfile);
4232            }            }
4233            if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
4234          fprintf(outfile, "\n");          fprintf(outfile, "\n");
4235          break;  /* Out of the /g loop */          break;  /* Out of the /g loop */
4236          }          }
# Line 4264  while (!done) Line 4310  while (!done)
4310                {                {
4311                if (markptr == NULL)                if (markptr == NULL)
4312                  {                  {
4313                  fprintf(outfile, "No match\n");                  fprintf(outfile, "No match");
4314                  }                  }
4315                else                else
4316                  {                  {
4317                  fprintf(outfile, "No match, mark = ");                  fprintf(outfile, "No match, mark = ");
4318                  PCHARSV(markptr, 0, -1, outfile);                  PCHARSV(markptr, 0, -1, outfile);
                 putc('\n', outfile);  
4319                  }                  }
4320                  if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
4321                  putc('\n', outfile);
4322                }                }
4323              break;              break;
4324    
# Line 4292  while (!done) Line 4339  while (!done)
4339              break;              break;
4340    
4341              default:              default:
4342              if (count < 0 &&              if (count < 0 &&
4343                  (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))                  (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))
4344                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);
4345              else              else

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

  ViewVC Help
Powered by ViewVC 1.1.5