glue5.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
/*
* Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
* All Rights Reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <ctype.h>
/*
* fgrep -- print all lines containing any of a set of keywords
*
* status returns:
* 0 - ok, and some matches
* 1 - ok, but no matches
* 2 - some error
*/
#define MAXSIZ 700
#define QSIZE 400
struct words {
char inp;
char out;
}
int nsucc;
int need;
char *instr;
int inct;
int rflag;
int xargc;
char **xargv;
int numwords;
int nfound;
static int flag = 0;
char **argv;
{
instr = 0;
flag = 0;
if (www==0)
}
{
switch(xargv[0][1])
{
case 'r': /* return value only */
rflag++;
break;
case 'n': /* number of answers needed */
break;
case 'i':
# if D2
# endif
break;
}
}
if (xargc<=0)
{
exit(2);
}
# if D1
# endif
cgotofn();
# if D1
# endif
cfail();
# if D1
# endif
execute();
# if D1
# endif
return(nsucc == 0);
}
execute()
{
register char *p;
register struct words *c;
register ch;
register ccount;
int f;
char *nlp;
f=0;
nfound=0;
nlp = p;
c = www;
# if D2
# endif
for (;;) {
# if D3
# endif
if (--ccount <= 0) {
# if D2
# endif
if (instr) break;
}
# if D2
}
# endif
}
ch = *p;
# if D2
# endif
c = c->nst;
}
else if (c->link != 0) {
c = c->link;
goto nstate;
}
else {
c = c->fail;
if (c==0) {
c = www;
c = c->nst;
}
else if (c->link != 0) {
c = c->link;
goto istate;
}
}
else goto nstate;
}
# if D2
# endif
{
# if D1
fprintf(stderr, "found, p %o nlp %o ccount %d buf %o buf[2*BUFSIZ] %o\n",p,nlp,ccount,buf,buf+2*BUFSIZ);
# endif
if (instr==0)
while (*p++ != '\n') {
# if D3
# endif
if (--ccount <= 0) {
}
# if D2
}
# endif
}
}
nsucc = 1;
if (rflag==0)
{
# if D2
if (p>nlp)
# endif
else {
}
}
if (instr==0)
{
nlp = p;
c = www;
nfound=0;
}
}
else
ccount++;
continue;
}
# if D2
# endif
if (instr)
p++;
else
if (*p++ == '\n')
{
nlp = p;
c = www;
nfound=0;
}
}
if (instr==0)
close(f);
}
cgotofn() {
register c;
register struct words *s;
for(;;) {
# if D1
# endif
if ((c = gch())==0) return;
else if (c == '\n') {
s->out = 1;
s = www;
}
else {
loop:
if (s->inp == c) {
s = s->nst;
continue;
}
if (s->link == 0) {
s = smax;
goto enter;
}
s = s->link;
goto loop;
}
}
do {
s->inp = c;
s = smax;
}
while ((c = gch()) != '\n');
s = www;
numwords++;
goto nword;
}
gch()
{
static char *s;
if (flag==0)
{
flag=1;
s = *xargv++;
# if D1
# endif
if (xargc-- <=0) return(0);
}
if (*s) return(*s++);
flag=0;
return('\n');
}
overflo() {
exit(2);
}
cfail() {
register char c;
register struct words *s;
s = www;
init:
if ((s->inp) != 0) {
}
if ((s = s->link) != 0) {
goto init;
}
s = *front;
else front++;
if ((c = s->inp) != 0) {
else rear++;
else
continue;
}
goto floop;
}
if ((s = s->link) != 0)
goto cloop;
}
}
static int seen[50];
new (x)
{
int i;
for(i=0; i<nfound; i++)
if (seen[i]==x)
return(0);
seen[i]=x;
return(1);
}