* added compilers lcc and bcc (linux86)
[mascara-docs.git] / compilers / linux86-0.16.17 / libc / regexp / timer.c
blob2d84a12370df4ff50eeb0e2db0c25a1f5345d1d5
1 /*
2 * Simple timing program for regcomp().
4 * Copyright (c) 1986 by University of Toronto.
5 * Written by Henry Spencer. Not derived from licensed software.
7 * Permission is granted to anyone to use this software for any
8 * purpose on any computer system, and to redistribute it freely,
9 * subject to the following restrictions:
11 * 1. The author is not responsible for the consequences of use of
12 * this software, no matter how awful, even if they arise
13 * from defects in it.
15 * 2. The origin of this software must not be misrepresented, either
16 * by explicit claim or by omission.
18 * 3. Altered versions must be plainly marked as such, and must not
19 * be misrepresented as being the original software.
21 * Usage: timer ncomp nexec nsub
22 * or
23 * timer ncomp nexec nsub regexp string [ answer [ sub ] ]
25 * The second form is for timing repetitions of a single test case.
26 * The first form's test data is a compiled-in copy of the "tests" file.
27 * Ncomp, nexec, nsub are how many times to do each regcomp, regexec,
28 * and regsub. The way to time an operation individually is to do something
29 * like "timer 1 50 1".
31 #include <stdio.h>
33 struct try {
34 char *re, *str, *ans, *src, *dst;
35 } tests[] = {
36 #include "timer.t.h"
37 { NULL, NULL, NULL, NULL, NULL }
40 #include <regexp.h>
42 int errreport = 0; /* Report errors via errseen? */
43 char *errseen = NULL; /* Error message. */
45 char *progname;
47 /* ARGSUSED */
48 main(argc, argv)
49 int argc;
50 char *argv[];
52 int ncomp, nexec, nsub;
53 struct try one;
54 char dummy[512];
56 if (argc < 4) {
57 ncomp = 1;
58 nexec = 1;
59 nsub = 1;
60 } else {
61 ncomp = atoi(argv[1]);
62 nexec = atoi(argv[2]);
63 nsub = atoi(argv[3]);
66 progname = argv[0];
67 if (argc > 5) {
68 one.re = argv[4];
69 one.str = argv[5];
70 if (argc > 6)
71 one.ans = argv[6];
72 else
73 one.ans = "y";
74 if (argc > 7) {
75 one.src = argv[7];
76 one.dst = "xxx";
77 } else {
78 one.src = "x";
79 one.dst = "x";
81 errreport = 1;
82 try(one, ncomp, nexec, nsub);
83 } else
84 multiple(ncomp, nexec, nsub);
85 exit(0);
88 void
89 regerror(s)
90 char *s;
92 if (errreport)
93 errseen = s;
94 else
95 error(s, "");
98 #ifndef ERRAVAIL
99 error(s1, s2)
100 char *s1;
101 char *s2;
103 fprintf(stderr, "regexp: ");
104 fprintf(stderr, s1, s2);
105 fprintf(stderr, "\n");
106 exit(1);
108 #endif
110 int lineno = 0;
112 multiple(ncomp, nexec, nsub)
113 int ncomp, nexec, nsub;
115 register int i;
116 extern char *strchr();
118 errreport = 1;
119 for (i = 0; tests[i].re != NULL; i++) {
120 lineno++;
121 try(tests[i], ncomp, nexec, nsub);
125 try(fields, ncomp, nexec, nsub)
126 struct try fields;
127 int ncomp, nexec, nsub;
129 regexp *r;
130 char dbuf[BUFSIZ];
131 register int i;
133 errseen = NULL;
134 r = regcomp(fields.re);
135 if (r == NULL) {
136 if (*fields.ans != 'c')
137 complain("regcomp failure in `%s'", fields.re);
138 return;
140 if (*fields.ans == 'c') {
141 complain("unexpected regcomp success in `%s'", fields.re);
142 free((char *)r);
143 return;
145 for (i = ncomp-1; i > 0; i--) {
146 free((char *)r);
147 r = regcomp(fields.re);
149 if (!regexec(r, fields.str)) {
150 if (*fields.ans != 'n')
151 complain("regexec failure in `%s'", "");
152 free((char *)r);
153 return;
155 if (*fields.ans == 'n') {
156 complain("unexpected regexec success", "");
157 free((char *)r);
158 return;
160 for (i = nexec-1; i > 0; i--)
161 (void) regexec(r, fields.str);
162 errseen = NULL;
163 for (i = nsub; i > 0; i--)
164 regsub(r, fields.src, dbuf);
165 if (errseen != NULL) {
166 complain("regsub complaint", "");
167 free((char *)r);
168 return;
170 if (strcmp(dbuf, fields.dst) != 0)
171 complain("regsub result `%s' wrong", dbuf);
172 free((char *)r);
175 complain(s1, s2)
176 char *s1;
177 char *s2;
179 fprintf(stderr, "try: %d: ", lineno);
180 fprintf(stderr, s1, s2);
181 fprintf(stderr, " (%s)\n", (errseen != NULL) ? errseen : "");