* Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)ex_move.c 9.1 (Berkeley) 11/9/94";
* ex_copy -- :[line [,line]] co[py] line [flags]
* It's possible to copy things into the area that's being
* copied, e.g. "2,5copy3" is legitimate. Save the text to
memset(&cb
, 0, sizeof(cb
));
for (cnt
= fm1
.lno
; cnt
<= fm2
.lno
; ++cnt
)
if (cut_line(sp
, cnt
, 0, 0, &cb
)) {
/* Put the text into place. */
if (put(sp
, &cb
, NULL
, &tm
, &m
, 1))
* Copy puts the cursor on the last line copied. The cursor
* returned by the put routine is the first line put, not the
* last, because that's the historic semantic of vi.
cnt
= (fm2
.lno
- fm1
.lno
) + 1;
sp
->lno
= m
.lno
+ (cnt
- 1);
err
: text_lfree(&cb
.textq
);
* ex_move -- :[line [,line]] mo[ve] line
recno_t cnt
, diff
, fl
, tl
, mfl
, mtl
;
* It's not possible to move things into the area that's being
if (cmdp
->lineno
>= fm1
.lno
&& cmdp
->lineno
<= fm2
.lno
) {
msgq(sp
, M_ERR
, "144|Destination line is inside move range");
* Log the positions of any marks in the to-be-deleted lines. This
* has to work with the logging code. What happens is that we log
* the old mark positions, make the changes, then log the new mark
* positions. Then the marks end up in the right positions no matter
* which way the log is traversed.
* Reset the MARK_USERSET flag so that the log can undo the mark.
* This isn't very clean, and should probably be fixed.
/* Log the old positions of the marks. */
for (lmp
= sp
->ep
->marks
.lh_first
; lmp
!= NULL
; lmp
= lmp
->q
.le_next
)
if (lmp
->name
!= ABSMARK1
&&
lmp
->lno
>= fl
&& lmp
->lno
<= tl
) {
F_CLR(lmp
, MARK_USERSET
);
/* Get memory for the copy. */
GET_SPACE_RET(sp
, bp
, blen
, 256);
diff
= (fm2
.lno
- fm1
.lno
) + 1;
if (tl
> fl
) { /* Destination > source. */
for (cnt
= diff
; cnt
--;) {
if ((p
= file_gline(sp
, fl
, &len
)) == NULL
)
BINC_RET(sp
, bp
, blen
, len
);
if (file_aline(sp
, 1, tl
, bp
, len
))
for (lmp
= sp
->ep
->marks
.lh_first
;
lmp
!= NULL
; lmp
= lmp
->q
.le_next
)
if (lmp
->name
!= ABSMARK1
&&
} else { /* Destination < source. */
for (cnt
= diff
; cnt
--;) {
if ((p
= file_gline(sp
, fl
, &len
)) == NULL
)
BINC_RET(sp
, bp
, blen
, len
);
if (file_aline(sp
, 1, tl
++, bp
, len
))
for (lmp
= sp
->ep
->marks
.lh_first
;
lmp
!= NULL
; lmp
= lmp
->q
.le_next
)
if (lmp
->name
!= ABSMARK1
&&
FREE_SPACE(sp
, bp
, blen
);
sp
->lno
= tl
; /* Last line moved. */
/* Log the new positions of the marks. */
for (lmp
= sp
->ep
->marks
.lh_first
;
lmp
!= NULL
; lmp
= lmp
->q
.le_next
)
if (lmp
->name
!= ABSMARK1
&&
lmp
->lno
>= mfl
&& lmp
->lno
<= mtl
)
sp
->rptlines
[L_MOVED
] += diff
;