Remove building with NOCRYPTO option
[minix.git] / external / bsd / nvi / dist / vi / v_xchar.c
blobd8b83d4e068999deebe54cdb1d6f40a2c2fd668f
1 /* $NetBSD: v_xchar.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_xchar.c,v 10.10 2001/06/25 15:19:36 skimo Exp (Berkeley) Date: 2001/06/25 15:19:36 ";
17 #endif /* not lint */
18 #else
19 __RCSID("$NetBSD: v_xchar.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_xchar -- [buffer] [count]x
35 * Deletes the character(s) on which the cursor sits.
37 * PUBLIC: int v_xchar __P((SCR *, VICMD *));
39 int
40 v_xchar(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 nodel;
48 return (1);
50 if (len == 0) {
51 nodel: msgq(sp, M_BERR, "206|No characters to delete");
52 return (1);
56 * Delete from the cursor toward the end of line, w/o moving the
57 * cursor.
59 * !!!
60 * Note, "2x" at EOL isn't the same as "xx" because the left movement
61 * of the cursor as part of the 'x' command isn't taken into account.
62 * Historically correct.
64 if (F_ISSET(vp, VC_C1SET))
65 vp->m_stop.cno += vp->count - 1;
66 if (vp->m_stop.cno >= len - 1) {
67 vp->m_stop.cno = len - 1;
68 vp->m_final.cno = vp->m_start.cno ? vp->m_start.cno - 1 : 0;
69 } else
70 vp->m_final.cno = vp->m_start.cno;
72 if (cut(sp,
73 F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
74 &vp->m_start, &vp->m_stop, 0))
75 return (1);
76 return (del(sp, &vp->m_start, &vp->m_stop, 0));
80 * v_Xchar -- [buffer] [count]X
81 * Deletes the character(s) immediately before the current cursor
82 * position.
84 * PUBLIC: int v_Xchar __P((SCR *, VICMD *));
86 int
87 v_Xchar(SCR *sp, VICMD *vp)
89 u_long cnt;
91 if (vp->m_start.cno == 0) {
92 v_sol(sp);
93 return (1);
96 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
97 if (cnt >= vp->m_start.cno)
98 vp->m_start.cno = 0;
99 else
100 vp->m_start.cno -= cnt;
101 --vp->m_stop.cno;
102 vp->m_final.cno = vp->m_start.cno;
104 if (cut(sp,
105 F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
106 &vp->m_start, &vp->m_stop, 0))
107 return (1);
108 return (del(sp, &vp->m_start, &vp->m_stop, 0));