1 /* @(#)cmd7.c 8.1 (Berkeley) 6/6/93 */
2 /* $NetBSD: cmd7.c,v 1.8 2006/05/02 22:30:25 christos Exp $ */
5 * Copyright (c) 1983, 1993
6 * The Regents of the University of California. All rights reserved.
8 * This code is derived from software contributed to Berkeley by
9 * Edward Wang at The University of California, Berkeley.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
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
39 #include "window_string.h"
42 void yank_highlight(int, int, int, int);
43 void yank_highlight_line(int, int, int);
44 void yank_line(int, int, int);
55 wwputs("New window size (lower right corner): ", cmdwin);
56 col = MIN(w->ww_w.r, wwncol) - 1;
57 row = MIN(w->ww_w.b, wwnrow) - 1;
58 wwadd(boxwin, framewin->ww_back);
60 wwbox(boxwin, w->ww_w.t - 1, w->ww_w.l - 1,
61 row - w->ww_w.t + 3, col - w->ww_w.l + 3);
62 wwsetcursor(row, col);
65 switch (getpos(&row, &col, w->ww_w.t, w->ww_w.l,
66 wwnrow - 1, wwncol - 1)) {
85 sizewin(w, row - w->ww_w.t + 1, col - w->ww_w.l + 1);
97 struct yb *yb_head, *yb_tail;
102 struct ww *w = selwin;
108 wwputs("Yank starting position: ", cmdwin);
113 wwsetcursor(row1, col1);
114 while (wwpeekc() < 0)
116 switch (getpos(&row1, &col1, w->ww_i.t, w->ww_i.l,
117 w->ww_i.b - 1, w->ww_i.r - 1)) {
129 wwputs("\nYank ending position: ", cmdwin);
133 wwsetcursor(row2, col2);
134 while (wwpeekc() < 0)
138 switch (getpos(&row2, &col2, w->ww_i.t, w->ww_i.l,
139 w->ww_i.b - 1, w->ww_i.r - 1)) {
141 yank_highlight(row1, col1, r, c);
146 yank_highlight(row1, col1, r, c);
147 yank_highlight(row1, col1, row2, col2);
153 if (row2 < row1 || (row2 == row1 && col2 < col1)) {
163 for (r = row1; r < row2; r++) {
164 yank_line(r, c, w->ww_b.r);
167 yank_line(r, c, col2);
168 yank_highlight(row1, col1, row2, col2);
170 wwputc('\n', cmdwin);
176 yank_highlight(int row1, int col1, int row2, int col2)
178 struct ww *w = selwin;
181 if ((wwavailmodes & WWM_REV) == 0)
183 if (row2 < row1 || (row2 == row1 && col2 < col1)) {
192 for (r = row1; r < row2; r++) {
193 yank_highlight_line(r, c, w->ww_b.r);
196 yank_highlight_line(r, c, col2);
200 yank_highlight_line(int r, int c, int cend)
202 struct ww *w = selwin;
205 if (r < w->ww_i.t || r >= w->ww_i.b)
209 if (cend >= w->ww_i.r)
211 for (win = w->ww_win[r] + c; c < cend; c++, win++) {
213 if (wwsmap[r][c] == w->ww_index) {
216 else if (*win == WWM_REV)
218 wwns[r][c].c_m ^= WWM_REV;
219 wwtouched[r] |= WWU_TOUCHED;
229 for (yp = yb_head; yp; yp = yq) {
234 yb_head = yb_tail = NULL;
238 yank_line(int r, int c, int cend)
248 if ((yp = (struct yb *) malloc(sizeof *yp)) == NULL)
251 nl = cend == selwin->ww_b.r;
252 bp = selwin->ww_buf[r];
253 for (cend--; cend >= c; cend--)
254 if (bp[cend].c_c != ' ')
256 yp->length = n = cend - c + 1;
259 if ((yp->line = str_alloc(yp->length + 1)) == NULL) {
263 for (bp += c, cp = yp->line; --n >= 0;)
269 yb_tail = yb_tail->link = yp;
271 yb_head = yb_tail = yp;
279 for (yp = yb_head; yp; yp = yp->link)
280 (void) write(selwin->ww_pty, yp->line, yp->length);