1: # include "what..c" 2: struct filans files[NFILES]; 3: char fnames[NAMES]; 4: int relfeed 0; 5: char *rb[NFEED]; 6: char rbb[200], *rbp rbb;; 7: 8: main(argc,argv) 9: char *argv[]; 10: { 11: char *s, *t, *xargv[50], *wd[50]; 12: struct filans *af; 13: int xargc 0, nw, nf, i; 14: while (argc>1 && argv[1][0]=='-') 15: { 16: switch(argv[1][1]) 17: { 18: case 'r': relfeed=1; break; 19: } 20: argc--; argv++; 21: } 22: if (argc<=1) 23: { 24: printf("No query.\n"); 25: return(0); 26: } 27: nf = doclook(argc,argv,0); 28: printf(" %d files\n",nf); 29: if (relfeed && nf>NFEED) 30: { 31: wrdoc(NFEED, argc, argv, 1); 32: nw = freqwd (rb, wd, argc); 33: for(i=0; rb[i]; i++) 34: unlink(rb[i]); 35: } 36: for(i=0; i<argc; i++) 37: xargv[xargc++]=argv[i]; 38: if (relfeed) 39: { 40: printf("Adding: "); 41: for(i=0; i<nw; i++) 42: if (!lfind(wd[i], xargc, xargv)) 43: printf("%s ", xargv[xargc++]=wd[i]); 44: printf("\n"); 45: nf = doclook(xargc, xargv, relfeed? xargc/4 : 0); 46: printf(" %d files\n",nf); 47: } 48: shell (nf, comp, exch); 49: wrdoc(nf, xargc, xargv, 0); 50: return(0); 51: } 52: exch( i1, i2 ) 53: { 54: struct filans *p1, *p2; 55: struct filans xt; 56: p1=files+i1; 57: p2=files+i2; 58: xt = *p1; 59: *p1 = *p2; 60: *p2 = xt; 61: } 62: comp(i1, i2) 63: { 64: struct filans *p1, *p2; 65: p1 = files+i1; 66: p2= files+i2; 67: if (p1->fdate != p2->fdate) 68: return(p2->fdate > p1->fdate); 69: return(p2->uid >= p1->uid); 70: } 71: wrdoc ( np, argc, argv, relfeed ) 72: { 73: struct filans *af; 74: char *s, *t, buf[200]; 75: int eval, k, pid; 76: FILE *rf NULL; 77: FILE *ans NULL; 78: pid=getpid(); 79: for(af=files; af<files+np; af++) 80: { 81: t = ctime(&af->fdate); 82: getpw(af->uid, s=buf); 83: while (*s && *s!=':') s++; 84: *s=0; 85: printf("%s (%.20s) %s, %ld bytes\n",af->nm,t+4,buf,af->size); 86: if (relfeed) 87: { 88: k=af-files; 89: _assert (k<NFEED); 90: sprintf(rb[k]=rbp, "rf%d.%d",pid, k); 91: rf = fopen(rb[k], "w"); 92: while (*rbp++); 93: } 94: describe(af->nm, argc,argv, rf); 95: if (relfeed) 96: { 97: printf("You like that one?"); 98: fflush(stdout); 99: fgets(buf, 100, stdin); 100: switch(buf[0]) 101: { 102: case 'y': case 'Y': eval=1; break; 103: case 'n': case 'N': eval = -1; break; 104: default: eval=0; break; 105: } 106: fclose(rf); 107: if (eval<=0) 108: { 109: unlink(rb[k]); 110: rb[k][0]=0; 111: } 112: } 113: } 114: if (relfeed) rb[np]=0; 115: } 116: lfind( wl, n, wds) 117: char *wl, *wds[]; 118: { 119: int i; 120: for(i=0; i<n; i++) 121: if (str6cmp(wl, wds[i])==0) 122: return(1); 123: return(0); 124: } 125: str6cmp(s, t) 126: char *s, *t; 127: { 128: int i 0, c; 129: while ( (c= *s++ ) == ( *t++)) 130: if (c==0 || ++i ==6) 131: return(0); 132: return(1); 133: }