ex/ex_display.c (ex_display): fix argument checking in case of wide characters
[nvi.git] / vi / v_xchar.c
blob072a8bdecda7a45edbba6b55e52188f7ae2f7f9a
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_xchar.c,v 10.10 2001/06/25 15:19:36 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19:36 $";
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_xchar -- [buffer] [count]x
29 * Deletes the character(s) on which the cursor sits.
31 * PUBLIC: int v_xchar __P((SCR *, VICMD *));
33 int
34 v_xchar(SCR *sp, VICMD *vp)
36 size_t len;
37 int isempty;
39 if (db_eget(sp, vp->m_start.lno, NULL, &len, &isempty)) {
40 if (isempty)
41 goto nodel;
42 return (1);
44 if (len == 0) {
45 nodel: msgq(sp, M_BERR, "206|No characters to delete");
46 return (1);
50 * Delete from the cursor toward the end of line, w/o moving the
51 * cursor.
53 * !!!
54 * Note, "2x" at EOL isn't the same as "xx" because the left movement
55 * of the cursor as part of the 'x' command isn't taken into account.
56 * Historically correct.
58 if (F_ISSET(vp, VC_C1SET))
59 vp->m_stop.cno += vp->count - 1;
60 if (vp->m_stop.cno >= len - 1) {
61 vp->m_stop.cno = len - 1;
62 vp->m_final.cno = vp->m_start.cno ? vp->m_start.cno - 1 : 0;
63 } else
64 vp->m_final.cno = vp->m_start.cno;
66 if (cut(sp,
67 F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
68 &vp->m_start, &vp->m_stop, 0))
69 return (1);
70 return (del(sp, &vp->m_start, &vp->m_stop, 0));
74 * v_Xchar -- [buffer] [count]X
75 * Deletes the character(s) immediately before the current cursor
76 * position.
78 * PUBLIC: int v_Xchar __P((SCR *, VICMD *));
80 int
81 v_Xchar(SCR *sp, VICMD *vp)
83 u_long cnt;
85 if (vp->m_start.cno == 0) {
86 v_sol(sp);
87 return (1);
90 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
91 if (cnt >= vp->m_start.cno)
92 vp->m_start.cno = 0;
93 else
94 vp->m_start.cno -= cnt;
95 --vp->m_stop.cno;
96 vp->m_final.cno = vp->m_start.cno;
98 if (cut(sp,
99 F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
100 &vp->m_start, &vp->m_stop, 0))
101 return (1);
102 return (del(sp, &vp->m_start, &vp->m_stop, 0));