xref: /illumos-gate/usr/src/ucbcmd/stty/stty.c (revision d9c3e05c)
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
5de81e71eSTim Marsland  * Common Development and Distribution License (the "License").
6de81e71eSTim Marsland  * 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  */
21de81e71eSTim Marsland 
227c478bd9Sstevel@tonic-gate /*
23de81e71eSTim Marsland  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <stdio.h>
31566b4223SToomas Soome #include <stdlib.h>
327c478bd9Sstevel@tonic-gate #include <ctype.h>
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <termio.h>
357c478bd9Sstevel@tonic-gate #include <sys/stermio.h>
367c478bd9Sstevel@tonic-gate #include <sys/termiox.h>
377c478bd9Sstevel@tonic-gate #include "stty.h"
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate extern char *getenv();
407c478bd9Sstevel@tonic-gate extern void exit();
417c478bd9Sstevel@tonic-gate extern void perror();
427c478bd9Sstevel@tonic-gate 
43de81e71eSTim Marsland static char *STTY = "stty: ";
44de81e71eSTim Marsland static char *USAGE = "usage: stty [-agh] [modes]\n";
457c478bd9Sstevel@tonic-gate static int	pitt = 0;
467c478bd9Sstevel@tonic-gate static struct termios cb;
477c478bd9Sstevel@tonic-gate static struct termio ocb; /* for non-streams devices */
487c478bd9Sstevel@tonic-gate static struct stio stio;
497c478bd9Sstevel@tonic-gate static struct termiox termiox;
507c478bd9Sstevel@tonic-gate static struct winsize winsize, owinsize;
517c478bd9Sstevel@tonic-gate static int term;
527c478bd9Sstevel@tonic-gate 
53cc6c5292Schin void prmodes(int);
54cc6c5292Schin void pramodes(int);
55cc6c5292Schin void prachars(void);
56cc6c5292Schin void pcol(int, int);
57cc6c5292Schin void pit(unsigned char, char *, char *);
58cc6c5292Schin void delay(int, char *s);
59cc6c5292Schin void prspeed(char *, int);
60cc6c5292Schin void prencode(void);
61cc6c5292Schin 
62de81e71eSTim Marsland #define	ioctl_desc	1
63de81e71eSTim Marsland #define	output		stderr
647c478bd9Sstevel@tonic-gate 
65cc6c5292Schin int
main(int argc,char * argv[])66cc6c5292Schin main(int argc, char *argv[])
677c478bd9Sstevel@tonic-gate {
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 	int i;
70de81e71eSTim Marsland 	char	*s_arg, *sttyparse();	/* s_arg: ptr to mode to be set */
717c478bd9Sstevel@tonic-gate 	extern const struct	speeds	speeds[];
72de81e71eSTim Marsland 
737c478bd9Sstevel@tonic-gate 	if (argc == 2) {
747c478bd9Sstevel@tonic-gate 		/*
757c478bd9Sstevel@tonic-gate 		 * "stty size", "stty speed" and "stty -g" are intended for
767c478bd9Sstevel@tonic-gate 		 * use within backquotes; thus, they do the "fetch" "ioctl"
777c478bd9Sstevel@tonic-gate 		 * from "/dev/tty" and always print their result on the
787c478bd9Sstevel@tonic-gate 		 * standard output.
797c478bd9Sstevel@tonic-gate 		 * Since their standard output is likely to be a pipe, they
807c478bd9Sstevel@tonic-gate 		 * should not try to read the modes from the standard output.
817c478bd9Sstevel@tonic-gate 		 */
827c478bd9Sstevel@tonic-gate 		if (strcmp(argv[1], "size") == 0) {
837c478bd9Sstevel@tonic-gate 			if ((i = open("/dev/tty", 0)) < 0) {
847c478bd9Sstevel@tonic-gate 				perror("stty: Cannot open /dev/tty");
857c478bd9Sstevel@tonic-gate 				exit(2);
867c478bd9Sstevel@tonic-gate 			}
877c478bd9Sstevel@tonic-gate 			if (ioctl(i, TIOCGWINSZ, &winsize) < 0) {
887c478bd9Sstevel@tonic-gate 				perror("stty: TIOCGWINSZ");
897c478bd9Sstevel@tonic-gate 				exit(2);
907c478bd9Sstevel@tonic-gate 			}
91de81e71eSTim Marsland 			(void) printf("%d %d\n",
92de81e71eSTim Marsland 			    winsize.ws_row, winsize.ws_col);
937c478bd9Sstevel@tonic-gate 			exit(0);
94de81e71eSTim Marsland 		} else if (strcmp(argv[1], "speed") == 0) {
957c478bd9Sstevel@tonic-gate 			if ((i = open("/dev/tty", 0)) < 0) {
967c478bd9Sstevel@tonic-gate 				perror("stty: Cannot open /dev/tty");
977c478bd9Sstevel@tonic-gate 				exit(2);
987c478bd9Sstevel@tonic-gate 			}
99de81e71eSTim Marsland 			if ((term = get_ttymode(i,
100de81e71eSTim Marsland 			    &ocb, &cb, &stio, &termiox, &winsize)) < 0) {
1017c478bd9Sstevel@tonic-gate 				perror(STTY);
1027c478bd9Sstevel@tonic-gate 				exit(2);
1037c478bd9Sstevel@tonic-gate 			}
1047c478bd9Sstevel@tonic-gate 			if (term & TERMIOS) {
105de81e71eSTim Marsland 				for (i = 0; speeds[i].string; i++)
106de81e71eSTim Marsland 					if (cfgetospeed(&cb) ==
107de81e71eSTim Marsland 					    speeds[i].speed) {
108de81e71eSTim Marsland 						(void) printf("%s\n",
109de81e71eSTim Marsland 						    speeds[i].string);
110de81e71eSTim Marsland 						exit(0);
111de81e71eSTim Marsland 					}
1127c478bd9Sstevel@tonic-gate 			} else {
113de81e71eSTim Marsland 				for (i = 0; speeds[i].string; i++)
114de81e71eSTim Marsland 					if ((cb.c_cflag&CBAUD) ==
115de81e71eSTim Marsland 					    speeds[i].speed) {
116de81e71eSTim Marsland 						(void) printf("%s\n",
117de81e71eSTim Marsland 						    speeds[i].string);
118de81e71eSTim Marsland 						exit(0);
119de81e71eSTim Marsland 					}
1207c478bd9Sstevel@tonic-gate 			}
1217c478bd9Sstevel@tonic-gate 			(void) printf("unknown\n");
1227c478bd9Sstevel@tonic-gate 			exit(1);
123de81e71eSTim Marsland 		} else if (strcmp(argv[1], "-g") == 0) {
1247c478bd9Sstevel@tonic-gate 			if ((i = open("/dev/tty", 0)) < 0) {
1257c478bd9Sstevel@tonic-gate 				perror("stty: Cannot open /dev/tty");
1267c478bd9Sstevel@tonic-gate 				exit(2);
1277c478bd9Sstevel@tonic-gate 			}
128de81e71eSTim Marsland 			if ((term = get_ttymode(i,
129de81e71eSTim Marsland 			    &ocb, &cb, &stio, &termiox, &winsize)) < 0) {
1307c478bd9Sstevel@tonic-gate 				perror(STTY);
1317c478bd9Sstevel@tonic-gate 				exit(2);
1327c478bd9Sstevel@tonic-gate 			}
1337c478bd9Sstevel@tonic-gate 			prencode();
1347c478bd9Sstevel@tonic-gate 			exit(0);
1357c478bd9Sstevel@tonic-gate 		}
1367c478bd9Sstevel@tonic-gate 	}
1377c478bd9Sstevel@tonic-gate 
138de81e71eSTim Marsland 	if ((term = get_ttymode(ioctl_desc,
139de81e71eSTim Marsland 	    &ocb, &cb, &stio, &termiox, &winsize)) < 0) {
1407c478bd9Sstevel@tonic-gate 		perror(STTY);
1417c478bd9Sstevel@tonic-gate 		exit(2);
1427c478bd9Sstevel@tonic-gate 	}
1437c478bd9Sstevel@tonic-gate 	owinsize = winsize;
1447c478bd9Sstevel@tonic-gate 	if (argc == 1) {
1457c478bd9Sstevel@tonic-gate 		prmodes(0);
1467c478bd9Sstevel@tonic-gate 		exit(0);
1477c478bd9Sstevel@tonic-gate 	}
148de81e71eSTim Marsland 	if ((argc == 2) && strcmp(argv[1], "all") == 0) {
1497c478bd9Sstevel@tonic-gate 		prmodes(1);
1507c478bd9Sstevel@tonic-gate 		exit(0);
1517c478bd9Sstevel@tonic-gate 	}
152de81e71eSTim Marsland 	if ((argc == 2) && strcmp(argv[1], "everything") == 0) {
1537c478bd9Sstevel@tonic-gate 		pramodes(1);
1547c478bd9Sstevel@tonic-gate 		exit(0);
1557c478bd9Sstevel@tonic-gate 	}
1567c478bd9Sstevel@tonic-gate 	if ((argc == 2) && (argv[1][0] == '-') && (argv[1][2] == '\0'))
157de81e71eSTim Marsland 		switch (argv[1][1]) {
1587c478bd9Sstevel@tonic-gate 		case 'a':
1597c478bd9Sstevel@tonic-gate 			pramodes(0);
1607c478bd9Sstevel@tonic-gate 			exit(0);
1617c478bd9Sstevel@tonic-gate 		case 'h':
1627c478bd9Sstevel@tonic-gate 			pramodes(1);
1637c478bd9Sstevel@tonic-gate 			exit(0);
1647c478bd9Sstevel@tonic-gate 		default:
1657c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s", USAGE);
1667c478bd9Sstevel@tonic-gate 			exit(2);
167de81e71eSTim Marsland 		}
168de81e71eSTim Marsland 	if (s_arg = sttyparse(argc, argv,
169de81e71eSTim Marsland 	    term, &ocb, &cb, &termiox, &winsize)) {
1707c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "unknown mode: %s\n", s_arg);
1717c478bd9Sstevel@tonic-gate 		exit(2);
1727c478bd9Sstevel@tonic-gate 	}
1737c478bd9Sstevel@tonic-gate 
174de81e71eSTim Marsland 	if (set_ttymode(ioctl_desc,
175de81e71eSTim Marsland 	    term, &ocb, &cb, &stio, &termiox, &winsize, &owinsize) == -1) {
1767c478bd9Sstevel@tonic-gate 		perror(STTY);
1777c478bd9Sstevel@tonic-gate 		exit(2);
1787c478bd9Sstevel@tonic-gate 	}
179cc6c5292Schin 	return (0);	/*NOTREACHED*/
1807c478bd9Sstevel@tonic-gate }
1817c478bd9Sstevel@tonic-gate 
182cc6c5292Schin void
prmodes(int moremodes)183cc6c5292Schin prmodes(int moremodes)
184cc6c5292Schin /* print modes, no options, argc is 1 */
1857c478bd9Sstevel@tonic-gate {
186cc6c5292Schin 	int m;
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 	if (!(term & ASYNC)) {
1897c478bd9Sstevel@tonic-gate 		m = stio.imode;
190de81e71eSTim Marsland 		if (m & IUCLC)
191de81e71eSTim Marsland 			(void) fprintf(output, "iuclc ");
192de81e71eSTim Marsland 		else
193de81e71eSTim Marsland 			(void) fprintf(output, "-iuclc ");
1947c478bd9Sstevel@tonic-gate 		m = stio.omode;
195de81e71eSTim Marsland 		if (m & OLCUC)
196de81e71eSTim Marsland 			(void) fprintf(output, "olcuc ");
197de81e71eSTim Marsland 		else
198de81e71eSTim Marsland 			(void) fprintf(output, "-olcuc ");
199de81e71eSTim Marsland 		if (m & TAB3)
200de81e71eSTim Marsland 			(void) fprintf(output, "tab3 ");
2017c478bd9Sstevel@tonic-gate 		m = stio.lmode;
202de81e71eSTim Marsland 		if (m & XCASE)
203de81e71eSTim Marsland 			(void) fprintf(output, "xcase ");
204de81e71eSTim Marsland 		else
205de81e71eSTim Marsland 			(void) fprintf(output, "-xcase ");
206de81e71eSTim Marsland 		if (m & STFLUSH)
207de81e71eSTim Marsland 			(void) fprintf(output, "stflush ");
208de81e71eSTim Marsland 		else
209de81e71eSTim Marsland 			(void) fprintf(output, "-stflush ");
210de81e71eSTim Marsland 		if (m & STWRAP)
211de81e71eSTim Marsland 			(void) fprintf(output, "stwrap ");
212de81e71eSTim Marsland 		else
213de81e71eSTim Marsland 			(void) fprintf(output, "-stwrap ");
214de81e71eSTim Marsland 		if (m & STAPPL)
215de81e71eSTim Marsland 			(void) fprintf(output, "stappl ");
216de81e71eSTim Marsland 		else
217de81e71eSTim Marsland 			(void) fprintf(output, "-stappl ");
2187c478bd9Sstevel@tonic-gate 		(void) fprintf(output, "\n");
2197c478bd9Sstevel@tonic-gate 	}
2207c478bd9Sstevel@tonic-gate 	if (term & ASYNC) {
2217c478bd9Sstevel@tonic-gate 		m = cb.c_cflag;
2227c478bd9Sstevel@tonic-gate 		if ((term & TERMIOS) && cfgetispeed(&cb) != 0 &&
2237c478bd9Sstevel@tonic-gate 		    cfgetispeed(&cb) != cfgetospeed(&cb)) {
2247c478bd9Sstevel@tonic-gate 			prspeed("ispeed ", cfgetispeed(&cb));
2257c478bd9Sstevel@tonic-gate 			prspeed("ospeed ", cfgetospeed(&cb));
2267c478bd9Sstevel@tonic-gate 		} else
2277c478bd9Sstevel@tonic-gate 			prspeed("speed ", cfgetospeed(&cb));
228de81e71eSTim Marsland 		if (m & PARENB) {
229de81e71eSTim Marsland 			if ((m & PAREXT) && (term & TERMIOS)) {
230de81e71eSTim Marsland 				if (m & PARODD)
231de81e71eSTim Marsland 					(void) fprintf(output, "markp ");
2327c478bd9Sstevel@tonic-gate 				else
233de81e71eSTim Marsland 					(void) fprintf(output, "spacep ");
2347c478bd9Sstevel@tonic-gate 			} else {
235de81e71eSTim Marsland 				if (m & PARODD)
236de81e71eSTim Marsland 					(void) fprintf(output, "oddp ");
2377c478bd9Sstevel@tonic-gate 				else
238de81e71eSTim Marsland 					(void) fprintf(output, "evenp ");
2397c478bd9Sstevel@tonic-gate 			}
2407c478bd9Sstevel@tonic-gate 		} else
241de81e71eSTim Marsland 			(void) fprintf(output, "-parity ");
242de81e71eSTim Marsland 		if (((m & PARENB) && !(m & CS7)) ||
243de81e71eSTim Marsland 		    (!(m & PARENB) && !(m & CS8)))
244de81e71eSTim Marsland 			(void) fprintf(output, "cs%c ", '5' + (m & CSIZE)/CS6);
245de81e71eSTim Marsland 		if (m & CSTOPB)
246de81e71eSTim Marsland 			(void) fprintf(output, "cstopb ");
247de81e71eSTim Marsland 		if (m & HUPCL)
248de81e71eSTim Marsland 			(void) fprintf(output, "hupcl ");
249de81e71eSTim Marsland 		if (!(m & CREAD))
250de81e71eSTim Marsland 			(void) fprintf(output, "-cread ");
251de81e71eSTim Marsland 		if (m & CLOCAL)
252de81e71eSTim Marsland 			(void) fprintf(output, "clocal ");
253de81e71eSTim Marsland 		if (m & LOBLK)
254de81e71eSTim Marsland 			(void) fprintf(output, "loblk ");
255de81e71eSTim Marsland 		(void) fprintf(output, "\n");
256de81e71eSTim Marsland 		if (ocb.c_line != 0)
257de81e71eSTim Marsland 			(void) fprintf(output, "line = %d; ", ocb.c_line);
258de81e71eSTim Marsland 		if (term & WINDOW) {
259de81e71eSTim Marsland 			(void) fprintf(output, "rows = %d; columns = %d;",
260de81e71eSTim Marsland 			    winsize.ws_row, winsize.ws_col);
261de81e71eSTim Marsland 			(void) fprintf(output, " ypixels = %d; xpixels = %d;\n",
262de81e71eSTim Marsland 			    winsize.ws_ypixel, winsize.ws_xpixel);
2637c478bd9Sstevel@tonic-gate 		}
264de81e71eSTim Marsland 		if ((cb.c_lflag & ICANON) == 0)
265de81e71eSTim Marsland 			(void) fprintf(output, "min = %d; time = %d;\n",
266de81e71eSTim Marsland 			    cb.c_cc[VMIN], cb.c_cc[VTIME]);
2677c478bd9Sstevel@tonic-gate 		if (!moremodes) {
268de81e71eSTim Marsland 			if (cb.c_cc[VINTR] != CINTR)
2697c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VINTR], "intr", "; ");
270de81e71eSTim Marsland 			if (cb.c_cc[VQUIT] != CQUIT)
2717c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VQUIT], "quit", "; ");
272de81e71eSTim Marsland 			if (cb.c_cc[VERASE] != CERASE)
2737c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VERASE], "erase", "; ");
274de81e71eSTim Marsland 			if (cb.c_cc[VKILL] != CKILL)
2757c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VKILL], "kill", "; ");
276de81e71eSTim Marsland 			if (cb.c_cc[VEOF] != CEOF)
2777c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VEOF], "eof", "; ");
278de81e71eSTim Marsland 			if (cb.c_cc[VEOL] != CNUL)
2797c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VEOL], "eol", "; ");
280de81e71eSTim Marsland 			if (cb.c_cc[VEOL2] != CNUL)
2817c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VEOL2], "eol2", "; ");
282de81e71eSTim Marsland 			if (cb.c_cc[VSWTCH] != CSWTCH)
2837c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VSWTCH], "swtch", "; ");
284de81e71eSTim Marsland 			if (term & TERMIOS) {
285de81e71eSTim Marsland 				if (cb.c_cc[VSTART] != CSTART)
2867c478bd9Sstevel@tonic-gate 					pit(cb.c_cc[VSTART], "start", "; ");
287de81e71eSTim Marsland 				if (cb.c_cc[VSTOP] != CSTOP)
2887c478bd9Sstevel@tonic-gate 					pit(cb.c_cc[VSTOP], "stop", "; ");
289de81e71eSTim Marsland 				if (cb.c_cc[VSUSP] != CSUSP)
2907c478bd9Sstevel@tonic-gate 					pit(cb.c_cc[VSUSP], "susp", "; ");
291de81e71eSTim Marsland 				if (cb.c_cc[VDSUSP] != CDSUSP)
2927c478bd9Sstevel@tonic-gate 					pit(cb.c_cc[VDSUSP], "dsusp", "; ");
293de81e71eSTim Marsland 				if (cb.c_cc[VREPRINT] != CRPRNT)
2947c478bd9Sstevel@tonic-gate 					pit(cb.c_cc[VREPRINT], "rprnt", "; ");
295de81e71eSTim Marsland 				if (cb.c_cc[VDISCARD] != CFLUSH)
2967c478bd9Sstevel@tonic-gate 					pit(cb.c_cc[VDISCARD], "flush", "; ");
297de81e71eSTim Marsland 				if (cb.c_cc[VWERASE] != CWERASE)
2987c478bd9Sstevel@tonic-gate 					pit(cb.c_cc[VWERASE], "werase", "; ");
299de81e71eSTim Marsland 				if (cb.c_cc[VLNEXT] != CLNEXT)
3007c478bd9Sstevel@tonic-gate 					pit(cb.c_cc[VLNEXT], "lnext", "; ");
3017c478bd9Sstevel@tonic-gate 			}
3027c478bd9Sstevel@tonic-gate 		}
303de81e71eSTim Marsland 		if (pitt)
304de81e71eSTim Marsland 			(void) fprintf(output, "\n");
3057c478bd9Sstevel@tonic-gate 		m = cb.c_iflag;
306de81e71eSTim Marsland 		if (m & IGNBRK)
307de81e71eSTim Marsland 			(void) fprintf(output, "ignbrk ");
308de81e71eSTim Marsland 		else if (!(m & BRKINT))
309de81e71eSTim Marsland 			(void) fprintf(output, "-brkint ");
310de81e71eSTim Marsland 		if (!(m & INPCK))
311de81e71eSTim Marsland 			(void) fprintf(output, "-inpck ");
312de81e71eSTim Marsland 		else if (!(m & IGNPAR))
313de81e71eSTim Marsland 			(void) fprintf(output, "-ignpar ");
314de81e71eSTim Marsland 		if (m & PARMRK)
315de81e71eSTim Marsland 			(void) fprintf(output, "parmrk ");
316de81e71eSTim Marsland 		if (!(m & ISTRIP))
317de81e71eSTim Marsland 			(void) fprintf(output, "-istrip ");
318de81e71eSTim Marsland 		if (m & INLCR)
319de81e71eSTim Marsland 			(void) fprintf(output, "inlcr ");
320de81e71eSTim Marsland 		if (m & IGNCR)
321de81e71eSTim Marsland 			(void) fprintf(output, "igncr ");
322de81e71eSTim Marsland 		if (!(m & ICRNL))
323de81e71eSTim Marsland 			(void) fprintf(output, "-icrnl ");
324de81e71eSTim Marsland 		if (m & IUCLC)
325de81e71eSTim Marsland 			(void) fprintf(output, "iuclc ");
326de81e71eSTim Marsland 		if (!(m & IXON))
327de81e71eSTim Marsland 			(void) fprintf(output, "-ixon ");
328de81e71eSTim Marsland 		else if (m & IXANY)
329de81e71eSTim Marsland 			(void) fprintf(output, "ixany ");
330de81e71eSTim Marsland 		if (m & IXOFF)
331de81e71eSTim Marsland 			(void) fprintf(output, "ixoff ");
332de81e71eSTim Marsland 		if ((term & TERMIOS) && (m & IMAXBEL))
333de81e71eSTim Marsland 			(void) fprintf(output, "imaxbel ");
3347c478bd9Sstevel@tonic-gate 		m = cb.c_oflag;
335de81e71eSTim Marsland 		if (!(m & OPOST))
336de81e71eSTim Marsland 			(void) fprintf(output, "-opost ");
3377c478bd9Sstevel@tonic-gate 		else {
338de81e71eSTim Marsland 			if (m & OLCUC)
339de81e71eSTim Marsland 				(void) fprintf(output, "olcuc ");
340de81e71eSTim Marsland 			if (!(m & ONLCR))
341de81e71eSTim Marsland 				(void) fprintf(output, "-onlcr ");
342de81e71eSTim Marsland 			if (m & OCRNL)
343de81e71eSTim Marsland 				(void) fprintf(output, "ocrnl ");
344de81e71eSTim Marsland 			if (m & ONOCR)
345de81e71eSTim Marsland 				(void) fprintf(output, "onocr ");
346de81e71eSTim Marsland 			if (m & ONLRET)
347de81e71eSTim Marsland 				(void) fprintf(output, "onlret ");
348de81e71eSTim Marsland 			if (m & OFILL)
349de81e71eSTim Marsland 				if (m & OFDEL)
350de81e71eSTim Marsland 					(void) fprintf(output, "del-fill ");
351de81e71eSTim Marsland 				else
352de81e71eSTim Marsland 					(void) fprintf(output, "nul-fill ");
353de81e71eSTim Marsland 			delay((m & CRDLY)/CR1, "cr");
354de81e71eSTim Marsland 			delay((m & NLDLY)/NL1, "nl");
355de81e71eSTim Marsland 			if ((m & TABDLY) == XTABS)
356de81e71eSTim Marsland 				(void) fprintf(output, "-tabs ");
3577c478bd9Sstevel@tonic-gate 			else
358de81e71eSTim Marsland 				delay((m & TABDLY)/TAB1, "tab");
359de81e71eSTim Marsland 			delay((m & BSDLY)/BS1, "bs");
360de81e71eSTim Marsland 			delay((m & VTDLY)/VT1, "vt");
361de81e71eSTim Marsland 			delay((m & FFDLY)/FF1, "ff");
3627c478bd9Sstevel@tonic-gate 		}
363de81e71eSTim Marsland 		(void) fprintf(output, "\n");
3647c478bd9Sstevel@tonic-gate 		m = cb.c_lflag;
365de81e71eSTim Marsland 		if (!(m & ISIG))
366de81e71eSTim Marsland 			(void) fprintf(output, "-isig ");
367de81e71eSTim Marsland 		if (!(m & ICANON))
368de81e71eSTim Marsland 			(void) fprintf(output, "-icanon ");
369de81e71eSTim Marsland 		if (m & XCASE)
370de81e71eSTim Marsland 			(void) fprintf(output, "xcase ");
371de81e71eSTim Marsland 		if (!(m & ECHO))
372de81e71eSTim Marsland 			(void) fprintf(output, "-echo ");
373de81e71eSTim Marsland 		if (m & ECHOE) {
374de81e71eSTim Marsland 			if (m & ECHOKE)
375de81e71eSTim Marsland 				(void) fprintf(output, "crt ");
3767c478bd9Sstevel@tonic-gate 			else
377de81e71eSTim Marsland 				(void) fprintf(output, "echoe -echoke ");
3787c478bd9Sstevel@tonic-gate 		} else {
379de81e71eSTim Marsland 			if (!(m & ECHOPRT))
380de81e71eSTim Marsland 				(void) fprintf(output, "-echoprt ");
3817c478bd9Sstevel@tonic-gate 		}
382de81e71eSTim Marsland 		if (!(m & ECHOK))
383de81e71eSTim Marsland 			(void) fprintf(output, "-echok ");
384de81e71eSTim Marsland 		if (m & ECHONL)
385de81e71eSTim Marsland 			(void) fprintf(output, "echonl ");
386de81e71eSTim Marsland 		if (m & NOFLSH)
387de81e71eSTim Marsland 			(void) fprintf(output, "noflsh ");
388de81e71eSTim Marsland 		if (m & TOSTOP)
389de81e71eSTim Marsland 			(void) fprintf(output, "tostop ");
390de81e71eSTim Marsland 		if (!(m & ECHOCTL))
391de81e71eSTim Marsland 			(void) fprintf(output, "-echoctl ");
392de81e71eSTim Marsland 		if (m & DEFECHO)
393de81e71eSTim Marsland 			(void) fprintf(output, "defecho ");
394de81e71eSTim Marsland 		if (m & FLUSHO)
395de81e71eSTim Marsland 			(void) fprintf(output, "flusho ");
396de81e71eSTim Marsland 		if (m & PENDIN)
397de81e71eSTim Marsland 			(void) fprintf(output, "pendin ");
398de81e71eSTim Marsland 		if (m & IEXTEN)
399de81e71eSTim Marsland 			(void) fprintf(output, "iexten ");
400de81e71eSTim Marsland 		(void) fprintf(output, "\n");
4017c478bd9Sstevel@tonic-gate 	}
402de81e71eSTim Marsland 	if (term & FLOW) {
4037c478bd9Sstevel@tonic-gate 		m = termiox.x_hflag;
404de81e71eSTim Marsland 		if (m & RTSXOFF)
405de81e71eSTim Marsland 			(void) fprintf(output, "rtsxoff ");
406de81e71eSTim Marsland 		if (m & CTSXON)
407de81e71eSTim Marsland 			(void) fprintf(output, "ctsxon ");
408de81e71eSTim Marsland 		if (m & DTRXOFF)
409de81e71eSTim Marsland 			(void) fprintf(output, "dterxoff ");
410de81e71eSTim Marsland 		if (m & CDXON)
411de81e71eSTim Marsland 			(void) fprintf(output, "rlsdxon ");
412de81e71eSTim Marsland 		if (m & ISXOFF)
413de81e71eSTim Marsland 			(void) fprintf(output, "isxoff ");
4147c478bd9Sstevel@tonic-gate 		m = termiox.x_cflag;
415de81e71eSTim Marsland 		switch (m & XMTCLK) {
416de81e71eSTim Marsland 		case XCIBRG:
417de81e71eSTim Marsland 			(void) fprintf(output, "xcibrg ");
418de81e71eSTim Marsland 			break;
419de81e71eSTim Marsland 		case XCTSET:
420de81e71eSTim Marsland 			(void) fprintf(output, "xctset ");
421de81e71eSTim Marsland 			break;
422de81e71eSTim Marsland 		case XCRSET:
423de81e71eSTim Marsland 			(void) fprintf(output, "xcrset ");
424de81e71eSTim Marsland 			break;
4257c478bd9Sstevel@tonic-gate 		}
426de81e71eSTim Marsland 
427de81e71eSTim Marsland 		switch (m & RCVCLK) {
428de81e71eSTim Marsland 		case RCIBRG:
429de81e71eSTim Marsland 			(void) fprintf(output, "rcibrg ");
430de81e71eSTim Marsland 			break;
431de81e71eSTim Marsland 		case RCTSET:
432de81e71eSTim Marsland 			(void) fprintf(output, "rctset ");
433de81e71eSTim Marsland 			break;
434de81e71eSTim Marsland 		case RCRSET:
435de81e71eSTim Marsland 			(void) fprintf(output, "rcrset ");
436de81e71eSTim Marsland 			break;
4377c478bd9Sstevel@tonic-gate 		}
438de81e71eSTim Marsland 
439de81e71eSTim Marsland 		switch (m & TSETCLK) {
440de81e71eSTim Marsland 		case TSETCOFF:
441de81e71eSTim Marsland 			(void) fprintf(output, "tsetcoff ");
442de81e71eSTim Marsland 			break;
443de81e71eSTim Marsland 		case TSETCRBRG:
444de81e71eSTim Marsland 			(void) fprintf(output, "tsetcrc ");
445de81e71eSTim Marsland 			break;
446de81e71eSTim Marsland 		case TSETCTBRG:
447de81e71eSTim Marsland 			(void) fprintf(output, "tsetcxc ");
448de81e71eSTim Marsland 			break;
4497c478bd9Sstevel@tonic-gate 		}
450de81e71eSTim Marsland 
451de81e71eSTim Marsland 		switch (m & RSETCLK) {
452de81e71eSTim Marsland 		case RSETCOFF:
453de81e71eSTim Marsland 			(void) fprintf(output, "rsetcoff ");
454de81e71eSTim Marsland 			break;
455de81e71eSTim Marsland 		case RSETCRBRG:
456de81e71eSTim Marsland 			(void) fprintf(output, "rsetcrc ");
457de81e71eSTim Marsland 			break;
458de81e71eSTim Marsland 		case RSETCTBRG:
459de81e71eSTim Marsland 			(void) fprintf(output, "rsetcxc ");
4607c478bd9Sstevel@tonic-gate 		}
461de81e71eSTim Marsland 		(void) fprintf(output, "\n");
4627c478bd9Sstevel@tonic-gate 	}
463de81e71eSTim Marsland 	if (moremodes)
4647c478bd9Sstevel@tonic-gate 		prachars();
4657c478bd9Sstevel@tonic-gate }
4667c478bd9Sstevel@tonic-gate 
467cc6c5292Schin void
pramodes(int tabform)468cc6c5292Schin pramodes(int tabform)
469cc6c5292Schin /* print all modes, -a option */
4707c478bd9Sstevel@tonic-gate {
471cc6c5292Schin 	int m;
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate 	m = cb.c_cflag;
474de81e71eSTim Marsland 	if (term & ASYNC) {
4757c478bd9Sstevel@tonic-gate 		if ((term & TERMIOS) && cfgetispeed(&cb) != 0 &&
4767c478bd9Sstevel@tonic-gate 		    cfgetispeed(&cb) != cfgetospeed(&cb)) {
4777c478bd9Sstevel@tonic-gate 			prspeed("ispeed ", cfgetispeed(&cb));
4787c478bd9Sstevel@tonic-gate 			prspeed("ospeed ", cfgetospeed(&cb));
4797c478bd9Sstevel@tonic-gate 		} else
4807c478bd9Sstevel@tonic-gate 			prspeed("speed ", cfgetospeed(&cb));
481de81e71eSTim Marsland 		if (!(term & TERMIOS))
482de81e71eSTim Marsland 			(void) fprintf(output, "line = %d; ", ocb.c_line);
483de81e71eSTim Marsland 		(void) fprintf(output, "\n");
484de81e71eSTim Marsland 		if (term & WINDOW) {
485de81e71eSTim Marsland 			(void) fprintf(output, "rows = %d columns = %d; ",
486de81e71eSTim Marsland 			    winsize.ws_row, winsize.ws_col);
487de81e71eSTim Marsland 			(void) fprintf(output, "ypixels = %d xpixels = %d\n",
488de81e71eSTim Marsland 			    winsize.ws_ypixel, winsize.ws_xpixel);
4897c478bd9Sstevel@tonic-gate 		}
490de81e71eSTim Marsland 		if ((cb.c_lflag & ICANON) == 0)
491de81e71eSTim Marsland 			(void) fprintf(output, "min = %d; time = %d;\n",
492de81e71eSTim Marsland 			    cb.c_cc[VMIN], cb.c_cc[VTIME]);
4937c478bd9Sstevel@tonic-gate 		if (!tabform) {
4947c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VINTR], "intr", "; ");
4957c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VQUIT], "quit", "; ");
4967c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VERASE], "erase", "; ");
4977c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VKILL], "kill", ";\n");
4987c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VEOF], "eof", "; ");
4997c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VEOL], "eol", "; ");
5007c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VEOL2], "eol2", "; ");
5017c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VSWTCH], "swtch", ";\n");
502de81e71eSTim Marsland 			if (term & TERMIOS) {
5037c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VSTART], "start", "; ");
5047c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VSTOP], "stop", "; ");
5057c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VSUSP], "susp", "; ");
5067c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VDSUSP], "dsusp", ";\n");
5077c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VREPRINT], "rprnt", "; ");
5087c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VDISCARD], "flush", "; ");
5097c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VWERASE], "werase", "; ");
5107c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VLNEXT], "lnext", ";\n");
5117c478bd9Sstevel@tonic-gate 			}
5127c478bd9Sstevel@tonic-gate 		}
5137c478bd9Sstevel@tonic-gate 	} else
5147c478bd9Sstevel@tonic-gate 		pit((unsigned)stio.tab, "ctab", "\n");
5157c478bd9Sstevel@tonic-gate 	m = cb.c_cflag;
516de81e71eSTim Marsland 	(void) fprintf(output, "-parenb " + ((m & PARENB) != 0));
517de81e71eSTim Marsland 	(void) fprintf(output, "-parodd " + ((m & PARODD) != 0));
518de81e71eSTim Marsland 	(void) fprintf(output, "cs%c ", '5'+ (m & CSIZE)/CS6);
519de81e71eSTim Marsland 	(void) fprintf(output, "-cstopb " + ((m & CSTOPB) != 0));
520de81e71eSTim Marsland 	(void) fprintf(output, "-hupcl " + ((m & HUPCL) != 0));
521de81e71eSTim Marsland 	(void) fprintf(output, "-cread " + ((m & CREAD) != 0));
522de81e71eSTim Marsland 	(void) fprintf(output, "-clocal " + ((m & CLOCAL) != 0));
523de81e71eSTim Marsland 
524de81e71eSTim Marsland 	(void) fprintf(output, "-loblk " + ((m & LOBLK) != 0));
525de81e71eSTim Marsland 	if (term & TERMIOS)
526de81e71eSTim Marsland 		(void) fprintf(output, "-parext " + ((m & PAREXT) != 0));
527de81e71eSTim Marsland 
528de81e71eSTim Marsland 	(void) fprintf(output, "\n");
5297c478bd9Sstevel@tonic-gate 	m = cb.c_iflag;
530de81e71eSTim Marsland 	(void) fprintf(output, "-ignbrk " + ((m & IGNBRK) != 0));
531de81e71eSTim Marsland 	(void) fprintf(output, "-brkint " + ((m & BRKINT) != 0));
532de81e71eSTim Marsland 	(void) fprintf(output, "-ignpar " + ((m & IGNPAR) != 0));
533de81e71eSTim Marsland 	(void) fprintf(output, "-parmrk " + ((m & PARMRK) != 0));
534de81e71eSTim Marsland 	(void) fprintf(output, "-inpck " + ((m & INPCK) != 0));
535de81e71eSTim Marsland 	(void) fprintf(output, "-istrip " + ((m & ISTRIP) != 0));
536de81e71eSTim Marsland 	(void) fprintf(output, "-inlcr " + ((m & INLCR) != 0));
537de81e71eSTim Marsland 	(void) fprintf(output, "-igncr " + ((m & IGNCR) != 0));
538de81e71eSTim Marsland 	(void) fprintf(output, "-icrnl " + ((m & ICRNL) != 0));
539de81e71eSTim Marsland 	(void) fprintf(output, "-iuclc " + ((m & IUCLC) != 0));
540de81e71eSTim Marsland 	(void) fprintf(output, "\n");
541de81e71eSTim Marsland 	(void) fprintf(output, "-ixon " + ((m & IXON) != 0));
542de81e71eSTim Marsland 	(void) fprintf(output, "-ixany " + ((m & IXANY) != 0));
543de81e71eSTim Marsland 	(void) fprintf(output, "-ixoff " + ((m & IXOFF) != 0));
544de81e71eSTim Marsland 	if (term & TERMIOS)
545de81e71eSTim Marsland 		(void) fprintf(output, "-imaxbel " + ((m & IMAXBEL) != 0));
546de81e71eSTim Marsland 	(void) fprintf(output, "\n");
5477c478bd9Sstevel@tonic-gate 	m = cb.c_lflag;
548de81e71eSTim Marsland 	(void) fprintf(output, "-isig " + ((m & ISIG) != 0));
549de81e71eSTim Marsland 	(void) fprintf(output, "-icanon " + ((m & ICANON) != 0));
550de81e71eSTim Marsland 	(void) fprintf(output, "-xcase " + ((m & XCASE) != 0));
551de81e71eSTim Marsland 	(void) fprintf(output, "-echo " + ((m & ECHO) != 0));
552de81e71eSTim Marsland 	(void) fprintf(output, "-echoe " + ((m & ECHOE) != 0));
553de81e71eSTim Marsland 	(void) fprintf(output, "-echok " + ((m & ECHOK) != 0));
554de81e71eSTim Marsland 	(void) fprintf(output, "-echonl " + ((m & ECHONL) != 0));
555de81e71eSTim Marsland 	(void) fprintf(output, "-noflsh " + ((m & NOFLSH) != 0));
556de81e71eSTim Marsland 	if (term & TERMIOS) {
557de81e71eSTim Marsland 		(void) fprintf(output, "\n");
558de81e71eSTim Marsland 		(void) fprintf(output, "-tostop " + ((m & TOSTOP) != 0));
559de81e71eSTim Marsland 		(void) fprintf(output, "-echoctl " + ((m & ECHOCTL) != 0));
560de81e71eSTim Marsland 		(void) fprintf(output, "-echoprt " + ((m & ECHOPRT) != 0));
561de81e71eSTim Marsland 		(void) fprintf(output, "-echoke " + ((m & ECHOKE) != 0));
562de81e71eSTim Marsland 		(void) fprintf(output, "-defecho " + ((m & DEFECHO) != 0));
563de81e71eSTim Marsland 		(void) fprintf(output, "-flusho " + ((m & FLUSHO) != 0));
564de81e71eSTim Marsland 		(void) fprintf(output, "-pendin " + ((m & PENDIN) != 0));
565de81e71eSTim Marsland 		(void) fprintf(output, "-iexten " + ((m & IEXTEN) != 0));
5667c478bd9Sstevel@tonic-gate 	}
567de81e71eSTim Marsland 	if (!(term & ASYNC)) {
568de81e71eSTim Marsland 		(void) fprintf(output, "-stflush " + ((m & STFLUSH) != 0));
569de81e71eSTim Marsland 		(void) fprintf(output, "-stwrap " + ((m & STWRAP) != 0));
570de81e71eSTim Marsland 		(void) fprintf(output, "-stappl " + ((m & STAPPL) != 0));
5717c478bd9Sstevel@tonic-gate 	}
572de81e71eSTim Marsland 	(void) fprintf(output, "\n");
5737c478bd9Sstevel@tonic-gate 	m = cb.c_oflag;
574de81e71eSTim Marsland 	(void) fprintf(output, "-opost " + ((m & OPOST) != 0));
575de81e71eSTim Marsland 	(void) fprintf(output, "-olcuc " + ((m & OLCUC) != 0));
576de81e71eSTim Marsland 	(void) fprintf(output, "-onlcr " + ((m & ONLCR) != 0));
577de81e71eSTim Marsland 	(void) fprintf(output, "-ocrnl " + ((m & OCRNL) != 0));
578de81e71eSTim Marsland 	(void) fprintf(output, "-onocr " + ((m & ONOCR) != 0));
579de81e71eSTim Marsland 	(void) fprintf(output, "-onlret " + ((m & ONLRET) != 0));
580de81e71eSTim Marsland 	(void) fprintf(output, "-ofill " + ((m & OFILL) != 0));
581de81e71eSTim Marsland 	(void) fprintf(output, "-ofdel " + ((m & OFDEL) != 0));
582de81e71eSTim Marsland 	delay((m & CRDLY)/CR1, "cr");
583de81e71eSTim Marsland 	delay((m & NLDLY)/NL1, "nl");
584de81e71eSTim Marsland 	if ((m & TABDLY) == XTABS)
585de81e71eSTim Marsland 		(void) fprintf(output, "-tabs ");
5867c478bd9Sstevel@tonic-gate 	else
587de81e71eSTim Marsland 		delay((m & TABDLY)/TAB1, "tab");
588de81e71eSTim Marsland 	delay((m & BSDLY)/BS1, "bs");
589de81e71eSTim Marsland 	delay((m & VTDLY)/VT1, "vt");
590de81e71eSTim Marsland 	delay((m & FFDLY)/FF1, "ff");
591de81e71eSTim Marsland 	(void) fprintf(output, "\n");
592de81e71eSTim Marsland 	if (term & FLOW) {
5937c478bd9Sstevel@tonic-gate 		m = termiox.x_hflag;
594de81e71eSTim Marsland 		(void) fprintf(output, "-rtsxoff " + ((m & RTSXOFF) != 0));
595de81e71eSTim Marsland 		(void) fprintf(output, "-ctsxon " + ((m & CTSXON) != 0));
596de81e71eSTim Marsland 		(void) fprintf(output, "-dterxoff " + ((m & DTRXOFF) != 0));
597de81e71eSTim Marsland 		(void) fprintf(output, "-rlsdxon " + ((m & CDXON) != 0));
598de81e71eSTim Marsland 		(void) fprintf(output, "-isxoff " + ((m & ISXOFF) != 0));
5997c478bd9Sstevel@tonic-gate 		m = termiox.x_cflag;
600de81e71eSTim Marsland 		switch (m & XMTCLK) {
601de81e71eSTim Marsland 		case XCIBRG:
602de81e71eSTim Marsland 			(void) fprintf(output, "xcibrg ");
603de81e71eSTim Marsland 			break;
604de81e71eSTim Marsland 		case XCTSET:
605de81e71eSTim Marsland 			(void) fprintf(output, "xctset ");
606de81e71eSTim Marsland 			break;
607de81e71eSTim Marsland 		case XCRSET:
608de81e71eSTim Marsland 			(void) fprintf(output, "xcrset ");
609de81e71eSTim Marsland 			break;
6107c478bd9Sstevel@tonic-gate 		}
611de81e71eSTim Marsland 
612de81e71eSTim Marsland 		switch (m & RCVCLK) {
613de81e71eSTim Marsland 		case RCIBRG:
614de81e71eSTim Marsland 			(void) fprintf(output, "rcibrg ");
615de81e71eSTim Marsland 			break;
616de81e71eSTim Marsland 		case RCTSET:
617de81e71eSTim Marsland 			(void) fprintf(output, "rctset ");
618de81e71eSTim Marsland 			break;
619de81e71eSTim Marsland 		case RCRSET:
620de81e71eSTim Marsland 			(void) fprintf(output, "rcrset ");
621de81e71eSTim Marsland 			break;
6227c478bd9Sstevel@tonic-gate 		}
623de81e71eSTim Marsland 
624de81e71eSTim Marsland 		switch (m & TSETCLK) {
625de81e71eSTim Marsland 		case TSETCOFF:
626de81e71eSTim Marsland 			(void) fprintf(output, "tsetcoff ");
627de81e71eSTim Marsland 			break;
628de81e71eSTim Marsland 		case TSETCRBRG:
629de81e71eSTim Marsland 			(void) fprintf(output, "tsetcrc ");
630de81e71eSTim Marsland 			break;
631de81e71eSTim Marsland 		case TSETCTBRG:
632de81e71eSTim Marsland 			(void) fprintf(output, "tsetcxc ");
633de81e71eSTim Marsland 			break;
6347c478bd9Sstevel@tonic-gate 		}
635de81e71eSTim Marsland 
636de81e71eSTim Marsland 		switch (m & RSETCLK) {
637de81e71eSTim Marsland 		case RSETCOFF:
638de81e71eSTim Marsland 			(void) fprintf(output, "rsetcoff ");
639de81e71eSTim Marsland 			break;
640de81e71eSTim Marsland 		case RSETCRBRG:
641de81e71eSTim Marsland 			(void) fprintf(output, "rsetcrc ");
642de81e71eSTim Marsland 			break;
643de81e71eSTim Marsland 		case RSETCTBRG:
644de81e71eSTim Marsland 			(void) fprintf(output, "rsetcxc ");
645de81e71eSTim Marsland 			break;
6467c478bd9Sstevel@tonic-gate 		}
647de81e71eSTim Marsland 		(void) fprintf(output, "\n");
6487c478bd9Sstevel@tonic-gate 	}
6497c478bd9Sstevel@tonic-gate 	if (tabform)
6507c478bd9Sstevel@tonic-gate 		prachars();
6517c478bd9Sstevel@tonic-gate }
6527c478bd9Sstevel@tonic-gate 
653cc6c5292Schin void
prachars(void)654cc6c5292Schin prachars(void)
6557c478bd9Sstevel@tonic-gate {
656de81e71eSTim Marsland 	if ((cb.c_lflag & ICANON) == 0)
657de81e71eSTim Marsland 		(void) fprintf(output, "min %d, time %d\n", cb.c_cc[VMIN],
6587c478bd9Sstevel@tonic-gate 		    cb.c_cc[VTIME]);
659de81e71eSTim Marsland 	(void) fprintf(output, "\
6607c478bd9Sstevel@tonic-gate erase  kill   werase rprnt  flush  lnext  susp   intr   quit   stop   eof\
6617c478bd9Sstevel@tonic-gate \n");
6627c478bd9Sstevel@tonic-gate 	pcol(cb.c_cc[VERASE], 0);
6637c478bd9Sstevel@tonic-gate 	pcol(cb.c_cc[VKILL], 0);
6647c478bd9Sstevel@tonic-gate 	pcol(cb.c_cc[VWERASE], 0);
6657c478bd9Sstevel@tonic-gate 	pcol(cb.c_cc[VREPRINT], 0);
6667c478bd9Sstevel@tonic-gate 	pcol(cb.c_cc[VDISCARD], 0);
6677c478bd9Sstevel@tonic-gate 	pcol(cb.c_cc[VLNEXT], 0);
6687c478bd9Sstevel@tonic-gate 	pcol(cb.c_cc[VSUSP], cb.c_cc[VDSUSP]);
6697c478bd9Sstevel@tonic-gate 	pcol(cb.c_cc[VINTR], 0);
6707c478bd9Sstevel@tonic-gate 	pcol(cb.c_cc[VQUIT], 0);
6717c478bd9Sstevel@tonic-gate 	pcol(cb.c_cc[VSTOP], cb.c_cc[VSTART]);
6727c478bd9Sstevel@tonic-gate 	if (cb.c_lflag&ICANON)
6737c478bd9Sstevel@tonic-gate 		pcol(cb.c_cc[VEOF], cb.c_cc[VEOL]);
674de81e71eSTim Marsland 	(void) fprintf(output, "\n");
6757c478bd9Sstevel@tonic-gate 	if (cb.c_cc[VEOL2] != 0 || cb.c_cc[VSWTCH] != 0) {
676de81e71eSTim Marsland 		(void) fprintf(output, "\
6777c478bd9Sstevel@tonic-gate eol2  swtch\
6787c478bd9Sstevel@tonic-gate \n");
6797c478bd9Sstevel@tonic-gate 		pcol(cb.c_cc[VEOL2], 0);
6807c478bd9Sstevel@tonic-gate 		pcol(cb.c_cc[VSWTCH], 0);
681de81e71eSTim Marsland 		(void) fprintf(output, "\n");
6827c478bd9Sstevel@tonic-gate 	}
6837c478bd9Sstevel@tonic-gate }
6847c478bd9Sstevel@tonic-gate 
685cc6c5292Schin void
pcol(int ch1,int ch2)686cc6c5292Schin pcol(int ch1, int ch2)
6877c478bd9Sstevel@tonic-gate {
6887c478bd9Sstevel@tonic-gate 	int nout = 0;
6897c478bd9Sstevel@tonic-gate 
6907c478bd9Sstevel@tonic-gate 	ch1 &= 0377;
6917c478bd9Sstevel@tonic-gate 	ch2 &= 0377;
6927c478bd9Sstevel@tonic-gate 	if (ch1 == ch2)
6937c478bd9Sstevel@tonic-gate 		ch2 = 0;
6947c478bd9Sstevel@tonic-gate 	for (; ch1 != 0 || ch2 != 0; ch1 = ch2, ch2 = 0) {
6957c478bd9Sstevel@tonic-gate 		if (ch1 == 0)
6967c478bd9Sstevel@tonic-gate 			continue;
6977c478bd9Sstevel@tonic-gate 		if (ch1 & 0200 && !isprint(ch1)) {
698de81e71eSTim Marsland 			(void) fprintf(output, "M-");
6997c478bd9Sstevel@tonic-gate 			nout += 2;
7007c478bd9Sstevel@tonic-gate 			ch1 &= ~ 0200;
7017c478bd9Sstevel@tonic-gate 		}
7027c478bd9Sstevel@tonic-gate 		if (ch1 == 0177) {
703de81e71eSTim Marsland 			(void) fprintf(output, "^");
7047c478bd9Sstevel@tonic-gate 			nout++;
7057c478bd9Sstevel@tonic-gate 			ch1 = '?';
7067c478bd9Sstevel@tonic-gate 		} else if (ch1 < ' ') {
707de81e71eSTim Marsland 			(void) fprintf(output, "^");
7087c478bd9Sstevel@tonic-gate 			nout++;
7097c478bd9Sstevel@tonic-gate 			ch1 += '@';
7107c478bd9Sstevel@tonic-gate 		}
711de81e71eSTim Marsland 		(void) fprintf(output, "%c", ch1);
7127c478bd9Sstevel@tonic-gate 		nout++;
7137c478bd9Sstevel@tonic-gate 		if (ch2 != 0) {
714de81e71eSTim Marsland 			(void) fprintf(output, "/");
7157c478bd9Sstevel@tonic-gate 			nout++;
7167c478bd9Sstevel@tonic-gate 		}
7177c478bd9Sstevel@tonic-gate 	}
7187c478bd9Sstevel@tonic-gate 	while (nout < 7) {
719de81e71eSTim Marsland 		(void) fprintf(output, " ");
7207c478bd9Sstevel@tonic-gate 		nout++;
7217c478bd9Sstevel@tonic-gate 	}
7227c478bd9Sstevel@tonic-gate }
7237c478bd9Sstevel@tonic-gate 
724cc6c5292Schin void
pit(unsigned char what,char * itsname,char * sep)725cc6c5292Schin pit(unsigned char what, char *itsname, char *sep)
726cc6c5292Schin /* print function for prmodes() and pramodes() */
7277c478bd9Sstevel@tonic-gate {
7287c478bd9Sstevel@tonic-gate 
7297c478bd9Sstevel@tonic-gate 	pitt++;
730de81e71eSTim Marsland 	(void) fprintf(output, "%s", itsname);
731de81e71eSTim Marsland 	if ((term & TERMIOS) && what == _POSIX_VDISABLE ||
732de81e71eSTim Marsland 	    !(term & TERMIOS) && what == 0200) {
733de81e71eSTim Marsland 		(void) fprintf(output, " = <undef>%s", sep);
7347c478bd9Sstevel@tonic-gate 		return;
7357c478bd9Sstevel@tonic-gate 	}
736de81e71eSTim Marsland 	(void) fprintf(output, " = ");
7377c478bd9Sstevel@tonic-gate 	if (what & 0200 && !isprint(what)) {
738de81e71eSTim Marsland 		(void) fprintf(output, "-");
7397c478bd9Sstevel@tonic-gate 		what &= ~ 0200;
7407c478bd9Sstevel@tonic-gate 	}
7417c478bd9Sstevel@tonic-gate 	if (what == 0177) {
742de81e71eSTim Marsland 		(void) fprintf(output, "^?%s", sep);
7437c478bd9Sstevel@tonic-gate 		return;
7447c478bd9Sstevel@tonic-gate 	} else if (what < ' ') {
745de81e71eSTim Marsland 		(void) fprintf(output, "^");
7467c478bd9Sstevel@tonic-gate 		what += '`';
7477c478bd9Sstevel@tonic-gate 	}
748de81e71eSTim Marsland 	(void) fprintf(output, "%c%s", what, sep);
7497c478bd9Sstevel@tonic-gate }
7507c478bd9Sstevel@tonic-gate 
751cc6c5292Schin void
delay(int m,char * s)752cc6c5292Schin delay(int m, char *s)
7537c478bd9Sstevel@tonic-gate {
754de81e71eSTim Marsland 	if (m)
755de81e71eSTim Marsland 		(void) fprintf(output, "%s%d ", s, m);
7567c478bd9Sstevel@tonic-gate }
7577c478bd9Sstevel@tonic-gate 
758*d9c3e05cSJoshua M. Clulow long speed[] = {
759de81e71eSTim Marsland 	0, 50, 75, 110, 134, 150, 200, 300,
760de81e71eSTim Marsland 	600, 1200, 1800, 2400, 4800, 9600, 19200, 38400,
761*d9c3e05cSJoshua M. Clulow 	57600, 76800, 115200, 153600, 230400, 307200, 460800, 921600,
762*d9c3e05cSJoshua M. Clulow 	1000000, 1152000, 1500000, 2000000, 2500000, 3000000, 3500000,
763*d9c3e05cSJoshua M. Clulow 	4000000
7647c478bd9Sstevel@tonic-gate };
7657c478bd9Sstevel@tonic-gate 
766cc6c5292Schin void
prspeed(char * c,int s)767cc6c5292Schin prspeed(char *c, int s)
7687c478bd9Sstevel@tonic-gate {
769de81e71eSTim Marsland 	(void) fprintf(output, "%s%d baud; ", c, speed[s]);
7707c478bd9Sstevel@tonic-gate }
7717c478bd9Sstevel@tonic-gate 
772cc6c5292Schin /*
773cc6c5292Schin  * print current settings for use with
774cc6c5292Schin  * another stty cmd, used for -g option
775cc6c5292Schin  */
776cc6c5292Schin void
prencode(void)777cc6c5292Schin prencode(void)
7787c478bd9Sstevel@tonic-gate {
7797c478bd9Sstevel@tonic-gate 	int i, last;
7807c478bd9Sstevel@tonic-gate 
781cc6c5292Schin 	/* Since the -g option is mostly used for redirecting to a file */
7827c478bd9Sstevel@tonic-gate 	/* We must print to stdout here, not stderr */
7837c478bd9Sstevel@tonic-gate 
784de81e71eSTim Marsland 	(void) printf("%x:%x:%x:%x:", cb.c_iflag, cb.c_oflag,
785de81e71eSTim Marsland 	    cb.c_cflag, cb.c_lflag);
7867c478bd9Sstevel@tonic-gate 
787de81e71eSTim Marsland 	if (term & TERMIOS)
7887c478bd9Sstevel@tonic-gate 	/* last control slot is unused */
7897c478bd9Sstevel@tonic-gate 		last = NCCS - 2;
7907c478bd9Sstevel@tonic-gate 	else
7917c478bd9Sstevel@tonic-gate 		last = NCC - 1;
792de81e71eSTim Marsland 	for (i = 0; i < last; i++)
7937c478bd9Sstevel@tonic-gate 		(void) printf("%x:", cb.c_cc[i]);
7947c478bd9Sstevel@tonic-gate 	(void) printf("%x\n", cb.c_cc[last]);
7957c478bd9Sstevel@tonic-gate }
796