1 /* $NetBSD: cmd7.c,v 1.8 2006/05/02 22:30:25 christos Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Edward Wang at The University of California, Berkeley.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
38 static char sccsid
[] = "@(#)cmd7.c 8.1 (Berkeley) 6/6/93";
40 __RCSID("$NetBSD: cmd7.c,v 1.8 2006/05/02 22:30:25 christos Exp $");
47 #include "window_string.h"
50 void yank_highlight(int, int, int, int);
51 void yank_highlight_line(int, int, int);
52 void yank_line(int, int, int);
63 wwputs("New window size (lower right corner): ", cmdwin
);
64 col
= MIN(w
->ww_w
.r
, wwncol
) - 1;
65 row
= MIN(w
->ww_w
.b
, wwnrow
) - 1;
66 wwadd(boxwin
, framewin
->ww_back
);
68 wwbox(boxwin
, w
->ww_w
.t
- 1, w
->ww_w
.l
- 1,
69 row
- w
->ww_w
.t
+ 3, col
- w
->ww_w
.l
+ 3);
70 wwsetcursor(row
, col
);
73 switch (getpos(&row
, &col
, w
->ww_w
.t
, w
->ww_w
.l
,
74 wwnrow
- 1, wwncol
- 1)) {
93 sizewin(w
, row
- w
->ww_w
.t
+ 1, col
- w
->ww_w
.l
+ 1);
105 struct yb
*yb_head
, *yb_tail
;
110 struct ww
*w
= selwin
;
116 wwputs("Yank starting position: ", cmdwin
);
121 wwsetcursor(row1
, col1
);
122 while (wwpeekc() < 0)
124 switch (getpos(&row1
, &col1
, w
->ww_i
.t
, w
->ww_i
.l
,
125 w
->ww_i
.b
- 1, w
->ww_i
.r
- 1)) {
137 wwputs("\nYank ending position: ", cmdwin
);
141 wwsetcursor(row2
, col2
);
142 while (wwpeekc() < 0)
146 switch (getpos(&row2
, &col2
, w
->ww_i
.t
, w
->ww_i
.l
,
147 w
->ww_i
.b
- 1, w
->ww_i
.r
- 1)) {
149 yank_highlight(row1
, col1
, r
, c
);
154 yank_highlight(row1
, col1
, r
, c
);
155 yank_highlight(row1
, col1
, row2
, col2
);
161 if (row2
< row1
|| (row2
== row1
&& col2
< col1
)) {
171 for (r
= row1
; r
< row2
; r
++) {
172 yank_line(r
, c
, w
->ww_b
.r
);
175 yank_line(r
, c
, col2
);
176 yank_highlight(row1
, col1
, row2
, col2
);
178 wwputc('\n', cmdwin
);
184 yank_highlight(int row1
, int col1
, int row2
, int col2
)
186 struct ww
*w
= selwin
;
189 if ((wwavailmodes
& WWM_REV
) == 0)
191 if (row2
< row1
|| (row2
== row1
&& col2
< col1
)) {
200 for (r
= row1
; r
< row2
; r
++) {
201 yank_highlight_line(r
, c
, w
->ww_b
.r
);
204 yank_highlight_line(r
, c
, col2
);
208 yank_highlight_line(int r
, int c
, int cend
)
210 struct ww
*w
= selwin
;
213 if (r
< w
->ww_i
.t
|| r
>= w
->ww_i
.b
)
217 if (cend
>= w
->ww_i
.r
)
219 for (win
= w
->ww_win
[r
] + c
; c
< cend
; c
++, win
++) {
221 if (wwsmap
[r
][c
] == w
->ww_index
) {
224 else if (*win
== WWM_REV
)
226 wwns
[r
][c
].c_m
^= WWM_REV
;
227 wwtouched
[r
] |= WWU_TOUCHED
;
237 for (yp
= yb_head
; yp
; yp
= yq
) {
242 yb_head
= yb_tail
= 0;
246 yank_line(int r
, int c
, int cend
)
256 if ((yp
= (struct yb
*) malloc(sizeof *yp
)) == 0)
259 nl
= cend
== selwin
->ww_b
.r
;
260 bp
= selwin
->ww_buf
[r
];
261 for (cend
--; cend
>= c
; cend
--)
262 if (bp
[cend
].c_c
!= ' ')
264 yp
->length
= n
= cend
- c
+ 1;
267 if ((yp
->line
= str_alloc(yp
->length
+ 1)) == NULL
) {
271 for (bp
+= c
, cp
= yp
->line
; --n
>= 0;)
277 yb_tail
= yb_tail
->link
= yp
;
279 yb_head
= yb_tail
= yp
;
287 for (yp
= yb_head
; yp
; yp
= yp
->link
)
288 (void) write(selwin
->ww_pty
, yp
->line
, yp
->length
);