ex/ex_display.c (ex_display): fix argument checking in case of wide characters
[nvi.git] / vi / v_delete.c
blobdba34d29badae77477a68d84a40ef120e5123025
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_delete.c,v 10.11 2001/06/25 15:19:31 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19:31 $";
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_delete -- [buffer][count]d[count]motion
29 * [buffer][count]D
30 * Delete a range of text.
32 * PUBLIC: int v_delete __P((SCR *, VICMD *));
34 int
35 v_delete(SCR *sp, VICMD *vp)
37 db_recno_t nlines;
38 size_t len;
39 int lmode;
41 lmode = F_ISSET(vp, VM_LMODE) ? CUT_LINEMODE : 0;
43 /* Yank the lines. */
44 if (cut(sp, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
45 &vp->m_start, &vp->m_stop,
46 lmode | (F_ISSET(vp, VM_CUTREQ) ? CUT_NUMREQ : CUT_NUMOPT)))
47 return (1);
49 /* Delete the lines. */
50 if (del(sp, &vp->m_start, &vp->m_stop, lmode))
51 return (1);
54 * Check for deletion of the entire file. Try to check a close
55 * by line so we don't go to the end of the file unnecessarily.
57 if (!db_exist(sp, vp->m_final.lno + 1)) {
58 if (db_last(sp, &nlines))
59 return (1);
60 if (nlines == 0) {
61 vp->m_final.lno = 1;
62 vp->m_final.cno = 0;
63 return (0);
68 * One special correction, in case we've deleted the current line or
69 * character. We check it here instead of checking in every command
70 * that can be a motion component.
72 if (db_get(sp, vp->m_final.lno, 0, NULL, &len)) {
73 if (db_get(sp, nlines, DBG_FATAL, NULL, &len))
74 return (1);
75 vp->m_final.lno = nlines;
79 * !!!
80 * Cursor movements, other than those caused by a line mode command
81 * moving to another line, historically reset the relative position.
83 * This currently matches the check made in v_yank(), I'm hoping that
84 * they should be consistent...
85 */
86 if (!F_ISSET(vp, VM_LMODE)) {
87 F_CLR(vp, VM_RCM_MASK);
88 F_SET(vp, VM_RCM_SET);
90 /* Make sure the set cursor position exists. */
91 if (vp->m_final.cno >= len)
92 vp->m_final.cno = len ? len - 1 : 0;
96 * !!!
97 * The "dd" command moved to the first non-blank; "d<motion>"
98 * didn't.
100 if (F_ISSET(vp, VM_LDOUBLE)) {
101 F_CLR(vp, VM_RCM_MASK);
102 F_SET(vp, VM_RCM_SETFNB);
104 return (0);