tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / nvi / dist / vi / v_xchar.c
blob0813ea213acb9bc9af3982dafe770244d09d5971
1 /* $NetBSD: v_xchar.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_xchar.c,v 10.10 2001/06/25 15:19:36 skimo Exp (Berkeley) Date: 2001/06/25 15:19:36 ";
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_xchar -- [buffer] [count]x
30 * Deletes the character(s) on which the cursor sits.
32 * PUBLIC: int v_xchar __P((SCR *, VICMD *));
34 int
35 v_xchar(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 nodel;
43 return (1);
45 if (len == 0) {
46 nodel: msgq(sp, M_BERR, "206|No characters to delete");
47 return (1);
51 * Delete from the cursor toward the end of line, w/o moving the
52 * cursor.
54 * !!!
55 * Note, "2x" at EOL isn't the same as "xx" because the left movement
56 * of the cursor as part of the 'x' command isn't taken into account.
57 * Historically correct.
59 if (F_ISSET(vp, VC_C1SET))
60 vp->m_stop.cno += vp->count - 1;
61 if (vp->m_stop.cno >= len - 1) {
62 vp->m_stop.cno = len - 1;
63 vp->m_final.cno = vp->m_start.cno ? vp->m_start.cno - 1 : 0;
64 } else
65 vp->m_final.cno = vp->m_start.cno;
67 if (cut(sp,
68 F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
69 &vp->m_start, &vp->m_stop, 0))
70 return (1);
71 return (del(sp, &vp->m_start, &vp->m_stop, 0));
75 * v_Xchar -- [buffer] [count]X
76 * Deletes the character(s) immediately before the current cursor
77 * position.
79 * PUBLIC: int v_Xchar __P((SCR *, VICMD *));
81 int
82 v_Xchar(SCR *sp, VICMD *vp)
84 u_long cnt;
86 if (vp->m_start.cno == 0) {
87 v_sol(sp);
88 return (1);
91 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
92 if (cnt >= vp->m_start.cno)
93 vp->m_start.cno = 0;
94 else
95 vp->m_start.cno -= cnt;
96 --vp->m_stop.cno;
97 vp->m_final.cno = vp->m_start.cno;
99 if (cut(sp,
100 F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
101 &vp->m_start, &vp->m_stop, 0))
102 return (1);
103 return (del(sp, &vp->m_start, &vp->m_stop, 0));