/[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 91 by nigel, Sat Feb 24 21:41:34 2007 UTC revision 107 by ph10, Wed Mar 7 11:02:28 2007 UTC
# 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    
47  #ifndef _WIN32  
48  #include <sys/resource.h>  /* A number of things vary for Windows builds. Originally, pcretest opened its
49    input and output without "b"; then I was told that "b" was needed in some
50    environments, so it was added for release 5.0 to both the input and output. (It
51    makes no difference on Unix-like systems.) Later I was told that it is wrong
52    for the input on Windows. I've now abstracted the modes into two macros that
53    are set here, to make it easier to fiddle with them, and removed "b" from the
54    input mode under Windows. */
55    
56    #if defined(_WIN32) || defined(WIN32)
57    #include <io.h>                /* For _setmode() */
58    #include <fcntl.h>             /* For _O_BINARY */
59    #define INPUT_MODE   "r"
60    #define OUTPUT_MODE  "wb"
61    
62    #else
63    #include <sys/time.h>          /* These two includes are needed */
64    #include <sys/resource.h>      /* for setrlimit(). */
65    #define INPUT_MODE   "rb"
66    #define OUTPUT_MODE  "wb"
67  #endif  #endif
68    
69    
70  #define PCRE_SPY        /* For Win32 build, import data, not export */  #define PCRE_SPY        /* For Win32 build, import data, not export */
71    
72  /* We include pcre_internal.h because we need the internal info for displaying  /* We include pcre_internal.h because we need the internal info for displaying
# Line 74  symbols to prevent clashes. */ Line 93  symbols to prevent clashes. */
93    
94  /* We also need the pcre_printint() function for printing out compiled  /* We also need the pcre_printint() function for printing out compiled
95  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
96  pcre_compile.c when that module is compiled with debugging enabled. */  pcre_compile.c when that module is compiled with debugging enabled.
97    
98    The definition of the macro PRINTABLE, which determines whether to print an
99    output character as-is or as a hex value when showing compiled patterns, is
100    contained in this file. We uses it here also, in cases when the locale has not
101    been explicitly changed, so as to get consistent output from systems that
102    differ in their output from isprint() even in the "C" locale. */
103    
104  #include "pcre_printint.src"  #include "pcre_printint.src"
105    
106    #define PRINTHEX(c) (locale_set? isprint(c) : PRINTABLE(c))
107    
108    
109  /* It is possible to compile this test program without including support for  /* It is possible to compile this test program without including support for
110  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 87  Makefile. */ Line 114  Makefile. */
114  #include "pcreposix.h"  #include "pcreposix.h"
115  #endif  #endif
116    
117  /* It is also possible, for the benefit of the version imported into Exim, to  /* It is also possible, for the benefit of the version currently imported into
118  build pcretest without support for UTF8 (define NOUTF8), without the interface  Exim, to build pcretest without support for UTF8 (define NOUTF8), without the
119  to the DFA matcher (NODFA), and without the doublecheck of the old "info"  interface to the DFA matcher (NODFA), and without the doublecheck of the old
120  function (define NOINFOCHECK). */  "info" function (define NOINFOCHECK). In fact, we automatically cut out the
121    UTF8 support if PCRE is built without it. */
122    
123    #ifndef SUPPORT_UTF8
124    #ifndef NOUTF8
125    #define NOUTF8
126    #endif
127    #endif
128    
129    
130  /* Other parameters */  /* Other parameters */
# Line 103  function (define NOINFOCHECK). */ Line 137  function (define NOINFOCHECK). */
137  #endif  #endif
138  #endif  #endif
139    
140    /* This is the default loop count for timing. */
141    
142  #define LOOPREPEAT 500000  #define LOOPREPEAT 500000
143    
144  /* Static variables */  /* Static variables */
# Line 114  static int callout_extra; Line 150  static int callout_extra;
150  static int callout_fail_count;  static int callout_fail_count;
151  static int callout_fail_id;  static int callout_fail_id;
152  static int first_callout;  static int first_callout;
153    static int locale_set = 0;
154  static int show_malloc;  static int show_malloc;
155  static int use_utf8;  static int use_utf8;
156  static size_t gotten_store;  static size_t gotten_store;
# Line 157  uschar *here = start; Line 194  uschar *here = start;
194  for (;;)  for (;;)
195    {    {
196    int rlen = buffer_size - (here - buffer);    int rlen = buffer_size - (here - buffer);
197    
198    if (rlen > 1000)    if (rlen > 1000)
199      {      {
200      int dlen;      int dlen;
# Line 213  return NULL;  /* Control never gets here Line 251  return NULL;  /* Control never gets here
251    
252  /* We don't use strtoul() because SunOS4 doesn't have it. Rather than mess  /* We don't use strtoul() because SunOS4 doesn't have it. Rather than mess
253  around with conditional compilation, just do the job by hand. It is only used  around with conditional compilation, just do the job by hand. It is only used
254  for unpicking the -o argument, so just keep it simple.  for unpicking arguments, so just keep it simple.
255    
256  Arguments:  Arguments:
257    str           string to be converted    str           string to be converted
# Line 311  Arguments: Line 349  Arguments:
349  Returns:     number of characters placed in the buffer  Returns:     number of characters placed in the buffer
350  */  */
351    
352    #if !defined NOUTF8
353    
354  static int  static int
355  ord2utf8(int cvalue, uschar *utf8bytes)  ord2utf8(int cvalue, uschar *utf8bytes)
356  {  {
# Line 327  for (j = i; j > 0; j--) Line 367  for (j = i; j > 0; j--)
367  return i + 1;  return i + 1;
368  }  }
369    
370    #endif
371    
372    
373    
374  /*************************************************  /*************************************************
# Line 353  while (length-- > 0) Line 395  while (length-- > 0)
395        {        {
396        length -= rc - 1;        length -= rc - 1;
397        p += rc;        p += rc;
398        if (c < 256 && isprint(c))        if (PRINTHEX(c))
399          {          {
400          if (f != NULL) fprintf(f, "%c", c);          if (f != NULL) fprintf(f, "%c", c);
401          yield++;          yield++;
402          }          }
403        else        else
404          {          {
405          int n;          int n = 4;
406          if (f != NULL) fprintf(f, "\\x{%02x}%n", c, &n);          if (f != NULL) fprintf(f, "\\x{%02x}", c);
407          yield += n;          yield += (n <= 0x000000ff)? 2 :
408                     (n <= 0x00000fff)? 3 :
409                     (n <= 0x0000ffff)? 4 :
410                     (n <= 0x000fffff)? 5 : 6;
411          }          }
412        continue;        continue;
413        }        }
# Line 371  while (length-- > 0) Line 416  while (length-- > 0)
416    
417     /* Not UTF-8, or malformed UTF-8  */     /* Not UTF-8, or malformed UTF-8  */
418    
419    if (isprint(c = *(p++)))    c = *p++;
420      if (PRINTHEX(c))
421      {      {
422      if (f != NULL) fprintf(f, "%c", c);      if (f != NULL) fprintf(f, "%c", c);
423      yield++;      yield++;
# Line 614  return count; Line 660  return count;
660  *************************************************/  *************************************************/
661    
662  /* This is used both at compile and run-time to check for <xxx> escapes, where  /* This is used both at compile and run-time to check for <xxx> escapes, where
663  xxx is LF, CR, or CRLF. Print a message and return 0 if there is no match.  xxx is LF, CR, CRLF, or ANY. Print a message and return 0 if there is no match.
664    
665  Arguments:  Arguments:
666    p           points after the leading '<'    p           points after the leading '<'
# Line 629  check_newline(uschar *p, FILE *f) Line 675  check_newline(uschar *p, FILE *f)
675  if (strncmp((char *)p, "cr>", 3) == 0) return PCRE_NEWLINE_CR;  if (strncmp((char *)p, "cr>", 3) == 0) return PCRE_NEWLINE_CR;
676  if (strncmp((char *)p, "lf>", 3) == 0) return PCRE_NEWLINE_LF;  if (strncmp((char *)p, "lf>", 3) == 0) return PCRE_NEWLINE_LF;
677  if (strncmp((char *)p, "crlf>", 5) == 0) return PCRE_NEWLINE_CRLF;  if (strncmp((char *)p, "crlf>", 5) == 0) return PCRE_NEWLINE_CRLF;
678    if (strncmp((char *)p, "any>", 4) == 0) return PCRE_NEWLINE_ANY;
679  fprintf(f, "Unknown newline type at: <%s\n", p);  fprintf(f, "Unknown newline type at: <%s\n", p);
680  return 0;  return 0;
681  }  }
# Line 636  return 0; Line 683  return 0;
683    
684    
685  /*************************************************  /*************************************************
686    *             Usage function                     *
687    *************************************************/
688    
689    static void
690    usage(void)
691    {
692    printf("Usage:     pcretest [options] [<input> [<output>]]\n");
693    printf("  -b       show compiled code (bytecode)\n");
694    printf("  -C       show PCRE compile-time options and exit\n");
695    printf("  -d       debug: show compiled code and information (-b and -i)\n");
696    #if !defined NODFA
697    printf("  -dfa     force DFA matching for all subjects\n");
698    #endif
699    printf("  -help    show usage information\n");
700    printf("  -i       show information about compiled patterns\n"
701           "  -m       output memory used information\n"
702           "  -o <n>   set size of offsets vector to <n>\n");
703    #if !defined NOPOSIX
704    printf("  -p       use POSIX interface\n");
705    #endif
706    printf("  -q       quiet: do not output PCRE version number at start\n");
707    printf("  -S <n>   set stack size to <n> megabytes\n");
708    printf("  -s       output store (memory) used information\n"
709           "  -t       time compilation and execution\n");
710    printf("  -t <n>   time compilation and execution, repeating <n> times\n");
711    printf("  -tm      time execution (matching) only\n");
712    printf("  -tm <n>  time execution (matching) only, repeating <n> times\n");
713    }
714    
715    
716    
717    /*************************************************
718  *                Main Program                    *  *                Main Program                    *
719  *************************************************/  *************************************************/
720    
# Line 650  int options = 0; Line 729  int options = 0;
729  int study_options = 0;  int study_options = 0;
730  int op = 1;  int op = 1;
731  int timeit = 0;  int timeit = 0;
732    int timeitm = 0;
733  int showinfo = 0;  int showinfo = 0;
734  int showstore = 0;  int showstore = 0;
735  int quiet = 0;  int quiet = 0;
# Line 681  buffer = (unsigned char *)malloc(buffer_ Line 761  buffer = (unsigned char *)malloc(buffer_
761  dbuffer = (unsigned char *)malloc(buffer_size);  dbuffer = (unsigned char *)malloc(buffer_size);
762  pbuffer = (unsigned char *)malloc(buffer_size);  pbuffer = (unsigned char *)malloc(buffer_size);
763    
764  /* The outfile variable is static so that new_malloc can use it. The _setmode()  /* The outfile variable is static so that new_malloc can use it. */
 stuff is some magic that I don't understand, but which apparently does good  
 things in Windows. It's related to line terminations.  */  
   
 #if defined(_WIN32) || defined(WIN32)  
 _setmode( _fileno( stdout ), 0x8000 );  
 #endif  /* defined(_WIN32) || defined(WIN32) */  
765    
766  outfile = stdout;  outfile = stdout;
767    
768    /* The following  _setmode() stuff is some Windows magic that tells its runtime
769    library to translate CRLF into a single LF character. At least, that's what
770    I've been told: never having used Windows I take this all on trust. Originally
771    it set 0x8000, but then I was advised that _O_BINARY was better. */
772    
773    #if defined(_WIN32) || defined(WIN32)
774    _setmode( _fileno( stdout ), _O_BINARY );
775    #endif
776    
777  /* Scan options */  /* Scan options */
778    
779  while (argc > 1 && argv[op][0] == '-')  while (argc > 1 && argv[op][0] == '-')
# Line 699  while (argc > 1 && argv[op][0] == '-') Line 782  while (argc > 1 && argv[op][0] == '-')
782    
783    if (strcmp(argv[op], "-s") == 0 || strcmp(argv[op], "-m") == 0)    if (strcmp(argv[op], "-s") == 0 || strcmp(argv[op], "-m") == 0)
784      showstore = 1;      showstore = 1;
   else if (strcmp(argv[op], "-t") == 0) timeit = 1;  
785    else if (strcmp(argv[op], "-q") == 0) quiet = 1;    else if (strcmp(argv[op], "-q") == 0) quiet = 1;
786      else if (strcmp(argv[op], "-b") == 0) debug = 1;
787    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;
788    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;
789  #if !defined NODFA  #if !defined NODFA
# Line 713  while (argc > 1 && argv[op][0] == '-') Line 796  while (argc > 1 && argv[op][0] == '-')
796      op++;      op++;
797      argc--;      argc--;
798      }      }
799      else if (strcmp(argv[op], "-t") == 0 || strcmp(argv[op], "-tm") == 0)
800        {
801        int both = argv[op][2] == 0;
802        int temp;
803        if (argc > 2 && (temp = get_value((unsigned char *)argv[op+1], &endptr),
804                         *endptr == 0))
805          {
806          timeitm = temp;
807          op++;
808          argc--;
809          }
810        else timeitm = LOOPREPEAT;
811        if (both) timeit = timeitm;
812        }
813    else if (strcmp(argv[op], "-S") == 0 && argc > 2 &&    else if (strcmp(argv[op], "-S") == 0 && argc > 2 &&
814        ((stack_size = get_value((unsigned char *)argv[op+1], &endptr)),        ((stack_size = get_value((unsigned char *)argv[op+1], &endptr)),
815          *endptr == 0))          *endptr == 0))
816      {      {
817  #ifdef _WIN32  #if defined(_WIN32) || defined(WIN32)
818      printf("PCRE: -S not supported on this OS\n");      printf("PCRE: -S not supported on this OS\n");
819      exit(1);      exit(1);
820  #else  #else
# Line 749  while (argc > 1 && argv[op][0] == '-') Line 846  while (argc > 1 && argv[op][0] == '-')
846      printf("  %sUnicode properties support\n", rc? "" : "No ");      printf("  %sUnicode properties support\n", rc? "" : "No ");
847      (void)pcre_config(PCRE_CONFIG_NEWLINE, &rc);      (void)pcre_config(PCRE_CONFIG_NEWLINE, &rc);
848      printf("  Newline sequence is %s\n", (rc == '\r')? "CR" :      printf("  Newline sequence is %s\n", (rc == '\r')? "CR" :
849        (rc == '\n')? "LF" : "CRLF");        (rc == '\n')? "LF" : (rc == ('\r'<<8 | '\n'))? "CRLF" :
850          (rc == -1)? "ANY" : "???");
851      (void)pcre_config(PCRE_CONFIG_LINK_SIZE, &rc);      (void)pcre_config(PCRE_CONFIG_LINK_SIZE, &rc);
852      printf("  Internal link size = %d\n", rc);      printf("  Internal link size = %d\n", rc);
853      (void)pcre_config(PCRE_CONFIG_POSIX_MALLOC_THRESHOLD, &rc);      (void)pcre_config(PCRE_CONFIG_POSIX_MALLOC_THRESHOLD, &rc);
# Line 762  while (argc > 1 && argv[op][0] == '-') Line 860  while (argc > 1 && argv[op][0] == '-')
860      printf("  Match recursion uses %s\n", rc? "stack" : "heap");      printf("  Match recursion uses %s\n", rc? "stack" : "heap");
861      exit(0);      exit(0);
862      }      }
863      else if (strcmp(argv[op], "-help") == 0 ||
864               strcmp(argv[op], "--help") == 0)
865        {
866        usage();
867        goto EXIT;
868        }
869    else    else
870      {      {
871      printf("** Unknown or malformed option %s\n", argv[op]);      printf("** Unknown or malformed option %s\n", argv[op]);
872      printf("Usage:   pcretest [options] [<input> [<output>]]\n");      usage();
     printf("  -C     show PCRE compile-time options and exit\n");  
     printf("  -d     debug: show compiled code; implies -i\n");  
 #if !defined NODFA  
     printf("  -dfa   force DFA matching for all subjects\n");  
 #endif  
     printf("  -i     show information about compiled pattern\n"  
            "  -m     output memory used information\n"  
            "  -o <n> set size of offsets vector to <n>\n");  
 #if !defined NOPOSIX  
     printf("  -p     use POSIX interface\n");  
 #endif  
     printf("  -S <n> set stack size to <n> megabytes\n");  
     printf("  -s     output store (memory) used information\n"  
            "  -t     time compilation and execution\n");  
873      yield = 1;      yield = 1;
874      goto EXIT;      goto EXIT;
875      }      }
# Line 803  if (offsets == NULL) Line 893  if (offsets == NULL)
893    
894  if (argc > 1)  if (argc > 1)
895    {    {
896    infile = fopen(argv[op], "rb");    infile = fopen(argv[op], INPUT_MODE);
897    if (infile == NULL)    if (infile == NULL)
898      {      {
899      printf("** Failed to open %s\n", argv[op]);      printf("** Failed to open %s\n", argv[op]);
# Line 814  if (argc > 1) Line 904  if (argc > 1)
904    
905  if (argc > 2)  if (argc > 2)
906    {    {
907    outfile = fopen(argv[op+1], "wb");    outfile = fopen(argv[op+1], OUTPUT_MODE);
908    if (outfile == NULL)    if (outfile == NULL)
909      {      {
910      printf("** Failed to open %s\n", argv[op+1]);      printf("** Failed to open %s\n", argv[op+1]);
# Line 859  while (!done) Line 949  while (!done)
949    int do_showinfo = showinfo;    int do_showinfo = showinfo;
950    int do_showrest = 0;    int do_showrest = 0;
951    int do_flip = 0;    int do_flip = 0;
952    int erroroffset, len, delimiter;    int erroroffset, len, delimiter, poffset;
953    
954    use_utf8 = 0;    use_utf8 = 0;
955    
# Line 969  while (!done) Line 1059  while (!done)
1059      }      }
1060    
1061    pp = p;    pp = p;
1062      poffset = p - buffer;
1063    
1064    for(;;)    for(;;)
1065      {      {
# Line 989  while (!done) Line 1080  while (!done)
1080      if (infile != stdin) fprintf(outfile, "%s", (char *)pp);      if (infile != stdin) fprintf(outfile, "%s", (char *)pp);
1081      }      }
1082    
1083      /* The buffer may have moved while being extended; reset the start of data
1084      pointer to the correct relative point in the buffer. */
1085    
1086      p = buffer + poffset;
1087    
1088    /* If the first character after the delimiter is backslash, make    /* If the first character after the delimiter is backslash, make
1089    the pattern end with backslash. This is purely to provide a way    the pattern end with backslash. This is purely to provide a way
1090    of testing for the error message when a pattern ends with backslash. */    of testing for the error message when a pattern ends with backslash. */
# Line 1020  while (!done) Line 1116  while (!done)
1116    
1117        case '+': do_showrest = 1; break;        case '+': do_showrest = 1; break;
1118        case 'A': options |= PCRE_ANCHORED; break;        case 'A': options |= PCRE_ANCHORED; break;
1119          case 'B': do_debug = 1; break;
1120        case 'C': options |= PCRE_AUTO_CALLOUT; break;        case 'C': options |= PCRE_AUTO_CALLOUT; break;
1121        case 'D': do_debug = do_showinfo = 1; break;        case 'D': do_debug = do_showinfo = 1; break;
1122        case 'E': options |= PCRE_DOLLAR_ENDONLY; break;        case 'E': options |= PCRE_DOLLAR_ENDONLY; break;
# Line 1042  while (!done) Line 1139  while (!done)
1139    
1140        case 'L':        case 'L':
1141        ppp = pp;        ppp = pp;
1142        /* The '\r' test here is so that it works on Windows */        /* The '\r' test here is so that it works on Windows. */
1143        while (*ppp != '\n' && *ppp != '\r' && *ppp != ' ') ppp++;        /* The '0' test is just in case this is an unterminated line. */
1144          while (*ppp != 0 && *ppp != '\n' && *ppp != '\r' && *ppp != ' ') ppp++;
1145        *ppp = 0;        *ppp = 0;
1146        if (setlocale(LC_CTYPE, (const char *)pp) == NULL)        if (setlocale(LC_CTYPE, (const char *)pp) == NULL)
1147          {          {
1148          fprintf(outfile, "** Failed to set locale \"%s\"\n", pp);          fprintf(outfile, "** Failed to set locale \"%s\"\n", pp);
1149          goto SKIP_DATA;          goto SKIP_DATA;
1150          }          }
1151          locale_set = 1;
1152        tables = pcre_maketables();        tables = pcre_maketables();
1153        pp = ppp;        pp = ppp;
1154        break;        break;
# Line 1116  while (!done) Line 1215  while (!done)
1215  #endif  /* !defined NOPOSIX */  #endif  /* !defined NOPOSIX */
1216    
1217      {      {
1218      if (timeit)      if (timeit > 0)
1219        {        {
1220        register int i;        register int i;
1221        clock_t time_taken;        clock_t time_taken;
1222        clock_t start_time = clock();        clock_t start_time = clock();
1223        for (i = 0; i < LOOPREPEAT; i++)        for (i = 0; i < timeit; i++)
1224          {          {
1225          re = pcre_compile((char *)p, options, &error, &erroroffset, tables);          re = pcre_compile((char *)p, options, &error, &erroroffset, tables);
1226          if (re != NULL) free(re);          if (re != NULL) free(re);
1227          }          }
1228        time_taken = clock() - start_time;        time_taken = clock() - start_time;
1229        fprintf(outfile, "Compile time %.3f milliseconds\n",        fprintf(outfile, "Compile time %.4f milliseconds\n",
1230          (((double)time_taken * 1000.0) / (double)LOOPREPEAT) /          (((double)time_taken * 1000.0) / (double)timeit) /
1231            (double)CLOCKS_PER_SEC);            (double)CLOCKS_PER_SEC);
1232        }        }
1233    
# Line 1180  while (!done) Line 1279  while (!done)
1279    
1280      if (do_study)      if (do_study)
1281        {        {
1282        if (timeit)        if (timeit > 0)
1283          {          {
1284          register int i;          register int i;
1285          clock_t time_taken;          clock_t time_taken;
1286          clock_t start_time = clock();          clock_t start_time = clock();
1287          for (i = 0; i < LOOPREPEAT; i++)          for (i = 0; i < timeit; i++)
1288            extra = pcre_study(re, study_options, &error);            extra = pcre_study(re, study_options, &error);
1289          time_taken = clock() - start_time;          time_taken = clock() - start_time;
1290          if (extra != NULL) free(extra);          if (extra != NULL) free(extra);
1291          fprintf(outfile, "  Study time %.3f milliseconds\n",          fprintf(outfile, "  Study time %.4f milliseconds\n",
1292            (((double)time_taken * 1000.0) / (double)LOOPREPEAT) /            (((double)time_taken * 1000.0) / (double)timeit) /
1293              (double)CLOCKS_PER_SEC);              (double)CLOCKS_PER_SEC);
1294          }          }
1295        extra = pcre_study(re, study_options, &error);        extra = pcre_study(re, study_options, &error);
# Line 1233  while (!done) Line 1332  while (!done)
1332    
1333      SHOW_INFO:      SHOW_INFO:
1334    
1335        if (do_debug)
1336          {
1337          fprintf(outfile, "------------------------------------------------------------------\n");
1338          pcre_printint(re, outfile);
1339          }
1340    
1341      if (do_showinfo)      if (do_showinfo)
1342        {        {
1343        unsigned long int get_options, all_options;        unsigned long int get_options, all_options;
# Line 1243  while (!done) Line 1348  while (!done)
1348        int nameentrysize, namecount;        int nameentrysize, namecount;
1349        const uschar *nametable;        const uschar *nametable;
1350    
       if (do_debug)  
         {  
         fprintf(outfile, "------------------------------------------------------------------\n");  
         pcre_printint(re, outfile);  
         }  
   
1351        new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);        new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);
1352        new_info(re, NULL, PCRE_INFO_SIZE, &size);        new_info(re, NULL, PCRE_INFO_SIZE, &size);
1353        new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count);        new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count);
# Line 1327  while (!done) Line 1426  while (!done)
1426            ((get_options & PCRE_NO_UTF8_CHECK) != 0)? " no_utf8_check" : "",            ((get_options & PCRE_NO_UTF8_CHECK) != 0)? " no_utf8_check" : "",
1427            ((get_options & PCRE_DUPNAMES) != 0)? " dupnames" : "");            ((get_options & PCRE_DUPNAMES) != 0)? " dupnames" : "");
1428    
1429        switch (get_options & PCRE_NEWLINE_CRLF)        switch (get_options & PCRE_NEWLINE_BITS)
1430          {          {
1431          case PCRE_NEWLINE_CR:          case PCRE_NEWLINE_CR:
1432          fprintf(outfile, "Forced newline sequence: CR\n");          fprintf(outfile, "Forced newline sequence: CR\n");
# Line 1341  while (!done) Line 1440  while (!done)
1440          fprintf(outfile, "Forced newline sequence: CRLF\n");          fprintf(outfile, "Forced newline sequence: CRLF\n");
1441          break;          break;
1442    
1443            case PCRE_NEWLINE_ANY:
1444            fprintf(outfile, "Forced newline sequence: ANY\n");
1445            break;
1446    
1447          default:          default:
1448          break;          break;
1449          }          }
# Line 1358  while (!done) Line 1461  while (!done)
1461          int ch = first_char & 255;          int ch = first_char & 255;
1462          const char *caseless = ((first_char & REQ_CASELESS) == 0)?          const char *caseless = ((first_char & REQ_CASELESS) == 0)?
1463            "" : " (caseless)";            "" : " (caseless)";
1464          if (isprint(ch))          if (PRINTHEX(ch))
1465            fprintf(outfile, "First char = \'%c\'%s\n", ch, caseless);            fprintf(outfile, "First char = \'%c\'%s\n", ch, caseless);
1466          else          else
1467            fprintf(outfile, "First char = %d%s\n", ch, caseless);            fprintf(outfile, "First char = %d%s\n", ch, caseless);
# Line 1373  while (!done) Line 1476  while (!done)
1476          int ch = need_char & 255;          int ch = need_char & 255;
1477          const char *caseless = ((need_char & REQ_CASELESS) == 0)?          const char *caseless = ((need_char & REQ_CASELESS) == 0)?
1478            "" : " (caseless)";            "" : " (caseless)";
1479          if (isprint(ch))          if (PRINTHEX(ch))
1480            fprintf(outfile, "Need char = \'%c\'%s\n", ch, caseless);            fprintf(outfile, "Need char = \'%c\'%s\n", ch, caseless);
1481          else          else
1482            fprintf(outfile, "Need char = %d%s\n", ch, caseless);            fprintf(outfile, "Need char = %d%s\n", ch, caseless);
# Line 1409  while (!done) Line 1512  while (!done)
1512                    fprintf(outfile, "\n  ");                    fprintf(outfile, "\n  ");
1513                    c = 2;                    c = 2;
1514                    }                    }
1515                  if (isprint(i) && i != ' ')                  if (PRINTHEX(i) && i != ' ')
1516                    {                    {
1517                    fprintf(outfile, "%c ", i);                    fprintf(outfile, "%c ", i);
1518                    c += 2;                    c += 2;
# Line 1468  while (!done) Line 1571  while (!done)
1571                  strerror(errno));                  strerror(errno));
1572                }                }
1573              else fprintf(outfile, "Study data written to %s\n", to_file);              else fprintf(outfile, "Study data written to %s\n", to_file);
1574    
1575              }              }
1576            }            }
1577          fclose(f);          fclose(f);
# Line 1866  while (!done) Line 1970  while (!done)
1970    
1971      for (;; gmatched++)    /* Loop for /g or /G */      for (;; gmatched++)    /* Loop for /g or /G */
1972        {        {
1973        if (timeit)        if (timeitm > 0)
1974          {          {
1975          register int i;          register int i;
1976          clock_t time_taken;          clock_t time_taken;
# Line 1876  while (!done) Line 1980  while (!done)
1980          if (all_use_dfa || use_dfa)          if (all_use_dfa || use_dfa)
1981            {            {
1982            int workspace[1000];            int workspace[1000];
1983            for (i = 0; i < LOOPREPEAT; i++)            for (i = 0; i < timeitm; i++)
1984              count = pcre_dfa_exec(re, NULL, (char *)bptr, len, start_offset,              count = pcre_dfa_exec(re, NULL, (char *)bptr, len, start_offset,
1985                options | g_notempty, use_offsets, use_size_offsets, workspace,                options | g_notempty, use_offsets, use_size_offsets, workspace,
1986                sizeof(workspace)/sizeof(int));                sizeof(workspace)/sizeof(int));
# Line 1884  while (!done) Line 1988  while (!done)
1988          else          else
1989  #endif  #endif
1990    
1991          for (i = 0; i < LOOPREPEAT; i++)          for (i = 0; i < timeitm; i++)
1992            count = pcre_exec(re, extra, (char *)bptr, len,            count = pcre_exec(re, extra, (char *)bptr, len,
1993              start_offset, options | g_notempty, use_offsets, use_size_offsets);              start_offset, options | g_notempty, use_offsets, use_size_offsets);
1994    
1995          time_taken = clock() - start_time;          time_taken = clock() - start_time;
1996          fprintf(outfile, "Execute time %.3f milliseconds\n",          fprintf(outfile, "Execute time %.4f milliseconds\n",
1997            (((double)time_taken * 1000.0) / (double)LOOPREPEAT) /            (((double)time_taken * 1000.0) / (double)timeitm) /
1998              (double)CLOCKS_PER_SEC);              (double)CLOCKS_PER_SEC);
1999          }          }
2000    
# Line 1966  while (!done) Line 2070  while (!done)
2070    
2071        if (count >= 0)        if (count >= 0)
2072          {          {
2073          int i;          int i, maxcount;
2074    
2075    #if !defined NODFA
2076            if (all_use_dfa || use_dfa) maxcount = use_size_offsets/2; else
2077    #endif
2078              maxcount = use_size_offsets/3;
2079    
2080            /* This is a check against a lunatic return value. */
2081    
2082            if (count > maxcount)
2083              {
2084              fprintf(outfile,
2085                "** PCRE error: returned count %d is too big for offset size %d\n",
2086                count, use_size_offsets);
2087              count = use_size_offsets/3;
2088              if (do_g || do_G)
2089                {
2090                fprintf(outfile, "** /%c loop abandoned\n", do_g? 'g' : 'G');
2091                do_g = do_G = FALSE;        /* Break g/G loop */
2092                }
2093              }
2094    
2095          for (i = 0; i < count * 2; i += 2)          for (i = 0; i < count * 2; i += 2)
2096            {            {
2097            if (use_offsets[i] < 0)            if (use_offsets[i] < 0)
# Line 2165  while (!done) Line 2290  while (!done)
2290      {      {
2291      new_free((void *)tables);      new_free((void *)tables);
2292      setlocale(LC_CTYPE, "C");      setlocale(LC_CTYPE, "C");
2293        locale_set = 0;
2294      }      }
2295    }    }
2296    

Legend:
Removed from v.91  
changed lines
  Added in v.107

  ViewVC Help
Powered by ViewVC 1.1.5