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

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

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

code/trunk/pcretest.c revision 3 by nigel, Sat Feb 24 21:38:01 2007 UTC code/tags/pcre-1.05/pcretest.c revision 14 by nigel, Sat Feb 24 21:38:23 2007 UTC
# Line 30  static int log_store = 0; Line 30  static int log_store = 0;
30  /* Debugging function to print the internal form of the regex. This is the same  /* Debugging function to print the internal form of the regex. This is the same
31  code as contained in pcre.c under the DEBUG macro. */  code as contained in pcre.c under the DEBUG macro. */
32    
33  static char *OP_names[] = { "End", "\\A", "\\B", "\\b", "\\D", "\\d",  static const char *OP_names[] = {
34      "End", "\\A", "\\B", "\\b", "\\D", "\\d",
35    "\\S", "\\s", "\\W", "\\w", "Cut", "\\Z", "^", "$", "Any", "chars",    "\\S", "\\s", "\\W", "\\w", "Cut", "\\Z", "^", "$", "Any", "chars",
36    "not",    "not",
37    "*", "*?", "+", "+?", "?", "??", "{", "{", "{",    "*", "*?", "+", "+?", "?", "??", "{", "{", "{",
38    "*", "*?", "+", "+?", "?", "??", "{", "{", "{",    "*", "*?", "+", "+?", "?", "??", "{", "{", "{",
39    "*", "*?", "+", "+?", "?", "??", "{", "{", "{",    "*", "*?", "+", "+?", "?", "??", "{", "{", "{",
40    "*", "*?", "+", "+?", "?", "??", "{", "{",    "*", "*?", "+", "+?", "?", "??", "{", "{",
41    "class", "Ref",    "class", "negclass", "Ref",
42    "Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not", "Once",    "Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not", "Once",
43    "Brazero", "Braminzero", "Bra"    "Brazero", "Braminzero", "Bra"
44  };  };
# Line 121  for(;;) Line 122  for(;;)
122      case OP_TYPEUPTO:      case OP_TYPEUPTO:
123      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
124      printf("    %s{", OP_names[code[3]]);      printf("    %s{", OP_names[code[3]]);
125      if (*code != OP_TYPEEXACT) printf(",");      if (*code != OP_TYPEEXACT) printf("0,");
126      printf("%d}", (code[1] << 8) + code[2]);      printf("%d}", (code[1] << 8) + code[2]);
127      if (*code == OP_TYPEMINUPTO) printf("?");      if (*code == OP_TYPEMINUPTO) printf("?");
128      code += 3;      code += 3;
# Line 156  for(;;) Line 157  for(;;)
157    
158      case OP_REF:      case OP_REF:
159      printf("    \\%d", *(++code));      printf("    \\%d", *(++code));
160      break;      code++;
161        goto CLASS_REF_REPEAT;
162    
163      case OP_CLASS:      case OP_CLASS:
164        case OP_NEGCLASS:
165        {        {
166        int i, min, max;        int i, min, max;
167          if (*code++ == OP_CLASS) printf("    [");
168        code++;          else printf("   ^[");
       printf("    [");  
169    
170        for (i = 0; i < 256; i++)        for (i = 0; i < 256; i++)
171          {          {
# Line 186  for(;;) Line 188  for(;;)
188        printf("]");        printf("]");
189        code += 32;        code += 32;
190    
191          CLASS_REF_REPEAT:
192    
193        switch(*code)        switch(*code)
194          {          {
195          case OP_CRSTAR:          case OP_CRSTAR:
# Line 264  int timeit = 0; Line 268  int timeit = 0;
268  int showinfo = 0;  int showinfo = 0;
269  int posix = 0;  int posix = 0;
270  int debug = 0;  int debug = 0;
271    int done = 0;
272  unsigned char buffer[30000];  unsigned char buffer[30000];
273  unsigned char dbuffer[1024];  unsigned char dbuffer[1024];
274    
# Line 322  fprintf(outfile, "PCRE version %s\n\n", Line 327  fprintf(outfile, "PCRE version %s\n\n",
327    
328  /* Main loop */  /* Main loop */
329    
330  for (;;)  while (!done)
331    {    {
332    pcre *re = NULL;    pcre *re = NULL;
333    pcre_extra *extra = NULL;    pcre_extra *extra = NULL;
334    regex_t preg;    regex_t preg;
335    char *error;    const char *error;
336    unsigned char *p, *pp;    unsigned char *p, *pp;
337    int do_study = 0;    int do_study = 0;
338    int do_debug = 0;    int do_debug = 0;
# Line 371  for (;;) Line 376  for (;;)
376      if (fgets((char *)pp, len, infile) == NULL)      if (fgets((char *)pp, len, infile) == NULL)
377        {        {
378        fprintf(outfile, "** Unexpected EOF\n");        fprintf(outfile, "** Unexpected EOF\n");
379        goto END_OFF;        done = 1;
380          goto CONTINUE;
381        }        }
382      if (infile != stdin) fprintf(outfile, (char *)pp);      if (infile != stdin) fprintf(outfile, (char *)pp);
383      }      }
# Line 406  for (;;) Line 412  for (;;)
412        }        }
413      }      }
414    
415    /* Handle compiing via the POSIX interface, which doesn't support the    /* Handle compiling via the POSIX interface, which doesn't support the
416    timing, showing, or debugging options. */    timing, showing, or debugging options. */
417    
418    if (posix || do_posix)    if (posix || do_posix)
# Line 461  for (;;) Line 467  for (;;)
467          for (;;)          for (;;)
468            {            {
469            if (fgets((char *)buffer, sizeof(buffer), infile) == NULL)            if (fgets((char *)buffer, sizeof(buffer), infile) == NULL)
470              goto END_OFF;              {
471                done = 1;
472                goto CONTINUE;
473                }
474            len = (int)strlen((char *)buffer);            len = (int)strlen((char *)buffer);
475            while (len > 0 && isspace(buffer[len-1])) len--;            while (len > 0 && isspace(buffer[len-1])) len--;
476            if (len == 0) break;            if (len == 0) break;
# Line 580  for (;;) Line 589  for (;;)
589    
590    for (;;)    for (;;)
591      {      {
592      unsigned char *pp;      unsigned char *q;
593      int count, c;      int count, c;
594      int offsets[30];      int offsets[30];
595      int size_offsets = sizeof(offsets)/sizeof(int);      int size_offsets = sizeof(offsets)/sizeof(int);
# Line 588  for (;;) Line 597  for (;;)
597      options = 0;      options = 0;
598    
599      if (infile == stdin) printf("  data> ");      if (infile == stdin) printf("  data> ");
600      if (fgets((char *)buffer, sizeof(buffer), infile) == NULL) goto END_OFF;      if (fgets((char *)buffer, sizeof(buffer), infile) == NULL)
601          {
602          done = 1;
603          goto CONTINUE;
604          }
605      if (infile != stdin) fprintf(outfile, (char *)buffer);      if (infile != stdin) fprintf(outfile, (char *)buffer);
606    
607      len = (int)strlen((char *)buffer);      len = (int)strlen((char *)buffer);
# Line 599  for (;;) Line 612  for (;;)
612      p = buffer;      p = buffer;
613      while (isspace(*p)) p++;      while (isspace(*p)) p++;
614    
615      pp = dbuffer;      q = dbuffer;
616      while ((c = *p++) != 0)      while ((c = *p++) != 0)
617        {        {
618        int i = 0;        int i = 0;
# Line 661  for (;;) Line 674  for (;;)
674    
675          case 'O':          case 'O':
676          while(isdigit(*p)) n = n * 10 + *p++ - '0';          while(isdigit(*p)) n = n * 10 + *p++ - '0';
677          if (n <= sizeof(offsets)/sizeof(int)) size_offsets = n;          if (n <= (int)(sizeof(offsets)/sizeof(int))) size_offsets = n;
678          continue;          continue;
679    
680          case 'Z':          case 'Z':
681          options |= PCRE_NOTEOL;          options |= PCRE_NOTEOL;
682          continue;          continue;
683          }          }
684        *pp++ = c;        *q++ = c;
685        }        }
686      *pp = 0;      *q = 0;
687      len = pp - dbuffer;      len = q - dbuffer;
688    
689      /* Handle matching via the POSIX interface, which does not      /* Handle matching via the POSIX interface, which does not
690      support timing. */      support timing. */
# Line 694  for (;;) Line 707  for (;;)
707          }          }
708        else        else
709          {          {
710          int i;          size_t i;
711          for (i = 0; i < sizeof(pmatch)/sizeof(regmatch_t); i++)          for (i = 0; i < sizeof(pmatch)/sizeof(regmatch_t); i++)
712            {            {
713            if (pmatch[i].rm_so >= 0)            if (pmatch[i].rm_so >= 0)
# Line 758  for (;;) Line 771  for (;;)
771        }        }
772      }      }
773    
774      CONTINUE:
775    if (posix || do_posix) regfree(&preg);    if (posix || do_posix) regfree(&preg);
776    if (re != NULL) free(re);    if (re != NULL) free(re);
777    if (extra != NULL) free(extra);    if (extra != NULL) free(extra);
778    }    }
779    
 END_OFF:  
780  fprintf(outfile, "\n");  fprintf(outfile, "\n");
781  return 0;  return 0;
782  }  }

Legend:
Removed from v.3  
changed lines
  Added in v.14

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12