/[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 579 by ph10, Wed Nov 24 17:39:25 2010 UTC revision 616 by ph10, Mon Jul 11 15:55:25 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 189  static uschar *buffer = NULL; Line 197  static uschar *buffer = NULL;
197  static uschar *dbuffer = NULL;  static uschar *dbuffer = NULL;
198  static uschar *pbuffer = NULL;  static uschar *pbuffer = NULL;
199    
200    /* Textual explanations for runtime error codes */
201    
202    static const char *errtexts[] = {
203      NULL,  /* 0 is no error */
204      NULL,  /* NOMATCH is handled specially */
205      "NULL argument passed",
206      "bad option value",
207      "magic number missing",
208      "unknown opcode - pattern overwritten?",
209      "no more memory",
210      NULL,  /* never returned by pcre_exec() or pcre_dfa_exec() */
211      "match limit exceeded",
212      "callout error code",
213      NULL,  /* BADUTF8 is handled specially */
214      "bad UTF-8 offset",
215      NULL,  /* PARTIAL is handled specially */
216      "not used - internal error",
217      "internal error - pattern overwritten?",
218      "bad count value",
219      "item unsupported for DFA matching",
220      "backreference condition or recursion test not supported for DFA matching",
221      "match limit not supported for DFA matching",
222      "workspace size exceeded in DFA matching",
223      "too much recursion for DFA matching",
224      "recursion limit exceeded",
225      "not used - internal error",
226      "invalid combination of newline options",
227      "bad offset value",
228      NULL  /* SHORTUTF8 is handled specially */
229    };
230    
231    
232  /*************************************************  /*************************************************
233  *         Alternate character tables             *  *         Alternate character tables             *
# Line 1147  printf("  -p       use POSIX interface\n Line 1186  printf("  -p       use POSIX interface\n
1186  #endif  #endif
1187  printf("  -q       quiet: do not output PCRE version number at start\n");  printf("  -q       quiet: do not output PCRE version number at start\n");
1188  printf("  -S <n>   set stack size to <n> megabytes\n");  printf("  -S <n>   set stack size to <n> megabytes\n");
1189  printf("  -s       output store (memory) used information\n"  printf("  -s       force each pattern to be studied\n"
1190         "  -t       time compilation and execution\n");         "  -t       time compilation and execution\n");
1191  printf("  -t <n>   time compilation and execution, repeating <n> times\n");  printf("  -t <n>   time compilation and execution, repeating <n> times\n");
1192  printf("  -tm      time execution (matching) only\n");  printf("  -tm      time execution (matching) only\n");
# Line 1175  int timeit = 0; Line 1214  int timeit = 0;
1214  int timeitm = 0;  int timeitm = 0;
1215  int showinfo = 0;  int showinfo = 0;
1216  int showstore = 0;  int showstore = 0;
1217    int force_study = 0;
1218  int quiet = 0;  int quiet = 0;
1219  int size_offsets = 45;  int size_offsets = 45;
1220  int size_offsets_max;  int size_offsets_max;
# Line 1223  while (argc > 1 && argv[op][0] == '-') Line 1263  while (argc > 1 && argv[op][0] == '-')
1263    {    {
1264    unsigned char *endptr;    unsigned char *endptr;
1265    
1266    if (strcmp(argv[op], "-s") == 0 || strcmp(argv[op], "-m") == 0)    if (strcmp(argv[op], "-m") == 0) showstore = 1;
1267      showstore = 1;    else if (strcmp(argv[op], "-s") == 0) force_study = 1;
1268    else if (strcmp(argv[op], "-q") == 0) quiet = 1;    else if (strcmp(argv[op], "-q") == 0) quiet = 1;
1269    else if (strcmp(argv[op], "-b") == 0) debug = 1;    else if (strcmp(argv[op], "-b") == 0) debug = 1;
1270    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;
# Line 1396  while (!done) Line 1436  while (!done)
1436    size_t size, regex_gotten_store;    size_t size, regex_gotten_store;
1437    int do_mark = 0;    int do_mark = 0;
1438    int do_study = 0;    int do_study = 0;
1439      int no_force_study = 0;
1440    int do_debug = debug;    int do_debug = debug;
1441    int do_G = 0;    int do_G = 0;
1442    int do_g = 0;    int do_g = 0;
1443    int do_showinfo = showinfo;    int do_showinfo = showinfo;
1444    int do_showrest = 0;    int do_showrest = 0;
1445      int do_showcaprest = 0;
1446    int do_flip = 0;    int do_flip = 0;
1447    int erroroffset, len, delimiter, poffset;    int erroroffset, len, delimiter, poffset;
1448    
# Line 1462  while (!done) Line 1504  while (!done)
1504          }          }
1505        }        }
1506    
1507      fprintf(outfile, "Compiled regex%s loaded from %s\n",      fprintf(outfile, "Compiled pattern%s loaded from %s\n",
1508        do_flip? " (byte-inverted)" : "", p);        do_flip? " (byte-inverted)" : "", p);
1509    
1510      /* 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 1512  while (!done)
1512      new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);      new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);
1513      use_utf8 = (get_options & PCRE_UTF8) != 0;      use_utf8 = (get_options & PCRE_UTF8) != 0;
1514    
1515      /* Now see if there is any following study data */      /* Now see if there is any following study data. */
1516    
1517      if (true_study_size != 0)      if (true_study_size != 0)
1518        {        {
# Line 1566  while (!done) Line 1608  while (!done)
1608        case 's': options |= PCRE_DOTALL; break;        case 's': options |= PCRE_DOTALL; break;
1609        case 'x': options |= PCRE_EXTENDED; break;        case 'x': options |= PCRE_EXTENDED; break;
1610    
1611        case '+': do_showrest = 1; break;        case '+':
1612          if (do_showrest) do_showcaprest = 1; else do_showrest = 1;
1613          break;
1614    
1615        case 'A': options |= PCRE_ANCHORED; break;        case 'A': options |= PCRE_ANCHORED; break;
1616        case 'B': do_debug = 1; break;        case 'B': do_debug = 1; break;
1617        case 'C': options |= PCRE_AUTO_CALLOUT; break;        case 'C': options |= PCRE_AUTO_CALLOUT; break;
# Line 1584  while (!done) Line 1629  while (!done)
1629        case 'P': do_posix = 1; break;        case 'P': do_posix = 1; break;
1630  #endif  #endif
1631    
1632        case 'S': do_study = 1; break;        case 'S':
1633          if (do_study == 0) do_study = 1; else
1634            {
1635            do_study = 0;
1636            no_force_study = 1;
1637            }
1638          break;
1639    
1640        case 'U': options |= PCRE_UNGREEDY; break;        case 'U': options |= PCRE_UNGREEDY; break;
1641        case 'W': options |= PCRE_UCP; break;        case 'W': options |= PCRE_UCP; break;
1642        case 'X': options |= PCRE_EXTRA; break;        case 'X': options |= PCRE_EXTRA; break;
# Line 1768  while (!done) Line 1820  while (!done)
1820      true_size = ((real_pcre *)re)->size;      true_size = ((real_pcre *)re)->size;
1821      regex_gotten_store = gotten_store;      regex_gotten_store = gotten_store;
1822    
1823      /* 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
1824      help with the matching. */      help with the matching, unless the pattern has the SS option, which
1825        suppresses the effect of /S (used for a few test patterns where studying is
1826        never sensible). */
1827    
1828      if (do_study)      if (do_study || (force_study && !no_force_study))
1829        {        {
1830        if (timeit > 0)        if (timeit > 0)
1831          {          {
# Line 2009  while (!done) Line 2063  while (!done)
2063        /* 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
2064        value, but it varies, depending on the computer architecture, and        value, but it varies, depending on the computer architecture, and
2065        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
2066        flipped.) */        flipped.) If study was forced by an external -s, don't show this
2067          information unless -i or -d was also present. This means that, except
2068          when auto-callouts are involved, the output from runs with and without
2069          -s should be identical. */
2070    
2071        if (do_study)        if (do_study || (force_study && showinfo && !no_force_study))
2072          {          {
2073          if (extra == NULL)          if (extra == NULL)
2074            fprintf(outfile, "Study returned NULL\n");            fprintf(outfile, "Study returned NULL\n");
# Line 2089  while (!done) Line 2146  while (!done)
2146            }            }
2147          else          else
2148            {            {
2149            fprintf(outfile, "Compiled regex written to %s\n", to_file);            fprintf(outfile, "Compiled pattern written to %s\n", to_file);
2150    
2151              /* If there is study data, write it, but verify the writing only
2152              if the studying was requested by /S, not just by -s. */
2153    
2154            if (extra != NULL)            if (extra != NULL)
2155              {              {
2156              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 2160  while (!done)
2160                  strerror(errno));                  strerror(errno));
2161                }                }
2162              else fprintf(outfile, "Study data written to %s\n", to_file);              else fprintf(outfile, "Study data written to %s\n", to_file);
   
2163              }              }
2164            }            }
2165          fclose(f);          fclose(f);
# Line 2531  while (!done) Line 2591  while (!done)
2591              (void)pchars(dbuffer + pmatch[i].rm_so,              (void)pchars(dbuffer + pmatch[i].rm_so,
2592                pmatch[i].rm_eo - pmatch[i].rm_so, outfile);                pmatch[i].rm_eo - pmatch[i].rm_so, outfile);
2593              fprintf(outfile, "\n");              fprintf(outfile, "\n");
2594              if (i == 0 && do_showrest)              if (do_showcaprest || (i == 0 && do_showrest))
2595                {                {
2596                fprintf(outfile, " 0+ ");                fprintf(outfile, "%2d+ ", (int)i);
2597                (void)pchars(dbuffer + pmatch[i].rm_eo, len - pmatch[i].rm_eo,                (void)pchars(dbuffer + pmatch[i].rm_eo, len - pmatch[i].rm_eo,
2598                  outfile);                  outfile);
2599                fprintf(outfile, "\n");                fprintf(outfile, "\n");
# Line 2685  while (!done) Line 2745  while (!done)
2745              (void)pchars(bptr + use_offsets[i],              (void)pchars(bptr + use_offsets[i],
2746                use_offsets[i+1] - use_offsets[i], outfile);                use_offsets[i+1] - use_offsets[i], outfile);
2747              fprintf(outfile, "\n");              fprintf(outfile, "\n");
2748              if (i == 0)              if (do_showcaprest || (i == 0 && do_showrest))
2749                {                {
2750                if (do_showrest)                fprintf(outfile, "%2d+ ", i/2);
2751                  {                (void)pchars(bptr + use_offsets[i+1], len - use_offsets[i+1],
2752                  fprintf(outfile, " 0+ ");                  outfile);
2753                  (void)pchars(bptr + use_offsets[i+1], len - use_offsets[i+1],                fprintf(outfile, "\n");
                   outfile);  
                 fprintf(outfile, "\n");  
                 }  
2754                }                }
2755              }              }
2756            }            }
# Line 2850  while (!done) Line 2907  while (!done)
2907            }            }
2908          else          else
2909            {            {
2910            if (count == PCRE_ERROR_NOMATCH)            switch(count)
2911              {              {
2912                case PCRE_ERROR_NOMATCH:
2913              if (gmatched == 0)              if (gmatched == 0)
2914                {                {
2915                if (markptr == NULL) fprintf(outfile, "No match\n");                if (markptr == NULL) fprintf(outfile, "No match\n");
2916                  else fprintf(outfile, "No match, mark = %s\n", markptr);                  else fprintf(outfile, "No match, mark = %s\n", markptr);
2917                }                }
2918                break;
2919    
2920                case PCRE_ERROR_BADUTF8:
2921                case PCRE_ERROR_SHORTUTF8:
2922                fprintf(outfile, "Error %d (%s UTF-8 string)", count,
2923                  (count == PCRE_ERROR_BADUTF8)? "bad" : "short");
2924                if (use_size_offsets >= 2)
2925                  fprintf(outfile, " offset=%d reason=%d", use_offsets[0],
2926                    use_offsets[1]);
2927                fprintf(outfile, "\n");
2928                break;
2929    
2930                default:
2931                if (count < 0 && (-count) < sizeof(errtexts)/sizeof(const char *))
2932                  fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);
2933                else
2934                  fprintf(outfile, "Error %d (Unexpected value)\n", count);
2935                break;
2936              }              }
2937            else fprintf(outfile, "Error %d\n", count);  
2938            break;  /* Out of the /g loop */            break;  /* Out of the /g loop */
2939            }            }
2940          }          }

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

  ViewVC Help
Powered by ViewVC 1.1.5