xref: /onnv-gate/usr/src/cmd/vi/port/ex_cmds.c (revision 802:73b56fb6544b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
22500Sceastha /*
23500Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24500Sceastha  * Use is subject to license terms.
25500Sceastha  */
26500Sceastha 
270Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate 
310Sstevel@tonic-gate /* Copyright (c) 1981 Regents of the University of California */
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #include "ex.h"
360Sstevel@tonic-gate #include "ex_argv.h"
370Sstevel@tonic-gate #include "ex_temp.h"
380Sstevel@tonic-gate #include "ex_tty.h"
390Sstevel@tonic-gate #include "ex_vis.h"
400Sstevel@tonic-gate 
410Sstevel@tonic-gate bool	pflag, nflag;
420Sstevel@tonic-gate int	poffset;
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #define	nochng()	lchng = chng
450Sstevel@tonic-gate 
460Sstevel@tonic-gate 
470Sstevel@tonic-gate /*
480Sstevel@tonic-gate  * Main loop for command mode command decoding.
490Sstevel@tonic-gate  * A few commands are executed here, but main function
500Sstevel@tonic-gate  * is to strip command addresses, do a little address oriented
510Sstevel@tonic-gate  * processing and call command routines to do the real work.
520Sstevel@tonic-gate  */
530Sstevel@tonic-gate extern unsigned char *Version;
54*802Scf46844 void
550Sstevel@tonic-gate commands(noprompt, exitoneof)
560Sstevel@tonic-gate 	bool noprompt, exitoneof;
570Sstevel@tonic-gate {
580Sstevel@tonic-gate 	line *addr;
590Sstevel@tonic-gate 	int c;
600Sstevel@tonic-gate 	int lchng;
610Sstevel@tonic-gate 	int given;
620Sstevel@tonic-gate 	int seensemi;
630Sstevel@tonic-gate 	int cnt;
640Sstevel@tonic-gate 	bool hadpr;
650Sstevel@tonic-gate 	bool gotfile;
660Sstevel@tonic-gate #ifdef XPG4
670Sstevel@tonic-gate 	int d;
680Sstevel@tonic-gate #endif /* XPG4 */
690Sstevel@tonic-gate 	unsigned char *vgetpass();
700Sstevel@tonic-gate 
710Sstevel@tonic-gate 	resetflav();
720Sstevel@tonic-gate 	nochng();
730Sstevel@tonic-gate 	for (;;) {
740Sstevel@tonic-gate 		if (!firstpat)
750Sstevel@tonic-gate 			laste = 0;
760Sstevel@tonic-gate 		/*
770Sstevel@tonic-gate 		 * If dot at last command
780Sstevel@tonic-gate 		 * ended up at zero, advance to one if there is a such.
790Sstevel@tonic-gate 		 */
800Sstevel@tonic-gate 		if (dot <= zero) {
810Sstevel@tonic-gate 			dot = zero;
820Sstevel@tonic-gate 			if (dol > zero)
830Sstevel@tonic-gate 				dot = one;
840Sstevel@tonic-gate 		}
850Sstevel@tonic-gate 		shudclob = 0;
860Sstevel@tonic-gate 
870Sstevel@tonic-gate 		/*
880Sstevel@tonic-gate 		 * If autoprint or trailing print flags,
890Sstevel@tonic-gate 		 * print the line at the specified offset
900Sstevel@tonic-gate 		 * before the next command.
910Sstevel@tonic-gate 		 */
920Sstevel@tonic-gate 		if ((pflag || lchng != chng && value(vi_AUTOPRINT) &&
930Sstevel@tonic-gate 		    !inglobal && !inopen && endline) || poffset != 0) {
940Sstevel@tonic-gate 			pflag = 0;
950Sstevel@tonic-gate 			nochng();
960Sstevel@tonic-gate 			if (dol != zero) {
970Sstevel@tonic-gate 				addr1 = addr2 = dot + poffset;
980Sstevel@tonic-gate 				poffset = 0;
990Sstevel@tonic-gate 				if (addr1 < one || addr1 > dol)
1000Sstevel@tonic-gate 					error(value(vi_TERSE) ?
1010Sstevel@tonic-gate 					    gettext("Offset out-of-bounds") :
1020Sstevel@tonic-gate 					    gettext("Offset after command "
1030Sstevel@tonic-gate 						"too large"));
1040Sstevel@tonic-gate 				dot = addr1;
1050Sstevel@tonic-gate 				setdot1();
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 				goto print;
1080Sstevel@tonic-gate 			}
1090Sstevel@tonic-gate 		}
1100Sstevel@tonic-gate 		nochng();
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate 		/*
1130Sstevel@tonic-gate 		 * Print prompt if appropriate.
1140Sstevel@tonic-gate 		 * If not in global flush output first to prevent
1150Sstevel@tonic-gate 		 * going into pfast mode unreasonably.
1160Sstevel@tonic-gate 		 */
1170Sstevel@tonic-gate 		if (inglobal == 0) {
1180Sstevel@tonic-gate 			flush();
1190Sstevel@tonic-gate 			if (!hush && value(vi_PROMPT) && !globp &&
1200Sstevel@tonic-gate 			    !noprompt && endline) {
1210Sstevel@tonic-gate 				putchar(':');
1220Sstevel@tonic-gate 				hadpr = 1;
1230Sstevel@tonic-gate 			}
1240Sstevel@tonic-gate 			TSYNC();
1250Sstevel@tonic-gate 		}
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate 		/*
1280Sstevel@tonic-gate 		 * Gobble up the address.
1290Sstevel@tonic-gate 		 * Degenerate addresses yield ".".
1300Sstevel@tonic-gate 		 */
1310Sstevel@tonic-gate 		addr2 = 0;
1320Sstevel@tonic-gate 		given = seensemi = 0;
1330Sstevel@tonic-gate 		do {
1340Sstevel@tonic-gate 			addr1 = addr2;
1350Sstevel@tonic-gate 			addr = address(0);
1360Sstevel@tonic-gate 			c = getcd();
1370Sstevel@tonic-gate 			if (addr == 0) {
1380Sstevel@tonic-gate 				if (c == ',' || c == ';')
1390Sstevel@tonic-gate 					addr = dot;
1400Sstevel@tonic-gate 				else if (addr1 != 0) {
1410Sstevel@tonic-gate 					addr2 = dot;
1420Sstevel@tonic-gate 					break;
1430Sstevel@tonic-gate 				} else
1440Sstevel@tonic-gate 					break;
1450Sstevel@tonic-gate 			}
1460Sstevel@tonic-gate 			addr2 = addr;
1470Sstevel@tonic-gate 			given++;
1480Sstevel@tonic-gate 			if (c == ';') {
1490Sstevel@tonic-gate 				c = ',';
1500Sstevel@tonic-gate 				dot = addr;
1510Sstevel@tonic-gate 				seensemi = 1;
1520Sstevel@tonic-gate 			}
1530Sstevel@tonic-gate 		} while (c == ',');
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate 		if (c == '%') {
1560Sstevel@tonic-gate 			/* %: same as 1,$ */
1570Sstevel@tonic-gate 			addr1 = one;
1580Sstevel@tonic-gate 			addr2 = dol;
1590Sstevel@tonic-gate 			given = 2;
1600Sstevel@tonic-gate 			c = getchar();
1610Sstevel@tonic-gate 		}
1620Sstevel@tonic-gate 		if (addr1 == 0)
1630Sstevel@tonic-gate 			addr1 = addr2;
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 		/*
1660Sstevel@tonic-gate 		 * eat multiple colons
1670Sstevel@tonic-gate 		 */
1680Sstevel@tonic-gate 		while (c == ':')
1690Sstevel@tonic-gate 			c = getchar();
1700Sstevel@tonic-gate 		/*
1710Sstevel@tonic-gate 		 * Set command name for special character commands.
1720Sstevel@tonic-gate 		 */
1730Sstevel@tonic-gate 		tailspec(c);
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate 		/*
1760Sstevel@tonic-gate 		 * If called via : escape from open or visual, limit
1770Sstevel@tonic-gate 		 * the set of available commands here to save work below.
1780Sstevel@tonic-gate 		 */
1790Sstevel@tonic-gate 		if (inopen) {
1800Sstevel@tonic-gate 			if (c == '\n' || c == '\r' ||
1810Sstevel@tonic-gate 			    c == CTRL('d') || c == EOF) {
1820Sstevel@tonic-gate 				if (addr2)
1830Sstevel@tonic-gate 					dot = addr2;
1840Sstevel@tonic-gate 				if (c == EOF)
1850Sstevel@tonic-gate 					return;
1860Sstevel@tonic-gate 				continue;
1870Sstevel@tonic-gate 			}
1880Sstevel@tonic-gate 			if (any(c, "o"))
1890Sstevel@tonic-gate notinvis:
1900Sstevel@tonic-gate 				tailprim(Command, 1, 1);
1910Sstevel@tonic-gate 		}
1920Sstevel@tonic-gate 		switch (c) {
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate 		case 'a':
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate 			switch (peekchar()) {
1970Sstevel@tonic-gate 			case 'b':
1980Sstevel@tonic-gate /* abbreviate */
1990Sstevel@tonic-gate 				tail("abbreviate");
2000Sstevel@tonic-gate 				setnoaddr();
2010Sstevel@tonic-gate 				mapcmd(0, 1);
2020Sstevel@tonic-gate 				anyabbrs = 1;
2030Sstevel@tonic-gate 				continue;
2040Sstevel@tonic-gate 			case 'r':
2050Sstevel@tonic-gate /* args */
2060Sstevel@tonic-gate 				tail("args");
2070Sstevel@tonic-gate 				setnoaddr();
2080Sstevel@tonic-gate 				eol();
2090Sstevel@tonic-gate 				pargs();
2100Sstevel@tonic-gate 				continue;
2110Sstevel@tonic-gate 			}
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate /* append */
2140Sstevel@tonic-gate 			if (inopen)
2150Sstevel@tonic-gate 				goto notinvis;
2160Sstevel@tonic-gate 			tail("append");
2170Sstevel@tonic-gate 			setdot();
2180Sstevel@tonic-gate 			aiflag = exclam();
2190Sstevel@tonic-gate 			donewline();
2200Sstevel@tonic-gate 			vmacchng(0);
2210Sstevel@tonic-gate 			deletenone();
2220Sstevel@tonic-gate 			setin(addr2);
2230Sstevel@tonic-gate 			inappend = 1;
2240Sstevel@tonic-gate 			(void) append(gettty, addr2);
2250Sstevel@tonic-gate 			inappend = 0;
2260Sstevel@tonic-gate 			nochng();
2270Sstevel@tonic-gate 			continue;
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate 		case 'c':
2300Sstevel@tonic-gate 			switch (peekchar()) {
2310Sstevel@tonic-gate 
2320Sstevel@tonic-gate /* copy */
2330Sstevel@tonic-gate 			case 'o':
2340Sstevel@tonic-gate 				tail("copy");
2350Sstevel@tonic-gate 				vmacchng(0);
2360Sstevel@tonic-gate 				vi_move();
2370Sstevel@tonic-gate 				continue;
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate /* crypt */
2400Sstevel@tonic-gate 			case 'r':
2410Sstevel@tonic-gate 				tail("crypt");
2420Sstevel@tonic-gate 				crflag = -1;
2430Sstevel@tonic-gate 			ent_crypt:
2440Sstevel@tonic-gate 				setnoaddr();
2450Sstevel@tonic-gate 				xflag = 1;
2460Sstevel@tonic-gate 				if (permflag)
2470Sstevel@tonic-gate 					(void) crypt_close(perm);
2480Sstevel@tonic-gate 				permflag = 1;
2490Sstevel@tonic-gate 				if ((kflag = run_setkey(perm,
2500Sstevel@tonic-gate 				    (key = vgetpass(
2510Sstevel@tonic-gate 					gettext("Enter key:"))))) == -1) {
2520Sstevel@tonic-gate 					xflag = 0;
2530Sstevel@tonic-gate 					kflag = 0;
2540Sstevel@tonic-gate 					crflag = 0;
2550Sstevel@tonic-gate 					smerror(gettext("Encryption facility "
2560Sstevel@tonic-gate 						    "not available\n"));
2570Sstevel@tonic-gate 				}
2580Sstevel@tonic-gate 				if (kflag == 0)
2590Sstevel@tonic-gate 					crflag = 0;
2600Sstevel@tonic-gate 				continue;
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate /* cd */
2630Sstevel@tonic-gate 			case 'd':
2640Sstevel@tonic-gate 				tail("cd");
2650Sstevel@tonic-gate 				goto changdir;
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate /* chdir */
2680Sstevel@tonic-gate 			case 'h':
2690Sstevel@tonic-gate 				ignchar();
2700Sstevel@tonic-gate 				if (peekchar() == 'd') {
271*802Scf46844 					unsigned char *p;
2720Sstevel@tonic-gate 					tail2of("chdir");
2730Sstevel@tonic-gate changdir:
2740Sstevel@tonic-gate 					if (savedfile[0] == '/' ||
2750Sstevel@tonic-gate 					    !value(vi_WARN))
2760Sstevel@tonic-gate 						(void) exclam();
2770Sstevel@tonic-gate 					else
2780Sstevel@tonic-gate 						(void) quickly();
2790Sstevel@tonic-gate 					if (skipend()) {
2800Sstevel@tonic-gate 						p = (unsigned char *)
2810Sstevel@tonic-gate 						    getenv("HOME");
2820Sstevel@tonic-gate 						if (p == NULL)
2830Sstevel@tonic-gate 							error(gettext(
2840Sstevel@tonic-gate 								"Home directory"
2850Sstevel@tonic-gate 								    /*CSTYLED*/
2860Sstevel@tonic-gate 								    " unknown"));
2870Sstevel@tonic-gate 					} else
2880Sstevel@tonic-gate 						getone(), p = file;
2890Sstevel@tonic-gate 					eol();
290*802Scf46844 					if (chdir((char *)p) < 0)
2910Sstevel@tonic-gate 						filioerr(p);
2920Sstevel@tonic-gate 					if (savedfile[0] != '/')
2930Sstevel@tonic-gate 						edited = 0;
2940Sstevel@tonic-gate 					continue;
2950Sstevel@tonic-gate 				}
2960Sstevel@tonic-gate 				if (inopen)
297*802Scf46844 					tailprim((unsigned char *)"change",
298*802Scf46844 					    2, 1);
2990Sstevel@tonic-gate 				tail2of("change");
3000Sstevel@tonic-gate 				break;
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate 			default:
3030Sstevel@tonic-gate 				if (inopen)
3040Sstevel@tonic-gate 					goto notinvis;
3050Sstevel@tonic-gate 				tail("change");
3060Sstevel@tonic-gate 				break;
3070Sstevel@tonic-gate 			}
3080Sstevel@tonic-gate /* change */
3090Sstevel@tonic-gate 			aiflag = exclam();
3100Sstevel@tonic-gate #ifdef XPG4ONLY
3110Sstevel@tonic-gate 			setcount2();
3120Sstevel@tonic-gate 			donewline();
3130Sstevel@tonic-gate #else /* XPG6 and Solaris */
3140Sstevel@tonic-gate 			setCNL();
3150Sstevel@tonic-gate #endif /* XPG4ONLY */
3160Sstevel@tonic-gate 			vmacchng(0);
3170Sstevel@tonic-gate 			setin(addr1);
318*802Scf46844 			(void) delete(0);
3190Sstevel@tonic-gate 			inappend = 1;
3200Sstevel@tonic-gate 			if (append(gettty, addr1 - 1) == 0) {
3210Sstevel@tonic-gate #ifdef XPG4
3220Sstevel@tonic-gate 				/*
3230Sstevel@tonic-gate 				 * P2003.2/D9:5.10.7.2.4, p. 646,
3240Sstevel@tonic-gate 				 * assertion 214(A). If nothing changed,
3250Sstevel@tonic-gate 				 * set dot to the line preceding the lines
3260Sstevel@tonic-gate 				 * to be changed.
3270Sstevel@tonic-gate 				 */
3280Sstevel@tonic-gate 				dot = addr1 - 1;
3290Sstevel@tonic-gate #else /* XPG4 */
3300Sstevel@tonic-gate 				dot = addr1;
3310Sstevel@tonic-gate #endif /* XPG4 */
3320Sstevel@tonic-gate 				if (dot > dol)
3330Sstevel@tonic-gate 					dot = dol;
3340Sstevel@tonic-gate 			}
3350Sstevel@tonic-gate 			inappend = 0;
3360Sstevel@tonic-gate 			nochng();
3370Sstevel@tonic-gate 			continue;
3380Sstevel@tonic-gate 
3390Sstevel@tonic-gate /* delete */
3400Sstevel@tonic-gate 		case 'd':
3410Sstevel@tonic-gate 			/*
3420Sstevel@tonic-gate 			 * Caution: dp and dl have special meaning already.
3430Sstevel@tonic-gate 			 */
3440Sstevel@tonic-gate 			tail("delete");
3450Sstevel@tonic-gate 			c = cmdreg();
3460Sstevel@tonic-gate #ifdef XPG4ONLY
3470Sstevel@tonic-gate 			setcount2();
3480Sstevel@tonic-gate 			donewline();
3490Sstevel@tonic-gate #else /* XPG6 and Solaris */
3500Sstevel@tonic-gate 			setCNL();
3510Sstevel@tonic-gate #endif /* XPG4ONLY */
3520Sstevel@tonic-gate 			vmacchng(0);
3530Sstevel@tonic-gate 			if (c)
354*802Scf46844 				(void) YANKreg(c);
355*802Scf46844 			(void) delete(0);
3560Sstevel@tonic-gate 			appendnone();
3570Sstevel@tonic-gate 			continue;
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate /* edit */
3600Sstevel@tonic-gate /* ex */
3610Sstevel@tonic-gate 		case 'e':
3620Sstevel@tonic-gate 			if (crflag == 2 || crflag == -2)
3630Sstevel@tonic-gate 				crflag = -1;
3640Sstevel@tonic-gate 			tail(peekchar() == 'x' ? "ex" : "edit");
3650Sstevel@tonic-gate editcmd:
3660Sstevel@tonic-gate 			if (!exclam() && chng)
3670Sstevel@tonic-gate 				c = 'E';
3680Sstevel@tonic-gate 			gotfile = 0;
3690Sstevel@tonic-gate 			if (c == 'E') {
3700Sstevel@tonic-gate 				if (inopen && !value(vi_AUTOWRITE)) {
3710Sstevel@tonic-gate 					filename(c);
3720Sstevel@tonic-gate 					gotfile = 1;
3730Sstevel@tonic-gate 				}
3740Sstevel@tonic-gate 				ungetchar(lastchar());
3750Sstevel@tonic-gate 				if (!exclam()) {
3760Sstevel@tonic-gate 					ckaw();
3770Sstevel@tonic-gate 					if (chng && dol > zero) {
3780Sstevel@tonic-gate 						xchng = 0;
3790Sstevel@tonic-gate 						error(value(vi_TERSE) ?
3800Sstevel@tonic-gate 						    gettext("No write") :
3810Sstevel@tonic-gate 						    gettext("No write since "
3820Sstevel@tonic-gate 							"last change (:%s! "
3830Sstevel@tonic-gate 							"overrides)"),
3840Sstevel@tonic-gate 						    Command);
3850Sstevel@tonic-gate 					}
3860Sstevel@tonic-gate 				}
3870Sstevel@tonic-gate 
3880Sstevel@tonic-gate 			}
3890Sstevel@tonic-gate 			if (gotfile == 0)
3900Sstevel@tonic-gate 				filename(c);
3910Sstevel@tonic-gate 			setnoaddr();
3920Sstevel@tonic-gate doecmd:
3930Sstevel@tonic-gate 			init();
3940Sstevel@tonic-gate 			addr2 = zero;
3950Sstevel@tonic-gate 			laste++;
3960Sstevel@tonic-gate 			sync();
3970Sstevel@tonic-gate 			rop(c);
3980Sstevel@tonic-gate 			nochng();
3990Sstevel@tonic-gate 			continue;
4000Sstevel@tonic-gate 
4010Sstevel@tonic-gate /* file */
4020Sstevel@tonic-gate 		case 'f':
4030Sstevel@tonic-gate 			tail("file");
4040Sstevel@tonic-gate 			setnoaddr();
4050Sstevel@tonic-gate 			filename(c);
4060Sstevel@tonic-gate 			noonl();
4070Sstevel@tonic-gate /*
4080Sstevel@tonic-gate  *			synctmp();
4090Sstevel@tonic-gate  */
4100Sstevel@tonic-gate 			continue;
4110Sstevel@tonic-gate 
4120Sstevel@tonic-gate /* global */
4130Sstevel@tonic-gate 		case 'g':
4140Sstevel@tonic-gate 			tail("global");
4150Sstevel@tonic-gate 			global(!exclam());
4160Sstevel@tonic-gate 			nochng();
4170Sstevel@tonic-gate 			continue;
4180Sstevel@tonic-gate 
4190Sstevel@tonic-gate /* insert */
4200Sstevel@tonic-gate 		case 'i':
4210Sstevel@tonic-gate 			if (inopen)
4220Sstevel@tonic-gate 				goto notinvis;
4230Sstevel@tonic-gate 			tail("insert");
4240Sstevel@tonic-gate 			setdot();
4250Sstevel@tonic-gate 			nonzero();
4260Sstevel@tonic-gate 			aiflag = exclam();
4270Sstevel@tonic-gate 			donewline();
4280Sstevel@tonic-gate 			vmacchng(0);
4290Sstevel@tonic-gate 			deletenone();
4300Sstevel@tonic-gate 			setin(addr2);
4310Sstevel@tonic-gate 			inappend = 1;
4320Sstevel@tonic-gate 			(void) append(gettty, addr2 - 1);
4330Sstevel@tonic-gate 			inappend = 0;
4340Sstevel@tonic-gate 			if (dot == zero && dol > zero)
4350Sstevel@tonic-gate 				dot = one;
4360Sstevel@tonic-gate 			nochng();
4370Sstevel@tonic-gate 			continue;
4380Sstevel@tonic-gate 
4390Sstevel@tonic-gate /* join */
4400Sstevel@tonic-gate 		case 'j':
4410Sstevel@tonic-gate 			tail("join");
4420Sstevel@tonic-gate 			c = exclam();
4430Sstevel@tonic-gate 			setcount();
4440Sstevel@tonic-gate 			nonzero();
4450Sstevel@tonic-gate 			donewline();
4460Sstevel@tonic-gate 			vmacchng(0);
4470Sstevel@tonic-gate #ifdef XPG4ONLY
4480Sstevel@tonic-gate 			/*
4490Sstevel@tonic-gate 			 * if no count was specified, addr1 == addr2. if only
4500Sstevel@tonic-gate 			 * 1 range arg was specified, inc addr2 to allow
4510Sstevel@tonic-gate 			 * joining of the next line.
4520Sstevel@tonic-gate 			 */
4530Sstevel@tonic-gate 			if (given < 2 && (addr1 == addr2) && (addr2 != dol))
4540Sstevel@tonic-gate 				addr2++;
4550Sstevel@tonic-gate 
4560Sstevel@tonic-gate #else /* XPG6 and Solaris */
4570Sstevel@tonic-gate 			if (given < 2 && addr2 != dol)
4580Sstevel@tonic-gate 				addr2++;
4590Sstevel@tonic-gate #endif /* XPG4ONLY */
460*802Scf46844 			(void) join(c);
4610Sstevel@tonic-gate 			continue;
4620Sstevel@tonic-gate 
4630Sstevel@tonic-gate /* k */
4640Sstevel@tonic-gate 		case 'k':
4650Sstevel@tonic-gate casek:
4660Sstevel@tonic-gate 			pastwh();
4670Sstevel@tonic-gate 			c = getchar();
4680Sstevel@tonic-gate 			if (endcmd(c))
469*802Scf46844 				serror((vi_TERSE) ?
470*802Scf46844 				    (unsigned char *)gettext("Mark what?") :
471*802Scf46844 				    (unsigned char *)
472*802Scf46844 				    gettext("%s requires following "
473*802Scf46844 				    "letter"), Command);
4740Sstevel@tonic-gate 			donewline();
4750Sstevel@tonic-gate 			if (!islower(c))
4760Sstevel@tonic-gate 				error((vi_TERSE) ? gettext("Bad mark") :
4770Sstevel@tonic-gate 					gettext("Mark must specify a letter"));
4780Sstevel@tonic-gate 			setdot();
4790Sstevel@tonic-gate 			nonzero();
4800Sstevel@tonic-gate 			names[c - 'a'] = *addr2 &~ 01;
4810Sstevel@tonic-gate 			anymarks = 1;
4820Sstevel@tonic-gate 			continue;
4830Sstevel@tonic-gate 
4840Sstevel@tonic-gate /* list */
4850Sstevel@tonic-gate 		case 'l':
4860Sstevel@tonic-gate 			tail("list");
4870Sstevel@tonic-gate #ifdef XPG4ONLY
4880Sstevel@tonic-gate 			setcount2();
4890Sstevel@tonic-gate 			donewline();
4900Sstevel@tonic-gate #else /* XPG6 and Solaris */
4910Sstevel@tonic-gate 			setCNL();
4920Sstevel@tonic-gate #endif /* XPG4ONLY */
4930Sstevel@tonic-gate 			(void) setlist(1);
4940Sstevel@tonic-gate 			pflag = 0;
4950Sstevel@tonic-gate 			goto print;
4960Sstevel@tonic-gate 
4970Sstevel@tonic-gate 		case 'm':
4980Sstevel@tonic-gate 			if (peekchar() == 'a') {
4990Sstevel@tonic-gate 				ignchar();
5000Sstevel@tonic-gate 				if (peekchar() == 'p') {
5010Sstevel@tonic-gate /* map */
5020Sstevel@tonic-gate 					tail2of("map");
5030Sstevel@tonic-gate 					setnoaddr();
5040Sstevel@tonic-gate 					mapcmd(0, 0);
5050Sstevel@tonic-gate 					continue;
5060Sstevel@tonic-gate 				}
5070Sstevel@tonic-gate /* mark */
5080Sstevel@tonic-gate 				tail2of("mark");
5090Sstevel@tonic-gate 				goto casek;
5100Sstevel@tonic-gate 			}
5110Sstevel@tonic-gate /* move */
5120Sstevel@tonic-gate 			tail("move");
5130Sstevel@tonic-gate 			vmacchng(0);
5140Sstevel@tonic-gate 			vi_move();
5150Sstevel@tonic-gate 			continue;
5160Sstevel@tonic-gate 
5170Sstevel@tonic-gate 		case 'n':
5180Sstevel@tonic-gate 			if (peekchar() == 'u') {
5190Sstevel@tonic-gate 				tail("number");
5200Sstevel@tonic-gate 				goto numberit;
5210Sstevel@tonic-gate 			}
5220Sstevel@tonic-gate /* next */
5230Sstevel@tonic-gate 			tail("next");
5240Sstevel@tonic-gate 			setnoaddr();
5250Sstevel@tonic-gate 			if (!exclam()) {
5260Sstevel@tonic-gate 				ckaw();
5270Sstevel@tonic-gate 				if (chng && dol > zero) {
5280Sstevel@tonic-gate 					xchng = 0;
5290Sstevel@tonic-gate 					error(value(vi_TERSE) ?
5300Sstevel@tonic-gate 					    gettext("No write") :
5310Sstevel@tonic-gate 					    gettext("No write since last "
5320Sstevel@tonic-gate 						"change (:%s! overrides)"),
5330Sstevel@tonic-gate 					    Command);
5340Sstevel@tonic-gate 				}
5350Sstevel@tonic-gate 			}
5360Sstevel@tonic-gate 
5370Sstevel@tonic-gate 			if (getargs())
5380Sstevel@tonic-gate 				makargs();
5390Sstevel@tonic-gate 			next();
5400Sstevel@tonic-gate 			c = 'e';
5410Sstevel@tonic-gate 			filename(c);
5420Sstevel@tonic-gate 			goto doecmd;
5430Sstevel@tonic-gate 
5440Sstevel@tonic-gate /* open */
5450Sstevel@tonic-gate 		case 'o':
5460Sstevel@tonic-gate 			tail("open");
5470Sstevel@tonic-gate 			oop();
5480Sstevel@tonic-gate 			pflag = 0;
5490Sstevel@tonic-gate 			nochng();
5500Sstevel@tonic-gate 			continue;
5510Sstevel@tonic-gate 
5520Sstevel@tonic-gate 		case 'p':
5530Sstevel@tonic-gate 		case 'P':
5540Sstevel@tonic-gate 			switch (peekchar()) {
5550Sstevel@tonic-gate #ifdef TAG_STACK
5560Sstevel@tonic-gate /* pop */
5570Sstevel@tonic-gate 			case 'o':
5580Sstevel@tonic-gate 				tail("pop");
5590Sstevel@tonic-gate 				poptag(exclam());
5600Sstevel@tonic-gate 				if (!inopen)
5610Sstevel@tonic-gate 					lchng = chng - 1;
5620Sstevel@tonic-gate 				else
5630Sstevel@tonic-gate 					nochng();
5640Sstevel@tonic-gate 				continue;
5650Sstevel@tonic-gate #endif
5660Sstevel@tonic-gate 
5670Sstevel@tonic-gate /* put */
5680Sstevel@tonic-gate 			case 'u':
5690Sstevel@tonic-gate 				tail("put");
5700Sstevel@tonic-gate 				setdot();
5710Sstevel@tonic-gate 				c = cmdreg();
5720Sstevel@tonic-gate 				eol();
5730Sstevel@tonic-gate 				vmacchng(0);
5740Sstevel@tonic-gate 				if (c)
575*802Scf46844 					(void) putreg(c);
5760Sstevel@tonic-gate 				else
577*802Scf46844 					(void) put();
5780Sstevel@tonic-gate 				continue;
5790Sstevel@tonic-gate 
5800Sstevel@tonic-gate 			case 'r':
5810Sstevel@tonic-gate 				ignchar();
5820Sstevel@tonic-gate 				if (peekchar() == 'e') {
5830Sstevel@tonic-gate /* preserve */
5840Sstevel@tonic-gate 					tail2of("preserve");
5850Sstevel@tonic-gate 					eol();
5860Sstevel@tonic-gate 					if (preserve() == 0)
5870Sstevel@tonic-gate 						error(gettext(
5880Sstevel@tonic-gate 						    "Preserve failed!"));
5890Sstevel@tonic-gate 					else {
5900Sstevel@tonic-gate #ifdef XPG4
5910Sstevel@tonic-gate 						/*
5920Sstevel@tonic-gate 						 * error() incs errcnt. this is
5930Sstevel@tonic-gate 						 * misleading here; and a
5940Sstevel@tonic-gate 						 * violation of POSIX. so call
5950Sstevel@tonic-gate 						 * noerror() instead.
5960Sstevel@tonic-gate 						 * this is for assertion ex:222.
5970Sstevel@tonic-gate 						 */
5980Sstevel@tonic-gate 						noerror(
5990Sstevel@tonic-gate 						    gettext("File preserved."));
6000Sstevel@tonic-gate 
6010Sstevel@tonic-gate #else /* XPG4 */
6020Sstevel@tonic-gate 						error(
6030Sstevel@tonic-gate 						    gettext("File preserved."));
6040Sstevel@tonic-gate #endif /* XPG4 */
6050Sstevel@tonic-gate 					}
6060Sstevel@tonic-gate 				}
6070Sstevel@tonic-gate 				tail2of("print");
6080Sstevel@tonic-gate 				break;
6090Sstevel@tonic-gate 
6100Sstevel@tonic-gate 			default:
6110Sstevel@tonic-gate 				tail("print");
6120Sstevel@tonic-gate 				break;
6130Sstevel@tonic-gate 			}
6140Sstevel@tonic-gate /* print */
6150Sstevel@tonic-gate 			setCNL();
6160Sstevel@tonic-gate 			pflag = 0;
6170Sstevel@tonic-gate print:
6180Sstevel@tonic-gate 			nonzero();
6190Sstevel@tonic-gate 			if (clear_screen && span() > lines) {
6200Sstevel@tonic-gate 				flush1();
6210Sstevel@tonic-gate 				vclear();
6220Sstevel@tonic-gate 			}
6230Sstevel@tonic-gate 			/*
6240Sstevel@tonic-gate 			 * poffset is nonzero if trailing + or - flags
6250Sstevel@tonic-gate 			 * were given, and in that case we need to
6260Sstevel@tonic-gate 			 * adjust dot before printing a line.
6270Sstevel@tonic-gate 			 */
6280Sstevel@tonic-gate 			if (poffset == 0)
6290Sstevel@tonic-gate 				plines(addr1, addr2, 1);
6300Sstevel@tonic-gate 			else
6310Sstevel@tonic-gate 				dot = addr2;
6320Sstevel@tonic-gate 			continue;
6330Sstevel@tonic-gate 
6340Sstevel@tonic-gate /* quit */
6350Sstevel@tonic-gate 		case 'q':
6360Sstevel@tonic-gate 			tail("quit");
6370Sstevel@tonic-gate 			setnoaddr();
6380Sstevel@tonic-gate 			c = quickly();
6390Sstevel@tonic-gate 			eol();
6400Sstevel@tonic-gate 			if (!c)
6410Sstevel@tonic-gate quit:
6420Sstevel@tonic-gate 				if (nomore())
6430Sstevel@tonic-gate 					continue;
6440Sstevel@tonic-gate 			if (inopen) {
6450Sstevel@tonic-gate 				vgoto(WECHO, 0);
6460Sstevel@tonic-gate 				if (!ateopr())
6470Sstevel@tonic-gate 					vnfl();
6480Sstevel@tonic-gate 				else {
6490Sstevel@tonic-gate 					tostop();
6500Sstevel@tonic-gate 				}
6510Sstevel@tonic-gate 				flush();
6520Sstevel@tonic-gate 				setty(normf);
6530Sstevel@tonic-gate 				ixlatctl(1);
6540Sstevel@tonic-gate 			}
6550Sstevel@tonic-gate 			cleanup(1);
6560Sstevel@tonic-gate 			exit(errcnt);
6570Sstevel@tonic-gate 
6580Sstevel@tonic-gate 		case 'r':
6590Sstevel@tonic-gate 			if (peekchar() == 'e') {
6600Sstevel@tonic-gate 				ignchar();
6610Sstevel@tonic-gate 				switch (peekchar()) {
6620Sstevel@tonic-gate 
6630Sstevel@tonic-gate /* rewind */
6640Sstevel@tonic-gate 				case 'w':
6650Sstevel@tonic-gate 					tail2of("rewind");
6660Sstevel@tonic-gate 					setnoaddr();
6670Sstevel@tonic-gate 					if (!exclam()) {
6680Sstevel@tonic-gate 						ckaw();
6690Sstevel@tonic-gate 						if (chng && dol > zero)
6700Sstevel@tonic-gate 							error((vi_TERSE) ?
6710Sstevel@tonic-gate 							    /*CSTYLED*/
6720Sstevel@tonic-gate 							    gettext("No write") :
6730Sstevel@tonic-gate 							    gettext("No write "
6740Sstevel@tonic-gate 								"since last "
6750Sstevel@tonic-gate 								"change (:rewi"
6760Sstevel@tonic-gate 								/*CSTYLED*/
6770Sstevel@tonic-gate 								"nd! overrides)"));
6780Sstevel@tonic-gate 					}
6790Sstevel@tonic-gate 					eol();
6800Sstevel@tonic-gate 					erewind();
6810Sstevel@tonic-gate 					next();
6820Sstevel@tonic-gate 					c = 'e';
6830Sstevel@tonic-gate 					ungetchar(lastchar());
6840Sstevel@tonic-gate 					filename(c);
6850Sstevel@tonic-gate 					goto doecmd;
6860Sstevel@tonic-gate 
6870Sstevel@tonic-gate /* recover */
6880Sstevel@tonic-gate 				case 'c':
6890Sstevel@tonic-gate 					tail2of("recover");
6900Sstevel@tonic-gate 					setnoaddr();
6910Sstevel@tonic-gate 					c = 'e';
6920Sstevel@tonic-gate 					if (!exclam() && chng)
6930Sstevel@tonic-gate 						c = 'E';
6940Sstevel@tonic-gate 					filename(c);
6950Sstevel@tonic-gate 					if (c == 'E') {
6960Sstevel@tonic-gate 						ungetchar(lastchar());
6970Sstevel@tonic-gate 						(void) quickly();
6980Sstevel@tonic-gate 					}
6990Sstevel@tonic-gate 					init();
7000Sstevel@tonic-gate 					addr2 = zero;
7010Sstevel@tonic-gate 					laste++;
7020Sstevel@tonic-gate 					sync();
7030Sstevel@tonic-gate 					recover();
7040Sstevel@tonic-gate 					rop2();
7050Sstevel@tonic-gate 					revocer();
7060Sstevel@tonic-gate 					if (status == 0)
7070Sstevel@tonic-gate 						rop3(c);
7080Sstevel@tonic-gate 					if (dol != zero)
7090Sstevel@tonic-gate 						change();
7100Sstevel@tonic-gate 					nochng();
7110Sstevel@tonic-gate 					continue;
7120Sstevel@tonic-gate 				}
7130Sstevel@tonic-gate 				tail2of("read");
7140Sstevel@tonic-gate 			} else
7150Sstevel@tonic-gate 				tail("read");
7160Sstevel@tonic-gate /* read */
7170Sstevel@tonic-gate 			if (crflag == 2 || crflag == -2)
7180Sstevel@tonic-gate 			/* restore crflag for new input text */
7190Sstevel@tonic-gate 				crflag = -1;
7200Sstevel@tonic-gate 			if (savedfile[0] == 0 && dol == zero)
7210Sstevel@tonic-gate 				c = 'e';
7220Sstevel@tonic-gate 			pastwh();
7230Sstevel@tonic-gate 			vmacchng(0);
7240Sstevel@tonic-gate 			if (peekchar() == '!') {
7250Sstevel@tonic-gate 				setdot();
7260Sstevel@tonic-gate 				ignchar();
727500Sceastha 				unix0(0, 1);
728*802Scf46844 				(void) vi_filter(0);
7290Sstevel@tonic-gate 				continue;
7300Sstevel@tonic-gate 			}
7310Sstevel@tonic-gate 			filename(c);
7320Sstevel@tonic-gate 			rop(c);
7330Sstevel@tonic-gate 			nochng();
7340Sstevel@tonic-gate 			if (inopen && endline && addr1 > zero && addr1 < dol)
7350Sstevel@tonic-gate 				dot = addr1 + 1;
7360Sstevel@tonic-gate 			continue;
7370Sstevel@tonic-gate 
7380Sstevel@tonic-gate 		case 's':
7390Sstevel@tonic-gate 			switch (peekchar()) {
7400Sstevel@tonic-gate 			/*
7410Sstevel@tonic-gate 			 * Caution: 2nd char cannot be c, g, or r
7420Sstevel@tonic-gate 			 * because these have meaning to substitute.
7430Sstevel@tonic-gate 			 */
7440Sstevel@tonic-gate 
7450Sstevel@tonic-gate /* set */
7460Sstevel@tonic-gate 			case 'e':
7470Sstevel@tonic-gate 				tail("set");
7480Sstevel@tonic-gate 				setnoaddr();
7490Sstevel@tonic-gate 				set();
7500Sstevel@tonic-gate 				continue;
7510Sstevel@tonic-gate 
7520Sstevel@tonic-gate /* shell */
7530Sstevel@tonic-gate 			case 'h':
7540Sstevel@tonic-gate 				tail("shell");
7550Sstevel@tonic-gate 				setNAEOL();
7560Sstevel@tonic-gate 				vnfl();
757*802Scf46844 				putpad((unsigned char *)exit_ca_mode);
7580Sstevel@tonic-gate 				flush();
7590Sstevel@tonic-gate 				resetterm();
7600Sstevel@tonic-gate 				unixwt(1, unixex("-i", (char *)0, 0, 0));
7610Sstevel@tonic-gate 				vcontin(0);
7620Sstevel@tonic-gate 				continue;
7630Sstevel@tonic-gate 
7640Sstevel@tonic-gate /* source */
7650Sstevel@tonic-gate 			case 'o':
7660Sstevel@tonic-gate #ifdef notdef
7670Sstevel@tonic-gate 				if (inopen)
7680Sstevel@tonic-gate 					goto notinvis;
7690Sstevel@tonic-gate #endif
7700Sstevel@tonic-gate 				tail("source");
7710Sstevel@tonic-gate 				setnoaddr();
7720Sstevel@tonic-gate 				getone();
7730Sstevel@tonic-gate 				eol();
7740Sstevel@tonic-gate 				source(file, 0);
7750Sstevel@tonic-gate 				continue;
7760Sstevel@tonic-gate #ifdef SIGTSTP
7770Sstevel@tonic-gate /* stop, suspend */
7780Sstevel@tonic-gate 			case 't':
7790Sstevel@tonic-gate 				tail("stop");
7800Sstevel@tonic-gate 				goto suspend;
7810Sstevel@tonic-gate 			case 'u':
7820Sstevel@tonic-gate #ifdef XPG4
7830Sstevel@tonic-gate 				/*
7840Sstevel@tonic-gate 				 * for POSIX, "su" with no other distinguishing
7850Sstevel@tonic-gate 				 * characteristics, maps to "s". Re. P1003.D11,
7860Sstevel@tonic-gate 				 * 5.10.7.3.
7870Sstevel@tonic-gate 				 *
7880Sstevel@tonic-gate 				 * so, unless the "su" is followed by a "s" or
7890Sstevel@tonic-gate 				 * a "!", we assume that the user means "s".
7900Sstevel@tonic-gate 				 */
7910Sstevel@tonic-gate 				switch (d = peekchar()) {
7920Sstevel@tonic-gate 				case 's':
7930Sstevel@tonic-gate 				case '!':
7940Sstevel@tonic-gate #endif /* XPG4 */
7950Sstevel@tonic-gate 					tail("suspend");
7960Sstevel@tonic-gate suspend:
7970Sstevel@tonic-gate 					c = exclam();
7980Sstevel@tonic-gate 					eol();
7990Sstevel@tonic-gate 					if (!c)
8000Sstevel@tonic-gate 						ckaw();
8010Sstevel@tonic-gate 					onsusp(0);
8020Sstevel@tonic-gate 					continue;
8030Sstevel@tonic-gate #ifdef XPG4
8040Sstevel@tonic-gate 				}
8050Sstevel@tonic-gate #endif /* XPG4 */
8060Sstevel@tonic-gate #endif
8070Sstevel@tonic-gate 
8080Sstevel@tonic-gate 			}
8090Sstevel@tonic-gate 			/* fall into ... */
8100Sstevel@tonic-gate 
8110Sstevel@tonic-gate /* & */
8120Sstevel@tonic-gate /* ~ */
8130Sstevel@tonic-gate /* substitute */
8140Sstevel@tonic-gate 		case '&':
8150Sstevel@tonic-gate 		case '~':
8160Sstevel@tonic-gate 			Command = (unsigned char *)"substitute";
8170Sstevel@tonic-gate 			if (c == 's')
8180Sstevel@tonic-gate 				tail(Command);
8190Sstevel@tonic-gate 			vmacchng(0);
8200Sstevel@tonic-gate 			if (!substitute(c))
8210Sstevel@tonic-gate 				pflag = 0;
8220Sstevel@tonic-gate 			continue;
8230Sstevel@tonic-gate 
8240Sstevel@tonic-gate /* t */
8250Sstevel@tonic-gate 		case 't':
8260Sstevel@tonic-gate 			if (peekchar() == 'a') {
8270Sstevel@tonic-gate 				tail("tag");
8280Sstevel@tonic-gate 				tagfind(exclam());
8290Sstevel@tonic-gate 				if (!inopen)
8300Sstevel@tonic-gate 					lchng = chng - 1;
8310Sstevel@tonic-gate 				else
8320Sstevel@tonic-gate 					nochng();
8330Sstevel@tonic-gate 				continue;
8340Sstevel@tonic-gate 			}
8350Sstevel@tonic-gate 			tail("t");
8360Sstevel@tonic-gate 			vmacchng(0);
8370Sstevel@tonic-gate 			vi_move();
8380Sstevel@tonic-gate 			continue;
8390Sstevel@tonic-gate 
8400Sstevel@tonic-gate 		case 'u':
8410Sstevel@tonic-gate 			if (peekchar() == 'n') {
8420Sstevel@tonic-gate 				ignchar();
8430Sstevel@tonic-gate 				switch (peekchar()) {
8440Sstevel@tonic-gate /* unmap */
8450Sstevel@tonic-gate 				case 'm':
8460Sstevel@tonic-gate 					tail2of("unmap");
8470Sstevel@tonic-gate 					setnoaddr();
8480Sstevel@tonic-gate 					mapcmd(1, 0);
8490Sstevel@tonic-gate 					continue;
8500Sstevel@tonic-gate /* unabbreviate */
8510Sstevel@tonic-gate 				case 'a':
8520Sstevel@tonic-gate 					tail2of("unabbreviate");
8530Sstevel@tonic-gate 					setnoaddr();
8540Sstevel@tonic-gate 					mapcmd(1, 1);
8550Sstevel@tonic-gate 					anyabbrs = 1;
8560Sstevel@tonic-gate 					continue;
8570Sstevel@tonic-gate 				}
8580Sstevel@tonic-gate /* undo */
8590Sstevel@tonic-gate 				tail2of("undo");
8600Sstevel@tonic-gate 			} else
8610Sstevel@tonic-gate 				tail("undo");
8620Sstevel@tonic-gate 			setnoaddr();
8630Sstevel@tonic-gate 			markDOT();
8640Sstevel@tonic-gate 			c = exclam();
8650Sstevel@tonic-gate 			donewline();
8660Sstevel@tonic-gate 			undo(c);
8670Sstevel@tonic-gate 			continue;
8680Sstevel@tonic-gate 
8690Sstevel@tonic-gate 		case 'v':
8700Sstevel@tonic-gate 			switch (peekchar()) {
8710Sstevel@tonic-gate 
8720Sstevel@tonic-gate 			case 'e':
8730Sstevel@tonic-gate /* version */
8740Sstevel@tonic-gate 				tail("version");
8750Sstevel@tonic-gate 				setNAEOL();
876*802Scf46844 				viprintf("%s", Version);
8770Sstevel@tonic-gate 				noonl();
8780Sstevel@tonic-gate 				continue;
8790Sstevel@tonic-gate 
8800Sstevel@tonic-gate /* visual */
8810Sstevel@tonic-gate 			case 'i':
8820Sstevel@tonic-gate 				tail("visual");
8830Sstevel@tonic-gate 				if (inopen) {
8840Sstevel@tonic-gate 					c = 'e';
8850Sstevel@tonic-gate 					goto editcmd;
8860Sstevel@tonic-gate 				}
8870Sstevel@tonic-gate 				vop();
8880Sstevel@tonic-gate 				pflag = 0;
8890Sstevel@tonic-gate 				nochng();
8900Sstevel@tonic-gate 				continue;
8910Sstevel@tonic-gate 			}
8920Sstevel@tonic-gate /* v */
8930Sstevel@tonic-gate 			tail("v");
8940Sstevel@tonic-gate 			global(0);
8950Sstevel@tonic-gate 			nochng();
8960Sstevel@tonic-gate 			continue;
8970Sstevel@tonic-gate 
8980Sstevel@tonic-gate /* write */
8990Sstevel@tonic-gate 		case 'w':
9000Sstevel@tonic-gate 			c = peekchar();
9010Sstevel@tonic-gate 			tail(c == 'q' ? "wq" : "write");
9020Sstevel@tonic-gate wq:
9030Sstevel@tonic-gate 			if (skipwh() && peekchar() == '!') {
9040Sstevel@tonic-gate 				pofix();
9050Sstevel@tonic-gate 				ignchar();
9060Sstevel@tonic-gate 				setall();
907500Sceastha 				unix0(0, 1);
908*802Scf46844 				(void) vi_filter(1);
9090Sstevel@tonic-gate 			} else {
9100Sstevel@tonic-gate 				setall();
9110Sstevel@tonic-gate 				if (c == 'q')
9120Sstevel@tonic-gate 					write_quit = 1;
9130Sstevel@tonic-gate 				else
9140Sstevel@tonic-gate 					write_quit = 0;
9150Sstevel@tonic-gate 				wop(1);
9160Sstevel@tonic-gate 				nochng();
9170Sstevel@tonic-gate 			}
9180Sstevel@tonic-gate 			if (c == 'q')
9190Sstevel@tonic-gate 				goto quit;
9200Sstevel@tonic-gate 			continue;
9210Sstevel@tonic-gate /* X: crypt */
9220Sstevel@tonic-gate 		case 'X':
9230Sstevel@tonic-gate 			crflag = -1; /* determine if file is encrypted */
9240Sstevel@tonic-gate 			goto ent_crypt;
9250Sstevel@tonic-gate 
9260Sstevel@tonic-gate 		case 'C':
9270Sstevel@tonic-gate 			crflag = 1;  /* assume files read in are encrypted */
9280Sstevel@tonic-gate 			goto ent_crypt;
9290Sstevel@tonic-gate 
9300Sstevel@tonic-gate /* xit */
9310Sstevel@tonic-gate 		case 'x':
9320Sstevel@tonic-gate 			tail("xit");
9330Sstevel@tonic-gate 			if (!chng)
9340Sstevel@tonic-gate 				goto quit;
9350Sstevel@tonic-gate 			c = 'q';
9360Sstevel@tonic-gate 			goto wq;
9370Sstevel@tonic-gate 
9380Sstevel@tonic-gate /* yank */
9390Sstevel@tonic-gate 		case 'y':
9400Sstevel@tonic-gate 			tail("yank");
9410Sstevel@tonic-gate 			c = cmdreg();
9420Sstevel@tonic-gate #ifdef XPG4ONLY
9430Sstevel@tonic-gate 			setcount2();
9440Sstevel@tonic-gate #else /* XPG6 and Solaris */
9450Sstevel@tonic-gate 			setcount();
9460Sstevel@tonic-gate #endif /* XPG4ONLY */
9470Sstevel@tonic-gate 			eol();
9480Sstevel@tonic-gate 			vmacchng(0);
9490Sstevel@tonic-gate 			if (c)
950*802Scf46844 				(void) YANKreg(c);
9510Sstevel@tonic-gate 			else
952*802Scf46844 				(void) yank();
9530Sstevel@tonic-gate 			continue;
9540Sstevel@tonic-gate 
9550Sstevel@tonic-gate /* z */
9560Sstevel@tonic-gate 		case 'z':
9570Sstevel@tonic-gate 			zop(0);
9580Sstevel@tonic-gate 			pflag = 0;
9590Sstevel@tonic-gate 			continue;
9600Sstevel@tonic-gate 
9610Sstevel@tonic-gate /* * */
9620Sstevel@tonic-gate /* @ */
9630Sstevel@tonic-gate 		case '*':
9640Sstevel@tonic-gate 		case '@':
9650Sstevel@tonic-gate 			c = getchar();
9660Sstevel@tonic-gate 			if (c == '\n' || c == '\r')
9670Sstevel@tonic-gate 				ungetchar(c);
9680Sstevel@tonic-gate 			if (any(c, "@*\n\r"))
9690Sstevel@tonic-gate 				c = lastmac;
9700Sstevel@tonic-gate 			if (isupper(c))
9710Sstevel@tonic-gate 				c = tolower(c);
9720Sstevel@tonic-gate 			if (!islower(c))
9730Sstevel@tonic-gate 				error(gettext("Bad register"));
9740Sstevel@tonic-gate 			donewline();
9750Sstevel@tonic-gate 			setdot();
9760Sstevel@tonic-gate 			cmdmac(c);
9770Sstevel@tonic-gate 			continue;
9780Sstevel@tonic-gate 
9790Sstevel@tonic-gate /* | */
9800Sstevel@tonic-gate 		case '|':
9810Sstevel@tonic-gate 			endline = 0;
9820Sstevel@tonic-gate 			goto caseline;
9830Sstevel@tonic-gate 
9840Sstevel@tonic-gate /* \n */
9850Sstevel@tonic-gate 		case '\n':
9860Sstevel@tonic-gate 			endline = 1;
9870Sstevel@tonic-gate caseline:
9880Sstevel@tonic-gate 			notempty();
9890Sstevel@tonic-gate 			if (addr2 == 0) {
9900Sstevel@tonic-gate 				if (cursor_up != NOSTR && c == '\n' &&
9910Sstevel@tonic-gate 				    !inglobal)
9920Sstevel@tonic-gate 					c = CTRL('k');
9930Sstevel@tonic-gate 				if (inglobal)
9940Sstevel@tonic-gate 					addr1 = addr2 = dot;
9950Sstevel@tonic-gate 				else {
9960Sstevel@tonic-gate 					if (dot == dol)
9970Sstevel@tonic-gate 						error((vi_TERSE) ?
9980Sstevel@tonic-gate 						    gettext("At EOF") :
9990Sstevel@tonic-gate 						    gettext("At end-of-file"));
10000Sstevel@tonic-gate 					addr1 = addr2 = dot + 1;
10010Sstevel@tonic-gate 				}
10020Sstevel@tonic-gate 			}
10030Sstevel@tonic-gate 			setdot();
10040Sstevel@tonic-gate 			nonzero();
10050Sstevel@tonic-gate 			if (seensemi)
10060Sstevel@tonic-gate 				addr1 = addr2;
10070Sstevel@tonic-gate 			getline(*addr1);
10080Sstevel@tonic-gate 			if (c == CTRL('k')) {
10090Sstevel@tonic-gate 				flush1();
10100Sstevel@tonic-gate 				destline--;
10110Sstevel@tonic-gate 				if (hadpr)
10120Sstevel@tonic-gate 					shudclob = 1;
10130Sstevel@tonic-gate 			}
10140Sstevel@tonic-gate 			plines(addr1, addr2, 1);
10150Sstevel@tonic-gate 			continue;
10160Sstevel@tonic-gate 
10170Sstevel@tonic-gate /* " */
10180Sstevel@tonic-gate 		case '"':
10190Sstevel@tonic-gate 			comment();
10200Sstevel@tonic-gate 			continue;
10210Sstevel@tonic-gate 
10220Sstevel@tonic-gate /* # */
10230Sstevel@tonic-gate 		case '#':
10240Sstevel@tonic-gate numberit:
10250Sstevel@tonic-gate 			setCNL();
10260Sstevel@tonic-gate 			(void) setnumb(1);
10270Sstevel@tonic-gate 			pflag = 0;
10280Sstevel@tonic-gate 			goto print;
10290Sstevel@tonic-gate 
10300Sstevel@tonic-gate /* = */
10310Sstevel@tonic-gate 		case '=':
10320Sstevel@tonic-gate 			donewline();
10330Sstevel@tonic-gate 			setall();
10340Sstevel@tonic-gate 			if (inglobal == 2)
10350Sstevel@tonic-gate 				pofix();
1036*802Scf46844 			viprintf("%d", lineno(addr2));
10370Sstevel@tonic-gate 			noonl();
10380Sstevel@tonic-gate 			continue;
10390Sstevel@tonic-gate 
10400Sstevel@tonic-gate /* ! */
10410Sstevel@tonic-gate 		case '!':
10420Sstevel@tonic-gate 			if (addr2 != 0) {
10430Sstevel@tonic-gate 				vmacchng(0);
1044500Sceastha 				unix0(0, 1);
10450Sstevel@tonic-gate 				setdot();
1046*802Scf46844 				(void) vi_filter(2);
10470Sstevel@tonic-gate 			} else {
1048500Sceastha 				unix0(1, 1);
10490Sstevel@tonic-gate 				pofix();
1050*802Scf46844 				putpad((unsigned char *)exit_ca_mode);
10510Sstevel@tonic-gate 				flush();
10520Sstevel@tonic-gate 				resetterm();
10530Sstevel@tonic-gate 				unixwt(1, unixex("-c", uxb, 0, 0));
10540Sstevel@tonic-gate 				vclrech(1);	/* vcontin(0); */
10550Sstevel@tonic-gate 				nochng();
10560Sstevel@tonic-gate 			}
10570Sstevel@tonic-gate 			continue;
10580Sstevel@tonic-gate 
10590Sstevel@tonic-gate /* < */
10600Sstevel@tonic-gate /* > */
10610Sstevel@tonic-gate 		case '<':
10620Sstevel@tonic-gate 		case '>':
10630Sstevel@tonic-gate 			for (cnt = 1; peekchar() == c; cnt++)
10640Sstevel@tonic-gate 				ignchar();
10650Sstevel@tonic-gate 			setCNL();
10660Sstevel@tonic-gate 			vmacchng(0);
10670Sstevel@tonic-gate 			shift(c, cnt);
10680Sstevel@tonic-gate 			continue;
10690Sstevel@tonic-gate 
10700Sstevel@tonic-gate /* ^D */
10710Sstevel@tonic-gate /* EOF */
10720Sstevel@tonic-gate 		case CTRL('d'):
10730Sstevel@tonic-gate 		case EOF:
10740Sstevel@tonic-gate 			if (exitoneof) {
10750Sstevel@tonic-gate 				if (addr2 != 0)
10760Sstevel@tonic-gate 					dot = addr2;
10770Sstevel@tonic-gate 				return;
10780Sstevel@tonic-gate 			}
10790Sstevel@tonic-gate 			if (!isatty(0)) {
10800Sstevel@tonic-gate 				if (intty)
10810Sstevel@tonic-gate 					/*
10820Sstevel@tonic-gate 					 * Chtty sys call at UCB may cause a
10830Sstevel@tonic-gate 					 * input which was a tty to suddenly be
10840Sstevel@tonic-gate 					 * turned into /dev/null.
10850Sstevel@tonic-gate 					 */
10860Sstevel@tonic-gate 					onhup(0);
10870Sstevel@tonic-gate 				return;
10880Sstevel@tonic-gate 			}
10890Sstevel@tonic-gate 			if (addr2 != 0) {
10900Sstevel@tonic-gate 				setlastchar('\n');
10910Sstevel@tonic-gate 				putnl();
10920Sstevel@tonic-gate 			}
10930Sstevel@tonic-gate 			if (dol == zero) {
10940Sstevel@tonic-gate 				if (addr2 == 0)
10950Sstevel@tonic-gate 					putnl();
10960Sstevel@tonic-gate 				notempty();
10970Sstevel@tonic-gate 			}
10980Sstevel@tonic-gate 			ungetchar(EOF);
10990Sstevel@tonic-gate 			zop(hadpr);
11000Sstevel@tonic-gate 			continue;
11010Sstevel@tonic-gate 		default:
11020Sstevel@tonic-gate 			if (!isalpha(c) || !isascii(c))
11030Sstevel@tonic-gate 				break;
11040Sstevel@tonic-gate 			ungetchar(c);
1105*802Scf46844 			tailprim((unsigned char *)"", 0, 0);
11060Sstevel@tonic-gate 		}
11070Sstevel@tonic-gate 		ungetchar(c);
11080Sstevel@tonic-gate 		{
11090Sstevel@tonic-gate 			int length;
11100Sstevel@tonic-gate 			char multic[MULTI_BYTE_MAX];
11110Sstevel@tonic-gate 			wchar_t wchar;
11120Sstevel@tonic-gate 			length = _mbftowc(multic, &wchar, getchar, &peekc);
11130Sstevel@tonic-gate 			if (length < 0)
11140Sstevel@tonic-gate 				length = -length;
11150Sstevel@tonic-gate 			multic[length] = '\0';
11160Sstevel@tonic-gate 			error((vi_TERSE) ? gettext("What?") :
11170Sstevel@tonic-gate 				gettext("Unknown command character '%s'"),
11180Sstevel@tonic-gate 			    multic);
11190Sstevel@tonic-gate 		}
11200Sstevel@tonic-gate 	}
11210Sstevel@tonic-gate }
1122