v_xchar.c revision 1.3 1 1.3 christos /* $NetBSD: v_xchar.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
2 1.1 christos /*-
3 1.1 christos * Copyright (c) 1992, 1993, 1994
4 1.1 christos * The Regents of the University of California. All rights reserved.
5 1.1 christos * Copyright (c) 1992, 1993, 1994, 1995, 1996
6 1.1 christos * Keith Bostic. All rights reserved.
7 1.1 christos *
8 1.1 christos * See the LICENSE file for redistribution information.
9 1.1 christos */
10 1.1 christos
11 1.1 christos #include "config.h"
12 1.1 christos
13 1.3 christos #include <sys/cdefs.h>
14 1.3 christos #if 0
15 1.1 christos #ifndef lint
16 1.1 christos 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 1.1 christos #endif /* not lint */
18 1.3 christos #else
19 1.3 christos __RCSID("$NetBSD: v_xchar.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
20 1.3 christos #endif
21 1.1 christos
22 1.1 christos #include <sys/types.h>
23 1.1 christos #include <sys/queue.h>
24 1.1 christos #include <sys/time.h>
25 1.1 christos
26 1.1 christos #include <bitstring.h>
27 1.1 christos #include <limits.h>
28 1.1 christos #include <stdio.h>
29 1.1 christos
30 1.1 christos #include "../common/common.h"
31 1.1 christos #include "vi.h"
32 1.1 christos
33 1.1 christos /*
34 1.1 christos * v_xchar -- [buffer] [count]x
35 1.1 christos * Deletes the character(s) on which the cursor sits.
36 1.1 christos *
37 1.1 christos * PUBLIC: int v_xchar __P((SCR *, VICMD *));
38 1.1 christos */
39 1.1 christos int
40 1.1 christos v_xchar(SCR *sp, VICMD *vp)
41 1.1 christos {
42 1.1 christos size_t len;
43 1.1 christos int isempty;
44 1.1 christos
45 1.1 christos if (db_eget(sp, vp->m_start.lno, NULL, &len, &isempty)) {
46 1.1 christos if (isempty)
47 1.1 christos goto nodel;
48 1.1 christos return (1);
49 1.1 christos }
50 1.1 christos if (len == 0) {
51 1.1 christos nodel: msgq(sp, M_BERR, "206|No characters to delete");
52 1.1 christos return (1);
53 1.1 christos }
54 1.1 christos
55 1.1 christos /*
56 1.1 christos * Delete from the cursor toward the end of line, w/o moving the
57 1.1 christos * cursor.
58 1.1 christos *
59 1.1 christos * !!!
60 1.1 christos * Note, "2x" at EOL isn't the same as "xx" because the left movement
61 1.1 christos * of the cursor as part of the 'x' command isn't taken into account.
62 1.1 christos * Historically correct.
63 1.1 christos */
64 1.1 christos if (F_ISSET(vp, VC_C1SET))
65 1.1 christos vp->m_stop.cno += vp->count - 1;
66 1.1 christos if (vp->m_stop.cno >= len - 1) {
67 1.1 christos vp->m_stop.cno = len - 1;
68 1.1 christos vp->m_final.cno = vp->m_start.cno ? vp->m_start.cno - 1 : 0;
69 1.1 christos } else
70 1.1 christos vp->m_final.cno = vp->m_start.cno;
71 1.1 christos
72 1.1 christos if (cut(sp,
73 1.1 christos F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
74 1.1 christos &vp->m_start, &vp->m_stop, 0))
75 1.1 christos return (1);
76 1.1 christos return (del(sp, &vp->m_start, &vp->m_stop, 0));
77 1.1 christos }
78 1.1 christos
79 1.1 christos /*
80 1.1 christos * v_Xchar -- [buffer] [count]X
81 1.1 christos * Deletes the character(s) immediately before the current cursor
82 1.1 christos * position.
83 1.1 christos *
84 1.1 christos * PUBLIC: int v_Xchar __P((SCR *, VICMD *));
85 1.1 christos */
86 1.1 christos int
87 1.1 christos v_Xchar(SCR *sp, VICMD *vp)
88 1.1 christos {
89 1.1 christos u_long cnt;
90 1.1 christos
91 1.1 christos if (vp->m_start.cno == 0) {
92 1.1 christos v_sol(sp);
93 1.1 christos return (1);
94 1.1 christos }
95 1.1 christos
96 1.1 christos cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
97 1.1 christos if (cnt >= vp->m_start.cno)
98 1.1 christos vp->m_start.cno = 0;
99 1.1 christos else
100 1.1 christos vp->m_start.cno -= cnt;
101 1.1 christos --vp->m_stop.cno;
102 1.1 christos vp->m_final.cno = vp->m_start.cno;
103 1.1 christos
104 1.1 christos if (cut(sp,
105 1.1 christos F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
106 1.1 christos &vp->m_start, &vp->m_stop, 0))
107 1.1 christos return (1);
108 1.1 christos return (del(sp, &vp->m_start, &vp->m_stop, 0));
109 1.1 christos }
110