changes designed so that ESIS and ARP may use routing table
[unix-history] / usr / src / usr.bin / systat / cmds.c
index 4625f35..c8c887e 100644 (file)
@@ -1,13 +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[] = "@(#)cmds.c     1.5 (Berkeley) %G%";
-#endif
+static char sccsid[] = "@(#)cmds.c     5.7 (Berkeley) %G%";
+#endif not lint
 
 /*
  * Command support.
  */
 
 #include "systat.h"
 
 /*
  * Command support.
  */
 
 #include "systat.h"
-#include <signal.h>
 #include <ctype.h>
 
 command(cmd)
 #include <ctype.h>
 
 command(cmd)
@@ -15,9 +20,9 @@ command(cmd)
 {
         register char *cp;
         register struct cmdtab *p;
 {
         register char *cp;
         register struct cmdtab *p;
-       int interval;
-        char *arg;
+       int interval, omask;
 
 
+       omask = sigblock(sigmask(SIGALRM));
         for (cp = cmd; *cp && !isspace(*cp); cp++)
                 ;
         if (*cp)
         for (cp = cmd; *cp && !isspace(*cp); cp++)
                 ;
         if (*cp)
@@ -30,13 +35,13 @@ command(cmd)
                 die();
        if (strcmp(cmd, "load") == 0) {
                load();
                 die();
        if (strcmp(cmd, "load") == 0) {
                load();
-               return;
+               goto done;
        }
         if (strcmp(cmd, "stop") == 0) {
                 alarm(0);
                 mvaddstr(CMDLINE, 0, "Refresh disabled.");
                 clrtoeol();
        }
         if (strcmp(cmd, "stop") == 0) {
                 alarm(0);
                 mvaddstr(CMDLINE, 0, "Refresh disabled.");
                 clrtoeol();
-                return;
+               goto done;
         }
        if (strcmp(cmd, "help") == 0) {
                int col, len;
         }
        if (strcmp(cmd, "help") == 0) {
                int col, len;
@@ -51,7 +56,7 @@ command(cmd)
                                addch(' ');
                }
                clrtoeol();
                                addch(' ');
                }
                clrtoeol();
-               return;
+               goto done;
        }
        interval = atoi(cmd);
         if (interval <= 0 &&
        }
        interval = atoi(cmd);
         if (interval <= 0 &&
@@ -59,7 +64,7 @@ command(cmd)
                interval = *cp ? atoi(cp) : naptime;
                 if (interval <= 0) {
                        error("%d: bad interval.", interval);
                interval = *cp ? atoi(cp) : naptime;
                 if (interval <= 0) {
                        error("%d: bad interval.", interval);
-                        return;
+                       goto done;
                 }
        }
        if (interval > 0) {
                 }
        }
        if (interval > 0) {
@@ -67,32 +72,44 @@ command(cmd)
                 naptime = interval;
                 display();
                 status();
                 naptime = interval;
                 display();
                 status();
-                return;
+               goto done;
         }
        p = lookup(cmd);
        if (p == (struct cmdtab *)-1) {
                error("%s: Ambiguous command.", cmd);
         }
        p = lookup(cmd);
        if (p == (struct cmdtab *)-1) {
                error("%s: Ambiguous command.", cmd);
-               return;
+               goto done;
        }
         if (p) {
                 if (curcmd == p)
        }
         if (p) {
                 if (curcmd == p)
-                        return;
+                       goto done;
                 alarm(0);
                (*curcmd->c_close)(wnd);
                wnd = (*p->c_open)();
                 alarm(0);
                (*curcmd->c_close)(wnd);
                wnd = (*p->c_open)();
-                curcmd = p;
+               if (wnd == 0) {
+                       error("Couldn't open new display");
+                       wnd = (*curcmd->c_open)();
+                       if (wnd == 0) {
+                               error("Couldn't change back to previous cmd");
+                               exit(1);
+                       }
+                       p = curcmd;
+               }
                if ((p->c_flags & CF_INIT) == 0) {
                if ((p->c_flags & CF_INIT) == 0) {
-                       (*p->c_init)();
-                       p->c_flags |= CF_INIT;
+                       if ((*p->c_init)())
+                               p->c_flags |= CF_INIT;
+                       else
+                               goto done;
                }
                }
+                curcmd = p;
                labels();
                 display();
                 status();
                labels();
                 display();
                 status();
-                return;
+               goto done;
         }
         }
-       if (curcmd->c_cmd && (*curcmd->c_cmd)(cmd, cp))
-               return;
-       error("%s: Unknown command.", cmd);
+       if (curcmd->c_cmd == 0 || !(*curcmd->c_cmd)(cmd, cp))
+               error("%s: Unknown command.", cmd);
+done:
+       sigsetmask(omask);
 }
 
 struct cmdtab *
 }
 
 struct cmdtab *
@@ -105,7 +122,7 @@ lookup(name)
 
        longest = 0;
        nmatches = 0;
 
        longest = 0;
        nmatches = 0;
-       found = 0;
+       found = (struct cmdtab *) 0;
        for (c = cmdtab; p = c->c_name; c++) {
                for (q = name; *q == *p++; q++)
                        if (*q == 0)            /* exact match? */
        for (c = cmdtab; p = c->c_name; c++) {
                for (q = name; *q == *p++; q++)
                        if (*q == 0)            /* exact match? */
@@ -134,13 +151,14 @@ status()
 suspend()
 {
         int oldmask;
 suspend()
 {
         int oldmask;
+       extern sig_t sigtstpdfl;
 
        alarm(0);
         move(CMDLINE, 0);
         refresh();
         echo();
         nocrmode();
 
        alarm(0);
         move(CMDLINE, 0);
         refresh();
         echo();
         nocrmode();
-        signal(SIGTSTP, SIG_DFL);
+        signal(SIGTSTP, sigtstpdfl);
         oldmask = sigsetmask(0);
         kill(getpid(), SIGTSTP);
         sigsetmask(oldmask);
         oldmask = sigsetmask(0);
         kill(getpid(), SIGTSTP);
         sigsetmask(oldmask);
@@ -148,6 +166,17 @@ suspend()
         crmode();
         noecho();
         move(CMDLINE, col);
         crmode();
         noecho();
         move(CMDLINE, col);
-        wrefresh(curscr);
        alarm(naptime);
 }
        alarm(naptime);
 }
+
+prefix(s1, s2)
+        register char *s1, *s2;
+{
+
+        while (*s1 == *s2) {
+                if (*s1 == '\0')
+                        return (1);
+                s1++, s2++;
+        }
+        return (*s1 == '\0');
+}