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

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

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

revision 579 by ph10, Wed Nov 24 17:39:25 2010 UTC revision 658 by ph10, Mon Aug 15 17:43:44 2011 UTC
# Line 79  input mode under Windows. */ Line 79  input mode under Windows. */
79  #define fileno _fileno  #define fileno _fileno
80  #endif  #endif
81    
82    /* A user sent this fix for Borland Builder 5 under Windows. */
83    
84    #ifdef __BORLANDC__
85    #define _setmode(handle, mode) setmode(handle, mode)
86    #endif
87    
88    /* Not Windows */
89    
90  #else  #else
91  #include <sys/time.h>          /* These two includes are needed */  #include <sys/time.h>          /* These two includes are needed */
92  #include <sys/resource.h>      /* for setrlimit(). */  #include <sys/resource.h>      /* for setrlimit(). */
# Line 181  static int locale_set = 0; Line 189  static int locale_set = 0;
189  static int show_malloc;  static int show_malloc;
190  static int use_utf8;  static int use_utf8;
191  static size_t gotten_store;  static size_t gotten_store;
192    static const unsigned char *last_callout_mark = NULL;
193    
194  /* The buffers grow automatically if very long input lines are encountered. */  /* The buffers grow automatically if very long input lines are encountered. */
195    
# Line 189  static uschar *buffer = NULL; Line 198  static uschar *buffer = NULL;
198  static uschar *dbuffer = NULL;  static uschar *dbuffer = NULL;
199  static uschar *pbuffer = NULL;  static uschar *pbuffer = NULL;
200    
201    /* Textual explanations for runtime error codes */
202    
203    static const char *errtexts[] = {
204      NULL,  /* 0 is no error */
205      NULL,  /* NOMATCH is handled specially */
206      "NULL argument passed",
207      "bad option value",
208      "magic number missing",
209      "unknown opcode - pattern overwritten?",
210      "no more memory",
211      NULL,  /* never returned by pcre_exec() or pcre_dfa_exec() */
212      "match limit exceeded",
213      "callout error code",
214      NULL,  /* BADUTF8 is handled specially */
215      "bad UTF-8 offset",
216      NULL,  /* PARTIAL is handled specially */
217      "not used - internal error",
218      "internal error - pattern overwritten?",
219      "bad count value",
220      "item unsupported for DFA matching",
221      "backreference condition or recursion test not supported for DFA matching",
222      "match limit not supported for DFA matching",
223      "workspace size exceeded in DFA matching",
224      "too much recursion for DFA matching",
225      "recursion limit exceeded",
226      "not used - internal error",
227      "invalid combination of newline options",
228      "bad offset value",
229      NULL,  /* SHORTUTF8 is handled specially */
230      "nested recursion at the same subject position"
231    };
232    
233    
234  /*************************************************  /*************************************************
235  *         Alternate character tables             *  *         Alternate character tables             *
# Line 920  fprintf(outfile, "%.*s", (cb->next_item_ Line 961  fprintf(outfile, "%.*s", (cb->next_item_
961  fprintf(outfile, "\n");  fprintf(outfile, "\n");
962  first_callout = 0;  first_callout = 0;
963    
964    if (cb->mark != last_callout_mark)
965      {
966      fprintf(outfile, "Latest Mark: %s\n",
967        (cb->mark == NULL)? "<unset>" : (char *)(cb->mark));
968      last_callout_mark = cb->mark;
969      }
970    
971  if (cb->callout_data != NULL)  if (cb->callout_data != NULL)
972    {    {
973    int callout_data = *((int *)(cb->callout_data));    int callout_data = *((int *)(cb->callout_data));
# Line 1147  printf("  -p       use POSIX interface\n Line 1195  printf("  -p       use POSIX interface\n
1195  #endif  #endif
1196  printf("  -q       quiet: do not output PCRE version number at start\n");  printf("  -q       quiet: do not output PCRE version number at start\n");
1197  printf("  -S <n>   set stack size to <n> megabytes\n");  printf("  -S <n>   set stack size to <n> megabytes\n");
1198  printf("  -s       output store (memory) used information\n"  printf("  -s       force each pattern to be studied\n"
1199         "  -t       time compilation and execution\n");         "  -t       time compilation and execution\n");
1200  printf("  -t <n>   time compilation and execution, repeating <n> times\n");  printf("  -t <n>   time compilation and execution, repeating <n> times\n");
1201  printf("  -tm      time execution (matching) only\n");  printf("  -tm      time execution (matching) only\n");
# Line 1175  int timeit = 0; Line 1223  int timeit = 0;
1223  int timeitm = 0;  int timeitm = 0;
1224  int showinfo = 0;  int showinfo = 0;
1225  int showstore = 0;  int showstore = 0;
1226    int force_study = 0;
1227  int quiet = 0;  int quiet = 0;
1228  int size_offsets = 45;  int size_offsets = 45;
1229  int size_offsets_max;  int size_offsets_max;
# Line 1223  while (argc > 1 && argv[op][0] == '-') Line 1272  while (argc > 1 && argv[op][0] == '-')
1272    {    {
1273    unsigned char *endptr;    unsigned char *endptr;
1274    
1275    if (strcmp(argv[op], "-s") == 0 || strcmp(argv[op], "-m") == 0)    if (strcmp(argv[op], "-m") == 0) showstore = 1;
1276      showstore = 1;    else if (strcmp(argv[op], "-s") == 0) force_study = 1;
1277    else if (strcmp(argv[op], "-q") == 0) quiet = 1;    else if (strcmp(argv[op], "-q") == 0) quiet = 1;
1278    else if (strcmp(argv[op], "-b") == 0) debug = 1;    else if (strcmp(argv[op], "-b") == 0) debug = 1;
1279    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;
# Line 1258  while (argc > 1 && argv[op][0] == '-') Line 1307  while (argc > 1 && argv[op][0] == '-')
1307        ((stack_size = get_value((unsigned char *)argv[op+1], &endptr)),        ((stack_size = get_value((unsigned char *)argv[op+1], &endptr)),
1308          *endptr == 0))          *endptr == 0))
1309      {      {
1310  #if defined(_WIN32) || defined(WIN32)  #if defined(_WIN32) || defined(WIN32) || defined(__minix)
1311      printf("PCRE: -S not supported on this OS\n");      printf("PCRE: -S not supported on this OS\n");
1312      exit(1);      exit(1);
1313  #else  #else
# Line 1394  while (!done) Line 1443  while (!done)
1443    const unsigned char *tables = NULL;    const unsigned char *tables = NULL;
1444    unsigned long int true_size, true_study_size = 0;    unsigned long int true_size, true_study_size = 0;
1445    size_t size, regex_gotten_store;    size_t size, regex_gotten_store;
1446      int do_allcaps = 0;
1447    int do_mark = 0;    int do_mark = 0;
1448    int do_study = 0;    int do_study = 0;
1449      int no_force_study = 0;
1450    int do_debug = debug;    int do_debug = debug;
1451    int do_G = 0;    int do_G = 0;
1452    int do_g = 0;    int do_g = 0;
1453    int do_showinfo = showinfo;    int do_showinfo = showinfo;
1454    int do_showrest = 0;    int do_showrest = 0;
1455      int do_showcaprest = 0;
1456    int do_flip = 0;    int do_flip = 0;
1457    int erroroffset, len, delimiter, poffset;    int erroroffset, len, delimiter, poffset;
1458    
# Line 1462  while (!done) Line 1514  while (!done)
1514          }          }
1515        }        }
1516    
1517      fprintf(outfile, "Compiled regex%s loaded from %s\n",      fprintf(outfile, "Compiled pattern%s loaded from %s\n",
1518        do_flip? " (byte-inverted)" : "", p);        do_flip? " (byte-inverted)" : "", p);
1519    
1520      /* Need to know if UTF-8 for printing data strings */      /* Need to know if UTF-8 for printing data strings */
# Line 1470  while (!done) Line 1522  while (!done)
1522      new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);      new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);
1523      use_utf8 = (get_options & PCRE_UTF8) != 0;      use_utf8 = (get_options & PCRE_UTF8) != 0;
1524    
1525      /* Now see if there is any following study data */      /* Now see if there is any following study data. */
1526    
1527      if (true_study_size != 0)      if (true_study_size != 0)
1528        {        {
# Line 1566  while (!done) Line 1618  while (!done)
1618        case 's': options |= PCRE_DOTALL; break;        case 's': options |= PCRE_DOTALL; break;
1619        case 'x': options |= PCRE_EXTENDED; break;        case 'x': options |= PCRE_EXTENDED; break;
1620    
1621        case '+': do_showrest = 1; break;        case '+':
1622          if (do_showrest) do_showcaprest = 1; else do_showrest = 1;
1623          break;
1624    
1625          case '=': do_allcaps = 1; break;
1626        case 'A': options |= PCRE_ANCHORED; break;        case 'A': options |= PCRE_ANCHORED; break;
1627        case 'B': do_debug = 1; break;        case 'B': do_debug = 1; break;
1628        case 'C': options |= PCRE_AUTO_CALLOUT; break;        case 'C': options |= PCRE_AUTO_CALLOUT; break;
# Line 1584  while (!done) Line 1640  while (!done)
1640        case 'P': do_posix = 1; break;        case 'P': do_posix = 1; break;
1641  #endif  #endif
1642    
1643        case 'S': do_study = 1; break;        case 'S':
1644          if (do_study == 0) do_study = 1; else
1645            {
1646            do_study = 0;
1647            no_force_study = 1;
1648            }
1649          break;
1650    
1651        case 'U': options |= PCRE_UNGREEDY; break;        case 'U': options |= PCRE_UNGREEDY; break;
1652        case 'W': options |= PCRE_UCP; break;        case 'W': options |= PCRE_UCP; break;
1653        case 'X': options |= PCRE_EXTRA; break;        case 'X': options |= PCRE_EXTRA; break;
# Line 1768  while (!done) Line 1831  while (!done)
1831      true_size = ((real_pcre *)re)->size;      true_size = ((real_pcre *)re)->size;
1832      regex_gotten_store = gotten_store;      regex_gotten_store = gotten_store;
1833    
1834      /* If /S was present, study the regexp to generate additional info to      /* If -s or /S was present, study the regex to generate additional info to
1835      help with the matching. */      help with the matching, unless the pattern has the SS option, which
1836        suppresses the effect of /S (used for a few test patterns where studying is
1837        never sensible). */
1838    
1839      if (do_study)      if (do_study || (force_study && !no_force_study))
1840        {        {
1841        if (timeit > 0)        if (timeit > 0)
1842          {          {
# Line 2009  while (!done) Line 2074  while (!done)
2074        /* 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
2075        value, but it varies, depending on the computer architecture, and        value, but it varies, depending on the computer architecture, and
2076        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
2077        flipped.) */        flipped.) If study was forced by an external -s, don't show this
2078          information unless -i or -d was also present. This means that, except
2079          when auto-callouts are involved, the output from runs with and without
2080          -s should be identical. */
2081    
2082        if (do_study)        if (do_study || (force_study && showinfo && !no_force_study))
2083          {          {
2084          if (extra == NULL)          if (extra == NULL)
2085            fprintf(outfile, "Study returned NULL\n");            fprintf(outfile, "Study returned NULL\n");
# Line 2089  while (!done) Line 2157  while (!done)
2157            }            }
2158          else          else
2159            {            {
2160            fprintf(outfile, "Compiled regex written to %s\n", to_file);            fprintf(outfile, "Compiled pattern written to %s\n", to_file);
2161    
2162              /* If there is study data, write it. */
2163    
2164            if (extra != NULL)            if (extra != NULL)
2165              {              {
2166              if (fwrite(extra->study_data, 1, true_study_size, f) <              if (fwrite(extra->study_data, 1, true_study_size, f) <
# Line 2099  while (!done) Line 2170  while (!done)
2170                  strerror(errno));                  strerror(errno));
2171                }                }
2172              else fprintf(outfile, "Study data written to %s\n", to_file);              else fprintf(outfile, "Study data written to %s\n", to_file);
   
2173              }              }
2174            }            }
2175          fclose(f);          fclose(f);
# Line 2148  while (!done) Line 2218  while (!done)
2218    
2219      pcre_callout = callout;      pcre_callout = callout;
2220      first_callout = 1;      first_callout = 1;
2221        last_callout_mark = NULL;
2222      callout_extra = 0;      callout_extra = 0;
2223      callout_count = 0;      callout_count = 0;
2224      callout_fail_count = 999999;      callout_fail_count = 999999;
# Line 2531  while (!done) Line 2602  while (!done)
2602              (void)pchars(dbuffer + pmatch[i].rm_so,              (void)pchars(dbuffer + pmatch[i].rm_so,
2603                pmatch[i].rm_eo - pmatch[i].rm_so, outfile);                pmatch[i].rm_eo - pmatch[i].rm_so, outfile);
2604              fprintf(outfile, "\n");              fprintf(outfile, "\n");
2605              if (i == 0 && do_showrest)              if (do_showcaprest || (i == 0 && do_showrest))
2606                {                {
2607                fprintf(outfile, " 0+ ");                fprintf(outfile, "%2d+ ", (int)i);
2608                (void)pchars(dbuffer + pmatch[i].rm_eo, len - pmatch[i].rm_eo,                (void)pchars(dbuffer + pmatch[i].rm_eo, len - pmatch[i].rm_eo,
2609                  outfile);                  outfile);
2610                fprintf(outfile, "\n");                fprintf(outfile, "\n");
# Line 2675  while (!done) Line 2746  while (!done)
2746              }              }
2747            }            }
2748    
2749            /* do_allcaps requests showing of all captures in the pattern, to check
2750            unset ones at the end. */
2751    
2752            if (do_allcaps)
2753              {
2754              new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count);
2755              count++;   /* Allow for full match */
2756              if (count * 2 > use_size_offsets) count = use_size_offsets/2;
2757              }
2758    
2759            /* Output the captured substrings */
2760    
2761          for (i = 0; i < count * 2; i += 2)          for (i = 0; i < count * 2; i += 2)
2762            {            {
2763            if (use_offsets[i] < 0)            if (use_offsets[i] < 0)
2764                {
2765                if (use_offsets[i] != -1)
2766                  fprintf(outfile, "ERROR: bad negative value %d for offset %d\n",
2767                    use_offsets[i], i);
2768                if (use_offsets[i+1] != -1)
2769                  fprintf(outfile, "ERROR: bad negative value %d for offset %d\n",
2770                    use_offsets[i+1], i+1);
2771              fprintf(outfile, "%2d: <unset>\n", i/2);              fprintf(outfile, "%2d: <unset>\n", i/2);
2772                }
2773            else            else
2774              {              {
2775              fprintf(outfile, "%2d: ", i/2);              fprintf(outfile, "%2d: ", i/2);
2776              (void)pchars(bptr + use_offsets[i],              (void)pchars(bptr + use_offsets[i],
2777                use_offsets[i+1] - use_offsets[i], outfile);                use_offsets[i+1] - use_offsets[i], outfile);
2778              fprintf(outfile, "\n");              fprintf(outfile, "\n");
2779              if (i == 0)              if (do_showcaprest || (i == 0 && do_showrest))
2780                {                {
2781                if (do_showrest)                fprintf(outfile, "%2d+ ", i/2);
2782                  {                (void)pchars(bptr + use_offsets[i+1], len - use_offsets[i+1],
2783                  fprintf(outfile, " 0+ ");                  outfile);
2784                  (void)pchars(bptr + use_offsets[i+1], len - use_offsets[i+1],                fprintf(outfile, "\n");
                   outfile);  
                 fprintf(outfile, "\n");  
                 }  
2785                }                }
2786              }              }
2787            }            }
# Line 2850  while (!done) Line 2938  while (!done)
2938            }            }
2939          else          else
2940            {            {
2941            if (count == PCRE_ERROR_NOMATCH)            switch(count)
2942              {              {
2943                case PCRE_ERROR_NOMATCH:
2944              if (gmatched == 0)              if (gmatched == 0)
2945                {                {
2946                if (markptr == NULL) fprintf(outfile, "No match\n");                if (markptr == NULL) fprintf(outfile, "No match\n");
2947                  else fprintf(outfile, "No match, mark = %s\n", markptr);                  else fprintf(outfile, "No match, mark = %s\n", markptr);
2948                }                }
2949                break;
2950    
2951                case PCRE_ERROR_BADUTF8:
2952                case PCRE_ERROR_SHORTUTF8:
2953                fprintf(outfile, "Error %d (%s UTF-8 string)", count,
2954                  (count == PCRE_ERROR_BADUTF8)? "bad" : "short");
2955                if (use_size_offsets >= 2)
2956                  fprintf(outfile, " offset=%d reason=%d", use_offsets[0],
2957                    use_offsets[1]);
2958                fprintf(outfile, "\n");
2959                break;
2960    
2961                default:
2962                if (count < 0 && (-count) < sizeof(errtexts)/sizeof(const char *))
2963                  fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);
2964                else
2965                  fprintf(outfile, "Error %d (Unexpected value)\n", count);
2966                break;
2967              }              }
2968            else fprintf(outfile, "Error %d\n", count);  
2969            break;  /* Out of the /g loop */            break;  /* Out of the /g loop */
2970            }            }
2971          }          }

Legend:
Removed from v.579  
changed lines
  Added in v.658

  ViewVC Help
Powered by ViewVC 1.1.5