rework ARGS structures as part of ex parser rework
[nvi.git] / vi / v_left.c
blob4afdf0c92b97b3af3ef8a96ebb131ddf82164764
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_left.c,v 8.2 1993/08/19 16:10:45 bostic Exp $ (Berkeley) $Date: 1993/08/19 16:10:45 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include "vi.h"
15 #include "vcmd.h"
18 * v_left -- [count]^H, [count]h
19 * Move left by columns.
21 int
22 v_left(sp, ep, vp, fm, tm, rp)
23 SCR *sp;
24 EXF *ep;
25 VICMDARG *vp;
26 MARK *fm, *tm, *rp;
28 recno_t cnt;
30 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
32 if (fm->cno == 0) {
33 msgq(sp, M_BERR, "Already in the first column.");
34 return (1);
37 rp->lno = fm->lno;
38 if (fm->cno > cnt)
39 rp->cno = fm->cno - cnt;
40 else
41 rp->cno = 0;
42 return (0);
46 * v_cfirst -- [count]_
48 * Move to the first non-blank column on a line.
50 int
51 v_cfirst(sp, ep, vp, fm, tm, rp)
52 SCR *sp;
53 EXF *ep;
54 VICMDARG *vp;
55 MARK *fm, *tm, *rp;
57 recno_t cnt;
59 /* A count moves down count - 1 rows, so, "3_" is the same as "2j_". */
60 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
61 if (cnt != 1) {
62 --vp->count;
63 if (v_down(sp, ep, vp, fm, tm, rp))
64 return (1);
65 } else
66 rp->lno = fm->lno;
67 return (0);
71 * v_first -- ^
72 * Move to the first non-blank column on this line.
74 int
75 v_first(sp, ep, vp, fm, tm, rp)
76 SCR *sp;
77 EXF *ep;
78 VICMDARG *vp;
79 MARK *fm, *tm, *rp;
82 * Yielding to none in our quest for compatibility with every
83 * historical blemish of vi, no matter how strange it might be,
84 * we permit the user to enter a count and then ignore it.
86 rp->lno = fm->lno;
87 return (0);
91 * v_ncol -- [count]|
92 * Move to column count or the first column on this line. If the
93 * requested column is past EOL, move to EOL. The nasty part is
94 * that we have to know character column widths to make this work.
96 int
97 v_ncol(sp, ep, vp, fm, tm, rp)
98 SCR *sp;
99 EXF *ep;
100 VICMDARG *vp;
101 MARK *fm, *tm, *rp;
103 if (F_ISSET(vp, VC_C1SET) && vp->count > 1)
104 rp->cno =
105 sp->s_chposition(sp, ep, fm->lno, (size_t)--vp->count);
106 else
107 rp->cno = 0;
108 rp->lno = fm->lno;
109 return (0);
113 * v_zero -- 0
114 * Move to the first column on this line.
117 v_zero(sp, ep, vp, fm, tm, rp)
118 SCR *sp;
119 EXF *ep;
120 VICMDARG *vp;
121 MARK *fm, *tm, *rp;
123 rp->lno = fm->lno;
124 rp->cno = 0;
125 return (0);