|
|
1.1 ! root 1: # include "stdio.h" ! 2: # include "ctype.h" ! 3: # include "assert.h" ! 4: # include "signal.h" ! 5: # include "sys/types.h" ! 6: # include "sys/stat.h" ! 7: # include "cbt.h" ! 8: # include "time.h" ! 9: char names[20][14]; ! 10: char heads[20][50]; ! 11: # define NST 200 ! 12: char storylist[NST][12]; ! 13: int stc=0; ! 14: int intr(); ! 15: char *getlogin(), *ctime(); ! 16: struct tm *localtime(); ! 17: int day, yesterday; ! 18: int stp=0; ! 19: int inolim=0; ! 20: int inodes[NST+5]; ! 21: char *getenv(), *getpwd(); ! 22: char nowfile[20]; ! 23: char pwdir[50]; ! 24: long filtim(); ! 25: char *storydir = "/usr/spool/ap"; ! 26: ! 27: /* logging */ ! 28: char *apnlog = "/usr/spool/ap/apnlog"; ! 29: long tmstart, tmend; ! 30: int nslug, nstory, nsearch; ! 31: ! 32: main(argc,argv) ! 33: char *argv[]; ! 34: { ! 35: char line[100]; ! 36: int i, lc=1; ! 37: long l; ! 38: char *ctp, *userp; ! 39: char forcebuf[BUFSIZ]; ! 40: setbuf(stdout, forcebuf); ! 41: for (argc--,argv++; argc>0 && argv[0][0]=='-'; argc--,argv++) ! 42: switch(argv[0][1]) ! 43: { ! 44: case 'f': ! 45: storydir = argv[1]; ! 46: argv++; argc--; ! 47: break; ! 48: } ! 49: tmstart = l = time(0); ! 50: day = localtime(&l)->tm_mday; ! 51: l -= 86400; /* go back one day */ ! 52: yesterday = localtime(&l)->tm_mday; ! 53: signal (SIGINT, intr); ! 54: strcpy(pwdir, getpwd()); ! 55: i = chdir(storydir); ! 56: if (i!=0) ! 57: { ! 58: fprintf(stderr, "no directory %s\n",storydir); ! 59: exit(1); ! 60: } ! 61: top(); ! 62: extend(20); ! 63: display(); ! 64: menu(lc); ! 65: fflush(stdout); ! 66: extend(30); ! 67: while (gets(line)) ! 68: { ! 69: tpos(0,0); ! 70: switch(line[0]) ! 71: { ! 72: case '0': case '1': case '2': case '3': case '4': ! 73: case '5': case '6': case '7': case '8': case '9': ! 74: i = atoi(line)-1; ! 75: if (i<0 || i>19) continue; ! 76: pr(names[i]); ! 77: nstory++; ! 78: lc=0; ! 79: break; ! 80: case 0: /* continue this story */ ! 81: if (lc==0) ! 82: pr(0); ! 83: else if (lc==1) ! 84: display(); ! 85: else if (lc==2) ! 86: sums(); ! 87: if (lc>0) menu(lc); ! 88: break; ! 89: case '?': ! 90: menu(0); ! 91: break; ! 92: case '!': ! 93: system(line+1); ! 94: break; ! 95: case '.': ! 96: disprint(); ! 97: break; ! 98: case 'a': ! 99: pr(line); ! 100: nstory++; ! 101: lc=0; ! 102: break; ! 103: case '+': ! 104: case 'm': ! 105: display(); ! 106: lc=1; ! 107: break; ! 108: case 'M': ! 109: sums(); ! 110: menu(lc=2); ! 111: break; ! 112: case 't': ! 113: top(); ! 114: extend(20); ! 115: display(); ! 116: menu(lc=1); ! 117: break; ! 118: case 'T': ! 119: top(); ! 120: extend(20); ! 121: sums(); ! 122: menu(lc=2); ! 123: break; ! 124: case 'c': ! 125: case 'C': /* copy file to my directory */ ! 126: i = atoi(line+1); ! 127: if (i>0) ! 128: strcpy(nowfile, names[i-1]); ! 129: copyto(line+1, nowfile); ! 130: break; ! 131: case 'D': /* delete file*/ ! 132: i = atoi(line+1); ! 133: if (i>0) ! 134: strcpy(nowfile, names[i-1]); ! 135: printf("Deleting /%s/\n",nowfile); ! 136: unlink(nowfile); ! 137: break; ! 138: case 'Y': ! 139: case 'y': /* must get keyword list */ ! 140: getkeys(line[0]=='Y'); ! 141: break; ! 142: case 'S': ! 143: case 's': /* search for words */ ! 144: wdsearch (line+1, line[0]=='S'); ! 145: nsearch++; ! 146: break; ! 147: case 'q': ! 148: tpos(23,0); ! 149: wrap(); ! 150: } ! 151: fflush(stdout); ! 152: } ! 153: tpos(23,0); ! 154: wrap(); ! 155: } ! 156: intr() ! 157: { ! 158: tpos(23,0); ! 159: wrap(); ! 160: exit(0); ! 161: } ! 162: int llens[10] ={70,70,70,70,70,70,70,70,70,70}; ! 163: pr (s) ! 164: char *s; ! 165: { ! 166: static FILE *f=NULL; ! 167: char line[120]; ! 168: int i, k, k1; ! 169: if (s && s[0]==0) ! 170: return; ! 171: if (s!=0) ! 172: { ! 173: if (f!= NULL) fclose(f); ! 174: f = fopen(s, "r"); ! 175: if (f==NULL) ! 176: { ! 177: printf("No file %s\n", s); ! 178: return; ! 179: } ! 180: strcpy(nowfile, s); ! 181: } ! 182: else ! 183: if (f==NULL) return; ! 184: tpos(12,0); ! 185: if (ifclear()) ! 186: clr2end(); ! 187: for(i=0; i<10; i++) ! 188: { ! 189: if(fgets(line, 100, f)==0) ! 190: break; ! 191: trimnl(line); ! 192: k = strlen(line); ! 193: if (line[0]=='\t') k+= 7; ! 194: if (!ifclear() &&ifclrline()) ! 195: clrline(); ! 196: fputs(line, stdout); ! 197: if (!ifclear() && !ifclrline()) ! 198: for(k1=llens[i]; k1>k; k1--) ! 199: putchar(' '); ! 200: printf("\n"); ! 201: llens[i]=k+1; ! 202: } ! 203: } ! 204: trimnl(s) ! 205: char *s; ! 206: { ! 207: while (*s) s++; ! 208: if (*--s == '\n') *s=0; ! 209: } ! 210: static hfgate=0; ! 211: static char hfbuff[5000]; ! 212: static char *hflab[400]; ! 213: static int hftop=0; ! 214: hfast (out, snam) ! 215: char *out, *snam; ! 216: { ! 217: char *s; ! 218: int i; ! 219: if (hfgate==0) ! 220: { ! 221: int f, n; ! 222: char fn[40], *index(); ! 223: sprintf(fn, "%s/.S%d", storydir, day); ! 224: f = open(fn, 0); ! 225: if (f<0) return(0); ! 226: n= read (f, hfbuff, 5000); ! 227: hfbuff[n]=0; ! 228: close(f); ! 229: hfgate=1; ! 230: s = hfbuff; ! 231: for(hftop=0; hftop<400; hftop++) ! 232: { ! 233: if (*s==0) break; ! 234: hflab[hftop] = s; ! 235: s = index(s, '\n'); ! 236: if (s==NULL) break; ! 237: *s++ = 0; ! 238: } ! 239: } ! 240: for(i=0; i<hftop; i++) ! 241: { ! 242: if (strncmp(snam, hflab[i], 5)==0 && hflab[i][6] !=0) ! 243: { ! 244: strcpy(out, hflab[i]+6); ! 245: return(1); ! 246: } ! 247: } ! 248: return(0); ! 249: } ! 250: hget(s, f) ! 251: char s[]; ! 252: FILE *f; ! 253: { ! 254: int i, c, nw; ! 255: char line[100], *wv[40], *p; ! 256: if (f==NULL) ! 257: { ! 258: *s=0; ! 259: return; ! 260: } ! 261: fgets(line, 100, f); ! 262: trimnl(line); ! 263: if (line[1]==' ' && line[3]==' ' && line[6]=='-') /* their heading */ ! 264: { ! 265: for(p=line+7; (c = *p) && c!=' '; p++) ! 266: *s++ = c; ! 267: *s=0; ! 268: return; ! 269: } ! 270: nw = getargs(line, wv); ! 271: strcpy(s, wv[i=pickbig(wv, nw)]); ! 272: wv[i]=""; ! 273: strcat(s, wv[pickbig(wv,nw)]); ! 274: return; ! 275: } ! 276: notnew(i, inodes, fname) ! 277: char *fname; ! 278: int *inodes; ! 279: { ! 280: int ino, j; ! 281: struct stat stbuff; ! 282: stat (fname, &stbuff); ! 283: ino = stbuff.st_ino; ! 284: for(j=0; j<i; j++) ! 285: if (ino==inodes[j]) ! 286: return(1); ! 287: inodes[i]=ino; ! 288: return(0); ! 289: } ! 290: display() ! 291: { ! 292: getnam(20); ! 293: disprint(); ! 294: nslug += 20; ! 295: } ! 296: disprint() ! 297: { ! 298: int i, kl, a; ! 299: char bform[30]; ! 300: FILE *fl; ! 301: startsc(); ! 302: for(i=0; i<20; i++) ! 303: { ! 304: if (names[i][0]== '\0') ! 305: break; ! 306: if (hfast(heads[i], names[i])) ! 307: continue; ! 308: fl = fopen(names[i], "r"); ! 309: if (fl!=NULL) ! 310: { ! 311: hget(heads[i],fl); ! 312: fclose(fl); ! 313: } ! 314: else ! 315: heads[i][0]=names[i][0]=0; ! 316: } ! 317: for(kl=i=0; i<10; i++) ! 318: { ! 319: a = strlen(heads[i]); ! 320: if (a>kl) kl=a; ! 321: } ! 322: kl += 2; ! 323: if (kl>30) kl=30; ! 324: sprintf(bform, "%%3d: (%%5s) %%-%d.%ds ", kl, kl); ! 325: for(i=0; i<10; i++) ! 326: { ! 327: clrline(); ! 328: if (strlen(names[i])<=5) ! 329: printf(bform, i+1, names[i], heads[i]); ! 330: else ! 331: printf("%3d: (%11s) %-19.19s ",i+1,names[i],heads[i]); ! 332: printf("%3d: (%5s) %.30s\n",i+11,names[i+10],heads[i+10]); ! 333: } ! 334: } ! 335: top() ! 336: { ! 337: char tstories[NST][6]; ! 338: int f, n, i, j; ! 339: stc = inolim = stp = 0; ! 340: f = open("..tlist", 0); ! 341: if (f<0) return; ! 342: n = read(f, tstories, NST*6); ! 343: stc = n/6; ! 344: /* reverse tstories */ ! 345: for(i=0, j=stc-1; i<j; i++,j--) ! 346: { ! 347: char x[6]; ! 348: strncpy(x,tstories[i],6); ! 349: strncpy(tstories[i],tstories[j],6); ! 350: strncpy(tstories[j],x,6); ! 351: } ! 352: close(f); ! 353: for(i=0; i<stc; i++) ! 354: { ! 355: strncpy(storylist[i],tstories[i],6); ! 356: storylist[i][6]= 0; ! 357: } ! 358: } ! 359: getnam(n) ! 360: { ! 361: int i; ! 362: for (i=0; i<n; i++) ! 363: heads[i][0]= names[i][0]= '\0'; ! 364: for (i=0; i<n; i++) ! 365: { ! 366: try: ! 367: if (stp>=stc) break; ! 368: strcpy(names[i], storylist[stp++]); ! 369: ! 370: if (names[i][0]=='a' && isdigit(names[i][1])) ! 371: continue; ! 372: if (names[i][5]=='.' && names[i][6]=='a' && ! 373: isdigit(names[i][7])) ! 374: continue; ! 375: goto try; ! 376: } ! 377: } ! 378: sums() ! 379: { ! 380: int i; ! 381: startsc(); ! 382: getnam(10); ! 383: for (i=0; i<10; i++) ! 384: { ! 385: printf("%d ",i+1); ! 386: prsum(names[i]); ! 387: } ! 388: } ! 389: wrap() ! 390: { ! 391: FILE *f; ! 392: tmend = time(0); ! 393: f = fopen(apnlog, "a"); ! 394: if (f!=NULL) ! 395: { ! 396: fprintf(f, ! 397: "%s slugs %d stories %d searches %d dir %s %.16s %d secs\n", ! 398: getlogin(), nslug, nstory, nsearch, storydir, ! 399: ctime(&tmstart), tmend-tmstart); ! 400: fclose(f); ! 401: } ! 402: exit(0); ! 403: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.