|
|
1.1 root 1: /*
2: * Copyright (c) 1983 Regents of the University of California.
3: * All rights reserved.
4: *
5: * This code is derived from software contributed to Berkeley by
6: * Edward Wang at The University of California, Berkeley.
7: *
8: * Redistribution and use in source and binary forms are permitted provided
9: * that: (1) source distributions retain this entire copyright notice and
10: * comment, and (2) distributions including binaries display the following
11: * acknowledgement: ``This product includes software developed by the
12: * University of California, Berkeley and its contributors'' in the
13: * documentation or other materials provided with the distribution and in
14: * all advertising materials mentioning features or use of this software.
15: * Neither the name of the University nor the names of its contributors may
16: * be used to endorse or promote products derived from this software without
17: * specific prior written permission.
18: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21: */
22:
23: #ifndef lint
24: static char sccsid[] = "@(#)cmd1.c 3.36 (Berkeley) 6/6/90";
25: #endif /* not lint */
26:
27: #include "defs.h"
28: #include "char.h"
29:
30: c_window()
31: {
32: int col, row, xcol, xrow;
33: int id;
34:
35: if ((id = findid()) < 0)
36: return;
37: if (!terse)
38: wwputs("New window (upper left corner): ", cmdwin);
39: col = 0;
40: row = 1;
41: wwadd(boxwin, framewin->ww_back);
42: for (;;) {
43: wwbox(boxwin, row - 1, col - 1, 3, 3);
44: wwsetcursor(row, col);
45: while (wwpeekc() < 0)
46: wwiomux();
47: switch (getpos(&row, &col, row > 1, 0,
48: wwnrow - 1, wwncol - 1)) {
49: case 3:
50: wwunbox(boxwin);
51: wwdelete(boxwin);
52: return;
53: case 2:
54: wwunbox(boxwin);
55: break;
56: case 1:
57: wwunbox(boxwin);
58: case 0:
59: continue;
60: }
61: break;
62: }
63: if (!terse)
64: wwputs("\nNew window (lower right corner): ", cmdwin);
65: xcol = col;
66: xrow = row;
67: for (;;) {
68: wwbox(boxwin, row - 1, col - 1,
69: xrow - row + 3, xcol - col + 3);
70: wwsetcursor(xrow, xcol);
71: while (wwpeekc() < 0)
72: wwiomux();
73: switch (getpos(&xrow, &xcol, row, col, wwnrow - 1, wwncol - 1))
74: {
75: case 3:
76: wwunbox(boxwin);
77: wwdelete(boxwin);
78: return;
79: case 2:
80: wwunbox(boxwin);
81: break;
82: case 1:
83: wwunbox(boxwin);
84: case 0:
85: continue;
86: }
87: break;
88: }
89: wwdelete(boxwin);
90: if (!terse)
91: wwputc('\n', cmdwin);
92: wwcurtowin(cmdwin);
93: (void) openwin(id, row, col, xrow-row+1, xcol-col+1, default_nline,
94: (char *) 0, 1, 1, default_shellfile, default_shell);
95: }
96:
97: getpos(row, col, minrow, mincol, maxrow, maxcol)
98: register int *row, *col;
99: int minrow, mincol;
100: int maxrow, maxcol;
101: {
102: static int scount;
103: int count;
104: char c;
105: int oldrow = *row, oldcol = *col;
106:
107: while ((c = wwgetc()) >= 0) {
108: switch (c) {
109: case '0': case '1': case '2': case '3': case '4':
110: case '5': case '6': case '7': case '8': case '9':
111: scount = scount * 10 + c - '0';
112: continue;
113: }
114: count = scount ? scount : 1;
115: scount = 0;
116: switch (c) {
117: case 'h':
118: if ((*col -= count) < mincol)
119: *col = mincol;
120: break;
121: case 'H':
122: *col = mincol;
123: break;
124: case 'l':
125: if ((*col += count) > maxcol)
126: *col = maxcol;
127: break;
128: case 'L':
129: *col = maxcol;
130: break;
131: case 'j':
132: if ((*row += count) > maxrow)
133: *row = maxrow;
134: break;
135: case 'J':
136: *row = maxrow;
137: break;
138: case 'k':
139: if ((*row -= count) < minrow)
140: *row = minrow;
141: break;
142: case 'K':
143: *row = minrow;
144: break;
145: case ctrl('['):
146: if (!terse)
147: wwputs("\nCancelled. ", cmdwin);
148: return 3;
149: case '\r':
150: return 2;
151: default:
152: if (!terse)
153: wwputs("\nType [hjklHJKL] to move, return to enter position, escape to cancel.", cmdwin);
154: wwbell();
155: }
156: }
157: return oldrow != *row || oldcol != *col;
158: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.