#include "cons.h" #include #include #include #include #include #include #include #include #define BIGSIZ 8192 #define puke(msg) { perror(msg); exit(1); } FILE *fp; struct conmon { int win; /* associated window */ int osize; /* size of file excluding unread data */ char serv[32]; char fname[64]; char buf[BIGSIZ]; int bufdex; } cm[64]; struct mywins { WINDOW *twin; /* title window */ WINDOW *dwin; /* data window */ char free; long tym; } sw[64]; int numw=0, numserv=0, dietym=60, numfree=0; main(argc,argv) int argc; char *argv[]; { int lfd, n, i, j, nc; char ch[BIGSIZ], log[32], dum[32], **namelist, optc; char beep=0, col2=0, optdone=0, incld=0, xcld=0, skip=0; int wlin=5, wcol; struct stat st; extern int optind; extern char *optarg; void leave(), checkold(), freewin(); /* options to add: -f list of filenames to tail */ while ((optc = getopt(argc, argv, "2bixl:t:w:")) != EOF) { switch (optc) { case 'b': beep=1; break; case '2': col2=1; break; case 'i': incld=1; break; case 'x': xcld=1; break; case 'w': numw=atol(optarg); break; case 'l': wlin=atol(optarg); break; case 't': dietym=atol(optarg); break; case '?': fprintf(stderr, "usage: conview [-2] [-b] [-w number of windows] [-l lines per window]\n [-t timeout] [-x server exclude list] [-i server include list]\n"); exit(1); break; } if (incld || xcld) { namelist=argv+optind; break; } } /* read the config file */ if ((fp=fopen("/n/pun/0/console/constab","r")) == NULL) puke ("fopen"); while(fgets(ch,127,fp) != NULL) { if (ch[0] != '#') { sscanf(ch,"%[^:]:%[^:]:%[^:]:%d\n",cm[numserv].serv,dum,log,dum); if (xcld) { skip=0; for (j=0; namelist[j] != NULL; ++j) { /* if (strncmp(namelist[j],cm[numserv].serv,strlen(namelist[j])) == 0) { */ if (strcmp(namelist[j],cm[numserv].serv) == 0) { skip=1; break; } } if (skip) continue; } else if (incld) { skip=1; for (j=0; namelist[j] != NULL; ++j) { /* if (strncmp(namelist[j],cm[numserv].serv,strlen(namelist[j])) == 0) { */ if (strcmp(namelist[j],cm[numserv].serv) == 0) { skip=0; break; } } if (skip) continue; } if (strcmp(log,"/dev/null") == 0) continue; sprintf(cm[numserv].fname,"/n/pun/0/console/%s\0",cm[numserv].serv); if (stat(cm[numserv].fname,&st) == -1) puke(cm[numserv].fname); cm[numserv].osize=st.st_size; cm[numserv].win=(-1); cm[numserv].bufdex=0; cm[numserv].serv[strlen(cm[numserv].serv)]='\0'; ++numserv; } } fclose(fp); signal(SIGINT,leave); signal(SIGALRM,checkold); alarm(dietym/4); initscr(); if (numw) { if (col2) numw=(numw+1)/2; /* round up; it will be mult by 2 below */ wlin=LINES/numw-1; } else numw=LINES/(wlin+1); wcol=COLS; if (col2) { numw *= 2; wcol=wcol/2-1; } numfree=numw; for (i=0; i 0) { cm[i].buf[cm[i].bufdex+nc]='\0'; spitout(i,cm[i].bufdex+nc); } close(lfd); } } } spitout(sern,len) int sern, len; { int i, j, oldest, oldtym; char *ptr; ptr=cm[sern].buf; if (cm[sern].win == -1) { if (numfree == 0) { /* no free ones - free the oldest one */ oldtym=time(NULL); oldest=0; for (j=0; j dietym) freewin(i); alarm(dietym/4); } void leave() { endwin(); exit(1); }