/[pcre]/code/tags/pcre-8.11/pcretest.c
ViewVC logotype

Diff of /code/tags/pcre-8.11/pcretest.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 236 by ph10, Tue Sep 11 12:57:06 2007 UTC revision 498 by ph10, Wed Mar 3 19:29:38 2010 UTC
# Line 48  POSSIBILITY OF SUCH DAMAGE. Line 48  POSSIBILITY OF SUCH DAMAGE.
48  #include <locale.h>  #include <locale.h>
49  #include <errno.h>  #include <errno.h>
50    
51    #ifdef SUPPORT_LIBREADLINE
52    #ifdef HAVE_UNISTD_H
53    #include <unistd.h>
54    #endif
55    #include <readline/readline.h>
56    #include <readline/history.h>
57    #endif
58    
59    
60  /* A number of things vary for Windows builds. Originally, pcretest opened its  /* A number of things vary for Windows builds. Originally, pcretest opened its
61  input and output without "b"; then I was told that "b" was needed in some  input and output without "b"; then I was told that "b" was needed in some
# Line 63  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 83  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 94  symbols to prevent clashes. */ Line 111  symbols to prevent clashes. */
111  #define _pcre_utf8_table4      utf8_table4  #define _pcre_utf8_table4      utf8_table4
112  #define _pcre_utt              utt  #define _pcre_utt              utt
113  #define _pcre_utt_size         utt_size  #define _pcre_utt_size         utt_size
114    #define _pcre_utt_names        utt_names
115  #define _pcre_OP_lengths       OP_lengths  #define _pcre_OP_lengths       OP_lengths
116    
117  #include "pcre_tables.c"  #include "pcre_tables.c"
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 188  optimal way of handling this, but hey, t Line 207  optimal way of handling this, but hey, t
207  Arguments:  Arguments:
208    f            the file to read    f            the file to read
209    start        where in buffer to start (this *must* be within buffer)    start        where in buffer to start (this *must* be within buffer)
210      prompt       for stdin or readline()
211    
212  Returns:       pointer to the start of new data  Returns:       pointer to the start of new data
213                 could be a copy of start, or could be moved                 could be a copy of start, or could be moved
# Line 195  Returns: pointer to the start of n Line 215  Returns: pointer to the start of n
215  */  */
216    
217  static uschar *  static uschar *
218  extend_inputline(FILE *f, uschar *start)  extend_inputline(FILE *f, uschar *start, const char *prompt)
219  {  {
220  uschar *here = start;  uschar *here = start;
221    
# Line 206  for (;;) Line 226  for (;;)
226    if (rlen > 1000)    if (rlen > 1000)
227      {      {
228      int dlen;      int dlen;
229      if (fgets((char *)here, rlen,  f) == NULL)  
230        return (here == start)? NULL : start;      /* If libreadline support is required, use readline() to read a line if the
231        input is a terminal. Note that readline() removes the trailing newline, so
232        we must put it back again, to be compatible with fgets(). */
233    
234    #ifdef SUPPORT_LIBREADLINE
235        if (isatty(fileno(f)))
236          {
237          size_t len;
238          char *s = readline(prompt);
239          if (s == NULL) return (here == start)? NULL : start;
240          len = strlen(s);
241          if (len > 0) add_history(s);
242          if (len > rlen - 1) len = rlen - 1;
243          memcpy(here, s, len);
244          here[len] = '\n';
245          here[len+1] = 0;
246          free(s);
247          }
248        else
249    #endif
250    
251        /* Read the next line by normal means, prompting if the file is stdin. */
252    
253          {
254          if (f == stdin) printf(prompt);
255          if (fgets((char *)here, rlen,  f) == NULL)
256            return (here == start)? NULL : start;
257          }
258    
259      dlen = (int)strlen((char *)here);      dlen = (int)strlen((char *)here);
260      if (dlen > 0 && here[dlen - 1] == '\n') return start;      if (dlen > 0 && here[dlen - 1] == '\n') return start;
261      here += dlen;      here += dlen;
# Line 727  return 0; Line 775  return 0;
775  static void  static void
776  usage(void)  usage(void)
777  {  {
778  printf("Usage:     pcretest [options] [<input> [<output>]]\n");  printf("Usage:     pcretest [options] [<input file> [<output file>]]\n\n");
779    printf("Input and output default to stdin and stdout.\n");
780    #ifdef SUPPORT_LIBREADLINE
781    printf("If input is a terminal, readline() is used to read from it.\n");
782    #else
783    printf("This version of pcretest is not linked with readline().\n");
784    #endif
785    printf("\nOptions:\n");
786  printf("  -b       show compiled code (bytecode)\n");  printf("  -b       show compiled code (bytecode)\n");
787  printf("  -C       show PCRE compile-time options and exit\n");  printf("  -C       show PCRE compile-time options and exit\n");
788  printf("  -d       debug: show compiled code and information (-b and -i)\n");  printf("  -d       debug: show compiled code and information (-b and -i)\n");
# Line 736  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 765  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 824  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 876  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 883  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 894  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 996  while (!done) Line 1057  while (!done)
1057    use_utf8 = 0;    use_utf8 = 0;
1058    debug_lengths = 1;    debug_lengths = 1;
1059    
1060    if (infile == stdin) printf("  re> ");    if (extend_inputline(infile, buffer, "  re> ") == NULL) break;
   if (extend_inputline(infile, buffer) == NULL) break;  
1061    if (infile != stdin) fprintf(outfile, "%s", (char *)buffer);    if (infile != stdin) fprintf(outfile, "%s", (char *)buffer);
1062    fflush(outfile);    fflush(outfile);
1063    
# Line 1097  while (!done) Line 1157  while (!done)
1157    
1158    if (isalnum(delimiter) || delimiter == '\\')    if (isalnum(delimiter) || delimiter == '\\')
1159      {      {
1160      fprintf(outfile, "** Delimiter must not be alphameric or \\\n");      fprintf(outfile, "** Delimiter must not be alphanumeric or \\\n");
1161      goto SKIP_DATA;      goto SKIP_DATA;
1162      }      }
1163    
# Line 1113  while (!done) Line 1173  while (!done)
1173        pp++;        pp++;
1174        }        }
1175      if (*pp != 0) break;      if (*pp != 0) break;
1176      if (infile == stdin) printf("    > ");      if ((pp = extend_inputline(infile, pp, "    > ")) == NULL)
     if ((pp = extend_inputline(infile, pp)) == NULL)  
1177        {        {
1178        fprintf(outfile, "** Unexpected EOF\n");        fprintf(outfile, "** Unexpected EOF\n");
1179        done = 1;        done = 1;
# Line 1206  while (!done) Line 1265  while (!done)
1265    
1266        case '<':        case '<':
1267          {          {
1268          int x = check_newline(pp, outfile);          if (strncmp((char *)pp, "JS>", 3) == 0)
1269          if (x == 0) goto SKIP_DATA;            {
1270          options |= x;            options |= PCRE_JAVASCRIPT_COMPAT;
1271          while (*pp++ != '>');            pp += 3;
1272              }
1273            else
1274              {
1275              int x = check_newline(pp, outfile);
1276              if (x == 0) goto SKIP_DATA;
1277              options |= x;
1278              while (*pp++ != '>');
1279              }
1280          }          }
1281        break;        break;
1282    
# Line 1239  while (!done) Line 1306  while (!done)
1306      if ((options & PCRE_DOTALL) != 0) cflags |= REG_DOTALL;      if ((options & PCRE_DOTALL) != 0) cflags |= REG_DOTALL;
1307      if ((options & PCRE_NO_AUTO_CAPTURE) != 0) cflags |= REG_NOSUB;      if ((options & PCRE_NO_AUTO_CAPTURE) != 0) cflags |= REG_NOSUB;
1308      if ((options & PCRE_UTF8) != 0) cflags |= REG_UTF8;      if ((options & PCRE_UTF8) != 0) cflags |= REG_UTF8;
1309        if ((options & PCRE_UNGREEDY) != 0) cflags |= REG_UNGREEDY;
1310    
1311      rc = regcomp(&preg, (char *)p, cflags);      rc = regcomp(&preg, (char *)p, cflags);
1312    
# Line 1259  while (!done) Line 1327  while (!done)
1327  #endif  /* !defined NOPOSIX */  #endif  /* !defined NOPOSIX */
1328    
1329      {      {
1330        unsigned long int get_options;
1331    
1332      if (timeit > 0)      if (timeit > 0)
1333        {        {
1334        register int i;        register int i;
# Line 1288  while (!done) Line 1358  while (!done)
1358          {          {
1359          for (;;)          for (;;)
1360            {            {
1361            if (extend_inputline(infile, buffer) == NULL)            if (extend_inputline(infile, buffer, NULL) == NULL)
1362              {              {
1363              done = 1;              done = 1;
1364              goto CONTINUE;              goto CONTINUE;
# Line 1302  while (!done) Line 1372  while (!done)
1372        goto CONTINUE;        goto CONTINUE;
1373        }        }
1374    
1375      /* Compilation succeeded; print data if required. There are now two      /* Compilation succeeded. It is now possible to set the UTF-8 option from
1376      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
1377      returns only limited data. Check that it agrees with the newer one. */      lines. */
1378    
1379        new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);
1380        if ((get_options & PCRE_UTF8) != 0) use_utf8 = 1;
1381    
1382        /* Print information if required. There are now two info-returning
1383        functions. The old one has a limited interface and returns only limited
1384        data. Check that it agrees with the newer one. */
1385    
1386      if (log_store)      if (log_store)
1387        fprintf(outfile, "Memory allocation (code space): %d\n",        fprintf(outfile, "Memory allocation (code space): %d\n",
# Line 1351  while (!done) Line 1428  while (!done)
1428      if (do_flip)      if (do_flip)
1429        {        {
1430        real_pcre *rre = (real_pcre *)re;        real_pcre *rre = (real_pcre *)re;
1431        rre->magic_number = byteflip(rre->magic_number, sizeof(rre->magic_number));        rre->magic_number =
1432            byteflip(rre->magic_number, sizeof(rre->magic_number));
1433        rre->size = byteflip(rre->size, sizeof(rre->size));        rre->size = byteflip(rre->size, sizeof(rre->size));
1434        rre->options = byteflip(rre->options, sizeof(rre->options));        rre->options = byteflip(rre->options, sizeof(rre->options));
1435        rre->flags = byteflip(rre->flags, sizeof(rre->flags));        rre->flags = (pcre_uint16)byteflip(rre->flags, sizeof(rre->flags));
1436        rre->top_bracket = byteflip(rre->top_bracket, sizeof(rre->top_bracket));        rre->top_bracket =
1437        rre->top_backref = byteflip(rre->top_backref, sizeof(rre->top_backref));          (pcre_uint16)byteflip(rre->top_bracket, sizeof(rre->top_bracket));
1438        rre->first_byte = byteflip(rre->first_byte, sizeof(rre->first_byte));        rre->top_backref =
1439        rre->req_byte = byteflip(rre->req_byte, sizeof(rre->req_byte));          (pcre_uint16)byteflip(rre->top_backref, sizeof(rre->top_backref));
1440        rre->name_table_offset = byteflip(rre->name_table_offset,        rre->first_byte =
1441            (pcre_uint16)byteflip(rre->first_byte, sizeof(rre->first_byte));
1442          rre->req_byte =
1443            (pcre_uint16)byteflip(rre->req_byte, sizeof(rre->req_byte));
1444          rre->name_table_offset = (pcre_uint16)byteflip(rre->name_table_offset,
1445          sizeof(rre->name_table_offset));          sizeof(rre->name_table_offset));
1446        rre->name_entry_size = byteflip(rre->name_entry_size,        rre->name_entry_size = (pcre_uint16)byteflip(rre->name_entry_size,
1447          sizeof(rre->name_entry_size));          sizeof(rre->name_entry_size));
1448        rre->name_count = byteflip(rre->name_count, sizeof(rre->name_count));        rre->name_count = (pcre_uint16)byteflip(rre->name_count,
1449            sizeof(rre->name_count));
1450    
1451        if (extra != NULL)        if (extra != NULL)
1452          {          {
1453          pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);          pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
1454          rsd->size = byteflip(rsd->size, sizeof(rsd->size));          rsd->size = byteflip(rsd->size, sizeof(rsd->size));
1455          rsd->options = byteflip(rsd->options, sizeof(rsd->options));          rsd->flags = byteflip(rsd->flags, sizeof(rsd->flags));
1456            rsd->minlength = byteflip(rsd->minlength, sizeof(rsd->minlength));
1457          }          }
1458        }        }
1459    
# Line 1383  while (!done) Line 1467  while (!done)
1467        pcre_printint(re, outfile, debug_lengths);        pcre_printint(re, outfile, debug_lengths);
1468        }        }
1469    
1470        /* We already have the options in get_options (see above) */
1471    
1472      if (do_showinfo)      if (do_showinfo)
1473        {        {
1474        unsigned long int get_options, all_options;        unsigned long int all_options;
1475  #if !defined NOINFOCHECK  #if !defined NOINFOCHECK
1476        int old_first_char, old_options, old_count;        int old_first_char, old_options, old_count;
1477  #endif  #endif
# Line 1394  while (!done) Line 1480  while (!done)
1480        int nameentrysize, namecount;        int nameentrysize, namecount;
1481        const uschar *nametable;        const uschar *nametable;
1482    
       new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);  
1483        new_info(re, NULL, PCRE_INFO_SIZE, &size);        new_info(re, NULL, PCRE_INFO_SIZE, &size);
1484        new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count);        new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count);
1485        new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax);        new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax);
# Line 1545  while (!done) Line 1630  while (!done)
1630          else          else
1631            {            {
1632            uschar *start_bits = NULL;            uschar *start_bits = NULL;
1633            new_info(re, extra, PCRE_INFO_FIRSTTABLE, &start_bits);            int minlength;
1634    
1635              new_info(re, extra, PCRE_INFO_MINLENGTH, &minlength);
1636              fprintf(outfile, "Subject length lower bound = %d\n", minlength);
1637    
1638              new_info(re, extra, PCRE_INFO_FIRSTTABLE, &start_bits);
1639            if (start_bits == NULL)            if (start_bits == NULL)
1640              fprintf(outfile, "No starting byte set\n");              fprintf(outfile, "No set of starting bytes\n");
1641            else            else
1642              {              {
1643              int i;              int i;
# Line 1595  while (!done) Line 1684  while (!done)
1684        else        else
1685          {          {
1686          uschar sbuf[8];          uschar sbuf[8];
1687          sbuf[0] = (true_size >> 24)  & 255;          sbuf[0] = (uschar)((true_size >> 24) & 255);
1688          sbuf[1] = (true_size >> 16)  & 255;          sbuf[1] = (uschar)((true_size >> 16) & 255);
1689          sbuf[2] = (true_size >>  8)  & 255;          sbuf[2] = (uschar)((true_size >>  8) & 255);
1690          sbuf[3] = (true_size)  & 255;          sbuf[3] = (uschar)((true_size) & 255);
1691    
1692          sbuf[4] = (true_study_size >> 24)  & 255;          sbuf[4] = (uschar)((true_study_size >> 24) & 255);
1693          sbuf[5] = (true_study_size >> 16)  & 255;          sbuf[5] = (uschar)((true_study_size >> 16) & 255);
1694          sbuf[6] = (true_study_size >>  8)  & 255;          sbuf[6] = (uschar)((true_study_size >>  8) & 255);
1695          sbuf[7] = (true_study_size)  & 255;          sbuf[7] = (uschar)((true_study_size) & 255);
1696    
1697          if (fwrite(sbuf, 1, 8, f) < 8 ||          if (fwrite(sbuf, 1, 8, f) < 8 ||
1698              fwrite(re, 1, true_size, f) < true_size)              fwrite(re, 1, true_size, f) < true_size)
# Line 1647  while (!done) Line 1736  while (!done)
1736      int callout_data_set = 0;      int callout_data_set = 0;
1737      int count, c;      int count, c;
1738      int copystrings = 0;      int copystrings = 0;
1739      int find_match_limit = 0;      int find_match_limit = default_find_match_limit;
1740      int getstrings = 0;      int getstrings = 0;
1741      int getlist = 0;      int getlist = 0;
1742      int gmatched = 0;      int gmatched = 0;
# Line 1677  while (!done) Line 1766  while (!done)
1766      len = 0;      len = 0;
1767      for (;;)      for (;;)
1768        {        {
1769        if (infile == stdin) printf("data> ");        if (extend_inputline(infile, buffer + len, "data> ") == NULL)
       if (extend_inputline(infile, buffer + len) == NULL)  
1770          {          {
1771          if (len > 0) break;          if (len > 0) break;
1772          done = 1;          done = 1;
# Line 1746  while (!done) Line 1834  while (!done)
1834              {              {
1835              unsigned char buff8[8];              unsigned char buff8[8];
1836              int ii, utn;              int ii, utn;
1837              utn = ord2utf8(c, buff8);              if (use_utf8)
1838              for (ii = 0; ii < utn - 1; ii++) *q++ = buff8[ii];                {
1839              c = buff8[ii];   /* Last byte */                utn = ord2utf8(c, buff8);
1840                  for (ii = 0; ii < utn - 1; ii++) *q++ = buff8[ii];
1841                  c = buff8[ii];   /* Last byte */
1842                  }
1843                else
1844                 {
1845                 if (c > 255)
1846                   fprintf(outfile, "** Character \\x{%x} is greater than 255 and "
1847                     "UTF-8 mode is not enabled.\n"
1848                     "** Truncation will probably give the wrong result.\n", c);
1849                 }
1850              p = pt + 1;              p = pt + 1;
1851              break;              break;
1852              }              }
# Line 1878  while (!done) Line 1976  while (!done)
1976          continue;          continue;
1977    
1978          case 'N':          case 'N':
1979          options |= PCRE_NOTEMPTY;          if ((options & PCRE_NOTEMPTY) != 0)
1980              options = (options & ~PCRE_NOTEMPTY) | PCRE_NOTEMPTY_ATSTART;
1981            else
1982              options |= PCRE_NOTEMPTY;
1983          continue;          continue;
1984    
1985          case 'O':          case 'O':
# Line 1901  while (!done) Line 2002  while (!done)
2002          continue;          continue;
2003    
2004          case 'P':          case 'P':
2005          options |= PCRE_PARTIAL;          options |= ((options & PCRE_PARTIAL_SOFT) == 0)?
2006              PCRE_PARTIAL_SOFT : PCRE_PARTIAL_HARD;
2007          continue;          continue;
2008    
2009          case 'Q':          case 'Q':
# Line 1936  while (!done) Line 2038  while (!done)
2038          show_malloc = 1;          show_malloc = 1;
2039          continue;          continue;
2040    
2041            case 'Y':
2042            options |= PCRE_NO_START_OPTIMIZE;
2043            continue;
2044    
2045          case 'Z':          case 'Z':
2046          options |= PCRE_NOTEOL;          options |= PCRE_NOTEOL;
2047          continue;          continue;
# Line 1958  while (!done) Line 2064  while (!done)
2064      *q = 0;      *q = 0;
2065      len = q - dbuffer;      len = q - dbuffer;
2066    
2067        /* Move the data to the end of the buffer so that a read over the end of
2068        the buffer will be seen by valgrind, even if it doesn't cause a crash. If
2069        we are using the POSIX interface, we must include the terminating zero. */
2070    
2071    #if !defined NOPOSIX
2072        if (posix || do_posix)
2073          {
2074          memmove(bptr + buffer_size - len - 1, bptr, len + 1);
2075          bptr += buffer_size - len - 1;
2076          }
2077        else
2078    #endif
2079          {
2080          memmove(bptr + buffer_size - len, bptr, len);
2081          bptr += buffer_size - len;
2082          }
2083    
2084      if ((all_use_dfa || use_dfa) && find_match_limit)      if ((all_use_dfa || use_dfa) && find_match_limit)
2085        {        {
2086        printf("**Match limit not relevant for DFA matching: ignored\n");        printf("**Match limit not relevant for DFA matching: ignored\n");
# Line 1977  while (!done) Line 2100  while (!done)
2100          pmatch = (regmatch_t *)malloc(sizeof(regmatch_t) * use_size_offsets);          pmatch = (regmatch_t *)malloc(sizeof(regmatch_t) * use_size_offsets);
2101        if ((options & PCRE_NOTBOL) != 0) eflags |= REG_NOTBOL;        if ((options & PCRE_NOTBOL) != 0) eflags |= REG_NOTBOL;
2102        if ((options & PCRE_NOTEOL) != 0) eflags |= REG_NOTEOL;        if ((options & PCRE_NOTEOL) != 0) eflags |= REG_NOTEOL;
2103          if ((options & PCRE_NOTEMPTY) != 0) eflags |= REG_NOTEMPTY;
2104    
2105        rc = regexec(&preg, (const char *)bptr, use_size_offsets, pmatch, eflags);        rc = regexec(&preg, (const char *)bptr, use_size_offsets, pmatch, eflags);
2106    
# Line 2032  while (!done) Line 2156  while (!done)
2156            {            {
2157            int workspace[1000];            int workspace[1000];
2158            for (i = 0; i < timeitm; i++)            for (i = 0; i < timeitm; i++)
2159              count = pcre_dfa_exec(re, NULL, (char *)bptr, len, start_offset,              count = pcre_dfa_exec(re, extra, (char *)bptr, len, start_offset,
2160                options | g_notempty, use_offsets, use_size_offsets, workspace,                options | g_notempty, use_offsets, use_size_offsets, workspace,
2161                sizeof(workspace)/sizeof(int));                sizeof(workspace)/sizeof(int));
2162            }            }
# Line 2095  while (!done) Line 2219  while (!done)
2219        else if (all_use_dfa || use_dfa)        else if (all_use_dfa || use_dfa)
2220          {          {
2221          int workspace[1000];          int workspace[1000];
2222          count = pcre_dfa_exec(re, NULL, (char *)bptr, len, start_offset,          count = pcre_dfa_exec(re, extra, (char *)bptr, len, start_offset,
2223            options | g_notempty, use_offsets, use_size_offsets, workspace,            options | g_notempty, use_offsets, use_size_offsets, workspace,
2224            sizeof(workspace)/sizeof(int));            sizeof(workspace)/sizeof(int));
2225          if (count == 0)          if (count == 0)
# Line 2250  while (!done) Line 2374  while (!done)
2374        else if (count == PCRE_ERROR_PARTIAL)        else if (count == PCRE_ERROR_PARTIAL)
2375          {          {
2376          fprintf(outfile, "Partial match");          fprintf(outfile, "Partial match");
2377  #if !defined NODFA          if (use_size_offsets > 1)
2378          if ((all_use_dfa || use_dfa) && use_size_offsets > 2)            {
2379            fprintf(outfile, ": %.*s", use_offsets[1] - use_offsets[0],            fprintf(outfile, ": ");
2380              bptr + use_offsets[0]);            pchars(bptr + use_offsets[0], use_offsets[1] - use_offsets[0],
2381  #endif              outfile);
2382              }
2383          fprintf(outfile, "\n");          fprintf(outfile, "\n");
2384          break;  /* Out of the /g loop */          break;  /* Out of the /g loop */
2385          }          }
# Line 2284  while (!done) Line 2409  while (!done)
2409              {              {
2410              int d;              int d;
2411              (void)pcre_config(PCRE_CONFIG_NEWLINE, &d);              (void)pcre_config(PCRE_CONFIG_NEWLINE, &d);
2412              obits = (d == '\r')? PCRE_NEWLINE_CR :              /* Note that these values are always the ASCII ones, even in
2413                      (d == '\n')? PCRE_NEWLINE_LF :              EBCDIC environments. CR = 13, NL = 10. */
2414                      (d == ('\r'<<8 | '\n'))? PCRE_NEWLINE_CRLF :              obits = (d == 13)? PCRE_NEWLINE_CR :
2415                        (d == 10)? PCRE_NEWLINE_LF :
2416                        (d == (13<<8 | 10))? PCRE_NEWLINE_CRLF :
2417                      (d == -2)? PCRE_NEWLINE_ANYCRLF :                      (d == -2)? PCRE_NEWLINE_ANYCRLF :
2418                      (d == -1)? PCRE_NEWLINE_ANY : 0;                      (d == -1)? PCRE_NEWLINE_ANY : 0;
2419              }              }
# Line 2325  while (!done) Line 2452  while (!done)
2452        if (!do_g && !do_G) break;        if (!do_g && !do_G) break;
2453    
2454        /* 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
2455        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
2456        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
2457        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
2458        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
2459        character. */        character. */
2460    
# Line 2336  while (!done) Line 2463  while (!done)
2463        if (use_offsets[0] == use_offsets[1])        if (use_offsets[0] == use_offsets[1])
2464          {          {
2465          if (use_offsets[0] == len) break;          if (use_offsets[0] == len) break;
2466          g_notempty = PCRE_NOTEMPTY | PCRE_ANCHORED;          g_notempty = PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED;
2467          }          }
2468    
2469        /* For /g, update the start offset, leaving the rest alone */        /* For /g, update the start offset, leaving the rest alone */

Legend:
Removed from v.236  
changed lines
  Added in v.498

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12