/[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 773 by ph10, Wed Nov 30 18:10:27 2011 UTC
# Line 112  to keep two copies, we include the sourc Line 112  to keep two copies, we include the sourc
112  external symbols to prevent clashes. */  external symbols to prevent clashes. */
113    
114  #define _pcre_ucp_gentype      ucp_gentype  #define _pcre_ucp_gentype      ucp_gentype
115    #define _pcre_ucp_typerange    ucp_typerange
116  #define _pcre_utf8_table1      utf8_table1  #define _pcre_utf8_table1      utf8_table1
117  #define _pcre_utf8_table1_size utf8_table1_size  #define _pcre_utf8_table1_size utf8_table1_size
118  #define _pcre_utf8_table2      utf8_table2  #define _pcre_utf8_table2      utf8_table2
119  #define _pcre_utf8_table3      utf8_table3  #define _pcre_utf8_table3      utf8_table3
120  #define _pcre_utf8_table4      utf8_table4  #define _pcre_utf8_table4      utf8_table4
121    #define _pcre_utf8_char_sizes  utf8_char_sizes
122  #define _pcre_utt              utt  #define _pcre_utt              utt
123  #define _pcre_utt_size         utt_size  #define _pcre_utt_size         utt_size
124  #define _pcre_utt_names        utt_names  #define _pcre_utt_names        utt_names
# Line 189  static int locale_set = 0; Line 191  static int locale_set = 0;
191  static int show_malloc;  static int show_malloc;
192  static int use_utf8;  static int use_utf8;
193  static size_t gotten_store;  static size_t gotten_store;
194    static size_t first_gotten_store = 0;
195    static const unsigned char *last_callout_mark = NULL;
196    
197  /* The buffers grow automatically if very long input lines are encountered. */  /* The buffers grow automatically if very long input lines are encountered. */
198    
# Line 207  static const char *errtexts[] = { Line 211  static const char *errtexts[] = {
211    "magic number missing",    "magic number missing",
212    "unknown opcode - pattern overwritten?",    "unknown opcode - pattern overwritten?",
213    "no more memory",    "no more memory",
214    NULL,  /* never returned by pcre_exec() or pcre_dfa_exec() */    NULL,  /* never returned by pcre_exec() or pcre_dfa_exec() */
215    "match limit exceeded",    "match limit exceeded",
216    "callout error code",    "callout error code",
217    NULL,  /* BADUTF8 is handled specially */    NULL,  /* BADUTF8 is handled specially */
# Line 220  static const char *errtexts[] = { Line 224  static const char *errtexts[] = {
224    "backreference condition or recursion test not supported for DFA matching",    "backreference condition or recursion test not supported for DFA matching",
225    "match limit not supported for DFA matching",    "match limit not supported for DFA matching",
226    "workspace size exceeded in DFA matching",    "workspace size exceeded in DFA matching",
227    "too much recursion for DFA matching",    "too much recursion for DFA matching",
228    "recursion limit exceeded",    "recursion limit exceeded",
229    "not used - internal error",    "not used - internal error",
230    "invalid combination of newline options",    "invalid combination of newline options",
231    "bad offset value",    "bad offset value",
232    NULL  /* SHORTUTF8 is handled specially */    NULL,  /* SHORTUTF8 is handled specially */
233      "nested recursion at the same subject position",
234      "JIT stack limit reached"
235  };  };
236    
237    
238  /*************************************************  /*************************************************
239  *         Alternate character tables             *  *         Alternate character tables             *
# Line 577  return sys_errlist[n]; Line 583  return sys_errlist[n];
583  #endif /* HAVE_STRERROR */  #endif /* HAVE_STRERROR */
584    
585    
586    /*************************************************
587    *         JIT memory callback                    *
588    *************************************************/
589    
590    static pcre_jit_stack* jit_callback(void *arg)
591    {
592    return (pcre_jit_stack *)arg;
593    }
594    
595    
596  /*************************************************  /*************************************************
# Line 959  fprintf(outfile, "%.*s", (cb->next_item_ Line 973  fprintf(outfile, "%.*s", (cb->next_item_
973  fprintf(outfile, "\n");  fprintf(outfile, "\n");
974  first_callout = 0;  first_callout = 0;
975    
976    if (cb->mark != last_callout_mark)
977      {
978      fprintf(outfile, "Latest Mark: %s\n",
979        (cb->mark == NULL)? "<unset>" : (char *)(cb->mark));
980      last_callout_mark = cb->mark;
981      }
982    
983  if (cb->callout_data != NULL)  if (cb->callout_data != NULL)
984    {    {
985    int callout_data = *((int *)(cb->callout_data));    int callout_data = *((int *)(cb->callout_data));
# Line 978  return (cb->callout_number != callout_fa Line 999  return (cb->callout_number != callout_fa
999  *            Local malloc functions              *  *            Local malloc functions              *
1000  *************************************************/  *************************************************/
1001    
1002  /* Alternative malloc function, to test functionality and show the size of the  /* Alternative malloc function, to test functionality and save the size of a
1003  compiled re. */  compiled re, which is the first store request that pcre_compile() makes. The
1004    show_malloc variable is set only during matching. */
1005    
1006  static void *new_malloc(size_t size)  static void *new_malloc(size_t size)
1007  {  {
1008  void *block = malloc(size);  void *block = malloc(size);
1009  gotten_store = size;  gotten_store = size;
1010    if (first_gotten_store == 0) first_gotten_store = size;
1011  if (show_malloc)  if (show_malloc)
1012    fprintf(outfile, "malloc       %3d %p\n", (int)size, block);    fprintf(outfile, "malloc       %3d %p\n", (int)size, block);
1013  return block;  return block;
# Line 997  if (show_malloc) Line 1020  if (show_malloc)
1020  free(block);  free(block);
1021  }  }
1022    
   
