/[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 75 by nigel, Sat Feb 24 21:40:37 2007 UTC revision 79 by nigel, Sat Feb 24 21:40:52 2007 UTC
# Line 4  Line 4 
4    
5  /* This program was hacked up as a tester for PCRE. I really should have  /* This program was hacked up as a tester for PCRE. I really should have
6  written it more tidily in the first place. Will I ever learn? It has grown and  written it more tidily in the first place. Will I ever learn? It has grown and
7  been extended and consequently is now rather untidy in places.  been extended and consequently is now rather, er, *very* untidy in places.
8    
9  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
10  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 44  POSSIBILITY OF SUCH DAMAGE. Line 44  POSSIBILITY OF SUCH DAMAGE.
44  #include <locale.h>  #include <locale.h>
45  #include <errno.h>  #include <errno.h>
46    
 /* We need the internal info for displaying the results of pcre_study(). Also  
 for getting the opcodes for showing compiled code. */  
   
47  #define PCRE_SPY        /* For Win32 build, import data, not export */  #define PCRE_SPY        /* For Win32 build, import data, not export */
48  #include "internal.h"  
49    /* We need the internal info for displaying the results of pcre_study() and
50    other internal data; pcretest also uses some of the fixed tables, and generally
51    has "inside information" compared to a program that strictly follows the PCRE
52    API. */
53    
54    #include "pcre_internal.h"
55    
56    
57  /* It is possible to compile this test program without including support for  /* It is possible to compile this test program without including support for
58  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 58  Makefile. */ Line 62  Makefile. */
62  #include "pcreposix.h"  #include "pcreposix.h"
63  #endif  #endif
64    
65    /* It is also possible, for the benefit of the version imported into Exim, to
66    build pcretest without support for UTF8 (define NOUTF8), without the interface
67    to the DFA matcher (NODFA), and without the doublecheck of the old "info"
68    function (define NOINFOCHECK). */
69    
70    
71  #ifndef CLOCKS_PER_SEC  #ifndef CLOCKS_PER_SEC
72  #ifdef CLK_TCK  #ifdef CLK_TCK
73  #define CLOCKS_PER_SEC CLK_TCK  #define CLOCKS_PER_SEC CLK_TCK
# Line 87  static size_t gotten_store; Line 97  static size_t gotten_store;
97  static uschar *pbuffer = NULL;  static uschar *pbuffer = NULL;
98    
99    
 static const int utf8_table1[] = {  
   0x0000007f, 0x000007ff, 0x0000ffff, 0x001fffff, 0x03ffffff, 0x7fffffff};  
   
 static const int utf8_table2[] = {  
   0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc};  
   
 static const int utf8_table3[] = {  
   0xff, 0x1f, 0x0f, 0x07, 0x03, 0x01};  
   
   
   
 /*************************************************  
 *         Print compiled regex                   *  
 *************************************************/  
   
 /* The code for doing this is held in a separate file that is also included in  
 pcre.c when it is compiled with the debug switch. It defines a function called  
 print_internals(), which uses a table of opcode lengths defined by the macro  
 OP_LENGTHS, whose name must be OP_lengths. It also uses a table that translates  
 Unicode property names to numbers; this is kept in a separate file. */  
   
 static uschar OP_lengths[] = { OP_LENGTHS };  
   
 #include "ucp.h"  
 #include "ucptypetable.c"  
 #include "printint.c"  
   
   
100    
101  /*************************************************  /*************************************************
102  *          Read number from string               *  *          Read number from string               *
# Line 143  return(result); Line 125  return(result);
125    
126    
127    
 /*************************************************  
 *       Convert character value to UTF-8         *  
 *************************************************/  
   
 /* This function takes an integer value in the range 0 - 0x7fffffff  
 and encodes it as a UTF-8 character in 0 to 6 bytes.  
   
 Arguments:  
   cvalue     the character value  
   buffer     pointer to buffer for result - at least 6 bytes long  
   
 Returns:     number of characters placed in the buffer  
              -1 if input character is negative  
              0 if input character is positive but too big (only when  
              int is longer than 32 bits)  
 */  
   
 static int  
 ord2utf8(int cvalue, unsigned char *buffer)  
 {  
 register int i, j;  
 for (i = 0; i < sizeof(utf8_table1)/sizeof(int); i++)  
   if (cvalue <= utf8_table1[i]) break;  
 if (i >= sizeof(utf8_table1)/sizeof(int)) return 0;  
 if (cvalue < 0) return -1;  
   
 buffer += i;  
 for (j = i; j > 0; j--)  
  {  
  *buffer-- = 0x80 | (cvalue & 0x3f);  
  cvalue >>= 6;  
  }  
 *buffer = utf8_table2[i] | cvalue;  
 return i + 1;  
 }  
   
128    
129  /*************************************************  /*************************************************
130  *            Convert UTF-8 string to value       *  *            Convert UTF-8 string to value       *
# Line 195  Returns:   >  0 => the number of bytes c Line 141  Returns:   >  0 => the number of bytes c
141             -6 to 0 => malformed UTF-8 character at offset = (-return)             -6 to 0 => malformed UTF-8 character at offset = (-return)
142  */  */
143    
144    #if !defined NOUTF8
145    
146  static int  static int
147  utf82ord(unsigned char *buffer, int *vptr)  utf82ord(unsigned char *buffer, int *vptr)
148  {  {
# Line 214  if (i == 0 || i == 6) return 0;        / Line 162  if (i == 0 || i == 6) return 0;        /
162  /* i now has a value in the range 1-5 */  /* i now has a value in the range 1-5 */
163    
164  s = 6*i;  s = 6*i;
165  d = (c & utf8_table3[i]) << s;  d = (c & _pcre_utf8_table3[i]) << s;
166    
167  for (j = 0; j < i; j++)  for (j = 0; j < i; j++)
168    {    {
# Line 226  for (j = 0; j < i; j++) Line 174  for (j = 0; j < i; j++)
174    
175  /* Check that encoding was the correct unique one */  /* Check that encoding was the correct unique one */
176    
177  for (j = 0; j < sizeof(utf8_table1)/sizeof(int); j++)  for (j = 0; j < _pcre_utf8_table1_size; j++)
178    if (d <= utf8_table1[j]) break;    if (d <= _pcre_utf8_table1[j]) break;
179  if (j != i) return -(i+1);  if (j != i) return -(i+1);
180    
181  /* Valid value */  /* Valid value */
# Line 236  if (j != i) return -(i+1); Line 184  if (j != i) return -(i+1);
184  return i+1;  return i+1;
185  }  }
186    
187    #endif
188    
189    
190    
191  /*************************************************  /*************************************************
# Line 253  int yield = 0; Line 203  int yield = 0;
203    
204  while (length-- > 0)  while (length-- > 0)
205    {    {
206    #if !defined NOUTF8
207    if (use_utf8)    if (use_utf8)
208      {      {
209      int rc = utf82ord(p, &c);      int rc = utf82ord(p, &c);
# Line 275  while (length-- > 0) Line 226  while (length-- > 0)
226        continue;        continue;
227        }        }
228      }      }
229    #endif
230    
231     /* Not UTF-8, or malformed UTF-8  */     /* Not UTF-8, or malformed UTF-8  */
232    
# Line 403  static void *new_malloc(size_t size) Line 355  static void *new_malloc(size_t size)
355  void *block = malloc(size);  void *block = malloc(size);
356  gotten_store = size;  gotten_store = size;
357  if (show_malloc)  if (show_malloc)
358    fprintf(outfile, "malloc       %3d %p\n", size, block);    fprintf(outfile, "malloc       %3d %p\n", (int)size, block);
359  return block;  return block;
360  }  }
361    
# Line 421  static void *stack_malloc(size_t size) Line 373  static void *stack_malloc(size_t size)
373  {  {
374  void *block = malloc(size);  void *block = malloc(size);
375  if (show_malloc)  if (show_malloc)
376    fprintf(outfile, "stack_malloc %3d %p\n", size, block);    fprintf(outfile, "stack_malloc %3d %p\n", (int)size, block);
377  return block;  return block;
378  }  }
379    
# Line 484  int showinfo = 0; Line 436  int showinfo = 0;
436  int showstore = 0;  int showstore = 0;
437  int size_offsets = 45;  int size_offsets = 45;
438  int size_offsets_max;  int size_offsets_max;
439  int *offsets;  int *offsets = NULL;
440  #if !defined NOPOSIX  #if !defined NOPOSIX
441  int posix = 0;  int posix = 0;
442  #endif  #endif
443  int debug = 0;  int debug = 0;
444  int done = 0;  int done = 0;
445    int all_use_dfa = 0;
446    int yield = 0;
447    
448  unsigned char *buffer;  unsigned char *buffer;
449  unsigned char *dbuffer;  unsigned char *dbuffer;
# Line 522  while (argc > 1 && argv[op][0] == '-') Line 476  while (argc > 1 && argv[op][0] == '-')
476    else if (strcmp(argv[op], "-t") == 0) timeit = 1;    else if (strcmp(argv[op], "-t") == 0) timeit = 1;
477    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;
478    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;
479    #if !defined NODFA
480      else if (strcmp(argv[op], "-dfa") == 0) all_use_dfa = 1;
481    #endif
482    else if (strcmp(argv[op], "-o") == 0 && argc > 2 &&    else if (strcmp(argv[op], "-o") == 0 && argc > 2 &&
483        ((size_offsets = get_value((unsigned char *)argv[op+1], &endptr)),        ((size_offsets = get_value((unsigned char *)argv[op+1], &endptr)),
484          *endptr == 0))          *endptr == 0))
# Line 558  while (argc > 1 && argv[op][0] == '-') Line 515  while (argc > 1 && argv[op][0] == '-')
515      printf("** Unknown or malformed option %s\n", argv[op]);      printf("** Unknown or malformed option %s\n", argv[op]);
516      printf("Usage:   pcretest [-d] [-i] [-o <n>] [-p] [-s] [-t] [<input> [<output>]]\n");      printf("Usage:   pcretest [-d] [-i] [-o <n>] [-p] [-s] [-t] [<input> [<output>]]\n");
517      printf("  -C     show PCRE compile-time options and exit\n");      printf("  -C     show PCRE compile-time options and exit\n");
518      printf("  -d     debug: show compiled code; implies -i\n"      printf("  -d     debug: show compiled code; implies -i\n");
519             "  -i     show information about compiled pattern\n"  #if !defined NODFA
520        printf("  -dfa   force DFA matching for all subjects\n");
521    #endif
522        printf("  -i     show information about compiled pattern\n"
523             "  -m     output memory used information\n"             "  -m     output memory used information\n"
524             "  -o <n> set size of offsets vector to <n>\n");             "  -o <n> set size of offsets vector to <n>\n");
525  #if !defined NOPOSIX  #if !defined NOPOSIX
# Line 567  while (argc > 1 && argv[op][0] == '-') Line 527  while (argc > 1 && argv[op][0] == '-')
527  #endif  #endif
528      printf("  -s     output store (memory) used information\n"      printf("  -s     output store (memory) used information\n"
529             "  -t     time compilation and execution\n");             "  -t     time compilation and execution\n");
530      return 1;      yield = 1;
531        goto EXIT;
532      }      }
533    op++;    op++;
534    argc--;    argc--;
# Line 581  if (offsets == NULL) Line 542  if (offsets == NULL)
542    {    {
543    printf("** Failed to get %d bytes of memory for offsets vector\n",    printf("** Failed to get %d bytes of memory for offsets vector\n",
544      size_offsets_max * sizeof(int));      size_offsets_max * sizeof(int));
545    return 1;    yield = 1;
546      goto EXIT;
547    }    }
548    
549  /* Sort out the input and output files */  /* Sort out the input and output files */
# Line 592  if (argc > 1) Line 554  if (argc > 1)
554    if (infile == NULL)    if (infile == NULL)
555      {      {
556      printf("** Failed to open %s\n", argv[op]);      printf("** Failed to open %s\n", argv[op]);
557      return 1;      yield = 1;
558        goto EXIT;
559      }      }
560    }    }
561    
# Line 602  if (argc > 2) Line 565  if (argc > 2)
565    if (outfile == NULL)    if (outfile == NULL)
566      {      {
567      printf("** Failed to open %s\n", argv[op+1]);      printf("** Failed to open %s\n", argv[op+1]);
568      return 1;      yield = 1;
569        goto EXIT;
570      }      }
571    }    }
572    
# Line 802  while (!done) Line 766  while (!done)
766      {      {
767      switch (*pp++)      switch (*pp++)
768        {        {
769          case 'f': options |= PCRE_FIRSTLINE; break;
770        case 'g': do_g = 1; break;        case 'g': do_g = 1; break;
771        case 'i': options |= PCRE_CASELESS; break;        case 'i': options |= PCRE_CASELESS; break;
772        case 'm': options |= PCRE_MULTILINE; break;        case 'm': options |= PCRE_MULTILINE; break;
# Line 831  while (!done) Line 796  while (!done)
796    
797        case 'L':        case 'L':
798        ppp = pp;        ppp = pp;
799        while (*ppp != '\n' && *ppp != ' ') ppp++;        /* The '\r' test here is so that it works on Windows */
800          while (*ppp != '\n' && *ppp != '\r' && *ppp != ' ') ppp++;
801        *ppp = 0;        *ppp = 0;
802        if (setlocale(LC_CTYPE, (const char *)pp) == NULL)        if (setlocale(LC_CTYPE, (const char *)pp) == NULL)
803          {          {
# Line 849  while (!done) Line 815  while (!done)
815        *pp = 0;        *pp = 0;
816        break;        break;
817    
818        case '\n': case ' ': break;        case '\r':                      /* So that it works in Windows */
819          case '\n':
820          case ' ':
821          break;
822    
823        default:        default:
824        fprintf(outfile, "** Unknown option '%c'\n", pp[-1]);        fprintf(outfile, "** Unknown option '%c'\n", pp[-1]);
# Line 869  while (!done) Line 838  while (!done)
838    
839      if ((options & PCRE_CASELESS) != 0) cflags |= REG_ICASE;      if ((options & PCRE_CASELESS) != 0) cflags |= REG_ICASE;
840      if ((options & PCRE_MULTILINE) != 0) cflags |= REG_NEWLINE;      if ((options & PCRE_MULTILINE) != 0) cflags |= REG_NEWLINE;
841        if ((options & PCRE_DOTALL) != 0) cflags |= REG_DOTALL;
842      rc = regcomp(&preg, (char *)p, cflags);      rc = regcomp(&preg, (char *)p, cflags);
843    
844      /* Compilation failed; go back for another re, skipping to blank line      /* Compilation failed; go back for another re, skipping to blank line
# Line 1008  while (!done) Line 978  while (!done)
978      if (do_showinfo)      if (do_showinfo)
979        {        {
980        unsigned long int get_options, all_options;        unsigned long int get_options, all_options;
981    #if !defined NOINFOCHECK
982        int old_first_char, old_options, old_count;        int old_first_char, old_options, old_count;
983    #endif
984        int count, backrefmax, first_char, need_char;        int count, backrefmax, first_char, need_char;
985        int nameentrysize, namecount;        int nameentrysize, namecount;
986        const uschar *nametable;        const uschar *nametable;
# Line 1016  while (!done) Line 988  while (!done)
988        if (do_debug)        if (do_debug)
989          {          {
990          fprintf(outfile, "------------------------------------------------------------------\n");          fprintf(outfile, "------------------------------------------------------------------\n");
991          print_internals(re, outfile);          _pcre_printint(re, outfile);
992          }          }
993    
994        new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);        new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);
# Line 1029  while (!done) Line 1001  while (!done)
1001        new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount);        new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount);
1002        new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable);        new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable);
1003    
1004    #if !defined NOINFOCHECK
1005        old_count = pcre_info(re, &old_options, &old_first_char);        old_count = pcre_info(re, &old_options, &old_first_char);
1006        if (count < 0) fprintf(outfile,        if (count < 0) fprintf(outfile,
1007          "Error %d from pcre_info()\n", count);          "Error %d from pcre_info()\n", count);
# Line 1046  while (!done) Line 1019  while (!done)
1019            "Options disagreement: pcre_fullinfo=%ld pcre_info=%d\n",            "Options disagreement: pcre_fullinfo=%ld pcre_info=%d\n",
1020              get_options, old_options);              get_options, old_options);
1021          }          }
1022    #endif
1023    
1024        if (size != regex_gotten_store) fprintf(outfile,        if (size != regex_gotten_store) fprintf(outfile,
1025          "Size disagreement: pcre_fullinfo=%d call to malloc for %d\n",          "Size disagreement: pcre_fullinfo=%d call to malloc for %d\n",
1026          size, regex_gotten_store);          (int)size, (int)regex_gotten_store);
1027    
1028        fprintf(outfile, "Capturing subpattern count = %d\n", count);        fprintf(outfile, "Capturing subpattern count = %d\n", count);
1029        if (backrefmax > 0)        if (backrefmax > 0)
# Line 1080  while (!done) Line 1054  while (!done)
1054          fprintf(outfile, "Partial matching not supported\n");          fprintf(outfile, "Partial matching not supported\n");
1055    
1056        if (get_options == 0) fprintf(outfile, "No options\n");        if (get_options == 0) fprintf(outfile, "No options\n");
1057          else fprintf(outfile, "Options:%s%s%s%s%s%s%s%s%s%s\n",          else fprintf(outfile, "Options:%s%s%s%s%s%s%s%s%s%s%s\n",
1058            ((get_options & PCRE_ANCHORED) != 0)? " anchored" : "",            ((get_options & PCRE_ANCHORED) != 0)? " anchored" : "",
1059            ((get_options & PCRE_CASELESS) != 0)? " caseless" : "",            ((get_options & PCRE_CASELESS) != 0)? " caseless" : "",
1060            ((get_options & PCRE_EXTENDED) != 0)? " extended" : "",            ((get_options & PCRE_EXTENDED) != 0)? " extended" : "",
1061            ((get_options & PCRE_MULTILINE) != 0)? " multiline" : "",            ((get_options & PCRE_MULTILINE) != 0)? " multiline" : "",
1062              ((get_options & PCRE_FIRSTLINE) != 0)? " firstline" : "",
1063            ((get_options & PCRE_DOTALL) != 0)? " dotall" : "",            ((get_options & PCRE_DOTALL) != 0)? " dotall" : "",
1064            ((get_options & PCRE_DOLLAR_ENDONLY) != 0)? " dollar_endonly" : "",            ((get_options & PCRE_DOLLAR_ENDONLY) != 0)? " dollar_endonly" : "",
1065            ((get_options & PCRE_EXTRA) != 0)? " extra" : "",            ((get_options & PCRE_EXTRA) != 0)? " extra" : "",
# Line 1222  while (!done) Line 1197  while (!done)
1197            }            }
1198          fclose(f);          fclose(f);
1199          }          }
1200    
1201          new_free(re);
1202          if (extra != NULL) new_free(extra);
1203          if (tables != NULL) new_free((void *)tables);
1204        continue;  /* With next regex */        continue;  /* With next regex */
1205        }        }
1206      }        /* End of non-POSIX compile */      }        /* End of non-POSIX compile */
# Line 1244  while (!done) Line 1223  while (!done)
1223      int gmatched = 0;      int gmatched = 0;
1224      int start_offset = 0;      int start_offset = 0;
1225      int g_notempty = 0;      int g_notempty = 0;
1226        int use_dfa = 0;
1227    
1228      options = 0;      options = 0;
1229    
# Line 1299  while (!done) Line 1279  while (!done)
1279    
1280          /* Handle \x{..} specially - new Perl thing for utf8 */          /* Handle \x{..} specially - new Perl thing for utf8 */
1281    
1282    #if !defined NOUTF8
1283          if (*p == '{')          if (*p == '{')
1284            {            {
1285            unsigned char *pt = p;            unsigned char *pt = p;
# Line 1309  while (!done) Line 1290  while (!done)
1290              {              {
1291              unsigned char buff8[8];              unsigned char buff8[8];
1292              int ii, utn;              int ii, utn;
1293              utn = ord2utf8(c, buff8);              utn = _pcre_ord2utf8(c, buff8);
1294              for (ii = 0; ii < utn - 1; ii++) *q++ = buff8[ii];              for (ii = 0; ii < utn - 1; ii++) *q++ = buff8[ii];
1295              c = buff8[ii];   /* Last byte */              c = buff8[ii];   /* Last byte */
1296              p = pt + 1;              p = pt + 1;
# Line 1317  while (!done) Line 1298  while (!done)
1298              }              }
1299            /* Not correct form; fall through */            /* Not correct form; fall through */
1300            }            }
1301    #endif
1302    
1303          /* Ordinary \x */          /* Ordinary \x */
1304    
# Line 1397  while (!done) Line 1379  while (!done)
1379            }            }
1380          continue;          continue;
1381    
1382    #if !defined NODFA
1383            case 'D':
1384    #if !defined NOPOSIX
1385            if (posix || do_posix)
1386              printf("** Can't use dfa matching in POSIX mode: \\D ignored\n");
1387            else
1388    #endif
1389              use_dfa = 1;
1390            continue;
1391    
1392            case 'F':
1393            options |= PCRE_DFA_SHORTEST;
1394            continue;
1395    #endif
1396    
1397          case 'G':          case 'G':
1398          if (isdigit(*p))          if (isdigit(*p))
1399            {            {
# Line 1439  while (!done) Line 1436  while (!done)
1436              {              {
1437              printf("** Failed to get %d bytes of memory for offsets vector\n",              printf("** Failed to get %d bytes of memory for offsets vector\n",
1438                size_offsets_max * sizeof(int));                size_offsets_max * sizeof(int));
1439              return 1;              yield = 1;
1440                goto EXIT;
1441              }              }
1442            }            }
1443          use_size_offsets = n;          use_size_offsets = n;
# Line 1450  while (!done) Line 1448  while (!done)
1448          options |= PCRE_PARTIAL;          options |= PCRE_PARTIAL;
1449          continue;          continue;
1450    
1451    #if !defined NODFA
1452            case 'R':
1453            options |= PCRE_DFA_RESTART;
1454            continue;
1455    #endif
1456    
1457          case 'S':          case 'S':
1458          show_malloc = 1;          show_malloc = 1;
1459          continue;          continue;
# Line 1467  while (!done) Line 1471  while (!done)
1471      *q = 0;      *q = 0;
1472      len = q - dbuffer;      len = q - dbuffer;
1473    
1474        if ((all_use_dfa || use_dfa) && find_match_limit)
1475          {
1476          printf("**Match limit not relevant for DFA matching: ignored\n");
1477          find_match_limit = 0;
1478          }
1479    
1480      /* Handle matching via the POSIX interface, which does not      /* Handle matching via the POSIX interface, which does not
1481      support timing or playing with the match limit or callout data. */      support timing or playing with the match limit or callout data. */
1482    
# Line 1524  while (!done) Line 1534  while (!done)
1534          register int i;          register int i;
1535          clock_t time_taken;          clock_t time_taken;
1536          clock_t start_time = clock();          clock_t start_time = clock();
1537    
1538    #if !defined NODFA
1539            if (all_use_dfa || use_dfa)
1540              {
1541              int workspace[1000];
1542              for (i = 0; i < LOOPREPEAT; i++)
1543                count = pcre_dfa_exec(re, NULL, (char *)bptr, len, start_offset,
1544                  options | g_notempty, use_offsets, use_size_offsets, workspace,
1545                  sizeof(workspace)/sizeof(int));
1546              }
1547            else
1548    #endif
1549    
1550          for (i = 0; i < LOOPREPEAT; i++)          for (i = 0; i < LOOPREPEAT; i++)
1551            count = pcre_exec(re, extra, (char *)bptr, len,            count = pcre_exec(re, extra, (char *)bptr, len,
1552              start_offset, options | g_notempty, use_offsets, use_size_offsets);              start_offset, options | g_notempty, use_offsets, use_size_offsets);
1553    
1554          time_taken = clock() - start_time;          time_taken = clock() - start_time;
1555          fprintf(outfile, "Execute time %.3f milliseconds\n",          fprintf(outfile, "Execute time %.3f milliseconds\n",
1556            (((double)time_taken * 1000.0) / (double)LOOPREPEAT) /            (((double)time_taken * 1000.0) / (double)LOOPREPEAT) /
# Line 1597  while (!done) Line 1621  while (!done)
1621        /* The normal case is just to do the match once, with the default        /* The normal case is just to do the match once, with the default
1622        value of match_limit. */        value of match_limit. */
1623    
1624        else  #if !defined NODFA
1625          else if (all_use_dfa || use_dfa)
1626          {          {
1627          count = pcre_exec(re, extra, (char *)bptr, len,          int workspace[1000];
1628            start_offset, options | g_notempty, use_offsets, use_size_offsets);          count = pcre_dfa_exec(re, NULL, (char *)bptr, len, start_offset,
1629              options | g_notempty, use_offsets, use_size_offsets, workspace,
1630              sizeof(workspace)/sizeof(int));
1631            if (count == 0)
1632              {
1633              fprintf(outfile, "Matched, but too many subsidiary matches\n");
1634              count = use_size_offsets/2;
1635              }
1636          }          }
1637    #endif
1638    
1639        if (count == 0)        else
1640          {          {
1641          fprintf(outfile, "Matched, but too many substrings\n");          count = pcre_exec(re, extra, (char *)bptr, len,
1642          count = use_size_offsets/3;            start_offset, options | g_notempty, use_offsets, use_size_offsets);
1643            if (count == 0)
1644              {
1645              fprintf(outfile, "Matched, but too many substrings\n");
1646              count = use_size_offsets/3;
1647              }
1648          }          }
1649    
1650        /* Matched */        /* Matched */
# Line 1692  while (!done) Line 1730  while (!done)
1730    
1731        else if (count == PCRE_ERROR_PARTIAL)        else if (count == PCRE_ERROR_PARTIAL)
1732          {          {
1733          fprintf(outfile, "Partial match\n");          fprintf(outfile, "Partial match");
1734    #if !defined NODFA
1735            if ((all_use_dfa || use_dfa) && use_size_offsets > 2)
1736              fprintf(outfile, ": %.*s", use_offsets[1] - use_offsets[0],
1737                bptr + use_offsets[0]);
1738    #endif
1739            fprintf(outfile, "\n");
1740          break;  /* Out of the /g loop */          break;  /* Out of the /g loop */
1741          }          }
1742    
# Line 1770  while (!done) Line 1814  while (!done)
1814    if (posix || do_posix) regfree(&preg);    if (posix || do_posix) regfree(&preg);
1815  #endif  #endif
1816    
1817    if (re != NULL) free(re);    if (re != NULL) new_free(re);
1818    if (extra != NULL) free(extra);    if (extra != NULL) new_free(extra);
1819    if (tables != NULL)    if (tables != NULL)
1820      {      {
1821      free((void *)tables);      new_free((void *)tables);
1822      setlocale(LC_CTYPE, "C");      setlocale(LC_CTYPE, "C");
1823      }      }
1824    }    }
1825    
1826  if (infile == stdin) fprintf(outfile, "\n");  if (infile == stdin) fprintf(outfile, "\n");
1827  return 0;  
1828    EXIT:
1829    
1830    if (infile != NULL && infile != stdin) fclose(infile);
1831    if (outfile != NULL && outfile != stdout) fclose(outfile);
1832    
1833    free(buffer);
1834    free(dbuffer);
1835    free(pbuffer);
1836    free(offsets);
1837    
1838    return yield;
1839  }  }
1840    
1841  /* End */  /* End of pcretest.c */

Legend:
Removed from v.75  
changed lines
  Added in v.79

  ViewVC Help
Powered by ViewVC 1.1.5