Home | History | Annotate | Line # | Download | only in vi
v_xchar.c revision 1.1
      1  1.1  christos /*-
      2  1.1  christos  * Copyright (c) 1992, 1993, 1994
      3  1.1  christos  *	The Regents of the University of California.  All rights reserved.
      4  1.1  christos  * Copyright (c) 1992, 1993, 1994, 1995, 1996
      5  1.1  christos  *	Keith Bostic.  All rights reserved.
      6  1.1  christos  *
      7  1.1  christos  * See the LICENSE file for redistribution information.
      8  1.1  christos  */
      9  1.1  christos 
     10  1.1  christos #include "config.h"
     11  1.1  christos 
     12  1.1  christos #ifndef lint
     13  1.1  christos static const char sccsid[] = "Id: v_xchar.c,v 10.10 2001/06/25 15:19:36 skimo Exp  (Berkeley) Date: 2001/06/25 15:19:36 ";
     14  1.1  christos #endif /* not lint */
     15  1.1  christos 
     16  1.1  christos #include <sys/types.h>
     17  1.1  christos #include <sys/queue.h>
     18  1.1  christos #include <sys/time.h>
     19  1.1  christos 
     20  1.1  christos #include <bitstring.h>
     21  1.1  christos #include <limits.h>
     22  1.1  christos #include <stdio.h>
     23  1.1  christos 
     24  1.1  christos #include "../common/common.h"
     25  1.1  christos #include "vi.h"
     26  1.1  christos 
     27  1.1  christos /*
     28  1.1  christos  * v_xchar -- [buffer] [count]x
     29  1.1  christos  *	Deletes the character(s) on which the cursor sits.
     30  1.1  christos  *
     31  1.1  christos  * PUBLIC: int v_xchar __P((SCR *, VICMD *));
     32  1.1  christos  */
     33  1.1  christos int
     34  1.1  christos v_xchar(SCR *sp, VICMD *vp)
     35  1.1  christos {
     36  1.1  christos 	size_t len;
     37  1.1  christos 	int isempty;
     38  1.1  christos 
     39  1.1  christos 	if (db_eget(sp, vp->m_start.lno, NULL, &len, &isempty)) {
     40  1.1  christos 		if (isempty)
     41  1.1  christos 			goto nodel;
     42  1.1  christos 		return (1);
     43  1.1  christos 	}
     44  1.1  christos 	if (len == 0) {
     45  1.1  christos nodel:		msgq(sp, M_BERR, "206|No characters to delete");
     46  1.1  christos 		return (1);
     47  1.1  christos 	}
     48  1.1  christos 
     49  1.1  christos 	/*
     50  1.1  christos 	 * Delete from the cursor toward the end of line, w/o moving the
     51  1.1  christos 	 * cursor.
     52  1.1  christos 	 *
     53  1.1  christos 	 * !!!
     54  1.1  christos 	 * Note, "2x" at EOL isn't the same as "xx" because the left movement
     55  1.1  christos 	 * of the cursor as part of the 'x' command isn't taken into account.
     56  1.1  christos 	 * Historically correct.
     57  1.1  christos 	 */
     58  1.1  christos 	if (F_ISSET(vp, VC_C1SET))
     59  1.1  christos 		vp->m_stop.cno += vp->count - 1;
     60  1.1  christos 	if (vp->m_stop.cno >= len - 1) {
     61  1.1  christos 		vp->m_stop.cno = len - 1;
     62  1.1  christos 		vp->m_final.cno = vp->m_start.cno ? vp->m_start.cno - 1 : 0;
     63  1.1  christos 	} else
     64  1.1  christos 		vp->m_final.cno = vp->m_start.cno;
     65  1.1  christos 
     66  1.1  christos 	if (cut(sp,
     67  1.1  christos 	    F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
     68  1.1  christos 	    &vp->m_start, &vp->m_stop, 0))
     69  1.1  christos 		return (1);
     70  1.1  christos 	return (del(sp, &vp->m_start, &vp->m_stop, 0));
     71  1.1  christos }
     72  1.1  christos 
     73  1.1  christos /*
     74  1.1  christos  * v_Xchar -- [buffer] [count]X
     75  1.1  christos  *	Deletes the character(s) immediately before the current cursor
     76  1.1  christos  *	position.
     77  1.1  christos  *
     78  1.1  christos  * PUBLIC: int v_Xchar __P((SCR *, VICMD *));
     79  1.1  christos  */
     80  1.1  christos int
     81  1.1  christos v_Xchar(SCR *sp, VICMD *vp)
     82  1.1  christos {
     83  1.1  christos 	u_long cnt;
     84  1.1  christos 
     85  1.1  christos 	if (vp->m_start.cno == 0) {
     86  1.1  christos 		v_sol(sp);
     87  1.1  christos 		return (1);
     88  1.1  christos 	}
     89  1.1  christos 
     90  1.1  christos 	cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
     91  1.1  christos 	if (cnt >= vp->m_start.cno)
     92  1.1  christos 		vp->m_start.cno = 0;
     93  1.1  christos 	else
     94  1.1  christos 		vp->m_start.cno -= cnt;
     95  1.1  christos 	--vp->m_stop.cno;
     96  1.1  christos 	vp->m_final.cno = vp->m_start.cno;
     97  1.1  christos 
     98  1.1  christos 	if (cut(sp,
     99  1.1  christos 	    F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
    100  1.1  christos 	    &vp->m_start, &vp->m_stop, 0))
    101  1.1  christos 		return (1);
    102  1.1  christos 	return (del(sp, &vp->m_start, &vp->m_stop, 0));
    103  1.1  christos }
    104