xref: /titanic_52/usr/src/cmd/ttymon/stty.c (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1999-2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
29  * All Rights Reserved
30  *
31  */
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 #include <stdio.h>
36 #include <ctype.h>
37 #include <locale.h>
38 #include <sys/types.h>
39 #include <termio.h>
40 #include <sys/stermio.h>
41 #include <sys/termiox.h>
42 #include <string.h>
43 #include <stdlib.h>
44 #include <limits.h>
45 #ifdef EUC
46 #include <sys/stat.h>
47 #include <fcntl.h>
48 #include <unistd.h>
49 #include <sys/param.h>
50 #include <sys/stropts.h>
51 #include <sys/eucioctl.h>
52 #include <sys/csiioctl.h>
53 #include <sys/stream.h>
54 #include <sys/termios.h>
55 #include <sys/ldterm.h>
56 #include <getwidth.h>
57 #endif /* EUC */
58 #include "stty.h"
59 
60 extern const char *not_supported[];
61 
62 extern char *getenv();
63 extern void exit();
64 extern void perror();
65 extern int get_ttymode();
66 extern int set_ttymode();
67 
68 static char *STTY = "stty: ";
69 static int pitt = 0;
70 static struct termios cb;
71 static struct termio ocb; /* for non-streams devices */
72 static struct stio stio;
73 static struct termiox termiox;
74 static struct winsize winsize, owinsize;
75 static int term;
76 #ifdef EUC
77 static struct eucioc kwp;
78 static eucwidth_t wp;
79 static ldterm_cs_data_user_t cswp;	/* User side codeset width data */
80 static ldterm_cs_data_user_t kcswp;	/* Kernel side codeset width data */
81 static int invalid_ldterm_dat_file;
82 #endif /* EUC */
83 
84 static void prmodes();
85 static void pramodes();
86 static void pit(unsigned char what, char *itsname, char *sep);
87 static void delay(int m, char *s);
88 static void prspeed(char *c, int s);
89 static void prencode();
90 
91 int
92 main(int argc, char *argv[])
93 {
94 	int i;
95 	int fd;
96 	char *s_arg, *sttyparse();	/* s_arg: ptr to mode to be set */
97 #ifdef	EUC
98 	char *lc;
99 	char tmps[PATH_MAX];
100 #endif	/* EUC */
101 
102 	(void) setlocale(LC_ALL, "");
103 #if !defined(TEXT_DOMAIN)
104 #define	TEXT_DOMAIN "SYS_TEST"
105 #endif
106 	(void) textdomain(TEXT_DOMAIN);
107 
108 #ifdef EUC
109 	lc = setlocale(LC_CTYPE, (const char *)NULL);
110 	if (lc) {
111 		sprintf(tmps, _LDTERM_DAT_PATH, lc);
112 
113 		fd = open(tmps, O_RDONLY, 0);
114 		if (fd != -1) {
115 			if (read(fd, (void *)&cswp, sizeof (cswp)) <
116 			    sizeof (cswp)) {
117 				(void) fprintf(stderr, gettext(
118 					"cannot read entier %s file\n"), tmps);
119 				exit(2);
120 			}
121 
122 			(void) close(fd);
123 
124 			/*
125 			 * If the ldterm.dat contains invalid data or
126 			 * the current locale name is too long, we clear
127 			 * the 'cswp' and flag the invalid ldterm.dat since
128 			 * we are not going to use the data.
129 			 */
130 			if (cswp.version > LDTERM_DATA_VERSION ||
131 			    cswp.codeset_type < LDTERM_CS_TYPE_MIN ||
132 			    cswp.codeset_type > LDTERM_CS_TYPE_MAX ||
133 			    strlen(lc) >= MAXNAMELEN ||
134 			    (cswp.codeset_type == LDTERM_CS_TYPE_EUC &&
135 			    cswp.csinfo_num > LDTERM_CS_TYPE_EUC_MAX_SUBCS) ||
136 			    (cswp.codeset_type == LDTERM_CS_TYPE_PCCS &&
137 			    (cswp.csinfo_num < LDTERM_CS_TYPE_PCCS_MIN_SUBCS ||
138 			    cswp.csinfo_num > LDTERM_CS_TYPE_PCCS_MAX_SUBCS))) {
139 				(void) memset((void *)&cswp, 0, sizeof (cswp));
140 				invalid_ldterm_dat_file = 1;
141 			} else {
142 				(void) strcpy(cswp.locale_name, lc);
143 			}
144 		}
145 	}
146 
147 	getwidth(&wp);
148 #endif /* EUC */
149 
150 	if ((term = get_ttymode(0, &ocb, &cb, &stio, &termiox, &winsize
151 #ifdef EUC
152 	    /* */, &kwp, &kcswp
153 #endif /* EUC */
154 	    /* */)) < 0) {
155 		perror(STTY);
156 		exit(2);
157 	}
158 	owinsize = winsize;
159 	if (argc == 1) {
160 		prmodes();
161 		exit(0);
162 	}
163 	if ((argc == 2) && (argv[1][0] == '-') && (argv[1][2] == '\0'))
164 	switch (argv[1][1]) {
165 		case 'a':
166 			pramodes();
167 			return (0);
168 		case 'g':
169 			prencode();
170 			return (0);
171 		case '-':
172 			prmodes(); /* stty -- */
173 			return (0);
174 		default:
175 			(void) fprintf(stderr, gettext(
176 				"usage: stty [-a| -g]\n"));
177 			(void) fprintf(stderr, gettext(
178 				"       stty [modes]\n"));
179 			return (2);
180 	}
181 
182 	if ((argc == 3) && (argv[1][0] == '-') && (argv[1][2] == '\0') &&
183 	(argv[2][0] == '-') && (argv[2][1] == '-') && (argv[2][2] == '\0'))
184 	switch (argv[1][1]) {
185 	case 'a':
186 		pramodes();
187 		return (0);
188 	case 'g':
189 		prencode();
190 		return (0);
191 	default:
192 		(void) fprintf(stderr, gettext(
193 			"usage: stty [-a| -g]\n"));
194 		(void) fprintf(stderr, gettext(
195 			"       stty [modes]\n"));
196 		return (2);
197 	}
198 	if ((argc >= 3) && (argv[1][0] == '-') && (argv[1][1] == '-') &&
199 		(argv[1][2] == '\0')) {
200 		/* ignore -- */
201 		--argc;
202 		++argv;
203 	}
204 	if (s_arg = sttyparse(argc, argv, term, &ocb, &cb, &termiox, &winsize
205 #ifdef EUC
206 	    /* */, &wp, &kwp, &cswp, &kcswp
207 #endif /* EUC */
208 	    /* */)) {
209 		char *s = s_arg;
210 		if (*s == '-') s++;
211 		for (i = 0; not_supported[i]; i++) {
212 			if (strcmp(not_supported[i], s) == 0) {
213 				(void) fprintf(stderr,
214 				gettext(
215 			"mode not supported on this device: %s\n"), s_arg);
216 				exit(2);
217 			}
218 		}
219 		(void) fprintf(stderr, gettext("unknown mode: %s\n"), s_arg);
220 		return (2);
221 	}
222 
223 	if (set_ttymode(0, term, &ocb, &cb, &stio, &termiox, &winsize, &owinsize
224 #ifdef EUC
225 	    /* */, &kwp, &kcswp, invalid_ldterm_dat_file
226 #endif /* EUC */
227 	    /* */) == -1) {
228 		perror(STTY);
229 		return (2);
230 	}
231 	return (0);
232 }
233 
234 void
235 prmodes(void)				/* print modes, no options, argc is 1 */
236 {
237 	int m;
238 
239 	if (!(term & ASYNC)) {
240 		m = stio.imode;
241 		if (m & IUCLC)
242 			(void) printf("iuclc ");
243 		else
244 			(void) printf("-iuclc ");
245 		m = stio.omode;
246 		if (m & OLCUC)
247 			(void) printf("olcuc ");
248 		else
249 			(void) printf("-olcuc ");
250 		if (m & TAB3)
251 			(void) printf("tab3 ");
252 		m = stio.lmode;
253 		if (m & XCASE)
254 			(void) printf("xcase ");
255 		else
256 			(void) printf("-xcase ");
257 		if (m & STFLUSH)
258 			(void) printf("stflush ");
259 		else
260 			(void) printf("-stflush ");
261 		if (m & STWRAP)
262 			(void) printf("stwrap ");
263 		else
264 			(void) printf("-stwrap ");
265 		if (m & STAPPL)
266 			(void) printf("stappl ");
267 		else
268 			(void) printf("-stappl ");
269 		(void) printf("\n");
270 	}
271 	if (term & ASYNC) {
272 		m = cb.c_cflag;
273 		if ((term & TERMIOS) && cfgetispeed(&cb) != 0 &&
274 		    cfgetispeed(&cb) != cfgetospeed(&cb)) {
275 			prspeed("ispeed ", cfgetispeed(&cb));
276 			prspeed("ospeed ", cfgetospeed(&cb));
277 		} else
278 			prspeed("speed ", cfgetospeed(&cb));
279 		if (m&PARENB) {
280 			if ((m&PAREXT) && (term & TERMIOS)) {
281 				if (m&PARODD)
282 					(void) printf("markp ");
283 				else
284 					(void) printf("spacep ");
285 			} else {
286 				if (m&PARODD)
287 					(void) printf("oddp ");
288 				else
289 					(void) printf("evenp ");
290 			}
291 		} else
292 			(void) printf("-parity ");
293 		if (((m&PARENB) && !(m&CS7)) || (!(m&PARENB) && !(m&CS8)))
294 			(void) printf("cs%c ", '5'+(m&CSIZE)/CS6);
295 		if (m&CSTOPB)
296 			(void) printf("cstopb ");
297 		if (m&HUPCL)
298 			(void) printf("hupcl ");
299 		if (!(m&CREAD))
300 			(void) printf("-cread ");
301 		if (m&CLOCAL)
302 			(void) printf("clocal ");
303 		if (m&LOBLK)
304 			(void) printf("loblk ");
305 		(void) printf("\n");
306 		if (ocb.c_line != 0)
307 			(void) printf(gettext("line = %d; "), ocb.c_line);
308 		if (term & WINDOW) {
309 			(void) printf(gettext(
310 		"rows = %d; columns = %d;"), winsize.ws_row, winsize.ws_col);
311 			(void) printf(gettext(
312 				" ypixels = %d; xpixels = %d;\n"),
313 				winsize.ws_ypixel, winsize.ws_xpixel);
314 		}
315 		if ((cb.c_lflag&ICANON) == 0)
316 			(void) printf(gettext("min = %d; time = %d;\n"),
317 			    cb.c_cc[VMIN], cb.c_cc[VTIME]);
318 		if (cb.c_cc[VINTR] != CINTR)
319 			pit(cb.c_cc[VINTR], "intr", "; ");
320 		if (cb.c_cc[VQUIT] != CQUIT)
321 			pit(cb.c_cc[VQUIT], "quit", "; ");
322 		if (cb.c_cc[VERASE] != CERASE)
323 			pit(cb.c_cc[VERASE], "erase", "; ");
324 		if (cb.c_cc[VKILL] != CKILL)
325 			pit(cb.c_cc[VKILL], "kill", "; ");
326 		if (cb.c_cc[VEOF] != CEOF)
327 			pit(cb.c_cc[VEOF], "eof", "; ");
328 		if (cb.c_cc[VEOL] != CNUL)
329 			pit(cb.c_cc[VEOL], "eol", "; ");
330 		if (cb.c_cc[VEOL2] != CNUL)
331 			pit(cb.c_cc[VEOL2], "eol2", "; ");
332 		if (cb.c_cc[VSWTCH] != CSWTCH)
333 			pit(cb.c_cc[VSWTCH], "swtch", "; ");
334 		if (term & TERMIOS) {
335 			if (cb.c_cc[VSTART] != CSTART)
336 				pit(cb.c_cc[VSTART], "start", "; ");
337 			if (cb.c_cc[VSTOP] != CSTOP)
338 				pit(cb.c_cc[VSTOP], "stop", "; ");
339 			if (cb.c_cc[VSUSP] != CSUSP)
340 				pit(cb.c_cc[VSUSP], "susp", "; ");
341 			if (cb.c_cc[VDSUSP] != CDSUSP)
342 				pit(cb.c_cc[VDSUSP], "dsusp", "; ");
343 			if (cb.c_cc[VREPRINT] != CRPRNT)
344 				pit(cb.c_cc[VREPRINT], "rprnt", "; ");
345 			if (cb.c_cc[VDISCARD] != CFLUSH)
346 				pit(cb.c_cc[VDISCARD], "flush", "; ");
347 			if (cb.c_cc[VWERASE] != CWERASE)
348 				pit(cb.c_cc[VWERASE], "werase", "; ");
349 			if (cb.c_cc[VLNEXT] != CLNEXT)
350 				pit(cb.c_cc[VLNEXT], "lnext", "; ");
351 		}
352 		if (pitt) (void) printf("\n");
353 		m = cb.c_iflag;
354 		if (m&IGNBRK)
355 			(void) printf("ignbrk ");
356 		else if (m&BRKINT)
357 			(void) printf("brkint ");
358 		if (!(m&INPCK))
359 			(void) printf("-inpck ");
360 		else if (m&IGNPAR)
361 			(void) printf("ignpar ");
362 		if (m&PARMRK)
363 			(void) printf("parmrk ");
364 		if (!(m&ISTRIP))
365 			(void) printf("-istrip ");
366 		if (m&INLCR)
367 			(void) printf("inlcr ");
368 		if (m&IGNCR)
369 			(void) printf("igncr ");
370 		if (m&ICRNL)
371 			(void) printf("icrnl ");
372 		if (m&IUCLC)
373 			(void) printf("iuclc ");
374 		if (!(m&IXON))
375 			(void) printf("-ixon ");
376 		else if (!(m&IXANY))
377 			(void) printf("-ixany ");
378 		if (m&IXOFF)
379 			(void) printf("ixoff ");
380 		if ((term & TERMIOS) && (m&IMAXBEL))
381 			(void) printf("imaxbel ");
382 		m = cb.c_oflag;
383 		if (!(m&OPOST))
384 			(void) printf("-opost ");
385 		else {
386 			if (m&OLCUC)
387 				(void) printf("olcuc ");
388 			if (m&ONLCR)
389 				(void) printf("onlcr ");
390 			if (m&OCRNL)
391 				(void) printf("ocrnl ");
392 			if (m&ONOCR)
393 				(void) printf("onocr ");
394 			if (m&ONLRET)
395 				(void) printf("onlret ");
396 			if (m&OFILL)
397 				if (m&OFDEL)
398 					(void) printf("del-fill ");
399 				else
400 					(void) printf("nul-fill ");
401 			delay((m&CRDLY)/CR1, "cr");
402 			delay((m&NLDLY)/NL1, "nl");
403 			delay((m&TABDLY)/TAB1, "tab");
404 			delay((m&BSDLY)/BS1, "bs");
405 			delay((m&VTDLY)/VT1, "vt");
406 			delay((m&FFDLY)/FF1, "ff");
407 		}
408 		(void) printf("\n");
409 		m = cb.c_lflag;
410 		if (!(m&ISIG))
411 			(void) printf("-isig ");
412 		if (!(m&ICANON))
413 			(void) printf("-icanon ");
414 		if (m&XCASE)
415 			(void) printf("xcase ");
416 		(void) printf("-echo "+((m&ECHO) != 0));
417 		(void) printf("-echoe "+((m&ECHOE) != 0));
418 		(void) printf("-echok "+((m&ECHOK) != 0));
419 		if (m&ECHONL)
420 			(void) printf("echonl ");
421 		if (m&NOFLSH)
422 			(void) printf("noflsh ");
423 		if (m&TOSTOP)
424 			(void) printf("tostop ");
425 		if (m&ECHOCTL)
426 			(void) printf("echoctl ");
427 		if (m&ECHOPRT)
428 			(void) printf("echoprt ");
429 		if (m&ECHOKE)
430 			(void) printf("echoke ");
431 		if (m&DEFECHO)
432 			(void) printf("defecho ");
433 		if (m&FLUSHO)
434 			(void) printf("flusho ");
435 		if (m&PENDIN)
436 			(void) printf("pendin ");
437 		if (m&IEXTEN)
438 			(void) printf("iexten ");
439 		(void) printf("\n");
440 	}
441 	if (term & FLOW) {
442 		m = termiox.x_hflag;
443 		if (m & RTSXOFF)
444 			(void) printf("rtsxoff ");
445 		if (m & CTSXON)
446 			(void) printf("ctsxon ");
447 		if (m & DTRXOFF)
448 			(void) printf("dtrxoff ");
449 		if (m & CDXON)
450 			(void) printf("cdxon ");
451 		if (m & ISXOFF)
452 			(void) printf("isxoff ");
453 		m = termiox.x_cflag;
454 		switch (m & XMTCLK) {
455 			case XCIBRG: (void)printf("xcibrg ");
456 				    break;
457 			case XCTSET: (void)printf("xctset ");
458 				    break;
459 			case XCRSET: (void)printf("xcrset ");
460 		}
461 
462 		switch (m & RCVCLK) {
463 			case RCIBRG: (void)printf("rcibrg ");
464 				    break;
465 			case RCTSET: (void)printf("rctset ");
466 				    break;
467 			case RCRSET: (void)printf("rcrset ");
468 		}
469 
470 		switch (m & TSETCLK) {
471 			case TSETCOFF: (void)printf("tsetcoff ");
472 				    break;
473 			case TSETCRBRG: (void)printf("tsetcrbrg ");
474 				    break;
475 			case TSETCTBRG: (void)printf("tsetctbrg ");
476 				    break;
477 			case TSETCTSET: (void)printf("tsetctset ");
478 				    break;
479 			case TSETCRSET: (void)printf("tsetcrset ");
480 		}
481 
482 		switch (m & RSETCLK) {
483 			case RSETCOFF: (void)printf("rsetcoff ");
484 				    break;
485 			case RSETCRBRG: (void)printf("rsetcrbrg ");
486 				    break;
487 			case RSETCTBRG: (void)printf("rsetctbrg ");
488 				    break;
489 			case RSETCTSET: (void)printf("rsetctset ");
490 				    break;
491 			case RSETCRSET: (void)printf("rsetcrset ");
492 		}
493 		(void) printf("\n");
494 	}
495 }
496 
497 void
498 pramodes(void)				/* print all modes, -a option */
499 {
500 	int m;
501 
502 	m = cb.c_cflag;
503 	if (term & ASYNC) {
504 		if ((term & TERMIOS) && cfgetispeed(&cb) != 0 &&
505 		    cfgetispeed(&cb) != cfgetospeed(&cb)) {
506 			prspeed("ispeed ", cfgetispeed(&cb));
507 			prspeed("ospeed ", cfgetospeed(&cb));
508 		} else
509 			prspeed("speed ", cfgetospeed(&cb));
510 		if (!(term & TERMIOS))
511 			(void) printf(gettext("line = %d; "), ocb.c_line);
512 		(void) printf("\n");
513 		if (term & WINDOW) {
514 			(void) printf(gettext("rows = %d; columns = %d;"),
515 				winsize.ws_row, winsize.ws_col);
516 			(void) printf(gettext(
517 				" ypixels = %d; xpixels = %d;\n"),
518 				winsize.ws_ypixel, winsize.ws_xpixel);
519 		}
520 #ifdef EUC
521 		if ((term & CSIW) && kcswp.locale_name[0]) {
522 			(void) printf("csdata %s\n", kcswp.locale_name);
523 		} else {
524 			(void) printf("csdata ?\n");
525 		}
526 		/*
527 		 * If kwp.eucw[0] is zero, it means the current codeset type
528 		 * in the ldterm is not EUC.
529 		 */
530 		if ((term & EUCW) && kwp.eucw[0]) {
531 			(void) printf("eucw %d:%d:%d:%d, ", kwp.eucw[0],
532 				kwp.eucw[1], kwp.eucw[2], kwp.eucw[3]);
533 			(void) printf("scrw %d:%d:%d:%d\n", kwp.scrw[0],
534 				kwp.scrw[1], kwp.scrw[2], kwp.scrw[3]);
535 		} else
536 			(void) printf("eucw ?, scrw ?\n");
537 #endif /* EUC */
538 		if ((cb.c_lflag&ICANON) == 0)
539 			(void) printf(gettext("min = %d; time = %d;\n"),
540 				cb.c_cc[VMIN], cb.c_cc[VTIME]);
541 		pit(cb.c_cc[VINTR], "intr", "; ");
542 		pit(cb.c_cc[VQUIT], "quit", "; ");
543 		pit(cb.c_cc[VERASE], "erase", "; ");
544 		pit(cb.c_cc[VKILL], "kill", ";\n");
545 		pit(cb.c_cc[VEOF], "eof", "; ");
546 		pit(cb.c_cc[VEOL], "eol", "; ");
547 		pit(cb.c_cc[VEOL2], "eol2", "; ");
548 		pit(cb.c_cc[VSWTCH], "swtch", ";\n");
549 		if (term & TERMIOS) {
550 			pit(cb.c_cc[VSTART], "start", "; ");
551 			pit(cb.c_cc[VSTOP], "stop", "; ");
552 			pit(cb.c_cc[VSUSP], "susp", "; ");
553 			pit(cb.c_cc[VDSUSP], "dsusp", ";\n");
554 			pit(cb.c_cc[VREPRINT], "rprnt", "; ");
555 			pit(cb.c_cc[VDISCARD], "flush", "; ");
556 			pit(cb.c_cc[VWERASE], "werase", "; ");
557 			pit(cb.c_cc[VLNEXT], "lnext", ";\n");
558 		}
559 	} else
560 		pit((unsigned)stio.tab, "ctab", "\n");
561 	m = cb.c_cflag;
562 	(void) printf("-parenb "+((m&PARENB) != 0));
563 	(void) printf("-parodd "+((m&PARODD) != 0));
564 	(void) printf("cs%c ", '5'+(m&CSIZE)/CS6);
565 	(void) printf("-cstopb "+((m&CSTOPB) != 0));
566 	(void) printf("-hupcl "+((m&HUPCL) != 0));
567 	(void) printf("-cread "+((m&CREAD) != 0));
568 	(void) printf("-clocal "+((m&CLOCAL) != 0));
569 
570 	(void) printf("-loblk "+((m&LOBLK) != 0));
571 	(void) printf("-crtscts "+((m&CRTSCTS) != 0));
572 	(void) printf("-crtsxoff "+((m&CRTSXOFF) != 0));
573 	if (term & TERMIOS)
574 		(void) printf("-parext "+((m&PAREXT) != 0));
575 
576 	(void) printf("\n");
577 	m = cb.c_iflag;
578 	(void) printf("-ignbrk "+((m&IGNBRK) != 0));
579 	(void) printf("-brkint "+((m&BRKINT) != 0));
580 	(void) printf("-ignpar "+((m&IGNPAR) != 0));
581 	(void) printf("-parmrk "+((m&PARMRK) != 0));
582 	(void) printf("-inpck "+((m&INPCK) != 0));
583 	(void) printf("-istrip "+((m&ISTRIP) != 0));
584 	(void) printf("-inlcr "+((m&INLCR) != 0));
585 	(void) printf("-igncr "+((m&IGNCR) != 0));
586 	(void) printf("-icrnl "+((m&ICRNL) != 0));
587 	(void) printf("-iuclc "+((m&IUCLC) != 0));
588 	(void) printf("\n");
589 	(void) printf("-ixon "+((m&IXON) != 0));
590 	(void) printf("-ixany "+((m&IXANY) != 0));
591 	(void) printf("-ixoff "+((m&IXOFF) != 0));
592 	if (term & TERMIOS)
593 		(void) printf("-imaxbel "+((m&IMAXBEL) != 0));
594 	(void) printf("\n");
595 	m = cb.c_lflag;
596 	(void) printf("-isig "+((m&ISIG) != 0));
597 	(void) printf("-icanon "+((m&ICANON) != 0));
598 	(void) printf("-xcase "+((m&XCASE) != 0));
599 	(void) printf("-echo "+((m&ECHO) != 0));
600 	(void) printf("-echoe "+((m&ECHOE) != 0));
601 	(void) printf("-echok "+((m&ECHOK) != 0));
602 	(void) printf("-echonl "+((m&ECHONL) != 0));
603 	(void) printf("-noflsh "+((m&NOFLSH) != 0));
604 	if (term & TERMIOS) {
605 		(void) printf("\n");
606 		(void) printf("-tostop "+((m&TOSTOP) != 0));
607 		(void) printf("-echoctl "+((m&ECHOCTL) != 0));
608 		(void) printf("-echoprt "+((m&ECHOPRT) != 0));
609 		(void) printf("-echoke "+((m&ECHOKE) != 0));
610 		(void) printf("-defecho "+((m&DEFECHO) != 0));
611 		(void) printf("-flusho "+((m&FLUSHO) != 0));
612 		(void) printf("-pendin "+((m&PENDIN) != 0));
613 		(void) printf("-iexten "+((m&IEXTEN) != 0));
614 	}
615 	if (!(term & ASYNC)) {
616 		(void) printf("-stflush "+((m&STFLUSH) != 0));
617 		(void) printf("-stwrap "+((m&STWRAP) != 0));
618 		(void) printf("-stappl "+((m&STAPPL) != 0));
619 	}
620 	(void) printf("\n");
621 	m = cb.c_oflag;
622 	(void) printf("-opost "+((m&OPOST) != 0));
623 	(void) printf("-olcuc "+((m&OLCUC) != 0));
624 	(void) printf("-onlcr "+((m&ONLCR) != 0));
625 	(void) printf("-ocrnl "+((m&OCRNL) != 0));
626 	(void) printf("-onocr "+((m&ONOCR) != 0));
627 	(void) printf("-onlret "+((m&ONLRET) != 0));
628 	(void) printf("-ofill "+((m&OFILL) != 0));
629 	(void) printf("-ofdel "+((m&OFDEL) != 0));
630 	delay((m&CRDLY)/CR1, "cr");
631 	delay((m&NLDLY)/NL1, "nl");
632 	delay((m&TABDLY)/TAB1, "tab");
633 	delay((m&BSDLY)/BS1, "bs");
634 	delay((m&VTDLY)/VT1, "vt");
635 	delay((m&FFDLY)/FF1, "ff");
636 	(void) printf("\n");
637 	if (term & FLOW) {
638 		m = termiox.x_hflag;
639 		(void) printf("-rtsxoff "+((m&RTSXOFF) != 0));
640 		(void) printf("-ctsxon "+((m&CTSXON) != 0));
641 		(void) printf("-dtrxoff "+((m&DTRXOFF) != 0));
642 		(void) printf("-cdxon "+((m&CDXON) != 0));
643 		(void) printf("-isxoff "+((m&ISXOFF) != 0));
644 		m = termiox.x_cflag;
645 		switch (m & XMTCLK) {
646 			case XCIBRG: (void)printf("xcibrg ");
647 				    break;
648 			case XCTSET: (void)printf("xctset ");
649 				    break;
650 			case XCRSET: (void)printf("xcrset ");
651 		}
652 
653 		switch (m & RCVCLK) {
654 			case RCIBRG: (void)printf("rcibrg ");
655 				    break;
656 			case RCTSET: (void)printf("rctset ");
657 				    break;
658 			case RCRSET: (void)printf("rcrset ");
659 		}
660 
661 		switch (m & TSETCLK) {
662 			case TSETCOFF: (void)printf("tsetcoff ");
663 				    break;
664 			case TSETCRBRG: (void)printf("tsetcrbrg ");
665 				    break;
666 			case TSETCTBRG: (void)printf("tsetctbrg ");
667 				    break;
668 			case TSETCTSET: (void)printf("tsetctset ");
669 				    break;
670 			case TSETCRSET: (void)printf("tsetcrset ");
671 		}
672 
673 		switch (m & RSETCLK) {
674 			case RSETCOFF: (void)printf("rsetcoff ");
675 				    break;
676 			case RSETCRBRG: (void)printf("rsetcrbrg ");
677 				    break;
678 			case RSETCTBRG: (void)printf("rsetctbrg ");
679 				    break;
680 			case RSETCTSET: (void)printf("rsetctset ");
681 				    break;
682 			case RSETCRSET: (void)printf("rsetcrset ");
683 		}
684 		(void) printf("\n");
685 	}
686 }
687 
688 /* print function for prmodes() and pramodes() */
689 void
690 pit(unsigned char what, char *itsname, char *sep)
691 {
692 
693 	pitt++;
694 	(void) printf("%s", itsname);
695 	if ((term & TERMIOS) && what == _POSIX_VDISABLE ||
696 			!(term & TERMIOS) && what == 0200) {
697 		(void) printf(" = <undef>%s", sep);
698 		return;
699 	}
700 	(void) printf(" = ");
701 	if (what & 0200 && !isprint(what)) {
702 		(void) printf("-");
703 		what &= ~ 0200;
704 	}
705 	if (what == 0177) {
706 		(void) printf("^?%s", sep);
707 		return;
708 	} else if (what < ' ') {
709 		(void) printf("^");
710 		what += '`';
711 		if (what > 'z')
712 			what -= 'a' -'A';
713 	}
714 	(void) printf("%c%s", what, sep);
715 }
716 
717 void
718 delay(int m, char *s)
719 {
720 	if (m)
721 		(void) printf("%s%d ", s, m);
722 }
723 
724 void
725 prspeed(char *c, int scode)
726 {
727 	int sval = -1;
728 	int i;
729 
730 	for (i = 0; speeds[i].string; i++) {
731 		if (speeds[i].code == scode) {
732 			sval = speeds[i].value;
733 			break;
734 		}
735 	}
736 
737 	(void) printf("%s%d baud; ", c, sval);
738 }
739 
740 /* print current settings for use with  */
741 void
742 prencode(void)		/* another stty cmd, used for -g option */
743 {
744 	int i, last;
745 
746 	/*
747 	 * Although there are only 16 control chars defined as of April 1995,
748 	 * prencode() and encode() will not have to be changed if up to MAX_CC
749 	 * control chars are defined in the future.  A maximum of MAX_CC rather
750 	 * than NCCS control chars are printed because the last control slot
751 	 * is unused.  "stty -g" prints out a total of NUM_FIELDS fields
752 	 * (NUM_MODES modes + MAX_CC control chars).  First print the input,
753 	 * output, control, and line discipline modes.
754 	 */
755 	(void) printf("%x:%x:%x:%x", cb.c_iflag, cb.c_oflag, cb.c_cflag,
756 		cb.c_lflag);
757 
758 	/* Print the control character fields. */
759 	if (term & TERMIOS)
760 		last = MAX_CC;
761 	else
762 		last = NCC;
763 #ifdef EUC
764 	if (term & CSIW) {
765 		for (i = 0; i < MAX_CC; i++)
766 			(void) printf(":%x", (i >= last) ? 0 : cb.c_cc[i]);
767 		/*
768 		 * Print out ldterm_cs_data_user_t data fields for
769 		 * PSARC/1999/140 TCR2. This change introduces additional
770 		 * 44 fields that come from the ldterm_cs_data_user_t data
771 		 * structure.
772 		 */
773 		(void) printf(":%x:%x:%x:", kcswp.version, kcswp.codeset_type,
774 				kcswp.csinfo_num);
775 		if (*kcswp.locale_name == '\0') {
776 			(void) printf("00");
777 		} else {
778 			for (i = 0; kcswp.locale_name[i] && i < MAXNAMELEN; i++)
779 				(void) printf("%02x", kcswp.locale_name[i]);
780 		}
781 		for (i = 0; i < LDTERM_CS_MAX_CODESETS; i++)
782 			(void) printf(":%x:%x:%x:%x",
783 				kcswp.eucpc_data[i].byte_length,
784 				kcswp.eucpc_data[i].screen_width,
785 				kcswp.eucpc_data[i].msb_start,
786 				kcswp.eucpc_data[i].msb_end);
787 	} else {
788 #endif /* EUC */
789 		for (i = 0; i < last; i++)
790 			(void) printf(":%x", cb.c_cc[i]);
791 #ifdef EUC
792 	}
793 #endif /* EUC */
794 	(void) printf("\n");
795 }
796