1: #include "refer.h" 2: # include "stdio.h" 3: # define unopen(fil) {if (fil!=NULL) {fclose(fil); fil=NULL;}} 4: extern char refdir[]; 5: int lmaster LLIST; 6: int *hfreq, hfrflg; 7: union ptr master NULL; 8: int iflong; 9: long *hpt 0; 10: int nhash 0; 11: extern char *fgnames[], **fgnamp; 12: extern char fgspace[], *fgp; 13: int typeindex 0; 14: char usedir[100]; 15: long indexdate 0, gdate(); 16: FILE *fa, *fb, *fc; 17: char *qitem[NQUERY]; 18: 19: huntmain(index) 20: char *index; 21: { 22: char indexname[100]; 23: char grepquery[QLEN]; 24: static char oldname[15] ; 25: static int maxhash 0; 26: int nitem, frtbl; 27: 28: savedir(); 29: strcpy (indexname, todir(index)); 30: fgnamp = fgnames; 31: fgp = fgspace; 32: if (typeindex == 0 || strcmp (oldname, indexname) !=0) 33: { 34: strcpy (oldname, indexname); 35: unopen(fa); 36: unopen(fb); 37: unopen(fc); 38: 39: if (ckexist(indexname, ".ib")) 40: { 41: fa = iopen(indexname, ".ia"); 42: fb = iopen(indexname, ".ib"); 43: fc = iopen(indexname, ".ic"); 44: typeindex =1; 45: indexdate = gdate(fb); 46: fread (&nhash, sizeof(nhash), 1, fa); 47: fread (&iflong, sizeof(iflong), 1, fa); 48: if (nhash > maxhash) 49: { 50: if (hpt) 51: free (hpt, maxhash, sizeof(*hpt)); 52: hpt=0; 53: if (hfreq) 54: free(hfreq, maxhash, sizeof(*hfreq)); 55: hfreq=0; 56: maxhash=nhash; 57: } 58: if (hpt==0) 59: hpt = zalloc(nhash, sizeof(*hpt)); 60: if (hpt == NULL) 61: err ("No space for hash list (%d)", nhash); 62: fread( hpt, sizeof(*hpt), nhash, fa); 63: if (hfreq==0) 64: hfreq=zalloc(nhash, sizeof(*hfreq)); 65: if (hfreq==NULL) 66: err ("No space for hash frequencies (%d)", nhash); 67: frtbl = fread(hfreq, sizeof(*hfreq), nhash, fa); 68: hfrflg = (frtbl == nhash); 69: if (master.a == NULL) 70: if (iflong) 71: master.b = zalloc(lmaster, sizeof(long)); 72: else 73: master.a = zalloc(lmaster, sizeof(int)); 74: if (master.a == NULL) 75: err ("no space for answer list",0); 76: } 77: else 78: if (makefgrep(indexname)) 79: typeindex=2; 80: else 81: { 82: err ("No files %s\n",indexname); 83: exit(1); 84: } 85: } 86: 87: tagout[0]=0; 88: if (typeindex==2) 89: { 90: grepcall(sinput, indexname); 91: restodir(); 92: return; 93: } 94: nitem = getq(qitem); 95: nfound = doquery(nitem); 96: nfound = baddrop(nfound, nitem); 97: if (fgnamp>fgnames) 98: { 99: char **fgp; 100: int k; 101: grepquery[0]=0; 102: for(k=0; k<nitem; k++) 103: { 104: strcat(grepquery, " "); 105: strcat(grepquery, qitem[k]); 106: } 107: for(fgp=fgnames; fgp<fgnamp; fgp++) 108: { 109: makefgrep(*fgp); 110: grepcall(grepquery, *fgp); 111: } 112: } 113: restodir(); 114: } 115: 116: todir(t) 117: char *t; 118: { 119: char *s; 120: s=t; 121: while (*s) s++; 122: while (s>=t && *s != '/') s--; 123: if (s<t) { 124: if (usedir[0]) 125: typeindex = 0; 126: usedir[0] = 0; 127: return(t); 128: } 129: *s++ = 0; 130: t = (*t ? t : "/"); 131: chdir (t); 132: if (strcmp(usedir,t)) 133: typeindex = 0; 134: strcpy (usedir,t); 135: *(s-1) = '/'; 136: return(s); 137: } 138: # include "sys/types.h" 139: # include "sys/stat.h" 140: long gdate(f) 141: FILE *f; 142: { 143: struct stat sb; 144: fstat (f->_file, &sb); 145: return (sb . st_mtime); 146: }