tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / nvi / dist / vi / v_right.c
blobc677782ff03a62d4a771d06cbd662d8043be4ed5
1 /* $NetBSD: v_right.c,v 1.2 2013/11/22 15:52:06 christos Exp $ */
2 /*-
3 * Copyright (c) 1992, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1992, 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
9 */
11 #include "config.h"
13 #ifndef lint
14 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 ";
15 #endif /* not lint */
17 #include <sys/types.h>
18 #include <sys/queue.h>
19 #include <sys/time.h>
21 #include <bitstring.h>
22 #include <limits.h>
23 #include <stdio.h>
25 #include "../common/common.h"
26 #include "vi.h"
29 * v_right -- [count]' ', [count]l
30 * Move right by columns.
32 * PUBLIC: int v_right __P((SCR *, VICMD *));
34 int
35 v_right(SCR *sp, VICMD *vp)
37 size_t len;
38 int isempty;
40 if (db_eget(sp, vp->m_start.lno, NULL, &len, &isempty)) {
41 if (isempty)
42 goto eol;
43 return (1);
46 /* It's always illegal to move right on empty lines. */
47 if (len == 0) {
48 eol: v_eol(sp, NULL);
49 return (1);
53 * Non-motion commands move to the end of the range. Delete and
54 * yank stay at the start. Ignore others. Adjust the end of the
55 * range for motion commands.
57 * !!!
58 * Historically, "[cdsy]l" worked at the end of a line. Also,
59 * EOL is a count sink.
61 vp->m_stop.cno = vp->m_start.cno +
62 (F_ISSET(vp, VC_C1SET) ? vp->count : 1);
63 if (vp->m_start.cno == len - 1 && !ISMOTION(vp)) {
64 v_eol(sp, NULL);
65 return (1);
67 if (vp->m_stop.cno >= len) {
68 vp->m_stop.cno = len - 1;
69 vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
70 } else if (ISMOTION(vp)) {
71 --vp->m_stop.cno;
72 vp->m_final = vp->m_start;
73 } else
74 vp->m_final = vp->m_stop;
75 return (0);
79 * v_dollar -- [count]$
80 * Move to the last column.
82 * PUBLIC: int v_dollar __P((SCR *, VICMD *));
84 int
85 v_dollar(SCR *sp, VICMD *vp)
87 size_t len;
88 int isempty;
91 * !!!
92 * A count moves down count - 1 rows, so, "3$" is the same as "2j$".
94 if ((F_ISSET(vp, VC_C1SET) ? vp->count : 1) != 1) {
96 * !!!
97 * Historically, if the $ is a motion, and deleting from
98 * at or before the first non-blank of the line, it's a
99 * line motion, and the line motion flag is set.
101 vp->m_stop.cno = 0;
102 if (nonblank(sp, vp->m_start.lno, &vp->m_stop.cno))
103 return (1);
104 if (ISMOTION(vp) && vp->m_start.cno <= vp->m_stop.cno)
105 F_SET(vp, VM_LMODE);
107 --vp->count;
108 if (v_down(sp, vp))
109 return (1);
113 * !!!
114 * Historically, it was illegal to use $ as a motion command on
115 * an empty line. Unfortunately, even though C was historically
116 * aliased to c$, it (and not c$) was special cased to work on
117 * empty lines. Since we alias C to c$ too, we have a problem.
118 * To fix it, we let c$ go through, on the assumption that it's
119 * not a problem for it to work.
121 if (db_eget(sp, vp->m_stop.lno, NULL, &len, &isempty)) {
122 if (!isempty)
123 return (1);
124 len = 0;
127 if (len == 0) {
128 if (ISMOTION(vp) && !ISCMD(vp->rkp, 'c')) {
129 v_eol(sp, NULL);
130 return (1);
132 return (0);
136 * Non-motion commands move to the end of the range. Delete
137 * and yank stay at the start. Ignore others.
139 vp->m_stop.cno = len ? len - 1 : 0;
140 vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
141 return (0);