ex_delete.c revision 1.5
1/* $OpenBSD: ex_delete.c,v 1.5 2002/02/16 21:27:57 millert Exp $ */ 2 3/*- 4 * Copyright (c) 1992, 1993, 1994 5 * The Regents of the University of California. All rights reserved. 6 * Copyright (c) 1992, 1993, 1994, 1995, 1996 7 * Keith Bostic. All rights reserved. 8 * 9 * See the LICENSE file for redistribution information. 10 */ 11 12#include "config.h" 13 14#ifndef lint 15static const char sccsid[] = "@(#)ex_delete.c 10.9 (Berkeley) 10/23/96"; 16#endif /* not lint */ 17 18#include <sys/types.h> 19#include <sys/queue.h> 20 21#include <bitstring.h> 22#include <limits.h> 23#include <stdio.h> 24 25#include "../common/common.h" 26 27/* 28 * ex_delete: [line [,line]] d[elete] [buffer] [count] [flags] 29 * 30 * Delete lines from the file. 31 * 32 * PUBLIC: int ex_delete(SCR *, EXCMD *); 33 */ 34int 35ex_delete(sp, cmdp) 36 SCR *sp; 37 EXCMD *cmdp; 38{ 39 recno_t lno; 40 41 NEEDFILE(sp, cmdp); 42 43 /* 44 * !!! 45 * Historically, lines deleted in ex were not placed in the numeric 46 * buffers. We follow historic practice so that we don't overwrite 47 * vi buffers accidentally. 48 */ 49 if (cut(sp, 50 FL_ISSET(cmdp->iflags, E_C_BUFFER) ? &cmdp->buffer : NULL, 51 &cmdp->addr1, &cmdp->addr2, CUT_LINEMODE)) 52 return (1); 53 54 /* Delete the lines. */ 55 if (del(sp, &cmdp->addr1, &cmdp->addr2, 1)) 56 return (1); 57 58 /* Set the cursor to the line after the last line deleted. */ 59 sp->lno = cmdp->addr1.lno; 60 61 /* Or the last line in the file if deleted to the end of the file. */ 62 if (db_last(sp, &lno)) 63 return (1); 64 if (sp->lno > lno) 65 sp->lno = lno; 66 return (0); 67} 68