upd.c A screen updating program
utzoo!decvax!duke!harpo!floyd!trb
utzoo!decvax!duke!harpo!floyd!trb
Thu Mar 25 14:04:22 AEST 1982
Please let me know if you have better ideas. -Andy
----------
/*
* cc upd.c -lcurses -ltermcap -o upd
*
* upd.c - popen a process and use its output to update the screen
* argv[1] is popen'ed so quote your command if it's more than one arg.
* argv[2] is number of seconds to sleep between cycles.
* Andy Tannenbaum WECo/BTL Whippany, NJ
*/
#include<curses.h>
#include<sys/ioctl.h>
/* 6*1024 is more than 66*80 */
#define BUFSIZE 6*1024
FILE *pp; /* popen pointer */
char buf[BUFSIZE];
char tbuf[128];
long larg;
main(argc,argv)
int argc; char **argv;
{
extern char *CD;
int i,n,sleeptime;
/* sleep for sleeptime seconds between cycles */
sleeptime = (argc > 1) ? atol(argv[2]) : 1;
initscr();
for(;;){
#ifdef VMUNIX
/* redraw whole screen when user types a newline */
/* can be done on UNIX 3.0 too, but I don't */
ioctl(0,FIONREAD,&larg);
if(larg != 0L){
read(0,tbuf,128);
clear();
}
#endif
/* if popen fails we're hurting, so break */
if((pp=popen(argv[1],"r")) == EOF)exit(1);
n=fread(buf,1,BUFSIZE,pp);
buf[n]=0;
pclose(pp);
mvaddstr(0,0,buf);
refresh();
/* my curses doesn't seem to clear the rest of the screen when
* data disappears from it, but it leaves the cursor down
* there, so diy */
printf("%s",CD);
for(i=0;i<n;i++)buf[n]=0;
sleep(sleeptime);
}
}
----------
More information about the Comp.sources.unix
mailing list