Remove building with NOCRYPTO option
[minix.git] / external / bsd / nvi / dist / vi / v_right.c
blob20541820f446c598c5a36ff04fba4702529b7ab3
1 /* $NetBSD: v_right.c,v 1.3 2014/01/26 21:43:45 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 #include <sys/cdefs.h>
14 #if 0
15 #ifndef lint
16 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 ";
17 #endif /* not lint */
18 #else
19 __RCSID("$NetBSD: v_right.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
20 #endif
22 #include <sys/types.h>
23 #include <sys/queue.h>
24 #include <sys/time.h>
26 #include <bitstring.h>
27 #include <limits.h>
28 #include <stdio.h>
30 #include "../common/common.h"
31 #include "vi.h"
34 * v_right -- [count]' ', [count]l
35 * Move right by columns.
37 * PUBLIC: int v_right __P((SCR *, VICMD *));
39 int
40 v_right(SCR *sp, VICMD *vp)
42 size_t len;
43 int isempty;
45 if (db_eget(sp, vp->m_start.lno, NULL, &len, &isempty)) {
46 if (isempty)
47 goto eol;
48 return (1);
51 /* It's always illegal to move right on empty lines. */
52 if (len == 0) {
53 eol: v_eol(sp, NULL);
54 return (1);
58 * Non-motion commands move to the end of the range. Delete and
59 * yank stay at the start. Ignore others. Adjust the end of the
60 * range for motion commands.
62 * !!!
63 * Historically, "[cdsy]l" worked at the end of a line. Also,
64 * EOL is a count sink.
66 vp->m_stop.cno = vp->m_start.cno +
67 (F_ISSET(vp, VC_C1SET) ? vp->count : 1);
68 if (vp->m_start.cno == len - 1 && !ISMOTION(vp)) {
69 v_eol(sp, NULL);
70 return (1);
72 if (vp->m_stop.cno >= len) {
73 vp->m_stop.cno = len - 1;
74 vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
75 } else if (ISMOTION(vp)) {
76 --vp->m_stop.cno;
77 vp->m_final = vp->m_start;
78 } else
79 vp->m_final = vp->m_stop;
80 return (0);
84 * v_dollar -- [count]$
85 * Move to the last column.
87 * PUBLIC: int v_dollar __P((SCR *, VICMD *));
89 int
90 v_dollar(SCR *sp, VICMD *vp)
92 size_t len;
93 int isempty;
96 * !!!
97 * A count moves down count - 1 rows, so, "3$" is the same as "2j$".
99 if ((F_ISSET(vp, VC_C1SET) ? vp->count : 1) != 1) {
101 * !!!
102 * Historically, if the $ is a motion, and deleting from
103 * at or before the first non-blank of the line, it's a
104 * line motion, and the line motion flag is set.
106 vp->m_stop.cno = 0;
107 if (nonblank(sp, vp->m_start.lno, &vp->m_stop.cno))
108 return (1);
109 if (ISMOTION(vp) && vp->m_start.cno <= vp->m_stop.cno)
110 F_SET(vp, VM_LMODE);
112 --vp->count;
113 if (v_down(sp, vp))
114 return (1);
118 * !!!
119 * Historically, it was illegal to use $ as a motion command on
120 * an empty line. Unfortunately, even though C was historically
121 * aliased to c$, it (and not c$) was special cased to work on
122 * empty lines. Since we alias C to c$ too, we have a problem.
123 * To fix it, we let c$ go through, on the assumption that it's
124 * not a problem for it to work.
126 if (db_eget(sp, vp->m_stop.lno, NULL, &len, &isempty)) {
127 if (!isempty)
128 return (1);
129 len = 0;
132 if (len == 0) {
133 if (ISMOTION(vp) && !ISCMD(vp->rkp, 'c')) {
134 v_eol(sp, NULL);
135 return (1);
137 return (0);
141 * Non-motion commands move to the end of the range. Delete
142 * and yank stay at the start. Ignore others.
144 vp->m_stop.cno = len ? len - 1 : 0;
145 vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
146 return (0);