Commit | Line | Data |
---|---|---|
708ccf0a | 1 | #ifndef lint |
101acab4 | 2 | static char *sccsid = "@(#)cmd2.c 1.8 83/07/28"; |
708ccf0a EW |
3 | #endif |
4 | ||
5 | #include "defs.h" | |
6 | ||
7 | struct ww *getwin(); | |
8 | struct ww *openwin(); | |
9 | char *strtime(); | |
10 | ||
11 | dohelp() | |
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"); | |
45 | wwprintf(w, ":escape c Set escape character to c.\r\n"); | |
46 | wwprintf(w, ":%{1-9} Select window {1-9}.\r\n"); | |
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"); | |
49 | waitnl(w); | |
708ccf0a EW |
50 | closewin(w); |
51 | } | |
52 | ||
53 | dotime(flag) | |
54 | { | |
55 | register struct ww *w; | |
56 | struct rusage rusage; | |
57 | struct timeval timeval; | |
58 | ||
c417b691 | 59 | if ((w = openwin(8, "Timing and Resource Usage")) == 0) { |
101acab4 EW |
60 | if (terse) |
61 | Ding(); | |
62 | else | |
63 | wwputs("Can't open time window. ", cmdwin); | |
708ccf0a | 64 | return; |
8c4fb896 | 65 | } |
708ccf0a EW |
66 | |
67 | gettimeofday(&timeval, &timezone); | |
68 | timeval.tv_sec -= starttime.tv_sec; | |
69 | if ((timeval.tv_usec -= starttime.tv_usec) < 0) { | |
70 | timeval.tv_sec--; | |
71 | timeval.tv_usec += 1000000; | |
72 | } | |
73 | getrusage(flag, &rusage); | |
74 | ||
75 | wwprintf(w, "time\t\tutime\t\tstime\t\tmaxrss\tixrss\tidrss\tisrss\r\n"); | |
76 | wwprintf(w, "%-16s", strtime(&timeval)); | |
77 | wwprintf(w, "%-16s", strtime(&rusage.ru_utime)); | |
78 | wwprintf(w, "%-16s", strtime(&rusage.ru_stime)); | |
79 | wwprintf(w, "%D\t%D\t%D\t%D\r\n", | |
80 | rusage.ru_maxrss, rusage.ru_ixrss, | |
81 | rusage.ru_idrss, rusage.ru_isrss); | |
82 | wwprintf(w, "minflt\tmajflt\tnswap\tinblk\toublk\tmsgsnd\tmsgrcv\tnsigs\tnvcsw\tnivcsw\r\n"); | |
83 | wwprintf(w, "%D\%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\r\n", | |
84 | rusage.ru_minflt, rusage.ru_majflt, rusage.ru_nswap, | |
85 | rusage.ru_inblock, rusage.ru_oublock, | |
86 | rusage.ru_msgsnd, rusage.ru_msgrcv, rusage.ru_nsignals, | |
87 | rusage.ru_nvcsw, rusage.ru_nivcsw); | |
88 | ||
b4be6cd6 | 89 | waitnl(w); |
708ccf0a EW |
90 | closewin(w); |
91 | } | |
92 | ||
93 | char * | |
94 | strtime(t) | |
95 | register struct timeval *t; | |
96 | { | |
97 | char fill = 0; | |
98 | static char buf[20]; | |
99 | register char *p = buf; | |
100 | ||
101 | if (t->tv_sec > 60*60) { | |
102 | sprintf(p, "%D:", t->tv_sec / (60*60)); | |
103 | while (*p++) | |
104 | ; | |
105 | p--; | |
106 | t->tv_sec %= 60*60; | |
107 | fill++; | |
108 | } | |
109 | if (t->tv_sec > 60) { | |
110 | sprintf(p, fill ? "%02D:" : "%D:", t->tv_sec / 60); | |
111 | while (*p++) | |
112 | ; | |
113 | p--; | |
114 | t->tv_sec %= 60; | |
115 | fill++; | |
116 | } | |
117 | sprintf(p, fill ? "%02D.%02d" : "%D.%02D", | |
118 | t->tv_sec, t->tv_usec / 10000); | |
119 | return buf; | |
120 | } | |
121 | ||
c417b691 EW |
122 | dostat() |
123 | { | |
124 | register struct ww *w; | |
125 | ||
39b49130 | 126 | if ((w = openwin(6, "IO Statics")) == 0) { |
101acab4 EW |
127 | if (terse) |
128 | Ding(); | |
129 | else | |
130 | wwputs("Can't open statistics window. ", cmdwin); | |
c417b691 EW |
131 | return; |
132 | } | |
39b49130 EW |
133 | wwprintf(w, "nread\tnreadz\tnreade\tnreadc\tnwrite\tnwritec\r\n"); |
134 | wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\r\n", | |
135 | nread, nreadz, nreade, nreadc, wwnwrite, wwnwritec); | |
c417b691 EW |
136 | waitnl(w); |
137 | closewin(w); | |
138 | } | |
139 | ||
101acab4 EW |
140 | dolist() |
141 | { | |
142 | register struct ww *w, *w1; | |
143 | int id; | |
144 | char doneit = 0; | |
145 | ||
146 | if ((w = openwin(14, "Active Windows")) == 0) { | |
147 | if (terse) | |
148 | Ding(); | |
149 | else | |
150 | wwputs("Can't open listing window. ", cmdwin); | |
151 | return; | |
152 | } | |
153 | for (id = 1; id <= NWINDOW; id++) { | |
154 | if ((w1 = wwfind(id)) == 0) | |
155 | continue; | |
156 | doneit = 1; | |
157 | wwprintf(w, "%d %s\r\n", id, w1->ww_label); | |
158 | } | |
159 | if (!doneit) | |
160 | wwprintf(w, "No windows.\r\n"); | |
161 | waitnl(w); | |
162 | closewin(w); | |
163 | } | |
164 | ||
8c4fb896 EW |
165 | doquit() |
166 | { | |
101acab4 EW |
167 | if (terse) |
168 | Wunhide(cmdwin->ww_win); | |
093074d6 | 169 | wwputs("Really quit [yn]? ", cmdwin); |
8c4fb896 EW |
170 | wwsetcursor(WCurRow(cmdwin->ww_win), WCurCol(cmdwin->ww_win)); |
171 | while (bpeekc() < 0) | |
172 | bread(); | |
173 | if (bgetc() == 'y') { | |
174 | wwputs("Yes", cmdwin); | |
175 | quit++; | |
176 | } else | |
177 | wwputs("\r\n", cmdwin); | |
101acab4 EW |
178 | if (terse) |
179 | Whide(cmdwin->ww_win); | |
8c4fb896 EW |
180 | } |
181 | ||
708ccf0a EW |
182 | struct ww * |
183 | openwin(nrow, label) | |
184 | char *label; | |
185 | { | |
186 | register struct ww *w; | |
101acab4 | 187 | int startcol; |
708ccf0a | 188 | |
101acab4 | 189 | if ((w = wwopen(WW_NONE, 0, nrow, wwncol, 0, 0)) == 0) |
708ccf0a | 190 | return 0; |
708ccf0a | 191 | wwframe(w); |
101acab4 EW |
192 | if ((startcol = (wwncol - strlen(label)) / 2) <= 0) |
193 | startcol = 1; | |
194 | wwlabel(w, startcol, label, WINVERSE); | |
8c4fb896 | 195 | wwsetcurwin(w); |
708ccf0a EW |
196 | return w; |
197 | } | |
198 | ||
b4be6cd6 | 199 | waitnl(w) |
708ccf0a EW |
200 | register struct ww *w; |
201 | { | |
8c4fb896 | 202 | wwsetcurwin(w); |
708ccf0a EW |
203 | wwprintf(w, "\r\nType return to continue: "); |
204 | wwsetcursor(WCurRow(w->ww_win), WCurCol(w->ww_win)); | |
b4be6cd6 | 205 | while (bgetc() < 0) |
708ccf0a | 206 | bread(); |
101acab4 | 207 | wwputs("\033E", w); /* clear and home cursor */ |
b4be6cd6 EW |
208 | } |
209 | ||
210 | closewin(w) | |
211 | register struct ww *w; | |
212 | { | |
708ccf0a | 213 | wwclose(w); |
8c4fb896 | 214 | wwsetcurwin(cmdwin); |
708ccf0a | 215 | } |