1023  /* For recursion malloc/free, to test stacking calls */  /* For recursion malloc/free, to test stacking calls */
1024    
1025  static void *stack_malloc(size_t size)  static void *stack_malloc(size_t size)
# Line 1186  printf("  -p       use POSIX interface\n Line 1208  printf("  -p       use POSIX interface\n
1208  #endif  #endif
1209  printf("  -q       quiet: do not output PCRE version number at start\n");  printf("  -q       quiet: do not output PCRE version number at start\n");
1210  printf("  -S <n>   set stack size to <n> megabytes\n");  printf("  -S <n>   set stack size to <n> megabytes\n");
1211  printf("  -s       force each pattern to be studied\n"  printf("  -s       force each pattern to be studied at basic level\n"
1212           "  -s+      force each pattern to be studied, using JIT if available\n"
1213         "  -t       time compilation and execution\n");         "  -t       time compilation and execution\n");
1214  printf("  -t <n>   time compilation and execution, repeating <n> times\n");  printf("  -t <n>   time compilation and execution, repeating <n> times\n");
1215  printf("  -tm      time execution (matching) only\n");  printf("  -tm      time execution (matching) only\n");
# Line 1214  int timeit = 0; Line 1237  int timeit = 0;
1237  int timeitm = 0;  int timeitm = 0;
1238  int showinfo = 0;  int showinfo = 0;
1239  int showstore = 0;  int showstore = 0;
1240  int force_study = 0;  int force_study = -1;
1241    int force_study_options = 0;
1242  int quiet = 0;  int quiet = 0;
1243  int size_offsets = 45;  int size_offsets = 45;
1244  int size_offsets_max;  int size_offsets_max;
# Line 1228  int all_use_dfa = 0; Line 1252  int all_use_dfa = 0;
1252  int yield = 0;  int yield = 0;
1253  int stack_size;  int stack_size;
1254    
1255    pcre_jit_stack *jit_stack = NULL;
1256    
1257    
1258  /* These vectors store, end-to-end, a list of captured substring names. Assume  /* These vectors store, end-to-end, a list of captured substring names. Assume
1259  that 1024 is plenty long enough for the few names we'll be testing. */  that 1024 is plenty long enough for the few names we'll be testing. */
1260    
# Line 1264  while (argc > 1 && argv[op][0] == '-') Line 1291  while (argc > 1 && argv[op][0] == '-')
1291    unsigned char *endptr;    unsigned char *endptr;
1292    
1293    if (strcmp(argv[op], "-m") == 0) showstore = 1;    if (strcmp(argv[op], "-m") == 0) showstore = 1;
1294    else if (strcmp(argv[op], "-s") == 0) force_study = 1;    else if (strcmp(argv[op], "-s") == 0) force_study = 0;
1295      else if (strcmp(argv[op], "-s+") == 0)
1296        {
1297        force_study = 1;
1298        force_study_options = PCRE_STUDY_JIT_COMPILE;
1299        }
1300    else if (strcmp(argv[op], "-q") == 0) quiet = 1;    else if (strcmp(argv[op], "-q") == 0) quiet = 1;
1301    else if (strcmp(argv[op], "-b") == 0) debug = 1;    else if (strcmp(argv[op], "-b") == 0) debug = 1;
1302    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;
# Line 1298  while (argc > 1 && argv[op][0] == '-') Line 1330  while (argc > 1 && argv[op][0] == '-')
1330        ((stack_size = get_value((unsigned char *)argv[op+1], &endptr)),        ((stack_size = get_value((unsigned char *)argv[op+1], &endptr)),
1331          *endptr == 0))          *endptr == 0))
1332      {      {
1333  #if defined(_WIN32) || defined(WIN32)  #if defined(_WIN32) || defined(WIN32) || defined(__minix)
1334      printf("PCRE: -S not supported on this OS\n");      printf("PCRE: -S not supported on this OS\n");
1335      exit(1);      exit(1);
1336  #else  #else
# Line 1329  while (argc > 1 && argv[op][0] == '-') Line 1361  while (argc > 1 && argv[op][0] == '-')
1361      printf("  %sUTF-8 support\n", rc? "" : "No ");      printf("  %sUTF-8 support\n", rc? "" : "No ");
1362      (void)pcre_config(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);      (void)pcre_config(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
1363      printf("  %sUnicode properties support\n", rc? "" : "No ");      printf("  %sUnicode properties support\n", rc? "" : "No ");
1364        (void)pcre_config(PCRE_CONFIG_JIT, &rc);
1365        if (rc)
1366          printf("  Just-in-time compiler support\n");
1367        else
1368          printf("  No just-in-time compiler support\n");
1369      (void)pcre_config(PCRE_CONFIG_NEWLINE, &rc);      (void)pcre_config(PCRE_CONFIG_NEWLINE, &rc);
1370      /* Note that these values are always the ASCII values, even      /* Note that these values are always the ASCII values, even
1371      in EBCDIC environments. CR is 13 and NL is 10. */      in EBCDIC environments. CR is 13 and NL is 10. */
# Line 1434  while (!done) Line 1471  while (!done)
1471    const unsigned char *tables = NULL;    const unsigned char *tables = NULL;
1472    unsigned long int true_size, true_study_size = 0;    unsigned long int true_size, true_study_size = 0;
1473    size_t size, regex_gotten_store;    size_t size, regex_gotten_store;
1474      int do_allcaps = 0;
1475    int do_mark = 0;    int do_mark = 0;
1476    int do_study = 0;    int do_study = 0;
1477      int no_force_study = 0;
1478    int do_debug = debug;    int do_debug = debug;
1479    int do_G = 0;    int do_G = 0;
1480    int do_g = 0;    int do_g = 0;
1481    int do_showinfo = showinfo;    int do_showinfo = showinfo;
1482    int do_showrest = 0;    int do_showrest = 0;
1483      int do_showcaprest = 0;
1484    int do_flip = 0;    int do_flip = 0;
1485    int erroroffset, len, delimiter, poffset;    int erroroffset, len, delimiter, poffset;
1486    
# Line 1483  while (!done) Line 1523  while (!done)
1523        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];
1524    
1525      re = (real_pcre *)new_malloc(true_size);      re = (real_pcre *)new_malloc(true_size);
1526      regex_gotten_store = gotten_store;      regex_gotten_store = first_gotten_store;
1527    
1528      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;
1529    
# Line 1502  while (!done) Line 1542  while (!done)
1542          }          }
1543        }        }
1544    
1545      fprintf(outfile, "Compiled regex%s loaded from %s\n",      fprintf(outfile, "Compiled pattern%s loaded from %s\n",
1546        do_flip? " (byte-inverted)" : "", p);        do_flip? " (byte-inverted)" : "", p);
1547    
1548      /* 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 1550  while (!done)
1550      new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);      new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);
1551      use_utf8 = (get_options & PCRE_UTF8) != 0;      use_utf8 = (get_options & PCRE_UTF8) != 0;
1552    
1553      /* Now see if there is any following study data */      /* Now see if there is any following study data. */
1554    
1555      if (true_study_size != 0)      if (true_study_size != 0)
1556        {        {
# Line 1526  while (!done) Line 1566  while (!done)
1566          {          {
1567          FAIL_READ:          FAIL_READ:
1568          fprintf(outfile, "Failed to read data from %s\n", p);          fprintf(outfile, "Failed to read data from %s\n", p);
1569          if (extra != NULL) new_free(extra);          if (extra != NULL) pcre_free_study(extra);
1570          if (re != NULL) new_free(re);          if (re != NULL) new_free(re);
1571          fclose(f);          fclose(f);
1572          continue;          continue;
# Line 1592  while (!done) Line 1632  while (!done)
1632    /* Look for options after final delimiter */    /* Look for options after final delimiter */
1633    
1634    options = 0;    options = 0;
   study_options = 0;  
1635    log_store = showstore;  /* default from command line */    log_store = showstore;  /* default from command line */
1636    
1637    while (*pp != 0)    while (*pp != 0)
# Line 1606  while (!done) Line 1645  while (!done)
1645        case 's': options |= PCRE_DOTALL; break;        case 's': options |= PCRE_DOTALL; break;
1646        case 'x': options |= PCRE_EXTENDED; break;        case 'x': options |= PCRE_EXTENDED; break;
1647    
1648        case '+': do_showrest = 1; break;        case '+':
1649          if (do_showrest) do_showcaprest = 1; else do_showrest = 1;
1650          break;
1651    
1652          case '=': do_allcaps = 1; break;
1653        case 'A': options |= PCRE_ANCHORED; break;        case 'A': options |= PCRE_ANCHORED; break;
1654        case 'B': do_debug = 1; break;        case 'B': do_debug = 1; break;
1655        case 'C': options |= PCRE_AUTO_CALLOUT; break;        case 'C': options |= PCRE_AUTO_CALLOUT; break;
# Line 1624  while (!done) Line 1667  while (!done)
1667        case 'P': do_posix = 1; break;        case 'P': do_posix = 1; break;
1668  #endif  #endif
1669    
1670        case 'S': do_study = 1; break;        case 'S':
1671          if (do_study == 0)
1672            {
1673            do_study = 1;
1674            if (*pp == '+')
1675              {
1676              study_options |= PCRE_STUDY_JIT_COMPILE;
1677              pp++;
1678              }
1679            }
1680          else
1681            {
1682            do_study = 0;
1683            no_force_study = 1;
1684            }
1685          break;
1686    
1687        case 'U': options |= PCRE_UNGREEDY; break;        case 'U': options |= PCRE_UNGREEDY; break;
1688        case 'W': options |= PCRE_UCP; break;        case 'W': options |= PCRE_UCP; break;
1689        case 'X': options |= PCRE_EXTRA; break;        case 'X': options |= PCRE_EXTRA; break;
# Line 1721  while (!done) Line 1780  while (!done)
1780      if ((options & PCRE_UCP) != 0) cflags |= REG_UCP;      if ((options & PCRE_UCP) != 0) cflags |= REG_UCP;
1781      if ((options & PCRE_UNGREEDY) != 0) cflags |= REG_UNGREEDY;      if ((options & PCRE_UNGREEDY) != 0) cflags |= REG_UNGREEDY;
1782    
1783        first_gotten_store = 0;
1784      rc = regcomp(&preg, (char *)p, cflags);      rc = regcomp(&preg, (char *)p, cflags);
1785    
1786      /* Compilation failed; go back for another re, skipping to blank line      /* Compilation failed; go back for another re, skipping to blank line
# Line 1758  while (!done) Line 1818  while (!done)
1818            (double)CLOCKS_PER_SEC);            (double)CLOCKS_PER_SEC);
1819        }        }
1820    
1821        first_gotten_store = 0;
1822      re = pcre_compile((char *)p, options, &error, &erroroffset, tables);      re = pcre_compile((char *)p, options, &error, &erroroffset, tables);
1823    
1824      /* Compilation failed; go back for another re, skipping to blank line      /* Compilation failed; go back for another re, skipping to blank line
# Line 1798  while (!done) Line 1859  while (!done)
1859    
1860      if (log_store)      if (log_store)
1861        fprintf(outfile, "Memory allocation (code space): %d\n",        fprintf(outfile, "Memory allocation (code space): %d\n",
1862          (int)(gotten_store -          (int)(first_gotten_store -
1863                sizeof(real_pcre) -                sizeof(real_pcre) -
1864                ((real_pcre *)re)->name_count * ((real_pcre *)re)->name_entry_size));                ((real_pcre *)re)->name_count * ((real_pcre *)re)->name_entry_size));
1865    
# Line 1806  while (!done) Line 1867  while (!done)
1867      and remember the store that was got. */      and remember the store that was got. */
1868    
1869      true_size = ((real_pcre *)re)->size;      true_size = ((real_pcre *)re)->size;
1870      regex_gotten_store = gotten_store;      regex_gotten_store = first_gotten_store;
1871    
1872      /* 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
1873      help with the matching. */      help with the matching, unless the pattern has the SS option, which
1874        suppresses the effect of /S (used for a few test patterns where studying is
1875        never sensible). */
1876    
1877      if (do_study || force_study)      if (do_study || (force_study >= 0 && !no_force_study))
1878        {        {
1879        if (timeit > 0)        if (timeit > 0)
1880          {          {
# Line 1819  while (!done) Line 1882  while (!done)
1882          clock_t time_taken;          clock_t time_taken;
1883          clock_t start_time = clock();          clock_t start_time = clock();
1884          for (i = 0; i < timeit; i++)          for (i = 0; i < timeit; i++)
1885            extra = pcre_study(re, study_options, &error);            extra = pcre_study(re, study_options | force_study_options, &error);
1886          time_taken = clock() - start_time;          time_taken = clock() - start_time;
1887          if (extra != NULL) free(extra);          if (extra != NULL) pcre_free_study(extra);
1888          fprintf(outfile, "  Study time %.4f milliseconds\n",          fprintf(outfile, "  Study time %.4f milliseconds\n",
1889            (((double)time_taken * 1000.0) / (double)timeit) /            (((double)time_taken * 1000.0) / (double)timeit) /
1890              (double)CLOCKS_PER_SEC);              (double)CLOCKS_PER_SEC);
1891          }          }
1892        extra = pcre_study(re, study_options, &error);        extra = pcre_study(re, study_options | force_study_options, &error);
1893        if (error != NULL)        if (error != NULL)
1894          fprintf(outfile, "Failed to study: %s\n", error);          fprintf(outfile, "Failed to study: %s\n", error);
1895        else if (extra != NULL)        else if (extra != NULL)
# Line 2049  while (!done) Line 2112  while (!done)
2112        /* 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
2113        value, but it varies, depending on the computer architecture, and        value, but it varies, depending on the computer architecture, and
2114        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
2115        flipped.) */        flipped.) If study was forced by an external -s, don't show this
2116          information unless -i or -d was also present. This means that, except
2117          when auto-callouts are involved, the output from runs with and without
2118          -s should be identical. */
2119    
2120        if (do_study || force_study)        if (do_study || (force_study >= 0 && showinfo && !no_force_study))
2121          {          {
2122          if (extra == NULL)          if (extra == NULL)
2123            fprintf(outfile, "Study returned NULL\n");            fprintf(outfile, "Study returned NULL\n");
# Line 2095  while (!done) Line 2161  while (!done)
2161              fprintf(outfile, "\n");              fprintf(outfile, "\n");
2162              }              }
2163            }            }
2164    
2165            /* Show this only if the JIT was set by /S, not by -s. */
2166    
2167            if ((study_options & PCRE_STUDY_JIT_COMPILE) != 0)
2168              {
2169              int jit;
2170              new_info(re, extra, PCRE_INFO_JIT, &jit);
2171              if (jit)
2172                fprintf(outfile, "JIT study was successful\n");
2173              else
2174    #ifdef SUPPORT_JIT
2175                fprintf(outfile, "JIT study was not successful\n");
2176    #else
2177                fprintf(outfile, "JIT support is not available in this version of PCRE\n");
2178    #endif
2179              }
2180          }          }
2181        }        }
2182    
# Line 2129  while (!done) Line 2211  while (!done)
2211            }            }
2212          else          else
2213            {            {
2214            fprintf(outfile, "Compiled regex written to %s\n", to_file);            fprintf(outfile, "Compiled pattern written to %s\n", to_file);
2215    
2216              /* If there is study data, write it. */
2217    
2218            if (extra != NULL)            if (extra != NULL)
2219              {              {
2220              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 2224  while (!done)
2224                  strerror(errno));                  strerror(errno));
2225                }                }
2226              else fprintf(outfile, "Study data written to %s\n", to_file);              else fprintf(outfile, "Study data written to %s\n", to_file);
   
