|
|
1.1 ! root 1: # include "stdio.h" ! 2: # include "cbt.h" ! 3: # include "assert.h" ! 4: # include "ctype.h" ! 5: # include "time.h" ! 6: # include "sys/types.h" ! 7: # include "sys/stat.h" ! 8: extern int day, yesterday; ! 9: # define NST 200 ! 10: extern int stc, inolim; ! 11: extern char storylist[NST][12]; ! 12: extern char nowfile[]; ! 13: extern char *storydir; ! 14: extern char names[20][14]; ! 15: extern char heads[20][50]; ! 16: char *index(); ! 17: extern int inodes[NST+5]; ! 18: ! 19: getkeys(firsen) ! 20: { ! 21: # define NWS 50 ! 22: char lb[200], *srchvec[NWS+1], *v[40], *s, *sufstr(); ! 23: char wb[NWS+1][15]; ! 24: int i, n, ng; ! 25: FILE *f; ! 26: f = fopen(nowfile, "r"); ! 27: n=0; ! 28: if (f==NULL) return; ! 29: while (fgets(lb, 200, f)) ! 30: { ! 31: if (lb[0]=='^') continue; ! 32: trimnl(lb); ! 33: ng = getargs(lb, v); ! 34: for(i=0; i<ng; i++) ! 35: { ! 36: if (common(v[i])) continue; ! 37: s = sufstr(v[i]); ! 38: if (strlen(s)>= 14) s[14]=0; ! 39: strcpy(srchvec[n]=wb[n], s); ! 40: if (n++ >NWS) break; ! 41: } ! 42: if (n>NWS) break; ! 43: } ! 44: fclose(f); ! 45: if (n<=0) return; ! 46: lkkeys( srchvec, n); ! 47: } ! 48: wdsearch(s, firsen) ! 49: char *s; ! 50: { ! 51: char *srchvec[50]; ! 52: int n; ! 53: n=mksrch (s, srchvec); ! 54: lkkeys( srchvec, n); ! 55: if (firsen) printf("----\n"); ! 56: } ! 57: mksrch (s, v) ! 58: char *s, *v[]; ! 59: { ! 60: char *g[20]; ! 61: int i, n, ng; ! 62: static char wb[20][20]; ! 63: lcase(s); ! 64: ng = getargs(s, g); ! 65: for (n=i=0; i<ng; i++) ! 66: { ! 67: if (common(g[i])) continue; ! 68: strcpy(v[n] = wb[n], sufstr(g[i])); ! 69: n++; ! 70: } ! 71: return(n); ! 72: } ! 73: bfile *bf=NULL; ! 74: bfile *bfy=NULL; ! 75: long ytim = 0L; ! 76: # define ND 50 ! 77: struct dst { ! 78: char dn[6]; ! 79: int dc; ! 80: }; ! 81: struct dst docs[ND]; ! 82: struct dst *pnd = docs; ! 83: lkkeys (srchvec, n) ! 84: char *srchvec[]; ! 85: { ! 86: mbuf key, rkey, rrec; ! 87: char ka[100], kb[100], kc[100], *dn; ! 88: int i; ! 89: key.mdata =ka; rkey.mdata=kb; rrec.mdata=kc; ! 90: if (bf==NULL) ! 91: { ! 92: sprintf(ka, "%s/.I%d", storydir, day); ! 93: bf = bopen(ka, 0); ! 94: if (bf==NULL) return; ! 95: } ! 96: if (bfy==NULL) ! 97: { ! 98: sprintf(ka, "%s/.I%d", storydir, yesterday); ! 99: bfy = bopen(ka,0); ! 100: strcat(ka, ".T"); ! 101: ytim = filtim(ka); ! 102: } ! 103: pnd = docs; ! 104: for(i=0; i<n; i++) ! 105: { ! 106: sprintf(key.mdata, "%s.", srchvec[i]); ! 107: key.mlen = strlen(key.mdata); ! 108: bseek (bf, key); ! 109: while (bread(bf, &rkey, &rrec)==NULL) ! 110: { ! 111: rkey.mdata[rkey.mlen]=0; ! 112: if (strncmp(rkey.mdata, key.mdata, key.mlen)!=0) ! 113: break; ! 114: docfnd(index(rkey.mdata, '.')); ! 115: } ! 116: if (bfy==NULL) continue; ! 117: bseek(bfy, key); ! 118: while (bread(bfy, &rkey, &rrec)==NULL) ! 119: { ! 120: rkey.mdata [rkey.mlen]=0; ! 121: if (strncmp(rkey.mdata, key.mdata, key.mlen)!=0) ! 122: break; ! 123: dn = index(rkey.mdata, '.'); ! 124: /* check that dn has not been overwritten */ ! 125: if (dn && filtim(dn+1) <= ytim) ! 126: docfnd(dn); ! 127: } ! 128: } ! 129: docsrt(); ! 130: n = pnd-docs; ! 131: if (n>20) n=20; ! 132: for(i=0; i<n; i++) ! 133: strcpy(names[i], docs[i].dn); ! 134: for (; i<20; i++) ! 135: names[i][0]=0; ! 136: for(i=0; i<20; i++) ! 137: heads[i][0]=0; ! 138: disprint(); ! 139: } ! 140: docfnd(s) ! 141: char *s; ! 142: { ! 143: int i; ! 144: struct dst *p; ! 145: if (s==NULL) return; ! 146: s++; ! 147: assert(strlen(s)<=5); ! 148: for(p=docs; p<pnd; p++) ! 149: { ! 150: if (strcmp(s, p->dn)==0) ! 151: break; ! 152: } ! 153: if (p<pnd) ! 154: p->dc++; ! 155: else ! 156: { ! 157: if (pnd>=docs+ND) return; ! 158: strcpy(pnd->dn, s); ! 159: pnd->dc=1; ! 160: pnd++; ! 161: } ! 162: } ! 163: docsrt() ! 164: { ! 165: int dcmp(); ! 166: struct dst *p; ! 167: qsort( docs, pnd-docs, sizeof(*pnd), dcmp); ! 168: } ! 169: dcmp(p1, p2) ! 170: struct dst *p1, *p2; ! 171: { ! 172: return (p2->dc - p1->dc); ! 173: } ! 174: menu(lc) ! 175: { ! 176: char *m; ! 177: tpos(10,0); ! 178: if (lc==1) ! 179: m="titles"; ! 180: else if (lc==0) ! 181: m="of this story"; ! 182: else if (lc==2) ! 183: m="first sentences"; ! 184: printf("CR: more %s; t: top titles; m: more titles; t>N: top, rated >= N;\n", m); ! 185: printf("s: search words; y: search story; c: copy; q: exit\n"); ! 186: } ! 187: extend(n) ! 188: { ! 189: /* make sure we have n stories */ ! 190: int i, ino; ! 191: FILE *f; ! 192: char line[20]; ! 193: struct stat stbuff; ! 194: if (stc>=n) return; ! 195: for (i=inolim; i<stc; i++) ! 196: { ! 197: stat (storylist[i], &stbuff); ! 198: inodes[i]= stbuff.st_ino; ! 199: } ! 200: if (access("..slist", 04)!=0 || (stc==0 && ! 201: filtim(".") > filtim("..slist"))) ! 202: { ! 203: if (fork()==0) ! 204: { ! 205: close(1); ! 206: assert( creat("..slist", 0666) == 1); ! 207: chmod("..slist", 0666); ! 208: execl("/usr/bin/ls", "ls", "-t", 0); ! 209: execl("/bin/ls", "ls", "-t", 0); ! 210: assert(0); ! 211: } ! 212: wait(0); ! 213: } ! 214: f = fopen("..slist", "r"); ! 215: assert(f!=NULL); ! 216: while (fgets(line, 20, f)) ! 217: { ! 218: trimnl(line); ! 219: /* acceptable lines are a9999 or mondy.a9999 */ ! 220: if (strlen(line)==5 && line[0]=='a') ! 221: ; ! 222: else ! 223: if (strlen(line)==11 && line[6]=='a') ! 224: ; ! 225: else ! 226: continue; ! 227: i=stat (line, &stbuff); ! 228: if (i!=0) continue; ! 229: ino = stbuff.st_ino; ! 230: for(i=0; i<stc; i++) ! 231: if (ino == inodes[i]) ! 232: break; ! 233: if (i<stc) ! 234: continue; ! 235: inodes[inolim=stc]=ino; ! 236: strcpy(storylist[stc++], line); ! 237: if (stc>=100) break; ! 238: } ! 239: fclose(f); ! 240: return; ! 241: } ! 242: long ! 243: filtim( f) ! 244: char *f; ! 245: { ! 246: struct stat stbuff; ! 247: int k; ! 248: k = stat (f, &stbuff); ! 249: if (k!=0) return(0L); ! 250: return(stbuff.st_mtime); ! 251: } ! 252: /* the next routine picks out longest word */ ! 253: pickbig (wv, nw) ! 254: char **wv; ! 255: { ! 256: int mlen, mat, i, k, c; ! 257: for(mlen=mat=i=0; i<nw; i++) ! 258: { ! 259: k = strlen(wv[i]); ! 260: if (k>mlen) ! 261: { ! 262: mlen=k; ! 263: mat=i; ! 264: } ! 265: } ! 266: c = wv[mat][0]; ! 267: if (islower(c)) wv[mat][0]=toupper(c); ! 268: return(mat); ! 269: } ! 270: lcase(s) ! 271: char *s; ! 272: { ! 273: for ( ; *s; s++) ! 274: { ! 275: if (isupper(*s)) ! 276: *s = tolower(*s); ! 277: } ! 278: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.