Afloyd.136
net.sources
utcsrgv!utzoo!decvax!duke!harpo!floyd!trb
Thu Mar 25 14:04:22 1982
upd.c A screen updating program
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; } ---------- </PRE SLEEP(SLEEPTIME);>
<HR>
This Usenet Oldnews Archive
article may be copied and distributed freely, provided:
<P>
1. There is no money collected for the text(s) of the articles.
<BR>
2. The following notice remains appended to each copy:
<P>
<EM>The Usenet Oldnews Archive: Compilation Copyright&copy 1981, 1996
<BR> Bruce Jones, Henry Spencer, David Wiseman.</EM>
<P>
<HR>
Goto <A HREF="82.04.03_ucf-cs.493_net.sources.html">NEXT</A> article in NET.sources Newsgroup
<BR>Return to <A HREF="NET.sources-index.html">NET.sources index</A>
<BR>Return to the
       <A HREF="../index.html">Usenet Oldnews Archive index</A>
</HTML>

-----------------------------------------------------------------
gopher://quux.org/ conversion by John Goerzen <[email protected]>
of http://communication.ucsd.edu/A-News/


This Usenet Oldnews Archive
article may be copied and distributed freely, provided:

1. There is no money collected for the text(s) of the articles.

2. The following notice remains appended to each copy:

The Usenet Oldnews Archive: Compilation Copyright (C) 1981, 1996
Bruce Jones, Henry Spencer, David Wiseman.