rework ARGS structures as part of ex parser rework
[nvi.git] / vi / v_right.c
blobae738b9960d50ab50c94f53c4452364c837c6a3f
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.2 1993/08/16 21:10:07 bostic Exp $ (Berkeley) $Date: 1993/08/16 21:10:07 $";
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 * One of places that you are allowed to move beyond the end of
69 * the line.
71 int
72 v_dollar(sp, ep, vp, fm, tm, rp)
73 SCR *sp;
74 EXF *ep;
75 VICMDARG *vp;
76 MARK *fm, *tm, *rp;
78 recno_t lno;
79 size_t len;
80 u_long cnt;
82 /* A count moves down count - 1 rows, so, "3$" is the same as "2j$". */
83 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
84 if (cnt != 1) {
85 --vp->count;
86 if (v_down(sp, ep, vp, fm, tm, rp))
87 return (1);
88 *fm = *rp;
91 if (file_gline(sp, ep, fm->lno, &len) == NULL) {
92 if (file_lline(sp, ep, &lno))
93 return (1);
94 if (lno == 0)
95 v_eol(sp, ep, NULL);
96 else
97 GETLINE_ERR(sp, fm->lno);
98 return (1);
101 if (len == 0) {
102 v_eol(sp, ep, NULL);
103 return (1);
106 rp->lno = fm->lno;
107 rp->cno = F_ISSET(vp, VC_C | VC_D | VC_Y) ? len : len - 1;
108 return (0);