diff options
author | Can Erkin Acar <canacar@cvs.openbsd.org> | 2008-10-31 06:50:10 +0000 |
---|---|---|
committer | Can Erkin Acar <canacar@cvs.openbsd.org> | 2008-10-31 06:50:10 +0000 |
commit | b4802e9db16836f2646fda39bd8caf675ee0bcdd (patch) | |
tree | de5770dfe75db05501cbf5494838501c205365bd | |
parent | d92a05b329ffbcc06f0090728253e03f1ea4c6c2 (diff) |
Implement start and stop commands as documented,
explicitly pass the command buffer to the command functions.
-rw-r--r-- | usr.bin/systat/engine.c | 8 | ||||
-rw-r--r-- | usr.bin/systat/engine.h | 9 | ||||
-rw-r--r-- | usr.bin/systat/main.c | 43 |
3 files changed, 35 insertions, 25 deletions
diff --git a/usr.bin/systat/engine.c b/usr.bin/systat/engine.c index 4c14c2fa8a0..54f2df32fbd 100644 --- a/usr.bin/systat/engine.c +++ b/usr.bin/systat/engine.c @@ -1,4 +1,4 @@ -/* $Id: engine.c,v 1.4 2008/07/22 03:00:23 canacar Exp $ */ +/* $Id: engine.c,v 1.5 2008/10/31 06:50:09 canacar Exp $ */ /* * Copyright (c) 2001, 2007 Can Erkin Acar <canacar@openbsd.org> * @@ -517,7 +517,7 @@ add_view(field_view *fv) } int -set_view(char *opt) +set_view(const char *opt) { struct view_ent *ve, *vm = NULL; field_view *v; @@ -815,7 +815,7 @@ print_fld_uint(field_def *fld, unsigned int size) /* ordering */ void -set_order(char *opt) +set_order(const char *opt) { order_type *o; @@ -1083,7 +1083,7 @@ cmd_keyboard(int ch) case 0x0d: { struct command * c = command_set(NULL, NULL); - c->exec(); + c->exec(cmdbuf); break; } case KEY_BACKSPACE: diff --git a/usr.bin/systat/engine.h b/usr.bin/systat/engine.h index 86f00012b53..6225cd69826 100644 --- a/usr.bin/systat/engine.h +++ b/usr.bin/systat/engine.h @@ -1,4 +1,4 @@ -/* $Id: engine.h,v 1.2 2008/07/22 03:00:23 canacar Exp $ */ +/* $Id: engine.h,v 1.3 2008/10/31 06:50:09 canacar Exp $ */ /* * Copyright (c) 2001, 2007 Can Erkin Acar <canacar@openbsd.org> * @@ -92,7 +92,7 @@ typedef struct { struct command { char *prompt; - void ( *exec)(void); + void ( *exec)(const char *); }; @@ -124,11 +124,11 @@ void show_field(field_def *fld); void field_setup(void); void add_view(field_view *fv); -int set_view(char *opt); +int set_view(const char *opt); void next_view(void); void prev_view(void); -void set_order(char *opt); +void set_order(const char *opt); void next_order(void); void setup_term(int maxpr); @@ -162,7 +162,6 @@ extern field_view *curr_view; extern struct view_manager *curr_mgr; extern char tmp_buf[MAX_LINE_BUF]; -extern char cmdbuf[MAX_LINE_BUF]; extern int curr_line; /* XXX temp */ extern u_int32_t num_disp; diff --git a/usr.bin/systat/main.c b/usr.bin/systat/main.c index 2017def8fb3..48c51eeff31 100644 --- a/usr.bin/systat/main.c +++ b/usr.bin/systat/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.45 2008/10/31 06:06:46 canacar Exp $ */ +/* $Id: main.c,v 1.46 2008/10/31 06:50:09 canacar Exp $ */ /* * Copyright (c) 2001, 2007 Can Erkin Acar * Copyright (c) 2001 Daniel Hartmeier @@ -71,9 +71,9 @@ int CMDLINE; /* command prompt */ -void cmd_delay(void); -void cmd_count(void); -void cmd_compat(void); +void cmd_delay(const char *); +void cmd_count(const char *); +void cmd_compat(const char *); struct command cm_compat = {"Command", cmd_compat}; struct command cm_delay = {"Seconds to delay", cmd_delay}; @@ -291,34 +291,45 @@ show_help(void) } void -cmd_compat(void) +cmd_compat(const char *buf) { - char *s; + const char *s; - if (strcasecmp(cmdbuf, "help") == 0) { + if (strcasecmp(buf, "help") == 0) { show_help(); need_update = 1; return; } - if (strcasecmp(cmdbuf, "quit") == 0 || strcasecmp(cmdbuf, "q") == 0) { + if (strcasecmp(buf, "quit") == 0 || strcasecmp(buf, "q") == 0) { gotsig_close = 1; return; } + if (strcasecmp(buf, "stop") == 0) { + paused = 1; + gotsig_alarm = 1; + return; + } + if (strncasecmp(buf, "start", 5) == 0) { + paused = 0; + gotsig_alarm = 1; + cmd_delay(buf + 6); + return; + } - for (s = cmdbuf; *s && strchr("0123456789+-.eE", *s) != NULL; s++) + for (s = buf; *s && strchr("0123456789+-.eE", *s) != NULL; s++) ; if (*s) { - if (set_view(cmdbuf)) - error("Invalid/ambigious view: %s", cmdbuf); + if (set_view(buf)) + error("Invalid/ambigious view: %s", buf); } else - cmd_delay(); + cmd_delay(buf); } void -cmd_delay(void) +cmd_delay(const char *buf) { double del; - del = atof(cmdbuf); + del = atof(buf); if (del > 0) { udelay = (useconds_t)(del * 1000000); @@ -328,10 +339,10 @@ cmd_delay(void) } void -cmd_count(void) +cmd_count(const char *buf) { int ms; - ms = atoi(cmdbuf); + ms = atoi(buf); if (ms <= 0 || ms > lines - HEADER_LINES) maxprint = lines - HEADER_LINES; |