# include "stdio.h" # define unopen(fil) {if (fil!=NULL) {fclose(fil); fil=NULL;}} #include "refer.h" #ifndef D1 #define D1 0 #endif int reached = 0; FILE *fd = 0; int colevel = 0; extern char *fgnames[], **fgnamp; int prfreqs = 0; int typeindex = 0; char usedir[100]; static int full = 1000; static int tags = 0; char *sinput, *soutput, *tagout; long indexdate = 0; int soutlen = 1000; int taglen = 1000; void huntmain(int argc, char **argv) { /* read query from stdin, expect name of indexes in argv[1] */ static FILE *fa, *fb, *fc; char indexname[DIRLEN], *qitem[NITEM], *rprog = 0; static char oldname[DIRLEN]; int alldrops = 0, nitem; List *drops; static Index ind; savedir(); for (; argc > 1 && argv[1][0] == '-'; argc--, argv++) { switch (argv[1][1]) { case 'a': /* all output, incl. false drops */ alldrops = 1; break; case 'r': argc--; argv++; rprog = argv[1]; break; case 'F': /* put out full text */ full = setfrom(argv[1][2]); break; case 'T': /* put out tags */ tags = setfrom(argv[1][2]); break; case 'i': /* input in argument string */ argc--; argv++; sinput = argv[1]; break; case 's': /*text output to string */ case 'o': argc--; argv++; soutput = argv[1]; if ((int)(argv[2]) < 16000) { soutlen = (int) argv[2]; argc--; argv++; } break; case 't': /*tag output to string */ argc--; argv++; tagout = argv[1]; if ((int)(argv[2]) < 16000) { taglen = (int)argv[2]; argc--; argv++; } break; case 'l': /* specify length of lists */ argc--; argv++; break; case 'C': argc--; argv++; colevel = atoi(argv[1]); break; } } strcpy(indexname, todir(argv[1])); # if D1 fprintf(stderr, "in huntmain indexname %s typeindex %d\n", indexname, typeindex); #endif if (typeindex == 0 || strcmp(oldname, indexname) != 0) { strcpy(oldname, indexname); unopen(fa); unopen(fb); unopen(fc); unopen(fd); if (ckexist(indexname, ".ib")) { # if D1 fprintf(stderr, "found old index\n"); #endif fa = iopen(indexname, ".ia"); fb = iopen(indexname, ".ib"); fc = iopen(indexname, ".ic"); if (ckexist(indexname, ".id")) fd = iopen(indexname, ".id"); typeindex = 1; # if D1 fprintf(stderr, "opened f's as %o %o %o\n", fa, fb, fc); #endif indexdate = gdate(fb); getindex(&ind, fa); # if D1 fprintf(stderr, "Read pointer files\n"); #endif } else { err("can't find index files %s.i[abc] - run pubindex\n", indexname); exit(1); } } # if D1 fprintf(stderr, "typeindex now %d\n", typeindex); #endif tagout[0] = 0; nitem = getq(qitem, NITEM); # if D1 fprintf(stderr, "approaching doquery fb %o\n", fb); #endif drops = doquery(&ind, fb, nitem, qitem); #if D1 fprintf(stderr, "return from doquery with nfound %d\n", drops->n); #endif if (!alldrops) dropout(drops, fc, nitem, qitem, rprog, full); #if D1 fprintf(stderr, "after dropout with nfound %d\n", drops->n); fprintf(stderr, "tagout is /%s/, sout /%s/\n", tagout, soutput); #endif if (tags) result(drops, tags, fc); # if D1 fprintf(stderr, "done with huntmain\n"); fprintf(stderr, "tagout is /%s/\n", tagout); fprintf(stderr, "string out is /%s/\n", soutput); #endif restodir(); }