Annotation of src/usr.bin/window/cmd7.c, Revision 1.3
1.3 ! downsj 1: /* $OpenBSD$ */
1.1 deraadt 2: /* $NetBSD: cmd7.c,v 1.3 1995/09/28 10:34:12 tls Exp $ */
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.
19: * 3. All advertising materials mentioning features or use of this software
20: * must display the following acknowledgement:
21: * This product includes software developed by the University of
22: * California, Berkeley and its contributors.
23: * 4. Neither the name of the University nor the names of its contributors
24: * may be used to endorse or promote products derived from this software
25: * without specific prior written permission.
26: *
27: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37: * SUCH DAMAGE.
38: */
39:
40: #ifndef lint
41: #if 0
42: static char sccsid[] = "@(#)cmd7.c 8.1 (Berkeley) 6/6/93";
43: #else
1.3 ! downsj 44: static char rcsid[] = "$OpenBSD$";
1.1 deraadt 45: #endif
46: #endif /* not lint */
47:
48: #include "defs.h"
49: #include "string.h"
50:
51: /*
52: * Window size.
53: */
54:
55: c_size(w)
56: register struct ww *w;
57: {
58: int col, row;
59:
60: if (!terse)
61: wwputs("New window size (lower right corner): ", cmdwin);
62: col = MIN(w->ww_w.r, wwncol) - 1;
63: row = MIN(w->ww_w.b, wwnrow) - 1;
64: wwadd(boxwin, framewin->ww_back);
65: for (;;) {
66: wwbox(boxwin, w->ww_w.t - 1, w->ww_w.l - 1,
67: row - w->ww_w.t + 3, col - w->ww_w.l + 3);
68: wwsetcursor(row, col);
69: while (wwpeekc() < 0)
70: wwiomux();
71: switch (getpos(&row, &col, w->ww_w.t, w->ww_w.l,
72: wwnrow - 1, wwncol - 1)) {
73: case 3:
74: wwunbox(boxwin);
75: wwdelete(boxwin);
76: return;
77: case 2:
78: wwunbox(boxwin);
79: break;
80: case 1:
81: wwunbox(boxwin);
82: case 0:
83: continue;
84: }
85: break;
86: }
87: wwdelete(boxwin);
88: if (!terse)
89: wwputc('\n', cmdwin);
90: wwcurtowin(cmdwin);
91: sizewin(w, row - w->ww_w.t + 1, col - w->ww_w.l + 1);
92: }
93:
94: /*
95: * Yank and put
96: */
97:
98: struct yb {
99: char *line;
100: int length;
101: struct yb *link;
102: };
103: struct yb *yb_head, *yb_tail;
104:
105: c_yank()
106: {
107: struct ww *w = selwin;
108: int col1, row1;
109: int col2, row2;
110: int r, c;
111:
112: if (!terse)
113: wwputs("Yank starting position: ", cmdwin);
114: wwcursor(w, 0);
115: row1 = w->ww_cur.r;
116: col1 = w->ww_cur.c;
117: for (;;) {
118: wwsetcursor(row1, col1);
119: while (wwpeekc() < 0)
120: wwiomux();
121: switch (getpos(&row1, &col1, w->ww_i.t, w->ww_i.l,
122: w->ww_i.b - 1, w->ww_i.r - 1)) {
123: case 3:
124: goto out;
125: case 2:
126: break;
127: case 1:
128: case 0:
129: continue;
130: }
131: break;
132: }
133: if (!terse)
134: wwputs("\nYank ending position: ", cmdwin);
135: row2 = row1;
136: col2 = col1;
137: for (;;) {
138: wwsetcursor(row2, col2);
139: while (wwpeekc() < 0)
140: wwiomux();
141: r = row2;
142: c = col2;
143: switch (getpos(&row2, &col2, w->ww_i.t, w->ww_i.l,
144: w->ww_i.b - 1, w->ww_i.r - 1)) {
145: case 3:
146: yank_highlight(row1, col1, r, c);
147: goto out;
148: case 2:
149: break;
150: case 1:
151: yank_highlight(row1, col1, r, c);
152: yank_highlight(row1, col1, row2, col2);
153: case 0:
154: continue;
155: }
156: break;
157: }
158: if (row2 < row1 || row2 == row1 && col2 < col1) {
159: r = row1;
160: c = col1;
161: row1 = row2;
162: col1 = col2;
163: row2 = r;
164: col2 = c;
165: }
166: unyank();
167: c = col1;
168: for (r = row1; r < row2; r++) {
169: yank_line(r, c, w->ww_b.r);
170: c = w->ww_b.l;
171: }
172: yank_line(r, c, col2);
173: yank_highlight(row1, col1, row2, col2);
174: if (!terse)
175: wwputc('\n', cmdwin);
176: out:
177: wwcursor(w, 1);
178: }
179:
180: yank_highlight(row1, col1, row2, col2)
181: {
182: struct ww *w = selwin;
183: int r, c;
184:
185: if ((wwavailmodes & WWM_REV) == 0)
186: return;
187: if (row2 < row1 || row2 == row1 && col2 < col1) {
188: r = row1;
189: c = col1;
190: row1 = row2;
191: col1 = col2;
192: row2 = r;
193: col2 = c;
194: }
195: c = col1;
196: for (r = row1; r < row2; r++) {
197: yank_highlight_line(r, c, w->ww_b.r);
198: c = w->ww_b.l;
199: }
200: yank_highlight_line(r, c, col2);
201: }
202:
203: yank_highlight_line(r, c, cend)
204: {
205: struct ww *w = selwin;
206: char *win;
207:
208: if (r < w->ww_i.t || r >= w->ww_i.b)
209: return;
210: if (c < w->ww_i.l)
211: c = w->ww_i.l;
212: if (cend >= w->ww_i.r)
213: cend = w->ww_i.r;
214: for (win = w->ww_win[r] + c; c < cend; c++, win++) {
215: *win ^= WWM_REV;
216: if (wwsmap[r][c] == w->ww_index) {
217: if (*win == 0)
218: w->ww_nvis[r]++;
219: else if (*win == WWM_REV)
220: w->ww_nvis[r]--;
221: wwns[r][c].c_m ^= WWM_REV;
222: wwtouched[r] |= WWU_TOUCHED;
223: }
224: }
225: }
226:
227: unyank()
228: {
229: struct yb *yp, *yq;
230:
231: for (yp = yb_head; yp; yp = yq) {
232: yq = yp->link;
233: str_free(yp->line);
234: free((char *) yp);
235: }
236: yb_head = yb_tail = 0;
237: }
238:
239: yank_line(r, c, cend)
240: {
241: struct yb *yp;
242: int nl = 0;
243: int n;
244: union ww_char *bp;
245: char *cp;
246:
247: if (c == cend)
248: return;
249: if ((yp = (struct yb *) malloc(sizeof *yp)) == 0)
250: return;
251: yp->link = 0;
252: nl = cend == selwin->ww_b.r;
253: bp = selwin->ww_buf[r];
254: for (cend--; cend >= c; cend--)
255: if (bp[cend].c_c != ' ')
256: break;
257: yp->length = n = cend - c + 1;
258: if (nl)
259: yp->length++;
260: yp->line = str_alloc(yp->length + 1);
261: for (bp += c, cp = yp->line; --n >= 0;)
262: *cp++ = bp++->c_c;
263: if (nl)
264: *cp++ = '\n';
265: *cp = 0;
266: if (yb_head)
267: yb_tail = yb_tail->link = yp;
268: else
269: yb_head = yb_tail = yp;
270: }
271:
272: c_put()
273: {
274: struct yb *yp;
275:
276: for (yp = yb_head; yp; yp = yp->link)
277: (void) write(selwin->ww_pty, yp->line, yp->length);
278: }