1 /*-
2 * %sccs.include.proprietary.c%
3 */
4
5 #ifndef lint
6 static char sccsid[] = "@(#)hunt6.c 4.4 (Berkeley) 04/18/91";
7 #endif /* not lint */
8
9 #include <stdio.h>
10 #include <assert.h>
11 #define TXTLEN 1000
12
13 char *outbuf = 0;
14 extern char *soutput;
15 extern int soutlen, iflong;
16 extern long indexdate;
17
baddrop(master,nf,fc,nitem,qitem,rprog,full)18 baddrop(master, nf, fc, nitem, qitem, rprog, full)
19 unsigned *master;
20 FILE *fc;
21 char *qitem[], *rprog;
22 {
23 /* checks list of drops for real bad drops; finds items with "deliv" */
24 union ptr {
25 unsigned *a;
26 long *b;
27 } umaster;
28 int i, g, j, need, got, na, len;
29 long lp;
30 char res[100], *ar[50], output[TXTLEN];
31 extern int colevel, reached;
32
33 if (iflong)
34 umaster.b = (long *) master;
35 else
36 umaster.a = master;
37 # if D1
38 if (iflong)
39 fprintf(stderr,"in baddrop, nf %d umaster %ld %ld %ld\n",
40 nf, umaster.b[0], umaster.b[1], umaster.b[2]);
41 else
42 fprintf(stderr,"in baddrop, nf %d umaster %d %d %d\n",
43 nf, umaster.a[0], umaster.a[1], umaster.a[2]);
44 # endif
45 for (i=g=0; i<nf; i++)
46 {
47 lp = iflong ? umaster.b[i] : umaster.a[i];
48 # if D1
49 if (iflong)
50 fprintf(stderr, "i %d umaster %lo lp %lo\n",
51 i, umaster.b[i], lp);
52 else
53 fprintf(stderr, "i %d umaster %o lp %lo\n",
54 i, umaster.a[i], lp);
55 # endif
56 fseek (fc, lp, 0);
57 fgets( res, 100, fc);
58 # if D1
59 fprintf(stderr, "tag %s", res);
60 # endif
61 if (!auxil(res,output))
62 {
63 char *s;
64 int c;
65 # if D1
66 fprintf(stderr, "not auxil try rprog %c\n",
67 rprog? 'y': 'n');
68 # endif
69 for(s=res; c= *s; s++)
70 if (c == ';' || c == '\n')
71 {
72 *s=0;
73 break;
74 }
75 len = rprog ?
76 corout (res, output, rprog, 0, TXTLEN) :
77 findline (res, output, TXTLEN, indexdate);
78 }
79 # if D1
80 _assert (len <TXTLEN);
81 fprintf(stderr,"item %d of %d, tag %s len %d output\n%s\n..\n",
82 i, nf, res, len, output);
83 # endif
84 if (len==0)
85 continue;
86 need = colevel ? reached : nitem;
87 na=0;
88 ar[na++] = "fgrep";
89 ar[na++] = "-r";
90 ar[na++] = "-n";
91 ar[na++] = (char *) need;
92 ar[na++] = "-i";
93 ar[na++] = output;
94 ar[na++] = (char *) len;
95 for(j=0; j<nitem; j++)
96 ar[na++] = qitem[j];
97 # ifdef D1
98 fprintf(stderr, "calling fgrep len %d ar[4] %s %o %d \n",
99 len,ar[4],ar[5],ar[6]);
100 # endif
101 if (fgrep(na, ar)==0)
102 {
103 # ifdef D1
104 fprintf(stderr, "fgrep found it\n");
105 # endif
106 if (iflong)
107 umaster.b[g++] = umaster.b[i];
108 else
109 umaster.a[g++] = umaster.a[i];
110 if (full >= g)
111 if (soutput==0)
112 fputs(output, stdout);
113 else
114 strcpy (soutput, output);
115 }
116 # ifdef D1
117 fprintf(stderr, "after fgrep\n");
118 # endif
119 }
120 return(g);
121 }
122
auxil(res,output)123 auxil( res, output)
124 char *res, *output;
125 {
126 extern FILE *fd;
127 long lp, c;
128 int len;
129 if (fd==0)return(0);
130 while (c = *res++)
131 {
132 if (c == ';')
133 {
134 sscanf(res, "%ld,%d", &lp, &len);
135 fseek (fd, lp, 0);
136 fgets(output, len, fd);
137 return(1);
138 }
139 }
140 return(0);
141 }
142