spelling error
[unix-history] / usr / src / usr.bin / window / cmd2.c
CommitLineData
708ccf0a 1#ifndef lint
35cbbdd0 2static char *sccsid = "@(#)cmd2.c 2.1 83/07/30";
708ccf0a
EW
3#endif
4
5#include "defs.h"
6
7struct ww *getwin();
8struct ww *openwin();
9char *strtime();
10
11dohelp()
12{
13 register struct ww *w;
14
101acab4
EW
15 if ((w = openwin(wwnrow - 1, "Help")) == 0) {
16 if (terse)
17 Ding();
18 else
19 wwputs("Can't open help window. ", cmdwin);
708ccf0a 20 return;
8c4fb896 21 }
101acab4
EW
22 wwprintf(w, "The escape character is %s, which gets you into command mode.\r\n\n",
23 unctrl(escapec));
24 wwprintf(w, "Short commands:\r\n\n");
25 wwprintf(w, "{1-9} Select window {1-9} and return to conversation mode.\r\n");
26 wwprintf(w, "%%{1-9} Select window {1-9}.\r\n");
27 wwprintf(w, "c{1-9} Close window {1-9}.\r\n");
8f716e82
EW
28 wwprintf(w, "C Close all windows.\r\n");
29 wwprintf(w, "S Show all windows in sequence.\r\n");
101acab4 30 wwprintf(w, "L List all windows with their labels.\r\n");
093074d6 31 wwprintf(w, "w Open a new window.\r\n");
101acab4
EW
32 wwprintf(w, "[^U^D] Scroll [up, down] half a window.\r\n");
33 wwprintf(w, "[^B^F] Scroll [up, down] a full window.\r\n");
093074d6 34 wwprintf(w, "[hjkl] Move cursor [left, down, up, right].\r\n");
093074d6
EW
35 wwprintf(w, "escape Exit command mode.\r\n");
36 wwprintf(w, "^L Redraw screen.\r\n");
37 wwprintf(w, "^Z Suspend.\r\n");
38 wwprintf(w, ". Quit.\r\n");
b4be6cd6 39 waitnl(w);
101acab4
EW
40 wwprintf(w, "Long commands:\r\n\n");
41 wwprintf(w, ":terse [off] Turn on (or off) terse mode.\r\n");
42 wwprintf(w, ":refresh {1-9} [off] Turn on (or off) refresh after every newline\r\n");
43 wwprintf(w, " for window {1-9}.\r\n");
44 wwprintf(w, ":label {1-9} string Label window {1-9}.\r\n");
e34ef5f5 45 wwprintf(w, ":escape C Set escape character to C.\r\n");
e311b0ee 46 wwprintf(w, ":%%{1-9} Select window {1-9}.\r\n");
101acab4
EW
47 wwprintf(w, ":window r c nr nc Open a window at row r column c\r\n");
48 wwprintf(w, " with nr rows and nc colomns\r\n");
e34ef5f5 49 wwprintf(w, ":source filename Execute the commands in `filename'.\r\n");
101acab4 50 waitnl(w);
708ccf0a
EW
51 closewin(w);
52}
53
54dotime(flag)
55{
56 register struct ww *w;
57 struct rusage rusage;
58 struct timeval timeval;
59
c417b691 60 if ((w = openwin(8, "Timing and Resource Usage")) == 0) {
101acab4
EW
61 if (terse)
62 Ding();
63 else
64 wwputs("Can't open time window. ", cmdwin);
708ccf0a 65 return;
8c4fb896 66 }
708ccf0a
EW
67
68 gettimeofday(&timeval, &timezone);
69 timeval.tv_sec -= starttime.tv_sec;
70 if ((timeval.tv_usec -= starttime.tv_usec) < 0) {
71 timeval.tv_sec--;
72 timeval.tv_usec += 1000000;
73 }
74 getrusage(flag, &rusage);
75
76 wwprintf(w, "time\t\tutime\t\tstime\t\tmaxrss\tixrss\tidrss\tisrss\r\n");
77 wwprintf(w, "%-16s", strtime(&timeval));
78 wwprintf(w, "%-16s", strtime(&rusage.ru_utime));
79 wwprintf(w, "%-16s", strtime(&rusage.ru_stime));
80 wwprintf(w, "%D\t%D\t%D\t%D\r\n",
81 rusage.ru_maxrss, rusage.ru_ixrss,
82 rusage.ru_idrss, rusage.ru_isrss);
83 wwprintf(w, "minflt\tmajflt\tnswap\tinblk\toublk\tmsgsnd\tmsgrcv\tnsigs\tnvcsw\tnivcsw\r\n");
84 wwprintf(w, "%D\%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\r\n",
85 rusage.ru_minflt, rusage.ru_majflt, rusage.ru_nswap,
86 rusage.ru_inblock, rusage.ru_oublock,
87 rusage.ru_msgsnd, rusage.ru_msgrcv, rusage.ru_nsignals,
88 rusage.ru_nvcsw, rusage.ru_nivcsw);
89
b4be6cd6 90 waitnl(w);
708ccf0a
EW
91 closewin(w);
92}
93
94char *
95strtime(t)
96register struct timeval *t;
97{
98 char fill = 0;
99 static char buf[20];
100 register char *p = buf;
101
102 if (t->tv_sec > 60*60) {
103 sprintf(p, "%D:", t->tv_sec / (60*60));
104 while (*p++)
105 ;
106 p--;
107 t->tv_sec %= 60*60;
108 fill++;
109 }
110 if (t->tv_sec > 60) {
111 sprintf(p, fill ? "%02D:" : "%D:", t->tv_sec / 60);
112 while (*p++)
113 ;
114 p--;
115 t->tv_sec %= 60;
116 fill++;
117 }
118 sprintf(p, fill ? "%02D.%02d" : "%D.%02D",
119 t->tv_sec, t->tv_usec / 10000);
120 return buf;
121}
122
c417b691
EW
123dostat()
124{
125 register struct ww *w;
126
39b49130 127 if ((w = openwin(6, "IO Statics")) == 0) {
101acab4
EW
128 if (terse)
129 Ding();
130 else
131 wwputs("Can't open statistics window. ", cmdwin);
c417b691
EW
132 return;
133 }
39b49130
EW
134 wwprintf(w, "nread\tnreadz\tnreade\tnreadc\tnwrite\tnwritec\r\n");
135 wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\r\n",
136 nread, nreadz, nreade, nreadc, wwnwrite, wwnwritec);
c417b691
EW
137 waitnl(w);
138 closewin(w);
139}
140
101acab4
EW
141dolist()
142{
143 register struct ww *w, *w1;
144 int id;
145 char doneit = 0;
146
147 if ((w = openwin(14, "Active Windows")) == 0) {
148 if (terse)
149 Ding();
150 else
151 wwputs("Can't open listing window. ", cmdwin);
152 return;
153 }
154 for (id = 1; id <= NWINDOW; id++) {
155 if ((w1 = wwfind(id)) == 0)
156 continue;
157 doneit = 1;
158 wwprintf(w, "%d %s\r\n", id, w1->ww_label);
159 }
160 if (!doneit)
161 wwprintf(w, "No windows.\r\n");
162 waitnl(w);
163 closewin(w);
164}
165
8c4fb896
EW
166doquit()
167{
101acab4
EW
168 if (terse)
169 Wunhide(cmdwin->ww_win);
093074d6 170 wwputs("Really quit [yn]? ", cmdwin);
8c4fb896
EW
171 wwsetcursor(WCurRow(cmdwin->ww_win), WCurCol(cmdwin->ww_win));
172 while (bpeekc() < 0)
173 bread();
174 if (bgetc() == 'y') {
175 wwputs("Yes", cmdwin);
176 quit++;
177 } else
178 wwputs("\r\n", cmdwin);
101acab4
EW
179 if (terse)
180 Whide(cmdwin->ww_win);
8c4fb896
EW
181}
182
708ccf0a
EW
183struct ww *
184openwin(nrow, label)
185char *label;
186{
187 register struct ww *w;
101acab4 188 int startcol;
708ccf0a 189
101acab4 190 if ((w = wwopen(WW_NONE, 0, nrow, wwncol, 0, 0)) == 0)
708ccf0a 191 return 0;
708ccf0a 192 wwframe(w);
101acab4
EW
193 if ((startcol = (wwncol - strlen(label)) / 2) <= 0)
194 startcol = 1;
195 wwlabel(w, startcol, label, WINVERSE);
8c4fb896 196 wwsetcurwin(w);
708ccf0a
EW
197 return w;
198}
199
b4be6cd6 200waitnl(w)
708ccf0a
EW
201register struct ww *w;
202{
8c4fb896 203 wwsetcurwin(w);
708ccf0a
EW
204 wwprintf(w, "\r\nType return to continue: ");
205 wwsetcursor(WCurRow(w->ww_win), WCurCol(w->ww_win));
b4be6cd6 206 while (bgetc() < 0)
708ccf0a 207 bread();
101acab4 208 wwputs("\033E", w); /* clear and home cursor */
b4be6cd6
EW
209}
210
211closewin(w)
212register struct ww *w;
213{
708ccf0a 214 wwclose(w);
8c4fb896 215 wwsetcurwin(cmdwin);
708ccf0a 216}