Deleted Added
full compact
cmds.c (226396) cmds.c (240605)
1/*-
2 * Copyright (c) 1980, 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31
1/*-
2 * Copyright (c) 1980, 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31
32__FBSDID("$FreeBSD: head/usr.bin/systat/cmds.c 226396 2011-10-15 13:20:36Z ed $");
32__FBSDID("$FreeBSD: head/usr.bin/systat/cmds.c 240605 2012-09-17 13:36:47Z melifaro $");
33
34#ifdef lint
35static const char sccsid[] = "@(#)cmds.c 8.2 (Berkeley) 4/29/95";
36#endif
37
33
34#ifdef lint
35static const char sccsid[] = "@(#)cmds.c 8.2 (Berkeley) 4/29/95";
36#endif
37
38#include <sys/param.h>
39
38#include <ctype.h>
39#include <signal.h>
40#include <stdlib.h>
41#include <string.h>
42#include <unistd.h>
43
44#include "systat.h"
45#include "extern.h"
46
47void
48command(const char *cmd)
49{
50 struct cmdtab *p;
51 char *cp, *tmpstr, *tmpstr1;
40#include <ctype.h>
41#include <signal.h>
42#include <stdlib.h>
43#include <string.h>
44#include <unistd.h>
45
46#include "systat.h"
47#include "extern.h"
48
49void
50command(const char *cmd)
51{
52 struct cmdtab *p;
53 char *cp, *tmpstr, *tmpstr1;
52 int interval, omask;
54 double t;
53
54 tmpstr = tmpstr1 = strdup(cmd);
55
56 tmpstr = tmpstr1 = strdup(cmd);
55 omask = sigblock(sigmask(SIGALRM));
56 for (cp = tmpstr1; *cp && !isspace(*cp); cp++)
57 ;
58 if (*cp)
59 *cp++ = '\0';
60 if (*tmpstr1 == '\0')
61 return;
62 for (; *cp && isspace(*cp); cp++)
63 ;
64 if (strcmp(tmpstr1, "quit") == 0 || strcmp(tmpstr1, "q") == 0)
65 die(0);
66 if (strcmp(tmpstr1, "load") == 0) {
67 load();
68 goto done;
69 }
70 if (strcmp(tmpstr1, "stop") == 0) {
57 for (cp = tmpstr1; *cp && !isspace(*cp); cp++)
58 ;
59 if (*cp)
60 *cp++ = '\0';
61 if (*tmpstr1 == '\0')
62 return;
63 for (; *cp && isspace(*cp); cp++)
64 ;
65 if (strcmp(tmpstr1, "quit") == 0 || strcmp(tmpstr1, "q") == 0)
66 die(0);
67 if (strcmp(tmpstr1, "load") == 0) {
68 load();
69 goto done;
70 }
71 if (strcmp(tmpstr1, "stop") == 0) {
71 alarm(0);
72 delay = 0;
72 mvaddstr(CMDLINE, 0, "Refresh disabled.");
73 clrtoeol();
74 goto done;
75 }
76 if (strcmp(tmpstr1, "help") == 0) {
77 int _col, _len;
78
79 move(CMDLINE, _col = 0);
80 for (p = cmdtab; p->c_name; p++) {
81 _len = strlen(p->c_name);
82 if (_col + _len > COLS)
83 break;
84 addstr(p->c_name); _col += _len;
85 if (_col + 1 < COLS)
86 addch(' ');
87 }
88 clrtoeol();
89 goto done;
90 }
73 mvaddstr(CMDLINE, 0, "Refresh disabled.");
74 clrtoeol();
75 goto done;
76 }
77 if (strcmp(tmpstr1, "help") == 0) {
78 int _col, _len;
79
80 move(CMDLINE, _col = 0);
81 for (p = cmdtab; p->c_name; p++) {
82 _len = strlen(p->c_name);
83 if (_col + _len > COLS)
84 break;
85 addstr(p->c_name); _col += _len;
86 if (_col + 1 < COLS)
87 addch(' ');
88 }
89 clrtoeol();
90 goto done;
91 }
91 interval = atoi(tmpstr1);
92 if (interval <= 0 &&
93 (strcmp(tmpstr1, "start") == 0 || strcmp(tmpstr1, "interval") == 0)) {
94 interval = *cp ? atoi(cp) : naptime;
95 if (interval <= 0) {
96 error("%d: bad interval.", interval);
97 goto done;
92 t = strtod(tmpstr1, NULL) * 1000000.0;
93 if (t > 0 && t < (double)UINT_MAX)
94 delay = (unsigned int)t;
95 if ((t <= 0 || t > (double)UINT_MAX) &&
96 (strcmp(tmpstr1, "start") == 0 ||
97 strcmp(tmpstr1, "interval") == 0)) {
98 if (*cp != '\0') {
99 t = strtod(cp, NULL) * 1000000.0;
100 if (t <= 0 || t >= (double)UINT_MAX) {
101 error("%d: bad interval.", (int)t);
102 goto done;
103 }
98 }
99 }
104 }
105 }
100 if (interval > 0) {
101 alarm(0);
102 naptime = interval;
103 display(0);
106 if (t > 0) {
107 delay = (unsigned int)t;
108 display();
104 status();
105 goto done;
106 }
107 p = lookup(tmpstr1);
108 if (p == (struct cmdtab *)-1) {
109 error("%s: Ambiguous command.", tmpstr1);
110 goto done;
111 }
112 if (p) {
113 if (curcmd == p)
114 goto done;
109 status();
110 goto done;
111 }
112 p = lookup(tmpstr1);
113 if (p == (struct cmdtab *)-1) {
114 error("%s: Ambiguous command.", tmpstr1);
115 goto done;
116 }
117 if (p) {
118 if (curcmd == p)
119 goto done;
115 alarm(0);
116 (*curcmd->c_close)(wnd);
117 curcmd->c_flags &= ~CF_INIT;
118 wnd = (*p->c_open)();
119 if (wnd == 0) {
120 error("Couldn't open new display");
121 wnd = (*curcmd->c_open)();
122 if (wnd == 0) {
123 error("Couldn't change back to previous cmd");

--- 4 unchanged lines hidden (view full) ---

128 if ((p->c_flags & CF_INIT) == 0) {
129 if ((*p->c_init)())
130 p->c_flags |= CF_INIT;
131 else
132 goto done;
133 }
134 curcmd = p;
135 labels();
120 (*curcmd->c_close)(wnd);
121 curcmd->c_flags &= ~CF_INIT;
122 wnd = (*p->c_open)();
123 if (wnd == 0) {
124 error("Couldn't open new display");
125 wnd = (*curcmd->c_open)();
126 if (wnd == 0) {
127 error("Couldn't change back to previous cmd");

--- 4 unchanged lines hidden (view full) ---

132 if ((p->c_flags & CF_INIT) == 0) {
133 if ((*p->c_init)())
134 p->c_flags |= CF_INIT;
135 else
136 goto done;
137 }
138 curcmd = p;
139 labels();
136 display(0);
140 display();
137 status();
138 goto done;
139 }
140 if (curcmd->c_cmd == 0 || !(*curcmd->c_cmd)(tmpstr1, cp))
141 error("%s: Unknown command.", tmpstr1);
142done:
141 status();
142 goto done;
143 }
144 if (curcmd->c_cmd == 0 || !(*curcmd->c_cmd)(tmpstr1, cp))
145 error("%s: Unknown command.", tmpstr1);
146done:
143 sigsetmask(omask);
144 free(tmpstr);
145}
146
147struct cmdtab *
148lookup(const char *name)
149{
150 const char *p, *q;
151 struct cmdtab *ct, *found;

--- 20 unchanged lines hidden (view full) ---

172 return (found);
173}
174
175void
176status(void)
177{
178
179 error("Showing %s, refresh every %d seconds.",
147 free(tmpstr);
148}
149
150struct cmdtab *
151lookup(const char *name)
152{
153 const char *p, *q;
154 struct cmdtab *ct, *found;

--- 20 unchanged lines hidden (view full) ---

175 return (found);
176}
177
178void
179status(void)
180{
181
182 error("Showing %s, refresh every %d seconds.",
180 curcmd->c_name, naptime);
183 curcmd->c_name, delay / 1000000);
181}
182
183int
184prefix(const char *s1, const char *s2)
185{
186
187 while (*s1 == *s2) {
188 if (*s1 == '\0')
189 return (1);
190 s1++, s2++;
191 }
192 return (*s1 == '\0');
193}
184}
185
186int
187prefix(const char *s1, const char *s2)
188{
189
190 while (*s1 == *s2) {
191 if (*s1 == '\0')
192 return (1);
193 s1++, s2++;
194 }
195 return (*s1 == '\0');
196}