Annotation of src/usr.bin/window/cmd1.c, Revision 1.2
1.2 ! niklas 1: /* $NetBSD: cmd1.c,v 1.4 1996/02/08 20:44:59 mycroft Exp $ */
1.1 deraadt 2:
3: /*
4: * Copyright (c) 1983, 1993
5: * The Regents of the University of California. All rights reserved.
6: *
7: * This code is derived from software contributed to Berkeley by
8: * Edward Wang at The University of California, Berkeley.
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: * 3. All advertising materials mentioning features or use of this software
19: * must display the following acknowledgement:
20: * This product includes software developed by the University of
21: * California, Berkeley and its contributors.
22: * 4. Neither the name of the University nor the names of its contributors
23: * may be used to endorse or promote products derived from this software
24: * without specific prior written permission.
25: *
26: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36: * SUCH DAMAGE.
37: */
38:
39: #ifndef lint
40: #if 0
41: static char sccsid[] = "@(#)cmd1.c 8.1 (Berkeley) 6/6/93";
42: #else
1.2 ! niklas 43: static char rcsid[] = "$NetBSD: cmd1.c,v 1.4 1996/02/08 20:44:59 mycroft Exp $";
1.1 deraadt 44: #endif
45: #endif /* not lint */
46:
47: #include "defs.h"
48: #include "char.h"
49:
50: c_window()
51: {
52: int col, row, xcol, xrow;
53: int id;
54:
55: if ((id = findid()) < 0)
56: return;
57: if (!terse)
58: wwputs("New window (upper left corner): ", cmdwin);
59: col = 0;
60: row = 1;
61: wwadd(boxwin, framewin->ww_back);
62: for (;;) {
63: wwbox(boxwin, row - 1, col - 1, 3, 3);
64: wwsetcursor(row, col);
65: while (wwpeekc() < 0)
66: wwiomux();
67: switch (getpos(&row, &col, row > 1, 0,
68: wwnrow - 1, wwncol - 1)) {
69: case 3:
70: wwunbox(boxwin);
71: wwdelete(boxwin);
72: return;
73: case 2:
74: wwunbox(boxwin);
75: break;
76: case 1:
77: wwunbox(boxwin);
78: case 0:
79: continue;
80: }
81: break;
82: }
83: if (!terse)
84: wwputs("\nNew window (lower right corner): ", cmdwin);
85: xcol = col;
86: xrow = row;
87: for (;;) {
88: wwbox(boxwin, row - 1, col - 1,
89: xrow - row + 3, xcol - col + 3);
90: wwsetcursor(xrow, xcol);
91: while (wwpeekc() < 0)
92: wwiomux();
93: switch (getpos(&xrow, &xcol, row, col, wwnrow - 1, wwncol - 1))
94: {
95: case 3:
96: wwunbox(boxwin);
97: wwdelete(boxwin);
98: return;
99: case 2:
100: wwunbox(boxwin);
101: break;
102: case 1:
103: wwunbox(boxwin);
104: case 0:
105: continue;
106: }
107: break;
108: }
109: wwdelete(boxwin);
110: if (!terse)
111: wwputc('\n', cmdwin);
112: wwcurtowin(cmdwin);
113: (void) openwin(id, row, col, xrow-row+1, xcol-col+1, default_nline,
1.2 ! niklas 114: (char *) 0, WWT_PTY, WWU_HASFRAME, default_shellfile,
! 115: default_shell);
1.1 deraadt 116: }
117:
118: getpos(row, col, minrow, mincol, maxrow, maxcol)
119: register int *row, *col;
120: int minrow, mincol;
121: int maxrow, maxcol;
122: {
123: static int scount;
124: int count;
1.2 ! niklas 125: int c;
1.1 deraadt 126: int oldrow = *row, oldcol = *col;
127:
128: while ((c = wwgetc()) >= 0) {
129: switch (c) {
130: case '0': case '1': case '2': case '3': case '4':
131: case '5': case '6': case '7': case '8': case '9':
132: scount = scount * 10 + c - '0';
133: continue;
134: }
135: count = scount ? scount : 1;
136: scount = 0;
137: switch (c) {
138: case 'h':
139: if ((*col -= count) < mincol)
140: *col = mincol;
141: break;
142: case 'H':
143: *col = mincol;
144: break;
145: case 'l':
146: if ((*col += count) > maxcol)
147: *col = maxcol;
148: break;
149: case 'L':
150: *col = maxcol;
151: break;
152: case 'j':
153: if ((*row += count) > maxrow)
154: *row = maxrow;
155: break;
156: case 'J':
157: *row = maxrow;
158: break;
159: case 'k':
160: if ((*row -= count) < minrow)
161: *row = minrow;
162: break;
163: case 'K':
164: *row = minrow;
165: break;
166: case ctrl('['):
167: if (!terse)
168: wwputs("\nCancelled. ", cmdwin);
169: return 3;
170: case '\r':
171: return 2;
172: default:
173: if (!terse)
174: wwputs("\nType [hjklHJKL] to move, return to enter position, escape to cancel.", cmdwin);
175: wwbell();
176: }
177: }
178: return oldrow != *row || oldcol != *col;
179: }