2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
9 static char sccsid
[] = "$Id: ex_move.c,v 8.6 1994/01/09 23:24:02 bostic Exp $ (Berkeley) $Date: 1994/01/09 23:24:02 $";
12 #include <sys/types.h>
19 enum which
{COPY
, MOVE
};
20 static int cm
__P((SCR
*, EXF
*, EXCMDARG
*, enum which
));
23 * ex_copy -- :[line [,line]] co[py] line [flags]
24 * Copy selected lines.
32 return (cm(sp
, ep
, cmdp
, COPY
));
36 * ex_move -- :[line [,line]] co[py] line
37 * Move selected lines.
45 return (cm(sp
, ep
, cmdp
, MOVE
));
62 tm
.lno
= cmdp
->lineno
;
65 /* Make sure the destination is valid. */
66 if (cmd
== MOVE
&& tm
.lno
>= fm1
.lno
&& tm
.lno
< fm2
.lno
) {
67 msgq(sp
, M_ERR
, "Destination line is inside move range.");
71 /* Save the text to a cut buffer. */
72 memset(&cb
, 0, sizeof(cb
));
73 CIRCLEQ_INIT(&cb
.textq
);
74 if (cut(sp
, ep
, &cb
, NULL
, &fm1
, &fm2
, CUT_LINEMODE
))
77 /* If we're not copying, delete the old text and adjust tm. */
79 if (delete(sp
, ep
, &fm1
, &fm2
, 1)) {
83 if (tm
.lno
>= fm1
.lno
)
84 tm
.lno
-= (fm2
.lno
- fm1
.lno
) + 1;
87 /* Add the new text. */
88 if (put(sp
, ep
, &cb
, NULL
, &tm
, &m
, 1)) {
94 * Move and copy put the cursor on the last line moved or copied.
95 * The returned cursor from the put routine is the first line put,
96 * not the last, because that's the semantics of vi.
98 diff
= (fm2
.lno
- fm1
.lno
) + 1;
99 sp
->lno
= m
.lno
+ (diff
- 1);
102 sp
->rptlines
[cmd
== COPY
? L_COPIED
: L_MOVED
] += diff
;
105 err
: (void)text_lfree(&cb
.textq
);