rmdel is already linked
[unix-history] / usr / src / usr.bin / systat / main.c
index 39fc134..d01b233 100644 (file)
@@ -1,6 +1,18 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)main.c     1.6 (Lucasfilm) %G%";
-#endif
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
+
+#ifndef lint
+static char sccsid[] = "@(#)main.c     5.2 (Berkeley) %G%";
+#endif not lint
 
 #include "systat.h"
 
 
 #include "systat.h"
 
@@ -9,6 +21,10 @@ static struct nlist nlst[] = {
         { "_ccpu" },
 #define X_AVENRUN       1
         { "_avenrun" },
         { "_ccpu" },
 #define X_AVENRUN       1
         { "_avenrun" },
+#define        X_HZ            2
+       { "_hz" },
+#define        X_PHZ           3
+       { "_phz" },
         { "" }
 };
 
         { "" }
 };
 
@@ -20,6 +36,10 @@ int  naptime = 5;
 int     die();
 int     display();
 int     suspend();
 int     die();
 int     display();
 int     suspend();
+int    (*sigtstpdfl)();
+
+double ccpu;
+int     dellave;
 
 static WINDOW *wload;                  /* one line window for load average */
 
 
 static WINDOW *wload;                  /* one line window for load average */
 
@@ -81,6 +101,7 @@ main(argc, argv)
         * routines to minimize update work by curses.
         */
         initscr();
         * routines to minimize update work by curses.
         */
         initscr();
+       CMDLINE = LINES - 1;
        wnd = (*curcmd->c_open)();
        if (wnd == NULL) {
                fprintf(stderr, "Couldn't initialize display.\n");
        wnd = (*curcmd->c_open)();
        if (wnd == NULL) {
                fprintf(stderr, "Couldn't initialize display.\n");
@@ -93,11 +114,13 @@ main(argc, argv)
        }
 
         gethostname(hostname, sizeof (hostname));
        }
 
         gethostname(hostname, sizeof (hostname));
-        lseek(kmem, nlst[X_CCPU].n_value, 0);
+        lseek(kmem, nlst[X_CCPU].n_value, L_SET);
         read(kmem, &ccpu, sizeof (ccpu));
         lccpu = log(ccpu);
         read(kmem, &ccpu, sizeof (ccpu));
         lccpu = log(ccpu);
+       hz = getw(nlst[X_HZ].n_value);
+       phz = getw(nlst[X_PHZ].n_value);
        (*curcmd->c_init)();
        (*curcmd->c_init)();
-       curcmd->c_flags = 1;
+       curcmd->c_flags |= CF_INIT;
         labels();
 
         known[0].k_uid = -1;
         labels();
 
         known[0].k_uid = -1;
@@ -109,7 +132,7 @@ main(argc, argv)
         dellave = 0.0;
 
         signal(SIGALRM, display);
         dellave = 0.0;
 
         signal(SIGALRM, display);
-        signal(SIGTSTP, suspend);
+        sigtstpdfl = signal(SIGTSTP, suspend);
         display();
         noecho();
         crmode();
         display();
         noecho();
         crmode();
@@ -120,9 +143,11 @@ main(argc, argv)
 labels()
 {
 
 labels()
 {
 
-        mvaddstr(2, 20,
-                "/0   /1   /2   /3   /4   /5   /6   /7   /8   /9   /10");
-        mvaddstr(3, 5, "Load Average");
+       if (curcmd->c_flags & CF_LOADAV) {
+               mvaddstr(2, 20,
+                   "/0   /1   /2   /3   /4   /5   /6   /7   /8   /9   /10");
+               mvaddstr(3, 5, "Load Average");
+       }
         (*curcmd->c_label)();
 #ifdef notdef
         mvprintw(21, 25, "CPU usage on %s", hostname);
         (*curcmd->c_label)();
 #ifdef notdef
         mvprintw(21, 25, "CPU usage on %s", hostname);
@@ -136,38 +161,43 @@ display()
 
         /* Get the load average over the last minute. */
         lseek(kmem, nlst[X_AVENRUN].n_value, L_SET);
 
         /* Get the load average over the last minute. */
         lseek(kmem, nlst[X_AVENRUN].n_value, L_SET);
-        read(kmem, &lave, sizeof (lave));
+       read(kmem, avenrun, sizeof (avenrun));
         (*curcmd->c_fetch)();
         (*curcmd->c_fetch)();
-        j = 5.0*lave + 0.5;
-        dellave -= lave;
-        if (dellave >= 0.0)
-                c = '<';
-        else {
-                c = '>';
-                dellave = -dellave;
-        }
-        if (dellave < 0.1)
-                c = '|';
-        dellave = lave;
-        wmove(wload, 0, 0); wclrtoeol(wload);
-        for (i = (j > 50) ? 50 : j; i > 0; i--)
-                waddch(wload, c);
-        if (j > 50)
-                wprintw(wload, " %4.1f", lave);
+       if (curcmd->c_flags & CF_LOADAV) {
+               j = 5.0*avenrun[0] + 0.5;
+               dellave -= avenrun[0];
+               if (dellave >= 0.0)
+                       c = '<';
+               else {
+                       c = '>';
+                       dellave = -dellave;
+               }
+               if (dellave < 0.1)
+                       c = '|';
+               dellave = avenrun[0];
+               wmove(wload, 0, 0); wclrtoeol(wload);
+               for (i = (j > 50) ? 50 : j; i > 0; i--)
+                       waddch(wload, c);
+               if (j > 50)
+                       wprintw(wload, " %4.1f", avenrun[0]);
+       }
         (*curcmd->c_refresh)();
         (*curcmd->c_refresh)();
-       wrefresh(wload);
+       if (curcmd->c_flags & CF_LOADAV)
+               wrefresh(wload);
         wrefresh(wnd);
         wrefresh(wnd);
-        move(22, col);
+        move(CMDLINE, col);
         refresh();
         alarm(naptime);
 }
 
 load()
 {
         refresh();
         alarm(naptime);
 }
 
 load()
 {
+       double  avenrun[3];
 
        lseek(kmem, nlst[X_AVENRUN].n_value, L_SET);
 
        lseek(kmem, nlst[X_AVENRUN].n_value, L_SET);
-       read(kmem, &lave, sizeof (lave));
-       mvprintw(22, 0, "%4.1f", lave);
+       read(kmem, avenrun, sizeof (avenrun));
+       mvprintw(CMDLINE, 0, "%4.1f %4.1f %4.1f",
+           avenrun[0], avenrun[1], avenrun[2]);
        clrtoeol();
 }
 
        clrtoeol();
 }
 
@@ -181,7 +211,7 @@ die()
 error(fmt, a1, a2, a3)
 {
 
 error(fmt, a1, a2, a3)
 {
 
-       mvprintw(22, 0, fmt, a1, a2, a3);
+       mvprintw(CMDLINE, 0, fmt, a1, a2, a3);
        clrtoeol();
        refresh();
 }
        clrtoeol();
        refresh();
 }