2227              }              }
2228            }            }
2229          fclose(f);          fclose(f);
2230          }          }
2231    
2232        new_free(re);        new_free(re);
2233        if (extra != NULL) new_free(extra);        if (extra != NULL) pcre_free_study(extra);
2234        if (locale_set)        if (locale_set)
2235          {          {
2236          new_free((void *)tables);          new_free((void *)tables);
# Line 2188  while (!done) Line 2272  while (!done)
2272    
2273      pcre_callout = callout;      pcre_callout = callout;
2274      first_callout = 1;      first_callout = 1;
2275        last_callout_mark = NULL;
2276      callout_extra = 0;      callout_extra = 0;
2277      callout_count = 0;      callout_count = 0;
2278      callout_fail_count = 999999;      callout_fail_count = 999999;
# Line 2266  while (!done) Line 2351  while (!done)
2351            {            {
2352            unsigned char *pt = p;            unsigned char *pt = p;
2353            c = 0;            c = 0;
2354            while (isxdigit(*(++pt)))  
2355              c = c * 16 + tolower(*pt) - ((isdigit(*pt))? '0' : 'W');            /* We used to have "while (isxdigit(*(++pt)))" here, but it fails
2356              when isxdigit() is a macro that refers to its argument more than
2357              once. This is banned by the C Standard, but apparently happens in at
2358              least one MacOS environment. */
2359    
2360              for (pt++; isxdigit(*pt); pt++)
2361                c = c * 16 + tolower(*pt) - ((isdigit(*pt))? '0' : 'a' - 10);
2362            if (*pt == '}')            if (*pt == '}')
2363              {              {
2364              unsigned char buff8[8];              unsigned char buff8[8];
# Line 2297  while (!done) Line 2388  while (!done)
2388          c = 0;          c = 0;
2389          while (i++ < 2 && isxdigit(*p))          while (i++ < 2 && isxdigit(*p))
2390            {            {
2391            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'W');            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);
2392            p++;            p++;
2393            }            }
2394          break;          break;
# Line 2413  while (!done) Line 2504  while (!done)
2504            }            }
2505          continue;          continue;
2506    
2507            case 'J':
2508            while(isdigit(*p)) n = n * 10 + *p++ - '0';
2509            if (extra != NULL
2510                && (extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0
2511                && extra->executable_jit != NULL)
2512              {
2513              if (jit_stack != NULL) pcre_jit_stack_free(jit_stack);
2514              jit_stack = pcre_jit_stack_alloc(1, n * 1024);
2515              pcre_assign_jit_stack(extra, jit_callback, jit_stack);
2516              }
2517            continue;
2518    
2519          case 'L':          case 'L':
2520          getlist = 1;          getlist = 1;
2521          continue;          continue;
# Line 2571  while (!done) Line 2674  while (!done)
2674              (void)pchars(dbuffer + pmatch[i].rm_so,              (void)pchars(dbuffer + pmatch[i].rm_so,
2675                pmatch[i].rm_eo - pmatch[i].rm_so, outfile);                pmatch[i].rm_eo - pmatch[i].rm_so, outfile);
2676              fprintf(outfile, "\n");              fprintf(outfile, "\n");
2677              if (i == 0 && do_showrest)              if (do_showcaprest || (i == 0 && do_showrest))
2678                {                {
2679                fprintf(outfile, " 0+ ");                fprintf(outfile, "%2d+ ", (int)i);
2680                (void)pchars(dbuffer + pmatch[i].rm_eo, len - pmatch[i].rm_eo,                (void)pchars(dbuffer + pmatch[i].rm_eo, len - pmatch[i].rm_eo,
2681                  outfile);                  outfile);
2682                fprintf(outfile, "\n");                fprintf(outfile, "\n");
# Line 2623  while (!done) Line 2726  while (!done)
2726    
2727        /* If find_match_limit is set, we want to do repeated matches with        /* If find_match_limit is set, we want to do repeated matches with
2728        varying limits in order to find the minimum value for the match limit and        varying limits in order to find the minimum value for the match limit and
2729        for the recursion limit. */        for the recursion limit. The match limits are relevant only to the normal
2730          running of pcre_exec(), so disable the JIT optimization. This makes it
2731          possible to run the same set of tests with and without JIT externally
2732          requested. */
2733    
2734        if (find_match_limit)        if (find_match_limit)
2735          {          {
# Line 2632  while (!done) Line 2738  while (!done)
2738            extra = (pcre_extra *)malloc(sizeof(pcre_extra));            extra = (pcre_extra *)malloc(sizeof(pcre_extra));
2739            extra->flags = 0;            extra->flags = 0;
2740            }            }
2741            else extra->flags &= ~PCRE_EXTRA_EXECUTABLE_JIT;
2742    
2743          (void)check_match_limit(re, extra, bptr, len, start_offset,          (void)check_match_limit(re, extra, bptr, len, start_offset,
2744            options|g_notempty, use_offsets, use_size_offsets,            options|g_notempty, use_offsets, use_size_offsets,
# Line 2715  while (!done) Line 2822  while (!done)
2822              }              }
2823            }            }
2824    
2825            /* do_allcaps requests showing of all captures in the pattern, to check
2826            unset ones at the end. */
2827    
2828            if (do_allcaps)
2829              {
2830              new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count);
2831              count++;   /* Allow for full match */
2832              if (count * 2 > use_size_offsets) count = use_size_offsets/2;
2833              }
2834    
2835            /* Output the captured substrings */
2836    
2837          for (i = 0; i < count * 2; i += 2)          for (i = 0; i < count * 2; i += 2)
2838            {            {
2839            if (use_offsets[i] < 0)            if (use_offsets[i] < 0)
2840                {
2841                if (use_offsets[i] != -1)
2842                  fprintf(outfile, "ERROR: bad negative value %d for offset %d\n",
2843                    use_offsets[i], i);
2844                if (use_offsets[i+1] != -1)
2845                  fprintf(outfile, "ERROR: bad negative value %d for offset %d\n",
2846                    use_offsets[i+1], i+1);
2847              fprintf(outfile, "%2d: <unset>\n", i/2);              fprintf(outfile, "%2d: <unset>\n", i/2);
2848                }
2849            else            else
2850              {              {
2851              fprintf(outfile, "%2d: ", i/2);              fprintf(outfile, "%2d: ", i/2);
2852              (void)pchars(bptr + use_offsets[i],              (void)pchars(bptr + use_offsets[i],
2853                use_offsets[i+1] - use_offsets[i], outfile);                use_offsets[i+1] - use_offsets[i], outfile);
2854              fprintf(outfile, "\n");              fprintf(outfile, "\n");
2855              if (i == 0)              if (do_showcaprest || (i == 0 && do_showrest))
2856                {                {
2857                if (do_showrest)                fprintf(outfile, "%2d+ ", i/2);
2858                  {                (void)pchars(bptr + use_offsets[i+1], len - use_offsets[i+1],
2859                  fprintf(outfile, " 0+ ");                  outfile);
2860                  (void)pchars(bptr + use_offsets[i+1], len - use_offsets[i+1],                fprintf(outfile, "\n");
                   outfile);  
                 fprintf(outfile, "\n");  
                 }  
2861                }                }
2862              }              }
2863            }            }
# Line 2813  while (!done) Line 2937  while (!done)
2937                fprintf(outfile, "%2dL %s\n", i, stringlist[i]);                fprintf(outfile, "%2dL %s\n", i, stringlist[i]);
2938              if (stringlist[i] != NULL)              if (stringlist[i] != NULL)
2939                fprintf(outfile, "string list not terminated by NULL\n");                fprintf(outfile, "string list not terminated by NULL\n");
             /* free((void *)stringlist); */  
2940              pcre_free_substring_list(stringlist);              pcre_free_substring_list(stringlist);
2941              }              }
2942            }            }
# Line 2891  while (!done) Line 3014  while (!done)
3014          else          else
3015            {            {
3016            switch(count)            switch(count)
3017              {              {
3018              case PCRE_ERROR_NOMATCH:              case PCRE_ERROR_NOMATCH:
3019              if (gmatched == 0)              if (gmatched == 0)
3020                {                {
# Line 2899  while (!done) Line 3022  while (!done)
3022                  else fprintf(outfile, "No match, mark = %s\n", markptr);                  else fprintf(outfile, "No match, mark = %s\n", markptr);
3023                }                }
3024              break;              break;
3025    
3026              case PCRE_ERROR_BADUTF8:              case PCRE_ERROR_BADUTF8:
3027              case PCRE_ERROR_SHORTUTF8:              case PCRE_ERROR_SHORTUTF8:
3028              fprintf(outfile, "Error %d (%s UTF-8 string)", count,              fprintf(outfile, "Error %d (%s UTF-8 string)", count,
3029                (count == PCRE_ERROR_BADUTF8)? "bad" : "short");                (count == PCRE_ERROR_BADUTF8)? "bad" : "short");
3030              if (use_size_offsets >= 2)              if (use_size_offsets >= 2)
3031                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],
3032                  use_offsets[1]);                  use_offsets[1]);
3033              fprintf(outfile, "\n");              fprintf(outfile, "\n");
3034              break;              break;
3035    
3036              default:              default:
3037              if (count < 0 && (-count) < sizeof(errtexts)/sizeof(const char *))              if (count < 0 && (-count) < sizeof(errtexts)/sizeof(const char *))
3038                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);                fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);
3039              else              else
3040                fprintf(outfile, "Error %d (Unexpected value)\n", count);                fprintf(outfile, "Error %d (Unexpected value)\n", count);
3041              break;              break;
3042              }              }
3043    
3044            break;  /* Out of the /g loop */            break;  /* Out of the /g loop */
3045            }            }
3046          }          }
# Line 2964  while (!done) Line 3087  while (!done)
3087  #endif  #endif
3088    
3089    if (re != NULL) new_free(re);    if (re != NULL) new_free(re);
3090    if (extra != NULL) new_free(extra);    if (extra != NULL) pcre_free_study(extra);
3091    if (locale_set)    if (locale_set)
3092      {      {
3093      new_free((void *)tables);      new_free((void *)tables);
3094      setlocale(LC_CTYPE, "C");      setlocale(LC_CTYPE, "C");
3095      locale_set = 0;      locale_set = 0;
3096      }      }
3097      if (jit_stack != NULL)
3098        {
3099        pcre_jit_stack_free(jit_stack);
3100        jit_stack = NULL;
3101        }
3102    }    }
3103    
3104  if (infile == stdin) fprintf(outfile, "\n");  if (infile == stdin) fprintf(outfile, "\n");

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

  ViewVC Help
Powered by ViewVC 1.1.5