Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / nvi / vi / v_right.c
blob402d2af383debe5e8d82d60a94e01e5379265148
1 /* $NetBSD$ */
3 /*-
4 * Copyright (c) 1992, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1992, 1993, 1994, 1995, 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
12 #include "config.h"
14 #ifndef lint
15 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";
16 #endif /* not lint */
18 #include <sys/types.h>
19 #include <sys/queue.h>
20 #include <sys/time.h>
22 #include <bitstring.h>
23 #include <limits.h>
24 #include <stdio.h>
26 #include "../common/common.h"
27 #include "vi.h"
30 * v_right -- [count]' ', [count]l
31 * Move right by columns.
33 * PUBLIC: int v_right __P((SCR *, VICMD *));
35 int
36 v_right(SCR *sp, VICMD *vp)
38 size_t len;
39 int isempty;
41 if (db_eget(sp, vp->m_start.lno, NULL, &len, &isempty)) {
42 if (isempty)
43 goto eol;
44 return (1);
47 /* It's always illegal to move right on empty lines. */
48 if (len == 0) {
49 eol: v_eol(sp, NULL);
50 return (1);
54 * Non-motion commands move to the end of the range. Delete and
55 * yank stay at the start. Ignore others. Adjust the end of the
56 * range for motion commands.
58 * !!!
59 * Historically, "[cdsy]l" worked at the end of a line. Also,
60 * EOL is a count sink.
62 vp->m_stop.cno = vp->m_start.cno +
63 (F_ISSET(vp, VC_C1SET) ? vp->count : 1);
64 if (vp->m_start.cno == len - 1 && !ISMOTION(vp)) {
65 v_eol(sp, NULL);
66 return (1);
68 if (vp->m_stop.cno >= len) {
69 vp->m_stop.cno = len - 1;
70 vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
71 } else if (ISMOTION(vp)) {
72 --vp->m_stop.cno;
73 vp->m_final = vp->m_start;
74 } else
75 vp->m_final = vp->m_stop;
76 return (0);
80 * v_dollar -- [count]$
81 * Move to the last column.
83 * PUBLIC: int v_dollar __P((SCR *, VICMD *));
85 int
86 v_dollar(SCR *sp, VICMD *vp)
88 size_t len;
89 int isempty;
92 * !!!
93 * A count moves down count - 1 rows, so, "3$" is the same as "2j$".
95 if ((F_ISSET(vp, VC_C1SET) ? vp->count : 1) != 1) {
97 * !!!
98 * Historically, if the $ is a motion, and deleting from
99 * at or before the first non-blank of the line, it's a
100 * line motion, and the line motion flag is set.
102 vp->m_stop.cno = 0;
103 if (nonblank(sp, vp->m_start.lno, &vp->m_stop.cno))
104 return (1);
105 if (ISMOTION(vp) && vp->m_start.cno <= vp->m_stop.cno)
106 F_SET(vp, VM_LMODE);
108 --vp->count;
109 if (v_down(sp, vp))
110 return (1);
114 * !!!
115 * Historically, it was illegal to use $ as a motion command on
116 * an empty line. Unfortunately, even though C was historically
117 * aliased to c$, it (and not c$) was special cased to work on
118 * empty lines. Since we alias C to c$ too, we have a problem.
119 * To fix it, we let c$ go through, on the assumption that it's
120 * not a problem for it to work.
122 if (db_eget(sp, vp->m_stop.lno, NULL, &len, &isempty)) {
123 if (!isempty)
124 return (1);
125 len = 0;
128 if (len == 0) {
129 if (ISMOTION(vp) && !ISCMD(vp->rkp, 'c')) {
130 v_eol(sp, NULL);
131 return (1);
133 return (0);
137 * Non-motion commands move to the end of the range. Delete
138 * and yank stay at the start. Ignore others.
140 vp->m_stop.cno = len ? len - 1 : 0;
141 vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
142 return (0);