update to 1.01
[nvi.git] / vi / v_right.c
blobd19ac4285b586ec917dc1a04fdd1659849a9ff2a
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_right.c,v 8.3 1993/12/16 12:04:11 bostic Exp $ (Berkeley) $Date: 1993/12/16 12:04:11 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include "vi.h"
15 #include "vcmd.h"
18 * v_right -- [count]' ', [count]l
19 * Move right by columns.
21 * Special case: the 'c' and 'd' commands can move past the end of line.
23 int
24 v_right(sp, ep, vp, fm, tm, rp)
25 SCR *sp;
26 EXF *ep;
27 VICMDARG *vp;
28 MARK *fm, *tm, *rp;
30 recno_t lno;
31 u_long cnt;
32 size_t len;
34 if (file_gline(sp, ep, fm->lno, &len) == NULL) {
35 if (file_lline(sp, ep, &lno))
36 return (1);
37 if (lno == 0)
38 v_eol(sp, ep, NULL);
39 else
40 GETLINE_ERR(sp, fm->lno);
41 return (1);
44 rp->lno = fm->lno;
45 if (len == 0 || fm->cno == len - 1) {
46 if (F_ISSET(vp, VC_C | VC_D | VC_Y)) {
47 rp->cno = len;
48 return (0);
50 v_eol(sp, ep, NULL);
51 return (1);
54 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
55 rp->cno = fm->cno + cnt;
56 if (rp->cno > len - 1)
57 if (F_ISSET(vp, VC_C | VC_D | VC_Y))
58 rp->cno = len;
59 else
60 rp->cno = len - 1;
61 return (0);
65 * v_dollar -- [count]$
66 * Move to the last column.
68 int
69 v_dollar(sp, ep, vp, fm, tm, rp)
70 SCR *sp;
71 EXF *ep;
72 VICMDARG *vp;
73 MARK *fm, *tm, *rp;
75 recno_t lno;
76 size_t len;
77 u_long cnt;
80 * A count moves down count - 1 rows, so, "3$" is the same as "2j$".
82 * !!!
83 * Historically, if the $ is a motion, and deleting from at or before
84 * the first non-blank of the line, it's a line motion, and the line
85 * motion flag is set.
87 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
88 if (cnt != 1) {
89 --vp->count;
90 if (v_down(sp, ep, vp, fm, tm, rp))
91 return (1);
92 rp->cno = 0;
93 if (nonblank(sp, ep, rp->lno, &rp->cno))
94 return (1);
95 if (fm->cno <= rp->cno && F_ISSET(vp, VC_C | VC_D | VC_Y))
96 F_SET(vp, VC_LMODE);
97 } else
98 rp->lno = fm->lno;
100 if (file_gline(sp, ep, rp->lno, &len) == NULL) {
101 if (file_lline(sp, ep, &lno))
102 return (1);
103 if (lno == 0)
104 v_eol(sp, ep, NULL);
105 else
106 GETLINE_ERR(sp, rp->lno);
107 return (1);
110 if (len == 0) {
111 v_eol(sp, ep, NULL);
112 return (1);
115 /* If it's a motion component, move one past the end of the line. */
116 rp->cno = F_ISSET(vp, VC_C | VC_D | VC_Y) ? len : len - 1;
117 return (0);