/[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 23 by nigel, Sat Feb 24 21:38:41 2007 UTC revision 25 by nigel, Sat Feb 24 21:38:45 2007 UTC
# Line 7  Line 7 
7  #include <string.h>  #include <string.h>
8  #include <stdlib.h>  #include <stdlib.h>
9  #include <time.h>  #include <time.h>
10    #include <locale.h>
11    
12  /* Use the internal info for displaying the results of pcre_study(). */  /* Use the internal info for displaying the results of pcre_study(). */
13    
# Line 313  while (argc > 1 && argv[op][0] == '-') Line 314  while (argc > 1 && argv[op][0] == '-')
314    else    else
315      {      {
316      printf("*** Unknown option %s\n", argv[op]);      printf("*** Unknown option %s\n", argv[op]);
317        printf("Usage: pcretest [-d] [-i] [-p] [-s] [-t] [<input> [<output>]]\n");
318        printf("  -d   debug: show compiled code; implies -i\n"
319               "  -i   show information about compiled pattern\n"
320               "  -p   use POSIX interface\n"
321               "  -s   output store information\n"
322               "  -t   time compilation and execution\n");
323      return 1;      return 1;
324      }      }
325    op++;    op++;
# Line 357  while (!done) Line 364  while (!done)
364    pcre_extra *extra = NULL;    pcre_extra *extra = NULL;
365    regex_t preg;    regex_t preg;
366    const char *error;    const char *error;
367    unsigned char *p, *pp;    unsigned char *p, *pp, *ppp;
368      unsigned const char *tables = NULL;
369    int do_study = 0;    int do_study = 0;
370    int do_debug = 0;    int do_debug = debug;
371      int do_showinfo = showinfo;
372    int do_posix = 0;    int do_posix = 0;
373    int erroroffset, len, delimiter;    int erroroffset, len, delimiter;
374    
# Line 422  while (!done) Line 431  while (!done)
431        case 'm': options |= PCRE_MULTILINE; break;        case 'm': options |= PCRE_MULTILINE; break;
432        case 's': options |= PCRE_DOTALL; break;        case 's': options |= PCRE_DOTALL; break;
433        case 'x': options |= PCRE_EXTENDED; break;        case 'x': options |= PCRE_EXTENDED; break;
434    
435        case 'A': options |= PCRE_ANCHORED; break;        case 'A': options |= PCRE_ANCHORED; break;
436        case 'D': do_debug = 1; break;        case 'D': do_debug = do_showinfo = 1; break;
437        case 'E': options |= PCRE_DOLLAR_ENDONLY; break;        case 'E': options |= PCRE_DOLLAR_ENDONLY; break;
438          case 'I': do_showinfo = 1; break;
439        case 'P': do_posix = 1; break;        case 'P': do_posix = 1; break;
440        case 'S': do_study = 1; break;        case 'S': do_study = 1; break;
441        case 'U': options |= PCRE_UNGREEDY; break;        case 'U': options |= PCRE_UNGREEDY; break;
442        case 'X': options |= PCRE_EXTRA; break;        case 'X': options |= PCRE_EXTRA; break;
443    
444          case 'L':
445          ppp = pp;
446          while (*ppp != '\n' && *ppp != ' ') ppp++;
447          *ppp = 0;
448          if (setlocale(LC_CTYPE, (const char *)pp) == NULL)
449            {
450            fprintf(outfile, "** Failed to set locale \"%s\"\n", pp);
451            goto SKIP_DATA;
452            }
453          tables = pcre_maketables();
454          pp = ppp;
455          break;
456    
457        case '\n': case ' ': break;        case '\n': case ' ': break;
458        default:        default:
459        fprintf(outfile, "** Unknown option '%c'\n", pp[-1]);        fprintf(outfile, "** Unknown option '%c'\n", pp[-1]);
# Line 437  while (!done) Line 462  while (!done)
462      }      }
463    
464    /* Handle compiling via the POSIX interface, which doesn't support the    /* Handle compiling via the POSIX interface, which doesn't support the
465    timing, showing, or debugging options. */    timing, showing, or debugging options, nor the ability to pass over
466      local character tables. */
467    
468    if (posix || do_posix)    if (posix || do_posix)
469      {      {
# Line 469  while (!done) Line 495  while (!done)
495        clock_t start_time = clock();        clock_t start_time = clock();
496        for (i = 0; i < LOOPREPEAT; i++)        for (i = 0; i < LOOPREPEAT; i++)
497          {          {
498          re = pcre_compile((char *)p, options, &error, &erroroffset);          re = pcre_compile((char *)p, options, &error, &erroroffset, tables);
499          if (re != NULL) free(re);          if (re != NULL) free(re);
500          }          }
501        time_taken = clock() - start_time;        time_taken = clock() - start_time;
# Line 477  while (!done) Line 503  while (!done)
503          ((double)time_taken)/(4 * CLOCKS_PER_SEC));          ((double)time_taken)/(4 * CLOCKS_PER_SEC));
504        }        }
505    
506      re = pcre_compile((char *)p, options, &error, &erroroffset);      re = pcre_compile((char *)p, options, &error, &erroroffset, tables);
507    
508      /* Compilation failed; go back for another re, skipping to blank line      /* Compilation failed; go back for another re, skipping to blank line
509      if non-interactive. */      if non-interactive. */
# Line 501  while (!done) Line 527  while (!done)
527            }            }
528          fprintf(outfile, "\n");          fprintf(outfile, "\n");
529          }          }
530        continue;        goto CONTINUE;
531        }        }
532    
533      /* Compilation succeeded; print data if required */      /* Compilation succeeded; print data if required */
534    
535      if (showinfo || do_debug)      if (do_showinfo)
536        {        {
537        int first_char, count;        int first_char, count;
538    
539        if (debug || do_debug) print_internals(re, outfile);        if (do_debug) print_internals(re, outfile);
540    
541        count = pcre_info(re, &options, &first_char);        count = pcre_info(re, &options, &first_char);
542        if (count < 0) fprintf(outfile,        if (count < 0) fprintf(outfile,
# Line 573  while (!done) Line 599  while (!done)
599        /* This looks at internal information. A bit kludgy to do it this        /* This looks at internal information. A bit kludgy to do it this
600        way, but it is useful for testing. */        way, but it is useful for testing. */
601    
602        else if (showinfo || do_debug)        else if (do_showinfo)
603          {          {
604          real_pcre_extra *xx = (real_pcre_extra *)extra;          real_pcre_extra *xx = (real_pcre_extra *)extra;
605          if ((xx->options & PCRE_STUDY_MAPPED) == 0)          if ((xx->options & PCRE_STUDY_MAPPED) == 0)
# Line 784  while (!done) Line 810  while (!done)
810    if (posix || do_posix) regfree(&preg);    if (posix || do_posix) regfree(&preg);
811    if (re != NULL) free(re);    if (re != NULL) free(re);
812    if (extra != NULL) free(extra);    if (extra != NULL) free(extra);
813      if (tables != NULL)
814        {
815        free((void *)tables);
816        setlocale(LC_CTYPE, "C");
817        }
818    }    }
819    
820  fprintf(outfile, "\n");  fprintf(outfile, "\n");

Legend:
Removed from v.23  
changed lines
  Added in v.25

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12