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