/[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 963 by ph10, Sat Apr 21 18:06:31 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 599  version is called. ----- */ Line 610  version is called. ----- */
610  #endif  #endif
611  #endif  #endif
612    
613    #if !defined NODFA
614    #define DFA_WS_DIMENSION 1000
615    #endif
616    
617  /* This is the default loop count for timing. */  /* This is the default loop count for timing. */
618    
619  #define LOOPREPEAT 500000  #define LOOPREPEAT 500000
# Line 613  static int callout_fail_count; Line 628  static int callout_fail_count;
628  static int callout_fail_id;  static int callout_fail_id;
629  static int debug_lengths;  static int debug_lengths;
630  static int first_callout;  static int first_callout;
631    static int jit_was_used;
632  static int locale_set = 0;  static int locale_set = 0;
633  static int show_malloc;  static int show_malloc;
634  static int use_utf;  static int use_utf;
# Line 674  static int use_pcre16 = 0; Line 690  static int use_pcre16 = 0;
690  static int use_pcre16 = 1;  static int use_pcre16 = 1;
691  #endif  #endif
692    
693    /* JIT study options for -s+n and /S+n where '1' <= n <= '7'. */
694    
695    static int jit_study_bits[] =
696      {
697      PCRE_STUDY_JIT_COMPILE,
698      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE,
699      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE,
700      PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
701      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
702      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE + PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
703      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE +
704        PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE
705    };
706    
707  /* Textual explanations for runtime error codes */  /* Textual explanations for runtime error codes */
708    
709  static const char *errtexts[] = {  static const char *errtexts[] = {
# Line 705  static const char *errtexts[] = { Line 735  static const char *errtexts[] = {
735    NULL,  /* SHORTUTF8/16 is handled specially */    NULL,  /* SHORTUTF8/16 is handled specially */
736    "nested recursion at the same subject position",    "nested recursion at the same subject position",
737    "JIT stack limit reached",    "JIT stack limit reached",
738    "pattern compiled in wrong mode: 8-bit/16-bit error"    "pattern compiled in wrong mode: 8-bit/16-bit error",
739      "pattern compiled with other endianness",
740      "invalid data in workspace for DFA restart"
741  };  };
742    
743    
# Line 1063  return sys_errlist[n]; Line 1095  return sys_errlist[n];
1095    
1096  static pcre_jit_stack* jit_callback(void *arg)  static pcre_jit_stack* jit_callback(void *arg)
1097  {  {
1098    jit_was_used = TRUE;
1099  return (pcre_jit_stack *)arg;  return (pcre_jit_stack *)arg;
1100  }  }
1101    
# Line 1276  for (;;) Line 1309  for (;;)
1309      {      {
1310      int dlen;      int dlen;
1311    
1312      /* 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
1313      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
1314      we must put it back again, to be compatible with fgets(). */      newline, so we must put it back again, to be compatible with fgets(). */
1315    
1316  #ifdef SUPPORT_LIBREADLINE  #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
1317      if (isatty(fileno(f)))      if (isatty(fileno(f)))
1318        {        {
1319        size_t len;        size_t len;
# Line 2096  usage(void) Line 2129  usage(void)
2129  {  {
2130  printf("Usage:     pcretest [options] [<input file> [<output file>]]\n\n");  printf("Usage:     pcretest [options] [<input file> [<output file>]]\n\n");
2131  printf("Input and output default to stdin and stdout.\n");  printf("Input and output default to stdin and stdout.\n");
2132  #ifdef SUPPORT_LIBREADLINE  #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
2133  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");
2134  #else  #else
2135  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 2165  printf("  -q       quiet: do not output
2165  printf("  -S <n>   set stack size to <n> megabytes\n");  printf("  -S <n>   set stack size to <n> megabytes\n");
2166  printf("  -s       force each pattern to be studied at basic level\n"  printf("  -s       force each pattern to be studied at basic level\n"
2167         "  -s+      force each pattern to be studied, using JIT if available\n"         "  -s+      force each pattern to be studied, using JIT if available\n"
2168           "  -s++     ditto, verifying when JIT was actually used\n"
2169           "  -s+n     force each pattern to be studied, using JIT if available,\n"
2170           "             where 1 <= n <= 7 selects JIT options\n"
2171           "  -s++n    ditto, verifying when JIT was actually used\n"
2172         "  -t       time compilation and execution\n");         "  -t       time compilation and execution\n");
2173  printf("  -t <n>   time compilation and execution, repeating <n> times\n");  printf("  -t <n>   time compilation and execution, repeating <n> times\n");
2174  printf("  -tm      time execution (matching) only\n");  printf("  -tm      time execution (matching) only\n");
# Line 2166  int quiet = 0; Line 2203  int quiet = 0;
2203  int size_offsets = 45;  int size_offsets = 45;
2204  int size_offsets_max;  int size_offsets_max;
2205  int *offsets = NULL;  int *offsets = NULL;
 #if !defined NOPOSIX  
 int posix = 0;  
 #endif  
2206  int debug = 0;  int debug = 0;
2207  int done = 0;  int done = 0;
2208  int all_use_dfa = 0;  int all_use_dfa = 0;
2209    int verify_jit = 0;
2210  int yield = 0;  int yield = 0;
2211  int stack_size;  int stack_size;
2212    
2213    #if !defined NOPOSIX
2214    int posix = 0;
2215    #endif
2216    #if !defined NODFA
2217    int *dfa_workspace = NULL;
2218    #endif
2219    
2220  pcre_jit_stack *jit_stack = NULL;  pcre_jit_stack *jit_stack = NULL;
2221    
2222  /* 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 2275  version = pcre16_version();
2275  while (argc > 1 && argv[op][0] == '-')  while (argc > 1 && argv[op][0] == '-')
2276    {    {
2277    pcre_uint8 *endptr;    pcre_uint8 *endptr;
2278      char *arg = argv[op];
2279    
2280    if (strcmp(argv[op], "-m") == 0) showstore = 1;    if (strcmp(arg, "-m") == 0) showstore = 1;
2281    else if (strcmp(argv[op], "-s") == 0) force_study = 0;    else if (strcmp(arg, "-s") == 0) force_study = 0;
2282    else if (strcmp(argv[op], "-s+") == 0)  
2283      else if (strncmp(arg, "-s+", 3) == 0)
2284      {      {
2285        arg += 3;
2286        if (*arg == '+') { arg++; verify_jit = TRUE; }
2287      force_study = 1;      force_study = 1;
2288      force_study_options = PCRE_STUDY_JIT_COMPILE;      if (*arg == 0)
2289          force_study_options = jit_study_bits[6];
2290        else if (*arg >= '1' && *arg <= '7')
2291          force_study_options = jit_study_bits[*arg - '1'];
2292        else goto BAD_ARG;
2293      }      }
2294    else if (strcmp(argv[op], "-16") == 0)    else if (strcmp(arg, "-16") == 0)
2295      {      {
2296  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2297      use_pcre16 = 1;      use_pcre16 = 1;
# Line 2250  while (argc > 1 && argv[op][0] == '-') Line 2300  while (argc > 1 && argv[op][0] == '-')
2300      exit(1);      exit(1);
2301  #endif  #endif
2302      }      }
2303    else if (strcmp(argv[op], "-q") == 0) quiet = 1;    else if (strcmp(arg, "-q") == 0) quiet = 1;
2304    else if (strcmp(argv[op], "-b") == 0) debug = 1;    else if (strcmp(arg, "-b") == 0) debug = 1;
2305    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;    else if (strcmp(arg, "-i") == 0) showinfo = 1;
2306    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;    else if (strcmp(arg, "-d") == 0) showinfo = debug = 1;
2307    else if (strcmp(argv[op], "-M") == 0) default_find_match_limit = TRUE;    else if (strcmp(arg, "-M") == 0) default_find_match_limit = TRUE;
2308  #if !defined NODFA  #if !defined NODFA
2309    else if (strcmp(argv[op], "-dfa") == 0) all_use_dfa = 1;    else if (strcmp(arg, "-dfa") == 0) all_use_dfa = 1;
2310  #endif  #endif
2311    else if (strcmp(argv[op], "-o") == 0 && argc > 2 &&    else if (strcmp(arg, "-o") == 0 && argc > 2 &&
2312        ((size_offsets = get_value((pcre_uint8 *)argv[op+1], &endptr)),        ((size_offsets = get_value((pcre_uint8 *)argv[op+1], &endptr)),
2313          *endptr == 0))          *endptr == 0))
2314      {      {
2315      op++;      op++;
2316      argc--;      argc--;
2317      }      }
2318    else if (strcmp(argv[op], "-t") == 0 || strcmp(argv[op], "-tm") == 0)    else if (strcmp(arg, "-t") == 0 || strcmp(arg, "-tm") == 0)
2319      {      {
2320      int both = argv[op][2] == 0;      int both = arg[2] == 0;
2321      int temp;      int temp;
2322      if (argc > 2 && (temp = get_value((pcre_uint8 *)argv[op+1], &endptr),      if (argc > 2 && (temp = get_value((pcre_uint8 *)argv[op+1], &endptr),
2323                       *endptr == 0))                       *endptr == 0))
# Line 2279  while (argc > 1 && argv[op][0] == '-') Line 2329  while (argc > 1 && argv[op][0] == '-')
2329      else timeitm = LOOPREPEAT;      else timeitm = LOOPREPEAT;
2330      if (both) timeit = timeitm;      if (both) timeit = timeitm;
2331      }      }
2332    else if (strcmp(argv[op], "-S") == 0 && argc > 2 &&    else if (strcmp(arg, "-S") == 0 && argc > 2 &&
2333        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),
2334          *endptr == 0))          *endptr == 0))
2335      {      {
# Line 2302  while (argc > 1 && argv[op][0] == '-') Line 2352  while (argc > 1 && argv[op][0] == '-')
2352  #endif  #endif
2353      }      }
2354  #if !defined NOPOSIX  #if !defined NOPOSIX
2355    else if (strcmp(argv[op], "-p") == 0) posix = 1;    else if (strcmp(arg, "-p") == 0) posix = 1;
2356  #endif  #endif
2357    else if (strcmp(argv[op], "-C") == 0)    else if (strcmp(arg, "-C") == 0)
2358      {      {
2359      int rc;      int rc;
2360      unsigned long int lrc;      unsigned long int lrc;
# Line 2444  are set, either both UTFs are supported Line 2494  are set, either both UTFs are supported
2494      printf("\n");      printf("\n");
2495      goto EXIT;      goto EXIT;
2496      }      }
2497    else if (strcmp(argv[op], "-help") == 0 ||    else if (strcmp(arg, "-help") == 0 ||
2498             strcmp(argv[op], "--help") == 0)             strcmp(arg, "--help") == 0)
2499      {      {
2500      usage();      usage();
2501      goto EXIT;      goto EXIT;
2502      }      }
2503    else    else
2504      {      {
2505      printf("** Unknown or malformed option %s\n", argv[op]);      BAD_ARG:
2506        printf("** Unknown or malformed option %s\n", arg);
2507      usage();      usage();
2508      yield = 1;      yield = 1;
2509      goto EXIT;      goto EXIT;
# Line 2549  while (!done) Line 2600  while (!done)
2600    int do_showcaprest = 0;    int do_showcaprest = 0;
2601    int do_flip = 0;    int do_flip = 0;
2602    int erroroffset, len, delimiter, poffset;    int erroroffset, len, delimiter, poffset;
2603    
2604    #if !defined NODFA
2605      int dfa_matched = 0;
2606    #endif
2607    
2608    use_utf = 0;    use_utf = 0;
2609    debug_lengths = 1;    debug_lengths = 1;
# Line 2768  while (!done) Line 2823  while (!done)
2823          do_study = 1;          do_study = 1;
2824          if (*pp == '+')          if (*pp == '+')
2825            {            {
2826            study_options |= PCRE_STUDY_JIT_COMPILE;            if (*(++pp) == '+')
2827            pp++;              {
2828                verify_jit = TRUE;
2829                pp++;
2830                }
2831              if (*pp >= '1' && *pp <= '7')
2832                study_options |= jit_study_bits[*pp++ - '1'];
2833              else
2834                study_options |= jit_study_bits[6];
2835            }            }
2836          }          }
2837        else        else
# Line 3062  while (!done) Line 3124  while (!done)
3124        {        {
3125        unsigned long int all_options;        unsigned long int all_options;
3126        int count, backrefmax, first_char, need_char, okpartial, jchanged,        int count, backrefmax, first_char, need_char, okpartial, jchanged,
3127          hascrorlf;          hascrorlf, maxlookbehind;
3128        int nameentrysize, namecount;        int nameentrysize, namecount;
3129        const pcre_uint8 *nametable;        const pcre_uint8 *nametable;
3130    
# Line 3076  while (!done) Line 3138  while (!done)
3138            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +            new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +
3139            new_info(re, NULL, PCRE_INFO_OKPARTIAL, &okpartial) +            new_info(re, NULL, PCRE_INFO_OKPARTIAL, &okpartial) +
3140            new_info(re, NULL, PCRE_INFO_JCHANGED, &jchanged) +            new_info(re, NULL, PCRE_INFO_JCHANGED, &jchanged) +
3141            new_info(re, NULL, PCRE_INFO_HASCRORLF, &hascrorlf)            new_info(re, NULL, PCRE_INFO_HASCRORLF, &hascrorlf) +
3142              new_info(re, NULL, PCRE_INFO_MAXLOOKBEHIND, &maxlookbehind)
3143            != 0)            != 0)
3144          goto SKIP_DATA;          goto SKIP_DATA;
3145    
# Line 3216  while (!done) Line 3279  while (!done)
3279            }            }
3280          }          }
3281    
3282          if (maxlookbehind > 0)
3283            fprintf(outfile, "Max lookbehind = %d\n", maxlookbehind);
3284    
3285        /* 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
3286        value, but it varies, depending on the computer architecture, and        value, but it varies, depending on the computer architecture, and
3287        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 3653  while (!done) Line 3719  while (!done)
3719            }            }
3720          use_size_offsets = n;          use_size_offsets = n;
3721          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 */
3722              else use_offsets = offsets + size_offsets_max - n;  /* To catch overruns */
3723          continue;          continue;
3724    
3725          case 'P':          case 'P':
# Line 3855  while (!done) Line 3922  while (!done)
3922        }        }
3923  #endif  #endif
3924    
3925        /* Ensure that there is a JIT callback if we want to verify that JIT was
3926        actually used. If jit_stack == NULL, no stack has yet been assigned. */
3927    
3928        if (verify_jit && jit_stack == NULL && extra != NULL)
3929           { PCRE_ASSIGN_JIT_STACK(extra, jit_callback, jit_stack); }
3930    
3931      for (;; gmatched++)    /* Loop for /g or /G */      for (;; gmatched++)    /* Loop for /g or /G */
3932        {        {
3933        markptr = NULL;        markptr = NULL;
3934          jit_was_used = FALSE;
3935    
3936        if (timeitm > 0)        if (timeitm > 0)
3937          {          {
# Line 3868  while (!done) Line 3942  while (!done)
3942  #if !defined NODFA  #if !defined NODFA
3943          if (all_use_dfa || use_dfa)          if (all_use_dfa || use_dfa)
3944            {            {
3945            int workspace[1000];            if ((options & PCRE_DFA_RESTART) != 0)
3946                {
3947                fprintf(outfile, "Timing DFA restarts is not supported\n");
3948                break;
3949                }
3950              if (dfa_workspace == NULL)
3951                dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
3952            for (i = 0; i < timeitm; i++)            for (i = 0; i < timeitm; i++)
3953              {              {
3954              PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,              PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
3955                (options | g_notempty), use_offsets, use_size_offsets, workspace,                (options | g_notempty), use_offsets, use_size_offsets,
3956                (sizeof(workspace)/sizeof(int)));                dfa_workspace, DFA_WS_DIMENSION);
3957              }              }
3958            }            }
3959          else          else
# Line 3939  while (!done) Line 4019  while (!done)
4019  #if !defined NODFA  #if !defined NODFA
4020        else if (all_use_dfa || use_dfa)        else if (all_use_dfa || use_dfa)
4021          {          {
4022          int workspace[1000];          if (dfa_workspace == NULL)
4023              dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
4024            if (dfa_matched++ == 0)
4025              dfa_workspace[0] = -1;  /* To catch bad restart */
4026          PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,          PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
4027            (options | g_notempty), use_offsets, use_size_offsets, workspace,            (options | g_notempty), use_offsets, use_size_offsets, dfa_workspace,
4028            (sizeof(workspace)/sizeof(int)));            DFA_WS_DIMENSION);
4029          if (count == 0)          if (count == 0)
4030            {            {
4031            fprintf(outfile, "Matched, but too many subsidiary matches\n");            fprintf(outfile, "Matched, but too many subsidiary matches\n");
# Line 4019  while (!done) Line 4102  while (!done)
4102              fprintf(outfile, "%2d: ", i/2);              fprintf(outfile, "%2d: ", i/2);
4103              PCHARSV(bptr, use_offsets[i],              PCHARSV(bptr, use_offsets[i],
4104                use_offsets[i+1] - use_offsets[i], outfile);                use_offsets[i+1] - use_offsets[i], outfile);
4105                if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
4106              fprintf(outfile, "\n");              fprintf(outfile, "\n");
4107              if (do_showcaprest || (i == 0 && do_showrest))              if (do_showcaprest || (i == 0 && do_showrest))
4108                {                {
# Line 4185  while (!done) Line 4269  while (!done)
4269            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],            PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],
4270              outfile);              outfile);
4271            }            }
4272            if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
4273          fprintf(outfile, "\n");          fprintf(outfile, "\n");
4274          break;  /* Out of the /g loop */          break;  /* Out of the /g loop */
4275          }          }
# Line 4264  while (!done) Line 4349  while (!done)
4349                {                {
4350                if (markptr == NULL)                if (markptr == NULL)
4351                  {                  {
4352                  fprintf(outfile, "No match\n");                  fprintf(outfile, "No match");
4353                  }                  }
4354                else                else
4355                  {                  {
4356                  fprintf(outfile, "No match, mark = ");                  fprintf(outfile, "No match, mark = ");
4357                  PCHARSV(markptr, 0, -1, outfile);                  PCHARSV(markptr, 0, -1, outfile);
                 putc('\n', outfile);  
4358                  }                  }
4359                  if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
4360                  putc('\n', outfile);
4361                }                }
4362              break;              break;
4363    
# Line 4292  while (!done) Line 4378  while (!done)
4378              break;              break;
4379    
4380              default:              default:
4381              if (count < 0 &&              if (count < 0 &&
4382                  (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))                  (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))
4383                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);
4384              else              else

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

  ViewVC Help
Powered by ViewVC 1.1.5