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
39 static char sccsid
[] = "@(#)lcmd2.c 8.1 (Berkeley) 6/6/93";
43 #include <sys/cdefs.h>
44 __FBSDID("$FreeBSD$");
47 #include <string.h> /* System string definitions. */
48 #include "mystring.h" /* Local string definitions. */
53 #include <sys/types.h>
54 #include <sys/resource.h>
60 register struct ww
*w
;
62 if ((w
= openiwin(16, "IO Statistics")) == 0) {
63 error("Can't open statistics window: %s.", wwerror());
66 wwprintf(w
, "ttflush\twrite\terror\tzero\tchar\n");
67 wwprintf(w
, "%d\t%d\t%d\t%d\t%d\n",
68 wwnflush
, wwnwr
, wwnwre
, wwnwrz
, wwnwrc
);
69 wwprintf(w
, "token\tuse\tbad\tsaving\ttotal\tbaud\n");
70 wwprintf(w
, "%d\t%d\t%d\t%d\t%d\t%d/%d (%.1f/%.1f)\n",
71 wwntokdef
, wwntokuse
, wwntokbad
, wwntoksave
, wwntokc
,
72 wwntokc
- wwntoksave
?
73 (int) ((float) wwbaud
* wwntokc
/
74 (wwntokc
- wwntoksave
)) :
76 wwnwrc
? (int) ((float) wwbaud
* (wwnwrc
+ wwntoksave
) /
79 wwntokc
- wwntoksave
?
80 (float) wwntokc
/ (wwntokc
- wwntoksave
) : 1.0,
81 wwnwrc
? (float) (wwnwrc
+ wwntoksave
) / wwnwrc
: 1.0);
82 wwprintf(w
, "wwwrite\tattempt\tchar\n");
83 wwprintf(w
, "%d\t%d\t%d\n",
84 wwnwwr
, wwnwwra
, wwnwwrc
);
85 wwprintf(w
, "wwupdat\tline\tmiss\tscan\tclreol\tclreos\tmiss\tline\n");
86 wwprintf(w
, "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",
87 wwnupdate
, wwnupdline
, wwnupdmiss
, wwnupdscan
, wwnupdclreol
,
88 wwnupdclreos
, wwnupdclreosmiss
, wwnupdclreosline
);
89 wwprintf(w
, "select\terror\tzero\n");
90 wwprintf(w
, "%d\t%d\t%d\n",
91 wwnselect
, wwnselecte
, wwnselectz
);
92 wwprintf(w
, "read\terror\tzero\tchar\tack\tnack\tstat\terrorc\n");
93 wwprintf(w
, "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",
94 wwnread
, wwnreade
, wwnreadz
, wwnreadc
, wwnreadack
, wwnreadnack
,
95 wwnreadstat
, wwnreadec
);
96 wwprintf(w
, "ptyread\terror\tzero\tcontrol\tdata\tchar\n");
97 wwprintf(w
, "%d\t%d\t%d\t%d\t%d\t%d\n",
98 wwnwread
, wwnwreade
, wwnwreadz
,
99 wwnwreadp
, wwnwreadd
, wwnwreadc
);
104 struct lcmd_arg arg_time
[] = {
105 { "who", 1, ARG_STR
},
112 register struct value
*a
;
114 register struct ww
*w
;
115 struct rusage rusage
;
116 struct timeval timeval
;
119 if ((w
= openiwin(8, "Timing and Resource Usage")) == 0) {
120 error("Can't open time window: %s.", wwerror());
124 (void) gettimeofday(&timeval
, (struct timezone
*)0);
125 timeval
.tv_sec
-= starttime
.tv_sec
;
126 if ((timeval
.tv_usec
-= starttime
.tv_usec
) < 0) {
128 timeval
.tv_usec
+= 1000000;
130 (void) getrusage(a
->v_type
== V_STR
131 && str_match(a
->v_str
, "children", 1)
132 ? RUSAGE_CHILDREN
: RUSAGE_SELF
, &rusage
);
134 wwprintf(w
, "%-15s %-15s %-15s\n",
135 "time", "utime", "stime");
136 wwprintf(w
, "%-15s ", strtime(&timeval
));
137 wwprintf(w
, "%-15s ", strtime(&rusage
.ru_utime
));
138 wwprintf(w
, "%-15s\n", strtime(&rusage
.ru_stime
));
139 wwprintf(w
, "%-15s %-15s %-15s %-15s\n",
140 "maxrss", "ixrss", "idrss", "isrss");
141 wwprintf(w
, "%-15ld %-15ld %-15ld %-15ld\n",
142 rusage
.ru_maxrss
, rusage
.ru_ixrss
,
143 rusage
.ru_idrss
, rusage
.ru_isrss
);
144 wwprintf(w
, "%-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s\n",
145 "minflt", "majflt", "nswap", "inblk", "oublk",
146 "msgsnd", "msgrcv", "nsigs", "nvcsw", "nivcsw");
147 wwprintf(w
, "%-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld\n",
148 rusage
.ru_minflt
, rusage
.ru_majflt
, rusage
.ru_nswap
,
149 rusage
.ru_inblock
, rusage
.ru_oublock
,
150 rusage
.ru_msgsnd
, rusage
.ru_msgrcv
, rusage
.ru_nsignals
,
151 rusage
.ru_nvcsw
, rusage
.ru_nivcsw
);
159 register struct timeval
*t
;
163 register char *p
= buf
;
165 if (t
->tv_sec
> 60*60) {
166 (void) sprintf(p
, "%ld:", t
->tv_sec
/ (60*60));
173 if (t
->tv_sec
> 60) {
174 (void) sprintf(p
, fill
? "%02ld:" : "%ld:", t
->tv_sec
/ 60);
181 (void) sprintf(p
, fill
? "%02ld.%02ld" : "%ld.%02ld",
182 t
->tv_sec
, t
->tv_usec
/ 10000);
190 register struct ww
*w
, *wp
;
194 for (n
= 0, i
= 0; i
< NWINDOW
; i
++)
198 error("No windows.");
201 if ((w
= openiwin(n
+ 2, "Windows")) == 0) {
202 error("Can't open listing window: %s.", wwerror());
205 for (i
= 0; i
< NWINDOW
; i
++) {
206 if ((wp
= window
[i
]) == 0)
208 wwprintf(w
, "%c %c %-13s %-.*s\n",
209 wp
== selwin
? '+' : (wp
== lastselwin
? '-' : ' '),
211 wp
->ww_state
== WWS_HASPROC
? "" : "(No process)",
213 wp
->ww_label
? wp
->ww_label
: "(No label)");
223 register struct ww
*w
;
226 if ((w
= openiwin(wwnrow
- 3, "Variables")) == 0) {
227 error("Can't open variable window: %s.", wwerror());
230 if (var_walk(printvar
, (long)w
) >= 0)
236 register struct ww
*w
;
237 register struct var
*r
;
241 wwprintf(w
, "%16s ", r
->r_name
);
242 switch (r
->r_val
.v_type
) {
244 wwprintf(w
, "%s\n", r
->r_val
.v_str
);
247 wwprintf(w
, "%d\n", r
->r_val
.v_num
);
250 wwprintf(w
, "ERROR\n");
256 struct lcmd_arg arg_def_shell
[] = {
257 { "", 0, ARG_ANY
|ARG_LIST
},
265 register struct value
*vp
;
267 if (a
->v_type
== V_ERR
) {
268 if ((v
->v_str
= str_cpy(default_shellfile
)) != 0)
272 if (v
->v_str
= default_shellfile
) {
274 for (pp
= default_shell
+ 1; *pp
; pp
++) {
279 for (pp
= default_shell
, vp
= a
;
280 vp
->v_type
!= V_ERR
&&
281 pp
< &default_shell
[sizeof default_shell
/sizeof *default_shell
-1];
283 if ((*pp
= vp
->v_type
== V_STR
?
284 str_cpy(vp
->v_str
) : str_itoa(vp
->v_num
)) == 0) {
285 /* just leave default_shell[] the way it is */
289 if (default_shellfile
= *default_shell
)
290 if (*default_shell
= rindex(default_shellfile
, '/'))
293 *default_shell
= default_shellfile
;
296 struct lcmd_arg arg_alias
[] = {
298 { "", 0, ARG_STR
|ARG_LIST
},
305 if (a
->v_type
== V_ERR
) {
306 register struct ww
*w
;
309 if ((w
= openiwin(wwnrow
- 3, "Aliases")) == 0) {
310 error("Can't open alias window: %s.", wwerror());
313 if (alias_walk(printalias
, (long)w
) >= 0)
317 register struct alias
*ap
= 0;
319 if (ap
= alias_lookup(a
->v_str
)) {
320 if ((v
->v_str
= str_cpy(ap
->a_buf
)) == 0) {
326 if (a
[1].v_type
== V_STR
) {
327 register struct value
*vp
;
328 register char *p
, *q
;
332 for (n
= 0, vp
= a
+ 1; vp
->v_type
!= V_ERR
; vp
++, n
++)
333 for (p
= vp
->v_str
; *p
; p
++, n
++)
335 if ((str
= str_alloc(n
)) == 0) {
339 for (q
= str
, vp
= a
+ 1; vp
->v_type
!= V_ERR
;
341 for (p
= vp
->v_str
; *q
++ = *p
++;)
344 if ((ap
= alias_set(a
[0].v_str
, (char *)0)) == 0) {
355 register struct ww
*w
;
356 register struct alias
*a
;
360 wwprintf(w
, "%16s %s\n", a
->a_name
, a
->a_buf
);
364 struct lcmd_arg arg_unalias
[] = {
365 { "alias", 1, ARG_STR
},
372 if (a
->v_type
== ARG_STR
)
373 v
->v_num
= alias_unset(a
->v_str
);
377 struct lcmd_arg arg_echo
[] = {
378 { "window", 1, ARG_NUM
},
379 { "", 0, ARG_ANY
|ARG_LIST
},
386 register struct value
*a
;
391 if ((w
= vtowin(a
++, selwin
)) == 0)
393 while (a
->v_type
!= V_ERR
) {
394 if (a
->v_type
== V_NUM
) {
395 (void) sprintf(buf
, "%d", a
->v_num
);
396 (void) wwwrite(w
, buf
, strlen(buf
));
398 (void) wwwrite(w
, a
->v_str
, strlen(a
->v_str
));
399 if ((++a
)->v_type
!= V_ERR
)
400 (void) wwwrite(w
, " ", 1);
402 (void) wwwrite(w
, "\r\n", 2);