112287Stut #ifndef lint 2*32269Sbostic static char *sccsid = "@(#)hunt6.c 4.3 (Berkeley) 09/28/87"; 312287Stut #endif 412287Stut 512287Stut #include <stdio.h> 612287Stut #include <assert.h> 712287Stut #define TXTLEN 1000 812287Stut 912287Stut char *outbuf = 0; 1012287Stut extern char *soutput; 1112287Stut extern int soutlen, iflong; 1212287Stut extern long indexdate; 1312287Stut 1412287Stut baddrop(master, nf, fc, nitem, qitem, rprog, full) 15*32269Sbostic unsigned *master; 1612287Stut FILE *fc; 1712287Stut char *qitem[], *rprog; 1812287Stut { 1912287Stut /* checks list of drops for real bad drops; finds items with "deliv" */ 20*32269Sbostic union ptr { 21*32269Sbostic unsigned *a; 22*32269Sbostic long *b; 23*32269Sbostic } umaster; 2412287Stut int i, g, j, need, got, na, len; 2512287Stut long lp; 2612287Stut char res[100], *ar[50], output[TXTLEN]; 2712287Stut extern int colevel, reached; 28*32269Sbostic 29*32269Sbostic if (iflong) 30*32269Sbostic umaster.b = (long *) master; 31*32269Sbostic else 32*32269Sbostic umaster.a = master; 3312287Stut # if D1 3412287Stut if (iflong) 35*32269Sbostic fprintf(stderr,"in baddrop, nf %d umaster %ld %ld %ld\n", 36*32269Sbostic nf, umaster.b[0], umaster.b[1], umaster.b[2]); 3712287Stut else 38*32269Sbostic fprintf(stderr,"in baddrop, nf %d umaster %d %d %d\n", 39*32269Sbostic nf, umaster.a[0], umaster.a[1], umaster.a[2]); 4012287Stut # endif 4112287Stut for (i=g=0; i<nf; i++) 4212287Stut { 43*32269Sbostic lp = iflong ? umaster.b[i] : umaster.a[i]; 4412287Stut # if D1 4512287Stut if (iflong) 46*32269Sbostic fprintf(stderr, "i %d umaster %lo lp %lo\n", 47*32269Sbostic i, umaster.b[i], lp); 4812287Stut else 49*32269Sbostic fprintf(stderr, "i %d umaster %o lp %lo\n", 50*32269Sbostic i, umaster.a[i], lp); 5112287Stut # endif 5212287Stut fseek (fc, lp, 0); 5312287Stut fgets( res, 100, fc); 5412287Stut # if D1 5512287Stut fprintf(stderr, "tag %s", res); 5612287Stut # endif 5712287Stut if (!auxil(res,output)) 5812287Stut { 5912287Stut char *s; 6012287Stut int c; 6112287Stut # if D1 6212287Stut fprintf(stderr, "not auxil try rprog %c\n", 6312287Stut rprog? 'y': 'n'); 6412287Stut # endif 6512287Stut for(s=res; c= *s; s++) 6612287Stut if (c == ';' || c == '\n') 6712287Stut { 6812287Stut *s=0; 6912287Stut break; 7012287Stut } 7112287Stut len = rprog ? 7212287Stut corout (res, output, rprog, 0, TXTLEN) : 7312287Stut findline (res, output, TXTLEN, indexdate); 7412287Stut } 7512287Stut # if D1 7612287Stut _assert (len <TXTLEN); 7712287Stut fprintf(stderr,"item %d of %d, tag %s len %d output\n%s\n..\n", 7812287Stut i, nf, res, len, output); 7912287Stut # endif 8012287Stut if (len==0) 8112287Stut continue; 8212287Stut need = colevel ? reached : nitem; 8312287Stut na=0; 8412287Stut ar[na++] = "fgrep"; 8512287Stut ar[na++] = "-r"; 8612287Stut ar[na++] = "-n"; 8717679Sralph ar[na++] = (char *) need; 8812287Stut ar[na++] = "-i"; 8912287Stut ar[na++] = output; 9017679Sralph ar[na++] = (char *) len; 9112287Stut for(j=0; j<nitem; j++) 9212287Stut ar[na++] = qitem[j]; 9312287Stut # ifdef D1 9412287Stut fprintf(stderr, "calling fgrep len %d ar[4] %s %o %d \n", 9512287Stut len,ar[4],ar[5],ar[6]); 9612287Stut # endif 9712287Stut if (fgrep(na, ar)==0) 9812287Stut { 9912287Stut # ifdef D1 10012287Stut fprintf(stderr, "fgrep found it\n"); 10112287Stut # endif 10212287Stut if (iflong) 103*32269Sbostic umaster.b[g++] = umaster.b[i]; 10412287Stut else 105*32269Sbostic umaster.a[g++] = umaster.a[i]; 10612287Stut if (full >= g) 10712287Stut if (soutput==0) 10812287Stut fputs(output, stdout); 10912287Stut else 11012287Stut strcpy (soutput, output); 11112287Stut } 11212287Stut # ifdef D1 11312287Stut fprintf(stderr, "after fgrep\n"); 11412287Stut # endif 11512287Stut } 11612287Stut return(g); 11712287Stut } 11812287Stut 11912287Stut auxil( res, output) 12012287Stut char *res, *output; 12112287Stut { 12212287Stut extern FILE *fd; 12312287Stut long lp, c; 12412287Stut int len; 12512287Stut if (fd==0)return(0); 12612287Stut while (c = *res++) 12712287Stut { 12812287Stut if (c == ';') 12912287Stut { 13012287Stut sscanf(res, "%ld,%d", &lp, &len); 13112287Stut fseek (fd, lp, 0); 13212287Stut fgets(output, len, fd); 13312287Stut return(1); 13412287Stut } 13512287Stut } 13612287Stut return(0); 13712287Stut } 138