xref: /illumos-gate/usr/src/cmd/vi/port/ex_cmds.c (revision 4175e69a)
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
568c92b9fScf  * Common Development and Distribution License (the "License").
668c92b9fScf  * 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 
22ec427229Sceastha /*
2323a1cceaSRoger A. Faulkner  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24ec427229Sceastha  */
25ec427229Sceastha 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27*4175e69aSToomas Soome /*	  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_argv.h"
347c478bd9Sstevel@tonic-gate #include "ex_temp.h"
357c478bd9Sstevel@tonic-gate #include "ex_tty.h"
367c478bd9Sstevel@tonic-gate #include "ex_vis.h"
377c478bd9Sstevel@tonic-gate 
38*4175e69aSToomas Soome extern int getchar(void);
39*4175e69aSToomas Soome 
407c478bd9Sstevel@tonic-gate bool	pflag, nflag;
417c478bd9Sstevel@tonic-gate int	poffset;
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #define	nochng()	lchng = chng
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate /*
477c478bd9Sstevel@tonic-gate  * Main loop for command mode command decoding.
487c478bd9Sstevel@tonic-gate  * A few commands are executed here, but main function
497c478bd9Sstevel@tonic-gate  * is to strip command addresses, do a little address oriented
507c478bd9Sstevel@tonic-gate  * processing and call command routines to do the real work.
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate extern unsigned char *Version;
53f6db9f27Scf void
commands(noprompt,exitoneof)547c478bd9Sstevel@tonic-gate commands(noprompt, exitoneof)
557c478bd9Sstevel@tonic-gate 	bool noprompt, exitoneof;
567c478bd9Sstevel@tonic-gate {
577c478bd9Sstevel@tonic-gate 	line *addr;
587c478bd9Sstevel@tonic-gate 	int c;
597c478bd9Sstevel@tonic-gate 	int lchng;
607c478bd9Sstevel@tonic-gate 	int given;
617c478bd9Sstevel@tonic-gate 	int seensemi;
627c478bd9Sstevel@tonic-gate 	int cnt;
637c478bd9Sstevel@tonic-gate 	bool hadpr;
647c478bd9Sstevel@tonic-gate 	bool gotfile;
657c478bd9Sstevel@tonic-gate #ifdef XPG4
667c478bd9Sstevel@tonic-gate 	int d;
677c478bd9Sstevel@tonic-gate #endif /* XPG4 */
687c478bd9Sstevel@tonic-gate 	unsigned char *vgetpass();
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 	resetflav();
717c478bd9Sstevel@tonic-gate 	nochng();
727c478bd9Sstevel@tonic-gate 	for (;;) {
737c478bd9Sstevel@tonic-gate 		if (!firstpat)
747c478bd9Sstevel@tonic-gate 			laste = 0;
757c478bd9Sstevel@tonic-gate 		/*
767c478bd9Sstevel@tonic-gate 		 * If dot at last command
777c478bd9Sstevel@tonic-gate 		 * ended up at zero, advance to one if there is a such.
787c478bd9Sstevel@tonic-gate 		 */
797c478bd9Sstevel@tonic-gate 		if (dot <= zero) {
807c478bd9Sstevel@tonic-gate 			dot = zero;
817c478bd9Sstevel@tonic-gate 			if (dol > zero)
827c478bd9Sstevel@tonic-gate 				dot = one;
837c478bd9Sstevel@tonic-gate 		}
847c478bd9Sstevel@tonic-gate 		shudclob = 0;
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 		/*
877c478bd9Sstevel@tonic-gate 		 * If autoprint or trailing print flags,
887c478bd9Sstevel@tonic-gate 		 * print the line at the specified offset
897c478bd9Sstevel@tonic-gate 		 * before the next command.
907c478bd9Sstevel@tonic-gate 		 */
917c478bd9Sstevel@tonic-gate 		if ((pflag || lchng != chng && value(vi_AUTOPRINT) &&
927c478bd9Sstevel@tonic-gate 		    !inglobal && !inopen && endline) || poffset != 0) {
937c478bd9Sstevel@tonic-gate 			pflag = 0;
947c478bd9Sstevel@tonic-gate 			nochng();
957c478bd9Sstevel@tonic-gate 			if (dol != zero) {
967c478bd9Sstevel@tonic-gate 				addr1 = addr2 = dot + poffset;
977c478bd9Sstevel@tonic-gate 				poffset = 0;
987c478bd9Sstevel@tonic-gate 				if (addr1 < one || addr1 > dol)
997c478bd9Sstevel@tonic-gate 					error(value(vi_TERSE) ?
1007c478bd9Sstevel@tonic-gate 					    gettext("Offset out-of-bounds") :
1017c478bd9Sstevel@tonic-gate 					    gettext("Offset after command "
1027c478bd9Sstevel@tonic-gate 						"too large"));
1037c478bd9Sstevel@tonic-gate 				dot = addr1;
1047c478bd9Sstevel@tonic-gate 				setdot1();
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 				goto print;
1077c478bd9Sstevel@tonic-gate 			}
1087c478bd9Sstevel@tonic-gate 		}
1097c478bd9Sstevel@tonic-gate 		nochng();
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 		/*
1127c478bd9Sstevel@tonic-gate 		 * Print prompt if appropriate.
1137c478bd9Sstevel@tonic-gate 		 * If not in global flush output first to prevent
1147c478bd9Sstevel@tonic-gate 		 * going into pfast mode unreasonably.
1157c478bd9Sstevel@tonic-gate 		 */
1167c478bd9Sstevel@tonic-gate 		if (inglobal == 0) {
1177c478bd9Sstevel@tonic-gate 			flush();
1187c478bd9Sstevel@tonic-gate 			if (!hush && value(vi_PROMPT) && !globp &&
1197c478bd9Sstevel@tonic-gate 			    !noprompt && endline) {
1207c478bd9Sstevel@tonic-gate 				putchar(':');
1217c478bd9Sstevel@tonic-gate 				hadpr = 1;
1227c478bd9Sstevel@tonic-gate 			}
1237c478bd9Sstevel@tonic-gate 			TSYNC();
1247c478bd9Sstevel@tonic-gate 		}
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 		/*
1277c478bd9Sstevel@tonic-gate 		 * Gobble up the address.
1287c478bd9Sstevel@tonic-gate 		 * Degenerate addresses yield ".".
1297c478bd9Sstevel@tonic-gate 		 */
1307c478bd9Sstevel@tonic-gate 		addr2 = 0;
1317c478bd9Sstevel@tonic-gate 		given = seensemi = 0;
1327c478bd9Sstevel@tonic-gate 		do {
1337c478bd9Sstevel@tonic-gate 			addr1 = addr2;
1347c478bd9Sstevel@tonic-gate 			addr = address(0);
1357c478bd9Sstevel@tonic-gate 			c = getcd();
1367c478bd9Sstevel@tonic-gate 			if (addr == 0) {
1377c478bd9Sstevel@tonic-gate 				if (c == ',' || c == ';')
1387c478bd9Sstevel@tonic-gate 					addr = dot;
1397c478bd9Sstevel@tonic-gate 				else if (addr1 != 0) {
1407c478bd9Sstevel@tonic-gate 					addr2 = dot;
1417c478bd9Sstevel@tonic-gate 					break;
1427c478bd9Sstevel@tonic-gate 				} else
1437c478bd9Sstevel@tonic-gate 					break;
1447c478bd9Sstevel@tonic-gate 			}
1457c478bd9Sstevel@tonic-gate 			addr2 = addr;
1467c478bd9Sstevel@tonic-gate 			given++;
1477c478bd9Sstevel@tonic-gate 			if (c == ';') {
1487c478bd9Sstevel@tonic-gate 				c = ',';
1497c478bd9Sstevel@tonic-gate 				dot = addr;
1507c478bd9Sstevel@tonic-gate 				seensemi = 1;
1517c478bd9Sstevel@tonic-gate 			}
1527c478bd9Sstevel@tonic-gate 		} while (c == ',');
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 		if (c == '%') {
1557c478bd9Sstevel@tonic-gate 			/* %: same as 1,$ */
1567c478bd9Sstevel@tonic-gate 			addr1 = one;
1577c478bd9Sstevel@tonic-gate 			addr2 = dol;
1587c478bd9Sstevel@tonic-gate 			given = 2;
1597c478bd9Sstevel@tonic-gate 			c = getchar();
1607c478bd9Sstevel@tonic-gate 		}
1617c478bd9Sstevel@tonic-gate 		if (addr1 == 0)
1627c478bd9Sstevel@tonic-gate 			addr1 = addr2;
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 		/*
1657c478bd9Sstevel@tonic-gate 		 * eat multiple colons
1667c478bd9Sstevel@tonic-gate 		 */
1677c478bd9Sstevel@tonic-gate 		while (c == ':')
1687c478bd9Sstevel@tonic-gate 			c = getchar();
1697c478bd9Sstevel@tonic-gate 		/*
1707c478bd9Sstevel@tonic-gate 		 * Set command name for special character commands.
1717c478bd9Sstevel@tonic-gate 		 */
1727c478bd9Sstevel@tonic-gate 		tailspec(c);
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 		/*
1757c478bd9Sstevel@tonic-gate 		 * If called via : escape from open or visual, limit
1767c478bd9Sstevel@tonic-gate 		 * the set of available commands here to save work below.
1777c478bd9Sstevel@tonic-gate 		 */
1787c478bd9Sstevel@tonic-gate 		if (inopen) {
1797c478bd9Sstevel@tonic-gate 			if (c == '\n' || c == '\r' ||
1807c478bd9Sstevel@tonic-gate 			    c == CTRL('d') || c == EOF) {
1817c478bd9Sstevel@tonic-gate 				if (addr2)
1827c478bd9Sstevel@tonic-gate 					dot = addr2;
1837c478bd9Sstevel@tonic-gate 				if (c == EOF)
1847c478bd9Sstevel@tonic-gate 					return;
1857c478bd9Sstevel@tonic-gate 				continue;
1867c478bd9Sstevel@tonic-gate 			}
1877c478bd9Sstevel@tonic-gate 			if (any(c, "o"))
1887c478bd9Sstevel@tonic-gate notinvis:
1897c478bd9Sstevel@tonic-gate 				tailprim(Command, 1, 1);
1907c478bd9Sstevel@tonic-gate 		}
1917c478bd9Sstevel@tonic-gate 		switch (c) {
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 		case 'a':
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 			switch (peekchar()) {
1967c478bd9Sstevel@tonic-gate 			case 'b':
1977c478bd9Sstevel@tonic-gate /* abbreviate */
1987c478bd9Sstevel@tonic-gate 				tail("abbreviate");
1997c478bd9Sstevel@tonic-gate 				setnoaddr();
2007c478bd9Sstevel@tonic-gate 				mapcmd(0, 1);
2017c478bd9Sstevel@tonic-gate 				anyabbrs = 1;
2027c478bd9Sstevel@tonic-gate 				continue;
2037c478bd9Sstevel@tonic-gate 			case 'r':
2047c478bd9Sstevel@tonic-gate /* args */
2057c478bd9Sstevel@tonic-gate 				tail("args");
2067c478bd9Sstevel@tonic-gate 				setnoaddr();
2077c478bd9Sstevel@tonic-gate 				eol();
2087c478bd9Sstevel@tonic-gate 				pargs();
2097c478bd9Sstevel@tonic-gate 				continue;
2107c478bd9Sstevel@tonic-gate 			}
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate /* append */
2137c478bd9Sstevel@tonic-gate 			if (inopen)
2147c478bd9Sstevel@tonic-gate 				goto notinvis;
2157c478bd9Sstevel@tonic-gate 			tail("append");
2167c478bd9Sstevel@tonic-gate 			setdot();
2177c478bd9Sstevel@tonic-gate 			aiflag = exclam();
2187c478bd9Sstevel@tonic-gate 			donewline();
2197c478bd9Sstevel@tonic-gate 			vmacchng(0);
2207c478bd9Sstevel@tonic-gate 			deletenone();
2217c478bd9Sstevel@tonic-gate 			setin(addr2);
2227c478bd9Sstevel@tonic-gate 			inappend = 1;
2237c478bd9Sstevel@tonic-gate 			(void) append(gettty, addr2);
2247c478bd9Sstevel@tonic-gate 			inappend = 0;
2257c478bd9Sstevel@tonic-gate 			nochng();
2267c478bd9Sstevel@tonic-gate 			continue;
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate 		case 'c':
2297c478bd9Sstevel@tonic-gate 			switch (peekchar()) {
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate /* copy */
2327c478bd9Sstevel@tonic-gate 			case 'o':
2337c478bd9Sstevel@tonic-gate 				tail("copy");
2347c478bd9Sstevel@tonic-gate 				vmacchng(0);
2357c478bd9Sstevel@tonic-gate 				vi_move();
2367c478bd9Sstevel@tonic-gate 				continue;
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate /* crypt */
2397c478bd9Sstevel@tonic-gate 			case 'r':
2407c478bd9Sstevel@tonic-gate 				tail("crypt");
2417c478bd9Sstevel@tonic-gate 				crflag = -1;
2427c478bd9Sstevel@tonic-gate 			ent_crypt:
2437c478bd9Sstevel@tonic-gate 				setnoaddr();
2447c478bd9Sstevel@tonic-gate 				xflag = 1;
2457c478bd9Sstevel@tonic-gate 				if (permflag)
2467c478bd9Sstevel@tonic-gate 					(void) crypt_close(perm);
2477c478bd9Sstevel@tonic-gate 				permflag = 1;
2487c478bd9Sstevel@tonic-gate 				if ((kflag = run_setkey(perm,
2497c478bd9Sstevel@tonic-gate 				    (key = vgetpass(
2507c478bd9Sstevel@tonic-gate 					gettext("Enter key:"))))) == -1) {
2517c478bd9Sstevel@tonic-gate 					xflag = 0;
2527c478bd9Sstevel@tonic-gate 					kflag = 0;
2537c478bd9Sstevel@tonic-gate 					crflag = 0;
2547c478bd9Sstevel@tonic-gate 					smerror(gettext("Encryption facility "
2557c478bd9Sstevel@tonic-gate 						    "not available\n"));
2567c478bd9Sstevel@tonic-gate 				}
2577c478bd9Sstevel@tonic-gate 				if (kflag == 0)
2587c478bd9Sstevel@tonic-gate 					crflag = 0;
2597c478bd9Sstevel@tonic-gate 				continue;
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate /* cd */
2627c478bd9Sstevel@tonic-gate 			case 'd':
2637c478bd9Sstevel@tonic-gate 				tail("cd");
2647c478bd9Sstevel@tonic-gate 				goto changdir;
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate /* chdir */
2677c478bd9Sstevel@tonic-gate 			case 'h':
2687c478bd9Sstevel@tonic-gate 				ignchar();
2697c478bd9Sstevel@tonic-gate 				if (peekchar() == 'd') {
270f6db9f27Scf 					unsigned char *p;
2717c478bd9Sstevel@tonic-gate 					tail2of("chdir");
2727c478bd9Sstevel@tonic-gate changdir:
2737c478bd9Sstevel@tonic-gate 					if (savedfile[0] == '/' ||
2747c478bd9Sstevel@tonic-gate 					    !value(vi_WARN))
2757c478bd9Sstevel@tonic-gate 						(void) exclam();
2767c478bd9Sstevel@tonic-gate 					else
2777c478bd9Sstevel@tonic-gate 						(void) quickly();
2787c478bd9Sstevel@tonic-gate 					if (skipend()) {
2797c478bd9Sstevel@tonic-gate 						p = (unsigned char *)
2807c478bd9Sstevel@tonic-gate 						    getenv("HOME");
2817c478bd9Sstevel@tonic-gate 						if (p == NULL)
2827c478bd9Sstevel@tonic-gate 							error(gettext(
2837c478bd9Sstevel@tonic-gate 								"Home directory"
2847c478bd9Sstevel@tonic-gate 								    /*CSTYLED*/
2857c478bd9Sstevel@tonic-gate 								    " unknown"));
2867c478bd9Sstevel@tonic-gate 					} else
2877c478bd9Sstevel@tonic-gate 						getone(), p = file;
2887c478bd9Sstevel@tonic-gate 					eol();
289f6db9f27Scf 					if (chdir((char *)p) < 0)
2907c478bd9Sstevel@tonic-gate 						filioerr(p);
2917c478bd9Sstevel@tonic-gate 					if (savedfile[0] != '/')
2927c478bd9Sstevel@tonic-gate 						edited = 0;
2937c478bd9Sstevel@tonic-gate 					continue;
2947c478bd9Sstevel@tonic-gate 				}
2957c478bd9Sstevel@tonic-gate 				if (inopen)
296f6db9f27Scf 					tailprim((unsigned char *)"change",
297f6db9f27Scf 					    2, 1);
2987c478bd9Sstevel@tonic-gate 				tail2of("change");
2997c478bd9Sstevel@tonic-gate 				break;
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 			default:
3027c478bd9Sstevel@tonic-gate 				if (inopen)
3037c478bd9Sstevel@tonic-gate 					goto notinvis;
3047c478bd9Sstevel@tonic-gate 				tail("change");
3057c478bd9Sstevel@tonic-gate 				break;
3067c478bd9Sstevel@tonic-gate 			}
3077c478bd9Sstevel@tonic-gate /* change */
3087c478bd9Sstevel@tonic-gate 			aiflag = exclam();
3097c478bd9Sstevel@tonic-gate #ifdef XPG4ONLY
3107c478bd9Sstevel@tonic-gate 			setcount2();
3117c478bd9Sstevel@tonic-gate 			donewline();
3127c478bd9Sstevel@tonic-gate #else /* XPG6 and Solaris */
3137c478bd9Sstevel@tonic-gate 			setCNL();
3147c478bd9Sstevel@tonic-gate #endif /* XPG4ONLY */
3157c478bd9Sstevel@tonic-gate 			vmacchng(0);
3167c478bd9Sstevel@tonic-gate 			setin(addr1);
317f6db9f27Scf 			(void) delete(0);
3187c478bd9Sstevel@tonic-gate 			inappend = 1;
3197c478bd9Sstevel@tonic-gate 			if (append(gettty, addr1 - 1) == 0) {
3207c478bd9Sstevel@tonic-gate #ifdef XPG4
3217c478bd9Sstevel@tonic-gate 				/*
3227c478bd9Sstevel@tonic-gate 				 * P2003.2/D9:5.10.7.2.4, p. 646,
3237c478bd9Sstevel@tonic-gate 				 * assertion 214(A). If nothing changed,
3247c478bd9Sstevel@tonic-gate 				 * set dot to the line preceding the lines
3257c478bd9Sstevel@tonic-gate 				 * to be changed.
3267c478bd9Sstevel@tonic-gate 				 */
3277c478bd9Sstevel@tonic-gate 				dot = addr1 - 1;
3287c478bd9Sstevel@tonic-gate #else /* XPG4 */
3297c478bd9Sstevel@tonic-gate 				dot = addr1;
3307c478bd9Sstevel@tonic-gate #endif /* XPG4 */
3317c478bd9Sstevel@tonic-gate 				if (dot > dol)
3327c478bd9Sstevel@tonic-gate 					dot = dol;
3337c478bd9Sstevel@tonic-gate 			}
3347c478bd9Sstevel@tonic-gate 			inappend = 0;
3357c478bd9Sstevel@tonic-gate 			nochng();
3367c478bd9Sstevel@tonic-gate 			continue;
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate /* delete */
3397c478bd9Sstevel@tonic-gate 		case 'd':
3407c478bd9Sstevel@tonic-gate 			/*
3417c478bd9Sstevel@tonic-gate 			 * Caution: dp and dl have special meaning already.
3427c478bd9Sstevel@tonic-gate 			 */
3437c478bd9Sstevel@tonic-gate 			tail("delete");
3447c478bd9Sstevel@tonic-gate 			c = cmdreg();
3457c478bd9Sstevel@tonic-gate #ifdef XPG4ONLY
3467c478bd9Sstevel@tonic-gate 			setcount2();
3477c478bd9Sstevel@tonic-gate 			donewline();
3487c478bd9Sstevel@tonic-gate #else /* XPG6 and Solaris */
3497c478bd9Sstevel@tonic-gate 			setCNL();
3507c478bd9Sstevel@tonic-gate #endif /* XPG4ONLY */
3517c478bd9Sstevel@tonic-gate 			vmacchng(0);
3527c478bd9Sstevel@tonic-gate 			if (c)
353f6db9f27Scf 				(void) YANKreg(c);
354f6db9f27Scf 			(void) delete(0);
3557c478bd9Sstevel@tonic-gate 			appendnone();
3567c478bd9Sstevel@tonic-gate 			continue;
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate /* edit */
3597c478bd9Sstevel@tonic-gate /* ex */
3607c478bd9Sstevel@tonic-gate 		case 'e':
3617c478bd9Sstevel@tonic-gate 			if (crflag == 2 || crflag == -2)
3627c478bd9Sstevel@tonic-gate 				crflag = -1;
3637c478bd9Sstevel@tonic-gate 			tail(peekchar() == 'x' ? "ex" : "edit");
3647c478bd9Sstevel@tonic-gate editcmd:
3657c478bd9Sstevel@tonic-gate 			if (!exclam() && chng)
3667c478bd9Sstevel@tonic-gate 				c = 'E';
3677c478bd9Sstevel@tonic-gate 			gotfile = 0;
3687c478bd9Sstevel@tonic-gate 			if (c == 'E') {
3697c478bd9Sstevel@tonic-gate 				if (inopen && !value(vi_AUTOWRITE)) {
3707c478bd9Sstevel@tonic-gate 					filename(c);
3717c478bd9Sstevel@tonic-gate 					gotfile = 1;
3727c478bd9Sstevel@tonic-gate 				}
3737c478bd9Sstevel@tonic-gate 				ungetchar(lastchar());
3747c478bd9Sstevel@tonic-gate 				if (!exclam()) {
3757c478bd9Sstevel@tonic-gate 					ckaw();
3767c478bd9Sstevel@tonic-gate 					if (chng && dol > zero) {
3777c478bd9Sstevel@tonic-gate 						xchng = 0;
3787c478bd9Sstevel@tonic-gate 						error(value(vi_TERSE) ?
3797c478bd9Sstevel@tonic-gate 						    gettext("No write") :
3807c478bd9Sstevel@tonic-gate 						    gettext("No write since "
3817c478bd9Sstevel@tonic-gate 							"last change (:%s! "
3827c478bd9Sstevel@tonic-gate 							"overrides)"),
3837c478bd9Sstevel@tonic-gate 						    Command);
3847c478bd9Sstevel@tonic-gate 					}
3857c478bd9Sstevel@tonic-gate 				}
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate 			}
3887c478bd9Sstevel@tonic-gate 			if (gotfile == 0)
3897c478bd9Sstevel@tonic-gate 				filename(c);
3907c478bd9Sstevel@tonic-gate 			setnoaddr();
3917c478bd9Sstevel@tonic-gate doecmd:
3927c478bd9Sstevel@tonic-gate 			init();
3937c478bd9Sstevel@tonic-gate 			addr2 = zero;
3947c478bd9Sstevel@tonic-gate 			laste++;
3957c478bd9Sstevel@tonic-gate 			sync();
3967c478bd9Sstevel@tonic-gate 			rop(c);
3977c478bd9Sstevel@tonic-gate 			nochng();
3987c478bd9Sstevel@tonic-gate 			continue;
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate /* file */
4017c478bd9Sstevel@tonic-gate 		case 'f':
4027c478bd9Sstevel@tonic-gate 			tail("file");
4037c478bd9Sstevel@tonic-gate 			setnoaddr();
4047c478bd9Sstevel@tonic-gate 			filename(c);
4057c478bd9Sstevel@tonic-gate 			noonl();
4067c478bd9Sstevel@tonic-gate /*
4077c478bd9Sstevel@tonic-gate  *			synctmp();
4087c478bd9Sstevel@tonic-gate  */
4097c478bd9Sstevel@tonic-gate 			continue;
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate /* global */
4127c478bd9Sstevel@tonic-gate 		case 'g':
4137c478bd9Sstevel@tonic-gate 			tail("global");
4147c478bd9Sstevel@tonic-gate 			global(!exclam());
4157c478bd9Sstevel@tonic-gate 			nochng();
4167c478bd9Sstevel@tonic-gate 			continue;
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate /* insert */
4197c478bd9Sstevel@tonic-gate 		case 'i':
4207c478bd9Sstevel@tonic-gate 			if (inopen)
4217c478bd9Sstevel@tonic-gate 				goto notinvis;
4227c478bd9Sstevel@tonic-gate 			tail("insert");
4237c478bd9Sstevel@tonic-gate 			setdot();
4247c478bd9Sstevel@tonic-gate 			nonzero();
4257c478bd9Sstevel@tonic-gate 			aiflag = exclam();
4267c478bd9Sstevel@tonic-gate 			donewline();
4277c478bd9Sstevel@tonic-gate 			vmacchng(0);
4287c478bd9Sstevel@tonic-gate 			deletenone();
4297c478bd9Sstevel@tonic-gate 			setin(addr2);
4307c478bd9Sstevel@tonic-gate 			inappend = 1;
4317c478bd9Sstevel@tonic-gate 			(void) append(gettty, addr2 - 1);
4327c478bd9Sstevel@tonic-gate 			inappend = 0;
4337c478bd9Sstevel@tonic-gate 			if (dot == zero && dol > zero)
4347c478bd9Sstevel@tonic-gate 				dot = one;
4357c478bd9Sstevel@tonic-gate 			nochng();
4367c478bd9Sstevel@tonic-gate 			continue;
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate /* join */
4397c478bd9Sstevel@tonic-gate 		case 'j':
4407c478bd9Sstevel@tonic-gate 			tail("join");
4417c478bd9Sstevel@tonic-gate 			c = exclam();
4427c478bd9Sstevel@tonic-gate 			setcount();
4437c478bd9Sstevel@tonic-gate 			nonzero();
4447c478bd9Sstevel@tonic-gate 			donewline();
4457c478bd9Sstevel@tonic-gate 			vmacchng(0);
4467c478bd9Sstevel@tonic-gate #ifdef XPG4ONLY
4477c478bd9Sstevel@tonic-gate 			/*
4487c478bd9Sstevel@tonic-gate 			 * if no count was specified, addr1 == addr2. if only
4497c478bd9Sstevel@tonic-gate 			 * 1 range arg was specified, inc addr2 to allow
4507c478bd9Sstevel@tonic-gate 			 * joining of the next line.
4517c478bd9Sstevel@tonic-gate 			 */
4527c478bd9Sstevel@tonic-gate 			if (given < 2 && (addr1 == addr2) && (addr2 != dol))
4537c478bd9Sstevel@tonic-gate 				addr2++;
4547c478bd9Sstevel@tonic-gate 
4557c478bd9Sstevel@tonic-gate #else /* XPG6 and Solaris */
4567c478bd9Sstevel@tonic-gate 			if (given < 2 && addr2 != dol)
4577c478bd9Sstevel@tonic-gate 				addr2++;
4587c478bd9Sstevel@tonic-gate #endif /* XPG4ONLY */
459f6db9f27Scf 			(void) join(c);
4607c478bd9Sstevel@tonic-gate 			continue;
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate /* k */
4637c478bd9Sstevel@tonic-gate 		case 'k':
4647c478bd9Sstevel@tonic-gate casek:
4657c478bd9Sstevel@tonic-gate 			pastwh();
4667c478bd9Sstevel@tonic-gate 			c = getchar();
4677c478bd9Sstevel@tonic-gate 			if (endcmd(c))
468f6db9f27Scf 				serror((vi_TERSE) ?
469f6db9f27Scf 				    (unsigned char *)gettext("Mark what?") :
470f6db9f27Scf 				    (unsigned char *)
471f6db9f27Scf 				    gettext("%s requires following "
472f6db9f27Scf 				    "letter"), Command);
4737c478bd9Sstevel@tonic-gate 			donewline();
4747c478bd9Sstevel@tonic-gate 			if (!islower(c))
4757c478bd9Sstevel@tonic-gate 				error((vi_TERSE) ? gettext("Bad mark") :
4767c478bd9Sstevel@tonic-gate 					gettext("Mark must specify a letter"));
4777c478bd9Sstevel@tonic-gate 			setdot();
4787c478bd9Sstevel@tonic-gate 			nonzero();
4797c478bd9Sstevel@tonic-gate 			names[c - 'a'] = *addr2 &~ 01;
4807c478bd9Sstevel@tonic-gate 			anymarks = 1;
4817c478bd9Sstevel@tonic-gate 			continue;
4827c478bd9Sstevel@tonic-gate 
4837c478bd9Sstevel@tonic-gate /* list */
4847c478bd9Sstevel@tonic-gate 		case 'l':
4857c478bd9Sstevel@tonic-gate 			tail("list");
4867c478bd9Sstevel@tonic-gate #ifdef XPG4ONLY
4877c478bd9Sstevel@tonic-gate 			setcount2();
4887c478bd9Sstevel@tonic-gate 			donewline();
4897c478bd9Sstevel@tonic-gate #else /* XPG6 and Solaris */
4907c478bd9Sstevel@tonic-gate 			setCNL();
4917c478bd9Sstevel@tonic-gate #endif /* XPG4ONLY */
4927c478bd9Sstevel@tonic-gate 			(void) setlist(1);
4937c478bd9Sstevel@tonic-gate 			pflag = 0;
4947c478bd9Sstevel@tonic-gate 			goto print;
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate 		case 'm':
4977c478bd9Sstevel@tonic-gate 			if (peekchar() == 'a') {
4987c478bd9Sstevel@tonic-gate 				ignchar();
4997c478bd9Sstevel@tonic-gate 				if (peekchar() == 'p') {
5007c478bd9Sstevel@tonic-gate /* map */
5017c478bd9Sstevel@tonic-gate 					tail2of("map");
5027c478bd9Sstevel@tonic-gate 					setnoaddr();
5037c478bd9Sstevel@tonic-gate 					mapcmd(0, 0);
5047c478bd9Sstevel@tonic-gate 					continue;
5057c478bd9Sstevel@tonic-gate 				}
5067c478bd9Sstevel@tonic-gate /* mark */
5077c478bd9Sstevel@tonic-gate 				tail2of("mark");
5087c478bd9Sstevel@tonic-gate 				goto casek;
5097c478bd9Sstevel@tonic-gate 			}
5107c478bd9Sstevel@tonic-gate /* move */
5117c478bd9Sstevel@tonic-gate 			tail("move");
5127c478bd9Sstevel@tonic-gate 			vmacchng(0);
5137c478bd9Sstevel@tonic-gate 			vi_move();
5147c478bd9Sstevel@tonic-gate 			continue;
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate 		case 'n':
5177c478bd9Sstevel@tonic-gate 			if (peekchar() == 'u') {
5187c478bd9Sstevel@tonic-gate 				tail("number");
5197c478bd9Sstevel@tonic-gate 				goto numberit;
5207c478bd9Sstevel@tonic-gate 			}
5217c478bd9Sstevel@tonic-gate /* next */
5227c478bd9Sstevel@tonic-gate 			tail("next");
5237c478bd9Sstevel@tonic-gate 			setnoaddr();
5247c478bd9Sstevel@tonic-gate 			if (!exclam()) {
5257c478bd9Sstevel@tonic-gate 				ckaw();
5267c478bd9Sstevel@tonic-gate 				if (chng && dol > zero) {
5277c478bd9Sstevel@tonic-gate 					xchng = 0;
5287c478bd9Sstevel@tonic-gate 					error(value(vi_TERSE) ?
5297c478bd9Sstevel@tonic-gate 					    gettext("No write") :
5307c478bd9Sstevel@tonic-gate 					    gettext("No write since last "
5317c478bd9Sstevel@tonic-gate 						"change (:%s! overrides)"),
5327c478bd9Sstevel@tonic-gate 					    Command);
5337c478bd9Sstevel@tonic-gate 				}
5347c478bd9Sstevel@tonic-gate 			}
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate 			if (getargs())
5377c478bd9Sstevel@tonic-gate 				makargs();
5387c478bd9Sstevel@tonic-gate 			next();
5397c478bd9Sstevel@tonic-gate 			c = 'e';
5407c478bd9Sstevel@tonic-gate 			filename(c);
5417c478bd9Sstevel@tonic-gate 			goto doecmd;
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate /* open */
5447c478bd9Sstevel@tonic-gate 		case 'o':
5457c478bd9Sstevel@tonic-gate 			tail("open");
5467c478bd9Sstevel@tonic-gate 			oop();
5477c478bd9Sstevel@tonic-gate 			pflag = 0;
5487c478bd9Sstevel@tonic-gate 			nochng();
5497c478bd9Sstevel@tonic-gate 			continue;
5507c478bd9Sstevel@tonic-gate 
5517c478bd9Sstevel@tonic-gate 		case 'p':
5527c478bd9Sstevel@tonic-gate 		case 'P':
5537c478bd9Sstevel@tonic-gate 			switch (peekchar()) {
5547c478bd9Sstevel@tonic-gate #ifdef TAG_STACK
5557c478bd9Sstevel@tonic-gate /* pop */
5567c478bd9Sstevel@tonic-gate 			case 'o':
5577c478bd9Sstevel@tonic-gate 				tail("pop");
5587c478bd9Sstevel@tonic-gate 				poptag(exclam());
5597c478bd9Sstevel@tonic-gate 				if (!inopen)
5607c478bd9Sstevel@tonic-gate 					lchng = chng - 1;
5617c478bd9Sstevel@tonic-gate 				else
5627c478bd9Sstevel@tonic-gate 					nochng();
5637c478bd9Sstevel@tonic-gate 				continue;
5647c478bd9Sstevel@tonic-gate #endif
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate /* put */
5677c478bd9Sstevel@tonic-gate 			case 'u':
5687c478bd9Sstevel@tonic-gate 				tail("put");
5697c478bd9Sstevel@tonic-gate 				setdot();
5707c478bd9Sstevel@tonic-gate 				c = cmdreg();
5717c478bd9Sstevel@tonic-gate 				eol();
5727c478bd9Sstevel@tonic-gate 				vmacchng(0);
5737c478bd9Sstevel@tonic-gate 				if (c)
574f6db9f27Scf 					(void) putreg(c);
5757c478bd9Sstevel@tonic-gate 				else
576f6db9f27Scf 					(void) put();
5777c478bd9Sstevel@tonic-gate 				continue;
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate 			case 'r':
5807c478bd9Sstevel@tonic-gate 				ignchar();
5817c478bd9Sstevel@tonic-gate 				if (peekchar() == 'e') {
5827c478bd9Sstevel@tonic-gate /* preserve */
5837c478bd9Sstevel@tonic-gate 					tail2of("preserve");
5847c478bd9Sstevel@tonic-gate 					eol();
5857c478bd9Sstevel@tonic-gate 					if (preserve() == 0)
5867c478bd9Sstevel@tonic-gate 						error(gettext(
5877c478bd9Sstevel@tonic-gate 						    "Preserve failed!"));
5887c478bd9Sstevel@tonic-gate 					else {
5897c478bd9Sstevel@tonic-gate #ifdef XPG4
5907c478bd9Sstevel@tonic-gate 						/*
5917c478bd9Sstevel@tonic-gate 						 * error() incs errcnt. this is
5927c478bd9Sstevel@tonic-gate 						 * misleading here; and a
5937c478bd9Sstevel@tonic-gate 						 * violation of POSIX. so call
5947c478bd9Sstevel@tonic-gate 						 * noerror() instead.
5957c478bd9Sstevel@tonic-gate 						 * this is for assertion ex:222.
5967c478bd9Sstevel@tonic-gate 						 */
5977c478bd9Sstevel@tonic-gate 						noerror(
5987c478bd9Sstevel@tonic-gate 						    gettext("File preserved."));
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate #else /* XPG4 */
6017c478bd9Sstevel@tonic-gate 						error(
6027c478bd9Sstevel@tonic-gate 						    gettext("File preserved."));
6037c478bd9Sstevel@tonic-gate #endif /* XPG4 */
6047c478bd9Sstevel@tonic-gate 					}
6057c478bd9Sstevel@tonic-gate 				}
6067c478bd9Sstevel@tonic-gate 				tail2of("print");
6077c478bd9Sstevel@tonic-gate 				break;
6087c478bd9Sstevel@tonic-gate 
6097c478bd9Sstevel@tonic-gate 			default:
6107c478bd9Sstevel@tonic-gate 				tail("print");
6117c478bd9Sstevel@tonic-gate 				break;
6127c478bd9Sstevel@tonic-gate 			}
6137c478bd9Sstevel@tonic-gate /* print */
6147c478bd9Sstevel@tonic-gate 			setCNL();
6157c478bd9Sstevel@tonic-gate 			pflag = 0;
6167c478bd9Sstevel@tonic-gate print:
6177c478bd9Sstevel@tonic-gate 			nonzero();
6187c478bd9Sstevel@tonic-gate 			if (clear_screen && span() > lines) {
6197c478bd9Sstevel@tonic-gate 				flush1();
6207c478bd9Sstevel@tonic-gate 				vclear();
6217c478bd9Sstevel@tonic-gate 			}
6227c478bd9Sstevel@tonic-gate 			/*
6237c478bd9Sstevel@tonic-gate 			 * poffset is nonzero if trailing + or - flags
6247c478bd9Sstevel@tonic-gate 			 * were given, and in that case we need to
6257c478bd9Sstevel@tonic-gate 			 * adjust dot before printing a line.
6267c478bd9Sstevel@tonic-gate 			 */
6277c478bd9Sstevel@tonic-gate 			if (poffset == 0)
6287c478bd9Sstevel@tonic-gate 				plines(addr1, addr2, 1);
6297c478bd9Sstevel@tonic-gate 			else
6307c478bd9Sstevel@tonic-gate 				dot = addr2;
6317c478bd9Sstevel@tonic-gate 			continue;
6327c478bd9Sstevel@tonic-gate 
6337c478bd9Sstevel@tonic-gate /* quit */
6347c478bd9Sstevel@tonic-gate 		case 'q':
6357c478bd9Sstevel@tonic-gate 			tail("quit");
6367c478bd9Sstevel@tonic-gate 			setnoaddr();
6377c478bd9Sstevel@tonic-gate 			c = quickly();
6387c478bd9Sstevel@tonic-gate 			eol();
6397c478bd9Sstevel@tonic-gate 			if (!c)
6407c478bd9Sstevel@tonic-gate quit:
6417c478bd9Sstevel@tonic-gate 				if (nomore())
6427c478bd9Sstevel@tonic-gate 					continue;
6437c478bd9Sstevel@tonic-gate 			if (inopen) {
6447c478bd9Sstevel@tonic-gate 				vgoto(WECHO, 0);
6457c478bd9Sstevel@tonic-gate 				if (!ateopr())
6467c478bd9Sstevel@tonic-gate 					vnfl();
6477c478bd9Sstevel@tonic-gate 				else {
6487c478bd9Sstevel@tonic-gate 					tostop();
6497c478bd9Sstevel@tonic-gate 				}
6507c478bd9Sstevel@tonic-gate 				flush();
6517c478bd9Sstevel@tonic-gate 				setty(normf);
6527c478bd9Sstevel@tonic-gate 				ixlatctl(1);
6537c478bd9Sstevel@tonic-gate 			}
6547c478bd9Sstevel@tonic-gate 			cleanup(1);
6557c478bd9Sstevel@tonic-gate 			exit(errcnt);
6567c478bd9Sstevel@tonic-gate 
6577c478bd9Sstevel@tonic-gate 		case 'r':
6587c478bd9Sstevel@tonic-gate 			if (peekchar() == 'e') {
6597c478bd9Sstevel@tonic-gate 				ignchar();
6607c478bd9Sstevel@tonic-gate 				switch (peekchar()) {
6617c478bd9Sstevel@tonic-gate 
6627c478bd9Sstevel@tonic-gate /* rewind */
6637c478bd9Sstevel@tonic-gate 				case 'w':
6647c478bd9Sstevel@tonic-gate 					tail2of("rewind");
6657c478bd9Sstevel@tonic-gate 					setnoaddr();
6667c478bd9Sstevel@tonic-gate 					if (!exclam()) {
6677c478bd9Sstevel@tonic-gate 						ckaw();
6687c478bd9Sstevel@tonic-gate 						if (chng && dol > zero)
6697c478bd9Sstevel@tonic-gate 							error((vi_TERSE) ?
6707c478bd9Sstevel@tonic-gate 							    /*CSTYLED*/
6717c478bd9Sstevel@tonic-gate 							    gettext("No write") :
6727c478bd9Sstevel@tonic-gate 							    gettext("No write "
6737c478bd9Sstevel@tonic-gate 								"since last "
6747c478bd9Sstevel@tonic-gate 								"change (:rewi"
6757c478bd9Sstevel@tonic-gate 								/*CSTYLED*/
6767c478bd9Sstevel@tonic-gate 								"nd! overrides)"));
6777c478bd9Sstevel@tonic-gate 					}
6787c478bd9Sstevel@tonic-gate 					eol();
6797c478bd9Sstevel@tonic-gate 					erewind();
6807c478bd9Sstevel@tonic-gate 					next();
6817c478bd9Sstevel@tonic-gate 					c = 'e';
6827c478bd9Sstevel@tonic-gate 					ungetchar(lastchar());
6837c478bd9Sstevel@tonic-gate 					filename(c);
6847c478bd9Sstevel@tonic-gate 					goto doecmd;
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate /* recover */
6877c478bd9Sstevel@tonic-gate 				case 'c':
6887c478bd9Sstevel@tonic-gate 					tail2of("recover");
6897c478bd9Sstevel@tonic-gate 					setnoaddr();
6907c478bd9Sstevel@tonic-gate 					c = 'e';
6917c478bd9Sstevel@tonic-gate 					if (!exclam() && chng)
6927c478bd9Sstevel@tonic-gate 						c = 'E';
6937c478bd9Sstevel@tonic-gate 					filename(c);
6947c478bd9Sstevel@tonic-gate 					if (c == 'E') {
6957c478bd9Sstevel@tonic-gate 						ungetchar(lastchar());
6967c478bd9Sstevel@tonic-gate 						(void) quickly();
6977c478bd9Sstevel@tonic-gate 					}
6987c478bd9Sstevel@tonic-gate 					init();
6997c478bd9Sstevel@tonic-gate 					addr2 = zero;
7007c478bd9Sstevel@tonic-gate 					laste++;
7017c478bd9Sstevel@tonic-gate 					sync();
7027c478bd9Sstevel@tonic-gate 					recover();
7037c478bd9Sstevel@tonic-gate 					rop2();
7047c478bd9Sstevel@tonic-gate 					revocer();
7057c478bd9Sstevel@tonic-gate 					if (status == 0)
7067c478bd9Sstevel@tonic-gate 						rop3(c);
7077c478bd9Sstevel@tonic-gate 					if (dol != zero)
7087c478bd9Sstevel@tonic-gate 						change();
7097c478bd9Sstevel@tonic-gate 					nochng();
7107c478bd9Sstevel@tonic-gate 					continue;
7117c478bd9Sstevel@tonic-gate 				}
7127c478bd9Sstevel@tonic-gate 				tail2of("read");
7137c478bd9Sstevel@tonic-gate 			} else
7147c478bd9Sstevel@tonic-gate 				tail("read");
7157c478bd9Sstevel@tonic-gate /* read */
7167c478bd9Sstevel@tonic-gate 			if (crflag == 2 || crflag == -2)
7177c478bd9Sstevel@tonic-gate 			/* restore crflag for new input text */
7187c478bd9Sstevel@tonic-gate 				crflag = -1;
7197c478bd9Sstevel@tonic-gate 			if (savedfile[0] == 0 && dol == zero)
7207c478bd9Sstevel@tonic-gate 				c = 'e';
7217c478bd9Sstevel@tonic-gate 			pastwh();
7227c478bd9Sstevel@tonic-gate 			vmacchng(0);
7237c478bd9Sstevel@tonic-gate 			if (peekchar() == '!') {
7247c478bd9Sstevel@tonic-gate 				setdot();
7257c478bd9Sstevel@tonic-gate 				ignchar();
726ec427229Sceastha 				unix0(0, 1);
727f6db9f27Scf 				(void) vi_filter(0);
7287c478bd9Sstevel@tonic-gate 				continue;
7297c478bd9Sstevel@tonic-gate 			}
7307c478bd9Sstevel@tonic-gate 			filename(c);
7317c478bd9Sstevel@tonic-gate 			rop(c);
7327c478bd9Sstevel@tonic-gate 			nochng();
7337c478bd9Sstevel@tonic-gate 			if (inopen && endline && addr1 > zero && addr1 < dol)
7347c478bd9Sstevel@tonic-gate 				dot = addr1 + 1;
7357c478bd9Sstevel@tonic-gate 			continue;
7367c478bd9Sstevel@tonic-gate 
7377c478bd9Sstevel@tonic-gate 		case 's':
7387c478bd9Sstevel@tonic-gate 			switch (peekchar()) {
7397c478bd9Sstevel@tonic-gate 			/*
7407c478bd9Sstevel@tonic-gate 			 * Caution: 2nd char cannot be c, g, or r
7417c478bd9Sstevel@tonic-gate 			 * because these have meaning to substitute.
7427c478bd9Sstevel@tonic-gate 			 */
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate /* set */
7457c478bd9Sstevel@tonic-gate 			case 'e':
7467c478bd9Sstevel@tonic-gate 				tail("set");
7477c478bd9Sstevel@tonic-gate 				setnoaddr();
7487c478bd9Sstevel@tonic-gate 				set();
7497c478bd9Sstevel@tonic-gate 				continue;
7507c478bd9Sstevel@tonic-gate 
7517c478bd9Sstevel@tonic-gate /* shell */
7527c478bd9Sstevel@tonic-gate 			case 'h':
7537c478bd9Sstevel@tonic-gate 				tail("shell");
7547c478bd9Sstevel@tonic-gate 				setNAEOL();
7557c478bd9Sstevel@tonic-gate 				vnfl();
756f6db9f27Scf 				putpad((unsigned char *)exit_ca_mode);
7577c478bd9Sstevel@tonic-gate 				flush();
7587c478bd9Sstevel@tonic-gate 				resetterm();
7597c478bd9Sstevel@tonic-gate 				unixwt(1, unixex("-i", (char *)0, 0, 0));
7607c478bd9Sstevel@tonic-gate 				vcontin(0);
7617c478bd9Sstevel@tonic-gate 				continue;
7627c478bd9Sstevel@tonic-gate 
7637c478bd9Sstevel@tonic-gate /* source */
7647c478bd9Sstevel@tonic-gate 			case 'o':
7657c478bd9Sstevel@tonic-gate #ifdef notdef
7667c478bd9Sstevel@tonic-gate 				if (inopen)
7677c478bd9Sstevel@tonic-gate 					goto notinvis;
7687c478bd9Sstevel@tonic-gate #endif
7697c478bd9Sstevel@tonic-gate 				tail("source");
7707c478bd9Sstevel@tonic-gate 				setnoaddr();
7717c478bd9Sstevel@tonic-gate 				getone();
7727c478bd9Sstevel@tonic-gate 				eol();
7737c478bd9Sstevel@tonic-gate 				source(file, 0);
7747c478bd9Sstevel@tonic-gate 				continue;
7757c478bd9Sstevel@tonic-gate #ifdef SIGTSTP
7767c478bd9Sstevel@tonic-gate /* stop, suspend */
7777c478bd9Sstevel@tonic-gate 			case 't':
7787c478bd9Sstevel@tonic-gate 				tail("stop");
7797c478bd9Sstevel@tonic-gate 				goto suspend;
7807c478bd9Sstevel@tonic-gate 			case 'u':
7817c478bd9Sstevel@tonic-gate #ifdef XPG4
7827c478bd9Sstevel@tonic-gate 				/*
7837c478bd9Sstevel@tonic-gate 				 * for POSIX, "su" with no other distinguishing
7847c478bd9Sstevel@tonic-gate 				 * characteristics, maps to "s". Re. P1003.D11,
7857c478bd9Sstevel@tonic-gate 				 * 5.10.7.3.
7867c478bd9Sstevel@tonic-gate 				 *
7877c478bd9Sstevel@tonic-gate 				 * so, unless the "su" is followed by a "s" or
7887c478bd9Sstevel@tonic-gate 				 * a "!", we assume that the user means "s".
7897c478bd9Sstevel@tonic-gate 				 */
7907c478bd9Sstevel@tonic-gate 				switch (d = peekchar()) {
7917c478bd9Sstevel@tonic-gate 				case 's':
7927c478bd9Sstevel@tonic-gate 				case '!':
7937c478bd9Sstevel@tonic-gate #endif /* XPG4 */
7947c478bd9Sstevel@tonic-gate 					tail("suspend");
7957c478bd9Sstevel@tonic-gate suspend:
7967c478bd9Sstevel@tonic-gate 					c = exclam();
7977c478bd9Sstevel@tonic-gate 					eol();
7987c478bd9Sstevel@tonic-gate 					if (!c)
7997c478bd9Sstevel@tonic-gate 						ckaw();
8007c478bd9Sstevel@tonic-gate 					onsusp(0);
8017c478bd9Sstevel@tonic-gate 					continue;
8027c478bd9Sstevel@tonic-gate #ifdef XPG4
8037c478bd9Sstevel@tonic-gate 				}
8047c478bd9Sstevel@tonic-gate #endif /* XPG4 */
8057c478bd9Sstevel@tonic-gate #endif
8067c478bd9Sstevel@tonic-gate 
8077c478bd9Sstevel@tonic-gate 			}
8089097ca5cSToomas Soome 			/* FALLTHROUGH */
8097c478bd9Sstevel@tonic-gate 
8107c478bd9Sstevel@tonic-gate /* & */
8117c478bd9Sstevel@tonic-gate /* ~ */
8127c478bd9Sstevel@tonic-gate /* substitute */
8137c478bd9Sstevel@tonic-gate 		case '&':
8147c478bd9Sstevel@tonic-gate 		case '~':
8157c478bd9Sstevel@tonic-gate 			Command = (unsigned char *)"substitute";
8167c478bd9Sstevel@tonic-gate 			if (c == 's')
8177c478bd9Sstevel@tonic-gate 				tail(Command);
8187c478bd9Sstevel@tonic-gate 			vmacchng(0);
8197c478bd9Sstevel@tonic-gate 			if (!substitute(c))
8207c478bd9Sstevel@tonic-gate 				pflag = 0;
8217c478bd9Sstevel@tonic-gate 			continue;
8227c478bd9Sstevel@tonic-gate 
8237c478bd9Sstevel@tonic-gate /* t */
8247c478bd9Sstevel@tonic-gate 		case 't':
8257c478bd9Sstevel@tonic-gate 			if (peekchar() == 'a') {
82668c92b9fScf 				tagflg = 1; /* :tag command */
8277c478bd9Sstevel@tonic-gate 				tail("tag");
8287c478bd9Sstevel@tonic-gate 				tagfind(exclam());
82968c92b9fScf 				tagflg = 0;
8307c478bd9Sstevel@tonic-gate 				if (!inopen)
8317c478bd9Sstevel@tonic-gate 					lchng = chng - 1;
8327c478bd9Sstevel@tonic-gate 				else
8337c478bd9Sstevel@tonic-gate 					nochng();
8347c478bd9Sstevel@tonic-gate 				continue;
8357c478bd9Sstevel@tonic-gate 			}
8367c478bd9Sstevel@tonic-gate 			tail("t");
8377c478bd9Sstevel@tonic-gate 			vmacchng(0);
8387c478bd9Sstevel@tonic-gate 			vi_move();
8397c478bd9Sstevel@tonic-gate 			continue;
8407c478bd9Sstevel@tonic-gate 
8417c478bd9Sstevel@tonic-gate 		case 'u':
8427c478bd9Sstevel@tonic-gate 			if (peekchar() == 'n') {
8437c478bd9Sstevel@tonic-gate 				ignchar();
8447c478bd9Sstevel@tonic-gate 				switch (peekchar()) {
8457c478bd9Sstevel@tonic-gate /* unmap */
8467c478bd9Sstevel@tonic-gate 				case 'm':
8477c478bd9Sstevel@tonic-gate 					tail2of("unmap");
8487c478bd9Sstevel@tonic-gate 					setnoaddr();
8497c478bd9Sstevel@tonic-gate 					mapcmd(1, 0);
8507c478bd9Sstevel@tonic-gate 					continue;
8517c478bd9Sstevel@tonic-gate /* unabbreviate */
8527c478bd9Sstevel@tonic-gate 				case 'a':
8537c478bd9Sstevel@tonic-gate 					tail2of("unabbreviate");
8547c478bd9Sstevel@tonic-gate 					setnoaddr();
8557c478bd9Sstevel@tonic-gate 					mapcmd(1, 1);
8567c478bd9Sstevel@tonic-gate 					anyabbrs = 1;
8577c478bd9Sstevel@tonic-gate 					continue;
8587c478bd9Sstevel@tonic-gate 				}
8597c478bd9Sstevel@tonic-gate /* undo */
8607c478bd9Sstevel@tonic-gate 				tail2of("undo");
8617c478bd9Sstevel@tonic-gate 			} else
8627c478bd9Sstevel@tonic-gate 				tail("undo");
8637c478bd9Sstevel@tonic-gate 			setnoaddr();
8647c478bd9Sstevel@tonic-gate 			markDOT();
8657c478bd9Sstevel@tonic-gate 			c = exclam();
8667c478bd9Sstevel@tonic-gate 			donewline();
8677c478bd9Sstevel@tonic-gate 			undo(c);
8687c478bd9Sstevel@tonic-gate 			continue;
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate 		case 'v':
8717c478bd9Sstevel@tonic-gate 			switch (peekchar()) {
8727c478bd9Sstevel@tonic-gate 
8737c478bd9Sstevel@tonic-gate 			case 'e':
8747c478bd9Sstevel@tonic-gate /* version */
8757c478bd9Sstevel@tonic-gate 				tail("version");
8767c478bd9Sstevel@tonic-gate 				setNAEOL();
877f6db9f27Scf 				viprintf("%s", Version);
8787c478bd9Sstevel@tonic-gate 				noonl();
8797c478bd9Sstevel@tonic-gate 				continue;
8807c478bd9Sstevel@tonic-gate 
8817c478bd9Sstevel@tonic-gate /* visual */
8827c478bd9Sstevel@tonic-gate 			case 'i':
8837c478bd9Sstevel@tonic-gate 				tail("visual");
8847c478bd9Sstevel@tonic-gate 				if (inopen) {
8857c478bd9Sstevel@tonic-gate 					c = 'e';
8867c478bd9Sstevel@tonic-gate 					goto editcmd;
8877c478bd9Sstevel@tonic-gate 				}
8887c478bd9Sstevel@tonic-gate 				vop();
8897c478bd9Sstevel@tonic-gate 				pflag = 0;
8907c478bd9Sstevel@tonic-gate 				nochng();
8917c478bd9Sstevel@tonic-gate 				continue;
8927c478bd9Sstevel@tonic-gate 			}
8937c478bd9Sstevel@tonic-gate /* v */
8947c478bd9Sstevel@tonic-gate 			tail("v");
8957c478bd9Sstevel@tonic-gate 			global(0);
8967c478bd9Sstevel@tonic-gate 			nochng();
8977c478bd9Sstevel@tonic-gate 			continue;
8987c478bd9Sstevel@tonic-gate 
8997c478bd9Sstevel@tonic-gate /* write */
9007c478bd9Sstevel@tonic-gate 		case 'w':
9017c478bd9Sstevel@tonic-gate 			c = peekchar();
9027c478bd9Sstevel@tonic-gate 			tail(c == 'q' ? "wq" : "write");
9037c478bd9Sstevel@tonic-gate wq:
9047c478bd9Sstevel@tonic-gate 			if (skipwh() && peekchar() == '!') {
9057c478bd9Sstevel@tonic-gate 				pofix();
9067c478bd9Sstevel@tonic-gate 				ignchar();
9077c478bd9Sstevel@tonic-gate 				setall();
908ec427229Sceastha 				unix0(0, 1);
909f6db9f27Scf 				(void) vi_filter(1);
9107c478bd9Sstevel@tonic-gate 			} else {
9117c478bd9Sstevel@tonic-gate 				setall();
9127c478bd9Sstevel@tonic-gate 				if (c == 'q')
9137c478bd9Sstevel@tonic-gate 					write_quit = 1;
9147c478bd9Sstevel@tonic-gate 				else
9157c478bd9Sstevel@tonic-gate 					write_quit = 0;
9167c478bd9Sstevel@tonic-gate 				wop(1);
9177c478bd9Sstevel@tonic-gate 				nochng();
9187c478bd9Sstevel@tonic-gate 			}
9197c478bd9Sstevel@tonic-gate 			if (c == 'q')
9207c478bd9Sstevel@tonic-gate 				goto quit;
9217c478bd9Sstevel@tonic-gate 			continue;
9227c478bd9Sstevel@tonic-gate /* X: crypt */
9237c478bd9Sstevel@tonic-gate 		case 'X':
9247c478bd9Sstevel@tonic-gate 			crflag = -1; /* determine if file is encrypted */
9257c478bd9Sstevel@tonic-gate 			goto ent_crypt;
9267c478bd9Sstevel@tonic-gate 
9277c478bd9Sstevel@tonic-gate 		case 'C':
9287c478bd9Sstevel@tonic-gate 			crflag = 1;  /* assume files read in are encrypted */
9297c478bd9Sstevel@tonic-gate 			goto ent_crypt;
9307c478bd9Sstevel@tonic-gate 
9317c478bd9Sstevel@tonic-gate /* xit */
9327c478bd9Sstevel@tonic-gate 		case 'x':
9337c478bd9Sstevel@tonic-gate 			tail("xit");
9347c478bd9Sstevel@tonic-gate 			if (!chng)
9357c478bd9Sstevel@tonic-gate 				goto quit;
9367c478bd9Sstevel@tonic-gate 			c = 'q';
9377c478bd9Sstevel@tonic-gate 			goto wq;
9387c478bd9Sstevel@tonic-gate 
9397c478bd9Sstevel@tonic-gate /* yank */
9407c478bd9Sstevel@tonic-gate 		case 'y':
9417c478bd9Sstevel@tonic-gate 			tail("yank");
9427c478bd9Sstevel@tonic-gate 			c = cmdreg();
9437c478bd9Sstevel@tonic-gate #ifdef XPG4ONLY
9447c478bd9Sstevel@tonic-gate 			setcount2();
9457c478bd9Sstevel@tonic-gate #else /* XPG6 and Solaris */
9467c478bd9Sstevel@tonic-gate 			setcount();
9477c478bd9Sstevel@tonic-gate #endif /* XPG4ONLY */
9487c478bd9Sstevel@tonic-gate 			eol();
9497c478bd9Sstevel@tonic-gate 			vmacchng(0);
9507c478bd9Sstevel@tonic-gate 			if (c)
951f6db9f27Scf 				(void) YANKreg(c);
9527c478bd9Sstevel@tonic-gate 			else
953f6db9f27Scf 				(void) yank();
9547c478bd9Sstevel@tonic-gate 			continue;
9557c478bd9Sstevel@tonic-gate 
9567c478bd9Sstevel@tonic-gate /* z */
9577c478bd9Sstevel@tonic-gate 		case 'z':
9587c478bd9Sstevel@tonic-gate 			zop(0);
9597c478bd9Sstevel@tonic-gate 			pflag = 0;
9607c478bd9Sstevel@tonic-gate 			continue;
9617c478bd9Sstevel@tonic-gate 
9627c478bd9Sstevel@tonic-gate /* * */
9637c478bd9Sstevel@tonic-gate /* @ */
9647c478bd9Sstevel@tonic-gate 		case '*':
9657c478bd9Sstevel@tonic-gate 		case '@':
9667c478bd9Sstevel@tonic-gate 			c = getchar();
9677c478bd9Sstevel@tonic-gate 			if (c == '\n' || c == '\r')
9687c478bd9Sstevel@tonic-gate 				ungetchar(c);
9697c478bd9Sstevel@tonic-gate 			if (any(c, "@*\n\r"))
9707c478bd9Sstevel@tonic-gate 				c = lastmac;
9717c478bd9Sstevel@tonic-gate 			if (isupper(c))
9727c478bd9Sstevel@tonic-gate 				c = tolower(c);
9737c478bd9Sstevel@tonic-gate 			if (!islower(c))
9747c478bd9Sstevel@tonic-gate 				error(gettext("Bad register"));
9757c478bd9Sstevel@tonic-gate 			donewline();
9767c478bd9Sstevel@tonic-gate 			setdot();
9777c478bd9Sstevel@tonic-gate 			cmdmac(c);
9787c478bd9Sstevel@tonic-gate 			continue;
9797c478bd9Sstevel@tonic-gate 
9807c478bd9Sstevel@tonic-gate /* | */
9817c478bd9Sstevel@tonic-gate 		case '|':
9827c478bd9Sstevel@tonic-gate 			endline = 0;
9837c478bd9Sstevel@tonic-gate 			goto caseline;
9847c478bd9Sstevel@tonic-gate 
9857c478bd9Sstevel@tonic-gate /* \n */
9867c478bd9Sstevel@tonic-gate 		case '\n':
9877c478bd9Sstevel@tonic-gate 			endline = 1;
9887c478bd9Sstevel@tonic-gate caseline:
9897c478bd9Sstevel@tonic-gate 			notempty();
9907c478bd9Sstevel@tonic-gate 			if (addr2 == 0) {
9917c478bd9Sstevel@tonic-gate 				if (cursor_up != NOSTR && c == '\n' &&
9927c478bd9Sstevel@tonic-gate 				    !inglobal)
9937c478bd9Sstevel@tonic-gate 					c = CTRL('k');
9947c478bd9Sstevel@tonic-gate 				if (inglobal)
9957c478bd9Sstevel@tonic-gate 					addr1 = addr2 = dot;
9967c478bd9Sstevel@tonic-gate 				else {
9977c478bd9Sstevel@tonic-gate 					if (dot == dol)
9987c478bd9Sstevel@tonic-gate 						error((vi_TERSE) ?
9997c478bd9Sstevel@tonic-gate 						    gettext("At EOF") :
10007c478bd9Sstevel@tonic-gate 						    gettext("At end-of-file"));
10017c478bd9Sstevel@tonic-gate 					addr1 = addr2 = dot + 1;
10027c478bd9Sstevel@tonic-gate 				}
10037c478bd9Sstevel@tonic-gate 			}
10047c478bd9Sstevel@tonic-gate 			setdot();
10057c478bd9Sstevel@tonic-gate 			nonzero();
10067c478bd9Sstevel@tonic-gate 			if (seensemi)
10077c478bd9Sstevel@tonic-gate 				addr1 = addr2;
100823a1cceaSRoger A. Faulkner 			getaline(*addr1);
10097c478bd9Sstevel@tonic-gate 			if (c == CTRL('k')) {
10107c478bd9Sstevel@tonic-gate 				flush1();
10117c478bd9Sstevel@tonic-gate 				destline--;
10127c478bd9Sstevel@tonic-gate 				if (hadpr)
10137c478bd9Sstevel@tonic-gate 					shudclob = 1;
10147c478bd9Sstevel@tonic-gate 			}
10157c478bd9Sstevel@tonic-gate 			plines(addr1, addr2, 1);
10167c478bd9Sstevel@tonic-gate 			continue;
10177c478bd9Sstevel@tonic-gate 
10187c478bd9Sstevel@tonic-gate /* " */
10197c478bd9Sstevel@tonic-gate 		case '"':
10207c478bd9Sstevel@tonic-gate 			comment();
10217c478bd9Sstevel@tonic-gate 			continue;
10227c478bd9Sstevel@tonic-gate 
10237c478bd9Sstevel@tonic-gate /* # */
10247c478bd9Sstevel@tonic-gate 		case '#':
10257c478bd9Sstevel@tonic-gate numberit:
10267c478bd9Sstevel@tonic-gate 			setCNL();
10277c478bd9Sstevel@tonic-gate 			(void) setnumb(1);
10287c478bd9Sstevel@tonic-gate 			pflag = 0;
10297c478bd9Sstevel@tonic-gate 			goto print;
10307c478bd9Sstevel@tonic-gate 
10317c478bd9Sstevel@tonic-gate /* = */
10327c478bd9Sstevel@tonic-gate 		case '=':
10337c478bd9Sstevel@tonic-gate 			donewline();
10347c478bd9Sstevel@tonic-gate 			setall();
10357c478bd9Sstevel@tonic-gate 			if (inglobal == 2)
10367c478bd9Sstevel@tonic-gate 				pofix();
1037f6db9f27Scf 			viprintf("%d", lineno(addr2));
10387c478bd9Sstevel@tonic-gate 			noonl();
10397c478bd9Sstevel@tonic-gate 			continue;
10407c478bd9Sstevel@tonic-gate 
10417c478bd9Sstevel@tonic-gate /* ! */
10427c478bd9Sstevel@tonic-gate 		case '!':
10437c478bd9Sstevel@tonic-gate 			if (addr2 != 0) {
10447c478bd9Sstevel@tonic-gate 				vmacchng(0);
1045ec427229Sceastha 				unix0(0, 1);
10467c478bd9Sstevel@tonic-gate 				setdot();
1047f6db9f27Scf 				(void) vi_filter(2);
10487c478bd9Sstevel@tonic-gate 			} else {
1049ec427229Sceastha 				unix0(1, 1);
10507c478bd9Sstevel@tonic-gate 				pofix();
1051f6db9f27Scf 				putpad((unsigned char *)exit_ca_mode);
10527c478bd9Sstevel@tonic-gate 				flush();
10537c478bd9Sstevel@tonic-gate 				resetterm();
105468c92b9fScf 				if (!tagflg) {
105568c92b9fScf 					unixwt(1, unixex("-c", uxb, 0, 0));
105668c92b9fScf 				} else {
105768c92b9fScf 					error(gettext("Invalid tags file:"
105868c92b9fScf 					    " contains shell escape"));
105968c92b9fScf 				}
10607c478bd9Sstevel@tonic-gate 				vclrech(1);	/* vcontin(0); */
10617c478bd9Sstevel@tonic-gate 				nochng();
10627c478bd9Sstevel@tonic-gate 			}
10637c478bd9Sstevel@tonic-gate 			continue;
10647c478bd9Sstevel@tonic-gate 
10657c478bd9Sstevel@tonic-gate /* < */
10667c478bd9Sstevel@tonic-gate /* > */
10677c478bd9Sstevel@tonic-gate 		case '<':
10687c478bd9Sstevel@tonic-gate 		case '>':
10697c478bd9Sstevel@tonic-gate 			for (cnt = 1; peekchar() == c; cnt++)
10707c478bd9Sstevel@tonic-gate 				ignchar();
10717c478bd9Sstevel@tonic-gate 			setCNL();
10727c478bd9Sstevel@tonic-gate 			vmacchng(0);
10737c478bd9Sstevel@tonic-gate 			shift(c, cnt);
10747c478bd9Sstevel@tonic-gate 			continue;
10757c478bd9Sstevel@tonic-gate 
10767c478bd9Sstevel@tonic-gate /* ^D */
10777c478bd9Sstevel@tonic-gate /* EOF */
10787c478bd9Sstevel@tonic-gate 		case CTRL('d'):
10797c478bd9Sstevel@tonic-gate 		case EOF:
10807c478bd9Sstevel@tonic-gate 			if (exitoneof) {
10817c478bd9Sstevel@tonic-gate 				if (addr2 != 0)
10827c478bd9Sstevel@tonic-gate 					dot = addr2;
10837c478bd9Sstevel@tonic-gate 				return;
10847c478bd9Sstevel@tonic-gate 			}
10857c478bd9Sstevel@tonic-gate 			if (!isatty(0)) {
10867c478bd9Sstevel@tonic-gate 				if (intty)
10877c478bd9Sstevel@tonic-gate 					/*
10887c478bd9Sstevel@tonic-gate 					 * Chtty sys call at UCB may cause a
10897c478bd9Sstevel@tonic-gate 					 * input which was a tty to suddenly be
10907c478bd9Sstevel@tonic-gate 					 * turned into /dev/null.
10917c478bd9Sstevel@tonic-gate 					 */
10927c478bd9Sstevel@tonic-gate 					onhup(0);
10937c478bd9Sstevel@tonic-gate 				return;
10947c478bd9Sstevel@tonic-gate 			}
10957c478bd9Sstevel@tonic-gate 			if (addr2 != 0) {
10967c478bd9Sstevel@tonic-gate 				setlastchar('\n');
10977c478bd9Sstevel@tonic-gate 				putnl();
10987c478bd9Sstevel@tonic-gate 			}
10997c478bd9Sstevel@tonic-gate 			if (dol == zero) {
11007c478bd9Sstevel@tonic-gate 				if (addr2 == 0)
11017c478bd9Sstevel@tonic-gate 					putnl();
11027c478bd9Sstevel@tonic-gate 				notempty();
11037c478bd9Sstevel@tonic-gate 			}
11047c478bd9Sstevel@tonic-gate 			ungetchar(EOF);
11057c478bd9Sstevel@tonic-gate 			zop(hadpr);
11067c478bd9Sstevel@tonic-gate 			continue;
11077c478bd9Sstevel@tonic-gate 		default:
11087c478bd9Sstevel@tonic-gate 			if (!isalpha(c) || !isascii(c))
11097c478bd9Sstevel@tonic-gate 				break;
11107c478bd9Sstevel@tonic-gate 			ungetchar(c);
1111f6db9f27Scf 			tailprim((unsigned char *)"", 0, 0);
11127c478bd9Sstevel@tonic-gate 		}
11137c478bd9Sstevel@tonic-gate 		ungetchar(c);
11147c478bd9Sstevel@tonic-gate 		{
11157c478bd9Sstevel@tonic-gate 			int length;
11167c478bd9Sstevel@tonic-gate 			char multic[MULTI_BYTE_MAX];
11177c478bd9Sstevel@tonic-gate 			wchar_t wchar;
11187c478bd9Sstevel@tonic-gate 			length = _mbftowc(multic, &wchar, getchar, &peekc);
11197c478bd9Sstevel@tonic-gate 			if (length < 0)
11207c478bd9Sstevel@tonic-gate 				length = -length;
11217c478bd9Sstevel@tonic-gate 			multic[length] = '\0';
11227c478bd9Sstevel@tonic-gate 			error((vi_TERSE) ? gettext("What?") :
11237c478bd9Sstevel@tonic-gate 				gettext("Unknown command character '%s'"),
11247c478bd9Sstevel@tonic-gate 			    multic);
11257c478bd9Sstevel@tonic-gate 		}
11267c478bd9Sstevel@tonic-gate 	}
11277c478bd9Sstevel@tonic-gate }
1128