2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Edward Wang at The University of California, Berkeley.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static char sccsid[] = "@(#)lcmd2.c 8.1 (Berkeley) 6/6/93";
39 static char rcsid[] = "@(#)$FreeBSD$";
43 #include <string.h> /* System string definitions. */
44 #include "mystring.h" /* Local string definitions. */
49 #include <sys/types.h>
50 #include <sys/resource.h>
56 register struct ww *w;
58 if ((w = openiwin(16, "IO Statistics")) == 0) {
59 error("Can't open statistics window: %s.", wwerror());
62 wwprintf(w, "ttflush\twrite\terror\tzero\tchar\n");
63 wwprintf(w, "%d\t%d\t%d\t%d\t%d\n",
64 wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc);
65 wwprintf(w, "token\tuse\tbad\tsaving\ttotal\tbaud\n");
66 wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d/%d (%.1f/%.1f)\n",
67 wwntokdef, wwntokuse, wwntokbad, wwntoksave, wwntokc,
68 wwntokc - wwntoksave ?
69 (int) ((float) wwbaud * wwntokc /
70 (wwntokc - wwntoksave)) :
72 wwnwrc ? (int) ((float) wwbaud * (wwnwrc + wwntoksave) /
75 wwntokc - wwntoksave ?
76 (float) wwntokc / (wwntokc - wwntoksave) : 1.0,
77 wwnwrc ? (float) (wwnwrc + wwntoksave) / wwnwrc : 1.0);
78 wwprintf(w, "wwwrite\tattempt\tchar\n");
79 wwprintf(w, "%d\t%d\t%d\n",
80 wwnwwr, wwnwwra, wwnwwrc);
81 wwprintf(w, "wwupdat\tline\tmiss\tscan\tclreol\tclreos\tmiss\tline\n");
82 wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",
83 wwnupdate, wwnupdline, wwnupdmiss, wwnupdscan, wwnupdclreol,
84 wwnupdclreos, wwnupdclreosmiss, wwnupdclreosline);
85 wwprintf(w, "select\terror\tzero\n");
86 wwprintf(w, "%d\t%d\t%d\n",
87 wwnselect, wwnselecte, wwnselectz);
88 wwprintf(w, "read\terror\tzero\tchar\tack\tnack\tstat\terrorc\n");
89 wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",
90 wwnread, wwnreade, wwnreadz, wwnreadc, wwnreadack, wwnreadnack,
91 wwnreadstat, wwnreadec);
92 wwprintf(w, "ptyread\terror\tzero\tcontrol\tdata\tchar\n");
93 wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\n",
94 wwnwread, wwnwreade, wwnwreadz,
95 wwnwreadp, wwnwreadd, wwnwreadc);
100 struct lcmd_arg arg_time[] = {
101 { "who", 1, ARG_STR },
108 register struct value *a;
110 register struct ww *w;
111 struct rusage rusage;
112 struct timeval timeval;
115 if ((w = openiwin(8, "Timing and Resource Usage")) == 0) {
116 error("Can't open time window: %s.", wwerror());
120 (void) gettimeofday(&timeval, (struct timezone *)0);
121 timeval.tv_sec -= starttime.tv_sec;
122 if ((timeval.tv_usec -= starttime.tv_usec) < 0) {
124 timeval.tv_usec += 1000000;
126 (void) getrusage(a->v_type == V_STR
127 && str_match(a->v_str, "children", 1)
128 ? RUSAGE_CHILDREN : RUSAGE_SELF, &rusage);
130 wwprintf(w, "%-15s %-15s %-15s\n",
131 "time", "utime", "stime");
132 wwprintf(w, "%-15s ", strtime(&timeval));
133 wwprintf(w, "%-15s ", strtime(&rusage.ru_utime));
134 wwprintf(w, "%-15s\n", strtime(&rusage.ru_stime));
135 wwprintf(w, "%-15s %-15s %-15s %-15s\n",
136 "maxrss", "ixrss", "idrss", "isrss");
137 wwprintf(w, "%-15ld %-15ld %-15ld %-15ld\n",
138 rusage.ru_maxrss, rusage.ru_ixrss,
139 rusage.ru_idrss, rusage.ru_isrss);
140 wwprintf(w, "%-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s\n",
141 "minflt", "majflt", "nswap", "inblk", "oublk",
142 "msgsnd", "msgrcv", "nsigs", "nvcsw", "nivcsw");
143 wwprintf(w, "%-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld\n",
144 rusage.ru_minflt, rusage.ru_majflt, rusage.ru_nswap,
145 rusage.ru_inblock, rusage.ru_oublock,
146 rusage.ru_msgsnd, rusage.ru_msgrcv, rusage.ru_nsignals,
147 rusage.ru_nvcsw, rusage.ru_nivcsw);
155 register struct timeval *t;
159 register char *p = buf;
161 if (t->tv_sec > 60*60) {
162 (void) sprintf(p, "%ld:", t->tv_sec / (60*60));
169 if (t->tv_sec > 60) {
170 (void) sprintf(p, fill ? "%02ld:" : "%ld:", t->tv_sec / 60);
177 (void) sprintf(p, fill ? "%02ld.%02d" : "%ld.%02ld",
178 t->tv_sec, t->tv_usec / 10000);
186 register struct ww *w, *wp;
190 for (n = 0, i = 0; i < NWINDOW; i++)
194 error("No windows.");
197 if ((w = openiwin(n + 2, "Windows")) == 0) {
198 error("Can't open listing window: %s.", wwerror());
201 for (i = 0; i < NWINDOW; i++) {
202 if ((wp = window[i]) == 0)
204 wwprintf(w, "%c %c %-13s %-.*s\n",
205 wp == selwin ? '+' : (wp == lastselwin ? '-' : ' '),
207 wp->ww_state == WWS_HASPROC ? "" : "(No process)",
209 wp->ww_label ? wp->ww_label : "(No label)");
219 register struct ww *w;
222 if ((w = openiwin(wwnrow - 3, "Variables")) == 0) {
223 error("Can't open variable window: %s.", wwerror());
226 if (var_walk(printvar, (long)w) >= 0)
232 register struct ww *w;
233 register struct var *r;
237 wwprintf(w, "%16s ", r->r_name);
238 switch (r->r_val.v_type) {
240 wwprintf(w, "%s\n", r->r_val.v_str);
243 wwprintf(w, "%d\n", r->r_val.v_num);
246 wwprintf(w, "ERROR\n");
252 struct lcmd_arg arg_def_shell[] = {
253 { "", 0, ARG_ANY|ARG_LIST },
261 register struct value *vp;
263 if (a->v_type == V_ERR) {
264 if ((v->v_str = str_cpy(default_shellfile)) != 0)
268 if (v->v_str = default_shellfile) {
270 for (pp = default_shell + 1; *pp; pp++) {
275 for (pp = default_shell, vp = a;
276 vp->v_type != V_ERR &&
277 pp < &default_shell[sizeof default_shell/sizeof *default_shell-1];
279 if ((*pp = vp->v_type == V_STR ?
280 str_cpy(vp->v_str) : str_itoa(vp->v_num)) == 0) {
281 /* just leave default_shell[] the way it is */
285 if (default_shellfile = *default_shell)
286 if (*default_shell = rindex(default_shellfile, '/'))
289 *default_shell = default_shellfile;
292 struct lcmd_arg arg_alias[] = {
294 { "", 0, ARG_STR|ARG_LIST },
301 if (a->v_type == V_ERR) {
302 register struct ww *w;
305 if ((w = openiwin(wwnrow - 3, "Aliases")) == 0) {
306 error("Can't open alias window: %s.", wwerror());
309 if (alias_walk(printalias, (long)w) >= 0)
313 register struct alias *ap = 0;
315 if (ap = alias_lookup(a->v_str)) {
316 if ((v->v_str = str_cpy(ap->a_buf)) == 0) {
322 if (a[1].v_type == V_STR) {
323 register struct value *vp;
324 register char *p, *q;
328 for (n = 0, vp = a + 1; vp->v_type != V_ERR; vp++, n++)
329 for (p = vp->v_str; *p; p++, n++)
331 if ((str = str_alloc(n)) == 0) {
335 for (q = str, vp = a + 1; vp->v_type != V_ERR;
337 for (p = vp->v_str; *q++ = *p++;)
340 if ((ap = alias_set(a[0].v_str, (char *)0)) == 0) {
351 register struct ww *w;
352 register struct alias *a;
356 wwprintf(w, "%16s %s\n", a->a_name, a->a_buf);
360 struct lcmd_arg arg_unalias[] = {
361 { "alias", 1, ARG_STR },
368 if (a->v_type == ARG_STR)
369 v->v_num = alias_unset(a->v_str);
373 struct lcmd_arg arg_echo[] = {
374 { "window", 1, ARG_NUM },
375 { "", 0, ARG_ANY|ARG_LIST },
382 register struct value *a;
387 if ((w = vtowin(a++, selwin)) == 0)
389 while (a->v_type != V_ERR) {
390 if (a->v_type == V_NUM) {
391 (void) sprintf(buf, "%d", a->v_num);
392 (void) wwwrite(w, buf, strlen(buf));
394 (void) wwwrite(w, a->v_str, strlen(a->v_str));
395 if ((++a)->v_type != V_ERR)
396 (void) wwwrite(w, " ", 1);
398 (void) wwwrite(w, "\r\n", 2);