|
|
1.1 root 1: /*
2: * Copyright (c) 1983 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that the above copyright notice and this paragraph are
7: * duplicated in all such forms and that any documentation,
8: * advertising materials, and other materials related to such
9: * distribution and use acknowledge that the software was developed
10: * by the University of California, Berkeley. The name of the
11: * University may not be used to endorse or promote products derived
12: * from this software without specific prior written permission.
13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15: * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16: */
17:
18: #ifndef lint
19: static char sccsid[] = "@(#)lcmd2.c 3.15 (Berkeley) 6/29/88";
20: #endif /* not lint */
21:
22: #include "defs.h"
23: #include "string.h"
24: #include "value.h"
25: #include "var.h"
26: #include "lcmd.h"
27: #include <sys/resource.h>
28: #include "alias.h"
29:
30: /*ARGSUSED*/
31: l_iostat(v, a)
32: struct value *v, *a;
33: {
34: register struct ww *w;
35:
36: if ((w = openiwin(14, "IO Statistics")) == 0) {
37: error("Can't open statistics window: %s.", wwerror());
38: return;
39: }
40: wwprintf(w, "ttflush\twrite\terror\tzero\tchar\n");
41: wwprintf(w, "%d\t%d\t%d\t%d\t%d\n",
42: wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc);
43: wwprintf(w, "wwwrite\tattempt\tchar\n");
44: wwprintf(w, "%d\t%d\t%d\n",
45: wwnwwr, wwnwwra, wwnwwrc);
46: wwprintf(w, "wwupdat\tline\tmiss\tmajor\tmiss\n");
47: wwprintf(w, "%d\t%d\t%d\t%d\t%d\n",
48: wwnupdate, wwnupdline, wwnupdmiss, wwnmajline, wwnmajmiss);
49: wwprintf(w, "select\terror\tzero\n");
50: wwprintf(w, "%d\t%d\t%d\n",
51: wwnselect, wwnselecte, wwnselectz);
52: wwprintf(w, "read\terror\tzero\tchar\n");
53: wwprintf(w, "%d\t%d\t%d\t%d\n",
54: wwnread, wwnreade, wwnreadz, wwnreadc);
55: wwprintf(w, "ptyread\terror\tzero\tcontrol\tdata\tchar\n");
56: wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\n",
57: wwnwread, wwnwreade, wwnwreadz,
58: wwnwreadp, wwnwreadd, wwnwreadc);
59: waitnl(w);
60: closeiwin(w);
61: }
62:
63: struct lcmd_arg arg_time[] = {
64: { "who", 1, ARG_STR },
65: 0
66: };
67:
68: /*ARGSUSED*/
69: l_time(v, a)
70: struct value *v;
71: register struct value *a;
72: {
73: register struct ww *w;
74: struct rusage rusage;
75: struct timeval timeval;
76: char *strtime();
77:
78: if ((w = openiwin(6, "Timing and Resource Usage")) == 0) {
79: error("Can't open time window: %s.", wwerror());
80: return;
81: }
82:
83: (void) gettimeofday(&timeval, (struct timezone *)0);
84: timeval.tv_sec -= starttime.tv_sec;
85: if ((timeval.tv_usec -= starttime.tv_usec) < 0) {
86: timeval.tv_sec--;
87: timeval.tv_usec += 1000000;
88: }
89: (void) getrusage(a->v_type == V_STR
90: && str_match(a->v_str, "children", 1)
91: ? RUSAGE_CHILDREN : RUSAGE_SELF, &rusage);
92:
93: wwprintf(w, "time\t\tutime\t\tstime\t\tmaxrss\tixrss\tidrss\tisrss\n");
94: wwprintf(w, "%-16s", strtime(&timeval));
95: wwprintf(w, "%-16s", strtime(&rusage.ru_utime));
96: wwprintf(w, "%-16s", strtime(&rusage.ru_stime));
97: wwprintf(w, "%ld\t%ld\t%ld\t%ld\n",
98: rusage.ru_maxrss, rusage.ru_ixrss,
99: rusage.ru_idrss, rusage.ru_isrss);
100: wwprintf(w, "minflt\tmajflt\tnswap\tinblk\toublk\tmsgsnd\tmsgrcv\tnsigs\tnvcsw\tnivcsw\n");
101: wwprintf(w, "%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\n",
102: rusage.ru_minflt, rusage.ru_majflt, rusage.ru_nswap,
103: rusage.ru_inblock, rusage.ru_oublock,
104: rusage.ru_msgsnd, rusage.ru_msgrcv, rusage.ru_nsignals,
105: rusage.ru_nvcsw, rusage.ru_nivcsw);
106:
107: waitnl(w);
108: closeiwin(w);
109: }
110:
111: char *
112: strtime(t)
113: register struct timeval *t;
114: {
115: char fill = 0;
116: static char buf[20];
117: register char *p = buf;
118:
119: if (t->tv_sec > 60*60) {
120: (void) sprintf(p, "%ld:", t->tv_sec / (60*60));
121: while (*p++)
122: ;
123: p--;
124: t->tv_sec %= 60*60;
125: fill++;
126: }
127: if (t->tv_sec > 60) {
128: (void) sprintf(p, fill ? "%02ld:" : "%ld:", t->tv_sec / 60);
129: while (*p++)
130: ;
131: p--;
132: t->tv_sec %= 60;
133: fill++;
134: }
135: (void) sprintf(p, fill ? "%02ld.%02d" : "%ld.%02ld",
136: t->tv_sec, t->tv_usec / 10000);
137: return buf;
138: }
139:
140: /*ARGSUSED*/
141: l_list(v, a)
142: struct value *v, *a;
143: {
144: register struct ww *w, *wp;
145: register i;
146: int n;
147:
148: for (n = 0, i = 0; i < NWINDOW; i++)
149: if (window[i] != 0)
150: n++;
151: if (n == 0) {
152: error("No windows.");
153: return;
154: }
155: if ((w = openiwin(n + 2, "Windows")) == 0) {
156: error("Can't open listing window: %s.", wwerror());
157: return;
158: }
159: for (i = 0; i < NWINDOW; i++) {
160: if ((wp = window[i]) == 0)
161: continue;
162: wwprintf(w, "%c %c %-13s %-.*s\n",
163: wp == selwin ? '+' : (wp == lastselwin ? '-' : ' '),
164: i + '1',
165: wp->ww_state == WWS_HASPROC ? "" : "(No process)",
166: wwncol - 20,
167: wp->ww_label ? wp->ww_label : "(No label)");
168: }
169: waitnl(w);
170: closeiwin(w);
171: }
172:
173: /*ARGSUSED*/
174: l_variable(v, a)
175: struct value *v, *a;
176: {
177: register struct ww *w;
178: int printvar();
179:
180: if ((w = openiwin(wwnrow - 3, "Variables")) == 0) {
181: error("Can't open variable window: %s.", wwerror());
182: return;
183: }
184: if (var_walk(printvar, (int)w) >= 0)
185: waitnl(w);
186: closeiwin(w);
187: }
188:
189: printvar(w, r)
190: register struct ww *w;
191: register struct var *r;
192: {
193: if (more(w, 0) == 2)
194: return -1;
195: wwprintf(w, "%16s ", r->r_name);
196: switch (r->r_val.v_type) {
197: case V_STR:
198: wwprintf(w, "%s\n", r->r_val.v_str);
199: break;
200: case V_NUM:
201: wwprintf(w, "%d\n", r->r_val.v_num);
202: break;
203: case V_ERR:
204: wwprintf(w, "ERROR\n");
205: break;
206: }
207: return 0;
208: }
209:
210: struct lcmd_arg arg_shell[] = {
211: { "", 0, ARG_ANY|ARG_LIST },
212: 0
213: };
214:
215: l_shell(v, a)
216: struct value *v, *a;
217: {
218: register char **pp;
219: register struct value *vp;
220:
221: if (a->v_type == V_ERR) {
222: if ((v->v_str = str_cpy(shellfile)) != 0)
223: v->v_type = V_STR;
224: return;
225: }
226: if (v->v_str = shellfile) {
227: v->v_type = V_STR;
228: for (pp = shell + 1; *pp; pp++) {
229: str_free(*pp);
230: *pp = 0;
231: }
232: }
233: for (pp = shell, vp = a;
234: vp->v_type != V_ERR && pp < &shell[sizeof shell/sizeof *shell-1];
235: pp++, vp++)
236: if ((*pp = vp->v_type == V_STR ?
237: str_cpy(vp->v_str) : str_itoa(vp->v_num)) == 0) {
238: /* just leave shell[] the way it is */
239: p_memerror();
240: break;
241: }
242: if (shellfile = *shell)
243: if (*shell = rindex(shellfile, '/'))
244: (*shell)++;
245: else
246: *shell = shellfile;
247: }
248:
249: struct lcmd_arg arg_alias[] = {
250: { "", 0, ARG_STR },
251: { "", 0, ARG_STR|ARG_LIST },
252: 0
253: };
254:
255: l_alias(v, a)
256: struct value *v, *a;
257: {
258: if (a->v_type == V_ERR) {
259: register struct ww *w;
260: int printalias();
261:
262: if ((w = openiwin(wwnrow - 3, "Aliases")) == 0) {
263: error("Can't open alias window: %s.", wwerror());
264: return;
265: }
266: if (alias_walk(printalias, (int)w) >= 0)
267: waitnl(w);
268: closeiwin(w);
269: } else {
270: register struct alias *ap = 0;
271:
272: if (ap = alias_lookup(a->v_str)) {
273: if ((v->v_str = str_cpy(ap->a_buf)) == 0) {
274: p_memerror();
275: return;
276: }
277: v->v_type = V_STR;
278: }
279: if (a[1].v_type == V_STR) {
280: register struct value *vp;
281: register char *p, *q;
282: char *str;
283: register n;
284:
285: for (n = 0, vp = a + 1; vp->v_type != V_ERR; vp++, n++)
286: for (p = vp->v_str; *p; p++, n++)
287: ;
288: if ((str = str_alloc(n)) == 0) {
289: p_memerror();
290: return;
291: }
292: for (q = str, vp = a + 1; vp->v_type != V_ERR;
293: vp++, q[-1] = ' ')
294: for (p = vp->v_str; *q++ = *p++;)
295: ;
296: q[-1] = 0;
297: if ((ap = alias_set(a[0].v_str, (char *)0)) == 0) {
298: p_memerror();
299: str_free(str);
300: return;
301: }
302: ap->a_buf = str;
303: }
304: }
305: }
306:
307: printalias(w, a)
308: register struct ww *w;
309: register struct alias *a;
310: {
311: if (more(w, 0) == 2)
312: return -1;
313: wwprintf(w, "%16s %s\n", a->a_name, a->a_buf);
314: return 0;
315: }
316:
317: struct lcmd_arg arg_unalias[] = {
318: { "alias", 1, ARG_STR },
319: 0
320: };
321:
322: l_unalias(v, a)
323: struct value *v, *a;
324: {
325: if (a->v_type == ARG_STR)
326: v->v_num = alias_unset(a->v_str);
327: v->v_type = V_NUM;
328: }
329:
330: struct lcmd_arg arg_echo[] = {
331: { "window", 1, ARG_NUM },
332: { "", 0, ARG_ANY|ARG_LIST },
333: 0
334: };
335:
336: /*ARGSUSED*/
337: l_echo(v, a)
338: struct value *v;
339: register struct value *a;
340: {
341: char buf[20];
342: struct ww *w;
343:
344: if ((w = vtowin(a++, selwin)) == 0)
345: return;
346: while (a->v_type != V_ERR) {
347: if (a->v_type == V_NUM) {
348: (void) sprintf(buf, "%d", a->v_num);
349: (void) wwwrite(w, buf, strlen(buf));
350: } else
351: (void) wwwrite(w, a->v_str, strlen(a->v_str));
352: if ((++a)->v_type != V_ERR)
353: (void) wwwrite(w, " ", 1);
354: }
355: (void) wwwrite(w, "\r\n", 2);
356: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.