/[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 126 by ph10, Mon Mar 19 10:20:14 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 760  while (argc > 1 && argv[op][0] == '-') Line 858  while (argc > 1 && argv[op][0] == '-')
858      printf("  Default recursion depth limit = %d\n", rc);      printf("  Default recursion depth limit = %d\n", rc);
859      (void)pcre_config(PCRE_CONFIG_STACKRECURSE, &rc);      (void)pcre_config(PCRE_CONFIG_STACKRECURSE, &rc);
860      printf("  Match recursion uses %s\n", rc? "stack" : "heap");      printf("  Match recursion uses %s\n", rc? "stack" : "heap");
861      exit(0);      goto EXIT;
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 854  while (!done) Line 944  while (!done)
944    size_t size, regex_gotten_store;    size_t size, regex_gotten_store;
945    int do_study = 0;    int do_study = 0;
946    int do_debug = debug;    int do_debug = debug;
947      int debug_lengths = 1;
948    int do_G = 0;    int do_G = 0;
949    int do_g = 0;    int do_g = 0;
950    int do_showinfo = showinfo;    int do_showinfo = showinfo;
951    int do_showrest = 0;    int do_showrest = 0;
952    int do_flip = 0;    int do_flip = 0;
953    int erroroffset, len, delimiter;    int erroroffset, len, delimiter, poffset;
954    
955    use_utf8 = 0;    use_utf8 = 0;
956    
# Line 969  while (!done) Line 1060  while (!done)
1060      }      }
1061    
1062    pp = p;    pp = p;
1063      poffset = p - buffer;
1064    
1065    for(;;)    for(;;)
1066      {      {
# Line 989  while (!done) Line 1081  while (!done)
1081      if (infile != stdin) fprintf(outfile, "%s", (char *)pp);      if (infile != stdin) fprintf(outfile, "%s", (char *)pp);
1082      }      }
1083    
1084      /* The buffer may have moved while being extended; reset the start of data
1085      pointer to the correct relative point in the buffer. */
1086    
1087      p = buffer + poffset;
1088    
1089    /* If the first character after the delimiter is backslash, make    /* If the first character after the delimiter is backslash, make
1090    the pattern end with backslash. This is purely to provide a way    the pattern end with backslash. This is purely to provide a way
1091    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 1117  while (!done)
1117    
1118        case '+': do_showrest = 1; break;        case '+': do_showrest = 1; break;
1119        case 'A': options |= PCRE_ANCHORED; break;        case 'A': options |= PCRE_ANCHORED; break;
1120          case 'B': do_debug = 1; break;
1121        case 'C': options |= PCRE_AUTO_CALLOUT; break;        case 'C': options |= PCRE_AUTO_CALLOUT; break;
1122        case 'D': do_debug = do_showinfo = 1; break;        case 'D': do_debug = do_showinfo = 1; break;
1123        case 'E': options |= PCRE_DOLLAR_ENDONLY; break;        case 'E': options |= PCRE_DOLLAR_ENDONLY; break;
# Line 1037  while (!done) Line 1135  while (!done)
1135        case 'S': do_study = 1; break;        case 'S': do_study = 1; break;
1136        case 'U': options |= PCRE_UNGREEDY; break;        case 'U': options |= PCRE_UNGREEDY; break;
1137        case 'X': options |= PCRE_EXTRA; break;        case 'X': options |= PCRE_EXTRA; break;
1138          case 'Z': debug_lengths = 0; break;
1139        case '8': options |= PCRE_UTF8; use_utf8 = 1; break;        case '8': options |= PCRE_UTF8; use_utf8 = 1; break;
1140        case '?': options |= PCRE_NO_UTF8_CHECK; break;        case '?': options |= PCRE_NO_UTF8_CHECK; break;
1141    
1142        case 'L':        case 'L':
1143        ppp = pp;        ppp = pp;
1144        /* The '\r' test here is so that it works on Windows */        /* The '\r' test here is so that it works on Windows. */
1145        while (*ppp != '\n' && *ppp != '\r' && *ppp != ' ') ppp++;        /* The '0' test is just in case this is an unterminated line. */
1146          while (*ppp != 0 && *ppp != '\n' && *ppp != '\r' && *ppp != ' ') ppp++;
1147        *ppp = 0;        *ppp = 0;
1148        if (setlocale(LC_CTYPE, (const char *)pp) == NULL)        if (setlocale(LC_CTYPE, (const char *)pp) == NULL)
1149          {          {
1150          fprintf(outfile, "** Failed to set locale \"%s\"\n", pp);          fprintf(outfile, "** Failed to set locale \"%s\"\n", pp);
1151          goto SKIP_DATA;          goto SKIP_DATA;
1152          }          }
1153          locale_set = 1;
1154        tables = pcre_maketables();        tables = pcre_maketables();
1155        pp = ppp;        pp = ppp;
1156        break;        break;
# Line 1116  while (!done) Line 1217  while (!done)
1217  #endif  /* !defined NOPOSIX */  #endif  /* !defined NOPOSIX */
1218    
1219      {      {
1220      if (timeit)      if (timeit > 0)
1221        {        {
1222        register int i;        register int i;
1223        clock_t time_taken;        clock_t time_taken;
1224        clock_t start_time = clock();        clock_t start_time = clock();
1225        for (i = 0; i < LOOPREPEAT; i++)        for (i = 0; i < timeit; i++)
1226          {          {
1227          re = pcre_compile((char *)p, options, &error, &erroroffset, tables);          re = pcre_compile((char *)p, options, &error, &erroroffset, tables);
1228          if (re != NULL) free(re);          if (re != NULL) free(re);
1229          }          }
1230        time_taken = clock() - start_time;        time_taken = clock() - start_time;
1231        fprintf(outfile, "Compile time %.3f milliseconds\n",        fprintf(outfile, "Compile time %.4f milliseconds\n",
1232          (((double)time_taken * 1000.0) / (double)LOOPREPEAT) /          (((double)time_taken * 1000.0) / (double)timeit) /
1233            (double)CLOCKS_PER_SEC);            (double)CLOCKS_PER_SEC);
1234        }        }
1235    
# Line 1180  while (!done) Line 1281  while (!done)
1281    
1282      if (do_study)      if (do_study)
1283        {        {
1284        if (timeit)        if (timeit > 0)
1285          {          {
1286          register int i;          register int i;
1287          clock_t time_taken;          clock_t time_taken;
1288          clock_t start_time = clock();          clock_t start_time = clock();
1289          for (i = 0; i < LOOPREPEAT; i++)          for (i = 0; i < timeit; i++)
1290            extra = pcre_study(re, study_options, &error);            extra = pcre_study(re, study_options, &error);
1291          time_taken = clock() - start_time;          time_taken = clock() - start_time;
1292          if (extra != NULL) free(extra);          if (extra != NULL) free(extra);
1293          fprintf(outfile, "  Study time %.3f milliseconds\n",          fprintf(outfile, "  Study time %.4f milliseconds\n",
1294            (((double)time_taken * 1000.0) / (double)LOOPREPEAT) /            (((double)time_taken * 1000.0) / (double)timeit) /
1295              (double)CLOCKS_PER_SEC);              (double)CLOCKS_PER_SEC);
1296          }          }
1297        extra = pcre_study(re, study_options, &error);        extra = pcre_study(re, study_options, &error);
# Line 1233  while (!done) Line 1334  while (!done)
1334    
1335      SHOW_INFO:      SHOW_INFO:
1336    
1337        if (do_debug)
1338          {
1339          fprintf(outfile, "------------------------------------------------------------------\n");
1340          pcre_printint(re, outfile, debug_lengths);
1341          }
1342    
1343      if (do_showinfo)      if (do_showinfo)
1344        {        {
1345        unsigned long int get_options, all_options;        unsigned long int get_options, all_options;
# Line 1243  while (!done) Line 1350  while (!done)
1350        int nameentrysize, namecount;        int nameentrysize, namecount;
1351        const uschar *nametable;        const uschar *nametable;
1352    
       if (do_debug)  
         {  
         fprintf(outfile, "------------------------------------------------------------------\n");  
         pcre_printint(re, outfile);  
         }  
   
1353        new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);        new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);
1354        new_info(re, NULL, PCRE_INFO_SIZE, &size);        new_info(re, NULL, PCRE_INFO_SIZE, &size);
1355        new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count);        new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count);
# Line 1327  while (!done) Line 1428  while (!done)
1428            ((get_options & PCRE_NO_UTF8_CHECK) != 0)? " no_utf8_check" : "",            ((get_options & PCRE_NO_UTF8_CHECK) != 0)? " no_utf8_check" : "",
1429            ((get_options & PCRE_DUPNAMES) != 0)? " dupnames" : "");            ((get_options & PCRE_DUPNAMES) != 0)? " dupnames" : "");
1430    
1431        switch (get_options & PCRE_NEWLINE_CRLF)        switch (get_options & PCRE_NEWLINE_BITS)
1432          {          {
1433          case PCRE_NEWLINE_CR:          case PCRE_NEWLINE_CR:
1434          fprintf(outfile, "Forced newline sequence: CR\n");          fprintf(outfile, "Forced newline sequence: CR\n");
# Line 1341  while (!done) Line 1442  while (!done)
1442          fprintf(outfile, "Forced newline sequence: CRLF\n");          fprintf(outfile, "Forced newline sequence: CRLF\n");
1443          break;          break;
1444    
1445            case PCRE_NEWLINE_ANY:
1446            fprintf(outfile, "Forced newline sequence: ANY\n");
1447            break;
1448    
1449          default:          default:
1450          break;          break;
1451          }          }
# Line 1358  while (!done) Line 1463  while (!done)
1463          int ch = first_char & 255;          int ch = first_char & 255;
1464          const char *caseless = ((first_char & REQ_CASELESS) == 0)?          const char *caseless = ((first_char & REQ_CASELESS) == 0)?
1465            "" : " (caseless)";            "" : " (caseless)";
1466          if (isprint(ch))          if (PRINTHEX(ch))
1467            fprintf(outfile, "First char = \'%c\'%s\n", ch, caseless);            fprintf(outfile, "First char = \'%c\'%s\n", ch, caseless);
1468          else          else
1469            fprintf(outfile, "First char = %d%s\n", ch, caseless);            fprintf(outfile, "First char = %d%s\n", ch, caseless);
# Line 1373  while (!done) Line 1478  while (!done)
1478          int ch = need_char & 255;          int ch = need_char & 255;
1479          const char *caseless = ((need_char & REQ_CASELESS) == 0)?          const char *caseless = ((need_char & REQ_CASELESS) == 0)?
1480            "" : " (caseless)";            "" : " (caseless)";
1481          if (isprint(ch))          if (PRINTHEX(ch))
1482            fprintf(outfile, "Need char = \'%c\'%s\n", ch, caseless);            fprintf(outfile, "Need char = \'%c\'%s\n", ch, caseless);
1483          else          else
1484            fprintf(outfile, "Need char = %d%s\n", ch, caseless);            fprintf(outfile, "Need char = %d%s\n", ch, caseless);
# Line 1409  while (!done) Line 1514  while (!done)
1514                    fprintf(outfile, "\n  ");                    fprintf(outfile, "\n  ");
1515                    c = 2;                    c = 2;
1516                    }                    }
1517                  if (isprint(i) && i != ' ')                  if (PRINTHEX(i) && i != ' ')
1518                    {                    {
1519                    fprintf(outfile, "%c ", i);                    fprintf(outfile, "%c ", i);
1520                    c += 2;                    c += 2;
# Line 1468  while (!done) Line 1573  while (!done)
1573                  strerror(errno));                  strerror(errno));
1574                }                }
1575              else fprintf(outfile, "Study data written to %s\n", to_file);              else fprintf(outfile, "Study data written to %s\n", to_file);
1576    
1577              }              }
1578            }            }
1579          fclose(f);          fclose(f);
# Line 1866  while (!done) Line 1972  while (!done)
1972    
1973      for (;; gmatched++)    /* Loop for /g or /G */      for (;; gmatched++)    /* Loop for /g or /G */
1974        {        {
1975        if (timeit)        if (timeitm > 0)
1976          {          {
1977          register int i;          register int i;
1978          clock_t time_taken;          clock_t time_taken;
# Line 1876  while (!done) Line 1982  while (!done)
1982          if (all_use_dfa || use_dfa)          if (all_use_dfa || use_dfa)
1983            {            {
1984            int workspace[1000];            int workspace[1000];
1985            for (i = 0; i < LOOPREPEAT; i++)            for (i = 0; i < timeitm; i++)
1986              count = pcre_dfa_exec(re, NULL, (char *)bptr, len, start_offset,              count = pcre_dfa_exec(re, NULL, (char *)bptr, len, start_offset,
1987                options | g_notempty, use_offsets, use_size_offsets, workspace,                options | g_notempty, use_offsets, use_size_offsets, workspace,
1988                sizeof(workspace)/sizeof(int));                sizeof(workspace)/sizeof(int));
# Line 1884  while (!done) Line 1990  while (!done)
1990          else          else
1991  #endif  #endif
1992    
1993          for (i = 0; i < LOOPREPEAT; i++)          for (i = 0; i < timeitm; i++)
1994            count = pcre_exec(re, extra, (char *)bptr, len,            count = pcre_exec(re, extra, (char *)bptr, len,
1995              start_offset, options | g_notempty, use_offsets, use_size_offsets);              start_offset, options | g_notempty, use_offsets, use_size_offsets);
1996    
1997          time_taken = clock() - start_time;          time_taken = clock() - start_time;
1998          fprintf(outfile, "Execute time %.3f milliseconds\n",          fprintf(outfile, "Execute time %.4f milliseconds\n",
1999            (((double)time_taken * 1000.0) / (double)LOOPREPEAT) /            (((double)time_taken * 1000.0) / (double)timeitm) /
2000              (double)CLOCKS_PER_SEC);              (double)CLOCKS_PER_SEC);
2001          }          }
2002    
# Line 1966  while (!done) Line 2072  while (!done)
2072    
2073        if (count >= 0)        if (count >= 0)
2074          {          {
2075          int i;          int i, maxcount;
2076    
2077    #if !defined NODFA
2078            if (all_use_dfa || use_dfa) maxcount = use_size_offsets/2; else
2079    #endif
2080              maxcount = use_size_offsets/3;
2081    
2082            /* This is a check against a lunatic return value. */
2083    
2084            if (count > maxcount)
2085              {
2086              fprintf(outfile,
2087                "** PCRE error: returned count %d is too big for offset size %d\n",
2088                count, use_size_offsets);
2089              count = use_size_offsets/3;
2090              if (do_g || do_G)
2091                {
2092                fprintf(outfile, "** /%c loop abandoned\n", do_g? 'g' : 'G');
2093                do_g = do_G = FALSE;        /* Break g/G loop */
2094                }
2095              }
2096    
2097          for (i = 0; i < count * 2; i += 2)          for (i = 0; i < count * 2; i += 2)
2098            {            {
2099            if (use_offsets[i] < 0)            if (use_offsets[i] < 0)
# Line 2165  while (!done) Line 2292  while (!done)
2292      {      {
2293      new_free((void *)tables);      new_free((void *)tables);
2294      setlocale(LC_CTYPE, "C");      setlocale(LC_CTYPE, "C");
2295        locale_set = 0;
2296      }      }
2297    }    }
2298    

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

  ViewVC Help
Powered by ViewVC 1.1.5