predefined variables
[unix-history] / usr / src / usr.bin / window / cmd.c
CommitLineData
f6dc361a 1#ifndef lint
a200c620 2static char *sccsid = "@(#)cmd.c 3.17 83/12/02";
f6dc361a
EW
3#endif
4
5#include "defs.h"
6
f6dc361a
EW
7docmd()
8{
9 register char c;
10 register struct ww *w;
f6dc361a 11
74329e4e 12 if (!terse)
bb05dfb5 13 wwadd(cmdwin, &wwhead);
c417b691 14 if (selwin != 0)
73218728 15 wwcursor(selwin, 1);
86845af3
EW
16 for (;;) {
17 while ((c = bgetc()) >= 0) {
18 if (!terse)
19 (void) wwputs("\r\n", cmdwin);
20 switch (c) {
21 default:
22 if (c == escapec)
23 goto foo;
f6dc361a 24 break;
86845af3
EW
25 case 'h': case 'j': case 'k': case 'l':
26 case CTRL(y):
27 case CTRL(e):
28 case CTRL(u):
29 case CTRL(d):
30 case CTRL(b):
31 case CTRL(f):
32 case CTRL(s):
33 case CTRL(q):
34 case CTRL([):
35 foo:
36 if (selwin == 0) {
37 error("No window.");
38 continue;
39 }
f6dc361a 40 }
86845af3
EW
41 switch (c) {
42 case '1': case '2': case '3': case '4': case '5':
43 case '6': case '7': case '8': case '9':
44 if ((w = window[c - '1']) == 0) {
7c0483b9 45 error("%c: No such window.", c);
86845af3
EW
46 break;
47 }
4c8ea7ce 48 setselwin(w);
86845af3
EW
49 if (checkproc(selwin) >= 0)
50 incmd = 0;
51 break;
52 case '%':
53 if ((w = getwin()) != 0)
54 setselwin(w);
55 break;
7c0483b9
EW
56 case CTRL(^):
57 if (lastselwin != 0) {
58 setselwin(lastselwin);
59 if (checkproc(selwin) >= 0)
60 incmd = 0;
61 } else
62 error("No previous window.");
63 break;
86845af3
EW
64 case 'c':
65 if ((w = getwin()) != 0)
66 c_close(w);
67 break;
68 case 'C':
69 c_close((struct ww *)0);
70 break;
71 case 'w':
72 c_window();
73 break;
74 case 'm':
75 if ((w = getwin()) != 0)
76 c_move(w);
77 break;
f176f953
EW
78 case 'M':
79 if ((w = getwin()) != 0)
80 movewin(w, w->ww_altpos.r,
81 w->ww_altpos.c);
82 break;
86845af3
EW
83 case 'S':
84 c_show();
85 break;
86 case 'L':
87 c_list();
88 break;
89 case ':':
90 c_colon();
91 break;
92 case 'h':
93 (void) wwwrite(selwin, "\b", 1);
94 break;
95 case 'j':
96 (void) wwwrite(selwin, "\n", 1);
97 break;
98 case 'k':
99 (void) wwwrite(selwin, "\033A", 2);
100 break;
101 case 'l':
102 (void) wwwrite(selwin, "\033C", 2);
103 break;
104 case CTRL(e):
105 wwscroll(selwin, 1);
106 break;
107 case CTRL(y):
108 wwscroll(selwin, -1);
109 break;
110 case CTRL(d):
111 wwscroll(selwin, selwin->ww_w.nr / 2);
112 break;
113 case CTRL(u):
114 wwscroll(selwin, - selwin->ww_w.nr / 2);
115 break;
116 case CTRL(f):
117 wwscroll(selwin, selwin->ww_w.nr);
118 break;
119 case CTRL(b):
120 wwscroll(selwin, - selwin->ww_w.nr);
121 break;
122 case CTRL(s):
123 (void) write(selwin->ww_pty,
124 &wwwintty.ww_tchars.t_stopc, 1);
125 break;
126 case CTRL(q):
127 (void) write(selwin->ww_pty,
128 &wwwintty.ww_tchars.t_startc, 1);
129 break;
130 case CTRL(l):
131 wwredraw();
132 break;
133 case '?':
134 c_help();
135 break;
136 case CTRL([):
137 if (checkproc(selwin) >= 0)
138 incmd = 0;
139 break;
140 case CTRL(z):
141 wwsuspend();
142 break;
143 case 'q':
144 c_quit();
145 break;
146 /* undocumented commands */
147 case 's':
148 c_stat();
149 break;
57fc9db6 150#ifndef O_4_1A
86845af3
EW
151 case 't':
152 c_time(RUSAGE_SELF);
153 break;
154 case 'T':
155 c_time(RUSAGE_CHILDREN);
156 break;
57fc9db6 157#endif
f176f953
EW
158 /* debugging stuff */
159 case '&':
160 if (debug) {
161 c_debug();
162 break;
163 }
86845af3 164 default:
86845af3
EW
165 if (c == escapec) {
166 if (checkproc(selwin) >= 0) {
167 (void) write(selwin->ww_pty,
168 &escapec, 1);
169 incmd = 0;
170 }
171 } else {
172 if (!terse)
173 wwbell();
174 error("Type ? for help.");
175 }
74329e4e 176 }
f6dc361a 177 }
86845af3
EW
178 if (!incmd || quit)
179 break;
180 if (terse)
181 wwsetcursor(0, 0);
182 else {
bb05dfb5 183 (void) wwputs("Command: ", cmdwin);
86845af3
EW
184 wwcurtowin(cmdwin);
185 }
186 while (bpeekc() < 0)
187 bread();
101acab4 188 }
bb05dfb5 189 if (!quit) {
bb05dfb5
EW
190 if (!terse) {
191 wwdelete(cmdwin);
192 reframe();
193 }
73218728 194 wwcursor(selwin, 0);
86845af3 195 }
f6dc361a
EW
196}
197
198struct ww *
199getwin()
200{
201 register int c;
4c8ea7ce 202 struct ww *w = 0;
f6dc361a 203
101acab4 204 if (!terse)
bb05dfb5 205 (void) wwputs("Which window? ", cmdwin);
f2a77fe1 206 wwcurtowin(cmdwin);
b4be6cd6 207 while ((c = bgetc()) < 0)
f6dc361a 208 bread();
bb05dfb5
EW
209 if (debug && c == 'c')
210 w = cmdwin;
211 else if (debug && c == 'f')
212 w = framewin;
720ae37c
EW
213 else if (debug && c == 'b')
214 w = boxwin;
bb05dfb5
EW
215 else if (c >= '1' && c < NWINDOW + '1')
216 w = window[c - '1'];
217 if (w == 0)
218 wwbell();
101acab4 219 if (!terse)
bb05dfb5 220 (void) wwputs("\r\n", cmdwin);
f6dc361a
EW
221 return w;
222}
223
86845af3
EW
224checkproc(w)
225struct ww *w;
226{
227 if (w->ww_state != WWS_HASPROC) {
228 error("No process in window.");
229 return -1;
230 }
231 return 0;
232}
233
f6dc361a 234setselwin(w)
fe24a747
EW
235struct ww *w;
236{
7c0483b9 237 lastselwin = selwin;
a200c620 238 front(selwin = w, 1);
fe24a747
EW
239}
240
27b31336 241/*
f176f953 242 * wwvisible() doesn't work for tinted windows.
27b31336
EW
243 * But anything to make it faster.
244 */
a200c620 245front(w, doreframe)
f6dc361a
EW
246register struct ww *w;
247{
84ad208b
EW
248 if (!wwvisible(w) && w->ww_back != framewin) {
249 wwdelete(w);
250 wwadd(w, framewin);
fe24a747 251 reframe();
a200c620
EW
252 } else if (doreframe)
253 reframe();
fe24a747
EW
254}
255
256reframe()
257{
258 register struct ww *w;
259
260 wwunframe(framewin);
261 for (w = wwhead.ww_back; w != &wwhead; w = w->ww_back)
262 if (w->ww_hasframe) {
263 wwframe(w, framewin);
264 labelwin(w);
265 }
f6dc361a
EW
266}
267
4c8ea7ce 268labelwin(w)
f6dc361a
EW
269register struct ww *w;
270{
bb05dfb5
EW
271 int mode = w == selwin ? WWM_REV : 0;
272
273 if (w->ww_id >= 0) {
274 char buf[2];
f6dc361a 275
bb05dfb5
EW
276 buf[0] = w->ww_id + '1';
277 buf[1] = 0;
03e75950 278 wwlabel(w, framewin, 1, buf, mode);
bb05dfb5
EW
279 }
280 if (w->ww_label) {
281 int col;
282
283 if (w->ww_center) {
284 col = (w->ww_w.nc - strlen(w->ww_label)) / 2;
285 col = MAX(3, col);
286 } else
287 col = 3;
03e75950 288 wwlabel(w, framewin, col, w->ww_label, mode);
bb05dfb5 289 }
f6dc361a 290}