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

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

  ViewVC Help
Powered by ViewVC 1.1.5