tentative print option fix
[nvi.git] / vi / v_right.c
blobabae5999ed26670846ef55525bfb0242c99100ec
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.7 1996/03/06 19:54:32 bostic Exp $ (Berkeley) $Date: 1996/03/06 19:54:32 $";
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(sp, vp)
35 SCR *sp;
36 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(sp, vp)
87 SCR *sp;
88 VICMD *vp;
90 size_t len;
91 int isempty;
94 * !!!
95 * A count moves down count - 1 rows, so, "3$" is the same as "2j$".
97 if ((F_ISSET(vp, VC_C1SET) ? vp->count : 1) != 1) {
99 * !!!
100 * Historically, if the $ is a motion, and deleting from
101 * at or before the first non-blank of the line, it's a
102 * line motion, and the line motion flag is set.
104 vp->m_stop.cno = 0;
105 if (nonblank(sp, vp->m_start.lno, &vp->m_stop.cno))
106 return (1);
107 if (ISMOTION(vp) && vp->m_start.cno <= vp->m_stop.cno)
108 F_SET(vp, VM_LMODE);
110 --vp->count;
111 if (v_down(sp, vp))
112 return (1);
116 * !!!
117 * Historically, it was illegal to use $ as a motion command on
118 * an empty line. Unfortunately, even though C was historically
119 * aliased to c$, it (and not c$) was special cased to work on
120 * empty lines. Since we alias C to c$ too, we have a problem.
121 * To fix it, we let c$ go through, on the assumption that it's
122 * not a problem for it to work.
124 if (db_eget(sp, vp->m_stop.lno, NULL, &len, &isempty)) {
125 if (!isempty)
126 return (1);
127 len = 0;
130 if (len == 0) {
131 if (ISMOTION(vp) && !ISCMD(vp->rkp, 'c')) {
132 v_eol(sp, NULL);
133 return (1);
135 return (0);
139 * Non-motion commands move to the end of the range. Delete
140 * and yank stay at the start. Ignore others.
142 vp->m_stop.cno = len ? len - 1 : 0;
143 vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
144 return (0);