+/*
+ * 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
-static char sccsid[] = "@(#)cmds.c 1.4 (Lucasfilm) %G%";
-#endif
+static char sccsid[] = "@(#)cmds.c 5.2 (Berkeley) %G%";
+#endif not lint
/*
* Command support.
*/
#include "systat.h"
-#include <signal.h>
#include <ctype.h>
command(cmd)
{
register char *cp;
register struct cmdtab *p;
+ int interval, omask;
char *arg;
+ extern (*sigtstpdfl)();
+ omask = sigblock(sigmask(SIGALRM));
for (cp = cmd; *cp && !isspace(*cp); cp++)
;
if (*cp)
die();
if (strcmp(cmd, "load") == 0) {
load();
- return;
+ goto done;
}
if (strcmp(cmd, "stop") == 0) {
alarm(0);
mvaddstr(CMDLINE, 0, "Refresh disabled.");
clrtoeol();
- return;
+ goto done;
}
- if (strcmp(cmd, "start") == 0 || strcmp(cmd, "interval") == 0) {
- int x;
+ if (strcmp(cmd, "help") == 0) {
+ int col, len;
- x = *cp ? atoi(cp) : naptime;
- if (x <= 0) {
- error("%d: bad interval.", x);
- return;
+ move(CMDLINE, col = 0);
+ for (p = cmdtab; p->c_name; p++) {
+ len = strlen(p->c_name);
+ if (col + len > COLS)
+ break;
+ addstr(p->c_name); col += len;
+ if (col + 1 < COLS)
+ addch(' ');
+ }
+ clrtoeol();
+ goto done;
+ }
+ interval = atoi(cmd);
+ if (interval <= 0 &&
+ (strcmp(cmd, "start") == 0 || strcmp(cmd, "interval") == 0)) {
+ interval = *cp ? atoi(cp) : naptime;
+ if (interval <= 0) {
+ error("%d: bad interval.", interval);
+ goto done;
}
+ }
+ if (interval > 0) {
alarm(0);
- naptime = x;
+ naptime = interval;
display();
status();
- return;
+ goto done;
}
p = lookup(cmd);
if (p == (struct cmdtab *)-1) {
error("%s: Ambiguous command.", cmd);
- return;
+ goto done;
}
if (p) {
if (curcmd == p)
- return;
+ goto done;
alarm(0);
(*curcmd->c_close)(wnd);
wnd = (*p->c_open)();
+ 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;
+ }
curcmd = p;
- if (p->c_flags == 0) {
+ if ((p->c_flags & CF_INIT) == 0) {
(*p->c_init)();
- p->c_flags = 1;
+ p->c_flags |= CF_INIT;
}
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 *
refresh();
echo();
nocrmode();
- signal(SIGTSTP, SIG_DFL);
+ signal(SIGTSTP, sigtstpdfl);
oldmask = sigsetmask(0);
kill(getpid(), SIGTSTP);
sigsetmask(oldmask);
crmode();
noecho();
move(CMDLINE, col);
- wrefresh(curscr);
alarm(naptime);
}
+
+prefix(s1, s2)
+ register char *s1, *s2;
+{
+
+ while (*s1 == *s2) {
+ if (*s1 == '\0')
+ return (1);
+ s1++, s2++;
+ }
+ return (*s1 == '\0');
+}