configure.in: check for sys/stropts.h header instead of grantpt function
[nvi.git] / ex / ex_delete.c
blobe1527ab9284b35da1bc81b07cfaa40267df22ca3
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: ex_delete.c,v 10.11 2001/06/25 15:19:15 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19:15 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <bitstring.h>
20 #include <limits.h>
21 #include <stdio.h>
23 #include "../common/common.h"
26 * ex_delete: [line [,line]] d[elete] [buffer] [count] [flags]
28 * Delete lines from the file.
30 * PUBLIC: int ex_delete __P((SCR *, EXCMD *));
32 int
33 ex_delete(SCR *sp, EXCMD *cmdp)
35 db_recno_t lno;
37 NEEDFILE(sp, cmdp);
40 * !!!
41 * Historically, lines deleted in ex were not placed in the numeric
42 * buffers. We follow historic practice so that we don't overwrite
43 * vi buffers accidentally.
45 if (cut(sp,
46 FL_ISSET(cmdp->iflags, E_C_BUFFER) ? &cmdp->buffer : NULL,
47 &cmdp->addr1, &cmdp->addr2, CUT_LINEMODE))
48 return (1);
50 /* Delete the lines. */
51 if (del(sp, &cmdp->addr1, &cmdp->addr2, 1))
52 return (1);
54 /* Set the cursor to the line after the last line deleted. */
55 sp->lno = cmdp->addr1.lno;
57 /* Or the last line in the file if deleted to the end of the file. */
58 if (db_last(sp, &lno))
59 return (1);
60 if (sp->lno > lno)
61 sp->lno = lno;
62 return (0);