|
|
1.1 root 1: /*
2: * Copyright (c) 1983 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that the above copyright notice and this paragraph are
7: * duplicated in all such forms and that any documentation,
8: * advertising materials, and other materials related to such
9: * distribution and use acknowledge that the software was developed
10: * by the University of California, Berkeley. The name of the
11: * University may not be used to endorse or promote products derived
12: * from this software without specific prior written permission.
13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15: * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16: */
17:
18: #ifndef lint
19: static char sccsid[] = "@(#)cmd.c 3.38 (Berkeley) 6/29/88";
20: #endif /* not lint */
21:
22: #include "defs.h"
23: #include "char.h"
24:
25: docmd()
26: {
27: register char c;
28: register struct ww *w;
29: char out = 0;
30:
31: while (!out && !quit) {
32: if ((c = wwgetc()) < 0) {
33: if (terse)
34: wwsetcursor(0, 0);
35: else {
36: wwputs("Command: ", cmdwin);
37: wwcurtowin(cmdwin);
38: }
39: do
40: wwiomux();
41: while ((c = wwgetc()) < 0);
42: }
43: if (!terse)
44: wwputc('\n', cmdwin);
45: switch (c) {
46: default:
47: if (c != escapec)
48: break;
49: case 'h': case 'j': case 'k': case 'l':
50: case ctrl('y'):
51: case ctrl('e'):
52: case ctrl('u'):
53: case ctrl('d'):
54: case ctrl('b'):
55: case ctrl('f'):
56: case ctrl('s'):
57: case ctrl('q'):
58: case ctrl('['):
59: if (selwin == 0) {
60: error("No window.");
61: continue;
62: }
63: }
64: switch (c) {
65: case '1': case '2': case '3': case '4': case '5':
66: case '6': case '7': case '8': case '9':
67: if ((w = window[c - '1']) == 0) {
68: error("%c: No such window.", c);
69: break;
70: }
71: setselwin(w);
72: if (checkproc(selwin) >= 0)
73: out = 1;
74: break;
75: case '%':
76: if ((w = getwin()) != 0)
77: setselwin(w);
78: break;
79: case ctrl('^'):
80: if (lastselwin != 0) {
81: setselwin(lastselwin);
82: if (checkproc(selwin) >= 0)
83: out = 1;
84: } else
85: error("No previous window.");
86: break;
87: case 'c':
88: if ((w = getwin()) != 0)
89: closewin(w);
90: break;
91: case 'w':
92: c_window();
93: break;
94: case 'm':
95: if ((w = getwin()) != 0)
96: c_move(w);
97: break;
98: case 'M':
99: if ((w = getwin()) != 0)
100: movewin(w, w->ww_alt.t, w->ww_alt.l);
101: break;
102: case 's':
103: if ((w = getwin()) != 0)
104: c_size(w);
105: break;
106: case 'S':
107: if ((w = getwin()) != 0)
108: sizewin(w, w->ww_alt.nr, w->ww_alt.nc);
109: break;
110: case ':':
111: c_colon();
112: break;
113: case 'h':
114: (void) wwwrite(selwin, "\b", 1);
115: break;
116: case 'j':
117: (void) wwwrite(selwin, "\n", 1);
118: break;
119: case 'k':
120: (void) wwwrite(selwin, "\033A", 2);
121: break;
122: case 'l':
123: (void) wwwrite(selwin, "\033C", 2);
124: break;
125: case ctrl('e'):
126: wwscroll(selwin, 1);
127: break;
128: case ctrl('y'):
129: wwscroll(selwin, -1);
130: break;
131: case ctrl('d'):
132: wwscroll(selwin, selwin->ww_w.nr / 2);
133: break;
134: case ctrl('u'):
135: wwscroll(selwin, - selwin->ww_w.nr / 2);
136: break;
137: case ctrl('f'):
138: wwscroll(selwin, selwin->ww_w.nr);
139: break;
140: case ctrl('b'):
141: wwscroll(selwin, - selwin->ww_w.nr);
142: break;
143: case ctrl('s'):
144: stopwin(selwin);
145: break;
146: case ctrl('q'):
147: startwin(selwin);
148: break;
149: case ctrl('l'):
150: wwredraw();
151: break;
152: case '?':
153: c_help();
154: break;
155: case ctrl('['):
156: if (checkproc(selwin) >= 0)
157: out = 1;
158: break;
159: case ctrl('z'):
160: wwsuspend();
161: break;
162: case 'q':
163: c_quit();
164: break;
165: /* debugging stuff */
166: case '&':
167: if (debug) {
168: c_debug();
169: break;
170: }
171: default:
172: if (c == escapec) {
173: if (checkproc(selwin) >= 0) {
174: (void) write(selwin->ww_pty,
175: &escapec, 1);
176: out = 1;
177: }
178: } else {
179: if (!terse)
180: wwbell();
181: error("Type ? for help.");
182: }
183: }
184: }
185: if (!quit)
186: setcmd(0);
187: }
188:
189: struct ww *
190: getwin()
191: {
192: register int c;
193: struct ww *w = 0;
194:
195: if (!terse)
196: wwputs("Which window? ", cmdwin);
197: wwcurtowin(cmdwin);
198: while ((c = wwgetc()) < 0)
199: wwiomux();
200: if (debug && c == 'c')
201: w = cmdwin;
202: else if (debug && c == 'f')
203: w = framewin;
204: else if (debug && c == 'b')
205: w = boxwin;
206: else if (c >= '1' && c < NWINDOW + '1')
207: w = window[c - '1'];
208: else if (c == '+')
209: w = selwin;
210: else if (c == '-')
211: w = lastselwin;
212: if (w == 0)
213: wwbell();
214: if (!terse)
215: wwputc('\n', cmdwin);
216: return w;
217: }
218:
219: checkproc(w)
220: struct ww *w;
221: {
222: if (w->ww_state != WWS_HASPROC) {
223: error("No process in window.");
224: return -1;
225: }
226: return 0;
227: }
228:
229: setcmd(new)
230: char new;
231: {
232: if (new && !incmd) {
233: if (!terse)
234: wwadd(cmdwin, &wwhead);
235: if (selwin != 0)
236: wwcursor(selwin, 1);
237: wwcurwin = 0;
238: } else if (!new && incmd) {
239: if (!terse) {
240: wwdelete(cmdwin);
241: reframe();
242: }
243: if (selwin != 0)
244: wwcursor(selwin, 0);
245: wwcurwin = selwin;
246: }
247: incmd = new;
248: }
249:
250: setterse(new)
251: char new;
252: {
253: if (incmd)
254: if (new && !terse) {
255: wwdelete(cmdwin);
256: reframe();
257: } else if (!new && terse)
258: wwadd(cmdwin, &wwhead);
259: terse = new;
260: }
261:
262: /*
263: * Set the current window.
264: */
265: setselwin(w)
266: struct ww *w;
267: {
268: if (selwin == w)
269: return;
270: if (selwin != 0)
271: lastselwin = selwin;
272: if ((selwin = w) != 0)
273: front(selwin, 1);
274: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.