Annotation of src/usr.bin/window/cmd.c, Revision 1.7
1.7 ! millert 1: /* $OpenBSD: cmd.c,v 1.6 2001/11/19 19:02:18 mpech Exp $ */
1.2 niklas 2: /* $NetBSD: cmd.c,v 1.4 1996/02/08 20:44:57 mycroft Exp $ */
1.1 deraadt 3:
4: /*
5: * Copyright (c) 1983, 1993
6: * The Regents of the University of California. All rights reserved.
7: *
8: * This code is derived from software contributed to Berkeley by
9: * Edward Wang at The University of California, Berkeley.
10: *
11: * Redistribution and use in source and binary forms, with or without
12: * modification, are permitted provided that the following conditions
13: * are met:
14: * 1. Redistributions of source code must retain the above copyright
15: * notice, this list of conditions and the following disclaimer.
16: * 2. Redistributions in binary form must reproduce the above copyright
17: * notice, this list of conditions and the following disclaimer in the
18: * documentation and/or other materials provided with the distribution.
1.7 ! millert 19: * 3. Neither the name of the University nor the names of its contributors
1.1 deraadt 20: * may be used to endorse or promote products derived from this software
21: * without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33: * SUCH DAMAGE.
34: */
35:
36: #ifndef lint
37: #if 0
38: static char sccsid[] = "@(#)cmd.c 8.1 (Berkeley) 6/6/93";
39: #else
1.7 ! millert 40: static char rcsid[] = "$OpenBSD: cmd.c,v 1.6 2001/11/19 19:02:18 mpech Exp $";
1.1 deraadt 41: #endif
42: #endif /* not lint */
43:
44: #include "defs.h"
45: #include "char.h"
46:
47: docmd()
48: {
1.6 mpech 49: int c;
50: struct ww *w;
1.1 deraadt 51: char out = 0;
52:
53: while (!out && !quit) {
54: if ((c = wwgetc()) < 0) {
55: if (terse)
56: wwsetcursor(0, 0);
57: else {
58: wwputs("Command: ", cmdwin);
59: wwcurtowin(cmdwin);
60: }
61: do
62: wwiomux();
63: while ((c = wwgetc()) < 0);
64: }
65: if (!terse)
66: wwputc('\n', cmdwin);
67: switch (c) {
68: default:
69: if (c != escapec)
70: break;
71: case 'h': case 'j': case 'k': case 'l':
72: case 'y': case 'p':
73: case ctrl('y'):
74: case ctrl('e'):
75: case ctrl('u'):
76: case ctrl('d'):
77: case ctrl('b'):
78: case ctrl('f'):
79: case ctrl('s'):
80: case ctrl('q'):
81: case ctrl('['):
82: if (selwin == 0) {
83: error("No window.");
84: continue;
85: }
86: }
87: switch (c) {
88: case '1': case '2': case '3': case '4': case '5':
89: case '6': case '7': case '8': case '9':
90: if ((w = window[c - '1']) == 0) {
91: error("%c: No such window.", c);
92: break;
93: }
94: setselwin(w);
95: if (checkproc(selwin) >= 0)
96: out = 1;
97: break;
98: case '%':
1.5 millert 99: if ((w = getwindow()) != 0)
1.1 deraadt 100: setselwin(w);
101: break;
102: case ctrl('^'):
103: if (lastselwin != 0) {
104: setselwin(lastselwin);
105: if (checkproc(selwin) >= 0)
106: out = 1;
107: } else
108: error("No previous window.");
109: break;
110: case 'c':
1.5 millert 111: if ((w = getwindow()) != 0)
1.1 deraadt 112: closewin(w);
113: break;
114: case 'w':
115: c_window();
116: break;
117: case 'm':
1.5 millert 118: if ((w = getwindow()) != 0)
1.1 deraadt 119: c_move(w);
120: break;
121: case 'M':
1.5 millert 122: if ((w = getwindow()) != 0)
1.1 deraadt 123: movewin(w, w->ww_alt.t, w->ww_alt.l);
124: break;
125: case 's':
1.5 millert 126: if ((w = getwindow()) != 0)
1.1 deraadt 127: c_size(w);
128: break;
129: case 'S':
1.5 millert 130: if ((w = getwindow()) != 0)
1.1 deraadt 131: sizewin(w, w->ww_alt.nr, w->ww_alt.nc);
132: break;
133: case 'y':
134: c_yank();
135: break;
136: case 'p':
137: c_put();
138: break;
139: case ':':
140: c_colon();
141: break;
142: case 'h':
143: (void) wwwrite(selwin, "\b", 1);
144: break;
145: case 'j':
146: (void) wwwrite(selwin, "\n", 1);
147: break;
148: case 'k':
149: (void) wwwrite(selwin, "\033A", 2);
150: break;
151: case 'l':
152: (void) wwwrite(selwin, "\033C", 2);
153: break;
154: case ctrl('e'):
155: wwscroll(selwin, 1);
156: break;
157: case ctrl('y'):
158: wwscroll(selwin, -1);
159: break;
160: case ctrl('d'):
161: wwscroll(selwin, selwin->ww_w.nr / 2);
162: break;
163: case ctrl('u'):
164: wwscroll(selwin, - selwin->ww_w.nr / 2);
165: break;
166: case ctrl('f'):
167: wwscroll(selwin, selwin->ww_w.nr);
168: break;
169: case ctrl('b'):
170: wwscroll(selwin, - selwin->ww_w.nr);
171: break;
172: case ctrl('s'):
173: stopwin(selwin);
174: break;
175: case ctrl('q'):
176: startwin(selwin);
177: break;
178: case ctrl('l'):
179: wwredraw();
180: break;
181: case '?':
182: c_help();
183: break;
184: case ctrl('['):
185: if (checkproc(selwin) >= 0)
186: out = 1;
187: break;
188: case ctrl('z'):
189: wwsuspend();
190: break;
191: case 'q':
192: c_quit();
193: break;
194: /* debugging stuff */
195: case '&':
196: if (debug) {
197: c_debug();
198: break;
199: }
200: default:
201: if (c == escapec) {
202: if (checkproc(selwin) >= 0) {
203: (void) write(selwin->ww_pty,
204: &escapec, 1);
205: out = 1;
206: }
207: } else {
208: if (!terse)
209: wwbell();
210: error("Type ? for help.");
211: }
212: }
213: }
214: if (!quit)
215: setcmd(0);
216: }
217:
218: struct ww *
1.5 millert 219: getwindow()
1.1 deraadt 220: {
1.6 mpech 221: int c;
1.1 deraadt 222: struct ww *w = 0;
223:
224: if (!terse)
225: wwputs("Which window? ", cmdwin);
226: wwcurtowin(cmdwin);
227: while ((c = wwgetc()) < 0)
228: wwiomux();
229: if (debug && c == 'c')
230: w = cmdwin;
231: else if (debug && c == 'f')
232: w = framewin;
233: else if (debug && c == 'b')
234: w = boxwin;
235: else if (c >= '1' && c < NWINDOW + '1')
236: w = window[c - '1'];
237: else if (c == '+')
238: w = selwin;
239: else if (c == '-')
240: w = lastselwin;
241: if (w == 0)
242: wwbell();
243: if (!terse)
244: wwputc('\n', cmdwin);
245: return w;
246: }
247:
248: checkproc(w)
249: struct ww *w;
250: {
251: if (w->ww_state != WWS_HASPROC) {
252: error("No process in window.");
253: return -1;
254: }
255: return 0;
256: }
257:
258: setcmd(new)
259: char new;
260: {
261: if (new && !incmd) {
262: if (!terse)
263: wwadd(cmdwin, &wwhead);
264: if (selwin != 0)
265: wwcursor(selwin, 1);
266: wwcurwin = 0;
267: } else if (!new && incmd) {
268: if (!terse) {
269: wwdelete(cmdwin);
270: reframe();
271: }
272: if (selwin != 0)
273: wwcursor(selwin, 0);
274: wwcurwin = selwin;
275: }
276: incmd = new;
277: }
278:
279: setterse(new)
280: char new;
281: {
282: if (incmd)
283: if (new && !terse) {
284: wwdelete(cmdwin);
285: reframe();
286: } else if (!new && terse)
287: wwadd(cmdwin, &wwhead);
288: terse = new;
289: }
290:
291: /*
292: * Set the current window.
293: */
294: setselwin(w)
295: struct ww *w;
296: {
297: if (selwin == w)
298: return;
299: if (selwin != 0)
300: lastselwin = selwin;
301: if ((selwin = w) != 0)
302: front(selwin, 1);
303: }