1 /* $NetBSD: ex_delete.c,v 1.2 2013/11/22 15:52:05 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. 7 * 8 * See the LICENSE file for redistribution information. 9 */ 10 11 #include "config.h" 12 13 #ifndef lint 14 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 "; 15 #endif /* not lint */ 16 17 #include <sys/types.h> 18 #include <sys/queue.h> 19 20 #include <bitstring.h> 21 #include <limits.h> 22 #include <stdio.h> 23 24 #include "../common/common.h" 25 26 /* 27 * ex_delete: [line [,line]] d[elete] [buffer] [count] [flags] 28 * 29 * Delete lines from the file. 30 * 31 * PUBLIC: int ex_delete __P((SCR *, EXCMD *)); 32 */ 33 int 34 ex_delete(SCR *sp, EXCMD *cmdp) 35 { 36 db_recno_t lno; 37 38 NEEDFILE(sp, cmdp); 39 40 /* 41 * !!! 42 * Historically, lines deleted in ex were not placed in the numeric 43 * buffers. We follow historic practice so that we don't overwrite 44 * vi buffers accidentally. 45 */ 46 if (cut(sp, 47 FL_ISSET(cmdp->iflags, E_C_BUFFER) ? &cmdp->buffer : NULL, 48 &cmdp->addr1, &cmdp->addr2, CUT_LINEMODE)) 49 return (1); 50 51 /* Delete the lines. */ 52 if (del(sp, &cmdp->addr1, &cmdp->addr2, 1)) 53 return (1); 54 55 /* Set the cursor to the line after the last line deleted. */ 56 sp->lno = cmdp->addr1.lno; 57 58 /* Or the last line in the file if deleted to the end of the file. */ 59 if (db_last(sp, &lno)) 60 return (1); 61 if (sp->lno > lno) 62 sp->lno = lno; 63 return (0); 64 } 65