/[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 289 by ph10, Sun Dec 23 12:17:20 2007 UTC revision 512 by ph10, Tue Mar 30 11:11:52 2010 UTC
# Line 49  POSSIBILITY OF SUCH DAMAGE. Line 49  POSSIBILITY OF SUCH DAMAGE.
49  #include <errno.h>  #include <errno.h>
50    
51  #ifdef SUPPORT_LIBREADLINE  #ifdef SUPPORT_LIBREADLINE
52    #ifdef HAVE_UNISTD_H
53  #include <unistd.h>  #include <unistd.h>
54    #endif
55  #include <readline/readline.h>  #include <readline/readline.h>
56  #include <readline/history.h>  #include <readline/history.h>
57  #endif  #endif
# Line 69  input mode under Windows. */ Line 71  input mode under Windows. */
71  #define INPUT_MODE   "r"  #define INPUT_MODE   "r"
72  #define OUTPUT_MODE  "wb"  #define OUTPUT_MODE  "wb"
73    
74    #ifndef isatty
75    #define isatty _isatty         /* This is what Windows calls them, I'm told, */
76    #endif                         /* though in some environments they seem to   */
77                                   /* be already defined, hence the #ifndefs.    */
78    #ifndef fileno
79    #define fileno _fileno
80    #endif
81    
82  #else  #else
83  #include <sys/time.h>          /* These two includes are needed */  #include <sys/time.h>          /* These two includes are needed */
84  #include <sys/resource.h>      /* for setrlimit(). */  #include <sys/resource.h>      /* for setrlimit(). */
# Line 89  appropriately for an application, not fo Line 99  appropriately for an application, not fo
99  #include "pcre.h"  #include "pcre.h"
100  #include "pcre_internal.h"  #include "pcre_internal.h"
101    
102  /* We need access to the data tables that PCRE uses. So as not to have to keep  /* We need access to some of the data tables that PCRE uses. So as not to have
103  two copies, we include the source file here, changing the names of the external  to keep two copies, we include the source file here, changing the names of the
104  symbols to prevent clashes. */  external symbols to prevent clashes. */
105    
106    #define _pcre_ucp_gentype      ucp_gentype
107  #define _pcre_utf8_table1      utf8_table1  #define _pcre_utf8_table1      utf8_table1
108  #define _pcre_utf8_table1_size utf8_table1_size  #define _pcre_utf8_table1_size utf8_table1_size
109  #define _pcre_utf8_table2      utf8_table2  #define _pcre_utf8_table2      utf8_table2
# Line 107  symbols to prevent clashes. */ Line 118  symbols to prevent clashes. */
118    
119  /* We also need the pcre_printint() function for printing out compiled  /* We also need the pcre_printint() function for printing out compiled
120  patterns. This function is in a separate file so that it can be included in  patterns. This function is in a separate file so that it can be included in
121  pcre_compile.c when that module is compiled with debugging enabled.  pcre_compile.c when that module is compiled with debugging enabled. It needs to
122    know which case is being compiled. */
 The definition of the macro PRINTABLE, which determines whether to print an  
 output character as-is or as a hex value when showing compiled patterns, is  
 contained in this file. We uses it here also, in cases when the locale has not  
 been explicitly changed, so as to get consistent output from systems that  
 differ in their output from isprint() even in the "C" locale. */  
123    
124    #define COMPILING_PCRETEST
125  #include "pcre_printint.src"  #include "pcre_printint.src"
126    
127  #define PRINTHEX(c) (locale_set? isprint(c) : PRINTABLE(c))  /* The definition of the macro PRINTABLE, which determines whether to print an
128    output character as-is or as a hex value when showing compiled patterns, is
129    contained in the printint.src file. We uses it here also, in cases when the
130    locale has not been explicitly changed, so as to get consistent output from
131    systems that differ in their output from isprint() even in the "C" locale. */
132    
133    #define PRINTHEX(c) (locale_set? isprint(c) : PRINTABLE(c))
134    
135  /* It is possible to compile this test program without including support for  /* It is possible to compile this test program without including support for
136  testing the POSIX interface, though this is not available via the standard  testing the POSIX interface, though this is not available via the standard
# Line 779  printf("  -dfa     force DFA matching fo Line 791  printf("  -dfa     force DFA matching fo
791  #endif  #endif
792  printf("  -help    show usage information\n");  printf("  -help    show usage information\n");
793  printf("  -i       show information about compiled patterns\n"  printf("  -i       show information about compiled patterns\n"
794           "  -M       find MATCH_LIMIT minimum for each subject\n"
795         "  -m       output memory used information\n"         "  -m       output memory used information\n"
796         "  -o <n>   set size of offsets vector to <n>\n");         "  -o <n>   set size of offsets vector to <n>\n");
797  #if !defined NOPOSIX  #if !defined NOPOSIX
# Line 808  int main(int argc, char **argv) Line 821  int main(int argc, char **argv)
821  FILE *infile = stdin;  FILE *infile = stdin;
822  int options = 0;  int options = 0;
823  int study_options = 0;  int study_options = 0;
824    int default_find_match_limit = FALSE;
825  int op = 1;  int op = 1;
826  int timeit = 0;  int timeit = 0;
827  int timeitm = 0;  int timeitm = 0;
# Line 867  while (argc > 1 && argv[op][0] == '-') Line 881  while (argc > 1 && argv[op][0] == '-')
881    else if (strcmp(argv[op], "-b") == 0) debug = 1;    else if (strcmp(argv[op], "-b") == 0) debug = 1;
882    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;
883    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;
884      else if (strcmp(argv[op], "-M") == 0) default_find_match_limit = TRUE;
885  #if !defined NODFA  #if !defined NODFA
886    else if (strcmp(argv[op], "-dfa") == 0) all_use_dfa = 1;    else if (strcmp(argv[op], "-dfa") == 0) all_use_dfa = 1;
887  #endif  #endif
# Line 919  while (argc > 1 && argv[op][0] == '-') Line 934  while (argc > 1 && argv[op][0] == '-')
934    else if (strcmp(argv[op], "-C") == 0)    else if (strcmp(argv[op], "-C") == 0)
935      {      {
936      int rc;      int rc;
937        unsigned long int lrc;
938      printf("PCRE version %s\n", pcre_version());      printf("PCRE version %s\n", pcre_version());
939      printf("Compiled with\n");      printf("Compiled with\n");
940      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
# Line 926  while (argc > 1 && argv[op][0] == '-') Line 942  while (argc > 1 && argv[op][0] == '-')
942      (void)pcre_config(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);      (void)pcre_config(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
943      printf("  %sUnicode properties support\n", rc? "" : "No ");      printf("  %sUnicode properties support\n", rc? "" : "No ");
944      (void)pcre_config(PCRE_CONFIG_NEWLINE, &rc);      (void)pcre_config(PCRE_CONFIG_NEWLINE, &rc);
945      printf("  Newline sequence is %s\n", (rc == '\r')? "CR" :      /* Note that these values are always the ASCII values, even
946        (rc == '\n')? "LF" : (rc == ('\r'<<8 | '\n'))? "CRLF" :      in EBCDIC environments. CR is 13 and NL is 10. */
947        printf("  Newline sequence is %s\n", (rc == 13)? "CR" :
948          (rc == 10)? "LF" : (rc == (13<<8 | 10))? "CRLF" :
949        (rc == -2)? "ANYCRLF" :        (rc == -2)? "ANYCRLF" :
950        (rc == -1)? "ANY" : "???");        (rc == -1)? "ANY" : "???");
951      (void)pcre_config(PCRE_CONFIG_BSR, &rc);      (void)pcre_config(PCRE_CONFIG_BSR, &rc);
# Line 937  while (argc > 1 && argv[op][0] == '-') Line 955  while (argc > 1 && argv[op][0] == '-')
955      printf("  Internal link size = %d\n", rc);      printf("  Internal link size = %d\n", rc);
956      (void)pcre_config(PCRE_CONFIG_POSIX_MALLOC_THRESHOLD, &rc);      (void)pcre_config(PCRE_CONFIG_POSIX_MALLOC_THRESHOLD, &rc);
957      printf("  POSIX malloc threshold = %d\n", rc);      printf("  POSIX malloc threshold = %d\n", rc);
958      (void)pcre_config(PCRE_CONFIG_MATCH_LIMIT, &rc);      (void)pcre_config(PCRE_CONFIG_MATCH_LIMIT, &lrc);
959      printf("  Default match limit = %d\n", rc);      printf("  Default match limit = %ld\n", lrc);
960      (void)pcre_config(PCRE_CONFIG_MATCH_LIMIT_RECURSION, &rc);      (void)pcre_config(PCRE_CONFIG_MATCH_LIMIT_RECURSION, &lrc);
961      printf("  Default recursion depth limit = %d\n", rc);      printf("  Default recursion depth limit = %ld\n", lrc);
962      (void)pcre_config(PCRE_CONFIG_STACKRECURSE, &rc);      (void)pcre_config(PCRE_CONFIG_STACKRECURSE, &rc);
963      printf("  Match recursion uses %s\n", rc? "stack" : "heap");      printf("  Match recursion uses %s\n", rc? "stack" : "heap");
964      goto EXIT;      goto EXIT;
# Line 1022  while (!done) Line 1040  while (!done)
1040  #endif  #endif
1041    
1042    const char *error;    const char *error;
1043      unsigned char *markptr;
1044    unsigned char *p, *pp, *ppp;    unsigned char *p, *pp, *ppp;
1045    unsigned char *to_file = NULL;    unsigned char *to_file = NULL;
1046    const unsigned char *tables = NULL;    const unsigned char *tables = NULL;
1047    unsigned long int true_size, true_study_size = 0;    unsigned long int true_size, true_study_size = 0;
1048    size_t size, regex_gotten_store;    size_t size, regex_gotten_store;
1049      int do_mark = 0;
1050    int do_study = 0;    int do_study = 0;
1051    int do_debug = debug;    int do_debug = debug;
1052    int do_G = 0;    int do_G = 0;
# Line 1208  while (!done) Line 1228  while (!done)
1228        case 'G': do_G = 1; break;        case 'G': do_G = 1; break;
1229        case 'I': do_showinfo = 1; break;        case 'I': do_showinfo = 1; break;
1230        case 'J': options |= PCRE_DUPNAMES; break;        case 'J': options |= PCRE_DUPNAMES; break;
1231          case 'K': do_mark = 1; break;
1232        case 'M': log_store = 1; break;        case 'M': log_store = 1; break;
1233        case 'N': options |= PCRE_NO_AUTO_CAPTURE; break;        case 'N': options |= PCRE_NO_AUTO_CAPTURE; break;
1234    
# Line 1247  while (!done) Line 1268  while (!done)
1268    
1269        case '<':        case '<':
1270          {          {
1271          int x = check_newline(pp, outfile);          if (strncmp((char *)pp, "JS>", 3) == 0)
1272          if (x == 0) goto SKIP_DATA;            {
1273          options |= x;            options |= PCRE_JAVASCRIPT_COMPAT;
1274          while (*pp++ != '>');            pp += 3;
1275              }
1276            else
1277              {
1278              int x = check_newline(pp, outfile);
1279              if (x == 0) goto SKIP_DATA;
1280              options |= x;
1281              while (*pp++ != '>');
1282              }
1283          }          }
1284        break;        break;
1285    
# Line 1280  while (!done) Line 1309  while (!done)
1309      if ((options & PCRE_DOTALL) != 0) cflags |= REG_DOTALL;      if ((options & PCRE_DOTALL) != 0) cflags |= REG_DOTALL;
1310      if ((options & PCRE_NO_AUTO_CAPTURE) != 0) cflags |= REG_NOSUB;      if ((options & PCRE_NO_AUTO_CAPTURE) != 0) cflags |= REG_NOSUB;
1311      if ((options & PCRE_UTF8) != 0) cflags |= REG_UTF8;      if ((options & PCRE_UTF8) != 0) cflags |= REG_UTF8;
1312        if ((options & PCRE_UNGREEDY) != 0) cflags |= REG_UNGREEDY;
1313    
1314      rc = regcomp(&preg, (char *)p, cflags);      rc = regcomp(&preg, (char *)p, cflags);
1315    
# Line 1300  while (!done) Line 1330  while (!done)
1330  #endif  /* !defined NOPOSIX */  #endif  /* !defined NOPOSIX */
1331    
1332      {      {
1333        unsigned long int get_options;
1334    
1335      if (timeit > 0)      if (timeit > 0)
1336        {        {
1337        register int i;        register int i;
# Line 1343  while (!done) Line 1375  while (!done)
1375        goto CONTINUE;        goto CONTINUE;
1376        }        }
1377    
1378      /* Compilation succeeded; print data if required. There are now two      /* Compilation succeeded. It is now possible to set the UTF-8 option from
1379      info-returning functions. The old one has a limited interface and      within the regex; check for this so that we know how to process the data
1380      returns only limited data. Check that it agrees with the newer one. */      lines. */
1381    
1382        new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);
1383        if ((get_options & PCRE_UTF8) != 0) use_utf8 = 1;
1384    
1385        /* Print information if required. There are now two info-returning
1386        functions. The old one has a limited interface and returns only limited
1387        data. Check that it agrees with the newer one. */
1388    
1389      if (log_store)      if (log_store)
1390        fprintf(outfile, "Memory allocation (code space): %d\n",        fprintf(outfile, "Memory allocation (code space): %d\n",
# Line 1384  while (!done) Line 1423  while (!done)
1423          true_study_size = ((pcre_study_data *)(extra->study_data))->size;          true_study_size = ((pcre_study_data *)(extra->study_data))->size;
1424        }        }
1425    
1426        /* If /K was present, we set up for handling MARK data. */
1427    
1428        if (do_mark)
1429          {
1430          if (extra == NULL)
1431            {
1432            extra = (pcre_extra *)malloc(sizeof(pcre_extra));
1433            extra->flags = 0;
1434            }
1435          extra->mark = &markptr;
1436          extra->flags |= PCRE_EXTRA_MARK;
1437          }
1438    
1439      /* If the 'F' option was present, we flip the bytes of all the integer      /* If the 'F' option was present, we flip the bytes of all the integer
1440      fields in the regex data block and the study block. This is to make it      fields in the regex data block and the study block. This is to make it
1441      possible to test PCRE's handling of byte-flipped patterns, e.g. those      possible to test PCRE's handling of byte-flipped patterns, e.g. those
# Line 1416  while (!done) Line 1468  while (!done)
1468          {          {
1469          pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);          pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
1470          rsd->size = byteflip(rsd->size, sizeof(rsd->size));          rsd->size = byteflip(rsd->size, sizeof(rsd->size));
1471          rsd->options = byteflip(rsd->options, sizeof(rsd->options));          rsd->flags = byteflip(rsd->flags, sizeof(rsd->flags));
1472            rsd->minlength = byteflip(rsd->minlength, sizeof(rsd->minlength));
1473          }          }
1474        }        }
1475    
# Line 1430  while (!done) Line 1483  while (!done)
1483        pcre_printint(re, outfile, debug_lengths);        pcre_printint(re, outfile, debug_lengths);
1484        }        }
1485    
1486        /* We already have the options in get_options (see above) */
1487    
1488      if (do_showinfo)      if (do_showinfo)
1489        {        {
1490        unsigned long int get_options, all_options;        unsigned long int all_options;
1491  #if !defined NOINFOCHECK  #if !defined NOINFOCHECK
1492        int old_first_char, old_options, old_count;        int old_first_char, old_options, old_count;
1493  #endif  #endif
# Line 1441  while (!done) Line 1496  while (!done)
1496        int nameentrysize, namecount;        int nameentrysize, namecount;
1497        const uschar *nametable;        const uschar *nametable;
1498    
       new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);  
1499        new_info(re, NULL, PCRE_INFO_SIZE, &size);        new_info(re, NULL, PCRE_INFO_SIZE, &size);
1500        new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count);        new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count);
1501        new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax);        new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax);
# Line 1592  while (!done) Line 1646  while (!done)
1646          else          else
1647            {            {
1648            uschar *start_bits = NULL;            uschar *start_bits = NULL;
1649            new_info(re, extra, PCRE_INFO_FIRSTTABLE, &start_bits);            int minlength;
1650    
1651              new_info(re, extra, PCRE_INFO_MINLENGTH, &minlength);
1652              fprintf(outfile, "Subject length lower bound = %d\n", minlength);
1653    
1654              new_info(re, extra, PCRE_INFO_FIRSTTABLE, &start_bits);
1655            if (start_bits == NULL)            if (start_bits == NULL)
1656              fprintf(outfile, "No starting byte set\n");              fprintf(outfile, "No set of starting bytes\n");
1657            else            else
1658              {              {
1659              int i;              int i;
# Line 1694  while (!done) Line 1752  while (!done)
1752      int callout_data_set = 0;      int callout_data_set = 0;
1753      int count, c;      int count, c;
1754      int copystrings = 0;      int copystrings = 0;
1755      int find_match_limit = 0;      int find_match_limit = default_find_match_limit;
1756      int getstrings = 0;      int getstrings = 0;
1757      int getlist = 0;      int getlist = 0;
1758      int gmatched = 0;      int gmatched = 0;
# Line 1792  while (!done) Line 1850  while (!done)
1850              {              {
1851              unsigned char buff8[8];              unsigned char buff8[8];
1852              int ii, utn;              int ii, utn;
1853              utn = ord2utf8(c, buff8);              if (use_utf8)
1854              for (ii = 0; ii < utn - 1; ii++) *q++ = buff8[ii];                {
1855              c = buff8[ii];   /* Last byte */                utn = ord2utf8(c, buff8);
1856                  for (ii = 0; ii < utn - 1; ii++) *q++ = buff8[ii];
1857                  c = buff8[ii];   /* Last byte */
1858                  }
1859                else
1860                 {
1861                 if (c > 255)
1862                   fprintf(outfile, "** Character \\x{%x} is greater than 255 and "
1863                     "UTF-8 mode is not enabled.\n"
1864                     "** Truncation will probably give the wrong result.\n", c);
1865                 }
1866              p = pt + 1;              p = pt + 1;
1867              break;              break;
1868              }              }
# Line 1924  while (!done) Line 1992  while (!done)
1992          continue;          continue;
1993    
1994          case 'N':          case 'N':
1995          options |= PCRE_NOTEMPTY;          if ((options & PCRE_NOTEMPTY) != 0)
1996              options = (options & ~PCRE_NOTEMPTY) | PCRE_NOTEMPTY_ATSTART;
1997            else
1998              options |= PCRE_NOTEMPTY;
1999          continue;          continue;
2000    
2001          case 'O':          case 'O':
# Line 1947  while (!done) Line 2018  while (!done)
2018          continue;          continue;
2019    
2020          case 'P':          case 'P':
2021          options |= PCRE_PARTIAL;          options |= ((options & PCRE_PARTIAL_SOFT) == 0)?
2022              PCRE_PARTIAL_SOFT : PCRE_PARTIAL_HARD;
2023          continue;          continue;
2024    
2025          case 'Q':          case 'Q':
# Line 1982  while (!done) Line 2054  while (!done)
2054          show_malloc = 1;          show_malloc = 1;
2055          continue;          continue;
2056    
2057            case 'Y':
2058            options |= PCRE_NO_START_OPTIMIZE;
2059            continue;
2060    
2061          case 'Z':          case 'Z':
2062          options |= PCRE_NOTEOL;          options |= PCRE_NOTEOL;
2063          continue;          continue;
# Line 2004  while (!done) Line 2080  while (!done)
2080      *q = 0;      *q = 0;
2081      len = q - dbuffer;      len = q - dbuffer;
2082    
2083        /* Move the data to the end of the buffer so that a read over the end of
2084        the buffer will be seen by valgrind, even if it doesn't cause a crash. If
2085        we are using the POSIX interface, we must include the terminating zero. */
2086    
2087    #if !defined NOPOSIX
2088        if (posix || do_posix)
2089          {
2090          memmove(bptr + buffer_size - len - 1, bptr, len + 1);
2091          bptr += buffer_size - len - 1;
2092          }
2093        else
2094    #endif
2095          {
2096          memmove(bptr + buffer_size - len, bptr, len);
2097          bptr += buffer_size - len;
2098          }
2099    
2100      if ((all_use_dfa || use_dfa) && find_match_limit)      if ((all_use_dfa || use_dfa) && find_match_limit)
2101        {        {
2102        printf("**Match limit not relevant for DFA matching: ignored\n");        printf("**Match limit not relevant for DFA matching: ignored\n");
# Line 2023  while (!done) Line 2116  while (!done)
2116          pmatch = (regmatch_t *)malloc(sizeof(regmatch_t) * use_size_offsets);          pmatch = (regmatch_t *)malloc(sizeof(regmatch_t) * use_size_offsets);
2117        if ((options & PCRE_NOTBOL) != 0) eflags |= REG_NOTBOL;        if ((options & PCRE_NOTBOL) != 0) eflags |= REG_NOTBOL;
2118        if ((options & PCRE_NOTEOL) != 0) eflags |= REG_NOTEOL;        if ((options & PCRE_NOTEOL) != 0) eflags |= REG_NOTEOL;
2119          if ((options & PCRE_NOTEMPTY) != 0) eflags |= REG_NOTEMPTY;
2120    
2121        rc = regexec(&preg, (const char *)bptr, use_size_offsets, pmatch, eflags);        rc = regexec(&preg, (const char *)bptr, use_size_offsets, pmatch, eflags);
2122    
# Line 2067  while (!done) Line 2161  while (!done)
2161    
2162      for (;; gmatched++)    /* Loop for /g or /G */      for (;; gmatched++)    /* Loop for /g or /G */
2163        {        {
2164          markptr = NULL;
2165    
2166        if (timeitm > 0)        if (timeitm > 0)
2167          {          {
2168          register int i;          register int i;
# Line 2078  while (!done) Line 2174  while (!done)
2174            {            {
2175            int workspace[1000];            int workspace[1000];
2176            for (i = 0; i < timeitm; i++)            for (i = 0; i < timeitm; i++)
2177              count = pcre_dfa_exec(re, NULL, (char *)bptr, len, start_offset,              count = pcre_dfa_exec(re, extra, (char *)bptr, len, start_offset,
2178                options | g_notempty, use_offsets, use_size_offsets, workspace,                options | g_notempty, use_offsets, use_size_offsets, workspace,
2179                sizeof(workspace)/sizeof(int));                sizeof(workspace)/sizeof(int));
2180            }            }
# Line 2141  while (!done) Line 2237  while (!done)
2237        else if (all_use_dfa || use_dfa)        else if (all_use_dfa || use_dfa)
2238          {          {
2239          int workspace[1000];          int workspace[1000];
2240          count = pcre_dfa_exec(re, NULL, (char *)bptr, len, start_offset,          count = pcre_dfa_exec(re, extra, (char *)bptr, len, start_offset,
2241            options | g_notempty, use_offsets, use_size_offsets, workspace,            options | g_notempty, use_offsets, use_size_offsets, workspace,
2242            sizeof(workspace)/sizeof(int));            sizeof(workspace)/sizeof(int));
2243          if (count == 0)          if (count == 0)
# Line 2212  while (!done) Line 2308  while (!done)
2308              }              }
2309            }            }
2310    
2311            if (markptr != NULL) fprintf(outfile, "MK: %s\n", markptr);
2312    
2313          for (i = 0; i < 32; i++)          for (i = 0; i < 32; i++)
2314            {            {
2315            if ((copystrings & (1 << i)) != 0)            if ((copystrings & (1 << i)) != 0)
# Line 2295  while (!done) Line 2393  while (!done)
2393    
2394        else if (count == PCRE_ERROR_PARTIAL)        else if (count == PCRE_ERROR_PARTIAL)
2395          {          {
2396          fprintf(outfile, "Partial match");          if (markptr == NULL) fprintf(outfile, "Partial match");
2397  #if !defined NODFA            else fprintf(outfile, "Partial match, mark=%s", markptr);
2398          if ((all_use_dfa || use_dfa) && use_size_offsets > 2)          if (use_size_offsets > 1)
2399            fprintf(outfile, ": %.*s", use_offsets[1] - use_offsets[0],            {
2400              bptr + use_offsets[0]);            fprintf(outfile, ": ");
2401  #endif            pchars(bptr + use_offsets[0], use_offsets[1] - use_offsets[0],
2402                outfile);
2403              }
2404          fprintf(outfile, "\n");          fprintf(outfile, "\n");
2405          break;  /* Out of the /g loop */          break;  /* Out of the /g loop */
2406          }          }
# Line 2330  while (!done) Line 2430  while (!done)
2430              {              {
2431              int d;              int d;
2432              (void)pcre_config(PCRE_CONFIG_NEWLINE, &d);              (void)pcre_config(PCRE_CONFIG_NEWLINE, &d);
2433              obits = (d == '\r')? PCRE_NEWLINE_CR :              /* Note that these values are always the ASCII ones, even in
2434                      (d == '\n')? PCRE_NEWLINE_LF :              EBCDIC environments. CR = 13, NL = 10. */
2435                      (d == ('\r'<<8 | '\n'))? PCRE_NEWLINE_CRLF :              obits = (d == 13)? PCRE_NEWLINE_CR :
2436                        (d == 10)? PCRE_NEWLINE_LF :
2437                        (d == (13<<8 | 10))? PCRE_NEWLINE_CRLF :
2438                      (d == -2)? PCRE_NEWLINE_ANYCRLF :                      (d == -2)? PCRE_NEWLINE_ANYCRLF :
2439                      (d == -1)? PCRE_NEWLINE_ANY : 0;                      (d == -1)? PCRE_NEWLINE_ANY : 0;
2440              }              }
# Line 2359  while (!done) Line 2461  while (!done)
2461            {            {
2462            if (count == PCRE_ERROR_NOMATCH)            if (count == PCRE_ERROR_NOMATCH)
2463              {              {
2464              if (gmatched == 0) fprintf(outfile, "No match\n");              if (gmatched == 0)
2465                  {
2466                  if (markptr == NULL) fprintf(outfile, "No match\n");
2467                    else fprintf(outfile, "No match, mark = %s\n", markptr);
2468                  }
2469              }              }
2470            else fprintf(outfile, "Error %d\n", count);            else fprintf(outfile, "Error %d\n", count);
2471            break;  /* Out of the /g loop */            break;  /* Out of the /g loop */
# Line 2371  while (!done) Line 2477  while (!done)
2477        if (!do_g && !do_G) break;        if (!do_g && !do_G) break;
2478    
2479        /* If we have matched an empty string, first check to see if we are at        /* If we have matched an empty string, first check to see if we are at
2480        the end of the subject. If so, the /g loop is over. Otherwise, mimic        the end of the subject. If so, the /g loop is over. Otherwise, mimic what
2481        what Perl's /g options does. This turns out to be rather cunning. First        Perl's /g options does. This turns out to be rather cunning. First we set
2482        we set PCRE_NOTEMPTY and PCRE_ANCHORED and try the match again at the        PCRE_NOTEMPTY_ATSTART and PCRE_ANCHORED and try the match again at the
2483        same point. If this fails (picked up above) we advance to the next        same point. If this fails (picked up above) we advance to the next
2484        character. */        character. */
2485    
# Line 2382  while (!done) Line 2488  while (!done)
2488        if (use_offsets[0] == use_offsets[1])        if (use_offsets[0] == use_offsets[1])
2489          {          {
2490          if (use_offsets[0] == len) break;          if (use_offsets[0] == len) break;
2491          g_notempty = PCRE_NOTEMPTY | PCRE_ANCHORED;          g_notempty = PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED;
2492          }          }
2493    
2494        /* For /g, update the start offset, leaving the rest alone */        /* For /g, update the start offset, leaving the rest alone */

Legend:
Removed from v.289  
changed lines
  Added in v.512

  ViewVC Help
Powered by ViewVC 1.1.5