xref: /titanic_52/usr/src/cmd/ttymon/stty.c (revision 19d32b9ab53d17ac6605971e14c45a5281f8d9bb)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 1999-2002 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*19d32b9aSRobert Mustacchi  * Copyright (c) 2014, Joyent, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
307c478bd9Sstevel@tonic-gate  * All Rights Reserved
317c478bd9Sstevel@tonic-gate  *
327c478bd9Sstevel@tonic-gate  */
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <stdio.h>
357c478bd9Sstevel@tonic-gate #include <ctype.h>
367c478bd9Sstevel@tonic-gate #include <locale.h>
377c478bd9Sstevel@tonic-gate #include <sys/types.h>
387c478bd9Sstevel@tonic-gate #include <termio.h>
397c478bd9Sstevel@tonic-gate #include <sys/stermio.h>
407c478bd9Sstevel@tonic-gate #include <sys/termiox.h>
417c478bd9Sstevel@tonic-gate #include <string.h>
427c478bd9Sstevel@tonic-gate #include <stdlib.h>
437c478bd9Sstevel@tonic-gate #include <limits.h>
447c478bd9Sstevel@tonic-gate #ifdef EUC
457c478bd9Sstevel@tonic-gate #include <sys/stat.h>
467c478bd9Sstevel@tonic-gate #include <fcntl.h>
477c478bd9Sstevel@tonic-gate #include <unistd.h>
487c478bd9Sstevel@tonic-gate #include <sys/param.h>
497c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
507c478bd9Sstevel@tonic-gate #include <sys/eucioctl.h>
517c478bd9Sstevel@tonic-gate #include <sys/csiioctl.h>
527c478bd9Sstevel@tonic-gate #include <sys/stream.h>
537c478bd9Sstevel@tonic-gate #include <sys/termios.h>
547c478bd9Sstevel@tonic-gate #include <sys/ldterm.h>
557c478bd9Sstevel@tonic-gate #include <getwidth.h>
567c478bd9Sstevel@tonic-gate #endif /* EUC */
577c478bd9Sstevel@tonic-gate #include "stty.h"
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate extern const char *not_supported[];
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate extern char *getenv();
627c478bd9Sstevel@tonic-gate extern void exit();
637c478bd9Sstevel@tonic-gate extern void perror();
647c478bd9Sstevel@tonic-gate extern int get_ttymode();
657c478bd9Sstevel@tonic-gate extern int set_ttymode();
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate static char *STTY = "stty: ";
687c478bd9Sstevel@tonic-gate static int pitt = 0;
697c478bd9Sstevel@tonic-gate static struct termios cb;
707c478bd9Sstevel@tonic-gate static struct termio ocb; /* for non-streams devices */
717c478bd9Sstevel@tonic-gate static struct stio stio;
727c478bd9Sstevel@tonic-gate static struct termiox termiox;
737c478bd9Sstevel@tonic-gate static struct winsize winsize, owinsize;
747c478bd9Sstevel@tonic-gate static int term;
757c478bd9Sstevel@tonic-gate #ifdef EUC
767c478bd9Sstevel@tonic-gate static struct eucioc kwp;
777c478bd9Sstevel@tonic-gate static eucwidth_t wp;
787c478bd9Sstevel@tonic-gate static ldterm_cs_data_user_t cswp;	/* User side codeset width data */
797c478bd9Sstevel@tonic-gate static ldterm_cs_data_user_t kcswp;	/* Kernel side codeset width data */
807c478bd9Sstevel@tonic-gate static int invalid_ldterm_dat_file;
817c478bd9Sstevel@tonic-gate #endif /* EUC */
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate static void prmodes();
847c478bd9Sstevel@tonic-gate static void pramodes();
857c478bd9Sstevel@tonic-gate static void pit(unsigned char what, char *itsname, char *sep);
867c478bd9Sstevel@tonic-gate static void delay(int m, char *s);
877c478bd9Sstevel@tonic-gate static void prspeed(char *c, int s);
887c478bd9Sstevel@tonic-gate static void prencode();
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate int
917c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
927c478bd9Sstevel@tonic-gate {
937c478bd9Sstevel@tonic-gate 	int i;
947c478bd9Sstevel@tonic-gate 	int fd;
957c478bd9Sstevel@tonic-gate 	char *s_arg, *sttyparse();	/* s_arg: ptr to mode to be set */
967c478bd9Sstevel@tonic-gate #ifdef	EUC
977c478bd9Sstevel@tonic-gate 	char *lc;
987c478bd9Sstevel@tonic-gate 	char tmps[PATH_MAX];
997c478bd9Sstevel@tonic-gate #endif	/* EUC */
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
1027c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
1037c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"
1047c478bd9Sstevel@tonic-gate #endif
1057c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate #ifdef EUC
1087c478bd9Sstevel@tonic-gate 	lc = setlocale(LC_CTYPE, (const char *)NULL);
1097c478bd9Sstevel@tonic-gate 	if (lc) {
1107c478bd9Sstevel@tonic-gate 		sprintf(tmps, _LDTERM_DAT_PATH, lc);
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 		fd = open(tmps, O_RDONLY, 0);
1137c478bd9Sstevel@tonic-gate 		if (fd != -1) {
1147c478bd9Sstevel@tonic-gate 			if (read(fd, (void *)&cswp, sizeof (cswp)) <
1157c478bd9Sstevel@tonic-gate 			    sizeof (cswp)) {
1167c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
117*19d32b9aSRobert Mustacchi 				    "cannot read entire %s file\n"), tmps);
1187c478bd9Sstevel@tonic-gate 				exit(2);
1197c478bd9Sstevel@tonic-gate 			}
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 			(void) close(fd);
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 			/*
1247c478bd9Sstevel@tonic-gate 			 * If the ldterm.dat contains invalid data or
1257c478bd9Sstevel@tonic-gate 			 * the current locale name is too long, we clear
1267c478bd9Sstevel@tonic-gate 			 * the 'cswp' and flag the invalid ldterm.dat since
1277c478bd9Sstevel@tonic-gate 			 * we are not going to use the data.
1287c478bd9Sstevel@tonic-gate 			 */
1297c478bd9Sstevel@tonic-gate 			if (cswp.version > LDTERM_DATA_VERSION ||
1307c478bd9Sstevel@tonic-gate 			    cswp.codeset_type < LDTERM_CS_TYPE_MIN ||
1317c478bd9Sstevel@tonic-gate 			    cswp.codeset_type > LDTERM_CS_TYPE_MAX ||
1327c478bd9Sstevel@tonic-gate 			    strlen(lc) >= MAXNAMELEN ||
1337c478bd9Sstevel@tonic-gate 			    (cswp.codeset_type == LDTERM_CS_TYPE_EUC &&
1347c478bd9Sstevel@tonic-gate 			    cswp.csinfo_num > LDTERM_CS_TYPE_EUC_MAX_SUBCS) ||
1357c478bd9Sstevel@tonic-gate 			    (cswp.codeset_type == LDTERM_CS_TYPE_PCCS &&
1367c478bd9Sstevel@tonic-gate 			    (cswp.csinfo_num < LDTERM_CS_TYPE_PCCS_MIN_SUBCS ||
1377c478bd9Sstevel@tonic-gate 			    cswp.csinfo_num > LDTERM_CS_TYPE_PCCS_MAX_SUBCS))) {
1387c478bd9Sstevel@tonic-gate 				(void) memset((void *)&cswp, 0, sizeof (cswp));
1397c478bd9Sstevel@tonic-gate 				invalid_ldterm_dat_file = 1;
1407c478bd9Sstevel@tonic-gate 			} else {
1417c478bd9Sstevel@tonic-gate 				(void) strcpy(cswp.locale_name, lc);
1427c478bd9Sstevel@tonic-gate 			}
1437c478bd9Sstevel@tonic-gate 		}
1447c478bd9Sstevel@tonic-gate 	}
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	getwidth(&wp);
1477c478bd9Sstevel@tonic-gate #endif /* EUC */
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 	if ((term = get_ttymode(0, &ocb, &cb, &stio, &termiox, &winsize
1507c478bd9Sstevel@tonic-gate #ifdef EUC
1517c478bd9Sstevel@tonic-gate 	    /* */, &kwp, &kcswp
1527c478bd9Sstevel@tonic-gate #endif /* EUC */
1537c478bd9Sstevel@tonic-gate 	    /* */)) < 0) {
1547c478bd9Sstevel@tonic-gate 		perror(STTY);
1557c478bd9Sstevel@tonic-gate 		exit(2);
1567c478bd9Sstevel@tonic-gate 	}
1577c478bd9Sstevel@tonic-gate 	owinsize = winsize;
1587c478bd9Sstevel@tonic-gate 	if (argc == 1) {
1597c478bd9Sstevel@tonic-gate 		prmodes();
1607c478bd9Sstevel@tonic-gate 		exit(0);
1617c478bd9Sstevel@tonic-gate 	}
1627c478bd9Sstevel@tonic-gate 	if ((argc == 2) && (argv[1][0] == '-') && (argv[1][2] == '\0'))
1637c478bd9Sstevel@tonic-gate 	switch (argv[1][1]) {
1647c478bd9Sstevel@tonic-gate 		case 'a':
1657c478bd9Sstevel@tonic-gate 			pramodes();
1667c478bd9Sstevel@tonic-gate 			return (0);
1677c478bd9Sstevel@tonic-gate 		case 'g':
1687c478bd9Sstevel@tonic-gate 			prencode();
1697c478bd9Sstevel@tonic-gate 			return (0);
1707c478bd9Sstevel@tonic-gate 		case '-':
1717c478bd9Sstevel@tonic-gate 			prmodes(); /* stty -- */
1727c478bd9Sstevel@tonic-gate 			return (0);
1737c478bd9Sstevel@tonic-gate 		default:
1747c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
1757c478bd9Sstevel@tonic-gate 			    "usage: stty [-a| -g]\n"));
1767c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
1777c478bd9Sstevel@tonic-gate 			    "       stty [modes]\n"));
1787c478bd9Sstevel@tonic-gate 			return (2);
1797c478bd9Sstevel@tonic-gate 	}
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	if ((argc == 3) && (argv[1][0] == '-') && (argv[1][2] == '\0') &&
1827c478bd9Sstevel@tonic-gate 	    (argv[2][0] == '-') && (argv[2][1] == '-') && (argv[2][2] == '\0'))
1837c478bd9Sstevel@tonic-gate 	switch (argv[1][1]) {
1847c478bd9Sstevel@tonic-gate 	case 'a':
1857c478bd9Sstevel@tonic-gate 		pramodes();
1867c478bd9Sstevel@tonic-gate 		return (0);
1877c478bd9Sstevel@tonic-gate 	case 'g':
1887c478bd9Sstevel@tonic-gate 		prencode();
1897c478bd9Sstevel@tonic-gate 		return (0);
1907c478bd9Sstevel@tonic-gate 	default:
1917c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext(
1927c478bd9Sstevel@tonic-gate 		    "usage: stty [-a| -g]\n"));
1937c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext(
1947c478bd9Sstevel@tonic-gate 		    "       stty [modes]\n"));
1957c478bd9Sstevel@tonic-gate 		return (2);
1967c478bd9Sstevel@tonic-gate 	}
1977c478bd9Sstevel@tonic-gate 	if ((argc >= 3) && (argv[1][0] == '-') && (argv[1][1] == '-') &&
1987c478bd9Sstevel@tonic-gate 	    (argv[1][2] == '\0')) {
1997c478bd9Sstevel@tonic-gate 		/* ignore -- */
2007c478bd9Sstevel@tonic-gate 		--argc;
2017c478bd9Sstevel@tonic-gate 		++argv;
2027c478bd9Sstevel@tonic-gate 	}
2037c478bd9Sstevel@tonic-gate 	if (s_arg = sttyparse(argc, argv, term, &ocb, &cb, &termiox, &winsize
2047c478bd9Sstevel@tonic-gate #ifdef EUC
2057c478bd9Sstevel@tonic-gate 	    /* */, &wp, &kwp, &cswp, &kcswp
2067c478bd9Sstevel@tonic-gate #endif /* EUC */
2077c478bd9Sstevel@tonic-gate 	    /* */)) {
2087c478bd9Sstevel@tonic-gate 		char *s = s_arg;
2097c478bd9Sstevel@tonic-gate 		if (*s == '-') s++;
2107c478bd9Sstevel@tonic-gate 		for (i = 0; not_supported[i]; i++) {
2117c478bd9Sstevel@tonic-gate 			if (strcmp(not_supported[i], s) == 0) {
2127c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
2137c478bd9Sstevel@tonic-gate 				    gettext(
214*19d32b9aSRobert Mustacchi 				    "mode not supported on this device: %s\n"),
215*19d32b9aSRobert Mustacchi 				    s_arg);
2167c478bd9Sstevel@tonic-gate 				exit(2);
2177c478bd9Sstevel@tonic-gate 			}
2187c478bd9Sstevel@tonic-gate 		}
2197c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext("unknown mode: %s\n"), s_arg);
2207c478bd9Sstevel@tonic-gate 		return (2);
2217c478bd9Sstevel@tonic-gate 	}
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 	if (set_ttymode(0, term, &ocb, &cb, &stio, &termiox, &winsize, &owinsize
2247c478bd9Sstevel@tonic-gate #ifdef EUC
2257c478bd9Sstevel@tonic-gate 	    /* */, &kwp, &kcswp, invalid_ldterm_dat_file
2267c478bd9Sstevel@tonic-gate #endif /* EUC */
2277c478bd9Sstevel@tonic-gate 	    /* */) == -1) {
2287c478bd9Sstevel@tonic-gate 		perror(STTY);
2297c478bd9Sstevel@tonic-gate 		return (2);
2307c478bd9Sstevel@tonic-gate 	}
2317c478bd9Sstevel@tonic-gate 	return (0);
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate void
2357c478bd9Sstevel@tonic-gate prmodes(void)				/* print modes, no options, argc is 1 */
2367c478bd9Sstevel@tonic-gate {
2377c478bd9Sstevel@tonic-gate 	int m;
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	if (!(term & ASYNC)) {
2407c478bd9Sstevel@tonic-gate 		m = stio.imode;
2417c478bd9Sstevel@tonic-gate 		if (m & IUCLC)
2427c478bd9Sstevel@tonic-gate 			(void) printf("iuclc ");
2437c478bd9Sstevel@tonic-gate 		else
2447c478bd9Sstevel@tonic-gate 			(void) printf("-iuclc ");
2457c478bd9Sstevel@tonic-gate 		m = stio.omode;
2467c478bd9Sstevel@tonic-gate 		if (m & OLCUC)
2477c478bd9Sstevel@tonic-gate 			(void) printf("olcuc ");
2487c478bd9Sstevel@tonic-gate 		else
2497c478bd9Sstevel@tonic-gate 			(void) printf("-olcuc ");
2507c478bd9Sstevel@tonic-gate 		if (m & TAB3)
2517c478bd9Sstevel@tonic-gate 			(void) printf("tab3 ");
2527c478bd9Sstevel@tonic-gate 		m = stio.lmode;
2537c478bd9Sstevel@tonic-gate 		if (m & XCASE)
2547c478bd9Sstevel@tonic-gate 			(void) printf("xcase ");
2557c478bd9Sstevel@tonic-gate 		else
2567c478bd9Sstevel@tonic-gate 			(void) printf("-xcase ");
2577c478bd9Sstevel@tonic-gate 		if (m & STFLUSH)
2587c478bd9Sstevel@tonic-gate 			(void) printf("stflush ");
2597c478bd9Sstevel@tonic-gate 		else
2607c478bd9Sstevel@tonic-gate 			(void) printf("-stflush ");
2617c478bd9Sstevel@tonic-gate 		if (m & STWRAP)
2627c478bd9Sstevel@tonic-gate 			(void) printf("stwrap ");
2637c478bd9Sstevel@tonic-gate 		else
2647c478bd9Sstevel@tonic-gate 			(void) printf("-stwrap ");
2657c478bd9Sstevel@tonic-gate 		if (m & STAPPL)
2667c478bd9Sstevel@tonic-gate 			(void) printf("stappl ");
2677c478bd9Sstevel@tonic-gate 		else
2687c478bd9Sstevel@tonic-gate 			(void) printf("-stappl ");
2697c478bd9Sstevel@tonic-gate 		(void) printf("\n");
2707c478bd9Sstevel@tonic-gate 	}
2717c478bd9Sstevel@tonic-gate 	if (term & ASYNC) {
2727c478bd9Sstevel@tonic-gate 		m = cb.c_cflag;
2737c478bd9Sstevel@tonic-gate 		if ((term & TERMIOS) && cfgetispeed(&cb) != 0 &&
2747c478bd9Sstevel@tonic-gate 		    cfgetispeed(&cb) != cfgetospeed(&cb)) {
2757c478bd9Sstevel@tonic-gate 			prspeed("ispeed ", cfgetispeed(&cb));
2767c478bd9Sstevel@tonic-gate 			prspeed("ospeed ", cfgetospeed(&cb));
2777c478bd9Sstevel@tonic-gate 		} else
2787c478bd9Sstevel@tonic-gate 			prspeed("speed ", cfgetospeed(&cb));
2797c478bd9Sstevel@tonic-gate 		if (m&PARENB) {
2807c478bd9Sstevel@tonic-gate 			if ((m&PAREXT) && (term & TERMIOS)) {
2817c478bd9Sstevel@tonic-gate 				if (m&PARODD)
2827c478bd9Sstevel@tonic-gate 					(void) printf("markp ");
2837c478bd9Sstevel@tonic-gate 				else
2847c478bd9Sstevel@tonic-gate 					(void) printf("spacep ");
2857c478bd9Sstevel@tonic-gate 			} else {
2867c478bd9Sstevel@tonic-gate 				if (m&PARODD)
2877c478bd9Sstevel@tonic-gate 					(void) printf("oddp ");
2887c478bd9Sstevel@tonic-gate 				else
2897c478bd9Sstevel@tonic-gate 					(void) printf("evenp ");
2907c478bd9Sstevel@tonic-gate 			}
2917c478bd9Sstevel@tonic-gate 		} else
2927c478bd9Sstevel@tonic-gate 			(void) printf("-parity ");
2937c478bd9Sstevel@tonic-gate 		if (((m&PARENB) && !(m&CS7)) || (!(m&PARENB) && !(m&CS8)))
2947c478bd9Sstevel@tonic-gate 			(void) printf("cs%c ", '5'+(m&CSIZE)/CS6);
2957c478bd9Sstevel@tonic-gate 		if (m&CSTOPB)
2967c478bd9Sstevel@tonic-gate 			(void) printf("cstopb ");
2977c478bd9Sstevel@tonic-gate 		if (m&HUPCL)
2987c478bd9Sstevel@tonic-gate 			(void) printf("hupcl ");
2997c478bd9Sstevel@tonic-gate 		if (!(m&CREAD))
3007c478bd9Sstevel@tonic-gate 			(void) printf("-cread ");
3017c478bd9Sstevel@tonic-gate 		if (m&CLOCAL)
3027c478bd9Sstevel@tonic-gate 			(void) printf("clocal ");
3037c478bd9Sstevel@tonic-gate 		if (m&LOBLK)
3047c478bd9Sstevel@tonic-gate 			(void) printf("loblk ");
3057c478bd9Sstevel@tonic-gate 		(void) printf("\n");
3067c478bd9Sstevel@tonic-gate 		if (ocb.c_line != 0)
3077c478bd9Sstevel@tonic-gate 			(void) printf(gettext("line = %d; "), ocb.c_line);
3087c478bd9Sstevel@tonic-gate 		if (term & WINDOW) {
309*19d32b9aSRobert Mustacchi 			(void) printf(gettext("rows = %d; columns = %d;"),
310*19d32b9aSRobert Mustacchi 			    winsize.ws_row, winsize.ws_col);
3117c478bd9Sstevel@tonic-gate 			(void) printf(gettext(
3127c478bd9Sstevel@tonic-gate 			    " ypixels = %d; xpixels = %d;\n"),
3137c478bd9Sstevel@tonic-gate 			    winsize.ws_ypixel, winsize.ws_xpixel);
3147c478bd9Sstevel@tonic-gate 		}
3157c478bd9Sstevel@tonic-gate 		if ((cb.c_lflag&ICANON) == 0)
3167c478bd9Sstevel@tonic-gate 			(void) printf(gettext("min = %d; time = %d;\n"),
3177c478bd9Sstevel@tonic-gate 			    cb.c_cc[VMIN], cb.c_cc[VTIME]);
3187c478bd9Sstevel@tonic-gate 		if (cb.c_cc[VINTR] != CINTR)
3197c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VINTR], "intr", "; ");
3207c478bd9Sstevel@tonic-gate 		if (cb.c_cc[VQUIT] != CQUIT)
3217c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VQUIT], "quit", "; ");
3227c478bd9Sstevel@tonic-gate 		if (cb.c_cc[VERASE] != CERASE)
3237c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VERASE], "erase", "; ");
3247c478bd9Sstevel@tonic-gate 		if (cb.c_cc[VKILL] != CKILL)
3257c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VKILL], "kill", "; ");
3267c478bd9Sstevel@tonic-gate 		if (cb.c_cc[VEOF] != CEOF)
3277c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VEOF], "eof", "; ");
3287c478bd9Sstevel@tonic-gate 		if (cb.c_cc[VEOL] != CNUL)
3297c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VEOL], "eol", "; ");
3307c478bd9Sstevel@tonic-gate 		if (cb.c_cc[VEOL2] != CNUL)
3317c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VEOL2], "eol2", "; ");
3327c478bd9Sstevel@tonic-gate 		if (cb.c_cc[VSWTCH] != CSWTCH)
3337c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VSWTCH], "swtch", "; ");
3347c478bd9Sstevel@tonic-gate 		if (term & TERMIOS) {
3357c478bd9Sstevel@tonic-gate 			if (cb.c_cc[VSTART] != CSTART)
3367c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VSTART], "start", "; ");
3377c478bd9Sstevel@tonic-gate 			if (cb.c_cc[VSTOP] != CSTOP)
3387c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VSTOP], "stop", "; ");
3397c478bd9Sstevel@tonic-gate 			if (cb.c_cc[VSUSP] != CSUSP)
3407c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VSUSP], "susp", "; ");
3417c478bd9Sstevel@tonic-gate 			if (cb.c_cc[VDSUSP] != CDSUSP)
3427c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VDSUSP], "dsusp", "; ");
3437c478bd9Sstevel@tonic-gate 			if (cb.c_cc[VREPRINT] != CRPRNT)
3447c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VREPRINT], "rprnt", "; ");
3457c478bd9Sstevel@tonic-gate 			if (cb.c_cc[VDISCARD] != CFLUSH)
3467c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VDISCARD], "flush", "; ");
3477c478bd9Sstevel@tonic-gate 			if (cb.c_cc[VWERASE] != CWERASE)
3487c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VWERASE], "werase", "; ");
3497c478bd9Sstevel@tonic-gate 			if (cb.c_cc[VLNEXT] != CLNEXT)
3507c478bd9Sstevel@tonic-gate 				pit(cb.c_cc[VLNEXT], "lnext", "; ");
351*19d32b9aSRobert Mustacchi 			if (cb.c_cc[VSTATUS] != CSTATUS)
352*19d32b9aSRobert Mustacchi 				pit(cb.c_cc[VSTATUS], "status", "; ");
3537c478bd9Sstevel@tonic-gate 		}
3547c478bd9Sstevel@tonic-gate 		if (pitt) (void) printf("\n");
3557c478bd9Sstevel@tonic-gate 		m = cb.c_iflag;
3567c478bd9Sstevel@tonic-gate 		if (m&IGNBRK)
3577c478bd9Sstevel@tonic-gate 			(void) printf("ignbrk ");
3587c478bd9Sstevel@tonic-gate 		else if (m&BRKINT)
3597c478bd9Sstevel@tonic-gate 			(void) printf("brkint ");
3607c478bd9Sstevel@tonic-gate 		if (!(m&INPCK))
3617c478bd9Sstevel@tonic-gate 			(void) printf("-inpck ");
3627c478bd9Sstevel@tonic-gate 		else if (m&IGNPAR)
3637c478bd9Sstevel@tonic-gate 			(void) printf("ignpar ");
3647c478bd9Sstevel@tonic-gate 		if (m&PARMRK)
3657c478bd9Sstevel@tonic-gate 			(void) printf("parmrk ");
3667c478bd9Sstevel@tonic-gate 		if (!(m&ISTRIP))
3677c478bd9Sstevel@tonic-gate 			(void) printf("-istrip ");
3687c478bd9Sstevel@tonic-gate 		if (m&INLCR)
3697c478bd9Sstevel@tonic-gate 			(void) printf("inlcr ");
3707c478bd9Sstevel@tonic-gate 		if (m&IGNCR)
3717c478bd9Sstevel@tonic-gate 			(void) printf("igncr ");
3727c478bd9Sstevel@tonic-gate 		if (m&ICRNL)
3737c478bd9Sstevel@tonic-gate 			(void) printf("icrnl ");
3747c478bd9Sstevel@tonic-gate 		if (m&IUCLC)
3757c478bd9Sstevel@tonic-gate 			(void) printf("iuclc ");
3767c478bd9Sstevel@tonic-gate 		if (!(m&IXON))
3777c478bd9Sstevel@tonic-gate 			(void) printf("-ixon ");
3787c478bd9Sstevel@tonic-gate 		else if (!(m&IXANY))
3797c478bd9Sstevel@tonic-gate 			(void) printf("-ixany ");
3807c478bd9Sstevel@tonic-gate 		if (m&IXOFF)
3817c478bd9Sstevel@tonic-gate 			(void) printf("ixoff ");
3827c478bd9Sstevel@tonic-gate 		if ((term & TERMIOS) && (m&IMAXBEL))
3837c478bd9Sstevel@tonic-gate 			(void) printf("imaxbel ");
3847c478bd9Sstevel@tonic-gate 		m = cb.c_oflag;
3857c478bd9Sstevel@tonic-gate 		if (!(m&OPOST))
3867c478bd9Sstevel@tonic-gate 			(void) printf("-opost ");
3877c478bd9Sstevel@tonic-gate 		else {
3887c478bd9Sstevel@tonic-gate 			if (m&OLCUC)
3897c478bd9Sstevel@tonic-gate 				(void) printf("olcuc ");
3907c478bd9Sstevel@tonic-gate 			if (m&ONLCR)
3917c478bd9Sstevel@tonic-gate 				(void) printf("onlcr ");
3927c478bd9Sstevel@tonic-gate 			if (m&OCRNL)
3937c478bd9Sstevel@tonic-gate 				(void) printf("ocrnl ");
3947c478bd9Sstevel@tonic-gate 			if (m&ONOCR)
3957c478bd9Sstevel@tonic-gate 				(void) printf("onocr ");
3967c478bd9Sstevel@tonic-gate 			if (m&ONLRET)
3977c478bd9Sstevel@tonic-gate 				(void) printf("onlret ");
3987c478bd9Sstevel@tonic-gate 			if (m&OFILL)
3997c478bd9Sstevel@tonic-gate 				if (m&OFDEL)
4007c478bd9Sstevel@tonic-gate 					(void) printf("del-fill ");
4017c478bd9Sstevel@tonic-gate 				else
4027c478bd9Sstevel@tonic-gate 					(void) printf("nul-fill ");
4037c478bd9Sstevel@tonic-gate 			delay((m&CRDLY)/CR1, "cr");
4047c478bd9Sstevel@tonic-gate 			delay((m&NLDLY)/NL1, "nl");
4057c478bd9Sstevel@tonic-gate 			delay((m&TABDLY)/TAB1, "tab");
4067c478bd9Sstevel@tonic-gate 			delay((m&BSDLY)/BS1, "bs");
4077c478bd9Sstevel@tonic-gate 			delay((m&VTDLY)/VT1, "vt");
4087c478bd9Sstevel@tonic-gate 			delay((m&FFDLY)/FF1, "ff");
4097c478bd9Sstevel@tonic-gate 		}
4107c478bd9Sstevel@tonic-gate 		(void) printf("\n");
4117c478bd9Sstevel@tonic-gate 		m = cb.c_lflag;
4127c478bd9Sstevel@tonic-gate 		if (!(m&ISIG))
4137c478bd9Sstevel@tonic-gate 			(void) printf("-isig ");
4147c478bd9Sstevel@tonic-gate 		if (!(m&ICANON))
4157c478bd9Sstevel@tonic-gate 			(void) printf("-icanon ");
4167c478bd9Sstevel@tonic-gate 		if (m&XCASE)
4177c478bd9Sstevel@tonic-gate 			(void) printf("xcase ");
4187c478bd9Sstevel@tonic-gate 		(void) printf("-echo "+((m&ECHO) != 0));
4197c478bd9Sstevel@tonic-gate 		(void) printf("-echoe "+((m&ECHOE) != 0));
4207c478bd9Sstevel@tonic-gate 		(void) printf("-echok "+((m&ECHOK) != 0));
4217c478bd9Sstevel@tonic-gate 		if (m&ECHONL)
4227c478bd9Sstevel@tonic-gate 			(void) printf("echonl ");
4237c478bd9Sstevel@tonic-gate 		if (m&NOFLSH)
4247c478bd9Sstevel@tonic-gate 			(void) printf("noflsh ");
4257c478bd9Sstevel@tonic-gate 		if (m&TOSTOP)
4267c478bd9Sstevel@tonic-gate 			(void) printf("tostop ");
4277c478bd9Sstevel@tonic-gate 		if (m&ECHOCTL)
4287c478bd9Sstevel@tonic-gate 			(void) printf("echoctl ");
4297c478bd9Sstevel@tonic-gate 		if (m&ECHOPRT)
4307c478bd9Sstevel@tonic-gate 			(void) printf("echoprt ");
4317c478bd9Sstevel@tonic-gate 		if (m&ECHOKE)
4327c478bd9Sstevel@tonic-gate 			(void) printf("echoke ");
4337c478bd9Sstevel@tonic-gate 		if (m&DEFECHO)
4347c478bd9Sstevel@tonic-gate 			(void) printf("defecho ");
4357c478bd9Sstevel@tonic-gate 		if (m&FLUSHO)
4367c478bd9Sstevel@tonic-gate 			(void) printf("flusho ");
4377c478bd9Sstevel@tonic-gate 		if (m&PENDIN)
4387c478bd9Sstevel@tonic-gate 			(void) printf("pendin ");
4397c478bd9Sstevel@tonic-gate 		if (m&IEXTEN)
4407c478bd9Sstevel@tonic-gate 			(void) printf("iexten ");
4417c478bd9Sstevel@tonic-gate 		(void) printf("\n");
4427c478bd9Sstevel@tonic-gate 	}
4437c478bd9Sstevel@tonic-gate 	if (term & FLOW) {
4447c478bd9Sstevel@tonic-gate 		m = termiox.x_hflag;
4457c478bd9Sstevel@tonic-gate 		if (m & RTSXOFF)
4467c478bd9Sstevel@tonic-gate 			(void) printf("rtsxoff ");
4477c478bd9Sstevel@tonic-gate 		if (m & CTSXON)
4487c478bd9Sstevel@tonic-gate 			(void) printf("ctsxon ");
4497c478bd9Sstevel@tonic-gate 		if (m & DTRXOFF)
4507c478bd9Sstevel@tonic-gate 			(void) printf("dtrxoff ");
4517c478bd9Sstevel@tonic-gate 		if (m & CDXON)
4527c478bd9Sstevel@tonic-gate 			(void) printf("cdxon ");
4537c478bd9Sstevel@tonic-gate 		if (m & ISXOFF)
4547c478bd9Sstevel@tonic-gate 			(void) printf("isxoff ");
4557c478bd9Sstevel@tonic-gate 		m = termiox.x_cflag;
4567c478bd9Sstevel@tonic-gate 		switch (m & XMTCLK) {
4577c478bd9Sstevel@tonic-gate 			case XCIBRG: (void)printf("xcibrg ");
4587c478bd9Sstevel@tonic-gate 					break;
4597c478bd9Sstevel@tonic-gate 			case XCTSET: (void)printf("xctset ");
4607c478bd9Sstevel@tonic-gate 					break;
4617c478bd9Sstevel@tonic-gate 			case XCRSET: (void)printf("xcrset ");
4627c478bd9Sstevel@tonic-gate 		}
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate 		switch (m & RCVCLK) {
4657c478bd9Sstevel@tonic-gate 			case RCIBRG: (void)printf("rcibrg ");
4667c478bd9Sstevel@tonic-gate 					break;
4677c478bd9Sstevel@tonic-gate 			case RCTSET: (void)printf("rctset ");
4687c478bd9Sstevel@tonic-gate 					break;
4697c478bd9Sstevel@tonic-gate 			case RCRSET: (void)printf("rcrset ");
4707c478bd9Sstevel@tonic-gate 		}
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 		switch (m & TSETCLK) {
4737c478bd9Sstevel@tonic-gate 			case TSETCOFF: (void)printf("tsetcoff ");
4747c478bd9Sstevel@tonic-gate 					break;
4757c478bd9Sstevel@tonic-gate 			case TSETCRBRG: (void)printf("tsetcrbrg ");
4767c478bd9Sstevel@tonic-gate 					break;
4777c478bd9Sstevel@tonic-gate 			case TSETCTBRG: (void)printf("tsetctbrg ");
4787c478bd9Sstevel@tonic-gate 					break;
4797c478bd9Sstevel@tonic-gate 			case TSETCTSET: (void)printf("tsetctset ");
4807c478bd9Sstevel@tonic-gate 					break;
4817c478bd9Sstevel@tonic-gate 			case TSETCRSET: (void)printf("tsetcrset ");
4827c478bd9Sstevel@tonic-gate 		}
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate 		switch (m & RSETCLK) {
4857c478bd9Sstevel@tonic-gate 			case RSETCOFF: (void)printf("rsetcoff ");
4867c478bd9Sstevel@tonic-gate 					break;
4877c478bd9Sstevel@tonic-gate 			case RSETCRBRG: (void)printf("rsetcrbrg ");
4887c478bd9Sstevel@tonic-gate 					break;
4897c478bd9Sstevel@tonic-gate 			case RSETCTBRG: (void)printf("rsetctbrg ");
4907c478bd9Sstevel@tonic-gate 					break;
4917c478bd9Sstevel@tonic-gate 			case RSETCTSET: (void)printf("rsetctset ");
4927c478bd9Sstevel@tonic-gate 					break;
4937c478bd9Sstevel@tonic-gate 			case RSETCRSET: (void)printf("rsetcrset ");
4947c478bd9Sstevel@tonic-gate 		}
4957c478bd9Sstevel@tonic-gate 		(void) printf("\n");
4967c478bd9Sstevel@tonic-gate 	}
4977c478bd9Sstevel@tonic-gate }
4987c478bd9Sstevel@tonic-gate 
4997c478bd9Sstevel@tonic-gate void
5007c478bd9Sstevel@tonic-gate pramodes(void)				/* print all modes, -a option */
5017c478bd9Sstevel@tonic-gate {
5027c478bd9Sstevel@tonic-gate 	int m;
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate 	m = cb.c_cflag;
5057c478bd9Sstevel@tonic-gate 	if (term & ASYNC) {
5067c478bd9Sstevel@tonic-gate 		if ((term & TERMIOS) && cfgetispeed(&cb) != 0 &&
5077c478bd9Sstevel@tonic-gate 		    cfgetispeed(&cb) != cfgetospeed(&cb)) {
5087c478bd9Sstevel@tonic-gate 			prspeed("ispeed ", cfgetispeed(&cb));
5097c478bd9Sstevel@tonic-gate 			prspeed("ospeed ", cfgetospeed(&cb));
5107c478bd9Sstevel@tonic-gate 		} else
5117c478bd9Sstevel@tonic-gate 			prspeed("speed ", cfgetospeed(&cb));
5127c478bd9Sstevel@tonic-gate 		if (!(term & TERMIOS))
5137c478bd9Sstevel@tonic-gate 			(void) printf(gettext("line = %d; "), ocb.c_line);
5147c478bd9Sstevel@tonic-gate 		(void) printf("\n");
5157c478bd9Sstevel@tonic-gate 		if (term & WINDOW) {
5167c478bd9Sstevel@tonic-gate 			(void) printf(gettext("rows = %d; columns = %d;"),
5177c478bd9Sstevel@tonic-gate 			    winsize.ws_row, winsize.ws_col);
5187c478bd9Sstevel@tonic-gate 			(void) printf(gettext(
5197c478bd9Sstevel@tonic-gate 			    " ypixels = %d; xpixels = %d;\n"),
5207c478bd9Sstevel@tonic-gate 			    winsize.ws_ypixel, winsize.ws_xpixel);
5217c478bd9Sstevel@tonic-gate 		}
5227c478bd9Sstevel@tonic-gate #ifdef EUC
5237c478bd9Sstevel@tonic-gate 		if ((term & CSIW) && kcswp.locale_name[0]) {
5247c478bd9Sstevel@tonic-gate 			(void) printf("csdata %s\n", kcswp.locale_name);
5257c478bd9Sstevel@tonic-gate 		} else {
5267c478bd9Sstevel@tonic-gate 			(void) printf("csdata ?\n");
5277c478bd9Sstevel@tonic-gate 		}
5287c478bd9Sstevel@tonic-gate 		/*
5297c478bd9Sstevel@tonic-gate 		 * If kwp.eucw[0] is zero, it means the current codeset type
5307c478bd9Sstevel@tonic-gate 		 * in the ldterm is not EUC.
5317c478bd9Sstevel@tonic-gate 		 */
5327c478bd9Sstevel@tonic-gate 		if ((term & EUCW) && kwp.eucw[0]) {
5337c478bd9Sstevel@tonic-gate 			(void) printf("eucw %d:%d:%d:%d, ", kwp.eucw[0],
5347c478bd9Sstevel@tonic-gate 			    kwp.eucw[1], kwp.eucw[2], kwp.eucw[3]);
5357c478bd9Sstevel@tonic-gate 			(void) printf("scrw %d:%d:%d:%d\n", kwp.scrw[0],
5367c478bd9Sstevel@tonic-gate 			    kwp.scrw[1], kwp.scrw[2], kwp.scrw[3]);
5377c478bd9Sstevel@tonic-gate 		} else
5387c478bd9Sstevel@tonic-gate 			(void) printf("eucw ?, scrw ?\n");
5397c478bd9Sstevel@tonic-gate #endif /* EUC */
5407c478bd9Sstevel@tonic-gate 		if ((cb.c_lflag&ICANON) == 0)
5417c478bd9Sstevel@tonic-gate 			(void) printf(gettext("min = %d; time = %d;\n"),
5427c478bd9Sstevel@tonic-gate 			    cb.c_cc[VMIN], cb.c_cc[VTIME]);
5437c478bd9Sstevel@tonic-gate 		pit(cb.c_cc[VINTR], "intr", "; ");
5447c478bd9Sstevel@tonic-gate 		pit(cb.c_cc[VQUIT], "quit", "; ");
5457c478bd9Sstevel@tonic-gate 		pit(cb.c_cc[VERASE], "erase", "; ");
5467c478bd9Sstevel@tonic-gate 		pit(cb.c_cc[VKILL], "kill", ";\n");
5477c478bd9Sstevel@tonic-gate 		pit(cb.c_cc[VEOF], "eof", "; ");
5487c478bd9Sstevel@tonic-gate 		pit(cb.c_cc[VEOL], "eol", "; ");
5497c478bd9Sstevel@tonic-gate 		pit(cb.c_cc[VEOL2], "eol2", "; ");
5507c478bd9Sstevel@tonic-gate 		pit(cb.c_cc[VSWTCH], "swtch", ";\n");
5517c478bd9Sstevel@tonic-gate 		if (term & TERMIOS) {
5527c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VSTART], "start", "; ");
5537c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VSTOP], "stop", "; ");
5547c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VSUSP], "susp", "; ");
5557c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VDSUSP], "dsusp", ";\n");
5567c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VREPRINT], "rprnt", "; ");
5577c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VDISCARD], "flush", "; ");
5587c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VWERASE], "werase", "; ");
5597c478bd9Sstevel@tonic-gate 			pit(cb.c_cc[VLNEXT], "lnext", ";\n");
560*19d32b9aSRobert Mustacchi 			pit(cb.c_cc[VSTATUS], "status", ";\n");
5617c478bd9Sstevel@tonic-gate 		}
5627c478bd9Sstevel@tonic-gate 	} else
5637c478bd9Sstevel@tonic-gate 		pit((unsigned)stio.tab, "ctab", "\n");
5647c478bd9Sstevel@tonic-gate 	m = cb.c_cflag;
5657c478bd9Sstevel@tonic-gate 	(void) printf("-parenb "+((m&PARENB) != 0));
5667c478bd9Sstevel@tonic-gate 	(void) printf("-parodd "+((m&PARODD) != 0));
5677c478bd9Sstevel@tonic-gate 	(void) printf("cs%c ", '5'+(m&CSIZE)/CS6);
5687c478bd9Sstevel@tonic-gate 	(void) printf("-cstopb "+((m&CSTOPB) != 0));
5697c478bd9Sstevel@tonic-gate 	(void) printf("-hupcl "+((m&HUPCL) != 0));
5707c478bd9Sstevel@tonic-gate 	(void) printf("-cread "+((m&CREAD) != 0));
5717c478bd9Sstevel@tonic-gate 	(void) printf("-clocal "+((m&CLOCAL) != 0));
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate 	(void) printf("-loblk "+((m&LOBLK) != 0));
5747c478bd9Sstevel@tonic-gate 	(void) printf("-crtscts "+((m&CRTSCTS) != 0));
5757c478bd9Sstevel@tonic-gate 	(void) printf("-crtsxoff "+((m&CRTSXOFF) != 0));
5767c478bd9Sstevel@tonic-gate 	if (term & TERMIOS)
5777c478bd9Sstevel@tonic-gate 		(void) printf("-parext "+((m&PAREXT) != 0));
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate 	(void) printf("\n");
5807c478bd9Sstevel@tonic-gate 	m = cb.c_iflag;
5817c478bd9Sstevel@tonic-gate 	(void) printf("-ignbrk "+((m&IGNBRK) != 0));
5827c478bd9Sstevel@tonic-gate 	(void) printf("-brkint "+((m&BRKINT) != 0));
5837c478bd9Sstevel@tonic-gate 	(void) printf("-ignpar "+((m&IGNPAR) != 0));
5847c478bd9Sstevel@tonic-gate 	(void) printf("-parmrk "+((m&PARMRK) != 0));
5857c478bd9Sstevel@tonic-gate 	(void) printf("-inpck "+((m&INPCK) != 0));
5867c478bd9Sstevel@tonic-gate 	(void) printf("-istrip "+((m&ISTRIP) != 0));
5877c478bd9Sstevel@tonic-gate 	(void) printf("-inlcr "+((m&INLCR) != 0));
5887c478bd9Sstevel@tonic-gate 	(void) printf("-igncr "+((m&IGNCR) != 0));
5897c478bd9Sstevel@tonic-gate 	(void) printf("-icrnl "+((m&ICRNL) != 0));
5907c478bd9Sstevel@tonic-gate 	(void) printf("-iuclc "+((m&IUCLC) != 0));
5917c478bd9Sstevel@tonic-gate 	(void) printf("\n");
5927c478bd9Sstevel@tonic-gate 	(void) printf("-ixon "+((m&IXON) != 0));
5937c478bd9Sstevel@tonic-gate 	(void) printf("-ixany "+((m&IXANY) != 0));
5947c478bd9Sstevel@tonic-gate 	(void) printf("-ixoff "+((m&IXOFF) != 0));
5957c478bd9Sstevel@tonic-gate 	if (term & TERMIOS)
5967c478bd9Sstevel@tonic-gate 		(void) printf("-imaxbel "+((m&IMAXBEL) != 0));
5977c478bd9Sstevel@tonic-gate 	(void) printf("\n");
5987c478bd9Sstevel@tonic-gate 	m = cb.c_lflag;
5997c478bd9Sstevel@tonic-gate 	(void) printf("-isig "+((m&ISIG) != 0));
6007c478bd9Sstevel@tonic-gate 	(void) printf("-icanon "+((m&ICANON) != 0));
6017c478bd9Sstevel@tonic-gate 	(void) printf("-xcase "+((m&XCASE) != 0));
6027c478bd9Sstevel@tonic-gate 	(void) printf("-echo "+((m&ECHO) != 0));
6037c478bd9Sstevel@tonic-gate 	(void) printf("-echoe "+((m&ECHOE) != 0));
6047c478bd9Sstevel@tonic-gate 	(void) printf("-echok "+((m&ECHOK) != 0));
6057c478bd9Sstevel@tonic-gate 	(void) printf("-echonl "+((m&ECHONL) != 0));
6067c478bd9Sstevel@tonic-gate 	(void) printf("-noflsh "+((m&NOFLSH) != 0));
6077c478bd9Sstevel@tonic-gate 	if (term & TERMIOS) {
6087c478bd9Sstevel@tonic-gate 		(void) printf("\n");
6097c478bd9Sstevel@tonic-gate 		(void) printf("-tostop "+((m&TOSTOP) != 0));
6107c478bd9Sstevel@tonic-gate 		(void) printf("-echoctl "+((m&ECHOCTL) != 0));
6117c478bd9Sstevel@tonic-gate 		(void) printf("-echoprt "+((m&ECHOPRT) != 0));
6127c478bd9Sstevel@tonic-gate 		(void) printf("-echoke "+((m&ECHOKE) != 0));
6137c478bd9Sstevel@tonic-gate 		(void) printf("-defecho "+((m&DEFECHO) != 0));
6147c478bd9Sstevel@tonic-gate 		(void) printf("-flusho "+((m&FLUSHO) != 0));
6157c478bd9Sstevel@tonic-gate 		(void) printf("-pendin "+((m&PENDIN) != 0));
6167c478bd9Sstevel@tonic-gate 		(void) printf("-iexten "+((m&IEXTEN) != 0));
6177c478bd9Sstevel@tonic-gate 	}
6187c478bd9Sstevel@tonic-gate 	if (!(term & ASYNC)) {
6197c478bd9Sstevel@tonic-gate 		(void) printf("-stflush "+((m&STFLUSH) != 0));
6207c478bd9Sstevel@tonic-gate 		(void) printf("-stwrap "+((m&STWRAP) != 0));
6217c478bd9Sstevel@tonic-gate 		(void) printf("-stappl "+((m&STAPPL) != 0));
6227c478bd9Sstevel@tonic-gate 	}
6237c478bd9Sstevel@tonic-gate 	(void) printf("\n");
6247c478bd9Sstevel@tonic-gate 	m = cb.c_oflag;
6257c478bd9Sstevel@tonic-gate 	(void) printf("-opost "+((m&OPOST) != 0));
6267c478bd9Sstevel@tonic-gate 	(void) printf("-olcuc "+((m&OLCUC) != 0));
6277c478bd9Sstevel@tonic-gate 	(void) printf("-onlcr "+((m&ONLCR) != 0));
6287c478bd9Sstevel@tonic-gate 	(void) printf("-ocrnl "+((m&OCRNL) != 0));
6297c478bd9Sstevel@tonic-gate 	(void) printf("-onocr "+((m&ONOCR) != 0));
6307c478bd9Sstevel@tonic-gate 	(void) printf("-onlret "+((m&ONLRET) != 0));
6317c478bd9Sstevel@tonic-gate 	(void) printf("-ofill "+((m&OFILL) != 0));
6327c478bd9Sstevel@tonic-gate 	(void) printf("-ofdel "+((m&OFDEL) != 0));
6337c478bd9Sstevel@tonic-gate 	delay((m&CRDLY)/CR1, "cr");
6347c478bd9Sstevel@tonic-gate 	delay((m&NLDLY)/NL1, "nl");
6357c478bd9Sstevel@tonic-gate 	delay((m&TABDLY)/TAB1, "tab");
6367c478bd9Sstevel@tonic-gate 	delay((m&BSDLY)/BS1, "bs");
6377c478bd9Sstevel@tonic-gate 	delay((m&VTDLY)/VT1, "vt");
6387c478bd9Sstevel@tonic-gate 	delay((m&FFDLY)/FF1, "ff");
6397c478bd9Sstevel@tonic-gate 	(void) printf("\n");
6407c478bd9Sstevel@tonic-gate 	if (term & FLOW) {
6417c478bd9Sstevel@tonic-gate 		m = termiox.x_hflag;
6427c478bd9Sstevel@tonic-gate 		(void) printf("-rtsxoff "+((m&RTSXOFF) != 0));
6437c478bd9Sstevel@tonic-gate 		(void) printf("-ctsxon "+((m&CTSXON) != 0));
6447c478bd9Sstevel@tonic-gate 		(void) printf("-dtrxoff "+((m&DTRXOFF) != 0));
6457c478bd9Sstevel@tonic-gate 		(void) printf("-cdxon "+((m&CDXON) != 0));
6467c478bd9Sstevel@tonic-gate 		(void) printf("-isxoff "+((m&ISXOFF) != 0));
6477c478bd9Sstevel@tonic-gate 		m = termiox.x_cflag;
6487c478bd9Sstevel@tonic-gate 		switch (m & XMTCLK) {
6497c478bd9Sstevel@tonic-gate 			case XCIBRG: (void)printf("xcibrg ");
6507c478bd9Sstevel@tonic-gate 					break;
6517c478bd9Sstevel@tonic-gate 			case XCTSET: (void)printf("xctset ");
6527c478bd9Sstevel@tonic-gate 					break;
6537c478bd9Sstevel@tonic-gate 			case XCRSET: (void)printf("xcrset ");
6547c478bd9Sstevel@tonic-gate 		}
6557c478bd9Sstevel@tonic-gate 
6567c478bd9Sstevel@tonic-gate 		switch (m & RCVCLK) {
6577c478bd9Sstevel@tonic-gate 			case RCIBRG: (void)printf("rcibrg ");
6587c478bd9Sstevel@tonic-gate 					break;
6597c478bd9Sstevel@tonic-gate 			case RCTSET: (void)printf("rctset ");
6607c478bd9Sstevel@tonic-gate 					break;
6617c478bd9Sstevel@tonic-gate 			case RCRSET: (void)printf("rcrset ");
6627c478bd9Sstevel@tonic-gate 		}
6637c478bd9Sstevel@tonic-gate 
6647c478bd9Sstevel@tonic-gate 		switch (m & TSETCLK) {
6657c478bd9Sstevel@tonic-gate 			case TSETCOFF: (void)printf("tsetcoff ");
6667c478bd9Sstevel@tonic-gate 					break;
6677c478bd9Sstevel@tonic-gate 			case TSETCRBRG: (void)printf("tsetcrbrg ");
6687c478bd9Sstevel@tonic-gate 					break;
6697c478bd9Sstevel@tonic-gate 			case TSETCTBRG: (void)printf("tsetctbrg ");
6707c478bd9Sstevel@tonic-gate 					break;
6717c478bd9Sstevel@tonic-gate 			case TSETCTSET: (void)printf("tsetctset ");
6727c478bd9Sstevel@tonic-gate 					break;
6737c478bd9Sstevel@tonic-gate 			case TSETCRSET: (void)printf("tsetcrset ");
6747c478bd9Sstevel@tonic-gate 		}
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate 		switch (m & RSETCLK) {
6777c478bd9Sstevel@tonic-gate 			case RSETCOFF: (void)printf("rsetcoff ");
6787c478bd9Sstevel@tonic-gate 					break;
6797c478bd9Sstevel@tonic-gate 			case RSETCRBRG: (void)printf("rsetcrbrg ");
6807c478bd9Sstevel@tonic-gate 					break;
6817c478bd9Sstevel@tonic-gate 			case RSETCTBRG: (void)printf("rsetctbrg ");
6827c478bd9Sstevel@tonic-gate 					break;
6837c478bd9Sstevel@tonic-gate 			case RSETCTSET: (void)printf("rsetctset ");
6847c478bd9Sstevel@tonic-gate 					break;
6857c478bd9Sstevel@tonic-gate 			case RSETCRSET: (void)printf("rsetcrset ");
6867c478bd9Sstevel@tonic-gate 		}
6877c478bd9Sstevel@tonic-gate 		(void) printf("\n");
6887c478bd9Sstevel@tonic-gate 	}
6897c478bd9Sstevel@tonic-gate }
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate /* print function for prmodes() and pramodes() */
6927c478bd9Sstevel@tonic-gate void
6937c478bd9Sstevel@tonic-gate pit(unsigned char what, char *itsname, char *sep)
6947c478bd9Sstevel@tonic-gate {
6957c478bd9Sstevel@tonic-gate 
6967c478bd9Sstevel@tonic-gate 	pitt++;
6977c478bd9Sstevel@tonic-gate 	(void) printf("%s", itsname);
6987c478bd9Sstevel@tonic-gate 	if ((term & TERMIOS) && what == _POSIX_VDISABLE ||
6997c478bd9Sstevel@tonic-gate 	    !(term & TERMIOS) && what == 0200) {
7007c478bd9Sstevel@tonic-gate 		(void) printf(" = <undef>%s", sep);
7017c478bd9Sstevel@tonic-gate 		return;
7027c478bd9Sstevel@tonic-gate 	}
7037c478bd9Sstevel@tonic-gate 	(void) printf(" = ");
7047c478bd9Sstevel@tonic-gate 	if (what & 0200 && !isprint(what)) {
7057c478bd9Sstevel@tonic-gate 		(void) printf("-");
7067c478bd9Sstevel@tonic-gate 		what &= ~ 0200;
7077c478bd9Sstevel@tonic-gate 	}
7087c478bd9Sstevel@tonic-gate 	if (what == 0177) {
7097c478bd9Sstevel@tonic-gate 		(void) printf("^?%s", sep);
7107c478bd9Sstevel@tonic-gate 		return;
7117c478bd9Sstevel@tonic-gate 	} else if (what < ' ') {
7127c478bd9Sstevel@tonic-gate 		(void) printf("^");
7137c478bd9Sstevel@tonic-gate 		what += '`';
7147c478bd9Sstevel@tonic-gate 		if (what > 'z')
7157c478bd9Sstevel@tonic-gate 			what -= 'a' -'A';
7167c478bd9Sstevel@tonic-gate 	}
7177c478bd9Sstevel@tonic-gate 	(void) printf("%c%s", what, sep);
7187c478bd9Sstevel@tonic-gate }
7197c478bd9Sstevel@tonic-gate 
7207c478bd9Sstevel@tonic-gate void
7217c478bd9Sstevel@tonic-gate delay(int m, char *s)
7227c478bd9Sstevel@tonic-gate {
7237c478bd9Sstevel@tonic-gate 	if (m)
7247c478bd9Sstevel@tonic-gate 		(void) printf("%s%d ", s, m);
7257c478bd9Sstevel@tonic-gate }
7267c478bd9Sstevel@tonic-gate 
7277c478bd9Sstevel@tonic-gate void
7287c478bd9Sstevel@tonic-gate prspeed(char *c, int scode)
7297c478bd9Sstevel@tonic-gate {
7307c478bd9Sstevel@tonic-gate 	int sval = -1;
7317c478bd9Sstevel@tonic-gate 	int i;
7327c478bd9Sstevel@tonic-gate 
7337c478bd9Sstevel@tonic-gate 	for (i = 0; speeds[i].string; i++) {
7347c478bd9Sstevel@tonic-gate 		if (speeds[i].code == scode) {
7357c478bd9Sstevel@tonic-gate 			sval = speeds[i].value;
7367c478bd9Sstevel@tonic-gate 			break;
7377c478bd9Sstevel@tonic-gate 		}
7387c478bd9Sstevel@tonic-gate 	}
7397c478bd9Sstevel@tonic-gate 
7407c478bd9Sstevel@tonic-gate 	(void) printf("%s%d baud; ", c, sval);
7417c478bd9Sstevel@tonic-gate }
7427c478bd9Sstevel@tonic-gate 
7437c478bd9Sstevel@tonic-gate /* print current settings for use with  */
7447c478bd9Sstevel@tonic-gate void
7457c478bd9Sstevel@tonic-gate prencode(void)		/* another stty cmd, used for -g option */
7467c478bd9Sstevel@tonic-gate {
7477c478bd9Sstevel@tonic-gate 	int i, last;
7487c478bd9Sstevel@tonic-gate 
7497c478bd9Sstevel@tonic-gate 	/*
7507c478bd9Sstevel@tonic-gate 	 * Although there are only 16 control chars defined as of April 1995,
7517c478bd9Sstevel@tonic-gate 	 * prencode() and encode() will not have to be changed if up to MAX_CC
7527c478bd9Sstevel@tonic-gate 	 * control chars are defined in the future.  A maximum of MAX_CC rather
7537c478bd9Sstevel@tonic-gate 	 * than NCCS control chars are printed because the last control slot
7547c478bd9Sstevel@tonic-gate 	 * is unused.  "stty -g" prints out a total of NUM_FIELDS fields
7557c478bd9Sstevel@tonic-gate 	 * (NUM_MODES modes + MAX_CC control chars).  First print the input,
7567c478bd9Sstevel@tonic-gate 	 * output, control, and line discipline modes.
7577c478bd9Sstevel@tonic-gate 	 */
7587c478bd9Sstevel@tonic-gate 	(void) printf("%x:%x:%x:%x", cb.c_iflag, cb.c_oflag, cb.c_cflag,
7597c478bd9Sstevel@tonic-gate 	    cb.c_lflag);
7607c478bd9Sstevel@tonic-gate 
7617c478bd9Sstevel@tonic-gate 	/* Print the control character fields. */
7627c478bd9Sstevel@tonic-gate 	if (term & TERMIOS)
7637c478bd9Sstevel@tonic-gate 		last = MAX_CC;
7647c478bd9Sstevel@tonic-gate 	else
7657c478bd9Sstevel@tonic-gate 		last = NCC;
7667c478bd9Sstevel@tonic-gate #ifdef EUC
7677c478bd9Sstevel@tonic-gate 	if (term & CSIW) {
7687c478bd9Sstevel@tonic-gate 		for (i = 0; i < MAX_CC; i++)
7697c478bd9Sstevel@tonic-gate 			(void) printf(":%x", (i >= last) ? 0 : cb.c_cc[i]);
7707c478bd9Sstevel@tonic-gate 		/*
7717c478bd9Sstevel@tonic-gate 		 * Print out ldterm_cs_data_user_t data fields for
7727c478bd9Sstevel@tonic-gate 		 * PSARC/1999/140 TCR2. This change introduces additional
7737c478bd9Sstevel@tonic-gate 		 * 44 fields that come from the ldterm_cs_data_user_t data
7747c478bd9Sstevel@tonic-gate 		 * structure.
7757c478bd9Sstevel@tonic-gate 		 */
7767c478bd9Sstevel@tonic-gate 		(void) printf(":%x:%x:%x:", kcswp.version, kcswp.codeset_type,
7777c478bd9Sstevel@tonic-gate 		    kcswp.csinfo_num);
7787c478bd9Sstevel@tonic-gate 		if (*kcswp.locale_name == '\0') {
7797c478bd9Sstevel@tonic-gate 			(void) printf("00");
7807c478bd9Sstevel@tonic-gate 		} else {
7817c478bd9Sstevel@tonic-gate 			for (i = 0; kcswp.locale_name[i] && i < MAXNAMELEN; i++)
7827c478bd9Sstevel@tonic-gate 				(void) printf("%02x", kcswp.locale_name[i]);
7837c478bd9Sstevel@tonic-gate 		}
7847c478bd9Sstevel@tonic-gate 		for (i = 0; i < LDTERM_CS_MAX_CODESETS; i++)
7857c478bd9Sstevel@tonic-gate 			(void) printf(":%x:%x:%x:%x",
7867c478bd9Sstevel@tonic-gate 			    kcswp.eucpc_data[i].byte_length,
7877c478bd9Sstevel@tonic-gate 			    kcswp.eucpc_data[i].screen_width,
7887c478bd9Sstevel@tonic-gate 			    kcswp.eucpc_data[i].msb_start,
7897c478bd9Sstevel@tonic-gate 			    kcswp.eucpc_data[i].msb_end);
7907c478bd9Sstevel@tonic-gate 	} else {
7917c478bd9Sstevel@tonic-gate #endif /* EUC */
7927c478bd9Sstevel@tonic-gate 		for (i = 0; i < last; i++)
7937c478bd9Sstevel@tonic-gate 			(void) printf(":%x", cb.c_cc[i]);
7947c478bd9Sstevel@tonic-gate #ifdef EUC
7957c478bd9Sstevel@tonic-gate 	}
7967c478bd9Sstevel@tonic-gate #endif /* EUC */
7977c478bd9Sstevel@tonic-gate 	(void) printf("\n");
7987c478bd9Sstevel@tonic-gate }
799