/[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 606 by ph10, Mon Jun 6 17:46:22 2011 UTC revision 642 by ph10, Thu Jul 28 18:59:40 2011 UTC
# Line 225  static const char *errtexts[] = { Line 225  static const char *errtexts[] = {
225    "not used - internal error",    "not used - internal error",
226    "invalid combination of newline options",    "invalid combination of newline options",
227    "bad offset value",    "bad offset value",
228    NULL  /* SHORTUTF8 is handled specially */    NULL,  /* SHORTUTF8 is handled specially */
229      "nested recursion at the same subject position"
230  };  };
231    
232    
# Line 1298  while (argc > 1 && argv[op][0] == '-') Line 1299  while (argc > 1 && argv[op][0] == '-')
1299        ((stack_size = get_value((unsigned char *)argv[op+1], &endptr)),        ((stack_size = get_value((unsigned char *)argv[op+1], &endptr)),
1300          *endptr == 0))          *endptr == 0))
1301      {      {
1302  #if defined(_WIN32) || defined(WIN32)  #if defined(_WIN32) || defined(WIN32) || defined(__minix)
1303      printf("PCRE: -S not supported on this OS\n");      printf("PCRE: -S not supported on this OS\n");
1304      exit(1);      exit(1);
1305  #else  #else
# Line 1434  while (!done) Line 1435  while (!done)
1435    const unsigned char *tables = NULL;    const unsigned char *tables = NULL;
1436    unsigned long int true_size, true_study_size = 0;    unsigned long int true_size, true_study_size = 0;
1437    size_t size, regex_gotten_store;    size_t size, regex_gotten_store;
1438      int do_allcaps = 0;
1439    int do_mark = 0;    int do_mark = 0;
1440    int do_study = 0;    int do_study = 0;
1441      int no_force_study = 0;
1442    int do_debug = debug;    int do_debug = debug;
1443    int do_G = 0;    int do_G = 0;
1444    int do_g = 0;    int do_g = 0;
1445    int do_showinfo = showinfo;    int do_showinfo = showinfo;
1446    int do_showrest = 0;    int do_showrest = 0;
1447      int do_showcaprest = 0;
1448    int do_flip = 0;    int do_flip = 0;
1449    int erroroffset, len, delimiter, poffset;    int erroroffset, len, delimiter, poffset;
1450    
# Line 1502  while (!done) Line 1506  while (!done)
1506          }          }
1507        }        }
1508    
1509      fprintf(outfile, "Compiled regex%s loaded from %s\n",      fprintf(outfile, "Compiled pattern%s loaded from %s\n",
1510        do_flip? " (byte-inverted)" : "", p);        do_flip? " (byte-inverted)" : "", p);
1511    
1512      /* Need to know if UTF-8 for printing data strings */      /* Need to know if UTF-8 for printing data strings */
# Line 1510  while (!done) Line 1514  while (!done)
1514      new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);      new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);
1515      use_utf8 = (get_options & PCRE_UTF8) != 0;      use_utf8 = (get_options & PCRE_UTF8) != 0;
1516    
1517      /* Now see if there is any following study data */      /* Now see if there is any following study data. */
1518    
1519      if (true_study_size != 0)      if (true_study_size != 0)
1520        {        {
# Line 1606  while (!done) Line 1610  while (!done)
1610        case 's': options |= PCRE_DOTALL; break;        case 's': options |= PCRE_DOTALL; break;
1611        case 'x': options |= PCRE_EXTENDED; break;        case 'x': options |= PCRE_EXTENDED; break;
1612    
1613        case '+': do_showrest = 1; break;        case '+':
1614          if (do_showrest) do_showcaprest = 1; else do_showrest = 1;
1615          break;
1616    
1617          case '=': do_allcaps = 1; break;
1618        case 'A': options |= PCRE_ANCHORED; break;        case 'A': options |= PCRE_ANCHORED; break;
1619        case 'B': do_debug = 1; break;        case 'B': do_debug = 1; break;
1620        case 'C': options |= PCRE_AUTO_CALLOUT; break;        case 'C': options |= PCRE_AUTO_CALLOUT; break;
# Line 1624  while (!done) Line 1632  while (!done)
1632        case 'P': do_posix = 1; break;        case 'P': do_posix = 1; break;
1633  #endif  #endif
1634    
1635        case 'S': do_study = 1; break;        case 'S':
1636          if (do_study == 0) do_study = 1; else
1637            {
1638            do_study = 0;
1639            no_force_study = 1;
1640            }
1641          break;
1642    
1643        case 'U': options |= PCRE_UNGREEDY; break;        case 'U': options |= PCRE_UNGREEDY; break;
1644        case 'W': options |= PCRE_UCP; break;        case 'W': options |= PCRE_UCP; break;
1645        case 'X': options |= PCRE_EXTRA; break;        case 'X': options |= PCRE_EXTRA; break;
# Line 1808  while (!done) Line 1823  while (!done)
1823      true_size = ((real_pcre *)re)->size;      true_size = ((real_pcre *)re)->size;
1824      regex_gotten_store = gotten_store;      regex_gotten_store = gotten_store;
1825    
1826      /* If -s or /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
1827      help with the matching. */      help with the matching, unless the pattern has the SS option, which
1828        suppresses the effect of /S (used for a few test patterns where studying is
1829        never sensible). */
1830    
1831      if (do_study || force_study)      if (do_study || (force_study && !no_force_study))
1832        {        {
1833        if (timeit > 0)        if (timeit > 0)
1834          {          {
# Line 2049  while (!done) Line 2066  while (!done)
2066        /* 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
2067        value, but it varies, depending on the computer architecture, and        value, but it varies, depending on the computer architecture, and
2068        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
2069        flipped.) */        flipped.) If study was forced by an external -s, don't show this
2070          information unless -i or -d was also present. This means that, except
2071          when auto-callouts are involved, the output from runs with and without
2072          -s should be identical. */
2073    
2074        if (do_study || force_study)        if (do_study || (force_study && showinfo && !no_force_study))
2075          {          {
2076          if (extra == NULL)          if (extra == NULL)
2077            fprintf(outfile, "Study returned NULL\n");            fprintf(outfile, "Study returned NULL\n");
# Line 2129  while (!done) Line 2149  while (!done)
2149            }            }
2150          else          else
2151            {            {
2152            fprintf(outfile, "Compiled regex written to %s\n", to_file);            fprintf(outfile, "Compiled pattern written to %s\n", to_file);
2153    
2154              /* If there is study data, write it, but verify the writing only
2155              if the studying was requested by /S, not just by -s. */
2156    
2157            if (extra != NULL)            if (extra != NULL)
2158              {              {
2159              if (fwrite(extra->study_data, 1, true_study_size, f) <              if (fwrite(extra->study_data, 1, true_study_size, f) <
# Line 2139  while (!done) Line 2163  while (!done)
2163                  strerror(errno));                  strerror(errno));
2164                }                }
2165              else fprintf(outfile, "Study data written to %s\n", to_file);              else fprintf(outfile, "Study data written to %s\n", to_file);
   
2166              }              }
2167            }            }
2168          fclose(f);          fclose(f);
# Line 2571  while (!done) Line 2594  while (!done)
2594              (void)pchars(dbuffer + pmatch[i].rm_so,              (void)pchars(dbuffer + pmatch[i].rm_so,
2595                pmatch[i].rm_eo - pmatch[i].rm_so, outfile);                pmatch[i].rm_eo - pmatch[i].rm_so, outfile);
2596              fprintf(outfile, "\n");              fprintf(outfile, "\n");
2597              if (i == 0 && do_showrest)              if (do_showcaprest || (i == 0 && do_showrest))
2598                {                {
2599                fprintf(outfile, " 0+ ");                fprintf(outfile, "%2d+ ", (int)i);
2600                (void)pchars(dbuffer + pmatch[i].rm_eo, len - pmatch[i].rm_eo,                (void)pchars(dbuffer + pmatch[i].rm_eo, len - pmatch[i].rm_eo,
2601                  outfile);                  outfile);
2602                fprintf(outfile, "\n");                fprintf(outfile, "\n");
# Line 2714  while (!done) Line 2737  while (!done)
2737              do_g = do_G = FALSE;        /* Break g/G loop */              do_g = do_G = FALSE;        /* Break g/G loop */
2738              }              }
2739            }            }
2740    
2741            /* do_allcaps requests showing of all captures in the pattern, to check
2742            unset ones at the end. */
2743    
2744            if (do_allcaps)
2745              {
2746              new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count);
2747              count++;   /* Allow for full match */
2748              if (count * 2 > use_size_offsets) count = use_size_offsets/2;
2749              }
2750    
2751            /* Output the captured substrings */
2752    
2753          for (i = 0; i < count * 2; i += 2)          for (i = 0; i < count * 2; i += 2)
2754            {            {
2755            if (use_offsets[i] < 0)            if (use_offsets[i] < 0)
2756                {
2757                if (use_offsets[i] != -1)
2758                  fprintf(outfile, "ERROR: bad negative value %d for offset %d\n",
2759                    use_offsets[i], i);
2760                if (use_offsets[i+1] != -1)
2761                  fprintf(outfile, "ERROR: bad negative value %d for offset %d\n",
2762                    use_offsets[i+1], i+1);
2763              fprintf(outfile, "%2d: <unset>\n", i/2);              fprintf(outfile, "%2d: <unset>\n", i/2);
2764                }
2765            else            else
2766              {              {
2767              fprintf(outfile, "%2d: ", i/2);              fprintf(outfile, "%2d: ", i/2);
2768              (void)pchars(bptr + use_offsets[i],              (void)pchars(bptr + use_offsets[i],
2769                use_offsets[i+1] - use_offsets[i], outfile);                use_offsets[i+1] - use_offsets[i], outfile);
2770              fprintf(outfile, "\n");              fprintf(outfile, "\n");
2771              if (i == 0)              if (do_showcaprest || (i == 0 && do_showrest))
2772                {                {
2773                if (do_showrest)                fprintf(outfile, "%2d+ ", i/2);
2774                  {                (void)pchars(bptr + use_offsets[i+1], len - use_offsets[i+1],
2775                  fprintf(outfile, " 0+ ");                  outfile);
2776                  (void)pchars(bptr + use_offsets[i+1], len - use_offsets[i+1],                fprintf(outfile, "\n");
                   outfile);  
                 fprintf(outfile, "\n");  
                 }  
2777                }                }
2778              }              }
2779            }            }

Legend:
Removed from v.606  
changed lines
  Added in v.642

  ViewVC Help
Powered by ViewVC 1.1.5