tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / nvi / dist / vi / v_left.c
blob8d0ba1a80d518a8f8c222efa439ba80919a83b57
1 /* $NetBSD: v_left.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_left.c,v 10.9 2001/06/25 15:19:32 skimo Exp (Berkeley) Date: 2001/06/25 15:19:32 ";
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_left -- [count]^H, [count]h
30 * Move left by columns.
32 * PUBLIC: int v_left __P((SCR *, VICMD *));
34 int
35 v_left(SCR *sp, VICMD *vp)
37 db_recno_t cnt;
40 * !!!
41 * The ^H and h commands always failed in the first column.
43 if (vp->m_start.cno == 0) {
44 v_sol(sp);
45 return (1);
48 /* Find the end of the range. */
49 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
50 if (vp->m_start.cno > cnt)
51 vp->m_stop.cno = vp->m_start.cno - cnt;
52 else
53 vp->m_stop.cno = 0;
56 * All commands move to the end of the range. Motion commands
57 * adjust the starting point to the character before the current
58 * one.
60 if (ISMOTION(vp))
61 --vp->m_start.cno;
62 vp->m_final = vp->m_stop;
63 return (0);
67 * v_cfirst -- [count]_
68 * Move to the first non-blank character in a line.
70 * PUBLIC: int v_cfirst __P((SCR *, VICMD *));
72 int
73 v_cfirst(SCR *sp, VICMD *vp)
75 db_recno_t cnt, lno;
78 * !!!
79 * If the _ is a motion component, it makes the command a line motion
80 * e.g. "d_" deletes the line. It also means that the cursor doesn't
81 * move.
83 * The _ command never failed in the first column.
85 if (ISMOTION(vp))
86 F_SET(vp, VM_LMODE);
88 * !!!
89 * Historically a specified count makes _ move down count - 1
90 * rows, so, "3_" is the same as "2j_".
92 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
93 if (cnt != 1) {
94 --vp->count;
95 return (v_down(sp, vp));
99 * Move to the first non-blank.
101 * Can't just use RCM_SET_FNB, in case _ is used as the motion
102 * component of another command.
104 vp->m_stop.cno = 0;
105 if (nonblank(sp, vp->m_stop.lno, &vp->m_stop.cno))
106 return (1);
109 * !!!
110 * The _ command has to fail if the file is empty and we're doing
111 * a delete. If deleting line 1, and 0 is the first nonblank,
112 * make the check.
114 if (vp->m_stop.lno == 1 &&
115 vp->m_stop.cno == 0 && ISCMD(vp->rkp, 'd')) {
116 if (db_last(sp, &lno))
117 return (1);
118 if (lno == 0) {
119 v_sol(sp);
120 return (1);
125 * Delete and non-motion commands move to the end of the range,
126 * yank stays at the start. Ignore others.
128 vp->m_final =
129 ISMOTION(vp) && ISCMD(vp->rkp, 'y') ? vp->m_start : vp->m_stop;
130 return (0);
134 * v_first -- ^
135 * Move to the first non-blank character in this line.
137 * PUBLIC: int v_first __P((SCR *, VICMD *));
140 v_first(SCR *sp, VICMD *vp)
143 * !!!
144 * Yielding to none in our quest for compatibility with every
145 * historical blemish of vi, no matter how strange it might be,
146 * we permit the user to enter a count and then ignore it.
150 * Move to the first non-blank.
152 * Can't just use RCM_SET_FNB, in case ^ is used as the motion
153 * component of another command.
155 vp->m_stop.cno = 0;
156 if (nonblank(sp, vp->m_stop.lno, &vp->m_stop.cno))
157 return (1);
160 * !!!
161 * The ^ command succeeded if used as a command when the cursor was
162 * on the first non-blank in the line, but failed if used as a motion
163 * component in the same situation.
165 if (ISMOTION(vp) && vp->m_start.cno == vp->m_stop.cno) {
166 v_sol(sp);
167 return (1);
171 * If moving right, non-motion commands move to the end of the range.
172 * Delete and yank stay at the start. Motion commands adjust the
173 * ending point to the character before the current ending charcter.
175 * If moving left, all commands move to the end of the range. Motion
176 * commands adjust the starting point to the character before the
177 * current starting character.
179 if (vp->m_start.cno < vp->m_stop.cno)
180 if (ISMOTION(vp)) {
181 --vp->m_stop.cno;
182 vp->m_final = vp->m_start;
183 } else
184 vp->m_final = vp->m_stop;
185 else {
186 if (ISMOTION(vp))
187 --vp->m_start.cno;
188 vp->m_final = vp->m_stop;
190 return (0);
194 * v_ncol -- [count]|
195 * Move to column count or the first column on this line. If the
196 * requested column is past EOL, move to EOL. The nasty part is
197 * that we have to know character column widths to make this work.
199 * PUBLIC: int v_ncol __P((SCR *, VICMD *));
202 v_ncol(SCR *sp, VICMD *vp)
204 if (F_ISSET(vp, VC_C1SET) && vp->count > 1) {
205 --vp->count;
206 vp->m_stop.cno =
207 vs_colpos(sp, vp->m_start.lno, (size_t)vp->count);
209 * !!!
210 * The | command succeeded if used as a command and the cursor
211 * didn't move, but failed if used as a motion component in the
212 * same situation.
214 if (ISMOTION(vp) && vp->m_stop.cno == vp->m_start.cno) {
215 v_nomove(sp);
216 return (1);
218 } else {
220 * !!!
221 * The | command succeeded if used as a command in column 0
222 * without a count, but failed if used as a motion component
223 * in the same situation.
225 if (ISMOTION(vp) && vp->m_start.cno == 0) {
226 v_sol(sp);
227 return (1);
229 vp->m_stop.cno = 0;
233 * If moving right, non-motion commands move to the end of the range.
234 * Delete and yank stay at the start. Motion commands adjust the
235 * ending point to the character before the current ending charcter.
237 * If moving left, all commands move to the end of the range. Motion
238 * commands adjust the starting point to the character before the
239 * current starting character.
241 if (vp->m_start.cno < vp->m_stop.cno)
242 if (ISMOTION(vp)) {
243 --vp->m_stop.cno;
244 vp->m_final = vp->m_start;
245 } else
246 vp->m_final = vp->m_stop;
247 else {
248 if (ISMOTION(vp))
249 --vp->m_start.cno;
250 vp->m_final = vp->m_stop;
252 return (0);
256 * v_zero -- 0
257 * Move to the first column on this line.
259 * PUBLIC: int v_zero __P((SCR *, VICMD *));
262 v_zero(SCR *sp, VICMD *vp)
265 * !!!
266 * The 0 command succeeded if used as a command in the first column
267 * but failed if used as a motion component in the same situation.
269 if (ISMOTION(vp) && vp->m_start.cno == 0) {
270 v_sol(sp);
271 return (1);
275 * All commands move to the end of the range. Motion commands
276 * adjust the starting point to the character before the current
277 * one.
279 vp->m_stop.cno = 0;
280 if (ISMOTION(vp))
281 --vp->m_start.cno;
282 vp->m_final = vp->m_stop;
283 return (0);