⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 v_text.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/*- * Copyright (c) 1992, 1993, 1994 *	The Regents of the University of California.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by the University of *	California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors *    may be used to endorse or promote products derived from this software *    without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */#ifndef lintstatic char sccsid[] = "@(#)v_text.c	8.33 (Berkeley) 4/13/94";#endif /* not lint */#include <sys/types.h>#include <sys/queue.h>#include <sys/time.h>#include <bitstring.h>#include <ctype.h>#include <errno.h>#include <limits.h>#include <signal.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <termios.h>#include "compat.h"#include <db.h>#include <regex.h>#include "vi.h"#include "vcmd.h"/* * !!! * Repeated input in the historic vi is mostly wrong and this isn't very * backward compatible.  For example, if the user entered "3Aab\ncd" in * the historic vi, the "ab" was repeated 3 times, and the "\ncd" was then * appended to the result.  There was also a hack which I don't remember * right now, where "3o" would open 3 lines and then let the user fill them * in, to make screen movements on 300 baud modems more tolerable.  I don't * think it's going to be missed. * * !!! * There's a problem with the way that we do logging for change commands with * implied motions (e.g. A, I, O, cc, etc.).  Since the main vi loop logs the * starting cursor position before the change command "moves" the cursor, the * cursor position to which we return on undo will be where the user entered * the change command, not the start of the change.  Several of the following * routines re-log the cursor to make this work correctly.  Historic vi tried * to do the same thing, and mostly got it right.  (The only spectacular way * it fails is if the user entered 'o' from anywhere but the last character of * the line, the undo returned the cursor to the start of the line.  If the * user was on the last character of the line, the cursor returned to that * position.)  We also check for mapped keys waiting, i.e. if we're in the * middle of a map, don't bother logging the cursor. */#define	LOG_CORRECT {							\	if (!MAPPED_KEYS_WAITING(sp))					\		(void)log_cursor(sp, ep);				\}#define	LOG_CORRECT_FIRST {						\	if (first == 1) {						\		LOG_CORRECT;						\		first = 0;						\	}								\}static u_int	set_txt_std __P((SCR *, VICMDARG *, u_int));static int	v_CS __P((SCR *, EXF *, VICMDARG *, u_int));/* * v_iA -- [count]A *	Append text to the end of the line. */intv_iA(sp, ep, vp)	SCR *sp;	EXF *ep;	VICMDARG *vp;{	recno_t lno;	u_long cnt;	size_t len;	u_int flags;	int first;	char *p;	flags = set_txt_std(sp, vp, TXT_APPENDEOL);	for (first = 1, lno = vp->m_start.lno,	    cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {		/* Move the cursor to the end of the line + 1. */		if ((p = file_gline(sp, ep, lno, &len)) == NULL) {			if (file_lline(sp, ep, &lno))				return (1);			if (lno != 0) {				GETLINE_ERR(sp, lno);				return (1);			}			lno = 1;			len = 0;		} else {			/* Correct logging for implied cursor motion. */			if (first == 1) {				sp->cno = len == 0 ? 0 : len - 1;				LOG_CORRECT;				first = 0;			}			/* Start the change after the line. */			sp->cno = len;		}		if (v_ntext(sp, ep,		    sp->tiqp, NULL, p, len, &vp->m_final, 0, OOBLNO, flags))			return (1);		flags = set_txt_std(sp, vp, TXT_APPENDEOL | TXT_REPLAY);		sp->lno = lno = vp->m_final.lno;		sp->cno = vp->m_final.cno;		if (F_ISSET(sp, S_INTERRUPTED))			break;	}	return (0);}/* * v_ia -- [count]a *	Append text to the cursor position. */intv_ia(sp, ep, vp)	SCR *sp;	EXF *ep;	VICMDARG *vp;{	recno_t lno;	u_long cnt;	u_int flags;	size_t len;	char *p;	flags = set_txt_std(sp, vp, 0);	for (lno = vp->m_start.lno,	    cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {		/*		 * Move the cursor one column to the right and		 * repaint the screen.		 */		if ((p = file_gline(sp, ep, lno, &len)) == NULL) {			if (file_lline(sp, ep, &lno))				return (1);			if (lno != 0) {				GETLINE_ERR(sp, lno);				return (1);			}			lno = 1;			len = 0;			LF_SET(TXT_APPENDEOL);		} else if (len) {			if (len == sp->cno + 1) {				sp->cno = len;				LF_SET(TXT_APPENDEOL);			} else				++sp->cno;		} else			LF_SET(TXT_APPENDEOL);		if (v_ntext(sp, ep,		    sp->tiqp, NULL, p, len, &vp->m_final, 0, OOBLNO, flags))			return (1);		flags = set_txt_std(sp, vp, TXT_REPLAY);		sp->lno = lno = vp->m_final.lno;		sp->cno = vp->m_final.cno;		if (F_ISSET(sp, S_INTERRUPTED))			break;	}	return (0);}/* * v_iI -- [count]I *	Insert text at the first non-blank character in the line. */intv_iI(sp, ep, vp)	SCR *sp;	EXF *ep;	VICMDARG *vp;{	recno_t lno;	u_long cnt;	size_t len;	u_int flags;	int first;	char *p;	flags = set_txt_std(sp, vp, 0);	for (first = 1, lno = vp->m_start.lno,	    cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {		/*		 * Move the cursor to the start of the line and repaint		 * the screen.		 */		if ((p = file_gline(sp, ep, lno, &len)) == NULL) {			if (file_lline(sp, ep, &lno))				return (1);			if (lno != 0) {				GETLINE_ERR(sp, lno);				return (1);			}			lno = 1;			len = 0;		} else {			sp->cno = 0;			if (nonblank(sp, ep, lno, &sp->cno))				return (1);			/* Correct logging for implied cursor motion. */			LOG_CORRECT_FIRST;		}		if (len == 0)			LF_SET(TXT_APPENDEOL);		if (v_ntext(sp, ep,		    sp->tiqp, NULL, p, len, &vp->m_final, 0, OOBLNO, flags))			return (1);		flags = set_txt_std(sp, vp, TXT_REPLAY);		sp->lno = lno = vp->m_final.lno;		sp->cno = vp->m_final.cno;		if (F_ISSET(sp, S_INTERRUPTED))			break;	}	return (0);}/* * v_ii -- [count]i *	Insert text at the cursor position. */intv_ii(sp, ep, vp)	SCR *sp;	EXF *ep;	VICMDARG *vp;{	recno_t lno;	u_long cnt;	size_t len;	u_int flags;	char *p;	flags = set_txt_std(sp, vp, 0);	for (lno = vp->m_start.lno,	    cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {		if ((p = file_gline(sp, ep, lno, &len)) == NULL) {			if (file_lline(sp, ep, &lno))				return (1);			if (lno != 0) {				GETLINE_ERR(sp, vp->m_start.lno);				return (1);			}			lno = 1;			len = 0;		}		/* If len == sp->cno, it's a replay caused by a count. */		if (len == 0 || len == sp->cno)			LF_SET(TXT_APPENDEOL);		if (v_ntext(sp, ep,		    sp->tiqp, NULL, p, len, &vp->m_final, 0, OOBLNO, flags))			return (1);		/*		 * On replay, if the line isn't empty, advance the insert		 * by one (make it an append).		 */		flags = set_txt_std(sp, vp, TXT_REPLAY);		sp->lno = lno = vp->m_final.lno;		if ((sp->cno = vp->m_final.cno) != 0)			++sp->cno;		if (F_ISSET(sp, S_INTERRUPTED))			break;	}	return (0);}/* * v_iO -- [count]O *	Insert text above this line. */intv_iO(sp, ep, vp)	SCR *sp;	EXF *ep;	VICMDARG *vp;{	recno_t ai_line, lno;	size_t len;	u_long cnt;	u_int flags;	int first;	char *p;	flags = set_txt_std(sp, vp, TXT_APPENDEOL);	for (first = 1, cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {		if (sp->lno == 1) {			if (file_lline(sp, ep, &lno))				return (1);			if (lno != 0)				goto insert;			p = NULL;			len = 0;			ai_line = OOBLNO;		} else {insert:			p = "";			sp->cno = 0;			/* Correct logging for implied cursor motion. */			LOG_CORRECT_FIRST;			if (file_iline(sp, ep, sp->lno, p, 0))				return (1);			if ((p = file_gline(sp, ep, sp->lno, &len)) == NULL) {				GETLINE_ERR(sp, sp->lno);				return (1);			}			ai_line = sp->lno + 1;		}		if (v_ntext(sp, ep,		    sp->tiqp, NULL, p, len, &vp->m_final, 0, ai_line, flags))			return (1);		flags = set_txt_std(sp, vp, TXT_APPENDEOL | TXT_REPLAY);		sp->lno = lno = vp->m_final.lno;		sp->cno = vp->m_final.cno;		if (F_ISSET(sp, S_INTERRUPTED))			break;	}	return (0);}/* * v_io -- [count]o *	Insert text after this line. */intv_io(sp, ep, vp)	SCR *sp;	EXF *ep;	VICMDARG *vp;{	recno_t ai_line, lno;	size_t len;	u_long cnt;	u_int flags;	int first;	char *p;	flags = set_txt_std(sp, vp, TXT_APPENDEOL);	for (first = 1,	    cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {		if (sp->lno == 1) {			if (file_lline(sp, ep, &lno))				return (1);			if (lno != 0)				goto insert;			p = NULL;			len = 0;			ai_line = OOBLNO;		} else {insert:			p = "";			sp->cno = 0;			/* Correct logging for implied cursor motion. */			LOG_CORRECT_FIRST;			len = 0;			if (file_aline(sp, ep, 1, sp->lno, p, len))				return (1);			if ((p = file_gline(sp, ep, ++sp->lno, &len)) == NULL) {				GETLINE_ERR(sp, sp->lno);				return (1);			}			ai_line = sp->lno - 1;		}		if (v_ntext(sp, ep,		    sp->tiqp, NULL, p, len, &vp->m_final, 0, ai_line, flags))			return (1);		flags = set_txt_std(sp, vp, TXT_APPENDEOL | TXT_REPLAY);		sp->lno = lno = vp->m_final.lno;		sp->cno = vp->m_final.cno;		if (F_ISSET(sp, S_INTERRUPTED))			break;	}	return (0);}/* * v_Change -- [buffer][count]C

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -