C:/Users/Dennis/src/lang/Life_start/Life/life-1.02/source/regexp/timer.c

Go to the documentation of this file.
00001 /*
00002  * Simple timing program for regcomp().
00003  *
00004  *      Copyright (c) 1986 by University of Toronto.
00005  *      Written by Henry Spencer.  Not derived from licensed software.
00006  *
00007  *      Permission is granted to anyone to use this software for any
00008  *      purpose on any computer system, and to redistribute it freely,
00009  *      subject to the following restrictions:
00010  *
00011  *      1. The author is not responsible for the consequences of use of
00012  *              this software, no matter how awful, even if they arise
00013  *              from defects in it.
00014  *
00015  *      2. The origin of this software must not be misrepresented, either
00016  *              by explicit claim or by omission.
00017  *
00018  *      3. Altered versions must be plainly marked as such, and must not
00019  *              be misrepresented as being the original software.
00020  *
00021  * Usage: timer ncomp nexec nsub
00022  *      or
00023  *      timer ncomp nexec nsub regexp string [ answer [ sub ] ]
00024  *
00025  * The second form is for timing repetitions of a single test case.
00026  * The first form's test data is a compiled-in copy of the "tests" file.
00027  * Ncomp, nexec, nsub are how many times to do each regcomp, regexec,
00028  * and regsub.  The way to time an operation individually is to do something
00029  * like "timer 1 50 1".
00030  */
00031 #include <stdio.h>
00032 
00033 struct try {
00034         char *re, *str, *ans, *src, *dst;
00035 } tests[] = {
00036 #include "timer.t.h"
00037 { NULL, NULL, NULL, NULL, NULL }
00038 };
00039 
00040 #include "regexp.h"
00041 
00042 int errreport = 0;              /* Report errors via errseen? */
00043 char *errseen = NULL;           /* Error message. */
00044 
00045 char *progname;
00046 
00047 /* ARGSUSED */
00048 main(argc, argv)
00049 int argc;
00050 char *argv[];
00051 {
00052         int ncomp, nexec, nsub;
00053         struct try one;
00054         char dummy[512];
00055 
00056         if (argc < 4) {
00057                 ncomp = 1;
00058                 nexec = 1;
00059                 nsub = 1;
00060         } else {
00061                 ncomp = atoi(argv[1]);
00062                 nexec = atoi(argv[2]);
00063                 nsub = atoi(argv[3]);
00064         }
00065         
00066         progname = argv[0];
00067         if (argc > 5) {
00068                 one.re = argv[4];
00069                 one.str = argv[5];
00070                 if (argc > 6)
00071                         one.ans = argv[6];
00072                 else
00073                         one.ans = "y";
00074                 if (argc > 7) { 
00075                         one.src = argv[7];
00076                         one.dst = "xxx";
00077                 } else {
00078                         one.src = "x";
00079                         one.dst = "x";
00080                 }
00081                 errreport = 1;
00082                 try(one, ncomp, nexec, nsub);
00083         } else
00084                 multiple(ncomp, nexec, nsub);
00085         exit(0);
00086 }
00087 
00088 void
00089 regerror(s)
00090 char *s;
00091 {
00092         if (errreport)
00093                 errseen = s;
00094         else
00095                 error(s, "");
00096 }
00097 
00098 #ifndef ERRAVAIL
00099 error(s1, s2)
00100 char *s1;
00101 char *s2;
00102 {
00103         fprintf(stderr, "regexp: ");
00104         fprintf(stderr, s1, s2);
00105         fprintf(stderr, "\n");
00106         exit(1);
00107 }
00108 #endif
00109 
00110 int lineno = 0;
00111 
00112 multiple(ncomp, nexec, nsub)
00113 int ncomp, nexec, nsub;
00114 {
00115         register int i;
00116         extern char *strchr();
00117 
00118         errreport = 1;
00119         for (i = 0; tests[i].re != NULL; i++) {
00120                 lineno++;
00121                 try(tests[i], ncomp, nexec, nsub);
00122         }
00123 }
00124 
00125 try(fields, ncomp, nexec, nsub)
00126 struct try fields;
00127 int ncomp, nexec, nsub;
00128 {
00129         regexp *r;
00130         char dbuf[BUFSIZ];
00131         register int i;
00132 
00133         errseen = NULL;
00134         r = regcomp(fields.re);
00135         if (r == NULL) {
00136                 if (*fields.ans != 'c')
00137                         complain("regcomp failure in `%s'", fields.re);
00138                 return;
00139         }
00140         if (*fields.ans == 'c') {
00141                 complain("unexpected regcomp success in `%s'", fields.re);
00142                 free((char *)r);
00143                 return;
00144         }
00145         for (i = ncomp-1; i > 0; i--) {
00146                 free((char *)r);
00147                 r = regcomp(fields.re);
00148         }
00149         if (!regexec(r, fields.str)) {
00150                 if (*fields.ans != 'n')
00151                         complain("regexec failure in `%s'", "");
00152                 free((char *)r);
00153                 return;
00154         }
00155         if (*fields.ans == 'n') {
00156                 complain("unexpected regexec success", "");
00157                 free((char *)r);
00158                 return;
00159         }
00160         for (i = nexec-1; i > 0; i--)
00161                 (void) regexec(r, fields.str);
00162         errseen = NULL;
00163         for (i = nsub; i > 0; i--)
00164                 regsub(r, fields.src, dbuf);
00165         if (errseen != NULL) {  
00166                 complain("regsub complaint", "");
00167                 free((char *)r);
00168                 return;
00169         }
00170         if (strcmp(dbuf, fields.dst) != 0)
00171                 complain("regsub result `%s' wrong", dbuf);
00172         free((char *)r);
00173 }
00174 
00175 complain(s1, s2)
00176 char *s1;
00177 char *s2;
00178 {
00179         fprintf(stderr, "try: %d: ", lineno);
00180         fprintf(stderr, s1, s2);
00181         fprintf(stderr, " (%s)\n", (errseen != NULL) ? errseen : "");
00182 }

Generated on Sat Jan 26 08:48:07 2008 for WildLife by  doxygen 1.5.4