2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: timer.c /main/3 1996/06/19 17:13:50 drk $ */
25 * Simple timing program for regcomp().
27 * Copyright (c) 1986 by University of Toronto.
28 * Written by Henry Spencer. Not derived from licensed software.
30 * Permission is granted to anyone to use this software for any
31 * purpose on any computer system, and to redistribute it freely,
32 * subject to the following restrictions:
34 * 1. The author is not responsible for the consequences of use of
35 * this software, no matter how awful, even if they arise
38 * 2. The origin of this software must not be misrepresented, either
39 * by explicit claim or by omission.
41 * 3. Altered versions must be plainly marked as such, and must not
42 * be misrepresented as being the original software.
44 * Usage: timer ncomp nexec nsub
46 * timer ncomp nexec nsub regexp string [ answer [ sub ] ]
48 * The second form is for timing repetitions of a single test case.
49 * The first form's test data is a compiled-in copy of the "tests" file.
50 * Ncomp, nexec, nsub are how many times to do each regcomp, regexec,
51 * and regsub. The way to time an operation individually is to do something
52 * like "timer 1 50 1".
57 char *re, *str, *ans, *src, *dst;
60 { NULL, NULL, NULL, NULL, NULL }
63 #include <tptregexp.h>
65 int errreport = 0; /* Report errors via errseen? */
66 char *errseen = NULL; /* Error message. */
75 int ncomp, nexec, nsub;
84 ncomp = atoi(argv[1]);
85 nexec = atoi(argv[2]);
105 try(one, ncomp, nexec, nsub);
107 multiple(ncomp, nexec, nsub);
126 fprintf(stderr, "regexp: ");
127 fprintf(stderr, s1, s2);
128 fprintf(stderr, "\n");
135 multiple(ncomp, nexec, nsub)
136 int ncomp, nexec, nsub;
139 extern char *strchr();
142 for (i = 0; tests[i].re != NULL; i++) {
144 try(tests[i], ncomp, nexec, nsub);
148 try(fields, ncomp, nexec, nsub)
150 int ncomp, nexec, nsub;
157 r = tpt_regcomp(fields.re);
159 if (*fields.ans != 'c')
160 complain("tpt_regcomp failure in `%s'", fields.re);
163 if (*fields.ans == 'c') {
164 complain("unexpected tpt_regcomp success in `%s'", fields.re);
168 for (i = ncomp-1; i > 0; i--) {
170 r = tpt_regcomp(fields.re);
172 if (!tpt_regexec(r, fields.str)) {
173 if (*fields.ans != 'n')
174 complain("tpt_regexec failure in `%s'", "");
178 if (*fields.ans == 'n') {
179 complain("unexpected tpt_regexec success", "");
183 for (i = nexec-1; i > 0; i--)
184 (void) tpt_regexec(r, fields.str);
186 for (i = nsub; i > 0; i--)
187 tpt_regsub(r, fields.src, dbuf);
188 if (errseen != NULL) {
189 complain("tpt_regsub complaint", "");
193 if (strcmp(dbuf, fields.dst) != 0)
194 complain("tpt_regsub result `%s' wrong", dbuf);
202 fprintf(stderr, "try: %d: ", lineno);
203 fprintf(stderr, s1, s2);
204 fprintf(stderr, " (%s)\n", (errseen != NULL) ? errseen : "");