version 1.8, 2001/11/23 22:20:06 |
version 1.9, 2001/12/07 07:57:35 |
|
|
|
|
void |
void |
command(cmd) |
command(cmd) |
char *cmd; |
char *cmd; |
{ |
{ |
struct cmdtab *p; |
struct cmdtab *p; |
char *cp; |
char *cp; |
int interval; |
int interval; |
sigset_t mask, omask; |
sigset_t mask, omask; |
|
|
sigemptyset(&mask); |
sigemptyset(&mask); |
sigaddset(&mask, SIGALRM); |
sigaddset(&mask, SIGALRM); |
sigprocmask(SIG_BLOCK, &mask, &omask); |
sigprocmask(SIG_BLOCK, &mask, &omask); |
for (cp = cmd; *cp && !isspace(*cp); cp++) |
for (cp = cmd; *cp && !isspace(*cp); cp++) |
; |
; |
if (*cp) |
if (*cp) |
*cp++ = '\0'; |
*cp++ = '\0'; |
if (*cmd == '\0') |
if (*cmd == '\0') |
return; |
return; |
for (; *cp && isspace(*cp); cp++) |
for (; *cp && isspace(*cp); cp++) |
; |
; |
if (strcmp(cmd, "quit") == 0 || strcmp(cmd, "q") == 0) |
if (strcmp(cmd, "quit") == 0 || strcmp(cmd, "q") == 0) |
die(); |
die(0); |
if (strcmp(cmd, "load") == 0) { |
if (strcmp(cmd, "load") == 0) { |
load(); |
load(); |
goto done; |
goto done; |
} |
} |
if (strcmp(cmd, "stop") == 0) { |
if (strcmp(cmd, "stop") == 0) { |
alarm(0); |
alarm(0); |
mvaddstr(CMDLINE, 0, "Refresh disabled."); |
mvaddstr(CMDLINE, 0, "Refresh disabled."); |
clrtoeol(); |
clrtoeol(); |
goto done; |
goto done; |
} |
} |
if (strcmp(cmd, "help") == 0) { |
if (strcmp(cmd, "help") == 0) { |
int col, len; |
int col, len; |
|
|
|
|
goto done; |
goto done; |
} |
} |
interval = atoi(cmd); |
interval = atoi(cmd); |
if (interval <= 0 && |
if (interval <= 0 && |
(strcmp(cmd, "start") == 0 || strcmp(cmd, "interval") == 0)) { |
(strcmp(cmd, "start") == 0 || strcmp(cmd, "interval") == 0)) { |
interval = *cp ? atoi(cp) : naptime; |
interval = *cp ? atoi(cp) : naptime; |
if (interval <= 0) { |
if (interval <= 0) { |
error("%d: bad interval.", interval); |
error("%d: bad interval.", interval); |
goto done; |
goto done; |
} |
} |
} |
} |
if (interval > 0) { |
if (interval > 0) { |
alarm(0); |
alarm(0); |
naptime = interval; |
naptime = interval; |
display(); |
display(0); |
status(); |
status(); |
goto done; |
goto done; |
} |
} |
p = lookup(cmd); |
p = lookup(cmd); |
if (p == (struct cmdtab *)-1) { |
if (p == (struct cmdtab *)-1) { |
error("%s: Ambiguous command.", cmd); |
error("%s: Ambiguous command.", cmd); |
goto done; |
goto done; |
} |
} |
if (p) { |
if (p) { |
if (curcmd == p) |
if (curcmd == p) |
goto done; |
goto done; |
alarm(0); |
alarm(0); |
(*curcmd->c_close)(wnd); |
(*curcmd->c_close)(wnd); |
wnd = (*p->c_open)(); |
wnd = (*p->c_open)(); |
if (wnd == 0) { |
if (wnd == 0) { |
|
|
else |
else |
goto done; |
goto done; |
} |
} |
curcmd = p; |
curcmd = p; |
labels(); |
labels(); |
display(); |
display(0); |
status(); |
status(); |
goto done; |
goto done; |
} |
} |
if (curcmd->c_cmd == 0 || !(*curcmd->c_cmd)(cmd, cp)) |
if (curcmd->c_cmd == 0 || !(*curcmd->c_cmd)(cmd, cp)) |
error("%s: Unknown command.", cmd); |
error("%s: Unknown command.", cmd); |
done: |
done: |
|
|
status() |
status() |
{ |
{ |
|
|
error("Showing %s, refresh every %d seconds.", |
error("Showing %s, refresh every %d seconds.", |
curcmd->c_name, naptime); |
curcmd->c_name, naptime); |
} |
} |
|
|
int |
int |
prefix(s1, s2) |
prefix(s1, s2) |
char *s1, *s2; |
char *s1, *s2; |
{ |
{ |
|
|
while (*s1 == *s2) { |
while (*s1 == *s2) { |
if (*s1 == '\0') |
if (*s1 == '\0') |
return (1); |
return (1); |
s1++, s2++; |
s1++, s2++; |
} |
} |
return (*s1 == '\0'); |
return (*s1 == '\0'); |
} |
} |