forgot to delete a TRACE call
[nvi.git] / ex / ex_move.c
blob8339cfb1330b31386f1f921b6f337e81aa1bb63b
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
9 static char sccsid[] = "$Id: ex_move.c,v 8.4 1993/12/29 10:37:04 bostic Exp $ (Berkeley) $Date: 1993/12/29 10:37:04 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include "vi.h"
15 #include "excmd.h"
17 enum which {COPY, MOVE};
18 static int cm __P((SCR *, EXF *, EXCMDARG *, enum which));
21 * ex_copy -- :[line [,line]] co[py] line [flags]
22 * Copy selected lines.
24 int
25 ex_copy(sp, ep, cmdp)
26 SCR *sp;
27 EXF *ep;
28 EXCMDARG *cmdp;
30 return (cm(sp, ep, cmdp, COPY));
34 * ex_move -- :[line [,line]] co[py] line
35 * Move selected lines.
37 int
38 ex_move(sp, ep, cmdp)
39 SCR *sp;
40 EXF *ep;
41 EXCMDARG *cmdp;
43 return (cm(sp, ep, cmdp, MOVE));
46 static int
47 cm(sp, ep, cmdp, cmd)
48 SCR *sp;
49 EXF *ep;
50 EXCMDARG *cmdp;
51 enum which cmd;
53 MARK fm1, fm2, m, tm;
54 recno_t diff;
56 fm1 = cmdp->addr1;
57 fm2 = cmdp->addr2;
58 tm.lno = cmdp->lineno;
59 tm.cno = 0;
61 /* Make sure the destination is valid. */
62 if (cmd == MOVE && tm.lno >= fm1.lno && tm.lno < fm2.lno) {
63 msgq(sp, M_ERR,
64 "Destination line is inside move range.");
65 return (1);
68 /* Save the text to a cut buffer. */
69 if (cut(sp, ep, DEFCB, &fm1, &fm2, 1))
70 return (1);
72 /* If we're not copying, delete the old text and adjust tm. */
73 if (cmd == MOVE) {
74 if (delete(sp, ep, &fm1, &fm2, 1))
75 return (1);
76 if (tm.lno >= fm1.lno)
77 tm.lno -= (fm2.lno - fm1.lno) + 1;
80 /* Add the new text. */
81 if (put(sp, ep, DEFCB, &tm, &m, 1))
82 return (1);
85 * Move and copy move the cursor to the last line moved or copied.
86 * The returned cursor from the put routine is the first line put,
87 * not the last, because that's the semantics that vi uses.
89 diff = (fm2.lno - fm1.lno) + 1;
90 sp->lno = m.lno + (diff - 1);
91 sp->cno = 0;
93 /* Reporting. */
94 sp->rptlines[cmd == COPY ? L_COPIED : L_MOVED] += diff;
95 return (0);