xref: /onnv-gate/usr/src/ucbcmd/stty/stty.c (revision 9354:9559ac454e7e)
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
5*9354STim.Marsland@Sun.COM  * Common Development and Distribution License (the "License").
6*9354STim.Marsland@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*9354STim.Marsland@Sun.COM 
220Sstevel@tonic-gate /*
23*9354STim.Marsland@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include <stdio.h>
310Sstevel@tonic-gate #include <ctype.h>
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <termio.h>
340Sstevel@tonic-gate #include <sys/stermio.h>
350Sstevel@tonic-gate #include <sys/termiox.h>
360Sstevel@tonic-gate #include "stty.h"
370Sstevel@tonic-gate 
380Sstevel@tonic-gate extern char *getenv();
390Sstevel@tonic-gate extern void exit();
400Sstevel@tonic-gate extern void perror();
410Sstevel@tonic-gate 
42*9354STim.Marsland@Sun.COM static char *STTY = "stty: ";
43*9354STim.Marsland@Sun.COM static char *USAGE = "usage: stty [-agh] [modes]\n";
440Sstevel@tonic-gate static int	pitt = 0;
450Sstevel@tonic-gate static struct termios cb;
460Sstevel@tonic-gate static struct termio ocb; /* for non-streams devices */
470Sstevel@tonic-gate static struct stio stio;
480Sstevel@tonic-gate static struct termiox termiox;
490Sstevel@tonic-gate static struct winsize winsize, owinsize;
500Sstevel@tonic-gate static int term;
510Sstevel@tonic-gate 
52669Schin void prmodes(int);
53669Schin void pramodes(int);
54669Schin void prachars(void);
55669Schin void pcol(int, int);
56669Schin void pit(unsigned char, char *, char *);
57669Schin void delay(int, char *s);
58669Schin void prspeed(char *, int);
59669Schin void prencode(void);
60669Schin 
61*9354STim.Marsland@Sun.COM #define	ioctl_desc	1
62*9354STim.Marsland@Sun.COM #define	output		stderr
630Sstevel@tonic-gate 
64669Schin int
main(int argc,char * argv[])65669Schin main(int argc, char *argv[])
660Sstevel@tonic-gate {
670Sstevel@tonic-gate 
680Sstevel@tonic-gate 	int i;
69*9354STim.Marsland@Sun.COM 	char	*s_arg, *sttyparse();	/* s_arg: ptr to mode to be set */
700Sstevel@tonic-gate 	extern const struct	speeds	speeds[];
71*9354STim.Marsland@Sun.COM 
720Sstevel@tonic-gate 	if (argc == 2) {
730Sstevel@tonic-gate 		/*
740Sstevel@tonic-gate 		 * "stty size", "stty speed" and "stty -g" are intended for
750Sstevel@tonic-gate 		 * use within backquotes; thus, they do the "fetch" "ioctl"
760Sstevel@tonic-gate 		 * from "/dev/tty" and always print their result on the
770Sstevel@tonic-gate 		 * standard output.
780Sstevel@tonic-gate 		 * Since their standard output is likely to be a pipe, they
790Sstevel@tonic-gate 		 * should not try to read the modes from the standard output.
800Sstevel@tonic-gate 		 */
810Sstevel@tonic-gate 		if (strcmp(argv[1], "size") == 0) {
820Sstevel@tonic-gate 			if ((i = open("/dev/tty", 0)) < 0) {
830Sstevel@tonic-gate 				perror("stty: Cannot open /dev/tty");
840Sstevel@tonic-gate 				exit(2);
850Sstevel@tonic-gate 			}
860Sstevel@tonic-gate 			if (ioctl(i, TIOCGWINSZ, &winsize) < 0) {
870Sstevel@tonic-gate 				perror("stty: TIOCGWINSZ");
880Sstevel@tonic-gate 				exit(2);
890Sstevel@tonic-gate 			}
90*9354STim.Marsland@Sun.COM 			(void) printf("%d %d\n",
91*9354STim.Marsland@Sun.COM 			    winsize.ws_row, winsize.ws_col);
920Sstevel@tonic-gate 			exit(0);
93*9354STim.Marsland@Sun.COM 		} else if (strcmp(argv[1], "speed") == 0) {
940Sstevel@tonic-gate 			if ((i = open("/dev/tty", 0)) < 0) {
950Sstevel@tonic-gate 				perror("stty: Cannot open /dev/tty");
960Sstevel@tonic-gate 				exit(2);
970Sstevel@tonic-gate 			}
98*9354STim.Marsland@Sun.COM 			if ((term = get_ttymode(i,
99*9354STim.Marsland@Sun.COM 			    &ocb, &cb, &stio, &termiox, &winsize)) < 0) {
1000Sstevel@tonic-gate 				perror(STTY);
1010Sstevel@tonic-gate 				exit(2);
1020Sstevel@tonic-gate 			}
1030Sstevel@tonic-gate 			if (term & TERMIOS) {
104*9354STim.Marsland@Sun.COM 				for (i = 0; speeds[i].string; i++)
105*9354STim.Marsland@Sun.COM 					if (cfgetospeed(&cb) ==
106*9354STim.Marsland@Sun.COM 					    speeds[i].speed) {
107*9354STim.Marsland@Sun.COM 						(void) printf("%s\n",
108*9354STim.Marsland@Sun.COM 						    speeds[i].string);
109*9354STim.Marsland@Sun.COM 						exit(0);
110*9354STim.Marsland@Sun.COM 					}
1110Sstevel@tonic-gate 			} else {
112*9354STim.Marsland@Sun.COM 				for (i = 0; speeds[i].string; i++)
113*9354STim.Marsland@Sun.COM 					if ((cb.c_cflag&CBAUD) ==
114*9354STim.Marsland@Sun.COM 					    speeds[i].speed) {
115*9354STim.Marsland@Sun.COM 						(void) printf("%s\n",
116*9354STim.Marsland@Sun.COM 						    speeds[i].string);
117*9354STim.Marsland@Sun.COM 						exit(0);
118*9354STim.Marsland@Sun.COM 					}
1190Sstevel@tonic-gate 			}
1200Sstevel@tonic-gate 			(void) printf("unknown\n");
1210Sstevel@tonic-gate 			exit(1);
122*9354STim.Marsland@Sun.COM 		} else if (strcmp(argv[1], "-g") == 0) {
1230Sstevel@tonic-gate 			if ((i = open("/dev/tty", 0)) < 0) {
1240Sstevel@tonic-gate 				perror("stty: Cannot open /dev/tty");
1250Sstevel@tonic-gate 				exit(2);
1260Sstevel@tonic-gate 			}
127*9354STim.Marsland@Sun.COM 			if ((term = get_ttymode(i,
128*9354STim.Marsland@Sun.COM 			    &ocb, &cb, &stio, &termiox, &winsize)) < 0) {
1290Sstevel@tonic-gate 				perror(STTY);
1300Sstevel@tonic-gate 				exit(2);
1310Sstevel@tonic-gate 			}
1320Sstevel@tonic-gate 			prencode();
1330Sstevel@tonic-gate 			exit(0);
1340Sstevel@tonic-gate 		}
1350Sstevel@tonic-gate 	}
1360Sstevel@tonic-gate 
137*9354STim.Marsland@Sun.COM 	if ((term = get_ttymode(ioctl_desc,
138*9354STim.Marsland@Sun.COM 	    &ocb, &cb, &stio, &termiox, &winsize)) < 0) {
1390Sstevel@tonic-gate 		perror(STTY);
1400Sstevel@tonic-gate 		exit(2);
1410Sstevel@tonic-gate 	}
1420Sstevel@tonic-gate 	owinsize = winsize;
1430Sstevel@tonic-gate 	if (argc == 1) {
1440Sstevel@tonic-gate 		prmodes(0);
1450Sstevel@tonic-gate 		exit(0);
1460Sstevel@tonic-gate 	}
147*9354STim.Marsland@Sun.COM 	if ((argc == 2) && strcmp(argv[1], "all") == 0) {
1480Sstevel@tonic-gate 		prmodes(1);
1490Sstevel@tonic-gate 		exit(0);
1500Sstevel@tonic-gate 	}
151*9354STim.Marsland@Sun.COM 	if ((argc == 2) && strcmp(argv[1], "everything") == 0) {
1520Sstevel@tonic-gate 		pramodes(1);
1530Sstevel@tonic-gate 		exit(0);
1540Sstevel@tonic-gate 	}
1550Sstevel@tonic-gate 	if ((argc == 2) && (argv[1][0] == '-') && (argv[1][2] == '\0'))
156*9354STim.Marsland@Sun.COM 		switch (argv[1][1]) {
1570Sstevel@tonic-gate 		case 'a':
1580Sstevel@tonic-gate 			pramodes(0);
1590Sstevel@tonic-gate 			exit(0);
1600Sstevel@tonic-gate 		case 'h':
1610Sstevel@tonic-gate 			pramodes(1);
1620Sstevel@tonic-gate 			exit(0);
1630Sstevel@tonic-gate 		default:
1640Sstevel@tonic-gate 			(void) fprintf(stderr, "%s", USAGE);
1650Sstevel@tonic-gate 			exit(2);
166*9354STim.Marsland@Sun.COM 		}
167*9354STim.Marsland@Sun.COM 	if (s_arg = sttyparse(argc, argv,
168*9354STim.Marsland@Sun.COM 	    term, &ocb, &cb, &termiox, &winsize)) {
1690Sstevel@tonic-gate 		(void) fprintf(stderr, "unknown mode: %s\n", s_arg);
1700Sstevel@tonic-gate 		exit(2);
1710Sstevel@tonic-gate 	}
1720Sstevel@tonic-gate 
173*9354STim.Marsland@Sun.COM 	if (set_ttymode(ioctl_desc,
174*9354STim.Marsland@Sun.COM 	    term, &ocb, &cb, &stio, &termiox, &winsize, &owinsize) == -1) {
1750Sstevel@tonic-gate 		perror(STTY);
1760Sstevel@tonic-gate 		exit(2);
1770Sstevel@tonic-gate 	}
178669Schin 	return (0);	/*NOTREACHED*/
1790Sstevel@tonic-gate }
1800Sstevel@tonic-gate 
181669Schin void
prmodes(int moremodes)182669Schin prmodes(int moremodes)
183669Schin /* print modes, no options, argc is 1 */
1840Sstevel@tonic-gate {
185669Schin 	int m;
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate 	if (!(term & ASYNC)) {
1880Sstevel@tonic-gate 		m = stio.imode;
189*9354STim.Marsland@Sun.COM 		if (m & IUCLC)
190*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "iuclc ");
191*9354STim.Marsland@Sun.COM 		else
192*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-iuclc ");
1930Sstevel@tonic-gate 		m = stio.omode;
194*9354STim.Marsland@Sun.COM 		if (m & OLCUC)
195*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "olcuc ");
196*9354STim.Marsland@Sun.COM 		else
197*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-olcuc ");
198*9354STim.Marsland@Sun.COM 		if (m & TAB3)
199*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "tab3 ");
2000Sstevel@tonic-gate 		m = stio.lmode;
201*9354STim.Marsland@Sun.COM 		if (m & XCASE)
202*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "xcase ");
203*9354STim.Marsland@Sun.COM 		else
204*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-xcase ");
205*9354STim.Marsland@Sun.COM 		if (m & STFLUSH)
206*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "stflush ");
207*9354STim.Marsland@Sun.COM 		else
208*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-stflush ");
209*9354STim.Marsland@Sun.COM 		if (m & STWRAP)
210*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "stwrap ");
211*9354STim.Marsland@Sun.COM 		else
212*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-stwrap ");
213*9354STim.Marsland@Sun.COM 		if (m & STAPPL)
214*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "stappl ");
215*9354STim.Marsland@Sun.COM 		else
216*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-stappl ");
2170Sstevel@tonic-gate 		(void) fprintf(output, "\n");
2180Sstevel@tonic-gate 	}
2190Sstevel@tonic-gate 	if (term & ASYNC) {
2200Sstevel@tonic-gate 		m = cb.c_cflag;
2210Sstevel@tonic-gate 		if ((term & TERMIOS) && cfgetispeed(&cb) != 0 &&
2220Sstevel@tonic-gate 		    cfgetispeed(&cb) != cfgetospeed(&cb)) {
2230Sstevel@tonic-gate 			prspeed("ispeed ", cfgetispeed(&cb));
2240Sstevel@tonic-gate 			prspeed("ospeed ", cfgetospeed(&cb));
2250Sstevel@tonic-gate 		} else
2260Sstevel@tonic-gate 			prspeed("speed ", cfgetospeed(&cb));
227*9354STim.Marsland@Sun.COM 		if (m & PARENB) {
228*9354STim.Marsland@Sun.COM 			if ((m & PAREXT) && (term & TERMIOS)) {
229*9354STim.Marsland@Sun.COM 				if (m & PARODD)
230*9354STim.Marsland@Sun.COM 					(void) fprintf(output, "markp ");
2310Sstevel@tonic-gate 				else
232*9354STim.Marsland@Sun.COM 					(void) fprintf(output, "spacep ");
2330Sstevel@tonic-gate 			} else {
234*9354STim.Marsland@Sun.COM 				if (m & PARODD)
235*9354STim.Marsland@Sun.COM 					(void) fprintf(output, "oddp ");
2360Sstevel@tonic-gate 				else
237*9354STim.Marsland@Sun.COM 					(void) fprintf(output, "evenp ");
2380Sstevel@tonic-gate 			}
2390Sstevel@tonic-gate 		} else
240*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-parity ");
241*9354STim.Marsland@Sun.COM 		if (((m & PARENB) && !(m & CS7)) ||
242*9354STim.Marsland@Sun.COM 		    (!(m & PARENB) && !(m & CS8)))
243*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "cs%c ", '5' + (m & CSIZE)/CS6);
244*9354STim.Marsland@Sun.COM 		if (m & CSTOPB)
245*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "cstopb ");
246*9354STim.Marsland@Sun.COM 		if (m & HUPCL)
247*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "hupcl ");
248*9354STim.Marsland@Sun.COM 		if (!(m & CREAD))
249*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-cread ");
250*9354STim.Marsland@Sun.COM 		if (m & CLOCAL)
251*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "clocal ");
252*9354STim.Marsland@Sun.COM 		if (m & LOBLK)
253*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "loblk ");
254*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "\n");
255*9354STim.Marsland@Sun.COM 		if (ocb.c_line != 0)
256*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "line = %d; ", ocb.c_line);
257*9354STim.Marsland@Sun.COM 		if (term & WINDOW) {
258*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "rows = %d; columns = %d;",
259*9354STim.Marsland@Sun.COM 			    winsize.ws_row, winsize.ws_col);
260*9354STim.Marsland@Sun.COM 			(void) fprintf(output, " ypixels = %d; xpixels = %d;\n",
261*9354STim.Marsland@Sun.COM 			    winsize.ws_ypixel, winsize.ws_xpixel);
2620Sstevel@tonic-gate 		}
263*9354STim.Marsland@Sun.COM 		if ((cb.c_lflag & ICANON) == 0)
264*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "min = %d; time = %d;\n",
265*9354STim.Marsland@Sun.COM 			    cb.c_cc[VMIN], cb.c_cc[VTIME]);
2660Sstevel@tonic-gate 		if (!moremodes) {
267*9354STim.Marsland@Sun.COM 			if (cb.c_cc[VINTR] != CINTR)
2680Sstevel@tonic-gate 				pit(cb.c_cc[VINTR], "intr", "; ");
269*9354STim.Marsland@Sun.COM 			if (cb.c_cc[VQUIT] != CQUIT)
2700Sstevel@tonic-gate 				pit(cb.c_cc[VQUIT], "quit", "; ");
271*9354STim.Marsland@Sun.COM 			if (cb.c_cc[VERASE] != CERASE)
2720Sstevel@tonic-gate 				pit(cb.c_cc[VERASE], "erase", "; ");
273*9354STim.Marsland@Sun.COM 			if (cb.c_cc[VKILL] != CKILL)
2740Sstevel@tonic-gate 				pit(cb.c_cc[VKILL], "kill", "; ");
275*9354STim.Marsland@Sun.COM 			if (cb.c_cc[VEOF] != CEOF)
2760Sstevel@tonic-gate 				pit(cb.c_cc[VEOF], "eof", "; ");
277*9354STim.Marsland@Sun.COM 			if (cb.c_cc[VEOL] != CNUL)
2780Sstevel@tonic-gate 				pit(cb.c_cc[VEOL], "eol", "; ");
279*9354STim.Marsland@Sun.COM 			if (cb.c_cc[VEOL2] != CNUL)
2800Sstevel@tonic-gate 				pit(cb.c_cc[VEOL2], "eol2", "; ");
281*9354STim.Marsland@Sun.COM 			if (cb.c_cc[VSWTCH] != CSWTCH)
2820Sstevel@tonic-gate 				pit(cb.c_cc[VSWTCH], "swtch", "; ");
283*9354STim.Marsland@Sun.COM 			if (term & TERMIOS) {
284*9354STim.Marsland@Sun.COM 				if (cb.c_cc[VSTART] != CSTART)
2850Sstevel@tonic-gate 					pit(cb.c_cc[VSTART], "start", "; ");
286*9354STim.Marsland@Sun.COM 				if (cb.c_cc[VSTOP] != CSTOP)
2870Sstevel@tonic-gate 					pit(cb.c_cc[VSTOP], "stop", "; ");
288*9354STim.Marsland@Sun.COM 				if (cb.c_cc[VSUSP] != CSUSP)
2890Sstevel@tonic-gate 					pit(cb.c_cc[VSUSP], "susp", "; ");
290*9354STim.Marsland@Sun.COM 				if (cb.c_cc[VDSUSP] != CDSUSP)
2910Sstevel@tonic-gate 					pit(cb.c_cc[VDSUSP], "dsusp", "; ");
292*9354STim.Marsland@Sun.COM 				if (cb.c_cc[VREPRINT] != CRPRNT)
2930Sstevel@tonic-gate 					pit(cb.c_cc[VREPRINT], "rprnt", "; ");
294*9354STim.Marsland@Sun.COM 				if (cb.c_cc[VDISCARD] != CFLUSH)
2950Sstevel@tonic-gate 					pit(cb.c_cc[VDISCARD], "flush", "; ");
296*9354STim.Marsland@Sun.COM 				if (cb.c_cc[VWERASE] != CWERASE)
2970Sstevel@tonic-gate 					pit(cb.c_cc[VWERASE], "werase", "; ");
298*9354STim.Marsland@Sun.COM 				if (cb.c_cc[VLNEXT] != CLNEXT)
2990Sstevel@tonic-gate 					pit(cb.c_cc[VLNEXT], "lnext", "; ");
3000Sstevel@tonic-gate 			}
3010Sstevel@tonic-gate 		}
302*9354STim.Marsland@Sun.COM 		if (pitt)
303*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "\n");
3040Sstevel@tonic-gate 		m = cb.c_iflag;
305*9354STim.Marsland@Sun.COM 		if (m & IGNBRK)
306*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "ignbrk ");
307*9354STim.Marsland@Sun.COM 		else if (!(m & BRKINT))
308*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-brkint ");
309*9354STim.Marsland@Sun.COM 		if (!(m & INPCK))
310*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-inpck ");
311*9354STim.Marsland@Sun.COM 		else if (!(m & IGNPAR))
312*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-ignpar ");
313*9354STim.Marsland@Sun.COM 		if (m & PARMRK)
314*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "parmrk ");
315*9354STim.Marsland@Sun.COM 		if (!(m & ISTRIP))
316*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-istrip ");
317*9354STim.Marsland@Sun.COM 		if (m & INLCR)
318*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "inlcr ");
319*9354STim.Marsland@Sun.COM 		if (m & IGNCR)
320*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "igncr ");
321*9354STim.Marsland@Sun.COM 		if (!(m & ICRNL))
322*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-icrnl ");
323*9354STim.Marsland@Sun.COM 		if (m & IUCLC)
324*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "iuclc ");
325*9354STim.Marsland@Sun.COM 		if (!(m & IXON))
326*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-ixon ");
327*9354STim.Marsland@Sun.COM 		else if (m & IXANY)
328*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "ixany ");
329*9354STim.Marsland@Sun.COM 		if (m & IXOFF)
330*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "ixoff ");
331*9354STim.Marsland@Sun.COM 		if ((term & TERMIOS) && (m & IMAXBEL))
332*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "imaxbel ");
3330Sstevel@tonic-gate 		m = cb.c_oflag;
334*9354STim.Marsland@Sun.COM 		if (!(m & OPOST))
335*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-opost ");
3360Sstevel@tonic-gate 		else {
337*9354STim.Marsland@Sun.COM 			if (m & OLCUC)
338*9354STim.Marsland@Sun.COM 				(void) fprintf(output, "olcuc ");
339*9354STim.Marsland@Sun.COM 			if (!(m & ONLCR))
340*9354STim.Marsland@Sun.COM 				(void) fprintf(output, "-onlcr ");
341*9354STim.Marsland@Sun.COM 			if (m & OCRNL)
342*9354STim.Marsland@Sun.COM 				(void) fprintf(output, "ocrnl ");
343*9354STim.Marsland@Sun.COM 			if (m & ONOCR)
344*9354STim.Marsland@Sun.COM 				(void) fprintf(output, "onocr ");
345*9354STim.Marsland@Sun.COM 			if (m & ONLRET)
346*9354STim.Marsland@Sun.COM 				(void) fprintf(output, "onlret ");
347*9354STim.Marsland@Sun.COM 			if (m & OFILL)
348*9354STim.Marsland@Sun.COM 				if (m & OFDEL)
349*9354STim.Marsland@Sun.COM 					(void) fprintf(output, "del-fill ");
350*9354STim.Marsland@Sun.COM 				else
351*9354STim.Marsland@Sun.COM 					(void) fprintf(output, "nul-fill ");
352*9354STim.Marsland@Sun.COM 			delay((m & CRDLY)/CR1, "cr");
353*9354STim.Marsland@Sun.COM 			delay((m & NLDLY)/NL1, "nl");
354*9354STim.Marsland@Sun.COM 			if ((m & TABDLY) == XTABS)
355*9354STim.Marsland@Sun.COM 				(void) fprintf(output, "-tabs ");
3560Sstevel@tonic-gate 			else
357*9354STim.Marsland@Sun.COM 				delay((m & TABDLY)/TAB1, "tab");
358*9354STim.Marsland@Sun.COM 			delay((m & BSDLY)/BS1, "bs");
359*9354STim.Marsland@Sun.COM 			delay((m & VTDLY)/VT1, "vt");
360*9354STim.Marsland@Sun.COM 			delay((m & FFDLY)/FF1, "ff");
3610Sstevel@tonic-gate 		}
362*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "\n");
3630Sstevel@tonic-gate 		m = cb.c_lflag;
364*9354STim.Marsland@Sun.COM 		if (!(m & ISIG))
365*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-isig ");
366*9354STim.Marsland@Sun.COM 		if (!(m & ICANON))
367*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-icanon ");
368*9354STim.Marsland@Sun.COM 		if (m & XCASE)
369*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "xcase ");
370*9354STim.Marsland@Sun.COM 		if (!(m & ECHO))
371*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-echo ");
372*9354STim.Marsland@Sun.COM 		if (m & ECHOE) {
373*9354STim.Marsland@Sun.COM 			if (m & ECHOKE)
374*9354STim.Marsland@Sun.COM 				(void) fprintf(output, "crt ");
3750Sstevel@tonic-gate 			else
376*9354STim.Marsland@Sun.COM 				(void) fprintf(output, "echoe -echoke ");
3770Sstevel@tonic-gate 		} else {
378*9354STim.Marsland@Sun.COM 			if (!(m & ECHOPRT))
379*9354STim.Marsland@Sun.COM 				(void) fprintf(output, "-echoprt ");
3800Sstevel@tonic-gate 		}
381*9354STim.Marsland@Sun.COM 		if (!(m & ECHOK))
382*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-echok ");
383*9354STim.Marsland@Sun.COM 		if (m & ECHONL)
384*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "echonl ");
385*9354STim.Marsland@Sun.COM 		if (m & NOFLSH)
386*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "noflsh ");
387*9354STim.Marsland@Sun.COM 		if (m & TOSTOP)
388*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "tostop ");
389*9354STim.Marsland@Sun.COM 		if (!(m & ECHOCTL))
390*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "-echoctl ");
391*9354STim.Marsland@Sun.COM 		if (m & DEFECHO)
392*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "defecho ");
393*9354STim.Marsland@Sun.COM 		if (m & FLUSHO)
394*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "flusho ");
395*9354STim.Marsland@Sun.COM 		if (m & PENDIN)
396*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "pendin ");
397*9354STim.Marsland@Sun.COM 		if (m & IEXTEN)
398*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "iexten ");
399*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "\n");
4000Sstevel@tonic-gate 	}
401*9354STim.Marsland@Sun.COM 	if (term & FLOW) {
4020Sstevel@tonic-gate 		m = termiox.x_hflag;
403*9354STim.Marsland@Sun.COM 		if (m & RTSXOFF)
404*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "rtsxoff ");
405*9354STim.Marsland@Sun.COM 		if (m & CTSXON)
406*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "ctsxon ");
407*9354STim.Marsland@Sun.COM 		if (m & DTRXOFF)
408*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "dterxoff ");
409*9354STim.Marsland@Sun.COM 		if (m & CDXON)
410*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "rlsdxon ");
411*9354STim.Marsland@Sun.COM 		if (m & ISXOFF)
412*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "isxoff ");
4130Sstevel@tonic-gate 		m = termiox.x_cflag;
414*9354STim.Marsland@Sun.COM 		switch (m & XMTCLK) {
415*9354STim.Marsland@Sun.COM 		case XCIBRG:
416*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "xcibrg ");
417*9354STim.Marsland@Sun.COM 			break;
418*9354STim.Marsland@Sun.COM 		case XCTSET:
419*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "xctset ");
420*9354STim.Marsland@Sun.COM 			break;
421*9354STim.Marsland@Sun.COM 		case XCRSET:
422*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "xcrset ");
423*9354STim.Marsland@Sun.COM 			break;
4240Sstevel@tonic-gate 		}
425*9354STim.Marsland@Sun.COM 
426*9354STim.Marsland@Sun.COM 		switch (m & RCVCLK) {
427*9354STim.Marsland@Sun.COM 		case RCIBRG:
428*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "rcibrg ");
429*9354STim.Marsland@Sun.COM 			break;
430*9354STim.Marsland@Sun.COM 		case RCTSET:
431*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "rctset ");
432*9354STim.Marsland@Sun.COM 			break;
433*9354STim.Marsland@Sun.COM 		case RCRSET:
434*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "rcrset ");
435*9354STim.Marsland@Sun.COM 			break;
4360Sstevel@tonic-gate 		}
437*9354STim.Marsland@Sun.COM 
438*9354STim.Marsland@Sun.COM 		switch (m & TSETCLK) {
439*9354STim.Marsland@Sun.COM 		case TSETCOFF:
440*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "tsetcoff ");
441*9354STim.Marsland@Sun.COM 			break;
442*9354STim.Marsland@Sun.COM 		case TSETCRBRG:
443*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "tsetcrc ");
444*9354STim.Marsland@Sun.COM 			break;
445*9354STim.Marsland@Sun.COM 		case TSETCTBRG:
446*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "tsetcxc ");
447*9354STim.Marsland@Sun.COM 			break;
4480Sstevel@tonic-gate 		}
449*9354STim.Marsland@Sun.COM 
450*9354STim.Marsland@Sun.COM 		switch (m & RSETCLK) {
451*9354STim.Marsland@Sun.COM 		case RSETCOFF:
452*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "rsetcoff ");
453*9354STim.Marsland@Sun.COM 			break;
454*9354STim.Marsland@Sun.COM 		case RSETCRBRG:
455*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "rsetcrc ");
456*9354STim.Marsland@Sun.COM 			break;
457*9354STim.Marsland@Sun.COM 		case RSETCTBRG:
458*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "rsetcxc ");
4590Sstevel@tonic-gate 		}
460*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "\n");
4610Sstevel@tonic-gate 	}
462*9354STim.Marsland@Sun.COM 	if (moremodes)
4630Sstevel@tonic-gate 		prachars();
4640Sstevel@tonic-gate }
4650Sstevel@tonic-gate 
466669Schin void
pramodes(int tabform)467669Schin pramodes(int tabform)
468669Schin /* print all modes, -a option */
4690Sstevel@tonic-gate {
470669Schin 	int m;
4710Sstevel@tonic-gate 
4720Sstevel@tonic-gate 	m = cb.c_cflag;
473*9354STim.Marsland@Sun.COM 	if (term & ASYNC) {
4740Sstevel@tonic-gate 		if ((term & TERMIOS) && cfgetispeed(&cb) != 0 &&
4750Sstevel@tonic-gate 		    cfgetispeed(&cb) != cfgetospeed(&cb)) {
4760Sstevel@tonic-gate 			prspeed("ispeed ", cfgetispeed(&cb));
4770Sstevel@tonic-gate 			prspeed("ospeed ", cfgetospeed(&cb));
4780Sstevel@tonic-gate 		} else
4790Sstevel@tonic-gate 			prspeed("speed ", cfgetospeed(&cb));
480*9354STim.Marsland@Sun.COM 		if (!(term & TERMIOS))
481*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "line = %d; ", ocb.c_line);
482*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "\n");
483*9354STim.Marsland@Sun.COM 		if (term & WINDOW) {
484*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "rows = %d columns = %d; ",
485*9354STim.Marsland@Sun.COM 			    winsize.ws_row, winsize.ws_col);
486*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "ypixels = %d xpixels = %d\n",
487*9354STim.Marsland@Sun.COM 			    winsize.ws_ypixel, winsize.ws_xpixel);
4880Sstevel@tonic-gate 		}
489*9354STim.Marsland@Sun.COM 		if ((cb.c_lflag & ICANON) == 0)
490*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "min = %d; time = %d;\n",
491*9354STim.Marsland@Sun.COM 			    cb.c_cc[VMIN], cb.c_cc[VTIME]);
4920Sstevel@tonic-gate 		if (!tabform) {
4930Sstevel@tonic-gate 			pit(cb.c_cc[VINTR], "intr", "; ");
4940Sstevel@tonic-gate 			pit(cb.c_cc[VQUIT], "quit", "; ");
4950Sstevel@tonic-gate 			pit(cb.c_cc[VERASE], "erase", "; ");
4960Sstevel@tonic-gate 			pit(cb.c_cc[VKILL], "kill", ";\n");
4970Sstevel@tonic-gate 			pit(cb.c_cc[VEOF], "eof", "; ");
4980Sstevel@tonic-gate 			pit(cb.c_cc[VEOL], "eol", "; ");
4990Sstevel@tonic-gate 			pit(cb.c_cc[VEOL2], "eol2", "; ");
5000Sstevel@tonic-gate 			pit(cb.c_cc[VSWTCH], "swtch", ";\n");
501*9354STim.Marsland@Sun.COM 			if (term & TERMIOS) {
5020Sstevel@tonic-gate 				pit(cb.c_cc[VSTART], "start", "; ");
5030Sstevel@tonic-gate 				pit(cb.c_cc[VSTOP], "stop", "; ");
5040Sstevel@tonic-gate 				pit(cb.c_cc[VSUSP], "susp", "; ");
5050Sstevel@tonic-gate 				pit(cb.c_cc[VDSUSP], "dsusp", ";\n");
5060Sstevel@tonic-gate 				pit(cb.c_cc[VREPRINT], "rprnt", "; ");
5070Sstevel@tonic-gate 				pit(cb.c_cc[VDISCARD], "flush", "; ");
5080Sstevel@tonic-gate 				pit(cb.c_cc[VWERASE], "werase", "; ");
5090Sstevel@tonic-gate 				pit(cb.c_cc[VLNEXT], "lnext", ";\n");
5100Sstevel@tonic-gate 			}
5110Sstevel@tonic-gate 		}
5120Sstevel@tonic-gate 	} else
5130Sstevel@tonic-gate 		pit((unsigned)stio.tab, "ctab", "\n");
5140Sstevel@tonic-gate 	m = cb.c_cflag;
515*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-parenb " + ((m & PARENB) != 0));
516*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-parodd " + ((m & PARODD) != 0));
517*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "cs%c ", '5'+ (m & CSIZE)/CS6);
518*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-cstopb " + ((m & CSTOPB) != 0));
519*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-hupcl " + ((m & HUPCL) != 0));
520*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-cread " + ((m & CREAD) != 0));
521*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-clocal " + ((m & CLOCAL) != 0));
5220Sstevel@tonic-gate 
523*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-loblk " + ((m & LOBLK) != 0));
524*9354STim.Marsland@Sun.COM 	if (term & TERMIOS)
525*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-parext " + ((m & PAREXT) != 0));
5260Sstevel@tonic-gate 
527*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "\n");
5280Sstevel@tonic-gate 	m = cb.c_iflag;
529*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-ignbrk " + ((m & IGNBRK) != 0));
530*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-brkint " + ((m & BRKINT) != 0));
531*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-ignpar " + ((m & IGNPAR) != 0));
532*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-parmrk " + ((m & PARMRK) != 0));
533*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-inpck " + ((m & INPCK) != 0));
534*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-istrip " + ((m & ISTRIP) != 0));
535*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-inlcr " + ((m & INLCR) != 0));
536*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-igncr " + ((m & IGNCR) != 0));
537*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-icrnl " + ((m & ICRNL) != 0));
538*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-iuclc " + ((m & IUCLC) != 0));
539*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "\n");
540*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-ixon " + ((m & IXON) != 0));
541*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-ixany " + ((m & IXANY) != 0));
542*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-ixoff " + ((m & IXOFF) != 0));
543*9354STim.Marsland@Sun.COM 	if (term & TERMIOS)
544*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-imaxbel " + ((m & IMAXBEL) != 0));
545*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "\n");
5460Sstevel@tonic-gate 	m = cb.c_lflag;
547*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-isig " + ((m & ISIG) != 0));
548*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-icanon " + ((m & ICANON) != 0));
549*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-xcase " + ((m & XCASE) != 0));
550*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-echo " + ((m & ECHO) != 0));
551*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-echoe " + ((m & ECHOE) != 0));
552*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-echok " + ((m & ECHOK) != 0));
553*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-echonl " + ((m & ECHONL) != 0));
554*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-noflsh " + ((m & NOFLSH) != 0));
555*9354STim.Marsland@Sun.COM 	if (term & TERMIOS) {
556*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "\n");
557*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-tostop " + ((m & TOSTOP) != 0));
558*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-echoctl " + ((m & ECHOCTL) != 0));
559*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-echoprt " + ((m & ECHOPRT) != 0));
560*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-echoke " + ((m & ECHOKE) != 0));
561*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-defecho " + ((m & DEFECHO) != 0));
562*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-flusho " + ((m & FLUSHO) != 0));
563*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-pendin " + ((m & PENDIN) != 0));
564*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-iexten " + ((m & IEXTEN) != 0));
5650Sstevel@tonic-gate 	}
566*9354STim.Marsland@Sun.COM 	if (!(term & ASYNC)) {
567*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-stflush " + ((m & STFLUSH) != 0));
568*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-stwrap " + ((m & STWRAP) != 0));
569*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-stappl " + ((m & STAPPL) != 0));
5700Sstevel@tonic-gate 	}
571*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "\n");
5720Sstevel@tonic-gate 	m = cb.c_oflag;
573*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-opost " + ((m & OPOST) != 0));
574*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-olcuc " + ((m & OLCUC) != 0));
575*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-onlcr " + ((m & ONLCR) != 0));
576*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-ocrnl " + ((m & OCRNL) != 0));
577*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-onocr " + ((m & ONOCR) != 0));
578*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-onlret " + ((m & ONLRET) != 0));
579*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-ofill " + ((m & OFILL) != 0));
580*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "-ofdel " + ((m & OFDEL) != 0));
581*9354STim.Marsland@Sun.COM 	delay((m & CRDLY)/CR1, "cr");
582*9354STim.Marsland@Sun.COM 	delay((m & NLDLY)/NL1, "nl");
583*9354STim.Marsland@Sun.COM 	if ((m & TABDLY) == XTABS)
584*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-tabs ");
5850Sstevel@tonic-gate 	else
586*9354STim.Marsland@Sun.COM 		delay((m & TABDLY)/TAB1, "tab");
587*9354STim.Marsland@Sun.COM 	delay((m & BSDLY)/BS1, "bs");
588*9354STim.Marsland@Sun.COM 	delay((m & VTDLY)/VT1, "vt");
589*9354STim.Marsland@Sun.COM 	delay((m & FFDLY)/FF1, "ff");
590*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "\n");
591*9354STim.Marsland@Sun.COM 	if (term & FLOW) {
5920Sstevel@tonic-gate 		m = termiox.x_hflag;
593*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-rtsxoff " + ((m & RTSXOFF) != 0));
594*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-ctsxon " + ((m & CTSXON) != 0));
595*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-dterxoff " + ((m & DTRXOFF) != 0));
596*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-rlsdxon " + ((m & CDXON) != 0));
597*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-isxoff " + ((m & ISXOFF) != 0));
5980Sstevel@tonic-gate 		m = termiox.x_cflag;
599*9354STim.Marsland@Sun.COM 		switch (m & XMTCLK) {
600*9354STim.Marsland@Sun.COM 		case XCIBRG:
601*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "xcibrg ");
602*9354STim.Marsland@Sun.COM 			break;
603*9354STim.Marsland@Sun.COM 		case XCTSET:
604*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "xctset ");
605*9354STim.Marsland@Sun.COM 			break;
606*9354STim.Marsland@Sun.COM 		case XCRSET:
607*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "xcrset ");
608*9354STim.Marsland@Sun.COM 			break;
6090Sstevel@tonic-gate 		}
610*9354STim.Marsland@Sun.COM 
611*9354STim.Marsland@Sun.COM 		switch (m & RCVCLK) {
612*9354STim.Marsland@Sun.COM 		case RCIBRG:
613*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "rcibrg ");
614*9354STim.Marsland@Sun.COM 			break;
615*9354STim.Marsland@Sun.COM 		case RCTSET:
616*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "rctset ");
617*9354STim.Marsland@Sun.COM 			break;
618*9354STim.Marsland@Sun.COM 		case RCRSET:
619*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "rcrset ");
620*9354STim.Marsland@Sun.COM 			break;
6210Sstevel@tonic-gate 		}
622*9354STim.Marsland@Sun.COM 
623*9354STim.Marsland@Sun.COM 		switch (m & TSETCLK) {
624*9354STim.Marsland@Sun.COM 		case TSETCOFF:
625*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "tsetcoff ");
626*9354STim.Marsland@Sun.COM 			break;
627*9354STim.Marsland@Sun.COM 		case TSETCRBRG:
628*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "tsetcrc ");
629*9354STim.Marsland@Sun.COM 			break;
630*9354STim.Marsland@Sun.COM 		case TSETCTBRG:
631*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "tsetcxc ");
632*9354STim.Marsland@Sun.COM 			break;
6330Sstevel@tonic-gate 		}
634*9354STim.Marsland@Sun.COM 
635*9354STim.Marsland@Sun.COM 		switch (m & RSETCLK) {
636*9354STim.Marsland@Sun.COM 		case RSETCOFF:
637*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "rsetcoff ");
638*9354STim.Marsland@Sun.COM 			break;
639*9354STim.Marsland@Sun.COM 		case RSETCRBRG:
640*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "rsetcrc ");
641*9354STim.Marsland@Sun.COM 			break;
642*9354STim.Marsland@Sun.COM 		case RSETCTBRG:
643*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "rsetcxc ");
644*9354STim.Marsland@Sun.COM 			break;
6450Sstevel@tonic-gate 		}
646*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "\n");
6470Sstevel@tonic-gate 	}
6480Sstevel@tonic-gate 	if (tabform)
6490Sstevel@tonic-gate 		prachars();
6500Sstevel@tonic-gate }
6510Sstevel@tonic-gate 
652669Schin void
prachars(void)653669Schin prachars(void)
6540Sstevel@tonic-gate {
655*9354STim.Marsland@Sun.COM 	if ((cb.c_lflag & ICANON) == 0)
656*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "min %d, time %d\n", cb.c_cc[VMIN],
6570Sstevel@tonic-gate 		    cb.c_cc[VTIME]);
658*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "\
6590Sstevel@tonic-gate erase  kill   werase rprnt  flush  lnext  susp   intr   quit   stop   eof\
6600Sstevel@tonic-gate \n");
6610Sstevel@tonic-gate 	pcol(cb.c_cc[VERASE], 0);
6620Sstevel@tonic-gate 	pcol(cb.c_cc[VKILL], 0);
6630Sstevel@tonic-gate 	pcol(cb.c_cc[VWERASE], 0);
6640Sstevel@tonic-gate 	pcol(cb.c_cc[VREPRINT], 0);
6650Sstevel@tonic-gate 	pcol(cb.c_cc[VDISCARD], 0);
6660Sstevel@tonic-gate 	pcol(cb.c_cc[VLNEXT], 0);
6670Sstevel@tonic-gate 	pcol(cb.c_cc[VSUSP], cb.c_cc[VDSUSP]);
6680Sstevel@tonic-gate 	pcol(cb.c_cc[VINTR], 0);
6690Sstevel@tonic-gate 	pcol(cb.c_cc[VQUIT], 0);
6700Sstevel@tonic-gate 	pcol(cb.c_cc[VSTOP], cb.c_cc[VSTART]);
6710Sstevel@tonic-gate 	if (cb.c_lflag&ICANON)
6720Sstevel@tonic-gate 		pcol(cb.c_cc[VEOF], cb.c_cc[VEOL]);
673*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "\n");
6740Sstevel@tonic-gate 	if (cb.c_cc[VEOL2] != 0 || cb.c_cc[VSWTCH] != 0) {
675*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "\
6760Sstevel@tonic-gate eol2  swtch\
6770Sstevel@tonic-gate \n");
6780Sstevel@tonic-gate 		pcol(cb.c_cc[VEOL2], 0);
6790Sstevel@tonic-gate 		pcol(cb.c_cc[VSWTCH], 0);
680*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "\n");
6810Sstevel@tonic-gate 	}
6820Sstevel@tonic-gate }
6830Sstevel@tonic-gate 
684669Schin void
pcol(int ch1,int ch2)685669Schin pcol(int ch1, int ch2)
6860Sstevel@tonic-gate {
6870Sstevel@tonic-gate 	int nout = 0;
6880Sstevel@tonic-gate 
6890Sstevel@tonic-gate 	ch1 &= 0377;
6900Sstevel@tonic-gate 	ch2 &= 0377;
6910Sstevel@tonic-gate 	if (ch1 == ch2)
6920Sstevel@tonic-gate 		ch2 = 0;
6930Sstevel@tonic-gate 	for (; ch1 != 0 || ch2 != 0; ch1 = ch2, ch2 = 0) {
6940Sstevel@tonic-gate 		if (ch1 == 0)
6950Sstevel@tonic-gate 			continue;
6960Sstevel@tonic-gate 		if (ch1 & 0200 && !isprint(ch1)) {
697*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "M-");
6980Sstevel@tonic-gate 			nout += 2;
6990Sstevel@tonic-gate 			ch1 &= ~ 0200;
7000Sstevel@tonic-gate 		}
7010Sstevel@tonic-gate 		if (ch1 == 0177) {
702*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "^");
7030Sstevel@tonic-gate 			nout++;
7040Sstevel@tonic-gate 			ch1 = '?';
7050Sstevel@tonic-gate 		} else if (ch1 < ' ') {
706*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "^");
7070Sstevel@tonic-gate 			nout++;
7080Sstevel@tonic-gate 			ch1 += '@';
7090Sstevel@tonic-gate 		}
710*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "%c", ch1);
7110Sstevel@tonic-gate 		nout++;
7120Sstevel@tonic-gate 		if (ch2 != 0) {
713*9354STim.Marsland@Sun.COM 			(void) fprintf(output, "/");
7140Sstevel@tonic-gate 			nout++;
7150Sstevel@tonic-gate 		}
7160Sstevel@tonic-gate 	}
7170Sstevel@tonic-gate 	while (nout < 7) {
718*9354STim.Marsland@Sun.COM 		(void) fprintf(output, " ");
7190Sstevel@tonic-gate 		nout++;
7200Sstevel@tonic-gate 	}
7210Sstevel@tonic-gate }
7220Sstevel@tonic-gate 
723669Schin void
pit(unsigned char what,char * itsname,char * sep)724669Schin pit(unsigned char what, char *itsname, char *sep)
725669Schin /* print function for prmodes() and pramodes() */
7260Sstevel@tonic-gate {
7270Sstevel@tonic-gate 
7280Sstevel@tonic-gate 	pitt++;
729*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "%s", itsname);
730*9354STim.Marsland@Sun.COM 	if ((term & TERMIOS) && what == _POSIX_VDISABLE ||
731*9354STim.Marsland@Sun.COM 	    !(term & TERMIOS) && what == 0200) {
732*9354STim.Marsland@Sun.COM 		(void) fprintf(output, " = <undef>%s", sep);
7330Sstevel@tonic-gate 		return;
7340Sstevel@tonic-gate 	}
735*9354STim.Marsland@Sun.COM 	(void) fprintf(output, " = ");
7360Sstevel@tonic-gate 	if (what & 0200 && !isprint(what)) {
737*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "-");
7380Sstevel@tonic-gate 		what &= ~ 0200;
7390Sstevel@tonic-gate 	}
7400Sstevel@tonic-gate 	if (what == 0177) {
741*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "^?%s", sep);
7420Sstevel@tonic-gate 		return;
7430Sstevel@tonic-gate 	} else if (what < ' ') {
744*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "^");
7450Sstevel@tonic-gate 		what += '`';
7460Sstevel@tonic-gate 	}
747*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "%c%s", what, sep);
7480Sstevel@tonic-gate }
7490Sstevel@tonic-gate 
750669Schin void
delay(int m,char * s)751669Schin delay(int m, char *s)
7520Sstevel@tonic-gate {
753*9354STim.Marsland@Sun.COM 	if (m)
754*9354STim.Marsland@Sun.COM 		(void) fprintf(output, "%s%d ", s, m);
7550Sstevel@tonic-gate }
7560Sstevel@tonic-gate 
7570Sstevel@tonic-gate long	speed[] = {
758*9354STim.Marsland@Sun.COM 	0, 50, 75, 110, 134, 150, 200, 300,
759*9354STim.Marsland@Sun.COM 	600, 1200, 1800, 2400, 4800, 9600, 19200, 38400,
760*9354STim.Marsland@Sun.COM 	57600, 76800, 115200, 153600, 230400, 307200, 460800, 921600
7610Sstevel@tonic-gate };
7620Sstevel@tonic-gate 
763669Schin void
prspeed(char * c,int s)764669Schin prspeed(char *c, int s)
7650Sstevel@tonic-gate {
766*9354STim.Marsland@Sun.COM 	(void) fprintf(output, "%s%d baud; ", c, speed[s]);
7670Sstevel@tonic-gate }
7680Sstevel@tonic-gate 
769669Schin /*
770669Schin  * print current settings for use with
771669Schin  * another stty cmd, used for -g option
772669Schin  */
773669Schin void
prencode(void)774669Schin prencode(void)
7750Sstevel@tonic-gate {
7760Sstevel@tonic-gate 	int i, last;
7770Sstevel@tonic-gate 
778669Schin 	/* Since the -g option is mostly used for redirecting to a file */
7790Sstevel@tonic-gate 	/* We must print to stdout here, not stderr */
7800Sstevel@tonic-gate 
781*9354STim.Marsland@Sun.COM 	(void) printf("%x:%x:%x:%x:", cb.c_iflag, cb.c_oflag,
782*9354STim.Marsland@Sun.COM 	    cb.c_cflag, cb.c_lflag);
7830Sstevel@tonic-gate 
784*9354STim.Marsland@Sun.COM 	if (term & TERMIOS)
7850Sstevel@tonic-gate 	/* last control slot is unused */
7860Sstevel@tonic-gate 		last = NCCS - 2;
7870Sstevel@tonic-gate 	else
7880Sstevel@tonic-gate 		last = NCC - 1;
789*9354STim.Marsland@Sun.COM 	for (i = 0; i < last; i++)
7900Sstevel@tonic-gate 		(void) printf("%x:", cb.c_cc[i]);
7910Sstevel@tonic-gate 	(void) printf("%x\n", cb.c_cc[last]);
7920Sstevel@tonic-gate }
793