xref: /illumos-gate/usr/src/cmd/vi/port/ex_vops.c (revision 55fea89d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5bbfd0aa6Scf  * Common Development and Distribution License (the "License").
6bbfd0aa6Scf  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2123a1cceaSRoger A. Faulkner 
227c478bd9Sstevel@tonic-gate /*
2323a1cceaSRoger A. Faulkner  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /* Copyright (c) 1981 Regents of the University of California */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include "ex.h"
337c478bd9Sstevel@tonic-gate #include "ex_tty.h"
347c478bd9Sstevel@tonic-gate #include "ex_vis.h"
357c478bd9Sstevel@tonic-gate 
36bbfd0aa6Scf void fixundo(void);
37bbfd0aa6Scf 
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate  * This file defines the operation sequences which interface the
407c478bd9Sstevel@tonic-gate  * logical changes to the file buffer with the internal and external
417c478bd9Sstevel@tonic-gate  * display representations.
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * Undo.
467c478bd9Sstevel@tonic-gate  *
477c478bd9Sstevel@tonic-gate  * Undo is accomplished in two ways.  We often for small changes in the
487c478bd9Sstevel@tonic-gate  * current line know how (in terms of a change operator) how the change
497c478bd9Sstevel@tonic-gate  * occurred.  Thus on an intelligent terminal we can undo the operation
507c478bd9Sstevel@tonic-gate  * by another such operation, using insert and delete character
517c478bd9Sstevel@tonic-gate  * stuff.  The pointers vU[AD][12] index the buffer vutmp when this
527c478bd9Sstevel@tonic-gate  * is possible and provide the necessary information.
537c478bd9Sstevel@tonic-gate  *
547c478bd9Sstevel@tonic-gate  * The other case is that the change involved multiple lines or that
557c478bd9Sstevel@tonic-gate  * we have moved away from the line or forgotten how the change was
567c478bd9Sstevel@tonic-gate  * accomplished.  In this case we do a redisplay and hope that the
577c478bd9Sstevel@tonic-gate  * low level optimization routines (which don't look for winning
587c478bd9Sstevel@tonic-gate  * via insert/delete character) will not lose too badly.
597c478bd9Sstevel@tonic-gate  */
607c478bd9Sstevel@tonic-gate unsigned char	*vUA1, *vUA2;
617c478bd9Sstevel@tonic-gate unsigned char	*vUD1, *vUD2;
627c478bd9Sstevel@tonic-gate 
63f6db9f27Scf void
vUndo(void)64f6db9f27Scf vUndo(void)
657c478bd9Sstevel@tonic-gate {
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 	/*
687c478bd9Sstevel@tonic-gate 	 * Avoid UU which clobbers ability to do u.
697c478bd9Sstevel@tonic-gate 	 */
707c478bd9Sstevel@tonic-gate 	if (vundkind == VNONE || vundkind == VCAPU || vUNDdot != dot) {
71f6db9f27Scf 		(void) beep();
727c478bd9Sstevel@tonic-gate 		return;
737c478bd9Sstevel@tonic-gate 	}
747c478bd9Sstevel@tonic-gate 	CP(vutmp, linebuf);
757c478bd9Sstevel@tonic-gate 	vUD1 = linebuf; vUD2 = strend(linebuf);
767c478bd9Sstevel@tonic-gate 	putmk1(dot, vUNDsav);
777c478bd9Sstevel@tonic-gate 	getDOT();
787c478bd9Sstevel@tonic-gate 	vUA1 = linebuf; vUA2 = strend(linebuf);
797c478bd9Sstevel@tonic-gate 	vundkind = VCAPU;
807c478bd9Sstevel@tonic-gate 	if (state == ONEOPEN || state == HARDOPEN) {
817c478bd9Sstevel@tonic-gate 		vjumpto(dot, vUNDcurs, 0);
827c478bd9Sstevel@tonic-gate 		return;
837c478bd9Sstevel@tonic-gate 	}
847c478bd9Sstevel@tonic-gate 	vdirty(vcline, 1);
857c478bd9Sstevel@tonic-gate 	if(MB_CUR_MAX > 1)
867c478bd9Sstevel@tonic-gate 		rewrite = _ON;
877c478bd9Sstevel@tonic-gate 	vsyncCL();
887c478bd9Sstevel@tonic-gate 	if(MB_CUR_MAX > 1)
897c478bd9Sstevel@tonic-gate 		rewrite = _OFF;
907c478bd9Sstevel@tonic-gate 	cursor = linebuf;
917c478bd9Sstevel@tonic-gate 	vfixcurs();
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate 
94f6db9f27Scf void
vundo(show)957c478bd9Sstevel@tonic-gate vundo(show)
967c478bd9Sstevel@tonic-gate bool show;	/* if true update the screen */
977c478bd9Sstevel@tonic-gate {
98f6db9f27Scf 	int cnt;
99f6db9f27Scf 	line *addr;
100f6db9f27Scf 	unsigned char *cp;
1017c478bd9Sstevel@tonic-gate 	unsigned char temp[LBSIZE];
1027c478bd9Sstevel@tonic-gate 	bool savenote;
1037c478bd9Sstevel@tonic-gate 	int (*OO)();
1047c478bd9Sstevel@tonic-gate 	short oldhold = hold;
1057c478bd9Sstevel@tonic-gate 	unsigned multic[MULTI_BYTE_MAX];
1067c478bd9Sstevel@tonic-gate 	int length;
1077c478bd9Sstevel@tonic-gate 	wchar_t wchar;
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	switch (vundkind) {
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 	case VMANYINS:
1127c478bd9Sstevel@tonic-gate 		wcursor = 0;
1137c478bd9Sstevel@tonic-gate 		addr1 = undap1;
1147c478bd9Sstevel@tonic-gate 		addr2 = undap2 - 1;
1157c478bd9Sstevel@tonic-gate 		vsave();
116f6db9f27Scf 		(void) YANKreg('1');
1177c478bd9Sstevel@tonic-gate 		notecnt = 0;
1189097ca5cSToomas Soome 		/* FALLTHROUGH */
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 	case VMANY:
1217c478bd9Sstevel@tonic-gate 	case VMCHNG:
1227c478bd9Sstevel@tonic-gate 		vsave();
1237c478bd9Sstevel@tonic-gate 		addr = dot - vcline;
1247c478bd9Sstevel@tonic-gate 		notecnt = 1;
1257c478bd9Sstevel@tonic-gate 		if (undkind == UNDPUT && undap1 == undap2) {
126f6db9f27Scf 			(void) beep();
1277c478bd9Sstevel@tonic-gate 			break;
1287c478bd9Sstevel@tonic-gate 		}
1297c478bd9Sstevel@tonic-gate 		/*
1307c478bd9Sstevel@tonic-gate 		 * Undo() call below basically replaces undap1 to undap2-1
1317c478bd9Sstevel@tonic-gate 		 * with dol through unddol-1.  Hack screen image to
1327c478bd9Sstevel@tonic-gate 		 * reflect this replacement.
1337c478bd9Sstevel@tonic-gate 		 */
1347c478bd9Sstevel@tonic-gate 		if (show)
1357c478bd9Sstevel@tonic-gate 			if (undkind == UNDMOVE)
1367c478bd9Sstevel@tonic-gate 				vdirty(0, lines);
1377c478bd9Sstevel@tonic-gate 			else
1387c478bd9Sstevel@tonic-gate 				vreplace(undap1 - addr, undap2 - undap1,
1397c478bd9Sstevel@tonic-gate 				    undkind == UNDPUT ? 0 : unddol - dol);
1407c478bd9Sstevel@tonic-gate 		savenote = notecnt;
1417c478bd9Sstevel@tonic-gate 		undo(1);
1427c478bd9Sstevel@tonic-gate 		if (show && (vundkind != VMCHNG || addr != dot))
1437c478bd9Sstevel@tonic-gate 			killU();
1447c478bd9Sstevel@tonic-gate 		vundkind = VMANY;
1457c478bd9Sstevel@tonic-gate 		cnt = dot - addr;
1467c478bd9Sstevel@tonic-gate 		if (cnt < 0 || cnt > vcnt || state != VISUAL) {
1477c478bd9Sstevel@tonic-gate 			if (show)
148f6db9f27Scf 				vjumpto(dot, (unsigned char *)NOSTR, '.');
1497c478bd9Sstevel@tonic-gate 			break;
1507c478bd9Sstevel@tonic-gate 		}
1517c478bd9Sstevel@tonic-gate 		if (!savenote)
1527c478bd9Sstevel@tonic-gate 			notecnt = 0;
1537c478bd9Sstevel@tonic-gate 		if (show) {
1547c478bd9Sstevel@tonic-gate 			vcline = cnt;
1557c478bd9Sstevel@tonic-gate 			if(MB_CUR_MAX > 1)
1567c478bd9Sstevel@tonic-gate 				rewrite = _ON;
1577c478bd9Sstevel@tonic-gate 			vrepaint(vmcurs);
1587c478bd9Sstevel@tonic-gate 			if(MB_CUR_MAX > 1)
1597c478bd9Sstevel@tonic-gate 				rewrite = _OFF;
1607c478bd9Sstevel@tonic-gate 		}
1617c478bd9Sstevel@tonic-gate 		vmcurs = 0;
1627c478bd9Sstevel@tonic-gate 		break;
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	case VCHNG:
1657c478bd9Sstevel@tonic-gate 	case VCAPU:
1667c478bd9Sstevel@tonic-gate 		vundkind = VCHNG;
1677c478bd9Sstevel@tonic-gate 		strcpy(temp, vutmp);
1687c478bd9Sstevel@tonic-gate 		strcpy(vutmp, linebuf);
1697c478bd9Sstevel@tonic-gate 		doomed = lcolumn(vUA2) - lcolumn(vUA1);
1707c478bd9Sstevel@tonic-gate 		strcLIN(temp);
1717c478bd9Sstevel@tonic-gate 		cp = vUA1; vUA1 = vUD1; vUD1 = cp;
1727c478bd9Sstevel@tonic-gate 		cp = vUA2; vUA2 = vUD2; vUD2 = cp;
1737c478bd9Sstevel@tonic-gate 		if (!show)
1747c478bd9Sstevel@tonic-gate 			break;
1757c478bd9Sstevel@tonic-gate 		cursor = vUD1;
1767c478bd9Sstevel@tonic-gate 		if (state == HARDOPEN) {
1777c478bd9Sstevel@tonic-gate 			doomed = 0;
1787c478bd9Sstevel@tonic-gate 			vsave();
1797c478bd9Sstevel@tonic-gate 			vopen(dot, WBOT);
1807c478bd9Sstevel@tonic-gate 			vnline(cursor);
1817c478bd9Sstevel@tonic-gate 			break;
1827c478bd9Sstevel@tonic-gate 		}
1837c478bd9Sstevel@tonic-gate 		/*
1847c478bd9Sstevel@tonic-gate 		 * Pseudo insert command.
1857c478bd9Sstevel@tonic-gate 		 */
1867c478bd9Sstevel@tonic-gate 		vcursat(cursor);
1877c478bd9Sstevel@tonic-gate 		OO = Outchar; Outchar = vinschar; hold |= HOLDQIK;
1887c478bd9Sstevel@tonic-gate 		vprepins();
1897c478bd9Sstevel@tonic-gate 		temp[vUA2 - linebuf] = 0;
1907c478bd9Sstevel@tonic-gate 		for (cp = &temp[vUA1 - linebuf]; *cp;) {
1917c478bd9Sstevel@tonic-gate 			length = mbtowc(&wchar, (char *)cp, MULTI_BYTE_MAX);
1927c478bd9Sstevel@tonic-gate 			if(length < 0) {
1937c478bd9Sstevel@tonic-gate 				putoctal = 1;
1947c478bd9Sstevel@tonic-gate 				putchar(*cp++);
1957c478bd9Sstevel@tonic-gate 				putoctal = 0;
1967c478bd9Sstevel@tonic-gate 			} else {
1977c478bd9Sstevel@tonic-gate 				putchar(wchar);
1987c478bd9Sstevel@tonic-gate 				cp += length;
1997c478bd9Sstevel@tonic-gate 			}
2007c478bd9Sstevel@tonic-gate 		}
2017c478bd9Sstevel@tonic-gate 		Outchar = OO; hold = oldhold;
2027c478bd9Sstevel@tonic-gate 		endim();
2037c478bd9Sstevel@tonic-gate 		physdc(cindent(), cindent() + doomed);
2047c478bd9Sstevel@tonic-gate 		doomed = 0;
2057c478bd9Sstevel@tonic-gate 		vdirty(vcline, 1);
2067c478bd9Sstevel@tonic-gate 		if(MB_CUR_MAX > 1)
2077c478bd9Sstevel@tonic-gate 			rewrite = _ON;
2087c478bd9Sstevel@tonic-gate 		vsyncCL();
2097c478bd9Sstevel@tonic-gate 		if(MB_CUR_MAX > 1)
2107c478bd9Sstevel@tonic-gate 			rewrite = _OFF;
2117c478bd9Sstevel@tonic-gate 		if (cursor > linebuf && cursor >= strend(linebuf))
2127c478bd9Sstevel@tonic-gate 			cursor = lastchr(linebuf, cursor);
2137c478bd9Sstevel@tonic-gate 		vfixcurs();
2147c478bd9Sstevel@tonic-gate 		break;
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 	case VNONE:
217f6db9f27Scf 		(void) beep();
2187c478bd9Sstevel@tonic-gate 		break;
2197c478bd9Sstevel@tonic-gate 	}
2207c478bd9Sstevel@tonic-gate }
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate /*
2237c478bd9Sstevel@tonic-gate  * Routine to handle a change inside a macro.
2247c478bd9Sstevel@tonic-gate  * Fromvis is true if we were called from a visual command (as
2257c478bd9Sstevel@tonic-gate  * opposed to an ex command).  This has nothing to do with being
2267c478bd9Sstevel@tonic-gate  * in open/visual mode as :s/foo/bar is not fromvis.
2277c478bd9Sstevel@tonic-gate  */
228f6db9f27Scf void
vmacchng(fromvis)2297c478bd9Sstevel@tonic-gate vmacchng(fromvis)
2307c478bd9Sstevel@tonic-gate bool fromvis;
2317c478bd9Sstevel@tonic-gate {
2327c478bd9Sstevel@tonic-gate 	line *savedot, *savedol;
2337c478bd9Sstevel@tonic-gate 	unsigned char *savecursor;
2347c478bd9Sstevel@tonic-gate 	unsigned char savelb[LBSIZE];
2357c478bd9Sstevel@tonic-gate 	int nlines, more;
236f6db9f27Scf 	line *a1, *a2;
2377c478bd9Sstevel@tonic-gate 	unsigned char ch;	/* DEBUG */
2387c478bd9Sstevel@tonic-gate 	int copyw(), copywR();
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 	if (!inopen)
2417c478bd9Sstevel@tonic-gate 		return;
2427c478bd9Sstevel@tonic-gate 	if (!vmacp)
2437c478bd9Sstevel@tonic-gate 		vch_mac = VC_NOTINMAC;
2447c478bd9Sstevel@tonic-gate #ifdef UNDOTRACE
2457c478bd9Sstevel@tonic-gate 	if (trace)
2467c478bd9Sstevel@tonic-gate 		fprintf(trace, "vmacchng, vch_mac=%d, linebuf='%s', *dot=%o\n", vch_mac, linebuf, *dot);
2477c478bd9Sstevel@tonic-gate #endif
2487c478bd9Sstevel@tonic-gate 	if (vmacp && fromvis)
2497c478bd9Sstevel@tonic-gate 		vsave();
2507c478bd9Sstevel@tonic-gate #ifdef UNDOTRACE
2517c478bd9Sstevel@tonic-gate 	if (trace)
2527c478bd9Sstevel@tonic-gate 		fprintf(trace, "after vsave, linebuf='%s', *dot=%o\n", linebuf, *dot);
2537c478bd9Sstevel@tonic-gate #endif
2547c478bd9Sstevel@tonic-gate 	switch(vch_mac) {
2557c478bd9Sstevel@tonic-gate 	case VC_NOCHANGE:
2567c478bd9Sstevel@tonic-gate 		vch_mac = VC_ONECHANGE;
2577c478bd9Sstevel@tonic-gate 		break;
2587c478bd9Sstevel@tonic-gate 	case VC_ONECHANGE:
2597c478bd9Sstevel@tonic-gate 		/* Save current state somewhere */
2607c478bd9Sstevel@tonic-gate #ifdef UNDOTRACE
2617c478bd9Sstevel@tonic-gate 		vudump("before vmacchng hairy case");
2627c478bd9Sstevel@tonic-gate #endif
2637c478bd9Sstevel@tonic-gate 		savedot = dot; savedol = dol; savecursor = cursor;
2647c478bd9Sstevel@tonic-gate 		CP(savelb, linebuf);
2657c478bd9Sstevel@tonic-gate 		nlines = dol - zero;
2667c478bd9Sstevel@tonic-gate 		while ((line *) endcore - truedol < nlines)
2677c478bd9Sstevel@tonic-gate 			if (morelines() < 0)
2687c478bd9Sstevel@tonic-gate 				return;	/* or could be fatal error */
2697c478bd9Sstevel@tonic-gate 		copyw(truedol+1, zero+1, nlines);
2707c478bd9Sstevel@tonic-gate 		truedol += nlines;
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate #ifdef UNDOTRACE
2737c478bd9Sstevel@tonic-gate 		visdump("before vundo");
2747c478bd9Sstevel@tonic-gate #endif
2757c478bd9Sstevel@tonic-gate 		/* Restore state as it was at beginning of macro */
2767c478bd9Sstevel@tonic-gate 		vundo(0);
2777c478bd9Sstevel@tonic-gate #ifdef UNDOTRACE
2787c478bd9Sstevel@tonic-gate 		visdump("after vundo");
2797c478bd9Sstevel@tonic-gate 		vudump("after vundo");
2807c478bd9Sstevel@tonic-gate #endif
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 		/* Do the saveall we should have done then */
2837c478bd9Sstevel@tonic-gate 		saveall();
2847c478bd9Sstevel@tonic-gate #ifdef UNDOTRACE
2857c478bd9Sstevel@tonic-gate 		vudump("after saveall");
2867c478bd9Sstevel@tonic-gate #endif
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 		/* Restore current state from where saved */
2897c478bd9Sstevel@tonic-gate 		more = savedol - dol; /* amount we shift everything by */
2907c478bd9Sstevel@tonic-gate 		if (more)
2917c478bd9Sstevel@tonic-gate 			(*(more>0 ? copywR : copyw))(savedol+1, dol+1, truedol-dol);
2927c478bd9Sstevel@tonic-gate 		unddol += more; truedol += more; undap2 += more;
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 		truedol -= nlines;
2957c478bd9Sstevel@tonic-gate 		copyw(zero+1, truedol+1, nlines);
2967c478bd9Sstevel@tonic-gate 		dot = savedot; dol = savedol ; cursor = savecursor;
2977c478bd9Sstevel@tonic-gate 		CP(linebuf, savelb);
2987c478bd9Sstevel@tonic-gate 		vch_mac = VC_MANYCHANGE;
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 		/* Arrange that no further undo saving happens within macro */
3017c478bd9Sstevel@tonic-gate 		otchng = tchng;	/* Copied this line blindly - bug? */
3027c478bd9Sstevel@tonic-gate 		inopen = -1;	/* no need to save since it had to be 1 or -1 before */
3037c478bd9Sstevel@tonic-gate 		vundkind = VMANY;
3047c478bd9Sstevel@tonic-gate #ifdef UNDOTRACE
3057c478bd9Sstevel@tonic-gate 		vudump("after vmacchng");
3067c478bd9Sstevel@tonic-gate #endif
3077c478bd9Sstevel@tonic-gate 		break;
3087c478bd9Sstevel@tonic-gate 	case VC_NOTINMAC:
3097c478bd9Sstevel@tonic-gate 	case VC_MANYCHANGE:
3107c478bd9Sstevel@tonic-gate 		/* Nothing to do for various reasons. */
3117c478bd9Sstevel@tonic-gate 		break;
3127c478bd9Sstevel@tonic-gate 	}
3137c478bd9Sstevel@tonic-gate }
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate /*
3167c478bd9Sstevel@tonic-gate  * Initialize undo information before an append.
3177c478bd9Sstevel@tonic-gate  */
318f6db9f27Scf void
vnoapp(void)319f6db9f27Scf vnoapp(void)
3207c478bd9Sstevel@tonic-gate {
3217c478bd9Sstevel@tonic-gate 	vUD1 = vUD2 = cursor;
322bbfd0aa6Scf 	/*
323bbfd0aa6Scf 	 * XPG6 assertion 273: Set vmcurs so that undo positions the
324bbfd0aa6Scf 	 * cursor column correctly when we've moved off the initial
325bbfd0aa6Scf 	 * line that was changed with the A, a, i, and R commands,
326bbfd0aa6Scf 	 * eg: when G has moved us off the line, or when a
327bbfd0aa6Scf 	 * multi-line change was done.
328bbfd0aa6Scf 	 */
329bbfd0aa6Scf 	if (lastcmd[0] == 'A' || lastcmd[0] == 'a' || lastcmd[0] == 'i' ||
330bbfd0aa6Scf 	    lastcmd[0] == 'R') {
331bbfd0aa6Scf 		vmcurs = cursor;
332bbfd0aa6Scf 	}
3337c478bd9Sstevel@tonic-gate }
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate /*
3367c478bd9Sstevel@tonic-gate  * All the rest of the motion sequences have one or more
3377c478bd9Sstevel@tonic-gate  * cases to deal with.  In the case wdot == 0, operation
3387c478bd9Sstevel@tonic-gate  * is totally within current line, from cursor to wcursor.
3397c478bd9Sstevel@tonic-gate  * If wdot is given, but wcursor is 0, then operation affects
3407c478bd9Sstevel@tonic-gate  * the inclusive line range.  The hardest case is when both wdot
3417c478bd9Sstevel@tonic-gate  * and wcursor are given, then operation affects from line dot at
3427c478bd9Sstevel@tonic-gate  * cursor to line wdot at wcursor.
3437c478bd9Sstevel@tonic-gate  */
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate /*
3467c478bd9Sstevel@tonic-gate  * Move is simple, except for moving onto new lines in hardcopy open mode.
3477c478bd9Sstevel@tonic-gate  */
348f6db9f27Scf int
vmove(void)349f6db9f27Scf vmove(void)
3507c478bd9Sstevel@tonic-gate {
351f6db9f27Scf 	int cnt;
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate 	if (wdot) {
3547c478bd9Sstevel@tonic-gate 		if (wdot < one || wdot > dol) {
355f6db9f27Scf 			(void) beep();
356f6db9f27Scf 			return (0);
3577c478bd9Sstevel@tonic-gate 		}
3587c478bd9Sstevel@tonic-gate 		cnt = wdot - dot;
3597c478bd9Sstevel@tonic-gate 		wdot = NOLINE;
3607c478bd9Sstevel@tonic-gate 		if (cnt)
3617c478bd9Sstevel@tonic-gate 			killU();
3627c478bd9Sstevel@tonic-gate 		vupdown(cnt, wcursor);
363f6db9f27Scf 		return (0);
3647c478bd9Sstevel@tonic-gate 	}
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate 	/*
3677c478bd9Sstevel@tonic-gate 	 * When we move onto a new line, save information for U undo.
3687c478bd9Sstevel@tonic-gate 	 */
3697c478bd9Sstevel@tonic-gate 	if (vUNDdot != dot) {
3707c478bd9Sstevel@tonic-gate 		vUNDsav = *dot;
3717c478bd9Sstevel@tonic-gate 		vUNDcurs = wcursor;
3727c478bd9Sstevel@tonic-gate 		vUNDdot = dot;
3737c478bd9Sstevel@tonic-gate 	}
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate 	/*
3767c478bd9Sstevel@tonic-gate 	 * In hardcopy open, type characters to left of cursor
3777c478bd9Sstevel@tonic-gate 	 * on new line, or back cursor up if its to left of where we are.
3787c478bd9Sstevel@tonic-gate 	 * In any case if the current line is ``rubbled'' i.e. has trashy
3797c478bd9Sstevel@tonic-gate 	 * looking overstrikes on it or \'s from deletes, we reprint
3807c478bd9Sstevel@tonic-gate 	 * so it is more comprehensible (and also because we can't work
3817c478bd9Sstevel@tonic-gate 	 * if we let it get more out of sync since column() won't work right.
3827c478bd9Sstevel@tonic-gate 	 */
3837c478bd9Sstevel@tonic-gate 	if (state == HARDOPEN) {
384f6db9f27Scf 		unsigned char *cp;
3857c478bd9Sstevel@tonic-gate 		if (rubble) {
386f6db9f27Scf 			int c;
3877c478bd9Sstevel@tonic-gate 			int oldhold = hold;
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate 			sethard();
3907c478bd9Sstevel@tonic-gate 			cp = wcursor;
3917c478bd9Sstevel@tonic-gate 			c = *cp;
3927c478bd9Sstevel@tonic-gate 			*cp = 0;
3937c478bd9Sstevel@tonic-gate 			hold |= HOLDDOL;
394f6db9f27Scf 			(void) vreopen(WTOP, lineDOT(), vcline);
3957c478bd9Sstevel@tonic-gate 			hold = oldhold;
3967c478bd9Sstevel@tonic-gate 			*cp = c;
3977c478bd9Sstevel@tonic-gate 		} else if (wcursor > cursor) {
398f6db9f27Scf 			int length;
3997c478bd9Sstevel@tonic-gate 			char multic[MULTI_BYTE_MAX];
4007c478bd9Sstevel@tonic-gate 			wchar_t wchar;
4017c478bd9Sstevel@tonic-gate 			vfixcurs();
4027c478bd9Sstevel@tonic-gate 			for (cp = cursor; *cp && cp < wcursor;) {
4037c478bd9Sstevel@tonic-gate 				length = mbtowc(&wchar, (char *)cp, MULTI_BYTE_MAX);
404*55fea89dSDan Cross 				if(length == 0)
4057c478bd9Sstevel@tonic-gate 					putchar(' ');
4067c478bd9Sstevel@tonic-gate 				else if(length < 0) {
4077c478bd9Sstevel@tonic-gate 					putoctal = 1;
4087c478bd9Sstevel@tonic-gate 					putchar(*cp++);
4097c478bd9Sstevel@tonic-gate 					putoctal = 0;
4107c478bd9Sstevel@tonic-gate 				} else {
4117c478bd9Sstevel@tonic-gate 					cp += length;
4127c478bd9Sstevel@tonic-gate 					putchar(wchar);
4137c478bd9Sstevel@tonic-gate 				}
4147c478bd9Sstevel@tonic-gate 			}
4157c478bd9Sstevel@tonic-gate 		}
4167c478bd9Sstevel@tonic-gate 	}
4177c478bd9Sstevel@tonic-gate 	vsetcurs(wcursor);
418f6db9f27Scf 	return (0);
4197c478bd9Sstevel@tonic-gate }
4207c478bd9Sstevel@tonic-gate 
4217c478bd9Sstevel@tonic-gate /*
4227c478bd9Sstevel@tonic-gate  * Delete operator.
4237c478bd9Sstevel@tonic-gate  *
4247c478bd9Sstevel@tonic-gate  * Hard case of deleting a range where both wcursor and wdot
4257c478bd9Sstevel@tonic-gate  * are specified is treated as a special case of change and handled
4267c478bd9Sstevel@tonic-gate  * by vchange (although vchange may pass it back if it degenerates
4277c478bd9Sstevel@tonic-gate  * to a full line range delete.)
4287c478bd9Sstevel@tonic-gate  */
429f6db9f27Scf int
vdelete(unsigned char c)430f6db9f27Scf vdelete(unsigned char c)
4317c478bd9Sstevel@tonic-gate {
432f6db9f27Scf 	unsigned char *cp;
433f6db9f27Scf 	int i;
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate 	if (wdot) {
4367c478bd9Sstevel@tonic-gate 		if (wcursor) {
437f6db9f27Scf 			(void) vchange('d');
438f6db9f27Scf 			return (0);
4397c478bd9Sstevel@tonic-gate 		}
4407c478bd9Sstevel@tonic-gate 		if ((i = xdw()) < 0)
441f6db9f27Scf 			return (0);
4427c478bd9Sstevel@tonic-gate 		if (state != VISUAL) {
4437c478bd9Sstevel@tonic-gate 			vgoto(LINE(0), 0);
444f6db9f27Scf 			(void) vputchar('@');
4457c478bd9Sstevel@tonic-gate 		}
4467c478bd9Sstevel@tonic-gate 		wdot = dot;
4477c478bd9Sstevel@tonic-gate 		vremote(i, delete, 0);
4487c478bd9Sstevel@tonic-gate 		notenam = (unsigned char *)"delete";
4497c478bd9Sstevel@tonic-gate 		DEL[0] = 0;
4507c478bd9Sstevel@tonic-gate 		killU();
4517c478bd9Sstevel@tonic-gate 		vreplace(vcline, i, 0);
4527c478bd9Sstevel@tonic-gate 		if (wdot > dol)
4537c478bd9Sstevel@tonic-gate 			vcline--;
4547c478bd9Sstevel@tonic-gate 		vrepaint(NOSTR);
455f6db9f27Scf 		return (0);
4567c478bd9Sstevel@tonic-gate 	}
4577c478bd9Sstevel@tonic-gate 	if (wcursor < linebuf)
4587c478bd9Sstevel@tonic-gate 		wcursor = linebuf;
4597c478bd9Sstevel@tonic-gate 	if (cursor == wcursor) {
460f6db9f27Scf 		(void) beep();
461f6db9f27Scf 		return (0);
4627c478bd9Sstevel@tonic-gate 	}
4637c478bd9Sstevel@tonic-gate 	i = vdcMID();
4647c478bd9Sstevel@tonic-gate 	cp = cursor;
4657c478bd9Sstevel@tonic-gate 	setDEL();
4667c478bd9Sstevel@tonic-gate 	CP(cp, wcursor);
4677c478bd9Sstevel@tonic-gate 	if (cp > linebuf && (cp[0] == 0 || c == '#'))
4687c478bd9Sstevel@tonic-gate 		cp = lastchr(linebuf, cp);
4697c478bd9Sstevel@tonic-gate 	if (state == HARDOPEN) {
4707c478bd9Sstevel@tonic-gate 		bleep(i, cp);
4717c478bd9Sstevel@tonic-gate 		cursor = cp;
472f6db9f27Scf 		return (0);
4737c478bd9Sstevel@tonic-gate 	}
4747c478bd9Sstevel@tonic-gate 	physdc(lcolumn(cursor), i);
4757c478bd9Sstevel@tonic-gate 	DEPTH(vcline) = 0;
4767c478bd9Sstevel@tonic-gate 	if(MB_CUR_MAX > 1)
4777c478bd9Sstevel@tonic-gate 		rewrite = _ON;
478f6db9f27Scf 	(void) vreopen(LINE(vcline), lineDOT(), vcline);
4797c478bd9Sstevel@tonic-gate 	if(MB_CUR_MAX > 1)
4807c478bd9Sstevel@tonic-gate 		rewrite = _OFF;
4817c478bd9Sstevel@tonic-gate 	vsyncCL();
4827c478bd9Sstevel@tonic-gate 	vsetcurs(cp);
483f6db9f27Scf 	return (0);
4847c478bd9Sstevel@tonic-gate }
4857c478bd9Sstevel@tonic-gate 
4867c478bd9Sstevel@tonic-gate /*
4877c478bd9Sstevel@tonic-gate  * Change operator.
4887c478bd9Sstevel@tonic-gate  *
4897c478bd9Sstevel@tonic-gate  * In a single line we mark the end of the changed area with '$'.
4907c478bd9Sstevel@tonic-gate  * On multiple whole lines, we clear the lines first.
4917c478bd9Sstevel@tonic-gate  * Across lines with both wcursor and wdot given, we delete
4927c478bd9Sstevel@tonic-gate  * and sync then append (but one operation for undo).
4937c478bd9Sstevel@tonic-gate  */
494f6db9f27Scf int
vchange(unsigned char c)495f6db9f27Scf vchange(unsigned char c)
4967c478bd9Sstevel@tonic-gate {
497f6db9f27Scf 	unsigned char *cp;
498f6db9f27Scf 	int i, ind, cnt;
4997c478bd9Sstevel@tonic-gate 	line *addr;
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate 	if (wdot) {
5027c478bd9Sstevel@tonic-gate 		/*
5037c478bd9Sstevel@tonic-gate 		 * Change/delete of lines or across line boundaries.
5047c478bd9Sstevel@tonic-gate 		 */
5057c478bd9Sstevel@tonic-gate 		if ((cnt = xdw()) < 0)
506f6db9f27Scf 			return (0);
5077c478bd9Sstevel@tonic-gate 		getDOT();
5087c478bd9Sstevel@tonic-gate 		if (wcursor && cnt == 1) {
5097c478bd9Sstevel@tonic-gate 			/*
5107c478bd9Sstevel@tonic-gate 			 * Not really.
5117c478bd9Sstevel@tonic-gate 			 */
5127c478bd9Sstevel@tonic-gate 			wdot = 0;
5137c478bd9Sstevel@tonic-gate 			if (c == 'd') {
514f6db9f27Scf 				(void) vdelete(c);
515f6db9f27Scf 				return (0);
5167c478bd9Sstevel@tonic-gate 			}
5177c478bd9Sstevel@tonic-gate 			goto smallchange;
5187c478bd9Sstevel@tonic-gate 		}
5197c478bd9Sstevel@tonic-gate 		if (cursor && wcursor) {
5207c478bd9Sstevel@tonic-gate 			/*
5217c478bd9Sstevel@tonic-gate 			 * Across line boundaries, but not
5227c478bd9Sstevel@tonic-gate 			 * necessarily whole lines.
5237c478bd9Sstevel@tonic-gate 			 * Construct what will be left.
5247c478bd9Sstevel@tonic-gate 			 */
5257c478bd9Sstevel@tonic-gate 			*cursor = 0;
5267c478bd9Sstevel@tonic-gate 			strcpy(genbuf, linebuf);
52723a1cceaSRoger A. Faulkner 			getaline(*wdot);
5287c478bd9Sstevel@tonic-gate 			if (strlen(genbuf) + strlen(wcursor) > LBSIZE - 2) {
5297c478bd9Sstevel@tonic-gate 				getDOT();
530f6db9f27Scf 				(void) beep();
531f6db9f27Scf 				return (0);
5327c478bd9Sstevel@tonic-gate 			}
5337c478bd9Sstevel@tonic-gate 			strcat(genbuf, wcursor);
5347c478bd9Sstevel@tonic-gate 			if (c == 'd' && *vpastwh(genbuf) == 0) {
5357c478bd9Sstevel@tonic-gate 				/*
5367c478bd9Sstevel@tonic-gate 				 * Although this is a delete
5377c478bd9Sstevel@tonic-gate 				 * spanning line boundaries, what
5387c478bd9Sstevel@tonic-gate 				 * would be left is all white space,
5397c478bd9Sstevel@tonic-gate 				 * so take it all away.
5407c478bd9Sstevel@tonic-gate 				 */
5417c478bd9Sstevel@tonic-gate 				wcursor = 0;
5427c478bd9Sstevel@tonic-gate 				getDOT();
5437c478bd9Sstevel@tonic-gate 				op = 0;
5447c478bd9Sstevel@tonic-gate 				notpart(lastreg);
5457c478bd9Sstevel@tonic-gate 				notpart('1');
546f6db9f27Scf 				(void) vdelete(c);
547f6db9f27Scf 				return (0);
5487c478bd9Sstevel@tonic-gate 			}
5497c478bd9Sstevel@tonic-gate 			ind = -1;
5507c478bd9Sstevel@tonic-gate 		} else if (c == 'd' && wcursor == 0) {
551f6db9f27Scf 			(void) vdelete(c);
552f6db9f27Scf 			return (0);
5537c478bd9Sstevel@tonic-gate 		} else
5547c478bd9Sstevel@tonic-gate 			/*
5557c478bd9Sstevel@tonic-gate 			 * We are just substituting text for whole lines,
5567c478bd9Sstevel@tonic-gate 			 * so determine the first autoindent.
5577c478bd9Sstevel@tonic-gate 			 */
5587c478bd9Sstevel@tonic-gate 			if (value(vi_LISP) && value(vi_AUTOINDENT))
5597c478bd9Sstevel@tonic-gate 				ind = lindent(dot);
5607c478bd9Sstevel@tonic-gate 			else
5617c478bd9Sstevel@tonic-gate 				ind = whitecnt(linebuf);
5627c478bd9Sstevel@tonic-gate 		i = vcline >= 0 ? LINE(vcline) : WTOP;
5637c478bd9Sstevel@tonic-gate 
5647c478bd9Sstevel@tonic-gate 		/*
5657c478bd9Sstevel@tonic-gate 		 * Delete the lines from the buffer,
5667c478bd9Sstevel@tonic-gate 		 * and remember how the partial stuff came about in
5677c478bd9Sstevel@tonic-gate 		 * case we are told to put.
5687c478bd9Sstevel@tonic-gate 		 */
5697c478bd9Sstevel@tonic-gate 		addr = dot;
5707c478bd9Sstevel@tonic-gate 		vremote(cnt, delete, 0);
5717c478bd9Sstevel@tonic-gate 		setpk();
5727c478bd9Sstevel@tonic-gate 		notenam = (unsigned char *)"delete";
5737c478bd9Sstevel@tonic-gate 		if (c != 'd')
5747c478bd9Sstevel@tonic-gate 			notenam = (unsigned char *)"change";
5757c478bd9Sstevel@tonic-gate 		/*
5767c478bd9Sstevel@tonic-gate 		 * If DEL[0] were nonzero, put would put it back
5777c478bd9Sstevel@tonic-gate 		 * rather than the deleted lines.
5787c478bd9Sstevel@tonic-gate 		 */
5797c478bd9Sstevel@tonic-gate 		DEL[0] = 0;
5807c478bd9Sstevel@tonic-gate 		if (cnt > 1)
5817c478bd9Sstevel@tonic-gate 			killU();
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate 		/*
5847c478bd9Sstevel@tonic-gate 		 * Now hack the screen image coordination.
5857c478bd9Sstevel@tonic-gate 		 */
5867c478bd9Sstevel@tonic-gate 		vreplace(vcline, cnt, 0);
5877c478bd9Sstevel@tonic-gate 		wdot = NOLINE;
5887c478bd9Sstevel@tonic-gate 		noteit(0);
5897c478bd9Sstevel@tonic-gate 		vcline--;
5907c478bd9Sstevel@tonic-gate 		if (addr <= dol)
5917c478bd9Sstevel@tonic-gate 			dot--;
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate 		/*
5947c478bd9Sstevel@tonic-gate 		 * If this is a across line delete/change,
5957c478bd9Sstevel@tonic-gate 		 * cursor stays where it is; just splice together the pieces
5967c478bd9Sstevel@tonic-gate 		 * of the new line.  Otherwise generate a autoindent
5977c478bd9Sstevel@tonic-gate 		 * after a S command.
5987c478bd9Sstevel@tonic-gate 		 */
5997c478bd9Sstevel@tonic-gate 		if (ind >= 0) {
600bbfd0aa6Scf 			/*
601bbfd0aa6Scf 			 * XPG6 assertion 273: Set vmcurs so that cursor
602bbfd0aa6Scf 			 * column will be set by undo.
603bbfd0aa6Scf 			 */
604bbfd0aa6Scf 			fixundo();
6057c478bd9Sstevel@tonic-gate 			*genindent(ind) = 0;
6067c478bd9Sstevel@tonic-gate 			vdoappend(genbuf);
6077c478bd9Sstevel@tonic-gate 		} else {
6087c478bd9Sstevel@tonic-gate 			vmcurs = cursor;
6097c478bd9Sstevel@tonic-gate 			strcLIN(genbuf);
6107c478bd9Sstevel@tonic-gate 			vdoappend(linebuf);
6117c478bd9Sstevel@tonic-gate 		}
6127c478bd9Sstevel@tonic-gate 
6137c478bd9Sstevel@tonic-gate 		/*
6147c478bd9Sstevel@tonic-gate 		 * Indicate a change on hardcopies by
6157c478bd9Sstevel@tonic-gate 		 * erasing the current line.
6167c478bd9Sstevel@tonic-gate 		 */
6177c478bd9Sstevel@tonic-gate 		if (c != 'd' && state != VISUAL && state != HARDOPEN) {
6187c478bd9Sstevel@tonic-gate 			int oldhold = hold;
6197c478bd9Sstevel@tonic-gate 
6207c478bd9Sstevel@tonic-gate 			hold |= HOLDAT, vclrlin(i, dot), hold = oldhold;
6217c478bd9Sstevel@tonic-gate 		}
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate 		/*
624*55fea89dSDan Cross 		 * Open the line (logically) on the screen, and
6257c478bd9Sstevel@tonic-gate 		 * update the screen tail.  Unless we are really a delete
6267c478bd9Sstevel@tonic-gate 		 * go off and gather up inserted characters.
6277c478bd9Sstevel@tonic-gate 		 */
6287c478bd9Sstevel@tonic-gate 		vcline++;
6297c478bd9Sstevel@tonic-gate 		if (vcline < 0)
6307c478bd9Sstevel@tonic-gate 			vcline = 0;
6317c478bd9Sstevel@tonic-gate 		vopen(dot, i);
6327c478bd9Sstevel@tonic-gate 		vsyncCL();
6337c478bd9Sstevel@tonic-gate 		noteit(1);
6347c478bd9Sstevel@tonic-gate 		if (c != 'd') {
6357c478bd9Sstevel@tonic-gate 			if (ind >= 0) {
6367c478bd9Sstevel@tonic-gate 				cursor = linebuf;
637bbfd0aa6Scf 				/*
638bbfd0aa6Scf 				 * XPG6 assertion 273: Set vmcurs so that
639bbfd0aa6Scf 				 * cursor column will be set by undo.  When
640bbfd0aa6Scf 				 * undo is preceded by 'S' or 'O' command,
641bbfd0aa6Scf 				 * white space isn't skipped in vnline(vmcurs).
642bbfd0aa6Scf 				 */
643bbfd0aa6Scf 				fixundo();
6447c478bd9Sstevel@tonic-gate 				linebuf[0] = 0;
6457c478bd9Sstevel@tonic-gate 				vfixcurs();
6467c478bd9Sstevel@tonic-gate 			} else {
6477c478bd9Sstevel@tonic-gate 				ind = 0;
648bbfd0aa6Scf 				/*
649bbfd0aa6Scf 				 * XPG6 assertion 273: Set vmcurs so that
650bbfd0aa6Scf 				 * cursor column will be set by undo.
651bbfd0aa6Scf 				 */
652bbfd0aa6Scf 				fixundo();
6537c478bd9Sstevel@tonic-gate 				vcursat(cursor);
6547c478bd9Sstevel@tonic-gate 			}
6557c478bd9Sstevel@tonic-gate 			vappend('x', 1, ind);
656f6db9f27Scf 			return (0);
6577c478bd9Sstevel@tonic-gate 		}
6587c478bd9Sstevel@tonic-gate 		if (*cursor == 0 && cursor > linebuf)
6597c478bd9Sstevel@tonic-gate 			cursor = lastchr(linebuf, cursor);
6607c478bd9Sstevel@tonic-gate 		vrepaint(cursor);
661f6db9f27Scf 		return (0);
6627c478bd9Sstevel@tonic-gate 	}
6637c478bd9Sstevel@tonic-gate 
6647c478bd9Sstevel@tonic-gate smallchange:
6657c478bd9Sstevel@tonic-gate 	/*
6667c478bd9Sstevel@tonic-gate 	 * The rest of this is just low level hacking on changes
6677c478bd9Sstevel@tonic-gate 	 * of small numbers of characters.
6687c478bd9Sstevel@tonic-gate 	 */
6697c478bd9Sstevel@tonic-gate 	if (wcursor < linebuf)
6707c478bd9Sstevel@tonic-gate 		wcursor = linebuf;
6717c478bd9Sstevel@tonic-gate 	if (cursor == wcursor) {
672f6db9f27Scf 		(void) beep();
673f6db9f27Scf 		return (0);
6747c478bd9Sstevel@tonic-gate 	}
6757c478bd9Sstevel@tonic-gate 	i = vdcMID();
6767c478bd9Sstevel@tonic-gate 	cp = cursor;
6777c478bd9Sstevel@tonic-gate 	if (state != HARDOPEN)
6787c478bd9Sstevel@tonic-gate 		vfixcurs();
6797c478bd9Sstevel@tonic-gate 
6807c478bd9Sstevel@tonic-gate 	/*
6817c478bd9Sstevel@tonic-gate 	 * Put out the \\'s indicating changed text in hardcopy,
6827c478bd9Sstevel@tonic-gate 	 * or mark the end of the change with $ if not hardcopy.
6837c478bd9Sstevel@tonic-gate 	 */
684*55fea89dSDan Cross 	if (state == HARDOPEN)
6857c478bd9Sstevel@tonic-gate 		bleep(i, cp);
6867c478bd9Sstevel@tonic-gate 	else {
6877c478bd9Sstevel@tonic-gate 		vcursbef(wcursor);
6887c478bd9Sstevel@tonic-gate 		putchar('$');
6897c478bd9Sstevel@tonic-gate 		i = cindent();
6907c478bd9Sstevel@tonic-gate 	}
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate 	/*
6937c478bd9Sstevel@tonic-gate 	 * Remember the deleted text for possible put,
6947c478bd9Sstevel@tonic-gate 	 * and then prepare and execute the input portion of the change.
6957c478bd9Sstevel@tonic-gate 	 */
6967c478bd9Sstevel@tonic-gate 	cursor = cp;
6977c478bd9Sstevel@tonic-gate 	setDEL();
6987c478bd9Sstevel@tonic-gate 	CP(cursor, wcursor);
699bbfd0aa6Scf 	/*
700bbfd0aa6Scf 	 * XPG6 assertion 273: Set vmcurs so that cursor column will be
701bbfd0aa6Scf 	 * set by undo.
702bbfd0aa6Scf 	 */
703bbfd0aa6Scf 	fixundo();
7047c478bd9Sstevel@tonic-gate 	if (state != HARDOPEN) {
7057c478bd9Sstevel@tonic-gate 		/* place cursor at beginning of changing text */
7067c478bd9Sstevel@tonic-gate 		vgotoCL(lcolumn(cp));
7077c478bd9Sstevel@tonic-gate 		doomed = i - cindent();
7087c478bd9Sstevel@tonic-gate 	} else {
7097c478bd9Sstevel@tonic-gate /*
7107c478bd9Sstevel@tonic-gate 		sethard();
7117c478bd9Sstevel@tonic-gate 		wcursor = cursor;
7127c478bd9Sstevel@tonic-gate 		cursor = linebuf;
7137c478bd9Sstevel@tonic-gate 		vgoto(outline, value(vi_NUMBER) << 3);
7147c478bd9Sstevel@tonic-gate 		vmove();
7157c478bd9Sstevel@tonic-gate */
7167c478bd9Sstevel@tonic-gate 		doomed = 0;
7177c478bd9Sstevel@tonic-gate 	}
7187c478bd9Sstevel@tonic-gate 	prepapp();
7197c478bd9Sstevel@tonic-gate 	vappend('c', 1, 0);
720f6db9f27Scf 	return (0);
7217c478bd9Sstevel@tonic-gate }
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate /*
7247c478bd9Sstevel@tonic-gate  * Open new lines.
7257c478bd9Sstevel@tonic-gate  */
726f6db9f27Scf void
voOpen(int c,int cnt)727f6db9f27Scf voOpen(int c, int cnt)
7287c478bd9Sstevel@tonic-gate {
729f6db9f27Scf 	int ind = 0, i;
7307c478bd9Sstevel@tonic-gate 	short oldhold = hold;
7317c478bd9Sstevel@tonic-gate 
7327c478bd9Sstevel@tonic-gate 	vsave();
7337c478bd9Sstevel@tonic-gate 	setLAST();
7347c478bd9Sstevel@tonic-gate 	if (value(vi_AUTOINDENT))
7357c478bd9Sstevel@tonic-gate 		ind = whitecnt(linebuf);
7367c478bd9Sstevel@tonic-gate 	if (c == 'O') {
7377c478bd9Sstevel@tonic-gate 		vcline--;
7387c478bd9Sstevel@tonic-gate 		dot--;
7397c478bd9Sstevel@tonic-gate 		if (dot > zero)
7407c478bd9Sstevel@tonic-gate 			getDOT();
7417c478bd9Sstevel@tonic-gate 	}
7427c478bd9Sstevel@tonic-gate 	if (value(vi_AUTOINDENT)) {
7437c478bd9Sstevel@tonic-gate 		if (value(vi_LISP))
7447c478bd9Sstevel@tonic-gate 			ind = lindent(dot + 1);
7457c478bd9Sstevel@tonic-gate 	}
7467c478bd9Sstevel@tonic-gate 	killU();
7477c478bd9Sstevel@tonic-gate 	prepapp();
7487c478bd9Sstevel@tonic-gate 	if (FIXUNDO)
7497c478bd9Sstevel@tonic-gate 		vundkind = VMANY;
7507c478bd9Sstevel@tonic-gate 	if (state != VISUAL)
7517c478bd9Sstevel@tonic-gate 		c = WBOT + 1;
7527c478bd9Sstevel@tonic-gate 	else {
7537c478bd9Sstevel@tonic-gate 		c = vcline < 0 ? WTOP - cnt : LINE(vcline) + DEPTH(vcline);
7547c478bd9Sstevel@tonic-gate 		if (c < ZERO)
7557c478bd9Sstevel@tonic-gate 			c = ZERO;
7567c478bd9Sstevel@tonic-gate 		i = LINE(vcline + 1) - c;
7577c478bd9Sstevel@tonic-gate 		if (i < cnt && c <= WBOT && (!insert_line || !delete_line))
7587c478bd9Sstevel@tonic-gate 			vinslin(c, cnt - i, vcline);
7597c478bd9Sstevel@tonic-gate 	}
7607c478bd9Sstevel@tonic-gate 	*genindent(ind) = 0;
7617c478bd9Sstevel@tonic-gate 	vdoappend(genbuf);
7627c478bd9Sstevel@tonic-gate 	vcline++;
7637c478bd9Sstevel@tonic-gate 	oldhold = hold;
7647c478bd9Sstevel@tonic-gate 	hold |= HOLDROL;
7657c478bd9Sstevel@tonic-gate 	vopen(dot, c);
7667c478bd9Sstevel@tonic-gate 	hold = oldhold;
7677c478bd9Sstevel@tonic-gate 	if (value(vi_SLOWOPEN))
7687c478bd9Sstevel@tonic-gate 		/*
7697c478bd9Sstevel@tonic-gate 		 * Oh, so lazy!
7707c478bd9Sstevel@tonic-gate 		 */
7717c478bd9Sstevel@tonic-gate 		vscrap();
7727c478bd9Sstevel@tonic-gate 	else
7737c478bd9Sstevel@tonic-gate 		vsync1(LINE(vcline));
7747c478bd9Sstevel@tonic-gate 	cursor = linebuf;
775bbfd0aa6Scf 	/*
776bbfd0aa6Scf 	 * XPG6 assertion 273: Set vmcurs so that cursor column will be
777bbfd0aa6Scf 	 * set by undo.  For undo preceded by 'o' command, white space
778bbfd0aa6Scf 	 * isn't skipped in vnline(vmcurs).
779bbfd0aa6Scf 	 */
780bbfd0aa6Scf 	fixundo();
7817c478bd9Sstevel@tonic-gate 	linebuf[0] = 0;
7823a5240e9Scf 	vappend('o', cnt, ind);
7837c478bd9Sstevel@tonic-gate }
7847c478bd9Sstevel@tonic-gate 
7857c478bd9Sstevel@tonic-gate /*
7867c478bd9Sstevel@tonic-gate  * > < and = shift operators.
7877c478bd9Sstevel@tonic-gate  *
7887c478bd9Sstevel@tonic-gate  * Note that =, which aligns lisp, is just a ragged sort of shift,
7897c478bd9Sstevel@tonic-gate  * since it never distributes text between lines.
7907c478bd9Sstevel@tonic-gate  */
7917c478bd9Sstevel@tonic-gate unsigned char	vshnam[2] = { 'x', 0 };
7927c478bd9Sstevel@tonic-gate 
793f6db9f27Scf int
vshftop(void)794f6db9f27Scf vshftop(void)
7957c478bd9Sstevel@tonic-gate {
796f6db9f27Scf 	line *addr;
797f6db9f27Scf 	int cnt;
7987c478bd9Sstevel@tonic-gate 
7997c478bd9Sstevel@tonic-gate 	if ((cnt = xdw()) < 0)
800f6db9f27Scf 		return (0);
8017c478bd9Sstevel@tonic-gate 	addr = dot;
8027c478bd9Sstevel@tonic-gate 	vremote(cnt, vshift, 0);
8037c478bd9Sstevel@tonic-gate 	vshnam[0] = op;
8047c478bd9Sstevel@tonic-gate 	notenam = vshnam;
8057c478bd9Sstevel@tonic-gate 	dot = addr;
8067c478bd9Sstevel@tonic-gate 	vreplace(vcline, cnt, cnt);
8077c478bd9Sstevel@tonic-gate 	if (state == HARDOPEN)
8087c478bd9Sstevel@tonic-gate 		vcnt = 0;
8097c478bd9Sstevel@tonic-gate 	vrepaint(NOSTR);
810f6db9f27Scf 	return (0);
8117c478bd9Sstevel@tonic-gate }
8127c478bd9Sstevel@tonic-gate 
8137c478bd9Sstevel@tonic-gate /*
8147c478bd9Sstevel@tonic-gate  * !.
8157c478bd9Sstevel@tonic-gate  *
8167c478bd9Sstevel@tonic-gate  * Filter portions of the buffer through unix commands.
8177c478bd9Sstevel@tonic-gate  */
818f6db9f27Scf int
vfilter(void)819f6db9f27Scf vfilter(void)
8207c478bd9Sstevel@tonic-gate {
821f6db9f27Scf 	line *addr;
822f6db9f27Scf 	int cnt;
8237c478bd9Sstevel@tonic-gate 	unsigned char *oglobp;
8247c478bd9Sstevel@tonic-gate 	short d;
8257c478bd9Sstevel@tonic-gate 
8267c478bd9Sstevel@tonic-gate 	if ((cnt = xdw()) < 0)
827f6db9f27Scf 		return (0);
8287c478bd9Sstevel@tonic-gate 	if (vglobp)
8297c478bd9Sstevel@tonic-gate 		vglobp = (unsigned char *)uxb;
8307c478bd9Sstevel@tonic-gate 	if (readecho('!'))
831f6db9f27Scf 		return (0);
8327c478bd9Sstevel@tonic-gate 	oglobp = globp; globp = genbuf + 1;
8337c478bd9Sstevel@tonic-gate 	d = peekc; ungetchar(0);
8347c478bd9Sstevel@tonic-gate 	CATCH
8357c478bd9Sstevel@tonic-gate 		fixech();
836ec427229Sceastha 		unix0(0, 0);
8377c478bd9Sstevel@tonic-gate 	ONERR
8387c478bd9Sstevel@tonic-gate 		splitw = 0;
8397c478bd9Sstevel@tonic-gate 		ungetchar(d);
8407c478bd9Sstevel@tonic-gate 		vrepaint(cursor);
8417c478bd9Sstevel@tonic-gate 		globp = oglobp;
842f6db9f27Scf 		return (0);
8437c478bd9Sstevel@tonic-gate 	ENDCATCH
8447c478bd9Sstevel@tonic-gate 	ungetchar(d); globp = oglobp;
8457c478bd9Sstevel@tonic-gate 	addr = dot;
8467c478bd9Sstevel@tonic-gate 	CATCH
8477c478bd9Sstevel@tonic-gate 		vgoto(WECHO, 0); flusho();
8487c478bd9Sstevel@tonic-gate 		vremote(cnt, vi_filter, 2);
8497c478bd9Sstevel@tonic-gate 	ONERR
8507c478bd9Sstevel@tonic-gate 		vdirty(0, lines);
8517c478bd9Sstevel@tonic-gate 	ENDCATCH
8527c478bd9Sstevel@tonic-gate 	if (dot == zero && dol > zero)
8537c478bd9Sstevel@tonic-gate 		dot = one;
8547c478bd9Sstevel@tonic-gate 	splitw = 0;
8557c478bd9Sstevel@tonic-gate 	notenam = (unsigned char *)"";
8567c478bd9Sstevel@tonic-gate 	/*
8577c478bd9Sstevel@tonic-gate 	 * BUG: we shouldn't be depending on what undap2 and undap1 are,
8587c478bd9Sstevel@tonic-gate 	 * since we may be inside a macro.  What's really wanted is the
8597c478bd9Sstevel@tonic-gate 	 * number of lines we read from the filter.  However, the mistake
8607c478bd9Sstevel@tonic-gate 	 * will be an overestimate so it only results in extra work,
8617c478bd9Sstevel@tonic-gate 	 * it shouldn't cause any real mess-ups.
8627c478bd9Sstevel@tonic-gate 	 */
8637c478bd9Sstevel@tonic-gate 	vreplace(vcline, cnt, undap2 - undap1);
8647c478bd9Sstevel@tonic-gate 	dot = addr;
8657c478bd9Sstevel@tonic-gate 	if (dot > dol) {
8667c478bd9Sstevel@tonic-gate 		dot--;
8677c478bd9Sstevel@tonic-gate 		vcline--;
8687c478bd9Sstevel@tonic-gate 	}
8697c478bd9Sstevel@tonic-gate 	vrepaint(NOSTR);
870f6db9f27Scf 	return (0);
8717c478bd9Sstevel@tonic-gate }
8727c478bd9Sstevel@tonic-gate 
8737c478bd9Sstevel@tonic-gate /*
8747c478bd9Sstevel@tonic-gate  * Xdw exchanges dot and wdot if appropriate and also checks
8757c478bd9Sstevel@tonic-gate  * that wdot is reasonable.  Its name comes from
8767c478bd9Sstevel@tonic-gate  *	xchange dotand wdot
8777c478bd9Sstevel@tonic-gate  */
878f6db9f27Scf int
xdw(void)879f6db9f27Scf xdw(void)
8807c478bd9Sstevel@tonic-gate {
881f6db9f27Scf 	unsigned char *cp;
882f6db9f27Scf 	int cnt;
8837c478bd9Sstevel@tonic-gate /*
8847c478bd9Sstevel@tonic-gate 	register int notp = 0;
8857c478bd9Sstevel@tonic-gate  */
8867c478bd9Sstevel@tonic-gate 
8877c478bd9Sstevel@tonic-gate 	if (wdot == NOLINE || wdot < one || wdot > dol) {
888f6db9f27Scf 		(void) beep();
8897c478bd9Sstevel@tonic-gate 		return (-1);
8907c478bd9Sstevel@tonic-gate 	}
8917c478bd9Sstevel@tonic-gate 	vsave();
8927c478bd9Sstevel@tonic-gate 	setLAST();
8937c478bd9Sstevel@tonic-gate 	if (dot > wdot || (dot == wdot && wcursor != 0 && cursor > wcursor)) {
894f6db9f27Scf 		line *addr;
8957c478bd9Sstevel@tonic-gate 
8967c478bd9Sstevel@tonic-gate 		vcline -= dot - wdot;
8977c478bd9Sstevel@tonic-gate 		addr = dot; dot = wdot; wdot = addr;
8987c478bd9Sstevel@tonic-gate 		cp = cursor; cursor = wcursor; wcursor = cp;
8997c478bd9Sstevel@tonic-gate 	}
9007c478bd9Sstevel@tonic-gate 	/*
9017c478bd9Sstevel@tonic-gate 	 * If a region is specified but wcursor is at the beginning
9027c478bd9Sstevel@tonic-gate 	 * of the last line, then we move it to be the end of the
9037c478bd9Sstevel@tonic-gate 	 * previous line (actually off the end).
9047c478bd9Sstevel@tonic-gate 	 */
9057c478bd9Sstevel@tonic-gate 	if (cursor && wcursor == linebuf && wdot > dot) {
9067c478bd9Sstevel@tonic-gate 		wdot--;
9077c478bd9Sstevel@tonic-gate 		getDOT();
9087c478bd9Sstevel@tonic-gate 		if (vpastwh(linebuf) >= cursor)
9097c478bd9Sstevel@tonic-gate 			wcursor = 0;
9107c478bd9Sstevel@tonic-gate 		else {
91123a1cceaSRoger A. Faulkner 			getaline(*wdot);
9127c478bd9Sstevel@tonic-gate 			wcursor = strend(linebuf);
9137c478bd9Sstevel@tonic-gate 			getDOT();
9147c478bd9Sstevel@tonic-gate 		}
9157c478bd9Sstevel@tonic-gate 		/*
9167c478bd9Sstevel@tonic-gate 		 * Should prepare in caller for possible dot == wdot.
9177c478bd9Sstevel@tonic-gate 		 */
9187c478bd9Sstevel@tonic-gate 	}
9197c478bd9Sstevel@tonic-gate 	cnt = wdot - dot + 1;
9207c478bd9Sstevel@tonic-gate 	if (vreg) {
9217c478bd9Sstevel@tonic-gate 		vremote(cnt, YANKreg, vreg);
9227c478bd9Sstevel@tonic-gate /*
9237c478bd9Sstevel@tonic-gate 		if (notp)
9247c478bd9Sstevel@tonic-gate 			notpart(vreg);
9257c478bd9Sstevel@tonic-gate  */
9267c478bd9Sstevel@tonic-gate 	}
9277c478bd9Sstevel@tonic-gate 
9287c478bd9Sstevel@tonic-gate 	/*
9297c478bd9Sstevel@tonic-gate 	 * Kill buffer code.  If delete operator is c or d, then save
9307c478bd9Sstevel@tonic-gate 	 * the region in numbered buffers.
9317c478bd9Sstevel@tonic-gate 	 *
9327c478bd9Sstevel@tonic-gate 	 * BUG:			This may be somewhat inefficient due
9337c478bd9Sstevel@tonic-gate 	 *			to the way named buffer are implemented,
9347c478bd9Sstevel@tonic-gate 	 *			necessitating some optimization.
9357c478bd9Sstevel@tonic-gate 	 */
9367c478bd9Sstevel@tonic-gate 	vreg = 0;
937bbfd0aa6Scf 	/* XPG6 assertion 194 and 264: use numeric buffers for 'C' and 'S' */
938bbfd0aa6Scf 	if (any(op, (unsigned char *)"cdCS")) {
9397c478bd9Sstevel@tonic-gate 		vremote(cnt, YANKreg, '1');
9407c478bd9Sstevel@tonic-gate /*
9417c478bd9Sstevel@tonic-gate 		if (notp)
9427c478bd9Sstevel@tonic-gate 			notpart('1');
9437c478bd9Sstevel@tonic-gate  */
9447c478bd9Sstevel@tonic-gate 	}
9457c478bd9Sstevel@tonic-gate 	return (cnt);
9467c478bd9Sstevel@tonic-gate }
9477c478bd9Sstevel@tonic-gate 
9487c478bd9Sstevel@tonic-gate /*
9497c478bd9Sstevel@tonic-gate  * Routine for vremote to call to implement shifts.
9507c478bd9Sstevel@tonic-gate  */
951f6db9f27Scf int
vshift(void)952f6db9f27Scf vshift(void)
9537c478bd9Sstevel@tonic-gate {
9547c478bd9Sstevel@tonic-gate 
9557c478bd9Sstevel@tonic-gate 	shift(op, 1);
956f6db9f27Scf 	return (0);
9577c478bd9Sstevel@tonic-gate }
9587c478bd9Sstevel@tonic-gate 
9597c478bd9Sstevel@tonic-gate /*
9607c478bd9Sstevel@tonic-gate  * Replace a single character with the next input character.
9617c478bd9Sstevel@tonic-gate  * A funny kind of insert.
9627c478bd9Sstevel@tonic-gate  */
963f6db9f27Scf void
vrep(int cnt)964f6db9f27Scf vrep(int cnt)
9657c478bd9Sstevel@tonic-gate {
966f6db9f27Scf 	int i, c;
967f6db9f27Scf 	unsigned char *endcurs;
9687c478bd9Sstevel@tonic-gate 	endcurs = cursor;
969bbfd0aa6Scf 	/* point endcurs to last char entered */
9707c478bd9Sstevel@tonic-gate 	for(i = 1; i <= cnt; i++) {
9717c478bd9Sstevel@tonic-gate 		if(!*endcurs) {
972f6db9f27Scf 			(void) beep();
9737c478bd9Sstevel@tonic-gate 			return;
9747c478bd9Sstevel@tonic-gate 		}
9757c478bd9Sstevel@tonic-gate 		endcurs = nextchr(endcurs);
9767c478bd9Sstevel@tonic-gate 	}
9777c478bd9Sstevel@tonic-gate 	i = lcolumn(endcurs);
9787c478bd9Sstevel@tonic-gate 	vcursat(cursor);
9797c478bd9Sstevel@tonic-gate 	doomed = i - cindent();
9807c478bd9Sstevel@tonic-gate 	/*
9817c478bd9Sstevel@tonic-gate 	 * TRANSLATION_NOTE
9827c478bd9Sstevel@tonic-gate 	 *	"r" is a terse mode message that corresponds to
9837c478bd9Sstevel@tonic-gate 	 *	"REPLACE 1 CHAR".
9847c478bd9Sstevel@tonic-gate 	 *	Translated message of "r" must be 1 character (not byte).
9857c478bd9Sstevel@tonic-gate 	 *	Or, just leave it.
9867c478bd9Sstevel@tonic-gate 	 */
9877c478bd9Sstevel@tonic-gate 	if(value(vi_TERSE))
9887c478bd9Sstevel@tonic-gate 		vshowmode(gettext("r"));
9897c478bd9Sstevel@tonic-gate 	else
9907c478bd9Sstevel@tonic-gate 		vshowmode(gettext("REPLACE 1 CHAR"));
9917c478bd9Sstevel@tonic-gate 	if (!vglobp) {
992bbfd0aa6Scf 		/* get a key using getkey() */
9937c478bd9Sstevel@tonic-gate 		c = getesc();
9947c478bd9Sstevel@tonic-gate 		if (c == 0) {
9957c478bd9Sstevel@tonic-gate 			vshowmode("");
9967c478bd9Sstevel@tonic-gate 			vfixcurs();
9977c478bd9Sstevel@tonic-gate 			return;
9987c478bd9Sstevel@tonic-gate 		}
9997c478bd9Sstevel@tonic-gate 		ungetkey(c);
10007c478bd9Sstevel@tonic-gate 	}
10017c478bd9Sstevel@tonic-gate 	CP(vutmp, linebuf);
10027c478bd9Sstevel@tonic-gate 	if (FIXUNDO)
10037c478bd9Sstevel@tonic-gate 		vundkind = VCHNG;
10047c478bd9Sstevel@tonic-gate 	wcursor = endcurs;
10057c478bd9Sstevel@tonic-gate 	vUD1 = cursor; vUD2 = wcursor;
10067c478bd9Sstevel@tonic-gate 	CP(cursor, wcursor);
1007bbfd0aa6Scf 	/* before appending lines, set addr1 and undo information */
10087c478bd9Sstevel@tonic-gate 	prepapp();
10097c478bd9Sstevel@tonic-gate 	vappend('r', cnt, 0);
10107c478bd9Sstevel@tonic-gate 	*lastcp++ = INS[0];
10117c478bd9Sstevel@tonic-gate 	setLAST();
10127c478bd9Sstevel@tonic-gate }
10137c478bd9Sstevel@tonic-gate 
10147c478bd9Sstevel@tonic-gate /*
10157c478bd9Sstevel@tonic-gate  * Yank.
10167c478bd9Sstevel@tonic-gate  *
10177c478bd9Sstevel@tonic-gate  * Yanking to string registers occurs for free (essentially)
10187c478bd9Sstevel@tonic-gate  * in the routine xdw().
10197c478bd9Sstevel@tonic-gate  */
1020f6db9f27Scf int
vyankit(void)1021f6db9f27Scf vyankit(void)
10227c478bd9Sstevel@tonic-gate {
1023f6db9f27Scf 	int cnt;
10247c478bd9Sstevel@tonic-gate 
10257c478bd9Sstevel@tonic-gate 	if (wdot) {
10267c478bd9Sstevel@tonic-gate 		if ((cnt = xdw()) < 0)
1027f6db9f27Scf 			return (0);
10287c478bd9Sstevel@tonic-gate 		vremote(cnt, yank, 0);
10297c478bd9Sstevel@tonic-gate 		setpk();
10307c478bd9Sstevel@tonic-gate 		notenam = (unsigned char *)"yank";
10317c478bd9Sstevel@tonic-gate 		if (FIXUNDO)
10327c478bd9Sstevel@tonic-gate 			vundkind = VNONE;
10337c478bd9Sstevel@tonic-gate 		DEL[0] = 0;
10347c478bd9Sstevel@tonic-gate 		wdot = NOLINE;
10357c478bd9Sstevel@tonic-gate 		if (notecnt <= vcnt - vcline && notecnt < value(vi_REPORT))
10367c478bd9Sstevel@tonic-gate 			notecnt = 0;
10377c478bd9Sstevel@tonic-gate 		vrepaint(cursor);
1038f6db9f27Scf 		return (0);
10393a5240e9Scf 	} else {
10403a5240e9Scf 		/*
10413a5240e9Scf 		 * For one line y<motion> commands, eg. 2yw, save the
10423a5240e9Scf 		 * command for a subsequent [count].
10433a5240e9Scf 		 */
10443a5240e9Scf 		setLAST();
10457c478bd9Sstevel@tonic-gate 	}
10467c478bd9Sstevel@tonic-gate 	takeout(DEL);
1047f6db9f27Scf 	return (0);
1048f6db9f27Scf 
10497c478bd9Sstevel@tonic-gate }
10507c478bd9Sstevel@tonic-gate 
10517c478bd9Sstevel@tonic-gate /*
10527c478bd9Sstevel@tonic-gate  * Set pkill variables so a put can
10537c478bd9Sstevel@tonic-gate  * know how to put back partial text.
10547c478bd9Sstevel@tonic-gate  * This is necessary because undo needs the complete
10557c478bd9Sstevel@tonic-gate  * line images to be saved, while a put wants to trim
10567c478bd9Sstevel@tonic-gate  * the first and last lines.  The compromise
10577c478bd9Sstevel@tonic-gate  * is for put to be more clever.
10587c478bd9Sstevel@tonic-gate  */
1059f6db9f27Scf void
setpk(void)1060f6db9f27Scf setpk(void)
10617c478bd9Sstevel@tonic-gate {
10627c478bd9Sstevel@tonic-gate 
10637c478bd9Sstevel@tonic-gate 	if (wcursor) {
10647c478bd9Sstevel@tonic-gate 		pkill[0] = cursor;
10657c478bd9Sstevel@tonic-gate 		pkill[1] = wcursor;
10667c478bd9Sstevel@tonic-gate 	}
10677c478bd9Sstevel@tonic-gate }
1068bbfd0aa6Scf 
1069bbfd0aa6Scf /*
1070bbfd0aa6Scf  * XPG6 assertion 273 : If the command is C, c, o, R, S, or s, set vmcurs
1071bbfd0aa6Scf  * so that the cursor column will be set by undo.
1072bbfd0aa6Scf  */
1073bbfd0aa6Scf void
fixundo(void)1074bbfd0aa6Scf fixundo(void)
1075bbfd0aa6Scf {
1076bbfd0aa6Scf 	if (lastcmd[0] == 'C' || lastcmd[0] == 'c' || lastcmd[0] == 'o' ||
1077bbfd0aa6Scf 	    lastcmd[0] == 'R' || lastcmd[0] == 'S' || lastcmd[0] == 's') {
1078bbfd0aa6Scf 		vmcurs = cursor;
1079bbfd0aa6Scf 	}
1080bbfd0aa6Scf }
1081