try.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Simple test program for regexp(3) stuff. Knows about debugging hooks.
*
* Copyright (c) 1986 by University of Toronto.
* Written by Henry Spencer. Not derived from licensed software.
*
* Permission is granted to anyone to use this software for any
* purpose on any computer system, and to redistribute it freely,
* subject to the following restrictions:
*
* 1. The author is not responsible for the consequences of use of
* this software, no matter how awful, even if they arise
* from defects in it.
*
* 2. The origin of this software must not be misrepresented, either
* by explicit claim or by omission.
*
* 3. Altered versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
*
* Usage: try re [string [output [-]]]
* The re is compiled and dumped, regexeced against the string, the result
* is applied to output using regsub(). The - triggers a running narrative
* from regexec(). Dumping and narrative don't happen unless DEBUG.
*
* If there are no arguments, stdin is assumed to be a stream of lines with
* five fields: a r.e., a string to match it against, a result code, a
* source string for regsub, and the proper result. Result codes are 'c'
* for compile failure, 'y' for match success, 'n' for match failure.
* Field separator is tab.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <tptregexp.h>
#ifdef ERRAVAIL
char *progname;
extern char *mkprogname();
#endif
#ifdef DEBUG
extern int regnarrate;
#endif
int errreport = 0; /* Report errors via errseen? */
int status = 0; /* Exit status. */
/* ARGSUSED */
int argc;
char *argv[];
{
regexp *r;
int i;
#ifdef ERRAVAIL
#endif
if (argc == 1) {
multiple();
}
if (r == NULL)
#ifdef DEBUG
regdump(r);
if (argc > 4)
regnarrate++;
#endif
if (argc > 2) {
printf("%d", i);
for (i = 1; i < NSUBEXP; i++)
printf(" \\%d", i);
printf("\n");
}
if (argc > 3) {
}
}
void
tpt_regerror(s)
char *s;
{
if (errreport)
errseen = s;
else
error(s, "");
}
#ifndef ERRAVAIL
char *s1;
char *s2;
{
exit(1);
}
#endif
int lineno;
multiple()
{
char *field[5];
char *scan;
int i;
regexp *r;
extern char *strchr();
errreport = 1;
lineno = 0;
lineno++;
for (i = 0; i < 5; i++) {
exit(1);
}
*scan++ = '\0';
}
}
/* And finish up with some internal testing... */
lineno = 9990;
lineno = 9991;
lineno = 9992;
r = tpt_regcomp("foo");
if (r == NULL) {
return;
}
lineno = 9993;
lineno = 9994;
lineno = 9995;
lineno = 9996;
lineno = 9997;
lineno = 9998;
}
char **fields;
{
regexp *r;
r = tpt_regcomp(fields[0]);
if (r == NULL) {
return;
}
free((char *)r);
return;
}
free((char *)r);
return;
}
free((char *)r);
return;
}
free((char *)r);
return;
}
free((char *)r);
}
char *s1;
char *s2;
{
status = 1;
}