1*48296Sbostic /*-
2*48296Sbostic * %sccs.include.proprietary.c%
3*48296Sbostic */
4*48296Sbostic
512287Stut #ifndef lint
6*48296Sbostic static char sccsid[] = "@(#)hunt6.c 4.4 (Berkeley) 04/18/91";
7*48296Sbostic #endif /* not lint */
812287Stut
912287Stut #include <stdio.h>
1012287Stut #include <assert.h>
1112287Stut #define TXTLEN 1000
1212287Stut
1312287Stut char *outbuf = 0;
1412287Stut extern char *soutput;
1512287Stut extern int soutlen, iflong;
1612287Stut extern long indexdate;
1712287Stut
baddrop(master,nf,fc,nitem,qitem,rprog,full)1812287Stut baddrop(master, nf, fc, nitem, qitem, rprog, full)
1932269Sbostic unsigned *master;
2012287Stut FILE *fc;
2112287Stut char *qitem[], *rprog;
2212287Stut {
2312287Stut /* checks list of drops for real bad drops; finds items with "deliv" */
2432269Sbostic union ptr {
2532269Sbostic unsigned *a;
2632269Sbostic long *b;
2732269Sbostic } umaster;
2812287Stut int i, g, j, need, got, na, len;
2912287Stut long lp;
3012287Stut char res[100], *ar[50], output[TXTLEN];
3112287Stut extern int colevel, reached;
3232269Sbostic
3332269Sbostic if (iflong)
3432269Sbostic umaster.b = (long *) master;
3532269Sbostic else
3632269Sbostic umaster.a = master;
3712287Stut # if D1
3812287Stut if (iflong)
3932269Sbostic fprintf(stderr,"in baddrop, nf %d umaster %ld %ld %ld\n",
4032269Sbostic nf, umaster.b[0], umaster.b[1], umaster.b[2]);
4112287Stut else
4232269Sbostic fprintf(stderr,"in baddrop, nf %d umaster %d %d %d\n",
4332269Sbostic nf, umaster.a[0], umaster.a[1], umaster.a[2]);
4412287Stut # endif
4512287Stut for (i=g=0; i<nf; i++)
4612287Stut {
4732269Sbostic lp = iflong ? umaster.b[i] : umaster.a[i];
4812287Stut # if D1
4912287Stut if (iflong)
5032269Sbostic fprintf(stderr, "i %d umaster %lo lp %lo\n",
5132269Sbostic i, umaster.b[i], lp);
5212287Stut else
5332269Sbostic fprintf(stderr, "i %d umaster %o lp %lo\n",
5432269Sbostic i, umaster.a[i], lp);
5512287Stut # endif
5612287Stut fseek (fc, lp, 0);
5712287Stut fgets( res, 100, fc);
5812287Stut # if D1
5912287Stut fprintf(stderr, "tag %s", res);
6012287Stut # endif
6112287Stut if (!auxil(res,output))
6212287Stut {
6312287Stut char *s;
6412287Stut int c;
6512287Stut # if D1
6612287Stut fprintf(stderr, "not auxil try rprog %c\n",
6712287Stut rprog? 'y': 'n');
6812287Stut # endif
6912287Stut for(s=res; c= *s; s++)
7012287Stut if (c == ';' || c == '\n')
7112287Stut {
7212287Stut *s=0;
7312287Stut break;
7412287Stut }
7512287Stut len = rprog ?
7612287Stut corout (res, output, rprog, 0, TXTLEN) :
7712287Stut findline (res, output, TXTLEN, indexdate);
7812287Stut }
7912287Stut # if D1
8012287Stut _assert (len <TXTLEN);
8112287Stut fprintf(stderr,"item %d of %d, tag %s len %d output\n%s\n..\n",
8212287Stut i, nf, res, len, output);
8312287Stut # endif
8412287Stut if (len==0)
8512287Stut continue;
8612287Stut need = colevel ? reached : nitem;
8712287Stut na=0;
8812287Stut ar[na++] = "fgrep";
8912287Stut ar[na++] = "-r";
9012287Stut ar[na++] = "-n";
9117679Sralph ar[na++] = (char *) need;
9212287Stut ar[na++] = "-i";
9312287Stut ar[na++] = output;
9417679Sralph ar[na++] = (char *) len;
9512287Stut for(j=0; j<nitem; j++)
9612287Stut ar[na++] = qitem[j];
9712287Stut # ifdef D1
9812287Stut fprintf(stderr, "calling fgrep len %d ar[4] %s %o %d \n",
9912287Stut len,ar[4],ar[5],ar[6]);
10012287Stut # endif
10112287Stut if (fgrep(na, ar)==0)
10212287Stut {
10312287Stut # ifdef D1
10412287Stut fprintf(stderr, "fgrep found it\n");
10512287Stut # endif
10612287Stut if (iflong)
10732269Sbostic umaster.b[g++] = umaster.b[i];
10812287Stut else
10932269Sbostic umaster.a[g++] = umaster.a[i];
11012287Stut if (full >= g)
11112287Stut if (soutput==0)
11212287Stut fputs(output, stdout);
11312287Stut else
11412287Stut strcpy (soutput, output);
11512287Stut }
11612287Stut # ifdef D1
11712287Stut fprintf(stderr, "after fgrep\n");
11812287Stut # endif
11912287Stut }
12012287Stut return(g);
12112287Stut }
12212287Stut
auxil(res,output)12312287Stut auxil( res, output)
12412287Stut char *res, *output;
12512287Stut {
12612287Stut extern FILE *fd;
12712287Stut long lp, c;
12812287Stut int len;
12912287Stut if (fd==0)return(0);
13012287Stut while (c = *res++)
13112287Stut {
13212287Stut if (c == ';')
13312287Stut {
13412287Stut sscanf(res, "%ld,%d", &lp, &len);
13512287Stut fseek (fd, lp, 0);
13612287Stut fgets(output, len, fd);
13712287Stut return(1);
13812287Stut }
13912287Stut }
14012287Stut return(0);
14112287Stut }
142