]>
git.saurik.com Git - apple/shell_cmds.git/blob - window/lcmd2.c
1 /* $NetBSD: lcmd2.c,v 1.9 1998/08/25 20:59:42 ross Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Edward Wang at The University of California, Berkeley.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <sys/cdefs.h>
42 static char sccsid
[] = "@(#)lcmd2.c 8.1 (Berkeley) 6/6/93";
44 __RCSID("$NetBSD: lcmd2.c,v 1.9 1998/08/25 20:59:42 ross Exp $");
48 #include <sys/types.h>
50 #include <sys/resource.h>
53 #include "window_string.h"
58 int printalias
__P((void *, struct var
*));
59 int printvar
__P((void *, struct var
*));
60 char *strtime
__P((struct timeval
*t
));
68 if ((w
= openiwin(16, "IO Statistics")) == 0) {
69 error("Can't open statistics window: %s.", wwerror());
72 wwprintf(w
, "ttflush\twrite\terror\tzero\tchar\n");
73 wwprintf(w
, "%d\t%d\t%d\t%d\t%d\n",
74 wwnflush
, wwnwr
, wwnwre
, wwnwrz
, wwnwrc
);
75 wwprintf(w
, "token\tuse\tbad\tsaving\ttotal\tbaud\n");
76 wwprintf(w
, "%d\t%d\t%d\t%d\t%d\t%d/%d (%.1f/%.1f)\n",
77 wwntokdef
, wwntokuse
, wwntokbad
, wwntoksave
, wwntokc
,
78 wwntokc
- wwntoksave
?
79 (int) ((float) wwbaud
* wwntokc
/
80 (wwntokc
- wwntoksave
)) :
82 wwnwrc
? (int) ((float) wwbaud
* (wwnwrc
+ wwntoksave
) /
85 wwntokc
- wwntoksave
?
86 (float) wwntokc
/ (wwntokc
- wwntoksave
) : 1.0,
87 wwnwrc
? (float) (wwnwrc
+ wwntoksave
) / wwnwrc
: 1.0);
88 wwprintf(w
, "wwwrite\tattempt\tchar\n");
89 wwprintf(w
, "%d\t%d\t%d\n",
90 wwnwwr
, wwnwwra
, wwnwwrc
);
91 wwprintf(w
, "wwupdat\tline\tmiss\tscan\tclreol\tclreos\tmiss\tline\n");
92 wwprintf(w
, "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",
93 wwnupdate
, wwnupdline
, wwnupdmiss
, wwnupdscan
, wwnupdclreol
,
94 wwnupdclreos
, wwnupdclreosmiss
, wwnupdclreosline
);
95 wwprintf(w
, "select\terror\tzero\n");
96 wwprintf(w
, "%d\t%d\t%d\n",
97 wwnselect
, wwnselecte
, wwnselectz
);
98 wwprintf(w
, "read\terror\tzero\tchar\tack\tnack\tstat\terrorc\n");
99 wwprintf(w
, "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",
100 wwnread
, wwnreade
, wwnreadz
, wwnreadc
, wwnreadack
, wwnreadnack
,
101 wwnreadstat
, wwnreadec
);
102 wwprintf(w
, "ptyread\terror\tzero\tcontrol\tdata\tchar\n");
103 wwprintf(w
, "%d\t%d\t%d\t%d\t%d\t%d\n",
104 wwnwread
, wwnwreade
, wwnwreadz
,
105 wwnwreadp
, wwnwreadd
, wwnwreadc
);
110 struct lcmd_arg arg_time
[] = {
111 { "who", 1, ARG_STR
},
120 struct rusage rusage
;
121 struct timeval timeval
;
123 if ((w
= openiwin(8, "Timing and Resource Usage")) == 0) {
124 error("Can't open time window: %s.", wwerror());
128 (void) gettimeofday(&timeval
, (struct timezone
*)0);
129 timersub(&timeval
, &starttime
, &timeval
);
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
);
165 if (t
->tv_sec
> 60*60) {
166 (void) sprintf(p
, "%ld:", (long int)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.%02d" : "%ld.%02ld",
182 t
->tv_sec
, t
->tv_usec
/ 10000);
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)");
225 if ((w
= openiwin(wwnrow
- 3, "Variables")) == 0) {
226 error("Can't open variable window: %s.", wwerror());
229 if (var_walk(printvar
, (void *)w
) >= 0)
242 wwprintf(w
, "%16s ", r
->r_name
);
243 switch (r
->r_val
.v_type
) {
245 wwprintf(w
, "%s\n", r
->r_val
.v_str
);
248 wwprintf(w
, "%d\n", r
->r_val
.v_num
);
251 wwprintf(w
, "ERROR\n");
257 struct lcmd_arg arg_def_shell
[] = {
258 { "", 0, ARG_ANY
|ARG_LIST
},
269 if (a
->v_type
== V_ERR
) {
270 if ((v
->v_str
= str_cpy(default_shellfile
)) != 0)
274 if ((v
->v_str
= default_shellfile
)) {
276 for (pp
= default_shell
+ 1; *pp
; pp
++) {
281 for (pp
= default_shell
, vp
= a
;
282 vp
->v_type
!= V_ERR
&&
283 pp
< &default_shell
[sizeof default_shell
/sizeof *default_shell
-1];
285 if ((*pp
= vp
->v_type
== V_STR
?
286 str_cpy(vp
->v_str
) : str_itoa(vp
->v_num
)) == 0) {
287 /* just leave default_shell[] the way it is */
291 if ((default_shellfile
= *default_shell
)) {
292 if ((*default_shell
= strrchr(default_shellfile
, '/')))
295 *default_shell
= default_shellfile
;
299 struct lcmd_arg arg_alias
[] = {
301 { "", 0, ARG_STR
|ARG_LIST
},
309 if (a
->v_type
== V_ERR
) {
312 if ((w
= openiwin(wwnrow
- 3, "Aliases")) == 0) {
313 error("Can't open alias window: %s.", wwerror());
316 if (alias_walk(printalias
, (void *)w
) >= 0)
320 struct alias
*ap
= 0;
322 if ((ap
= alias_lookup(a
->v_str
))) {
323 if ((v
->v_str
= str_cpy(ap
->a_buf
)) == 0) {
329 if (a
[1].v_type
== V_STR
) {
335 for (n
= 0, vp
= a
+ 1; vp
->v_type
!= V_ERR
; vp
++, n
++)
336 for (p
= vp
->v_str
; *p
; p
++, n
++)
338 if ((str
= str_alloc(n
)) == 0) {
342 for (q
= str
, vp
= a
+ 1; vp
->v_type
!= V_ERR
;
344 for (p
= vp
->v_str
; (*q
++ = *p
++);)
347 if ((ap
= alias_set(a
[0].v_str
, (char *)0)) == 0) {
365 wwprintf(w
, "%16s %s\n", a
->a_name
, a
->a_buf
);
369 struct lcmd_arg arg_unalias
[] = {
370 { "alias", 1, ARG_STR
},
378 if (a
->v_type
== ARG_STR
)
379 v
->v_num
= alias_unset(a
->v_str
);
383 struct lcmd_arg arg_echo
[] = {
384 { "window", 1, ARG_NUM
},
385 { "", 0, ARG_ANY
|ARG_LIST
},
396 if ((w
= vtowin(a
++, selwin
)) == 0)
398 while (a
->v_type
!= V_ERR
) {
399 if (a
->v_type
== V_NUM
) {
400 (void) sprintf(buf
, "%d", a
->v_num
);
401 (void) wwwrite(w
, buf
, strlen(buf
));
403 (void) wwwrite(w
, a
->v_str
, strlen(a
->v_str
));
404 if ((++a
)->v_type
!= V_ERR
)
405 (void) wwwrite(w
, " ", 1);
407 (void) wwwrite(w
, "\r\n", 2);