optionally use bundled db
[nvi.git] / vi / v_right.c
blob0cde37989b36fa9a823a5a97cabf57dfc2f8112d
1 /*-
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: v_right.c,v 10.8 2001/06/25 15:19:34 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19:34 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 #include <sys/time.h>
20 #include <bitstring.h>
21 #include <limits.h>
22 #include <stdio.h>
24 #include "../common/common.h"
25 #include "vi.h"
28 * v_right -- [count]' ', [count]l
29 * Move right by columns.
31 * PUBLIC: int v_right __P((SCR *, VICMD *));
33 int
34 v_right(SCR *sp, VICMD *vp)
36 size_t len;
37 int isempty;
39 if (db_eget(sp, vp->m_start.lno, NULL, &len, &isempty)) {
40 if (isempty)
41 goto eol;
42 return (1);
45 /* It's always illegal to move right on empty lines. */
46 if (len == 0) {
47 eol: v_eol(sp, NULL);
48 return (1);
52 * Non-motion commands move to the end of the range. Delete and
53 * yank stay at the start. Ignore others. Adjust the end of the
54 * range for motion commands.
56 * !!!
57 * Historically, "[cdsy]l" worked at the end of a line. Also,
58 * EOL is a count sink.
60 vp->m_stop.cno = vp->m_start.cno +
61 (F_ISSET(vp, VC_C1SET) ? vp->count : 1);
62 if (vp->m_start.cno == len - 1 && !ISMOTION(vp)) {
63 v_eol(sp, NULL);
64 return (1);
66 if (vp->m_stop.cno >= len) {
67 vp->m_stop.cno = len - 1;
68 vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
69 } else if (ISMOTION(vp)) {
70 --vp->m_stop.cno;
71 vp->m_final = vp->m_start;
72 } else
73 vp->m_final = vp->m_stop;
74 return (0);
78 * v_dollar -- [count]$
79 * Move to the last column.
81 * PUBLIC: int v_dollar __P((SCR *, VICMD *));
83 int
84 v_dollar(SCR *sp, VICMD *vp)
86 size_t len;
87 int isempty;
90 * !!!
91 * A count moves down count - 1 rows, so, "3$" is the same as "2j$".
93 if ((F_ISSET(vp, VC_C1SET) ? vp->count : 1) != 1) {
95 * !!!
96 * Historically, if the $ is a motion, and deleting from
97 * at or before the first non-blank of the line, it's a
98 * line motion, and the line motion flag is set.
100 vp->m_stop.cno = 0;
101 if (nonblank(sp, vp->m_start.lno, &vp->m_stop.cno))
102 return (1);
103 if (ISMOTION(vp) && vp->m_start.cno <= vp->m_stop.cno)
104 F_SET(vp, VM_LMODE);
106 --vp->count;
107 if (v_down(sp, vp))
108 return (1);
112 * !!!
113 * Historically, it was illegal to use $ as a motion command on
114 * an empty line. Unfortunately, even though C was historically
115 * aliased to c$, it (and not c$) was special cased to work on
116 * empty lines. Since we alias C to c$ too, we have a problem.
117 * To fix it, we let c$ go through, on the assumption that it's
118 * not a problem for it to work.
120 if (db_eget(sp, vp->m_stop.lno, NULL, &len, &isempty)) {
121 if (!isempty)
122 return (1);
123 len = 0;
126 if (len == 0) {
127 if (ISMOTION(vp) && !ISCMD(vp->rkp, 'c')) {
128 v_eol(sp, NULL);
129 return (1);
131 return (0);
135 * Non-motion commands move to the end of the range. Delete
136 * and yank stay at the start. Ignore others.
138 vp->m_stop.cno = len ? len - 1 : 0;
139 vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
140 return (0);