-> 1.03
[nvi.git] / vi / v_xchar.c
blobe5db1c7ad3319533e4d878a3fda40e83328040d2
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: v_xchar.c,v 8.4 1994/01/09 14:21:16 bostic Exp $ (Berkeley) $Date: 1994/01/09 14:21:16 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include "vi.h"
15 #include "vcmd.h"
17 #define NODEL(sp) { \
18 msgq(sp, M_BERR, "No characters to delete."); \
19 return (1); \
23 * v_xchar --
24 * Deletes the character(s) on which the cursor sits.
26 int
27 v_xchar(sp, ep, vp, fm, tm, rp)
28 SCR *sp;
29 EXF *ep;
30 VICMDARG *vp;
31 MARK *fm, *tm, *rp;
33 MARK m;
34 recno_t lno;
35 u_long cnt;
36 size_t len;
38 if (file_gline(sp, ep, fm->lno, &len) == NULL) {
39 if (file_lline(sp, ep, &lno))
40 return (1);
41 if (lno == 0)
42 NODEL(sp);
43 GETLINE_ERR(sp, fm->lno);
44 return (1);
47 if (len == 0)
48 NODEL(sp);
50 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
53 * Deleting from the cursor toward the end of line, w/o moving the
54 * cursor. Note, "2x" at EOL isn't the same as "xx" because the
55 * left movement of the cursor as part of the 'x' command isn't
56 * taken into account. Historically correct.
58 tm->lno = fm->lno;
59 if (cnt < len - fm->cno) {
60 tm->cno = fm->cno + cnt;
61 m = *fm;
62 } else {
63 tm->cno = len;
64 m.lno = fm->lno;
65 m.cno = fm->cno ? fm->cno - 1 : 0;
68 if (cut(sp, ep,
69 NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, fm, tm, 0))
70 return (1);
71 if (delete(sp, ep, fm, tm, 0))
72 return (1);
74 *rp = m;
75 return (0);
79 * v_Xchar --
80 * Deletes the character(s) immediately before the current cursor
81 * position.
83 int
84 v_Xchar(sp, ep, vp, fm, tm, rp)
85 SCR *sp;
86 EXF *ep;
87 VICMDARG *vp;
88 MARK *fm, *tm, *rp;
90 u_long cnt;
92 if (fm->cno == 0) {
93 msgq(sp, M_BERR, "Already at the left-hand margin.");
94 return (1);
97 *tm = *fm;
98 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
99 fm->cno = cnt >= tm->cno ? 0 : tm->cno - cnt;
101 if (cut(sp, ep,
102 NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, fm, tm, 0))
103 return (1);
104 if (delete(sp, ep, fm, tm, 0))
105 return (1);
107 *rp = *fm;
108 return (0);