|
|
1.1 root 1: # include "stdio.h"
2: # define unopen(fil) {if (fil!=NULL) {fclose(fil); fil=NULL;}}
3: extern char refdir[];
4: int lmaster = 1000;
5: int reached = 0;
6: FILE *fd = 0;
7: long *zalloc();
8: char *todir();
9: FILE *iopen();
10: int *hfreq, hfrflg;
11: int colevel = 0;
12: static union {unsigned *a; long *b;} master;
13: int iflong;
14: extern char *fgnames[], **fgnamp;
15: int prfreqs = 0;
16: int typeindex = 0;
17: char usedir[100];
18: static int full = 1000;
19: static int tags = 0;
20: char *sinput, *soutput, *tagout;
21: long indexdate = 0, gdate();
22: int soutlen = 1000;
23: int taglen = 1000;
24:
25: huntmain(argc,argv)
26: char *argv[];
27: {
28: /* read query from stdin, expect name of indexes in argv[1] */
29: static FILE *fa, *fb, *fc;
30: char indexname[100], *qitem[100], *rprog = 0;
31: char grepquery[200];
32: static char oldname[30] ;
33: static int nhash = 0;
34: static int maxhash = 0;
35: int falseflg = 0, nitem, nfound, frtbl;
36: static long *hpt = 0;
37: # if D1
38: fprintf(stderr, "in glue1 argc %d argv %o %o\n", argc, argv[0],argv[1]);
39: # endif
40: savedir();
41: while (argv[1][0] == '-')
42: {
43: # if D1
44: fprintf(stderr, "argv.1 is %s\n",argv[1]);
45: # endif
46: switch(argv[1][1])
47: {
48: case 'a': /* all output, incl. false drops */
49: falseflg = 1; break;
50: case 'r':
51: argc--; argv++;
52: rprog = argv[1];
53: break;
54: case 'F': /* put out full text */
55: full = setfrom(argv[1][2]);
56: break;
57: case 'T': /* put out tags */
58: tags = setfrom(argv[1][2]);
59: break;
60: case 'i': /* input in argument string */
61: argc--; argv++;
62: sinput = argv[1];
63: break;
64: case 's': /*text output to string */
65: case 'o':
66: argc--; argv++;
67: soutput = argv[1];
68: if ((int)(argv[2])<16000)
69: {
70: soutlen = (int) argv[2];
71: argc--; argv++;
72: }
73: break;
74: case 't': /*tag output to string */
75: argc--; argv++;
76: tagout = argv[1];
77: if ((int)(argv[2])<16000)
78: {
79: taglen = (int)argv[2];
80: argc--; argv++;
81: }
82: break;
83: case 'l': /* specify length of lists */
84: argc--; argv++;
85: lmaster = atoi(argv[1]);
86: # if D1
87: fprintf(stderr, "lmaster now %d\n",lmaster);
88: # endif
89: break;
90: case 'C':
91: argc--; argv++;
92: colevel = atoi(argv[1]);
93: break;
94: }
95: argc--; argv++;
96: }
97: strcpy (indexname, todir(argv[1]));
98: # if D1
99: fprintf(stderr, "in huntmain indexname %s typeindex %d\n", indexname, typeindex);
100: # endif
101: if (typeindex == 0 || strcmp (oldname, indexname) !=0)
102: {
103: strcpy (oldname, indexname);
104: unopen(fa); unopen(fb); unopen(fc);
105:
106: if (ckexist(indexname, ".ib"))
107: {
108: # if D1
109: fprintf(stderr, "found old index\n");
110: # endif
111: fa = iopen(indexname, ".ia");
112: fb = iopen(indexname, ".ib");
113: fc = iopen(indexname, ".ic");
114: typeindex =1;
115: # if D1
116: fprintf(stderr, "opened f's as %o %o %o\n",fa,fb,fc);
117: # endif
118: indexdate = gdate(fb);
119: fread (&nhash, sizeof(nhash), 1, fa);
120: fread (&iflong, sizeof(iflong), 1, fa);
121: if (nhash > maxhash)
122: {
123: if (hpt)
124: free (hpt, maxhash, sizeof(*hpt));
125: hpt=0;
126: if (hfreq)
127: free(hfreq, maxhash, sizeof(*hfreq));
128: hfreq=0;
129: maxhash=nhash;
130: # if D1
131: fprintf(stderr, "Freed if needed maxhash %d\n",maxhash);
132: # endif
133: }
134: if (hpt==0)
135: hpt = zalloc(nhash, sizeof(*hpt));
136: # if D1
137: fprintf(stderr, "hpt now %o\n",hpt);
138: # endif
139: if (hpt == NULL)
140: err ("No space for hash list (%d)", nhash);
141: fread( hpt, sizeof(*hpt), nhash, fa);
142: if (hfreq==0)
143: hfreq= (int *) zalloc(nhash, sizeof(*hfreq));
144: if (hfreq==NULL)
145: err ("No space for hash frequencies (%d)", nhash);
146: frtbl = fread(hfreq, sizeof(*hfreq), nhash, fa);
147: hfrflg = (frtbl == nhash);
148: # if D1
149: fprintf(stderr,"Read pointer files\n");
150: # endif
151: if (master.a == NULL)
152: if (iflong)
153: master.b = zalloc(lmaster, sizeof(long));
154: else
155: master.a = (unsigned *)zalloc(lmaster, sizeof(int));
156: if (master.a == NULL)
157: err ("no space for answer list",0);
158: }
159: else
160: if (makefgrep(indexname))
161: typeindex=2;
162: else
163: {
164: err ("No files %s\n",indexname);
165: exit(1);
166: }
167: }
168:
169: # if D1
170: fprintf(stderr, "typeindex now %d\n",typeindex);
171: # endif
172: tagout[0]=0;
173: if (typeindex==2)
174: {
175: grepcall(sinput, tagout, indexname);
176: # if D1
177: fprintf(stderr, " back from grepcall\n");
178: # endif
179: restodir();
180: return;
181: }
182: nitem = getq(qitem);
183: # if D1
184: fprintf(stderr, "approaching doquery fb %o\n", fb);
185: # endif
186: nfound = doquery(hpt, nhash, fb, nitem, qitem, master);
187: # ifdef D1
188: fprintf(stderr, "return from doquery with nfound %d\n", nfound);
189: # endif
190: if (falseflg == 0)
191: nfound = baddrop(master, nfound, fc, nitem, qitem, rprog, full);
192: # ifdef D1
193: fprintf(stderr, "after baddrop with nfound %d\n",nfound);
194: fprintf(stderr, "tagout is /%s/, sout /%s/\n",tagout, soutput);
195: # endif
196: if (tags)
197: result (master, nfound >tags ? tags : nfound, fc);
198: # if D1
199: fprintf(stderr, "done with huntmain\n");
200: fprintf(stderr, "tagout is /%s/\n", tagout);
201: fprintf(stderr, "string out is /%s/\n", soutput);
202: # endif
203: if (fgnamp>fgnames)
204: {
205: char **fgp;
206: int k;
207: # if D1
208: fprintf(stderr, "were %d bad files\n", fgnamp-fgnames);
209: # endif
210: grepquery[0]=0;
211: for(k=0; k<nitem; k++)
212: {
213: strcat(grepquery, " ");
214: strcat(grepquery, qitem[k]);
215: }
216: for(fgp=fgnames; fgp<fgnamp; fgp++)
217: {
218: # if D1
219: fprintf(stderr, "Now on %s query /%s/\n", *fgp, grepquery);
220: # endif
221: makefgrep(*fgp);
222: grepcall(grepquery, tagout, *fgp);
223: # if D1
224: fprintf(stderr, "tagout now /%s/\n", tagout);
225: # endif
226: }
227: }
228: restodir();
229: }
230:
231: char *
232: todir(t)
233: char *t;
234: {
235: char *s;
236: s=t;
237: while (*s) s++;
238: while (s>=t && *s != '/') s--;
239: if (s<t) return(t);
240: *s++ = 0;
241: t = (*t ? t : "/");
242: chdir (t);
243: strcpy (usedir,t);
244: return(s);
245: }
246: setfrom(c)
247: {
248: switch(c)
249: {
250: case 'y': case '\0':
251: default:
252: return(1000);
253: case '1':
254: case '2': case '3': case '4': case '5':
255: case '6': case '7': case '8': case '9':
256: return(c-'0');
257: case 'n': case '0':
258: return(0);
259: }
260: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.