source: trunk/athena/bin/rep/rep.c @ 5066

Revision 5066, 2.6 KB checked in by probe, 33 years ago (diff)
RIOS integration
Line 
1/******************************************************************************
2 *                                                                            *
3 * rep -- run a program repeatedly using 'curses'.                            *
4 *                                                                            *
5 *      Usage: rep [-n] command                                               *
6 *                                                                            *
7 *      Permits the user to watch a program like 'w' or 'finger' change with  *
8 *      time.  Given an argument '-x' will cause a repetion every x seconds.  *
9 *                                                                            *
10 * ORIGINAL                                                                   *
11 * Ray Lubinsky University of Virginia, Dept. of Computer Science             *
12 *           uucp: decvax!mcnc!ncsu!uvacs!rwl                                 *
13 * MODIFIED 3/85                                                              *
14 * Bruce Karsh, Univ. Wisconsin, Madison.  Dept. of Geophysics.               *
15 *           uucp: uwvax\!geowhiz\!karsh                                      *
16 ******************************************************************************/
17
18#include <curses.h>
19#ifdef POSIX
20#include <term.h>
21#endif
22#include <signal.h>
23
24#define NextLine        fgets(buf,sizeof buf,input)
25
26FILE    *input;                         /* Pipe from 'source' */
27char    source[512];                    /* Source program to run repeatedly */
28char    *progname;                      /* Name of this program (for errors) */
29int     interval = 1;                   /* Seconds between repitions */
30int     deathflag = 0;                  /* Set by interupt trap routine */
31
32main(argc,argv)
33        int     argc;
34        char    **argv;
35{
36        int     endrep();               /* Mop up routine on break */
37        FILE    *popen();
38
39        char    buf[BUFSIZ];            /* Buffer holds a line from 'source' */
40        int     i;
41
42        progname = *argv;
43        source[0]=0;
44        if (argc == 1)
45                badargs();
46        if (**(argv+1) == '-')          /* User specified interval */
47                if ((--argc == 1) || ((interval = atoi(*(++argv)+1)) == 0))
48                        badargs();
49        while (--argc > 0) {            /* Argument becomes source program */
50                strcat(source,*++argv);
51                strcat(source," ");
52        }
53        signal(SIGINT,endrep);
54        if(deathflag == 1)goto die;
55        initscr();
56        if(deathflag == 1)goto die;
57        crmode();
58        if(deathflag == 1)goto die;
59        nonl();
60        if(deathflag == 1)goto die;
61        clear();
62        if(deathflag == 1)goto die;
63        for (;;) {
64                if(deathflag == 1)goto die;
65                if ((input = popen(source,"r")) == NULL) {
66                        fprintf(stderr,"%s: can't run %s\n",progname,source);
67                        goto die;
68                }
69                for (i = 0; (i < LINES) && (NextLine != NULL); i++) {
70                        mvaddstr(i,0,buf);
71                        clrtoeol();
72                        if(deathflag == 1)goto die;
73                }
74                if(deathflag == 1)goto die;
75                pclose(input);
76                if(deathflag == 1)goto die;
77                clrtobot();
78                if(deathflag == 1)goto die;
79                refresh();
80                if(deathflag == 1)goto die;
81                sleep(interval);
82                if(deathflag == 1)goto die;
83        }
84die:
85        signal(SIGINT,SIG_IGN);
86        if (input != NULL)
87          pclose(input);
88        clear();
89        refresh();
90        endwin();
91        exit(0);
92}
93
94endrep()
95{
96deathflag=1;
97}
98
99badargs()
100{
101        fprintf(stderr,"Usage: %s [-n] command\n",progname);
102        exit(1);
103}
Note: See TracBrowser for help on using the repository browser.